2 * linux/fs/9p/vfs_inode.c
4 * This file contains vfs inode ops for the 9P2000 protocol.
6 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
7 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2
11 * as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to:
20 * Free Software Foundation
21 * 51 Franklin Street, Fifth Floor
22 * Boston, MA 02111-1301 USA
26 #include <linux/module.h>
27 #include <linux/errno.h>
29 #include <linux/file.h>
30 #include <linux/pagemap.h>
31 #include <linux/stat.h>
32 #include <linux/string.h>
33 #include <linux/inet.h>
34 #include <linux/namei.h>
35 #include <linux/idr.h>
36 #include <linux/sched.h>
37 #include <net/9p/9p.h>
38 #include <net/9p/client.h>
44 static const struct inode_operations v9fs_dir_inode_operations
;
45 static const struct inode_operations v9fs_dir_inode_operations_ext
;
46 static const struct inode_operations v9fs_file_inode_operations
;
47 static const struct inode_operations v9fs_symlink_inode_operations
;
50 * unixmode2p9mode - convert unix mode bits to plan 9
51 * @v9ses: v9fs session information
52 * @mode: mode to convert
56 static int unixmode2p9mode(struct v9fs_session_info
*v9ses
, int mode
)
62 if (v9fs_extended(v9ses
)) {
65 if (v9ses
->nodev
== 0) {
69 res
|= P9_DMNAMEDPIPE
;
76 if ((mode
& S_ISUID
) == S_ISUID
)
78 if ((mode
& S_ISGID
) == S_ISGID
)
80 if ((mode
& S_ISVTX
) == S_ISVTX
)
82 if ((mode
& P9_DMLINK
))
90 * p9mode2unixmode- convert plan9 mode bits to unix mode bits
91 * @v9ses: v9fs session information
92 * @mode: mode to convert
96 static int p9mode2unixmode(struct v9fs_session_info
*v9ses
, int mode
)
102 if ((mode
& P9_DMDIR
) == P9_DMDIR
)
104 else if ((mode
& P9_DMSYMLINK
) && (v9fs_extended(v9ses
)))
106 else if ((mode
& P9_DMSOCKET
) && (v9fs_extended(v9ses
))
107 && (v9ses
->nodev
== 0))
109 else if ((mode
& P9_DMNAMEDPIPE
) && (v9fs_extended(v9ses
))
110 && (v9ses
->nodev
== 0))
112 else if ((mode
& P9_DMDEVICE
) && (v9fs_extended(v9ses
))
113 && (v9ses
->nodev
== 0))
118 if (v9fs_extended(v9ses
)) {
119 if ((mode
& P9_DMSETUID
) == P9_DMSETUID
)
122 if ((mode
& P9_DMSETGID
) == P9_DMSETGID
)
125 if ((mode
& P9_DMSETVTX
) == P9_DMSETVTX
)
132 int v9fs_uflags2omode(int uflags
)
155 if (uflags
& O_TRUNC
)
158 if (uflags
& O_APPEND
)
165 * v9fs_blank_wstat - helper function to setup a 9P stat structure
166 * @v9ses: 9P session info (for determining extended mode)
167 * @wstat: structure to initialize
172 v9fs_blank_wstat(struct p9_wstat
*wstat
)
176 wstat
->qid
.type
= ~0;
177 wstat
->qid
.version
= ~0;
178 *((long long *)&wstat
->qid
.path
) = ~0;
190 wstat
->extension
= NULL
;
194 * v9fs_get_inode - helper function to setup an inode
196 * @mode: mode to setup inode with
200 struct inode
*v9fs_get_inode(struct super_block
*sb
, int mode
)
203 struct v9fs_session_info
*v9ses
= sb
->s_fs_info
;
205 P9_DPRINTK(P9_DEBUG_VFS
, "super block: %p mode: %o\n", sb
, mode
);
207 inode
= new_inode(sb
);
209 inode
->i_mode
= mode
;
210 inode
->i_uid
= current
->fsuid
;
211 inode
->i_gid
= current
->fsgid
;
214 inode
->i_atime
= inode
->i_mtime
= inode
->i_ctime
= CURRENT_TIME
;
215 inode
->i_mapping
->a_ops
= &v9fs_addr_operations
;
217 switch (mode
& S_IFMT
) {
222 if (!v9fs_extended(v9ses
)) {
223 P9_DPRINTK(P9_DEBUG_ERROR
,
224 "special files without extended mode\n");
225 return ERR_PTR(-EINVAL
);
227 init_special_inode(inode
, inode
->i_mode
,
231 inode
->i_op
= &v9fs_file_inode_operations
;
232 inode
->i_fop
= &v9fs_file_operations
;
235 if (!v9fs_extended(v9ses
)) {
236 P9_DPRINTK(P9_DEBUG_ERROR
,
237 "extended modes used w/o 9P2000.u\n");
238 return ERR_PTR(-EINVAL
);
240 inode
->i_op
= &v9fs_symlink_inode_operations
;
244 if (v9fs_extended(v9ses
))
245 inode
->i_op
= &v9fs_dir_inode_operations_ext
;
247 inode
->i_op
= &v9fs_dir_inode_operations
;
248 inode
->i_fop
= &v9fs_dir_operations
;
251 P9_DPRINTK(P9_DEBUG_ERROR
,
252 "BAD mode 0x%x S_IFMT 0x%x\n",
253 mode
, mode
& S_IFMT
);
254 return ERR_PTR(-EINVAL
);
257 P9_EPRINTK(KERN_WARNING
, "Problem allocating inode\n");
258 return ERR_PTR(-ENOMEM
);
264 static struct v9fs_fid*
265 v9fs_clone_walk(struct v9fs_session_info *v9ses, u32 fid, struct dentry *dentry)
269 struct v9fs_fid *ret;
270 struct v9fs_fcall *fcall;
272 nfid = v9fs_get_idpool(&v9ses->fidpool);
274 eprintk(KERN_WARNING, "no free fids available\n");
275 return ERR_PTR(-ENOSPC);
278 err = v9fs_t_walk(v9ses, fid, nfid, (char *) dentry->d_name.name,
282 if (fcall && fcall->id == RWALK)
285 PRINT_FCALL_ERROR("walk error", fcall);
286 v9fs_put_idpool(nfid, &v9ses->fidpool);
292 ret = v9fs_fid_create(v9ses, nfid);
298 err = v9fs_fid_insert(ret, dentry);
300 v9fs_fid_destroy(ret);
307 v9fs_t_clunk(v9ses, nfid);
315 static struct inode
*
316 v9fs_inode_from_fid(struct v9fs_session_info
*v9ses
, struct p9_fid
*fid
,
317 struct super_block
*sb
)
324 st
= p9_client_stat(fid
);
331 umode
= p9mode2unixmode(v9ses
, st
->mode
);
332 ret
= v9fs_get_inode(sb
, umode
);
339 v9fs_stat2inode(st
, ret
, sb
);
340 ret
->i_ino
= v9fs_qid2ino(&st
->qid
);
353 * v9fs_remove - helper function to remove files and directories
354 * @dir: directory inode that is being deleted
355 * @file: dentry that is being deleted
356 * @rmdir: removing a directory
360 static int v9fs_remove(struct inode
*dir
, struct dentry
*file
, int rmdir
)
362 struct inode
*file_inode
;
363 struct v9fs_session_info
*v9ses
;
364 struct p9_fid
*v9fid
;
366 P9_DPRINTK(P9_DEBUG_VFS
, "inode: %p dentry: %p rmdir: %d\n", dir
, file
,
369 file_inode
= file
->d_inode
;
370 v9ses
= v9fs_inode2v9ses(file_inode
);
371 v9fid
= v9fs_fid_clone(file
);
373 return PTR_ERR(v9fid
);
375 return p9_client_remove(v9fid
);
379 v9fs_open_created(struct inode
*inode
, struct file
*file
)
386 * v9fs_create - Create a file
387 * @dentry: dentry that is being created
388 * @perm: create permissions
392 static struct p9_fid
*
393 v9fs_create(struct v9fs_session_info
*v9ses
, struct inode
*dir
,
394 struct dentry
*dentry
, char *extension
, u32 perm
, u8 mode
)
398 struct p9_fid
*dfid
, *ofid
, *fid
;
404 name
= (char *) dentry
->d_name
.name
;
405 dfid
= v9fs_fid_clone(dentry
->d_parent
);
412 /* clone a fid to use for creation */
413 ofid
= p9_client_walk(dfid
, 0, NULL
, 1);
420 err
= p9_client_fcreate(ofid
, name
, perm
, mode
, extension
);
424 /* now walk from the parent so we can get unopened fid */
425 fid
= p9_client_walk(dfid
, 1, &name
, 0);
433 /* instantiate inode and assign the unopened fid to the dentry */
434 inode
= v9fs_inode_from_fid(v9ses
, fid
, dir
->i_sb
);
436 err
= PTR_ERR(inode
);
441 dentry
->d_op
= &v9fs_cached_dentry_operations
;
443 dentry
->d_op
= &v9fs_dentry_operations
;
445 d_instantiate(dentry
, inode
);
446 v9fs_fid_add(dentry
, fid
);
451 p9_client_clunk(dfid
);
454 p9_client_clunk(ofid
);
457 p9_client_clunk(fid
);
463 * v9fs_vfs_create - VFS hook to create files
464 * @inode: directory inode that is being created
465 * @dentry: dentry that is being deleted
466 * @mode: create permissions
467 * @nd: path information
472 v9fs_vfs_create(struct inode
*dir
, struct dentry
*dentry
, int mode
,
473 struct nameidata
*nd
)
478 struct v9fs_session_info
*v9ses
;
484 v9ses
= v9fs_inode2v9ses(dir
);
485 perm
= unixmode2p9mode(v9ses
, mode
);
486 if (nd
&& nd
->flags
& LOOKUP_OPEN
)
487 flags
= nd
->intent
.open
.flags
- 1;
491 fid
= v9fs_create(v9ses
, dir
, dentry
, NULL
, perm
,
492 v9fs_uflags2omode(flags
));
499 /* if we are opening a file, assign the open fid to the file */
500 if (nd
&& nd
->flags
& LOOKUP_OPEN
) {
501 filp
= lookup_instantiate_filp(nd
, dentry
, v9fs_open_created
);
507 filp
->private_data
= fid
;
509 p9_client_clunk(fid
);
515 p9_client_clunk(fid
);
521 * v9fs_vfs_mkdir - VFS mkdir hook to create a directory
522 * @inode: inode that is being unlinked
523 * @dentry: dentry that is being unlinked
524 * @mode: mode for new directory
528 static int v9fs_vfs_mkdir(struct inode
*dir
, struct dentry
*dentry
, int mode
)
532 struct v9fs_session_info
*v9ses
;
535 P9_DPRINTK(P9_DEBUG_VFS
, "name %s\n", dentry
->d_name
.name
);
537 v9ses
= v9fs_inode2v9ses(dir
);
538 perm
= unixmode2p9mode(v9ses
, mode
| S_IFDIR
);
539 fid
= v9fs_create(v9ses
, dir
, dentry
, NULL
, perm
, P9_OREAD
);
546 p9_client_clunk(fid
);
552 * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode
553 * @dir: inode that is being walked from
554 * @dentry: dentry that is being walked to?
555 * @nameidata: path data
559 static struct dentry
*v9fs_vfs_lookup(struct inode
*dir
, struct dentry
*dentry
,
560 struct nameidata
*nameidata
)
562 struct super_block
*sb
;
563 struct v9fs_session_info
*v9ses
;
564 struct p9_fid
*dfid
, *fid
;
569 P9_DPRINTK(P9_DEBUG_VFS
, "dir: %p dentry: (%s) %p nameidata: %p\n",
570 dir
, dentry
->d_name
.name
, dentry
, nameidata
);
573 v9ses
= v9fs_inode2v9ses(dir
);
574 dfid
= v9fs_fid_lookup(dentry
->d_parent
);
576 return ERR_CAST(dfid
);
578 name
= (char *) dentry
->d_name
.name
;
579 fid
= p9_client_walk(dfid
, 1, &name
, 1);
581 result
= PTR_ERR(fid
);
582 if (result
== -ENOENT
) {
587 return ERR_PTR(result
);
590 inode
= v9fs_inode_from_fid(v9ses
, fid
, dir
->i_sb
);
592 result
= PTR_ERR(inode
);
597 result
= v9fs_fid_add(dentry
, fid
);
601 if ((fid
->qid
.version
) && (v9ses
->cache
))
602 dentry
->d_op
= &v9fs_cached_dentry_operations
;
604 dentry
->d_op
= &v9fs_dentry_operations
;
606 d_add(dentry
, inode
);
611 p9_client_clunk(fid
);
613 return ERR_PTR(result
);
617 * v9fs_vfs_unlink - VFS unlink hook to delete an inode
618 * @i: inode that is being unlinked
619 * @d: dentry that is being unlinked
623 static int v9fs_vfs_unlink(struct inode
*i
, struct dentry
*d
)
625 return v9fs_remove(i
, d
, 0);
629 * v9fs_vfs_rmdir - VFS unlink hook to delete a directory
630 * @i: inode that is being unlinked
631 * @d: dentry that is being unlinked
635 static int v9fs_vfs_rmdir(struct inode
*i
, struct dentry
*d
)
637 return v9fs_remove(i
, d
, 1);
641 * v9fs_vfs_rename - VFS hook to rename an inode
642 * @old_dir: old dir inode
643 * @old_dentry: old dentry
644 * @new_dir: new dir inode
645 * @new_dentry: new dentry
650 v9fs_vfs_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
651 struct inode
*new_dir
, struct dentry
*new_dentry
)
653 struct inode
*old_inode
;
654 struct v9fs_session_info
*v9ses
;
655 struct p9_fid
*oldfid
;
656 struct p9_fid
*olddirfid
;
657 struct p9_fid
*newdirfid
;
658 struct p9_wstat wstat
;
661 P9_DPRINTK(P9_DEBUG_VFS
, "\n");
663 old_inode
= old_dentry
->d_inode
;
664 v9ses
= v9fs_inode2v9ses(old_inode
);
665 oldfid
= v9fs_fid_lookup(old_dentry
);
667 return PTR_ERR(oldfid
);
669 olddirfid
= v9fs_fid_clone(old_dentry
->d_parent
);
670 if (IS_ERR(olddirfid
)) {
671 retval
= PTR_ERR(olddirfid
);
675 newdirfid
= v9fs_fid_clone(new_dentry
->d_parent
);
676 if (IS_ERR(newdirfid
)) {
677 retval
= PTR_ERR(newdirfid
);
681 /* 9P can only handle file rename in the same directory */
682 if (memcmp(&olddirfid
->qid
, &newdirfid
->qid
, sizeof(newdirfid
->qid
))) {
683 P9_DPRINTK(P9_DEBUG_ERROR
,
684 "old dir and new dir are different\n");
689 v9fs_blank_wstat(&wstat
);
690 wstat
.muid
= v9ses
->uname
;
691 wstat
.name
= (char *) new_dentry
->d_name
.name
;
692 retval
= p9_client_wstat(oldfid
, &wstat
);
695 p9_client_clunk(newdirfid
);
698 p9_client_clunk(olddirfid
);
705 * v9fs_vfs_getattr - retrieve file metadata
706 * @mnt - mount information
707 * @dentry - file to get attributes on
708 * @stat - metadata structure to populate
713 v9fs_vfs_getattr(struct vfsmount
*mnt
, struct dentry
*dentry
,
717 struct v9fs_session_info
*v9ses
;
721 P9_DPRINTK(P9_DEBUG_VFS
, "dentry: %p\n", dentry
);
723 v9ses
= v9fs_inode2v9ses(dentry
->d_inode
);
724 if (v9ses
->cache
== CACHE_LOOSE
)
725 return simple_getattr(mnt
, dentry
, stat
);
727 fid
= v9fs_fid_lookup(dentry
);
731 st
= p9_client_stat(fid
);
735 v9fs_stat2inode(st
, dentry
->d_inode
, dentry
->d_inode
->i_sb
);
736 generic_fillattr(dentry
->d_inode
, stat
);
743 * v9fs_vfs_setattr - set file metadata
744 * @dentry: file whose metadata to set
745 * @iattr: metadata assignment structure
749 static int v9fs_vfs_setattr(struct dentry
*dentry
, struct iattr
*iattr
)
752 struct v9fs_session_info
*v9ses
;
754 struct p9_wstat wstat
;
756 P9_DPRINTK(P9_DEBUG_VFS
, "\n");
758 v9ses
= v9fs_inode2v9ses(dentry
->d_inode
);
759 fid
= v9fs_fid_lookup(dentry
);
763 v9fs_blank_wstat(&wstat
);
764 if (iattr
->ia_valid
& ATTR_MODE
)
765 wstat
.mode
= unixmode2p9mode(v9ses
, iattr
->ia_mode
);
767 if (iattr
->ia_valid
& ATTR_MTIME
)
768 wstat
.mtime
= iattr
->ia_mtime
.tv_sec
;
770 if (iattr
->ia_valid
& ATTR_ATIME
)
771 wstat
.atime
= iattr
->ia_atime
.tv_sec
;
773 if (iattr
->ia_valid
& ATTR_SIZE
)
774 wstat
.length
= iattr
->ia_size
;
776 if (v9fs_extended(v9ses
)) {
777 if (iattr
->ia_valid
& ATTR_UID
)
778 wstat
.n_uid
= iattr
->ia_uid
;
780 if (iattr
->ia_valid
& ATTR_GID
)
781 wstat
.n_gid
= iattr
->ia_gid
;
784 retval
= p9_client_wstat(fid
, &wstat
);
786 retval
= inode_setattr(dentry
->d_inode
, iattr
);
792 * v9fs_stat2inode - populate an inode structure with mistat info
793 * @stat: Plan 9 metadata (mistat) structure
794 * @inode: inode to populate
795 * @sb: superblock of filesystem
800 v9fs_stat2inode(struct p9_stat
*stat
, struct inode
*inode
,
801 struct super_block
*sb
)
805 struct v9fs_session_info
*v9ses
= sb
->s_fs_info
;
809 inode
->i_atime
.tv_sec
= stat
->atime
;
810 inode
->i_mtime
.tv_sec
= stat
->mtime
;
811 inode
->i_ctime
.tv_sec
= stat
->mtime
;
813 inode
->i_uid
= v9ses
->dfltuid
;
814 inode
->i_gid
= v9ses
->dfltgid
;
816 if (v9fs_extended(v9ses
)) {
817 inode
->i_uid
= stat
->n_uid
;
818 inode
->i_gid
= stat
->n_gid
;
821 inode
->i_mode
= p9mode2unixmode(v9ses
, stat
->mode
);
822 if ((S_ISBLK(inode
->i_mode
)) || (S_ISCHR(inode
->i_mode
))) {
827 n
= stat
->extension
.len
;
828 if (n
> sizeof(ext
)-1)
830 memmove(ext
, stat
->extension
.str
, n
);
832 sscanf(ext
, "%c %u %u", &type
, &major
, &minor
);
835 inode
->i_mode
&= ~S_IFBLK
;
836 inode
->i_mode
|= S_IFCHR
;
841 P9_DPRINTK(P9_DEBUG_ERROR
,
842 "Unknown special type %c (%.*s)\n", type
,
843 stat
->extension
.len
, stat
->extension
.str
);
845 inode
->i_rdev
= MKDEV(major
, minor
);
849 inode
->i_size
= stat
->length
;
851 /* not real number of blocks, but 512 byte ones ... */
852 inode
->i_blocks
= (inode
->i_size
+ 512 - 1) >> 9;
856 * v9fs_qid2ino - convert qid into inode number
859 * BUG: potential for inode number collisions?
862 ino_t
v9fs_qid2ino(struct p9_qid
*qid
)
864 u64 path
= qid
->path
+ 2;
867 if (sizeof(ino_t
) == sizeof(path
))
868 memcpy(&i
, &path
, sizeof(ino_t
));
870 i
= (ino_t
) (path
^ (path
>> 32));
876 * v9fs_readlink - read a symlink's location (internal version)
877 * @dentry: dentry for symlink
878 * @buffer: buffer to load symlink location into
879 * @buflen: length of buffer
883 static int v9fs_readlink(struct dentry
*dentry
, char *buffer
, int buflen
)
887 struct v9fs_session_info
*v9ses
;
891 P9_DPRINTK(P9_DEBUG_VFS
, " %s\n", dentry
->d_name
.name
);
893 v9ses
= v9fs_inode2v9ses(dentry
->d_inode
);
894 fid
= v9fs_fid_lookup(dentry
);
898 if (!v9fs_extended(v9ses
))
901 st
= p9_client_stat(fid
);
905 if (!(st
->mode
& P9_DMSYMLINK
)) {
910 /* copy extension buffer into buffer */
911 if (st
->extension
.len
< buflen
)
912 buflen
= st
->extension
.len
+ 1;
914 memmove(buffer
, st
->extension
.str
, buflen
- 1);
915 buffer
[buflen
-1] = 0;
917 P9_DPRINTK(P9_DEBUG_VFS
,
918 "%s -> %.*s (%s)\n", dentry
->d_name
.name
, st
->extension
.len
,
919 st
->extension
.str
, buffer
);
929 * v9fs_vfs_readlink - read a symlink's location
930 * @dentry: dentry for symlink
931 * @buf: buffer to load symlink location into
932 * @buflen: length of buffer
936 static int v9fs_vfs_readlink(struct dentry
*dentry
, char __user
* buffer
,
941 char *link
= __getname();
946 if (buflen
> PATH_MAX
)
949 P9_DPRINTK(P9_DEBUG_VFS
, " dentry: %s (%p)\n", dentry
->d_iname
, dentry
);
951 retval
= v9fs_readlink(dentry
, link
, buflen
);
954 if ((ret
= copy_to_user(buffer
, link
, retval
)) != 0) {
955 P9_DPRINTK(P9_DEBUG_ERROR
,
956 "problem copying to user: %d\n", ret
);
966 * v9fs_vfs_follow_link - follow a symlink path
967 * @dentry: dentry for symlink
972 static void *v9fs_vfs_follow_link(struct dentry
*dentry
, struct nameidata
*nd
)
975 char *link
= __getname();
977 P9_DPRINTK(P9_DEBUG_VFS
, "%s n", dentry
->d_name
.name
);
980 link
= ERR_PTR(-ENOMEM
);
982 len
= v9fs_readlink(dentry
, link
, PATH_MAX
);
990 nd_set_link(nd
, link
);
996 * v9fs_vfs_put_link - release a symlink path
997 * @dentry: dentry for symlink
1002 static void v9fs_vfs_put_link(struct dentry
*dentry
, struct nameidata
*nd
, void *p
)
1004 char *s
= nd_get_link(nd
);
1006 P9_DPRINTK(P9_DEBUG_VFS
, " %s %s\n", dentry
->d_name
.name
, s
);
1011 static int v9fs_vfs_mkspecial(struct inode
*dir
, struct dentry
*dentry
,
1012 int mode
, const char *extension
)
1015 struct v9fs_session_info
*v9ses
;
1018 v9ses
= v9fs_inode2v9ses(dir
);
1019 if (!v9fs_extended(v9ses
)) {
1020 P9_DPRINTK(P9_DEBUG_ERROR
, "not extended\n");
1024 perm
= unixmode2p9mode(v9ses
, mode
);
1025 fid
= v9fs_create(v9ses
, dir
, dentry
, (char *) extension
, perm
,
1028 return PTR_ERR(fid
);
1030 p9_client_clunk(fid
);
1035 * v9fs_vfs_symlink - helper function to create symlinks
1036 * @dir: directory inode containing symlink
1037 * @dentry: dentry for symlink
1038 * @symname: symlink data
1040 * See 9P2000.u RFC for more information
1045 v9fs_vfs_symlink(struct inode
*dir
, struct dentry
*dentry
, const char *symname
)
1047 P9_DPRINTK(P9_DEBUG_VFS
, " %lu,%s,%s\n", dir
->i_ino
,
1048 dentry
->d_name
.name
, symname
);
1050 return v9fs_vfs_mkspecial(dir
, dentry
, S_IFLNK
, symname
);
1054 * v9fs_vfs_link - create a hardlink
1055 * @old_dentry: dentry for file to link to
1056 * @dir: inode destination for new link
1057 * @dentry: dentry for link
1061 /* XXX - lots of code dup'd from symlink and creates,
1062 * figure out a better reuse strategy
1066 v9fs_vfs_link(struct dentry
*old_dentry
, struct inode
*dir
,
1067 struct dentry
*dentry
)
1070 struct p9_fid
*oldfid
;
1073 P9_DPRINTK(P9_DEBUG_VFS
,
1074 " %lu,%s,%s\n", dir
->i_ino
, dentry
->d_name
.name
,
1075 old_dentry
->d_name
.name
);
1077 oldfid
= v9fs_fid_clone(old_dentry
);
1079 return PTR_ERR(oldfid
);
1082 if (unlikely(!name
)) {
1087 sprintf(name
, "%d\n", oldfid
->fid
);
1088 retval
= v9fs_vfs_mkspecial(dir
, dentry
, P9_DMLINK
, name
);
1092 p9_client_clunk(oldfid
);
1097 * v9fs_vfs_mknod - create a special file
1098 * @dir: inode destination for new link
1099 * @dentry: dentry for file
1100 * @mode: mode for creation
1101 * @dev_t: device associated with special file
1106 v9fs_vfs_mknod(struct inode
*dir
, struct dentry
*dentry
, int mode
, dev_t rdev
)
1111 P9_DPRINTK(P9_DEBUG_VFS
,
1112 " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir
->i_ino
,
1113 dentry
->d_name
.name
, mode
, MAJOR(rdev
), MINOR(rdev
));
1115 if (!new_valid_dev(rdev
))
1121 /* build extension */
1123 sprintf(name
, "b %u %u", MAJOR(rdev
), MINOR(rdev
));
1124 else if (S_ISCHR(mode
))
1125 sprintf(name
, "c %u %u", MAJOR(rdev
), MINOR(rdev
));
1126 else if (S_ISFIFO(mode
))
1133 retval
= v9fs_vfs_mkspecial(dir
, dentry
, mode
, name
);
1139 static const struct inode_operations v9fs_dir_inode_operations_ext
= {
1140 .create
= v9fs_vfs_create
,
1141 .lookup
= v9fs_vfs_lookup
,
1142 .symlink
= v9fs_vfs_symlink
,
1143 .link
= v9fs_vfs_link
,
1144 .unlink
= v9fs_vfs_unlink
,
1145 .mkdir
= v9fs_vfs_mkdir
,
1146 .rmdir
= v9fs_vfs_rmdir
,
1147 .mknod
= v9fs_vfs_mknod
,
1148 .rename
= v9fs_vfs_rename
,
1149 .readlink
= v9fs_vfs_readlink
,
1150 .getattr
= v9fs_vfs_getattr
,
1151 .setattr
= v9fs_vfs_setattr
,
1154 static const struct inode_operations v9fs_dir_inode_operations
= {
1155 .create
= v9fs_vfs_create
,
1156 .lookup
= v9fs_vfs_lookup
,
1157 .unlink
= v9fs_vfs_unlink
,
1158 .mkdir
= v9fs_vfs_mkdir
,
1159 .rmdir
= v9fs_vfs_rmdir
,
1160 .mknod
= v9fs_vfs_mknod
,
1161 .rename
= v9fs_vfs_rename
,
1162 .getattr
= v9fs_vfs_getattr
,
1163 .setattr
= v9fs_vfs_setattr
,
1166 static const struct inode_operations v9fs_file_inode_operations
= {
1167 .getattr
= v9fs_vfs_getattr
,
1168 .setattr
= v9fs_vfs_setattr
,
1171 static const struct inode_operations v9fs_symlink_inode_operations
= {
1172 .readlink
= v9fs_vfs_readlink
,
1173 .follow_link
= v9fs_vfs_follow_link
,
1174 .put_link
= v9fs_vfs_put_link
,
1175 .getattr
= v9fs_vfs_getattr
,
1176 .setattr
= v9fs_vfs_setattr
,