26 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28 #include <linux/module.h>
29 #include <linux/errno.h>
33 #include <linux/stat.h>
34 #include <linux/string.h>
38 #include <linux/sched.h>
39 #include <linux/slab.h>
40 #include <linux/xattr.h>
70 if (v9fs_proto_dotu(v9ses)) {
71 if (v9ses->
nodev == 0) {
82 if ((mode &
S_ISUID) == S_ISUID)
84 if ((mode &
S_ISGID) == S_ISGID)
86 if ((mode &
S_ISVTX) == S_ISVTX)
102 int mode = stat->
mode;
105 if (v9fs_proto_dotu(v9ses)) {
132 res = p9mode2perm(v9ses, stat);
136 else if ((mode &
P9_DMSYMLINK) && (v9fs_proto_dotu(v9ses)))
138 else if ((mode &
P9_DMSOCKET) && (v9fs_proto_dotu(v9ses))
139 && (v9ses->
nodev == 0))
142 && (v9ses->
nodev == 0))
144 else if ((mode &
P9_DMDEVICE) && (v9fs_proto_dotu(v9ses))
145 && (v9ses->
nodev == 0)) {
150 sscanf(
ext,
"%c %u %u", &type, &major, &minor);
162 *rdev =
MKDEV(major, minor);
220 wstat->
qid.type = ~0;
221 wstat->
qid.version = ~0;
222 *((
long long *)&wstat->
qid.path) = ~0;
248 #ifdef CONFIG_9P_FSCACHE
249 v9inode->fscache =
NULL;
290 if (v9fs_proto_dotl(v9ses)) {
292 }
else if (v9fs_proto_dotu(v9ses)) {
293 inode->
i_op = &v9fs_file_inode_operations;
296 "special files without extended mode\n");
303 if (v9fs_proto_dotl(v9ses)) {
311 inode->
i_op = &v9fs_file_inode_operations;
320 if (!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses)) {
322 "extended modes used with legacy protocol\n");
327 if (v9fs_proto_dotl(v9ses))
330 inode->
i_op = &v9fs_symlink_inode_operations;
335 if (v9fs_proto_dotl(v9ses))
337 else if (v9fs_proto_dotu(v9ses))
338 inode->
i_op = &v9fs_dir_inode_operations_dotu;
340 inode->
i_op = &v9fs_dir_inode_operations;
342 if (v9fs_proto_dotl(v9ses))
350 mode, mode & S_IFMT);
376 pr_warn(
"%s (%d): Problem allocating inode\n",
377 __func__, task_pid_nr(
current));
454 #ifdef CONFIG_9P_FSCACHE
464 static int v9fs_test_inode(
struct inode *inode,
void *
data)
472 umode = p9mode2unixmode(v9ses, st, &rdev);
479 &st->
qid.version,
sizeof(v9inode->
qid.version)))
482 if (v9inode->
qid.type != st->
qid.type)
487 static int v9fs_test_new_inode(
struct inode *inode,
void *data)
492 static int v9fs_set_inode(
struct inode *inode,
void *data)
512 int (*
test)(
struct inode *,
void *);
515 test = v9fs_test_new_inode;
517 test = v9fs_test_inode;
531 umode = p9mode2unixmode(v9ses, st, &rdev);
537 #ifdef CONFIG_9P_FSCACHE
545 return ERR_PTR(retval);
554 struct inode *inode =
NULL;
560 inode = v9fs_qid_iget(sb, &st->
qid, st,
new);
571 static int v9fs_at_to_dotl_flags(
int flags)
587 static int v9fs_remove(
struct inode *dir,
struct dentry *
dentry,
int flags)
591 struct p9_fid *v9fid, *dfid;
597 v9ses = v9fs_inode2v9ses(dir);
601 retval = PTR_ERR(dfid);
605 if (v9fs_proto_dotl(v9ses))
607 v9fs_at_to_dotl_flags(flags));
612 return PTR_ERR(v9fid);
626 v9fs_invalidate_inode_attr(inode);
627 v9fs_invalidate_inode_attr(dir);
656 name = (
char *) dentry->
d_name.name;
684 "p9_client_walk failed %d\n", err);
691 inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->
i_sb);
693 err = PTR_ERR(inode);
695 "inode creation failed %d\n", err);
727 v9fs_vfs_create(
struct inode *dir,
struct dentry *dentry,
umode_t mode,
731 u32 perm = unixmode2p9mode(v9ses, mode);
735 fid = v9fs_create(v9ses, dir, dentry,
NULL, perm,
P9_ORDWR);
739 v9fs_invalidate_inode_attr(dir);
753 static int v9fs_vfs_mkdir(
struct inode *dir,
struct dentry *dentry,
umode_t mode)
762 v9ses = v9fs_inode2v9ses(dir);
763 perm = unixmode2p9mode(v9ses, mode |
S_IFDIR);
764 fid = v9fs_create(v9ses, dir, dentry,
NULL, perm,
P9_OREAD);
770 v9fs_invalidate_inode_attr(dir);
799 dir, dentry->
d_name.name, dentry, flags);
805 v9ses = v9fs_inode2v9ses(dir);
809 return ERR_CAST(dfid);
811 name = (
char *) dentry->
d_name.name;
814 result = PTR_ERR(fid);
820 return ERR_PTR(result);
828 inode = v9fs_get_inode_from_fid(v9ses, fid, dir->
i_sb);
830 inode = v9fs_get_new_inode_from_fid(v9ses, fid, dir->
i_sb);
832 result = PTR_ERR(inode);
850 result = PTR_ERR(res);
856 return ERR_PTR(result);
860 v9fs_vfs_atomic_open(
struct inode *dir,
struct dentry *dentry,
869 struct dentry *res =
NULL;
871 if (d_unhashed(dentry)) {
886 v9ses = v9fs_inode2v9ses(dir);
887 perm = unixmode2p9mode(v9ses, mode);
888 fid = v9fs_create(v9ses, dir, dentry,
NULL, perm,
890 v9fs_proto_dotu(v9ses)));
897 v9fs_invalidate_inode_attr(dir);
898 v9inode = V9FS_I(dentry->
d_inode);
910 if (IS_ERR(inode_fid)) {
911 err = PTR_ERR(inode_fid);
923 #ifdef CONFIG_9P_FSCACHE
948 return v9fs_remove(i, d, 0);
974 struct inode *new_dir,
struct dentry *new_dentry)
977 struct inode *old_inode;
987 old_inode = old_dentry->
d_inode;
988 new_inode = new_dentry->
d_inode;
989 v9ses = v9fs_inode2v9ses(old_inode);
992 return PTR_ERR(oldfid);
995 if (IS_ERR(olddirfid)) {
996 retval = PTR_ERR(olddirfid);
1001 if (IS_ERR(newdirfid)) {
1002 retval = PTR_ERR(newdirfid);
1007 if (v9fs_proto_dotl(v9ses)) {
1009 newdirfid, new_dentry->
d_name.name);
1012 new_dentry->
d_name.name);
1027 wstat.
name = (
char *) new_dentry->
d_name.name;
1043 v9fs_invalidate_inode_attr(old_inode);
1044 v9fs_invalidate_inode_attr(old_dir);
1045 v9fs_invalidate_inode_attr(new_dir);
1048 d_move(old_dentry, new_dentry);
1069 v9fs_vfs_getattr(
struct vfsmount *mnt,
struct dentry *dentry,
1079 v9ses = v9fs_dentry2v9ses(dentry);
1086 return PTR_ERR(fid);
1107 static int v9fs_vfs_setattr(
struct dentry *dentry,
struct iattr *
iattr)
1120 v9ses = v9fs_dentry2v9ses(dentry);
1123 return PTR_ERR(fid);
1127 wstat.mode = unixmode2p9mode(v9ses, iattr->
ia_mode);
1130 wstat.mtime = iattr->
ia_mtime.tv_sec;
1133 wstat.atime = iattr->
ia_atime.tv_sec;
1136 wstat.length = iattr->
ia_size;
1138 if (v9fs_proto_dotu(v9ses)) {
1140 wstat.n_uid = iattr->
ia_uid;
1143 wstat.n_gid = iattr->
ia_gid;
1158 v9fs_invalidate_inode_attr(dentry->
d_inode);
1161 mark_inode_dirty(dentry->
d_inode);
1180 unsigned int i_nlink;
1193 if (v9fs_proto_dotu(v9ses)) {
1198 if (v9fs_proto_dotu(v9ses) && (stat->
extension[0] !=
'\0')) {
1208 sscanf(ext,
"%13s %u", tag_name, &i_nlink);
1209 if (!
strncmp(tag_name,
"HARDLINKCOUNT", 13))
1213 mode = p9mode2perm(v9ses, stat);
1214 mode |= inode->
i_mode & ~S_IALLUGO;
1216 i_size_write(inode, stat->
length);
1219 inode->
i_blocks = (i_size_read(inode) + 512 - 1) >> 9;
1235 if (
sizeof(
ino_t) ==
sizeof(path))
1238 i = (
ino_t) (path ^ (path >> 32));
1251 static int v9fs_readlink(
struct dentry *dentry,
char *
buffer,
int buflen)
1261 v9ses = v9fs_dentry2v9ses(dentry);
1264 return PTR_ERR(fid);
1266 if (!v9fs_proto_dotu(v9ses))
1273 if (!(st->
mode & P9_DMSYMLINK)) {
1298 static void *v9fs_vfs_follow_link(
struct dentry *dentry,
struct nameidata *nd)
1308 len = v9fs_readlink(dentry, link,
PATH_MAX);
1312 link = ERR_PTR(len);
1316 nd_set_link(nd, link);
1332 char *
s = nd_get_link(nd);
1335 dentry->
d_name.name, IS_ERR(s) ?
"<error>" : s);
1349 static int v9fs_vfs_mkspecial(
struct inode *dir,
struct dentry *dentry,
1350 u32 perm,
const char *extension)
1355 v9ses = v9fs_inode2v9ses(dir);
1356 if (!v9fs_proto_dotu(v9ses)) {
1361 fid = v9fs_create(v9ses, dir, dentry, (
char *) extension, perm,
1364 return PTR_ERR(fid);
1366 v9fs_invalidate_inode_attr(dir);
1382 v9fs_vfs_symlink(
struct inode *dir,
struct dentry *dentry,
const char *symname)
1387 return v9fs_vfs_mkspecial(dir, dentry, P9_DMSYMLINK, symname);
1399 v9fs_vfs_link(
struct dentry *old_dentry,
struct inode *dir,
1400 struct dentry *dentry)
1411 return PTR_ERR(oldfid);
1420 retval = v9fs_vfs_mkspecial(dir, dentry, P9_DMLINK, name);
1424 v9fs_invalidate_inode_attr(dir);
1441 v9fs_vfs_mknod(
struct inode *dir,
struct dentry *dentry,
umode_t mode,
dev_t rdev)
1452 if (!new_valid_dev(rdev))
1472 perm = unixmode2p9mode(v9ses, mode);
1473 retval = v9fs_vfs_mkspecial(dir, dentry, perm, name);
1487 v9ses = v9fs_inode2v9ses(inode);
1494 umode = p9mode2unixmode(v9ses, st, &rdev);
1495 if ((inode->
i_mode & S_IFMT) != (umode & S_IFMT))
1498 spin_lock(&inode->
i_lock);
1507 spin_unlock(&inode->
i_lock);
1515 .create = v9fs_vfs_create,
1517 .atomic_open = v9fs_vfs_atomic_open,
1518 .symlink = v9fs_vfs_symlink,
1519 .link = v9fs_vfs_link,
1521 .mkdir = v9fs_vfs_mkdir,
1523 .mknod = v9fs_vfs_mknod,
1525 .getattr = v9fs_vfs_getattr,
1526 .setattr = v9fs_vfs_setattr,
1530 .create = v9fs_vfs_create,
1532 .atomic_open = v9fs_vfs_atomic_open,
1534 .mkdir = v9fs_vfs_mkdir,
1536 .mknod = v9fs_vfs_mknod,
1538 .getattr = v9fs_vfs_getattr,
1539 .setattr = v9fs_vfs_setattr,
1543 .getattr = v9fs_vfs_getattr,
1544 .setattr = v9fs_vfs_setattr,
1549 .follow_link = v9fs_vfs_follow_link,
1551 .getattr = v9fs_vfs_getattr,
1552 .setattr = v9fs_vfs_setattr,