hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/fs/9p/vfs_inode_dotl.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * linux/fs/9p/vfs_inode_dotl.c
34 *
....@@ -5,22 +6,6 @@
56 *
67 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
78 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
8
- *
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.
12
- *
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.
17
- *
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
23
- *
249 */
2510
2611 #include <linux/module.h>
....@@ -74,7 +59,7 @@
7459 struct p9_stat_dotl *st = (struct p9_stat_dotl *)data;
7560
7661 /* don't match inode of different type */
77
- if ((inode->i_mode & S_IFMT) != (st->st_mode & S_IFMT))
62
+ if (inode_wrong_type(inode, st->st_mode))
7863 return 0;
7964
8065 if (inode->i_generation != st->st_gen)
....@@ -555,8 +540,11 @@
555540 int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)
556541 {
557542 int retval;
558
- struct p9_fid *fid;
559
- struct p9_iattr_dotl p9attr;
543
+ struct p9_fid *fid = NULL;
544
+ struct p9_iattr_dotl p9attr = {
545
+ .uid = INVALID_UID,
546
+ .gid = INVALID_GID,
547
+ };
560548 struct inode *inode = d_inode(dentry);
561549
562550 p9_debug(P9_DEBUG_VFS, "\n");
....@@ -566,16 +554,29 @@
566554 return retval;
567555
568556 p9attr.valid = v9fs_mapped_iattr_valid(iattr->ia_valid);
569
- p9attr.mode = iattr->ia_mode;
570
- p9attr.uid = iattr->ia_uid;
571
- p9attr.gid = iattr->ia_gid;
572
- p9attr.size = iattr->ia_size;
573
- p9attr.atime_sec = iattr->ia_atime.tv_sec;
574
- p9attr.atime_nsec = iattr->ia_atime.tv_nsec;
575
- p9attr.mtime_sec = iattr->ia_mtime.tv_sec;
576
- p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec;
557
+ if (iattr->ia_valid & ATTR_MODE)
558
+ p9attr.mode = iattr->ia_mode;
559
+ if (iattr->ia_valid & ATTR_UID)
560
+ p9attr.uid = iattr->ia_uid;
561
+ if (iattr->ia_valid & ATTR_GID)
562
+ p9attr.gid = iattr->ia_gid;
563
+ if (iattr->ia_valid & ATTR_SIZE)
564
+ p9attr.size = iattr->ia_size;
565
+ if (iattr->ia_valid & ATTR_ATIME_SET) {
566
+ p9attr.atime_sec = iattr->ia_atime.tv_sec;
567
+ p9attr.atime_nsec = iattr->ia_atime.tv_nsec;
568
+ }
569
+ if (iattr->ia_valid & ATTR_MTIME_SET) {
570
+ p9attr.mtime_sec = iattr->ia_mtime.tv_sec;
571
+ p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec;
572
+ }
577573
578
- fid = v9fs_fid_lookup(dentry);
574
+ if (iattr->ia_valid & ATTR_FILE) {
575
+ fid = iattr->ia_file->private_data;
576
+ WARN_ON(!fid);
577
+ }
578
+ if (!fid)
579
+ fid = v9fs_fid_lookup(dentry);
579580 if (IS_ERR(fid))
580581 return PTR_ERR(fid);
581582
....@@ -656,14 +657,10 @@
656657 if (stat->st_result_mask & P9_STATS_NLINK)
657658 set_nlink(inode, stat->st_nlink);
658659 if (stat->st_result_mask & P9_STATS_MODE) {
659
- inode->i_mode = stat->st_mode;
660
- if ((S_ISBLK(inode->i_mode)) ||
661
- (S_ISCHR(inode->i_mode)))
662
- init_special_inode(inode, inode->i_mode,
663
- inode->i_rdev);
660
+ mode = stat->st_mode & S_IALLUGO;
661
+ mode |= inode->i_mode & ~S_IALLUGO;
662
+ inode->i_mode = mode;
664663 }
665
- if (stat->st_result_mask & P9_STATS_RDEV)
666
- inode->i_rdev = new_decode_dev(stat->st_rdev);
667664 if (!(flags & V9FS_STAT2INODE_KEEP_ISIZE) &&
668665 stat->st_result_mask & P9_STATS_SIZE)
669666 v9fs_i_size_write(inode, stat->st_size);
....@@ -943,7 +940,7 @@
943940 /*
944941 * Don't update inode if the file type is different
945942 */
946
- if ((inode->i_mode & S_IFMT) != (st->st_mode & S_IFMT))
943
+ if (inode_wrong_type(inode, st->st_mode))
947944 goto out;
948945
949946 /*