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 as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to:
21 * Free Software Foundation
22 * 51 Franklin Street, Fifth Floor
23 * Boston, MA 02111-1301 USA
27 #include <linux/module.h>
28 #include <linux/errno.h>
30 #include <linux/file.h>
31 #include <linux/pagemap.h>
32 #include <linux/stat.h>
33 #include <linux/string.h>
34 #include <linux/smp_lock.h>
35 #include <linux/inet.h>
36 #include <linux/namei.h>
37 #include <linux/idr.h>
45 static struct inode_operations v9fs_dir_inode_operations
;
46 static struct inode_operations v9fs_dir_inode_operations_ext
;
47 static struct inode_operations v9fs_file_inode_operations
;
48 static struct inode_operations v9fs_symlink_inode_operations
;
51 * unixmode2p9mode - convert unix mode bits to plan 9
52 * @v9ses: v9fs session information
53 * @mode: mode to convert
57 static int unixmode2p9mode(struct v9fs_session_info
*v9ses
, int mode
)
63 if (v9ses
->extended
) {
65 res
|= V9FS_DMSYMLINK
;
66 if (v9ses
->nodev
== 0) {
70 res
|= V9FS_DMNAMEDPIPE
;
77 if ((mode
& S_ISUID
) == S_ISUID
)
79 if ((mode
& S_ISGID
) == S_ISGID
)
81 if ((mode
& V9FS_DMLINK
))
89 * p9mode2unixmode- convert plan9 mode bits to unix mode bits
90 * @v9ses: v9fs session information
91 * @mode: mode to convert
95 static int p9mode2unixmode(struct v9fs_session_info
*v9ses
, int mode
)
101 if ((mode
& V9FS_DMDIR
) == V9FS_DMDIR
)
103 else if ((mode
& V9FS_DMSYMLINK
) && (v9ses
->extended
))
105 else if ((mode
& V9FS_DMSOCKET
) && (v9ses
->extended
)
106 && (v9ses
->nodev
== 0))
108 else if ((mode
& V9FS_DMNAMEDPIPE
) && (v9ses
->extended
)
109 && (v9ses
->nodev
== 0))
111 else if ((mode
& V9FS_DMDEVICE
) && (v9ses
->extended
)
112 && (v9ses
->nodev
== 0))
117 if (v9ses
->extended
) {
118 if ((mode
& V9FS_DMSETUID
) == V9FS_DMSETUID
)
121 if ((mode
& V9FS_DMSETGID
) == V9FS_DMSETGID
)
129 * v9fs_blank_wstat - helper function to setup a 9P stat structure
130 * @v9ses: 9P session info (for determining extended mode)
131 * @wstat: structure to initialize
136 v9fs_blank_wstat(struct v9fs_wstat
*wstat
)
140 wstat
->qid
.type
= ~0;
141 wstat
->qid
.version
= ~0;
142 *((long long *)&wstat
->qid
.path
) = ~0;
154 wstat
->extension
= NULL
;
158 * v9fs_get_inode - helper function to setup an inode
160 * @mode: mode to setup inode with
164 struct inode
*v9fs_get_inode(struct super_block
*sb
, int mode
)
166 struct inode
*inode
= NULL
;
167 struct v9fs_session_info
*v9ses
= sb
->s_fs_info
;
169 dprintk(DEBUG_VFS
, "super block: %p mode: %o\n", sb
, mode
);
171 inode
= new_inode(sb
);
173 inode
->i_mode
= mode
;
174 inode
->i_uid
= current
->fsuid
;
175 inode
->i_gid
= current
->fsgid
;
176 inode
->i_blksize
= sb
->s_blocksize
;
179 inode
->i_atime
= inode
->i_mtime
= inode
->i_ctime
= CURRENT_TIME
;
181 switch (mode
& S_IFMT
) {
186 if(!v9ses
->extended
) {
187 dprintk(DEBUG_ERROR
, "special files without extended mode\n");
188 return ERR_PTR(-EINVAL
);
190 init_special_inode(inode
, inode
->i_mode
,
194 inode
->i_op
= &v9fs_file_inode_operations
;
195 inode
->i_fop
= &v9fs_file_operations
;
198 if(!v9ses
->extended
) {
199 dprintk(DEBUG_ERROR
, "extended modes used w/o 9P2000.u\n");
200 return ERR_PTR(-EINVAL
);
202 inode
->i_op
= &v9fs_symlink_inode_operations
;
207 inode
->i_op
= &v9fs_dir_inode_operations_ext
;
209 inode
->i_op
= &v9fs_dir_inode_operations
;
210 inode
->i_fop
= &v9fs_dir_operations
;
213 dprintk(DEBUG_ERROR
, "BAD mode 0x%x S_IFMT 0x%x\n",
214 mode
, mode
& S_IFMT
);
215 return ERR_PTR(-EINVAL
);
218 eprintk(KERN_WARNING
, "Problem allocating inode\n");
219 return ERR_PTR(-ENOMEM
);
225 * v9fs_create - helper function to create files and directories
226 * @dir: directory inode file is being created in
227 * @file_dentry: dentry file is being created in
228 * @perm: permissions file is being created with
229 * @open_mode: resulting open mode for file
234 v9fs_create(struct inode
*dir
,
235 struct dentry
*file_dentry
,
236 unsigned int perm
, unsigned int open_mode
)
238 struct v9fs_session_info
*v9ses
= v9fs_inode2v9ses(dir
);
239 struct super_block
*sb
= dir
->i_sb
;
240 struct v9fs_fid
*dirfid
=
241 v9fs_fid_lookup(file_dentry
->d_parent
);
242 struct v9fs_fid
*fid
= NULL
;
243 struct inode
*file_inode
= NULL
;
244 struct v9fs_fcall
*fcall
= NULL
;
249 unsigned int iounit
= 0;
253 perm
= unixmode2p9mode(v9ses
, perm
);
255 dprintk(DEBUG_VFS
, "dir: %p dentry: %p perm: %o mode: %o\n", dir
,
256 file_dentry
, perm
, open_mode
);
261 dirfidnum
= dirfid
->fid
;
263 dprintk(DEBUG_ERROR
, "No fid for the directory #%lu\n",
268 if (file_dentry
->d_inode
) {
270 "Odd. There is an inode for dir %lu, name :%s:\n",
271 dir
->i_ino
, file_dentry
->d_name
.name
);
275 newfid
= v9fs_get_idpool(&v9ses
->fidpool
);
277 eprintk(KERN_WARNING
, "no free fids available\n");
281 result
= v9fs_t_walk(v9ses
, dirfidnum
, newfid
, NULL
, &fcall
);
283 PRINT_FCALL_ERROR("clone error", fcall
);
284 v9fs_put_idpool(newfid
, &v9ses
->fidpool
);
292 result
= v9fs_t_create(v9ses
, newfid
, (char *)file_dentry
->d_name
.name
,
293 perm
, open_mode
, &fcall
);
295 PRINT_FCALL_ERROR("create fails", fcall
);
299 iounit
= fcall
->params
.rcreate
.iounit
;
300 qid
= fcall
->params
.rcreate
.qid
;
304 if (!(perm
&V9FS_DMDIR
)) {
305 fid
= v9fs_fid_create(file_dentry
, v9ses
, newfid
, 1);
306 dprintk(DEBUG_VFS
, "fid %p %d\n", fid
, fid
->fidcreate
);
313 fid
->iounit
= iounit
;
315 err
= v9fs_t_clunk(v9ses
, newfid
);
318 dprintk(DEBUG_ERROR
, "clunk for mkdir failed: %d\n", err
);
321 /* walk to the newly created file and put the fid in the dentry */
322 wfidno
= v9fs_get_idpool(&v9ses
->fidpool
);
324 eprintk(KERN_WARNING
, "no free fids available\n");
328 result
= v9fs_t_walk(v9ses
, dirfidnum
, wfidno
,
329 (char *) file_dentry
->d_name
.name
, &fcall
);
331 PRINT_FCALL_ERROR("clone error", fcall
);
332 v9fs_put_idpool(wfidno
, &v9ses
->fidpool
);
339 if (!v9fs_fid_create(file_dentry
, v9ses
, wfidno
, 0)) {
340 v9fs_put_idpool(wfidno
, &v9ses
->fidpool
);
345 if ((perm
& V9FS_DMSYMLINK
) || (perm
& V9FS_DMLINK
) ||
346 (perm
& V9FS_DMNAMEDPIPE
) || (perm
& V9FS_DMSOCKET
) ||
347 (perm
& V9FS_DMDEVICE
))
350 result
= v9fs_t_stat(v9ses
, wfidno
, &fcall
);
352 PRINT_FCALL_ERROR("stat error", fcall
);
357 file_inode
= v9fs_get_inode(sb
,
358 p9mode2unixmode(v9ses
, fcall
->params
.rstat
.stat
.mode
));
360 if ((!file_inode
) || IS_ERR(file_inode
)) {
361 dprintk(DEBUG_ERROR
, "create inode failed\n");
366 v9fs_stat2inode(&fcall
->params
.rstat
.stat
, file_inode
, sb
);
369 file_dentry
->d_op
= &v9fs_dentry_operations
;
370 d_instantiate(file_dentry
, file_inode
);
379 err
= v9fs_t_clunk(v9ses
, newfid
);
381 dprintk(DEBUG_ERROR
, "clunk failed: %d\n", err
);
384 err
= v9fs_t_clunk(v9ses
, wfidno
);
386 dprintk(DEBUG_ERROR
, "clunk failed: %d\n", err
);
392 * v9fs_remove - helper function to remove files and directories
393 * @dir: directory inode that is being deleted
394 * @file: dentry that is being deleted
395 * @rmdir: removing a directory
399 static int v9fs_remove(struct inode
*dir
, struct dentry
*file
, int rmdir
)
401 struct v9fs_fcall
*fcall
= NULL
;
402 struct super_block
*sb
= NULL
;
403 struct v9fs_session_info
*v9ses
= NULL
;
404 struct v9fs_fid
*v9fid
= NULL
;
405 struct inode
*file_inode
= NULL
;
409 dprintk(DEBUG_VFS
, "inode: %p dentry: %p rmdir: %d\n", dir
, file
,
412 file_inode
= file
->d_inode
;
413 sb
= file_inode
->i_sb
;
414 v9ses
= v9fs_inode2v9ses(file_inode
);
415 v9fid
= v9fs_fid_lookup(file
);
425 dprintk(DEBUG_ERROR
, "inode #%lu, no fid!\n",
430 result
= v9fs_t_remove(v9ses
, fid
, &fcall
);
432 PRINT_FCALL_ERROR("remove fails", fcall
);
434 v9fs_put_idpool(fid
, &v9ses
->fidpool
);
435 v9fs_fid_destroy(v9fid
);
443 * v9fs_vfs_create - VFS hook to create files
444 * @inode: directory inode that is being deleted
445 * @dentry: dentry that is being deleted
446 * @perm: create permissions
447 * @nd: path information
452 v9fs_vfs_create(struct inode
*inode
, struct dentry
*dentry
, int perm
,
453 struct nameidata
*nd
)
455 return v9fs_create(inode
, dentry
, perm
, O_RDWR
);
459 * v9fs_vfs_mkdir - VFS mkdir hook to create a directory
460 * @inode: inode that is being unlinked
461 * @dentry: dentry that is being unlinked
462 * @mode: mode for new directory
466 static int v9fs_vfs_mkdir(struct inode
*inode
, struct dentry
*dentry
, int mode
)
468 return v9fs_create(inode
, dentry
, mode
| S_IFDIR
, O_RDONLY
);
472 * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode
473 * @dir: inode that is being walked from
474 * @dentry: dentry that is being walked to?
475 * @nameidata: path data
479 static struct dentry
*v9fs_vfs_lookup(struct inode
*dir
, struct dentry
*dentry
,
480 struct nameidata
*nameidata
)
482 struct super_block
*sb
;
483 struct v9fs_session_info
*v9ses
;
484 struct v9fs_fid
*dirfid
;
485 struct v9fs_fid
*fid
;
487 struct v9fs_fcall
*fcall
= NULL
;
492 dprintk(DEBUG_VFS
, "dir: %p dentry: (%s) %p nameidata: %p\n",
493 dir
, dentry
->d_iname
, dentry
, nameidata
);
496 v9ses
= v9fs_inode2v9ses(dir
);
497 dirfid
= v9fs_fid_lookup(dentry
->d_parent
);
500 dprintk(DEBUG_ERROR
, "no dirfid\n");
501 return ERR_PTR(-EINVAL
);
504 dirfidnum
= dirfid
->fid
;
507 dprintk(DEBUG_ERROR
, "no dirfid for inode %p, #%lu\n",
509 return ERR_PTR(-EBADF
);
512 newfid
= v9fs_get_idpool(&v9ses
->fidpool
);
514 eprintk(KERN_WARNING
, "newfid fails!\n");
515 return ERR_PTR(-ENOSPC
);
519 v9fs_t_walk(v9ses
, dirfidnum
, newfid
, (char *)dentry
->d_name
.name
,
522 v9fs_put_idpool(newfid
, &v9ses
->fidpool
);
523 if (result
== -ENOENT
) {
526 "Return negative dentry %p count %d\n",
527 dentry
, atomic_read(&dentry
->d_count
));
530 dprintk(DEBUG_ERROR
, "walk error:%d\n", result
);
534 result
= v9fs_t_stat(v9ses
, newfid
, &fcall
);
536 dprintk(DEBUG_ERROR
, "stat error\n");
540 inode
= v9fs_get_inode(sb
, p9mode2unixmode(v9ses
,
541 fcall
->params
.rstat
.stat
.mode
));
543 if (IS_ERR(inode
) && (PTR_ERR(inode
) == -ENOSPC
)) {
544 eprintk(KERN_WARNING
, "inode alloc failes, returns %ld\n",
551 inode
->i_ino
= v9fs_qid2ino(&fcall
->params
.rstat
.stat
.qid
);
553 fid
= v9fs_fid_create(dentry
, v9ses
, newfid
, 0);
555 dprintk(DEBUG_ERROR
, "couldn't insert\n");
560 fid
->qid
= fcall
->params
.rstat
.stat
.qid
;
562 dentry
->d_op
= &v9fs_dentry_operations
;
563 v9fs_stat2inode(&fcall
->params
.rstat
.stat
, inode
, inode
->i_sb
);
565 d_add(dentry
, inode
);
572 return ERR_PTR(result
);
576 * v9fs_vfs_unlink - VFS unlink hook to delete an inode
577 * @i: inode that is being unlinked
578 * @d: dentry that is being unlinked
582 static int v9fs_vfs_unlink(struct inode
*i
, struct dentry
*d
)
584 return v9fs_remove(i
, d
, 0);
588 * v9fs_vfs_rmdir - VFS unlink hook to delete a directory
589 * @i: inode that is being unlinked
590 * @d: dentry that is being unlinked
594 static int v9fs_vfs_rmdir(struct inode
*i
, struct dentry
*d
)
596 return v9fs_remove(i
, d
, 1);
600 * v9fs_vfs_rename - VFS hook to rename an inode
601 * @old_dir: old dir inode
602 * @old_dentry: old dentry
603 * @new_dir: new dir inode
604 * @new_dentry: new dentry
609 v9fs_vfs_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
610 struct inode
*new_dir
, struct dentry
*new_dentry
)
612 struct inode
*old_inode
= old_dentry
->d_inode
;
613 struct v9fs_session_info
*v9ses
= v9fs_inode2v9ses(old_inode
);
614 struct v9fs_fid
*oldfid
= v9fs_fid_lookup(old_dentry
);
615 struct v9fs_fid
*olddirfid
=
616 v9fs_fid_lookup(old_dentry
->d_parent
);
617 struct v9fs_fid
*newdirfid
=
618 v9fs_fid_lookup(new_dentry
->d_parent
);
619 struct v9fs_wstat wstat
;
620 struct v9fs_fcall
*fcall
= NULL
;
622 int olddirfidnum
= -1;
623 int newdirfidnum
= -1;
626 dprintk(DEBUG_VFS
, "\n");
628 if ((!oldfid
) || (!olddirfid
) || (!newdirfid
)) {
629 dprintk(DEBUG_ERROR
, "problem with arguments\n");
633 /* 9P can only handle file rename in the same directory */
634 if (memcmp(&olddirfid
->qid
, &newdirfid
->qid
, sizeof(newdirfid
->qid
))) {
635 dprintk(DEBUG_ERROR
, "old dir and new dir are different\n");
641 olddirfidnum
= olddirfid
->fid
;
642 newdirfidnum
= newdirfid
->fid
;
645 dprintk(DEBUG_ERROR
, "no fid for old file #%lu\n",
651 v9fs_blank_wstat(&wstat
);
652 wstat
.muid
= v9ses
->name
;
653 wstat
.name
= (char *) new_dentry
->d_name
.name
;
655 retval
= v9fs_t_wstat(v9ses
, fid
, &wstat
, &fcall
);
659 PRINT_FCALL_ERROR("wstat error", fcall
);
666 * v9fs_vfs_getattr - retrieve file metadata
667 * @mnt - mount information
668 * @dentry - file to get attributes on
669 * @stat - metadata structure to populate
674 v9fs_vfs_getattr(struct vfsmount
*mnt
, struct dentry
*dentry
,
677 struct v9fs_fcall
*fcall
= NULL
;
678 struct v9fs_session_info
*v9ses
= v9fs_inode2v9ses(dentry
->d_inode
);
679 struct v9fs_fid
*fid
= v9fs_fid_lookup(dentry
);
682 dprintk(DEBUG_VFS
, "dentry: %p\n", dentry
);
685 "couldn't find fid associated with dentry\n");
689 err
= v9fs_t_stat(v9ses
, fid
->fid
, &fcall
);
692 dprintk(DEBUG_ERROR
, "stat error\n");
694 v9fs_stat2inode(&fcall
->params
.rstat
.stat
, dentry
->d_inode
,
695 dentry
->d_inode
->i_sb
);
696 generic_fillattr(dentry
->d_inode
, stat
);
704 * v9fs_vfs_setattr - set file metadata
705 * @dentry: file whose metadata to set
706 * @iattr: metadata assignment structure
710 static int v9fs_vfs_setattr(struct dentry
*dentry
, struct iattr
*iattr
)
712 struct v9fs_session_info
*v9ses
= v9fs_inode2v9ses(dentry
->d_inode
);
713 struct v9fs_fid
*fid
= v9fs_fid_lookup(dentry
);
714 struct v9fs_fcall
*fcall
= NULL
;
715 struct v9fs_wstat wstat
;
718 dprintk(DEBUG_VFS
, "\n");
722 "Couldn't find fid associated with dentry\n");
726 v9fs_blank_wstat(&wstat
);
727 if (iattr
->ia_valid
& ATTR_MODE
)
728 wstat
.mode
= unixmode2p9mode(v9ses
, iattr
->ia_mode
);
730 if (iattr
->ia_valid
& ATTR_MTIME
)
731 wstat
.mtime
= iattr
->ia_mtime
.tv_sec
;
733 if (iattr
->ia_valid
& ATTR_ATIME
)
734 wstat
.atime
= iattr
->ia_atime
.tv_sec
;
736 if (iattr
->ia_valid
& ATTR_SIZE
)
737 wstat
.length
= iattr
->ia_size
;
739 if (v9ses
->extended
) {
740 if (iattr
->ia_valid
& ATTR_UID
)
741 wstat
.n_uid
= iattr
->ia_uid
;
743 if (iattr
->ia_valid
& ATTR_GID
)
744 wstat
.n_gid
= iattr
->ia_gid
;
747 res
= v9fs_t_wstat(v9ses
, fid
->fid
, &wstat
, &fcall
);
750 PRINT_FCALL_ERROR("wstat error", fcall
);
754 res
= inode_setattr(dentry
->d_inode
, iattr
);
760 * v9fs_stat2inode - populate an inode structure with mistat info
761 * @stat: Plan 9 metadata (mistat) structure
762 * @inode: inode to populate
763 * @sb: superblock of filesystem
768 v9fs_stat2inode(struct v9fs_stat
*stat
, struct inode
*inode
,
769 struct super_block
*sb
)
773 struct v9fs_session_info
*v9ses
= sb
->s_fs_info
;
777 inode
->i_atime
.tv_sec
= stat
->atime
;
778 inode
->i_mtime
.tv_sec
= stat
->mtime
;
779 inode
->i_ctime
.tv_sec
= stat
->mtime
;
781 inode
->i_uid
= v9ses
->uid
;
782 inode
->i_gid
= v9ses
->gid
;
784 if (v9ses
->extended
) {
785 inode
->i_uid
= stat
->n_uid
;
786 inode
->i_gid
= stat
->n_gid
;
789 inode
->i_mode
= p9mode2unixmode(v9ses
, stat
->mode
);
790 if ((S_ISBLK(inode
->i_mode
)) || (S_ISCHR(inode
->i_mode
))) {
795 n
= stat
->extension
.len
;
796 if (n
> sizeof(ext
)-1)
798 memmove(ext
, stat
->extension
.str
, n
);
800 sscanf(ext
, "%c %u %u", &type
, &major
, &minor
);
803 inode
->i_mode
&= ~S_IFBLK
;
804 inode
->i_mode
|= S_IFCHR
;
809 dprintk(DEBUG_ERROR
, "Unknown special type %c (%.*s)\n",
810 type
, stat
->extension
.len
, stat
->extension
.str
);
812 inode
->i_rdev
= MKDEV(major
, minor
);
816 inode
->i_size
= stat
->length
;
818 inode
->i_blksize
= sb
->s_blocksize
;
820 (inode
->i_size
+ inode
->i_blksize
- 1) >> sb
->s_blocksize_bits
;
824 * v9fs_qid2ino - convert qid into inode number
827 * BUG: potential for inode number collisions?
830 ino_t
v9fs_qid2ino(struct v9fs_qid
*qid
)
832 u64 path
= qid
->path
+ 2;
835 if (sizeof(ino_t
) == sizeof(path
))
836 memcpy(&i
, &path
, sizeof(ino_t
));
838 i
= (ino_t
) (path
^ (path
>> 32));
844 * v9fs_readlink - read a symlink's location (internal version)
845 * @dentry: dentry for symlink
846 * @buffer: buffer to load symlink location into
847 * @buflen: length of buffer
851 static int v9fs_readlink(struct dentry
*dentry
, char *buffer
, int buflen
)
855 struct v9fs_fcall
*fcall
= NULL
;
856 struct v9fs_session_info
*v9ses
= v9fs_inode2v9ses(dentry
->d_inode
);
857 struct v9fs_fid
*fid
= v9fs_fid_lookup(dentry
);
860 dprintk(DEBUG_ERROR
, "could not resolve fid from dentry\n");
865 if (!v9ses
->extended
) {
867 dprintk(DEBUG_ERROR
, "not extended\n");
871 dprintk(DEBUG_VFS
, " %s\n", dentry
->d_name
.name
);
872 retval
= v9fs_t_stat(v9ses
, fid
->fid
, &fcall
);
875 dprintk(DEBUG_ERROR
, "stat error\n");
882 if (!(fcall
->params
.rstat
.stat
.mode
& V9FS_DMSYMLINK
)) {
887 /* copy extension buffer into buffer */
888 if (fcall
->params
.rstat
.stat
.extension
.len
< buflen
)
889 buflen
= fcall
->params
.rstat
.stat
.extension
.len
;
891 memcpy(buffer
, fcall
->params
.rstat
.stat
.extension
.str
, buflen
- 1);
892 buffer
[buflen
-1] = 0;
903 * v9fs_vfs_readlink - read a symlink's location
904 * @dentry: dentry for symlink
905 * @buf: buffer to load symlink location into
906 * @buflen: length of buffer
910 static int v9fs_vfs_readlink(struct dentry
*dentry
, char __user
* buffer
,
915 char *link
= __getname();
917 if (buflen
> PATH_MAX
)
920 dprintk(DEBUG_VFS
, " dentry: %s (%p)\n", dentry
->d_iname
, dentry
);
922 retval
= v9fs_readlink(dentry
, link
, buflen
);
925 if ((ret
= copy_to_user(buffer
, link
, retval
)) != 0) {
926 dprintk(DEBUG_ERROR
, "problem copying to user: %d\n",
937 * v9fs_vfs_follow_link - follow a symlink path
938 * @dentry: dentry for symlink
943 static void *v9fs_vfs_follow_link(struct dentry
*dentry
, struct nameidata
*nd
)
946 char *link
= __getname();
948 dprintk(DEBUG_VFS
, "%s n", dentry
->d_name
.name
);
951 link
= ERR_PTR(-ENOMEM
);
953 len
= v9fs_readlink(dentry
, link
, strlen(link
));
961 nd_set_link(nd
, link
);
967 * v9fs_vfs_put_link - release a symlink path
968 * @dentry: dentry for symlink
973 static void v9fs_vfs_put_link(struct dentry
*dentry
, struct nameidata
*nd
, void *p
)
975 char *s
= nd_get_link(nd
);
977 dprintk(DEBUG_VFS
, " %s %s\n", dentry
->d_name
.name
, s
);
982 static int v9fs_vfs_mkspecial(struct inode
*dir
, struct dentry
*dentry
,
983 int mode
, const char *extension
)
986 struct v9fs_session_info
*v9ses
;
987 struct v9fs_fcall
*fcall
;
988 struct v9fs_fid
*fid
;
989 struct v9fs_wstat wstat
;
991 v9ses
= v9fs_inode2v9ses(dir
);
995 if (!v9ses
->extended
) {
996 dprintk(DEBUG_ERROR
, "not extended\n");
1000 /* issue a create */
1001 retval
= v9fs_create(dir
, dentry
, mode
, 0);
1005 fid
= v9fs_fid_get_created(dentry
);
1007 dprintk(DEBUG_ERROR
, "couldn't resolve fid from dentry\n");
1011 /* issue a Twstat */
1012 v9fs_blank_wstat(&wstat
);
1013 wstat
.muid
= v9ses
->name
;
1014 wstat
.extension
= (char *) extension
;
1015 retval
= v9fs_t_wstat(v9ses
, fid
->fid
, &wstat
, &fcall
);
1017 PRINT_FCALL_ERROR("wstat error", fcall
);
1021 err
= v9fs_t_clunk(v9ses
, fid
->fid
);
1023 dprintk(DEBUG_ERROR
, "clunk failed: %d\n", err
);
1027 d_drop(dentry
); /* FID - will this also clunk? */
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 dprintk(DEBUG_VFS
, " %lu,%s,%s\n", dir
->i_ino
, dentry
->d_name
.name
,
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 v9fs_fid
*oldfid
;
1073 dprintk(DEBUG_VFS
, " %lu,%s,%s\n", dir
->i_ino
, dentry
->d_name
.name
,
1074 old_dentry
->d_name
.name
);
1076 oldfid
= v9fs_fid_lookup(old_dentry
);
1078 dprintk(DEBUG_ERROR
, "can't find oldfid\n");
1083 sprintf(name
, "hardlink(%d)\n", oldfid
->fid
);
1084 retval
= v9fs_vfs_mkspecial(dir
, dentry
, V9FS_DMLINK
, name
);
1091 * v9fs_vfs_mknod - create a special file
1092 * @dir: inode destination for new link
1093 * @dentry: dentry for file
1094 * @mode: mode for creation
1095 * @dev_t: device associated with special file
1100 v9fs_vfs_mknod(struct inode
*dir
, struct dentry
*dentry
, int mode
, dev_t rdev
)
1105 dprintk(DEBUG_VFS
, " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir
->i_ino
,
1106 dentry
->d_name
.name
, mode
, MAJOR(rdev
), MINOR(rdev
));
1108 if (!new_valid_dev(rdev
))
1112 /* build extension */
1114 sprintf(name
, "b %u %u", MAJOR(rdev
), MINOR(rdev
));
1115 else if (S_ISCHR(mode
))
1116 sprintf(name
, "c %u %u", MAJOR(rdev
), MINOR(rdev
));
1117 else if (S_ISFIFO(mode
))
1124 retval
= v9fs_vfs_mkspecial(dir
, dentry
, mode
, name
);
1130 static struct inode_operations v9fs_dir_inode_operations_ext
= {
1131 .create
= v9fs_vfs_create
,
1132 .lookup
= v9fs_vfs_lookup
,
1133 .symlink
= v9fs_vfs_symlink
,
1134 .link
= v9fs_vfs_link
,
1135 .unlink
= v9fs_vfs_unlink
,
1136 .mkdir
= v9fs_vfs_mkdir
,
1137 .rmdir
= v9fs_vfs_rmdir
,
1138 .mknod
= v9fs_vfs_mknod
,
1139 .rename
= v9fs_vfs_rename
,
1140 .readlink
= v9fs_vfs_readlink
,
1141 .getattr
= v9fs_vfs_getattr
,
1142 .setattr
= v9fs_vfs_setattr
,
1145 static struct inode_operations v9fs_dir_inode_operations
= {
1146 .create
= v9fs_vfs_create
,
1147 .lookup
= v9fs_vfs_lookup
,
1148 .unlink
= v9fs_vfs_unlink
,
1149 .mkdir
= v9fs_vfs_mkdir
,
1150 .rmdir
= v9fs_vfs_rmdir
,
1151 .mknod
= v9fs_vfs_mknod
,
1152 .rename
= v9fs_vfs_rename
,
1153 .getattr
= v9fs_vfs_getattr
,
1154 .setattr
= v9fs_vfs_setattr
,
1157 static struct inode_operations v9fs_file_inode_operations
= {
1158 .getattr
= v9fs_vfs_getattr
,
1159 .setattr
= v9fs_vfs_setattr
,
1162 static struct inode_operations v9fs_symlink_inode_operations
= {
1163 .readlink
= v9fs_vfs_readlink
,
1164 .follow_link
= v9fs_vfs_follow_link
,
1165 .put_link
= v9fs_vfs_put_link
,
1166 .getattr
= v9fs_vfs_getattr
,
1167 .setattr
= v9fs_vfs_setattr
,