1 /* dir.c: AFS filesystem directory handling
3 * Copyright (C) 2002 Red Hat, Inc. All Rights Reserved.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/init.h>
16 #include <linux/namei.h>
17 #include <linux/pagemap.h>
18 #include <linux/ctype.h>
19 #include <linux/sched.h>
22 static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
23 struct nameidata *nd);
24 static int afs_dir_open(struct inode *inode, struct file *file);
25 static int afs_readdir(struct file *file, void *dirent, filldir_t filldir);
26 static int afs_d_revalidate(struct dentry *dentry, struct nameidata *nd);
27 static int afs_d_delete(const struct dentry *dentry);
28 static void afs_d_release(struct dentry *dentry);
29 static int afs_lookup_filldir(void *_cookie, const char *name, int nlen,
30 loff_t fpos, u64 ino, unsigned dtype);
31 static int afs_create(struct inode *dir, struct dentry *dentry, int mode,
32 struct nameidata *nd);
33 static int afs_mkdir(struct inode *dir, struct dentry *dentry, int mode);
34 static int afs_rmdir(struct inode *dir, struct dentry *dentry);
35 static int afs_unlink(struct inode *dir, struct dentry *dentry);
36 static int afs_link(struct dentry *from, struct inode *dir,
37 struct dentry *dentry);
38 static int afs_symlink(struct inode *dir, struct dentry *dentry,
40 static int afs_rename(struct inode *old_dir, struct dentry *old_dentry,
41 struct inode *new_dir, struct dentry *new_dentry);
43 const struct file_operations afs_dir_file_operations = {
45 .release = afs_release,
46 .readdir = afs_readdir,
48 .llseek = generic_file_llseek,
51 const struct inode_operations afs_dir_inode_operations = {
56 .symlink = afs_symlink,
60 .permission = afs_permission,
61 .getattr = afs_getattr,
62 .setattr = afs_setattr,
65 static const struct dentry_operations afs_fs_dentry_operations = {
66 .d_revalidate = afs_d_revalidate,
67 .d_delete = afs_d_delete,
68 .d_release = afs_d_release,
71 #define AFS_DIR_HASHTBL_SIZE 128
72 #define AFS_DIR_DIRENT_SIZE 32
73 #define AFS_DIRENT_PER_BLOCK 64
83 uint8_t overflow[4]; /* if any char of the name (inc
84 * NUL) reaches here, consume
85 * the next dirent too */
87 uint8_t extended_name[32];
90 /* AFS directory page header (one at the beginning of every 2048-byte chunk) */
91 struct afs_dir_pagehdr {
94 #define AFS_DIR_MAGIC htons(1234)
100 /* directory block layout */
101 union afs_dir_block {
103 struct afs_dir_pagehdr pagehdr;
106 struct afs_dir_pagehdr pagehdr;
107 uint8_t alloc_ctrs[128];
109 uint16_t hashtable[AFS_DIR_HASHTBL_SIZE];
112 union afs_dirent dirents[AFS_DIRENT_PER_BLOCK];
115 /* layout on a linux VM page */
116 struct afs_dir_page {
117 union afs_dir_block blocks[PAGE_SIZE / sizeof(union afs_dir_block)];
120 struct afs_lookup_cookie {
128 * check that a directory page is valid
130 static inline void afs_dir_check_page(struct inode *dir, struct page *page)
132 struct afs_dir_page *dbuf;
137 /* check the page count */
138 qty = desc.size / sizeof(dbuf->blocks[0]);
142 if (page->index == 0 && qty != ntohs(dbuf->blocks[0].pagehdr.npages)) {
143 printk("kAFS: %s(%lu): wrong number of dir blocks %d!=%hu\n",
144 __func__, dir->i_ino, qty,
145 ntohs(dbuf->blocks[0].pagehdr.npages));
150 /* determine how many magic numbers there should be in this page */
151 latter = dir->i_size - page_offset(page);
152 if (latter >= PAGE_SIZE)
156 qty /= sizeof(union afs_dir_block);
159 dbuf = page_address(page);
160 for (tmp = 0; tmp < qty; tmp++) {
161 if (dbuf->blocks[tmp].pagehdr.magic != AFS_DIR_MAGIC) {
162 printk("kAFS: %s(%lu): bad magic %d/%d is %04hx\n",
163 __func__, dir->i_ino, tmp, qty,
164 ntohs(dbuf->blocks[tmp].pagehdr.magic));
169 SetPageChecked(page);
173 SetPageChecked(page);
178 * discard a page cached in the pagecache
180 static inline void afs_dir_put_page(struct page *page)
183 page_cache_release(page);
187 * get a page into the pagecache
189 static struct page *afs_dir_get_page(struct inode *dir, unsigned long index,
193 _enter("{%lu},%lu", dir->i_ino, index);
195 page = read_cache_page(dir->i_mapping, index, afs_page_filler, key);
198 if (!PageChecked(page))
199 afs_dir_check_page(dir, page);
206 afs_dir_put_page(page);
208 return ERR_PTR(-EIO);
212 * open an AFS directory file
214 static int afs_dir_open(struct inode *inode, struct file *file)
216 _enter("{%lu}", inode->i_ino);
218 BUILD_BUG_ON(sizeof(union afs_dir_block) != 2048);
219 BUILD_BUG_ON(sizeof(union afs_dirent) != 32);
221 if (test_bit(AFS_VNODE_DELETED, &AFS_FS_I(inode)->flags))
224 return afs_open(inode, file);
228 * deal with one block in an AFS directory
230 static int afs_dir_iterate_block(unsigned *fpos,
231 union afs_dir_block *block,
236 union afs_dirent *dire;
237 unsigned offset, next, curr;
241 _enter("%u,%x,%p,,",*fpos,blkoff,block);
243 curr = (*fpos - blkoff) / sizeof(union afs_dirent);
245 /* walk through the block, an entry at a time */
246 for (offset = AFS_DIRENT_PER_BLOCK - block->pagehdr.nentries;
247 offset < AFS_DIRENT_PER_BLOCK;
252 /* skip entries marked unused in the bitmap */
253 if (!(block->pagehdr.bitmap[offset / 8] &
254 (1 << (offset % 8)))) {
255 _debug("ENT[%Zu.%u]: unused",
256 blkoff / sizeof(union afs_dir_block), offset);
259 next * sizeof(union afs_dirent);
263 /* got a valid entry */
264 dire = &block->dirents[offset];
265 nlen = strnlen(dire->u.name,
267 offset * sizeof(union afs_dirent));
269 _debug("ENT[%Zu.%u]: %s %Zu \"%s\"",
270 blkoff / sizeof(union afs_dir_block), offset,
271 (offset < curr ? "skip" : "fill"),
274 /* work out where the next possible entry is */
275 for (tmp = nlen; tmp > 15; tmp -= sizeof(union afs_dirent)) {
276 if (next >= AFS_DIRENT_PER_BLOCK) {
277 _debug("ENT[%Zu.%u]:"
278 " %u travelled beyond end dir block"
280 blkoff / sizeof(union afs_dir_block),
281 offset, next, tmp, nlen);
284 if (!(block->pagehdr.bitmap[next / 8] &
285 (1 << (next % 8)))) {
286 _debug("ENT[%Zu.%u]:"
287 " %u unmarked extension (len %u/%Zu)",
288 blkoff / sizeof(union afs_dir_block),
289 offset, next, tmp, nlen);
293 _debug("ENT[%Zu.%u]: ext %u/%Zu",
294 blkoff / sizeof(union afs_dir_block),
299 /* skip if starts before the current position */
303 /* found the next entry */
304 ret = filldir(cookie,
307 blkoff + offset * sizeof(union afs_dirent),
308 ntohl(dire->u.vnode),
309 filldir == afs_lookup_filldir ?
310 ntohl(dire->u.unique) : DT_UNKNOWN);
312 _leave(" = 0 [full]");
316 *fpos = blkoff + next * sizeof(union afs_dirent);
319 _leave(" = 1 [more]");
324 * iterate through the data blob that lists the contents of an AFS directory
326 static int afs_dir_iterate(struct inode *dir, unsigned *fpos, void *cookie,
327 filldir_t filldir, struct key *key)
329 union afs_dir_block *dblock;
330 struct afs_dir_page *dbuf;
332 unsigned blkoff, limit;
335 _enter("{%lu},%u,,", dir->i_ino, *fpos);
337 if (test_bit(AFS_VNODE_DELETED, &AFS_FS_I(dir)->flags)) {
338 _leave(" = -ESTALE");
342 /* round the file position up to the next entry boundary */
343 *fpos += sizeof(union afs_dirent) - 1;
344 *fpos &= ~(sizeof(union afs_dirent) - 1);
346 /* walk through the blocks in sequence */
348 while (*fpos < dir->i_size) {
349 blkoff = *fpos & ~(sizeof(union afs_dir_block) - 1);
351 /* fetch the appropriate page from the directory */
352 page = afs_dir_get_page(dir, blkoff / PAGE_SIZE, key);
358 limit = blkoff & ~(PAGE_SIZE - 1);
360 dbuf = page_address(page);
362 /* deal with the individual blocks stashed on this page */
364 dblock = &dbuf->blocks[(blkoff % PAGE_SIZE) /
365 sizeof(union afs_dir_block)];
366 ret = afs_dir_iterate_block(fpos, dblock, blkoff,
369 afs_dir_put_page(page);
373 blkoff += sizeof(union afs_dir_block);
375 } while (*fpos < dir->i_size && blkoff < limit);
377 afs_dir_put_page(page);
382 _leave(" = %d", ret);
387 * read an AFS directory
389 static int afs_readdir(struct file *file, void *cookie, filldir_t filldir)
394 _enter("{%Ld,{%lu}}",
395 file->f_pos, file->f_path.dentry->d_inode->i_ino);
397 ASSERT(file->private_data != NULL);
400 ret = afs_dir_iterate(file->f_path.dentry->d_inode, &fpos,
401 cookie, filldir, file->private_data);
404 _leave(" = %d", ret);
409 * search the directory for a name
410 * - if afs_dir_iterate_block() spots this function, it'll pass the FID
411 * uniquifier through dtype
413 static int afs_lookup_filldir(void *_cookie, const char *name, int nlen,
414 loff_t fpos, u64 ino, unsigned dtype)
416 struct afs_lookup_cookie *cookie = _cookie;
418 _enter("{%s,%Zu},%s,%u,,%llu,%u",
419 cookie->name, cookie->nlen, name, nlen,
420 (unsigned long long) ino, dtype);
422 /* insanity checks first */
423 BUILD_BUG_ON(sizeof(union afs_dir_block) != 2048);
424 BUILD_BUG_ON(sizeof(union afs_dirent) != 32);
426 if (cookie->nlen != nlen || memcmp(cookie->name, name, nlen) != 0) {
431 cookie->fid.vnode = ino;
432 cookie->fid.unique = dtype;
435 _leave(" = -1 [found]");
440 * do a lookup in a directory
441 * - just returns the FID the dentry name maps to if found
443 static int afs_do_lookup(struct inode *dir, struct dentry *dentry,
444 struct afs_fid *fid, struct key *key)
446 struct afs_lookup_cookie cookie;
447 struct afs_super_info *as;
451 _enter("{%lu},%p{%s},", dir->i_ino, dentry, dentry->d_name.name);
453 as = dir->i_sb->s_fs_info;
455 /* search the directory */
456 cookie.name = dentry->d_name.name;
457 cookie.nlen = dentry->d_name.len;
458 cookie.fid.vid = as->volume->vid;
462 ret = afs_dir_iterate(dir, &fpos, &cookie, afs_lookup_filldir,
465 _leave(" = %d [iter]", ret);
471 _leave(" = -ENOENT [not found]");
476 _leave(" = 0 { vn=%u u=%u }", fid->vnode, fid->unique);
481 * Try to auto mount the mountpoint with pseudo directory, if the autocell
482 * operation is setted.
484 static struct inode *afs_try_auto_mntpt(
485 int ret, struct dentry *dentry, struct inode *dir, struct key *key,
488 const char *devname = dentry->d_name.name;
489 struct afs_vnode *vnode = AFS_FS_I(dir);
492 _enter("%d, %p{%s}, {%x:%u}, %p",
493 ret, dentry, devname, vnode->fid.vid, vnode->fid.vnode, key);
495 if (ret != -ENOENT ||
496 !test_bit(AFS_VNODE_AUTOCELL, &vnode->flags))
499 inode = afs_iget_autocell(dir, devname, strlen(devname), key);
501 ret = PTR_ERR(inode);
505 *fid = AFS_FS_I(inode)->fid;
506 _leave("= %p", inode);
515 * look up an entry in a directory
517 static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
518 struct nameidata *nd)
520 struct afs_vnode *vnode;
526 vnode = AFS_FS_I(dir);
528 _enter("{%x:%u},%p{%s},",
529 vnode->fid.vid, vnode->fid.vnode, dentry, dentry->d_name.name);
531 ASSERTCMP(dentry->d_inode, ==, NULL);
533 if (dentry->d_name.len >= AFSNAMEMAX) {
534 _leave(" = -ENAMETOOLONG");
535 return ERR_PTR(-ENAMETOOLONG);
538 if (test_bit(AFS_VNODE_DELETED, &vnode->flags)) {
539 _leave(" = -ESTALE");
540 return ERR_PTR(-ESTALE);
543 key = afs_request_key(vnode->volume->cell);
545 _leave(" = %ld [key]", PTR_ERR(key));
546 return ERR_CAST(key);
549 ret = afs_validate(vnode, key);
552 _leave(" = %d [val]", ret);
556 ret = afs_do_lookup(dir, dentry, &fid, key);
558 inode = afs_try_auto_mntpt(ret, dentry, dir, key, &fid);
559 if (!IS_ERR(inode)) {
564 ret = PTR_ERR(inode);
566 if (ret == -ENOENT) {
568 _leave(" = NULL [negative]");
571 _leave(" = %d [do]", ret);
574 dentry->d_fsdata = (void *)(unsigned long) vnode->status.data_version;
576 /* instantiate the dentry */
577 inode = afs_iget(dir->i_sb, key, &fid, NULL, NULL);
580 _leave(" = %ld", PTR_ERR(inode));
581 return ERR_CAST(inode);
585 d_set_d_op(dentry, &afs_fs_dentry_operations);
587 d_add(dentry, inode);
588 _leave(" = 0 { vn=%u u=%u } -> { ino=%lu v=%llu }",
591 dentry->d_inode->i_ino,
592 (unsigned long long)dentry->d_inode->i_version);
598 * check that a dentry lookup hit has found a valid entry
599 * - NOTE! the hit can be a negative hit too, so we can't assume we have an
602 static int afs_d_revalidate(struct dentry *dentry, struct nameidata *nd)
604 struct afs_vnode *vnode, *dir;
605 struct afs_fid uninitialized_var(fid);
606 struct dentry *parent;
611 if (nd->flags & LOOKUP_RCU)
614 vnode = AFS_FS_I(dentry->d_inode);
617 _enter("{v={%x:%u} n=%s fl=%lx},",
618 vnode->fid.vid, vnode->fid.vnode, dentry->d_name.name,
621 _enter("{neg n=%s}", dentry->d_name.name);
623 key = afs_request_key(AFS_FS_S(dentry->d_sb)->volume->cell);
627 /* lock down the parent dentry so we can peer at it */
628 parent = dget_parent(dentry);
629 if (!parent->d_inode)
632 dir = AFS_FS_I(parent->d_inode);
634 /* validate the parent directory */
635 if (test_bit(AFS_VNODE_MODIFIED, &dir->flags))
636 afs_validate(dir, key);
638 if (test_bit(AFS_VNODE_DELETED, &dir->flags)) {
639 _debug("%s: parent dir deleted", dentry->d_name.name);
643 dir_version = (void *) (unsigned long) dir->status.data_version;
644 if (dentry->d_fsdata == dir_version)
645 goto out_valid; /* the dir contents are unchanged */
647 _debug("dir modified");
649 /* search the directory for this vnode */
650 ret = afs_do_lookup(&dir->vfs_inode, dentry, &fid, key);
653 /* the filename maps to something */
654 if (!dentry->d_inode)
656 if (is_bad_inode(dentry->d_inode)) {
657 printk("kAFS: afs_d_revalidate: %s/%s has bad inode\n",
658 parent->d_name.name, dentry->d_name.name);
662 /* if the vnode ID has changed, then the dirent points to a
664 if (fid.vnode != vnode->fid.vnode) {
665 _debug("%s: dirent changed [%u != %u]",
666 dentry->d_name.name, fid.vnode,
671 /* if the vnode ID uniqifier has changed, then the file has
672 * been deleted and replaced, and the original vnode ID has
674 if (fid.unique != vnode->fid.unique) {
675 _debug("%s: file deleted (uq %u -> %u I:%llu)",
676 dentry->d_name.name, fid.unique,
678 (unsigned long long)dentry->d_inode->i_version);
679 spin_lock(&vnode->lock);
680 set_bit(AFS_VNODE_DELETED, &vnode->flags);
681 spin_unlock(&vnode->lock);
687 /* the filename is unknown */
688 _debug("%s: dirent not found", dentry->d_name.name);
694 _debug("failed to iterate dir %s: %d",
695 parent->d_name.name, ret);
700 dentry->d_fsdata = dir_version;
704 _leave(" = 1 [valid]");
707 /* the dirent, if it exists, now points to a different vnode */
709 spin_lock(&dentry->d_lock);
710 dentry->d_flags |= DCACHE_NFSFS_RENAMED;
711 spin_unlock(&dentry->d_lock);
714 if (dentry->d_inode) {
715 /* don't unhash if we have submounts */
716 if (have_submounts(dentry))
720 _debug("dropping dentry %s/%s",
721 parent->d_name.name, dentry->d_name.name);
722 shrink_dcache_parent(dentry);
727 _leave(" = 0 [bad]");
732 * allow the VFS to enquire as to whether a dentry should be unhashed (mustn't
734 * - called from dput() when d_count is going to 0.
735 * - return 1 to request dentry be unhashed, 0 otherwise
737 static int afs_d_delete(const struct dentry *dentry)
739 _enter("%s", dentry->d_name.name);
741 if (dentry->d_flags & DCACHE_NFSFS_RENAMED)
744 if (dentry->d_inode &&
745 (test_bit(AFS_VNODE_DELETED, &AFS_FS_I(dentry->d_inode)->flags) ||
746 test_bit(AFS_VNODE_PSEUDODIR, &AFS_FS_I(dentry->d_inode)->flags)))
749 _leave(" = 0 [keep]");
753 _leave(" = 1 [zap]");
758 * handle dentry release
760 static void afs_d_release(struct dentry *dentry)
762 _enter("%s", dentry->d_name.name);
766 * create a directory on an AFS filesystem
768 static int afs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
770 struct afs_file_status status;
771 struct afs_callback cb;
772 struct afs_server *server;
773 struct afs_vnode *dvnode, *vnode;
779 dvnode = AFS_FS_I(dir);
781 _enter("{%x:%u},{%s},%o",
782 dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name, mode);
785 if (dentry->d_name.len >= AFSNAMEMAX)
788 key = afs_request_key(dvnode->volume->cell);
795 ret = afs_vnode_create(dvnode, key, dentry->d_name.name,
796 mode, &fid, &status, &cb, &server);
800 inode = afs_iget(dir->i_sb, key, &fid, &status, &cb);
802 /* ENOMEM at a really inconvenient time - just abandon the new
803 * directory on the server */
804 ret = PTR_ERR(inode);
808 /* apply the status report we've got for the new vnode */
809 vnode = AFS_FS_I(inode);
810 spin_lock(&vnode->lock);
812 spin_unlock(&vnode->lock);
813 afs_vnode_finalise_status_update(vnode, server);
814 afs_put_server(server);
816 d_instantiate(dentry, inode);
817 if (d_unhashed(dentry)) {
818 _debug("not hashed");
826 afs_put_server(server);
831 _leave(" = %d", ret);
836 * remove a directory from an AFS filesystem
838 static int afs_rmdir(struct inode *dir, struct dentry *dentry)
840 struct afs_vnode *dvnode, *vnode;
844 dvnode = AFS_FS_I(dir);
846 _enter("{%x:%u},{%s}",
847 dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name);
850 if (dentry->d_name.len >= AFSNAMEMAX)
853 key = afs_request_key(dvnode->volume->cell);
859 ret = afs_vnode_remove(dvnode, key, dentry->d_name.name, true);
863 if (dentry->d_inode) {
864 vnode = AFS_FS_I(dentry->d_inode);
865 clear_nlink(&vnode->vfs_inode);
866 set_bit(AFS_VNODE_DELETED, &vnode->flags);
867 afs_discard_callback_on_delete(vnode);
877 _leave(" = %d", ret);
882 * remove a file from an AFS filesystem
884 static int afs_unlink(struct inode *dir, struct dentry *dentry)
886 struct afs_vnode *dvnode, *vnode;
890 dvnode = AFS_FS_I(dir);
892 _enter("{%x:%u},{%s}",
893 dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name);
896 if (dentry->d_name.len >= AFSNAMEMAX)
899 key = afs_request_key(dvnode->volume->cell);
905 if (dentry->d_inode) {
906 vnode = AFS_FS_I(dentry->d_inode);
908 /* make sure we have a callback promise on the victim */
909 ret = afs_validate(vnode, key);
914 ret = afs_vnode_remove(dvnode, key, dentry->d_name.name, false);
918 if (dentry->d_inode) {
919 /* if the file wasn't deleted due to excess hard links, the
920 * fileserver will break the callback promise on the file - if
921 * it had one - before it returns to us, and if it was deleted,
924 * however, if we didn't have a callback promise outstanding,
925 * or it was outstanding on a different server, then it won't
928 vnode = AFS_FS_I(dentry->d_inode);
929 if (test_bit(AFS_VNODE_DELETED, &vnode->flags))
930 _debug("AFS_VNODE_DELETED");
931 if (test_bit(AFS_VNODE_CB_BROKEN, &vnode->flags))
932 _debug("AFS_VNODE_CB_BROKEN");
933 set_bit(AFS_VNODE_CB_BROKEN, &vnode->flags);
934 ret = afs_validate(vnode, key);
935 _debug("nlink %d [val %d]", vnode->vfs_inode.i_nlink, ret);
945 _leave(" = %d", ret);
950 * create a regular file on an AFS filesystem
952 static int afs_create(struct inode *dir, struct dentry *dentry, int mode,
953 struct nameidata *nd)
955 struct afs_file_status status;
956 struct afs_callback cb;
957 struct afs_server *server;
958 struct afs_vnode *dvnode, *vnode;
964 dvnode = AFS_FS_I(dir);
966 _enter("{%x:%u},{%s},%o,",
967 dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name, mode);
970 if (dentry->d_name.len >= AFSNAMEMAX)
973 key = afs_request_key(dvnode->volume->cell);
980 ret = afs_vnode_create(dvnode, key, dentry->d_name.name,
981 mode, &fid, &status, &cb, &server);
985 inode = afs_iget(dir->i_sb, key, &fid, &status, &cb);
987 /* ENOMEM at a really inconvenient time - just abandon the new
988 * directory on the server */
989 ret = PTR_ERR(inode);
993 /* apply the status report we've got for the new vnode */
994 vnode = AFS_FS_I(inode);
995 spin_lock(&vnode->lock);
997 spin_unlock(&vnode->lock);
998 afs_vnode_finalise_status_update(vnode, server);
999 afs_put_server(server);
1001 d_instantiate(dentry, inode);
1002 if (d_unhashed(dentry)) {
1003 _debug("not hashed");
1011 afs_put_server(server);
1016 _leave(" = %d", ret);
1021 * create a hard link between files in an AFS filesystem
1023 static int afs_link(struct dentry *from, struct inode *dir,
1024 struct dentry *dentry)
1026 struct afs_vnode *dvnode, *vnode;
1030 vnode = AFS_FS_I(from->d_inode);
1031 dvnode = AFS_FS_I(dir);
1033 _enter("{%x:%u},{%x:%u},{%s}",
1034 vnode->fid.vid, vnode->fid.vnode,
1035 dvnode->fid.vid, dvnode->fid.vnode,
1036 dentry->d_name.name);
1038 ret = -ENAMETOOLONG;
1039 if (dentry->d_name.len >= AFSNAMEMAX)
1042 key = afs_request_key(dvnode->volume->cell);
1048 ret = afs_vnode_link(dvnode, vnode, key, dentry->d_name.name);
1052 ihold(&vnode->vfs_inode);
1053 d_instantiate(dentry, &vnode->vfs_inode);
1062 _leave(" = %d", ret);
1067 * create a symlink in an AFS filesystem
1069 static int afs_symlink(struct inode *dir, struct dentry *dentry,
1070 const char *content)
1072 struct afs_file_status status;
1073 struct afs_server *server;
1074 struct afs_vnode *dvnode, *vnode;
1076 struct inode *inode;
1080 dvnode = AFS_FS_I(dir);
1082 _enter("{%x:%u},{%s},%s",
1083 dvnode->fid.vid, dvnode->fid.vnode, dentry->d_name.name,
1086 ret = -ENAMETOOLONG;
1087 if (dentry->d_name.len >= AFSNAMEMAX)
1091 if (strlen(content) >= AFSPATHMAX)
1094 key = afs_request_key(dvnode->volume->cell);
1100 ret = afs_vnode_symlink(dvnode, key, dentry->d_name.name, content,
1101 &fid, &status, &server);
1105 inode = afs_iget(dir->i_sb, key, &fid, &status, NULL);
1106 if (IS_ERR(inode)) {
1107 /* ENOMEM at a really inconvenient time - just abandon the new
1108 * directory on the server */
1109 ret = PTR_ERR(inode);
1113 /* apply the status report we've got for the new vnode */
1114 vnode = AFS_FS_I(inode);
1115 spin_lock(&vnode->lock);
1116 vnode->update_cnt++;
1117 spin_unlock(&vnode->lock);
1118 afs_vnode_finalise_status_update(vnode, server);
1119 afs_put_server(server);
1121 d_instantiate(dentry, inode);
1122 if (d_unhashed(dentry)) {
1123 _debug("not hashed");
1131 afs_put_server(server);
1136 _leave(" = %d", ret);
1141 * rename a file in an AFS filesystem and/or move it between directories
1143 static int afs_rename(struct inode *old_dir, struct dentry *old_dentry,
1144 struct inode *new_dir, struct dentry *new_dentry)
1146 struct afs_vnode *orig_dvnode, *new_dvnode, *vnode;
1150 vnode = AFS_FS_I(old_dentry->d_inode);
1151 orig_dvnode = AFS_FS_I(old_dir);
1152 new_dvnode = AFS_FS_I(new_dir);
1154 _enter("{%x:%u},{%x:%u},{%x:%u},{%s}",
1155 orig_dvnode->fid.vid, orig_dvnode->fid.vnode,
1156 vnode->fid.vid, vnode->fid.vnode,
1157 new_dvnode->fid.vid, new_dvnode->fid.vnode,
1158 new_dentry->d_name.name);
1160 ret = -ENAMETOOLONG;
1161 if (new_dentry->d_name.len >= AFSNAMEMAX)
1164 key = afs_request_key(orig_dvnode->volume->cell);
1170 ret = afs_vnode_rename(orig_dvnode, new_dvnode, key,
1171 old_dentry->d_name.name,
1172 new_dentry->d_name.name);
1183 _leave(" = %d", ret);