^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * fs/cifs/inode.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) International Business Machines Corp., 2002,2010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Author(s): Steve French (sfrench@us.ibm.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * This library is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * it under the terms of the GNU Lesser General Public License as published
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * by the Free Software Foundation; either version 2.1 of the License, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * (at your option) any later version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * This library is distributed in the hope that it will be useful,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * but WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * the GNU Lesser General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * You should have received a copy of the GNU Lesser General Public License
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * along with this library; if not, write to the Free Software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/freezer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/wait_bit.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/fiemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <asm/div64.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include "cifsfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include "cifspdu.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include "cifsglob.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include "cifsproto.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include "smb2proto.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include "cifs_debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include "cifs_fs_sb.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include "cifs_unicode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include "fscache.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static void cifs_set_ops(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) switch (inode->i_mode & S_IFMT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) case S_IFREG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) inode->i_op = &cifs_file_inode_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DIRECT_IO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) inode->i_fop = &cifs_file_direct_nobrl_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) inode->i_fop = &cifs_file_direct_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) } else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_STRICT_IO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) inode->i_fop = &cifs_file_strict_nobrl_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) inode->i_fop = &cifs_file_strict_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) } else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_BRL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) inode->i_fop = &cifs_file_nobrl_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) else { /* not direct, send byte range locks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) inode->i_fop = &cifs_file_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /* check if server can support readpages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (cifs_sb_master_tcon(cifs_sb)->ses->server->max_read <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) PAGE_SIZE + MAX_CIFS_HDR_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) inode->i_data.a_ops = &cifs_addr_ops_smallbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) inode->i_data.a_ops = &cifs_addr_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) case S_IFDIR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #ifdef CONFIG_CIFS_DFS_UPCALL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (IS_AUTOMOUNT(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) inode->i_op = &cifs_dfs_referral_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #else /* NO DFS support, treat as a directory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) inode->i_op = &cifs_dir_inode_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) inode->i_fop = &cifs_dir_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) case S_IFLNK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) inode->i_op = &cifs_symlink_inode_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) init_special_inode(inode, inode->i_mode, inode->i_rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) /* check inode attributes against fattr. If they don't match, tag the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * inode for cache invalidation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) cifs_revalidate_cache(struct inode *inode, struct cifs_fattr *fattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct cifsInodeInfo *cifs_i = CIFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) cifs_dbg(FYI, "%s: revalidating inode %llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) __func__, cifs_i->uniqueid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (inode->i_state & I_NEW) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) cifs_dbg(FYI, "%s: inode %llu is new\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) __func__, cifs_i->uniqueid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /* don't bother with revalidation if we have an oplock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (CIFS_CACHE_READ(cifs_i)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) cifs_dbg(FYI, "%s: inode %llu is oplocked\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) __func__, cifs_i->uniqueid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /* revalidate if mtime or size have changed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) fattr->cf_mtime = timestamp_truncate(fattr->cf_mtime, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if (timespec64_equal(&inode->i_mtime, &fattr->cf_mtime) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) cifs_i->server_eof == fattr->cf_eof) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) cifs_dbg(FYI, "%s: inode %llu is unchanged\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) __func__, cifs_i->uniqueid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) cifs_dbg(FYI, "%s: invalidating inode %llu mapping\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) __func__, cifs_i->uniqueid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) set_bit(CIFS_INO_INVALID_MAPPING, &cifs_i->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * copy nlink to the inode, unless it wasn't provided. Provide
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * sane values if we don't have an existing one and none was provided
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) cifs_nlink_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * if we're in a situation where we can't trust what we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * got from the server (readdir, some non-unix cases)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * fake reasonable values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (fattr->cf_flags & CIFS_FATTR_UNKNOWN_NLINK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /* only provide fake values on a new inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (inode->i_state & I_NEW) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (fattr->cf_cifsattrs & ATTR_DIRECTORY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) set_nlink(inode, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) set_nlink(inode, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /* we trust the server, so update it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) set_nlink(inode, fattr->cf_nlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /* populate an inode with info from a cifs_fattr struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) struct cifsInodeInfo *cifs_i = CIFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) cifs_revalidate_cache(inode, fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) fattr->cf_mtime = timestamp_truncate(fattr->cf_mtime, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) fattr->cf_atime = timestamp_truncate(fattr->cf_atime, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) fattr->cf_ctime = timestamp_truncate(fattr->cf_ctime, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) /* we do not want atime to be less than mtime, it broke some apps */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) if (timespec64_compare(&fattr->cf_atime, &fattr->cf_mtime) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) inode->i_atime = fattr->cf_mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) inode->i_atime = fattr->cf_atime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) inode->i_mtime = fattr->cf_mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) inode->i_ctime = fattr->cf_ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) inode->i_rdev = fattr->cf_rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) cifs_nlink_fattr_to_inode(inode, fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) inode->i_uid = fattr->cf_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) inode->i_gid = fattr->cf_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) /* if dynperm is set, don't clobber existing mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (inode->i_state & I_NEW ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) !(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) inode->i_mode = fattr->cf_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) cifs_i->cifsAttrs = fattr->cf_cifsattrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (fattr->cf_flags & CIFS_FATTR_NEED_REVAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) cifs_i->time = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) cifs_i->time = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (fattr->cf_flags & CIFS_FATTR_DELETE_PENDING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) set_bit(CIFS_INO_DELETE_PENDING, &cifs_i->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) clear_bit(CIFS_INO_DELETE_PENDING, &cifs_i->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) cifs_i->server_eof = fattr->cf_eof;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * Can't safely change the file size here if the client is writing to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * it due to potential races.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (is_size_safe_to_change(cifs_i, fattr->cf_eof)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) i_size_write(inode, fattr->cf_eof);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * i_blocks is not related to (i_size / i_blksize),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) * but instead 512 byte (2**9) size is required for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * calculating num blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) inode->i_blocks = (512 - 1 + fattr->cf_bytes) >> 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (fattr->cf_flags & CIFS_FATTR_DFS_REFERRAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) inode->i_flags |= S_AUTOMOUNT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (inode->i_state & I_NEW)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) cifs_set_ops(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) cifs_fill_uniqueid(struct super_block *sb, struct cifs_fattr *fattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) fattr->cf_uniqueid = iunique(sb, ROOT_I);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) /* Fill a cifs_fattr struct with info from FILE_UNIX_BASIC_INFO. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) cifs_unix_basic_to_fattr(struct cifs_fattr *fattr, FILE_UNIX_BASIC_INFO *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) struct cifs_sb_info *cifs_sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) memset(fattr, 0, sizeof(*fattr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) fattr->cf_uniqueid = le64_to_cpu(info->UniqueId);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) fattr->cf_bytes = le64_to_cpu(info->NumOfBytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) fattr->cf_eof = le64_to_cpu(info->EndOfFile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) fattr->cf_atime = cifs_NTtimeToUnix(info->LastAccessTime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) fattr->cf_mtime = cifs_NTtimeToUnix(info->LastModificationTime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) fattr->cf_ctime = cifs_NTtimeToUnix(info->LastStatusChange);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) /* old POSIX extensions don't get create time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) fattr->cf_mode = le64_to_cpu(info->Permissions);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) * Since we set the inode type below we need to mask off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) * to avoid strange results if bits set above.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) fattr->cf_mode &= ~S_IFMT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) switch (le32_to_cpu(info->Type)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) case UNIX_FILE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) fattr->cf_mode |= S_IFREG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) fattr->cf_dtype = DT_REG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) case UNIX_SYMLINK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) fattr->cf_mode |= S_IFLNK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) fattr->cf_dtype = DT_LNK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) case UNIX_DIR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) fattr->cf_mode |= S_IFDIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) fattr->cf_dtype = DT_DIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) case UNIX_CHARDEV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) fattr->cf_mode |= S_IFCHR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) fattr->cf_dtype = DT_CHR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) fattr->cf_rdev = MKDEV(le64_to_cpu(info->DevMajor),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) le64_to_cpu(info->DevMinor) & MINORMASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) case UNIX_BLOCKDEV:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) fattr->cf_mode |= S_IFBLK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) fattr->cf_dtype = DT_BLK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) fattr->cf_rdev = MKDEV(le64_to_cpu(info->DevMajor),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) le64_to_cpu(info->DevMinor) & MINORMASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) case UNIX_FIFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) fattr->cf_mode |= S_IFIFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) fattr->cf_dtype = DT_FIFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) case UNIX_SOCKET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) fattr->cf_mode |= S_IFSOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) fattr->cf_dtype = DT_SOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /* safest to call it a file if we do not know */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) fattr->cf_mode |= S_IFREG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) fattr->cf_dtype = DT_REG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) cifs_dbg(FYI, "unknown type %d\n", le32_to_cpu(info->Type));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) fattr->cf_uid = cifs_sb->mnt_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) u64 id = le64_to_cpu(info->Uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if (id < ((uid_t)-1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) kuid_t uid = make_kuid(&init_user_ns, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) if (uid_valid(uid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) fattr->cf_uid = uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) fattr->cf_gid = cifs_sb->mnt_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) u64 id = le64_to_cpu(info->Gid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) if (id < ((gid_t)-1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) kgid_t gid = make_kgid(&init_user_ns, id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) if (gid_valid(gid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) fattr->cf_gid = gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) fattr->cf_nlink = le64_to_cpu(info->Nlinks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * Fill a cifs_fattr struct with fake inode info.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * Needed to setup cifs_fattr data for the directory which is the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) * junction to the new submount (ie to setup the fake directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) * which represents a DFS referral).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) cifs_create_dfs_fattr(struct cifs_fattr *fattr, struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) cifs_dbg(FYI, "creating fake fattr for DFS referral\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) memset(fattr, 0, sizeof(*fattr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) fattr->cf_mode = S_IFDIR | S_IXUGO | S_IRWXU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) fattr->cf_uid = cifs_sb->mnt_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) fattr->cf_gid = cifs_sb->mnt_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) ktime_get_coarse_real_ts64(&fattr->cf_mtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) fattr->cf_atime = fattr->cf_ctime = fattr->cf_mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) fattr->cf_nlink = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) fattr->cf_flags = CIFS_FATTR_DFS_REFERRAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) cifs_get_file_info_unix(struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) unsigned int xid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) FILE_UNIX_BASIC_INFO find_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) struct cifs_fattr fattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) struct inode *inode = file_inode(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) struct cifsFileInfo *cfile = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) xid = get_xid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) rc = CIFSSMBUnixQFileInfo(xid, tcon, cfile->fid.netfid, &find_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) if (!rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) cifs_unix_basic_to_fattr(&fattr, &find_data, cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) } else if (rc == -EREMOTE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) cifs_create_dfs_fattr(&fattr, inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) cifs_fattr_to_inode(inode, &fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) free_xid(xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) int cifs_get_inode_info_unix(struct inode **pinode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) const unsigned char *full_path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) struct super_block *sb, unsigned int xid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) FILE_UNIX_BASIC_INFO find_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) struct cifs_fattr fattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) struct cifs_tcon *tcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) struct tcon_link *tlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) cifs_dbg(FYI, "Getting info on %s\n", full_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) tlink = cifs_sb_tlink(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) if (IS_ERR(tlink))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) return PTR_ERR(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) tcon = tlink_tcon(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) /* could have done a find first instead but this returns more info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) rc = CIFSSMBUnixQPathInfo(xid, tcon, full_path, &find_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) cifs_sb->local_nls, cifs_remap(cifs_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) cifs_put_tlink(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) if (!rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) cifs_unix_basic_to_fattr(&fattr, &find_data, cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) } else if (rc == -EREMOTE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) cifs_create_dfs_fattr(&fattr, sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) /* check for Minshall+French symlinks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) int tmprc = check_mf_symlink(xid, tcon, cifs_sb, &fattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) full_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) if (tmprc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) cifs_dbg(FYI, "check_mf_symlink: %d\n", tmprc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) if (*pinode == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) /* get new inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) cifs_fill_uniqueid(sb, &fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) *pinode = cifs_iget(sb, &fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) if (!*pinode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) /* we already have inode, update it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) /* if uniqueid is different, return error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) if (unlikely(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) CIFS_I(*pinode)->uniqueid != fattr.cf_uniqueid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) CIFS_I(*pinode)->time = 0; /* force reval */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) rc = -ESTALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) goto cgiiu_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) /* if filetype is different, return error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) if (unlikely(inode_wrong_type(*pinode, fattr.cf_mode))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) CIFS_I(*pinode)->time = 0; /* force reval */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) rc = -ESTALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) goto cgiiu_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) cifs_fattr_to_inode(*pinode, &fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) cgiiu_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) cifs_sfu_type(struct cifs_fattr *fattr, const char *path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) struct cifs_sb_info *cifs_sb, unsigned int xid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) __u32 oplock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) struct tcon_link *tlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) struct cifs_tcon *tcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) struct cifs_fid fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) struct cifs_open_parms oparms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) struct cifs_io_parms io_parms = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) char buf[24];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) unsigned int bytes_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) char *pbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) int buf_type = CIFS_NO_BUFFER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) pbuf = buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) fattr->cf_mode &= ~S_IFMT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) if (fattr->cf_eof == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) fattr->cf_mode |= S_IFIFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) fattr->cf_dtype = DT_FIFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) } else if (fattr->cf_eof < 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) fattr->cf_mode |= S_IFREG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) fattr->cf_dtype = DT_REG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) return -EINVAL; /* EOPNOTSUPP? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) tlink = cifs_sb_tlink(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) if (IS_ERR(tlink))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) return PTR_ERR(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) tcon = tlink_tcon(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) oparms.tcon = tcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) oparms.cifs_sb = cifs_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) oparms.desired_access = GENERIC_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) oparms.create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) oparms.disposition = FILE_OPEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) oparms.path = path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) oparms.fid = &fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) oparms.reconnect = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) if (tcon->ses->server->oplocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) oplock = REQ_OPLOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) oplock = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) rc = tcon->ses->server->ops->open(xid, &oparms, &oplock, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) cifs_dbg(FYI, "check sfu type of %s, open rc = %d\n", path, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) cifs_put_tlink(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) /* Read header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) io_parms.netfid = fid.netfid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) io_parms.pid = current->tgid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) io_parms.tcon = tcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) io_parms.offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) io_parms.length = 24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) rc = tcon->ses->server->ops->sync_read(xid, &fid, &io_parms,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) &bytes_read, &pbuf, &buf_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) if ((rc == 0) && (bytes_read >= 8)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) if (memcmp("IntxBLK", pbuf, 8) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) cifs_dbg(FYI, "Block device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) fattr->cf_mode |= S_IFBLK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) fattr->cf_dtype = DT_BLK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) if (bytes_read == 24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) /* we have enough to decode dev num */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) __u64 mjr; /* major */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) __u64 mnr; /* minor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) mjr = le64_to_cpu(*(__le64 *)(pbuf+8));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) mnr = le64_to_cpu(*(__le64 *)(pbuf+16));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) fattr->cf_rdev = MKDEV(mjr, mnr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) } else if (memcmp("IntxCHR", pbuf, 8) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) cifs_dbg(FYI, "Char device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) fattr->cf_mode |= S_IFCHR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) fattr->cf_dtype = DT_CHR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) if (bytes_read == 24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) /* we have enough to decode dev num */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) __u64 mjr; /* major */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) __u64 mnr; /* minor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) mjr = le64_to_cpu(*(__le64 *)(pbuf+8));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) mnr = le64_to_cpu(*(__le64 *)(pbuf+16));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) fattr->cf_rdev = MKDEV(mjr, mnr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) } else if (memcmp("IntxLNK", pbuf, 7) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) cifs_dbg(FYI, "Symlink\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) fattr->cf_mode |= S_IFLNK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) fattr->cf_dtype = DT_LNK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) fattr->cf_mode |= S_IFREG; /* file? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) fattr->cf_dtype = DT_REG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) rc = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) fattr->cf_mode |= S_IFREG; /* then it is a file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) fattr->cf_dtype = DT_REG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) rc = -EOPNOTSUPP; /* or some unknown SFU type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) tcon->ses->server->ops->close(xid, tcon, &fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) cifs_put_tlink(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) #define SFBITS_MASK (S_ISVTX | S_ISGID | S_ISUID) /* SETFILEBITS valid bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) * Fetch mode bits as provided by SFU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) * FIXME: Doesn't this clobber the type bit we got from cifs_sfu_type ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) static int cifs_sfu_mode(struct cifs_fattr *fattr, const unsigned char *path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) struct cifs_sb_info *cifs_sb, unsigned int xid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) #ifdef CONFIG_CIFS_XATTR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) ssize_t rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) char ea_value[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) __u32 mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) struct tcon_link *tlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) struct cifs_tcon *tcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) tlink = cifs_sb_tlink(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) if (IS_ERR(tlink))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) return PTR_ERR(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) tcon = tlink_tcon(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) if (tcon->ses->server->ops->query_all_EAs == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) cifs_put_tlink(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) rc = tcon->ses->server->ops->query_all_EAs(xid, tcon, path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) "SETFILEBITS", ea_value, 4 /* size of buf */,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) cifs_put_tlink(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) return (int)rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) else if (rc > 3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) mode = le32_to_cpu(*((__le32 *)ea_value));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) fattr->cf_mode &= ~SFBITS_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) cifs_dbg(FYI, "special bits 0%o org mode 0%o\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) mode, fattr->cf_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) fattr->cf_mode = (mode & SFBITS_MASK) | fattr->cf_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) cifs_dbg(FYI, "special mode bits 0%o\n", mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) /* Fill a cifs_fattr struct with info from POSIX info struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) smb311_posix_info_to_fattr(struct cifs_fattr *fattr, struct smb311_posix_qinfo *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) struct super_block *sb, bool adjust_tz, bool symlink)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) memset(fattr, 0, sizeof(*fattr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) /* no fattr->flags to set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) fattr->cf_cifsattrs = le32_to_cpu(info->DosAttributes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) fattr->cf_uniqueid = le64_to_cpu(info->Inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) if (info->LastAccessTime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) fattr->cf_atime = cifs_NTtimeToUnix(info->LastAccessTime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) ktime_get_coarse_real_ts64(&fattr->cf_atime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) fattr->cf_ctime = cifs_NTtimeToUnix(info->ChangeTime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) fattr->cf_mtime = cifs_NTtimeToUnix(info->LastWriteTime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) if (adjust_tz) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) fattr->cf_ctime.tv_sec += tcon->ses->server->timeAdj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) fattr->cf_mtime.tv_sec += tcon->ses->server->timeAdj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) fattr->cf_eof = le64_to_cpu(info->EndOfFile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) fattr->cf_bytes = le64_to_cpu(info->AllocationSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) fattr->cf_createtime = le64_to_cpu(info->CreationTime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) fattr->cf_nlink = le32_to_cpu(info->HardLinks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) fattr->cf_mode = (umode_t) le32_to_cpu(info->Mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) /* The srv fs device id is overridden on network mount so setting rdev isn't needed here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) /* fattr->cf_rdev = le32_to_cpu(info->DeviceId); */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) if (symlink) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) fattr->cf_mode |= S_IFLNK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) fattr->cf_dtype = DT_LNK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) } else if (fattr->cf_cifsattrs & ATTR_DIRECTORY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) fattr->cf_mode |= S_IFDIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) fattr->cf_dtype = DT_DIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) } else { /* file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) fattr->cf_mode |= S_IFREG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) fattr->cf_dtype = DT_REG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) /* else if reparse point ... TODO: add support for FIFO and blk dev; special file types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) fattr->cf_uid = cifs_sb->mnt_uid; /* TODO: map uid and gid from SID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) fattr->cf_gid = cifs_sb->mnt_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) cifs_dbg(FYI, "POSIX query info: mode 0x%x uniqueid 0x%llx nlink %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) fattr->cf_mode, fattr->cf_uniqueid, fattr->cf_nlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) /* Fill a cifs_fattr struct with info from FILE_ALL_INFO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) cifs_all_info_to_fattr(struct cifs_fattr *fattr, FILE_ALL_INFO *info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) struct super_block *sb, bool adjust_tz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) bool symlink, u32 reparse_tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) memset(fattr, 0, sizeof(*fattr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) fattr->cf_cifsattrs = le32_to_cpu(info->Attributes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) if (info->DeletePending)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) fattr->cf_flags |= CIFS_FATTR_DELETE_PENDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) if (info->LastAccessTime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) fattr->cf_atime = cifs_NTtimeToUnix(info->LastAccessTime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) ktime_get_coarse_real_ts64(&fattr->cf_atime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) fattr->cf_ctime = cifs_NTtimeToUnix(info->ChangeTime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) fattr->cf_mtime = cifs_NTtimeToUnix(info->LastWriteTime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) if (adjust_tz) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) fattr->cf_ctime.tv_sec += tcon->ses->server->timeAdj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) fattr->cf_mtime.tv_sec += tcon->ses->server->timeAdj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) fattr->cf_eof = le64_to_cpu(info->EndOfFile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) fattr->cf_bytes = le64_to_cpu(info->AllocationSize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) fattr->cf_createtime = le64_to_cpu(info->CreationTime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) fattr->cf_nlink = le32_to_cpu(info->NumberOfLinks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) if (reparse_tag == IO_REPARSE_TAG_LX_SYMLINK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) fattr->cf_mode |= S_IFLNK | cifs_sb->mnt_file_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) fattr->cf_dtype = DT_LNK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) } else if (reparse_tag == IO_REPARSE_TAG_LX_FIFO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) fattr->cf_mode |= S_IFIFO | cifs_sb->mnt_file_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) fattr->cf_dtype = DT_FIFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) } else if (reparse_tag == IO_REPARSE_TAG_AF_UNIX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) fattr->cf_mode |= S_IFSOCK | cifs_sb->mnt_file_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) fattr->cf_dtype = DT_SOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) } else if (reparse_tag == IO_REPARSE_TAG_LX_CHR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) fattr->cf_mode |= S_IFCHR | cifs_sb->mnt_file_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) fattr->cf_dtype = DT_CHR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) } else if (reparse_tag == IO_REPARSE_TAG_LX_BLK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) fattr->cf_mode |= S_IFBLK | cifs_sb->mnt_file_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) fattr->cf_dtype = DT_BLK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) } else if (symlink) { /* TODO add more reparse tag checks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) fattr->cf_mode = S_IFLNK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) fattr->cf_dtype = DT_LNK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) } else if (fattr->cf_cifsattrs & ATTR_DIRECTORY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) fattr->cf_mode = S_IFDIR | cifs_sb->mnt_dir_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) fattr->cf_dtype = DT_DIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) * Server can return wrong NumberOfLinks value for directories
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) * when Unix extensions are disabled - fake it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) if (!tcon->unix_ext)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) fattr->cf_flags |= CIFS_FATTR_UNKNOWN_NLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) fattr->cf_mode = S_IFREG | cifs_sb->mnt_file_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) fattr->cf_dtype = DT_REG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) /* clear write bits if ATTR_READONLY is set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) if (fattr->cf_cifsattrs & ATTR_READONLY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) fattr->cf_mode &= ~(S_IWUGO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) * Don't accept zero nlink from non-unix servers unless
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) * delete is pending. Instead mark it as unknown.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) if ((fattr->cf_nlink < 1) && !tcon->unix_ext &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) !info->DeletePending) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) cifs_dbg(VFS, "bogus file nlink value %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) fattr->cf_nlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) fattr->cf_flags |= CIFS_FATTR_UNKNOWN_NLINK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) fattr->cf_uid = cifs_sb->mnt_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) fattr->cf_gid = cifs_sb->mnt_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) cifs_get_file_info(struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) unsigned int xid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) FILE_ALL_INFO find_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) struct cifs_fattr fattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) struct inode *inode = file_inode(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) struct cifsFileInfo *cfile = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) struct cifs_tcon *tcon = tlink_tcon(cfile->tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) struct TCP_Server_Info *server = tcon->ses->server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) if (!server->ops->query_file_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) xid = get_xid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) rc = server->ops->query_file_info(xid, tcon, &cfile->fid, &find_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) switch (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) /* TODO: add support to query reparse tag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) cifs_all_info_to_fattr(&fattr, &find_data, inode->i_sb, false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) false, 0 /* no reparse tag */);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) case -EREMOTE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) cifs_create_dfs_fattr(&fattr, inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) case -EOPNOTSUPP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) case -EINVAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) * FIXME: legacy server -- fall back to path-based call?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) * for now, just skip revalidating and mark inode for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) * immediate reval.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) CIFS_I(inode)->time = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) goto cgfi_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) * don't bother with SFU junk here -- just mark inode as needing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) * revalidation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) fattr.cf_uniqueid = CIFS_I(inode)->uniqueid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) fattr.cf_flags |= CIFS_FATTR_NEED_REVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) cifs_fattr_to_inode(inode, &fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) cgfi_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) free_xid(xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) /* Simple function to return a 64 bit hash of string. Rarely called */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) static __u64 simple_hashstr(const char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) const __u64 hash_mult = 1125899906842597ULL; /* a big enough prime */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) __u64 hash = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) while (*str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) hash = (hash + (__u64) *str++) * hash_mult;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) return hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) * cifs_backup_query_path_info - SMB1 fallback code to get ino
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) * Fallback code to get file metadata when we don't have access to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) * @full_path (EACCES) and have backup creds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) * @data will be set to search info result buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) * @resp_buf will be set to cifs resp buf and needs to be freed with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) * cifs_buf_release() when done with @data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) cifs_backup_query_path_info(int xid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) struct cifs_tcon *tcon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) const char *full_path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) void **resp_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) FILE_ALL_INFO **data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) struct cifs_search_info info = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) u16 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) *resp_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) info.endOfSearch = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) if (tcon->unix_ext)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) info.info_level = SMB_FIND_FILE_UNIX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) else if ((tcon->ses->capabilities &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) tcon->ses->server->vals->cap_nt_find) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) info.info_level = SMB_FIND_FILE_INFO_STANDARD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) info.info_level = SMB_FIND_FILE_ID_FULL_DIR_INFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) else /* no srvino useful for fallback to some netapp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) info.info_level = SMB_FIND_FILE_DIRECTORY_INFO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) flags = CIFS_SEARCH_CLOSE_ALWAYS |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) CIFS_SEARCH_CLOSE_AT_END |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) CIFS_SEARCH_BACKUP_SEARCH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) rc = CIFSFindFirst(xid, tcon, full_path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) cifs_sb, NULL, flags, &info, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) *resp_buf = (void *)info.ntwrk_buf_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) *data = (FILE_ALL_INFO *)info.srch_entries_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) cifs_set_fattr_ino(int xid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) struct cifs_tcon *tcon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) struct inode **inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) const char *full_path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) FILE_ALL_INFO *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) struct cifs_fattr *fattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) struct TCP_Server_Info *server = tcon->ses->server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) if (*inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) fattr->cf_uniqueid = CIFS_I(*inode)->uniqueid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) fattr->cf_uniqueid = iunique(sb, ROOT_I);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) * If we have an inode pass a NULL tcon to ensure we don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) * make a round trip to the server. This only works for SMB2+.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) rc = server->ops->get_srv_inum(xid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) *inode ? NULL : tcon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) cifs_sb, full_path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) &fattr->cf_uniqueid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) * If that fails reuse existing ino or generate one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) * and disable server ones
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) if (*inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) fattr->cf_uniqueid = CIFS_I(*inode)->uniqueid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) fattr->cf_uniqueid = iunique(sb, ROOT_I);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) cifs_autodisable_serverino(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) /* If no errors, check for zero root inode (invalid) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) if (fattr->cf_uniqueid == 0 && strlen(full_path) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) cifs_dbg(FYI, "Invalid (0) inodenum\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) if (*inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) /* reuse */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) fattr->cf_uniqueid = CIFS_I(*inode)->uniqueid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) /* make an ino by hashing the UNC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) fattr->cf_flags |= CIFS_FATTR_FAKE_ROOT_INO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) fattr->cf_uniqueid = simple_hashstr(tcon->treeName);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) static inline bool is_inode_cache_good(struct inode *ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) return ino && CIFS_CACHE_READ(CIFS_I(ino)) && CIFS_I(ino)->time != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) cifs_get_inode_info(struct inode **inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) const char *full_path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) FILE_ALL_INFO *in_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) struct super_block *sb, int xid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) const struct cifs_fid *fid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) struct cifs_tcon *tcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) struct TCP_Server_Info *server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) struct tcon_link *tlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) bool adjust_tz = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) struct cifs_fattr fattr = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) bool is_reparse_point = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) FILE_ALL_INFO *data = in_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) FILE_ALL_INFO *tmp_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) void *smb1_backup_rsp_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) int tmprc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) __u32 reparse_tag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) tlink = cifs_sb_tlink(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) if (IS_ERR(tlink))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) return PTR_ERR(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) tcon = tlink_tcon(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) server = tcon->ses->server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) * 1. Fetch file metadata if not provided (data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) if (!data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) if (is_inode_cache_good(*inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) cifs_dbg(FYI, "No need to revalidate cached inode sizes\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) tmp_data = kmalloc(sizeof(FILE_ALL_INFO), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) if (!tmp_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) rc = server->ops->query_path_info(xid, tcon, cifs_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) full_path, tmp_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) &adjust_tz, &is_reparse_point);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) data = tmp_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) * 2. Convert it to internal cifs metadata (fattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) switch (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) * If the file is a reparse point, it is more complicated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) * since we have to check if its reparse tag matches a known
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) * special file type e.g. symlink or fifo or char etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) if ((le32_to_cpu(data->Attributes) & ATTR_REPARSE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) server->ops->query_reparse_tag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) rc = server->ops->query_reparse_tag(xid, tcon, cifs_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) full_path, &reparse_tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) cifs_dbg(FYI, "reparse tag 0x%x\n", reparse_tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) cifs_all_info_to_fattr(&fattr, data, sb, adjust_tz,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) is_reparse_point, reparse_tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) case -EREMOTE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) /* DFS link, no metadata available on this server */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) cifs_create_dfs_fattr(&fattr, sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) case -EACCES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) * perm errors, try again with backup flags if possible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) * For SMB2 and later the backup intent flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) * is already sent if needed on open and there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) * is no path based FindFirst operation to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) * to retry with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) if (backup_cred(cifs_sb) && is_smb1_server(server)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) /* for easier reading */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) FILE_DIRECTORY_INFO *fdi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) SEARCH_ID_FULL_DIR_INFO *si;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) rc = cifs_backup_query_path_info(xid, tcon, sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) full_path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) &smb1_backup_rsp_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) &data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) fdi = (FILE_DIRECTORY_INFO *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) si = (SEARCH_ID_FULL_DIR_INFO *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) cifs_dir_info_to_fattr(&fattr, fdi, cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) fattr.cf_uniqueid = le64_to_cpu(si->UniqueId);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) /* uniqueid set, skip get inum step */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) goto handle_mnt_opt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) /* nothing we can do, bail out */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) cifs_dbg(FYI, "%s: unhandled err rc %d\n", __func__, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) * 3. Get or update inode number (fattr.cf_uniqueid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) cifs_set_fattr_ino(xid, tcon, sb, inode, full_path, data, &fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) * 4. Tweak fattr based on mount options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) handle_mnt_opt:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) /* query for SFU type info if supported and needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) if (fattr.cf_cifsattrs & ATTR_SYSTEM &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) tmprc = cifs_sfu_type(&fattr, full_path, cifs_sb, xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) if (tmprc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) cifs_dbg(FYI, "cifs_sfu_type failed: %d\n", tmprc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) /* fill in 0777 bits from ACL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MODE_FROM_SID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) rc = cifs_acl_to_fattr(cifs_sb, &fattr, *inode, true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) full_path, fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) if (rc == -EREMOTE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) cifs_dbg(FYI, "%s: Get mode from SID failed. rc=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) __func__, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) } else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) rc = cifs_acl_to_fattr(cifs_sb, &fattr, *inode, false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) full_path, fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) if (rc == -EREMOTE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) cifs_dbg(FYI, "%s: Getting ACL failed with error: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) __func__, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) /* fill in remaining high mode bits e.g. SUID, VTX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) cifs_sfu_mode(&fattr, full_path, cifs_sb, xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) /* check for Minshall+French symlinks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) tmprc = check_mf_symlink(xid, tcon, cifs_sb, &fattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) full_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) if (tmprc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) cifs_dbg(FYI, "check_mf_symlink: %d\n", tmprc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) * 5. Update inode with final fattr data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) if (!*inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) *inode = cifs_iget(sb, &fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) if (!*inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) /* we already have inode, update it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) /* if uniqueid is different, return error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) if (unlikely(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) CIFS_I(*inode)->uniqueid != fattr.cf_uniqueid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) CIFS_I(*inode)->time = 0; /* force reval */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) rc = -ESTALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) /* if filetype is different, return error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) if (unlikely(((*inode)->i_mode & S_IFMT) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) (fattr.cf_mode & S_IFMT))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) CIFS_I(*inode)->time = 0; /* force reval */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) rc = -ESTALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) cifs_fattr_to_inode(*inode, &fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) cifs_buf_release(smb1_backup_rsp_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) cifs_put_tlink(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) kfree(tmp_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) smb311_posix_get_inode_info(struct inode **inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) const char *full_path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) struct super_block *sb, unsigned int xid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) struct cifs_tcon *tcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) struct tcon_link *tlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) bool adjust_tz = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) struct cifs_fattr fattr = {0};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) bool symlink = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) struct smb311_posix_qinfo *data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) int tmprc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) tlink = cifs_sb_tlink(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) if (IS_ERR(tlink))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) return PTR_ERR(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) tcon = tlink_tcon(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) * 1. Fetch file metadata
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) if (is_inode_cache_good(*inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) cifs_dbg(FYI, "No need to revalidate cached inode sizes\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) data = kmalloc(sizeof(struct smb311_posix_qinfo), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) if (!data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) rc = smb311_posix_query_path_info(xid, tcon, cifs_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) full_path, data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) &adjust_tz, &symlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) * 2. Convert it to internal cifs metadata (fattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) switch (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) smb311_posix_info_to_fattr(&fattr, data, sb, adjust_tz, symlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) case -EREMOTE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) /* DFS link, no metadata available on this server */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) cifs_create_dfs_fattr(&fattr, sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) case -EACCES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) * For SMB2 and later the backup intent flag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) * is already sent if needed on open and there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) * is no path based FindFirst operation to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) * to retry with so nothing we can do, bail out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) cifs_dbg(FYI, "%s: unhandled err rc %d\n", __func__, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) * 3. Tweak fattr based on mount options
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) /* check for Minshall+French symlinks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) tmprc = check_mf_symlink(xid, tcon, cifs_sb, &fattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) full_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) if (tmprc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) cifs_dbg(FYI, "check_mf_symlink: %d\n", tmprc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) * 4. Update inode with final fattr data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) if (!*inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) *inode = cifs_iget(sb, &fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) if (!*inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) /* we already have inode, update it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) /* if uniqueid is different, return error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) if (unlikely(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) CIFS_I(*inode)->uniqueid != fattr.cf_uniqueid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) CIFS_I(*inode)->time = 0; /* force reval */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) rc = -ESTALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) /* if filetype is different, return error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) if (unlikely(((*inode)->i_mode & S_IFMT) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) (fattr.cf_mode & S_IFMT))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) CIFS_I(*inode)->time = 0; /* force reval */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) rc = -ESTALE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) cifs_fattr_to_inode(*inode, &fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) cifs_put_tlink(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) kfree(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) static const struct inode_operations cifs_ipc_inode_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) .lookup = cifs_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) cifs_find_inode(struct inode *inode, void *opaque)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) struct cifs_fattr *fattr = (struct cifs_fattr *) opaque;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) /* don't match inode with different uniqueid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) if (CIFS_I(inode)->uniqueid != fattr->cf_uniqueid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) /* use createtime like an i_generation field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) if (CIFS_I(inode)->createtime != fattr->cf_createtime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) /* don't match inode of different type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) if (inode_wrong_type(inode, fattr->cf_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) /* if it's not a directory or has no dentries, then flag it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) if (S_ISDIR(inode->i_mode) && !hlist_empty(&inode->i_dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) fattr->cf_flags |= CIFS_FATTR_INO_COLLISION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) cifs_init_inode(struct inode *inode, void *opaque)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) struct cifs_fattr *fattr = (struct cifs_fattr *) opaque;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) CIFS_I(inode)->uniqueid = fattr->cf_uniqueid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) CIFS_I(inode)->createtime = fattr->cf_createtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) * walk dentry list for an inode and report whether it has aliases that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) * are hashed. We use this to determine if a directory inode can actually
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) * be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) inode_has_hashed_dentries(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) if (!d_unhashed(dentry) || IS_ROOT(dentry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) /* Given fattrs, get a corresponding inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) struct inode *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) cifs_iget(struct super_block *sb, struct cifs_fattr *fattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) unsigned long hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) retry_iget5_locked:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) cifs_dbg(FYI, "looking for uniqueid=%llu\n", fattr->cf_uniqueid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) /* hash down to 32-bits on 32-bit arch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) hash = cifs_uniqueid_to_ino_t(fattr->cf_uniqueid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) inode = iget5_locked(sb, hash, cifs_find_inode, cifs_init_inode, fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) if (inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) /* was there a potentially problematic inode collision? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) if (fattr->cf_flags & CIFS_FATTR_INO_COLLISION) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) fattr->cf_flags &= ~CIFS_FATTR_INO_COLLISION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) if (inode_has_hashed_dentries(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) cifs_autodisable_serverino(CIFS_SB(sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) fattr->cf_uniqueid = iunique(sb, ROOT_I);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) goto retry_iget5_locked;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) cifs_fattr_to_inode(inode, fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) if (sb->s_flags & SB_NOATIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) inode->i_flags |= S_NOATIME | S_NOCMTIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) if (inode->i_state & I_NEW) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) inode->i_ino = hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) #ifdef CONFIG_CIFS_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) /* initialize per-inode cache cookie pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) CIFS_I(inode)->fscache = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) unlock_new_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) /* gets root inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) struct inode *cifs_root_iget(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) unsigned int xid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) struct inode *inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) long rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) char *path = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_USE_PREFIX_PATH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) && cifs_sb->prepath) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) len = strlen(cifs_sb->prepath);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) path = kzalloc(len + 2 /* leading sep + null */, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) if (path == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) path[0] = '/';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) memcpy(path+1, cifs_sb->prepath, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) path = kstrdup("", GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) if (path == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) xid = get_xid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) if (tcon->unix_ext) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) rc = cifs_get_inode_info_unix(&inode, path, sb, xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) /* some servers mistakenly claim POSIX support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) if (rc != -EOPNOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) goto iget_no_retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) cifs_dbg(VFS, "server does not support POSIX extensions\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) tcon->unix_ext = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) convert_delimiter(path, CIFS_DIR_SEP(cifs_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) if (tcon->posix_extensions)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) rc = smb311_posix_get_inode_info(&inode, path, sb, xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) rc = cifs_get_inode_info(&inode, path, NULL, sb, xid, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) iget_no_retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) if (!inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) inode = ERR_PTR(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) #ifdef CONFIG_CIFS_FSCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) /* populate tcon->resource_id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) tcon->resource_id = CIFS_I(inode)->uniqueid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) if (rc && tcon->pipe) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) cifs_dbg(FYI, "ipc connection - fake read inode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) inode->i_mode |= S_IFDIR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) set_nlink(inode, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) inode->i_op = &cifs_ipc_inode_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) inode->i_fop = &simple_dir_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) inode->i_uid = cifs_sb->mnt_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) inode->i_gid = cifs_sb->mnt_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) } else if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) iget_failed(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) inode = ERR_PTR(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) kfree(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) free_xid(xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) cifs_set_file_info(struct inode *inode, struct iattr *attrs, unsigned int xid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) char *full_path, __u32 dosattr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) bool set_time = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) struct TCP_Server_Info *server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) FILE_BASIC_INFO info_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) if (attrs == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) server = cifs_sb_master_tcon(cifs_sb)->ses->server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) if (!server->ops->set_file_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) info_buf.Pad = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) if (attrs->ia_valid & ATTR_ATIME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) set_time = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) info_buf.LastAccessTime =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_atime));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) info_buf.LastAccessTime = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) if (attrs->ia_valid & ATTR_MTIME) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) set_time = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) info_buf.LastWriteTime =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_mtime));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) info_buf.LastWriteTime = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) * Samba throws this field away, but windows may actually use it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) * Do not set ctime unless other time stamps are changed explicitly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) * (i.e. by utimes()) since we would then have a mix of client and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) * server times.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) if (set_time && (attrs->ia_valid & ATTR_CTIME)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) cifs_dbg(FYI, "CIFS - CTIME changed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) info_buf.ChangeTime =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) cpu_to_le64(cifs_UnixTimeToNT(attrs->ia_ctime));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) info_buf.ChangeTime = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) info_buf.CreationTime = 0; /* don't change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) info_buf.Attributes = cpu_to_le32(dosattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) return server->ops->set_file_info(inode, full_path, &info_buf, xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) * Open the given file (if it isn't already), set the DELETE_ON_CLOSE bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) * and rename it to a random name that hopefully won't conflict with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) * anything else.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) cifs_rename_pending_delete(const char *full_path, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) const unsigned int xid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) int oplock = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) struct cifs_fid fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) struct cifs_open_parms oparms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) struct inode *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) struct cifsInodeInfo *cifsInode = CIFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) struct tcon_link *tlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) struct cifs_tcon *tcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) __u32 dosattr, origattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) FILE_BASIC_INFO *info_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) tlink = cifs_sb_tlink(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) if (IS_ERR(tlink))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) return PTR_ERR(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) tcon = tlink_tcon(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) * We cannot rename the file if the server doesn't support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) * CAP_INFOLEVEL_PASSTHRU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) if (!(tcon->ses->capabilities & CAP_INFOLEVEL_PASSTHRU)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) rc = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) oparms.tcon = tcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) oparms.cifs_sb = cifs_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) oparms.desired_access = DELETE | FILE_WRITE_ATTRIBUTES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) oparms.create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) oparms.disposition = FILE_OPEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) oparms.path = full_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) oparms.fid = &fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) oparms.reconnect = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) rc = CIFS_open(xid, &oparms, &oplock, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) if (rc != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) origattr = cifsInode->cifsAttrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) if (origattr == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) origattr |= ATTR_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) dosattr = origattr & ~ATTR_READONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) if (dosattr == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) dosattr |= ATTR_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) dosattr |= ATTR_HIDDEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) /* set ATTR_HIDDEN and clear ATTR_READONLY, but only if needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) if (dosattr != origattr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) info_buf = kzalloc(sizeof(*info_buf), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) if (info_buf == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) goto out_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) info_buf->Attributes = cpu_to_le32(dosattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) rc = CIFSSMBSetFileInfo(xid, tcon, info_buf, fid.netfid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) current->tgid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) /* although we would like to mark the file hidden
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) if that fails we will still try to rename it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) if (!rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) cifsInode->cifsAttrs = dosattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) dosattr = origattr; /* since not able to change them */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) /* rename the file */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) rc = CIFSSMBRenameOpenFile(xid, tcon, fid.netfid, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) cifs_sb->local_nls,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) cifs_remap(cifs_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) if (rc != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) rc = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) goto undo_setattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) /* try to set DELETE_ON_CLOSE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) if (!test_bit(CIFS_INO_DELETE_PENDING, &cifsInode->flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) rc = CIFSSMBSetFileDisposition(xid, tcon, true, fid.netfid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) current->tgid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) * some samba versions return -ENOENT when we try to set the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) * file disposition here. Likely a samba bug, but work around
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) * it for now. This means that some cifsXXX files may hang
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) * around after they shouldn't.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) * BB: remove this hack after more servers have the fix
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) if (rc == -ENOENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) else if (rc != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) rc = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) goto undo_rename;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) set_bit(CIFS_INO_DELETE_PENDING, &cifsInode->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) out_close:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) CIFSSMBClose(xid, tcon, fid.netfid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) kfree(info_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) cifs_put_tlink(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) * reset everything back to the original state. Don't bother
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) * dealing with errors here since we can't do anything about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) * them anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) undo_rename:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) CIFSSMBRenameOpenFile(xid, tcon, fid.netfid, dentry->d_name.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) cifs_sb->local_nls, cifs_remap(cifs_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) undo_setattr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) if (dosattr != origattr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) info_buf->Attributes = cpu_to_le32(origattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) if (!CIFSSMBSetFileInfo(xid, tcon, info_buf, fid.netfid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) current->tgid))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) cifsInode->cifsAttrs = origattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) goto out_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) /* copied from fs/nfs/dir.c with small changes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) cifs_drop_nlink(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) if (inode->i_nlink > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) drop_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) * If d_inode(dentry) is null (usually meaning the cached dentry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) * is a negative dentry) then we would attempt a standard SMB delete, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) * if that fails we can not attempt the fall back mechanisms on EACCES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) * but will return the EACCES to the caller. Note that the VFS does not call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) * unlink on negative dentries currently.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) int cifs_unlink(struct inode *dir, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) unsigned int xid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) char *full_path = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) struct inode *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) struct cifsInodeInfo *cifs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) struct super_block *sb = dir->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) struct cifs_sb_info *cifs_sb = CIFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) struct tcon_link *tlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) struct cifs_tcon *tcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) struct TCP_Server_Info *server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) struct iattr *attrs = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) __u32 dosattr = 0, origattr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) cifs_dbg(FYI, "cifs_unlink, dir=0x%p, dentry=0x%p\n", dir, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) tlink = cifs_sb_tlink(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) if (IS_ERR(tlink))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) return PTR_ERR(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) tcon = tlink_tcon(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) server = tcon->ses->server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) xid = get_xid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) if (tcon->nodelete) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) rc = -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) goto unlink_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) /* Unlink can be called from rename so we can not take the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) * sb->s_vfs_rename_mutex here */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) full_path = build_path_from_dentry(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) if (full_path == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) goto unlink_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) if (cap_unix(tcon->ses) && (CIFS_UNIX_POSIX_PATH_OPS_CAP &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) le64_to_cpu(tcon->fsUnixInfo.Capability))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) rc = CIFSPOSIXDelFile(xid, tcon, full_path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) SMB_POSIX_UNLINK_FILE_TARGET, cifs_sb->local_nls,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) cifs_remap(cifs_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) cifs_dbg(FYI, "posix del rc %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) if ((rc == 0) || (rc == -ENOENT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) goto psx_del_no_retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) retry_std_delete:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) if (!server->ops->unlink) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) rc = -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) goto psx_del_no_retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) rc = server->ops->unlink(xid, tcon, full_path, cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) psx_del_no_retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) if (!rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) if (inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) cifs_drop_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) } else if (rc == -ENOENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) d_drop(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) } else if (rc == -EBUSY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) if (server->ops->rename_pending_delete) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) rc = server->ops->rename_pending_delete(full_path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) dentry, xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) if (rc == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) cifs_drop_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) } else if ((rc == -EACCES) && (dosattr == 0) && inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) attrs = kzalloc(sizeof(*attrs), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) if (attrs == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) goto out_reval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) /* try to reset dos attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) cifs_inode = CIFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) origattr = cifs_inode->cifsAttrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) if (origattr == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) origattr |= ATTR_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) dosattr = origattr & ~ATTR_READONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) if (dosattr == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) dosattr |= ATTR_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) dosattr |= ATTR_HIDDEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) rc = cifs_set_file_info(inode, attrs, xid, full_path, dosattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) if (rc != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) goto out_reval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) goto retry_std_delete;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) /* undo the setattr if we errored out and it's needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) if (rc != 0 && dosattr != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) cifs_set_file_info(inode, attrs, xid, full_path, origattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) out_reval:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) if (inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) cifs_inode = CIFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) cifs_inode->time = 0; /* will force revalidate to get info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) when needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) dir->i_ctime = dir->i_mtime = current_time(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) cifs_inode = CIFS_I(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) CIFS_I(dir)->time = 0; /* force revalidate of dir as well */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) unlink_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) kfree(full_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) kfree(attrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) free_xid(xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) cifs_put_tlink(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) cifs_mkdir_qinfo(struct inode *parent, struct dentry *dentry, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) const char *full_path, struct cifs_sb_info *cifs_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) struct cifs_tcon *tcon, const unsigned int xid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) struct inode *inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) if (tcon->posix_extensions)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) rc = smb311_posix_get_inode_info(&inode, full_path, parent->i_sb, xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) else if (tcon->unix_ext)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) rc = cifs_get_inode_info_unix(&inode, full_path, parent->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) rc = cifs_get_inode_info(&inode, full_path, NULL, parent->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) xid, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) * setting nlink not necessary except in cases where we failed to get it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) * from the server or was set bogus. Also, since this is a brand new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) * inode, no need to grab the i_lock before setting the i_nlink.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) if (inode->i_nlink < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) set_nlink(inode, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) mode &= ~current_umask();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) /* must turn on setgid bit if parent dir has it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) if (parent->i_mode & S_ISGID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) mode |= S_ISGID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) if (tcon->unix_ext) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) struct cifs_unix_set_info_args args = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) .mode = mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) .ctime = NO_CHANGE_64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) .atime = NO_CHANGE_64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) .mtime = NO_CHANGE_64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) .device = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) args.uid = current_fsuid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) if (parent->i_mode & S_ISGID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) args.gid = parent->i_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) args.gid = current_fsgid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) args.uid = INVALID_UID; /* no change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) args.gid = INVALID_GID; /* no change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) CIFSSMBUnixSetPathInfo(xid, tcon, full_path, &args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) cifs_sb->local_nls,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) cifs_remap(cifs_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) struct TCP_Server_Info *server = tcon->ses->server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) (mode & S_IWUGO) == 0 && server->ops->mkdir_setinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) server->ops->mkdir_setinfo(inode, full_path, cifs_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) tcon, xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) inode->i_mode = (mode | S_IFDIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) inode->i_uid = current_fsuid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) if (inode->i_mode & S_ISGID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) inode->i_gid = parent->i_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) inode->i_gid = current_fsgid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) d_instantiate(dentry, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) cifs_posix_mkdir(struct inode *inode, struct dentry *dentry, umode_t mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) const char *full_path, struct cifs_sb_info *cifs_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) struct cifs_tcon *tcon, const unsigned int xid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) u32 oplock = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) FILE_UNIX_BASIC_INFO *info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) struct inode *newinode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) struct cifs_fattr fattr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) info = kzalloc(sizeof(FILE_UNIX_BASIC_INFO), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) if (info == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) goto posix_mkdir_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) mode &= ~current_umask();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) rc = CIFSPOSIXCreate(xid, tcon, SMB_O_DIRECTORY | SMB_O_CREAT, mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) NULL /* netfid */, info, &oplock, full_path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) cifs_sb->local_nls, cifs_remap(cifs_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) if (rc == -EOPNOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) goto posix_mkdir_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) else if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) cifs_dbg(FYI, "posix mkdir returned 0x%x\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) d_drop(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) goto posix_mkdir_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) if (info->Type == cpu_to_le32(-1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) /* no return info, go query for it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) goto posix_mkdir_get_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) * BB check (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID ) to see if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) * need to set uid/gid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) cifs_unix_basic_to_fattr(&fattr, info, cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) cifs_fill_uniqueid(inode->i_sb, &fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) newinode = cifs_iget(inode->i_sb, &fattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) if (!newinode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) goto posix_mkdir_get_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) d_instantiate(dentry, newinode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) #ifdef CONFIG_CIFS_DEBUG2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) cifs_dbg(FYI, "instantiated dentry %p %pd to inode %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) dentry, dentry, newinode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) if (newinode->i_nlink != 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) cifs_dbg(FYI, "unexpected number of links %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) newinode->i_nlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) posix_mkdir_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) kfree(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) posix_mkdir_get_info:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) rc = cifs_mkdir_qinfo(inode, dentry, mode, full_path, cifs_sb, tcon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) goto posix_mkdir_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) int cifs_mkdir(struct inode *inode, struct dentry *direntry, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) unsigned int xid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) struct cifs_sb_info *cifs_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) struct tcon_link *tlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) struct cifs_tcon *tcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) struct TCP_Server_Info *server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) char *full_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) cifs_dbg(FYI, "In cifs_mkdir, mode = %04ho inode = 0x%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) mode, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) cifs_sb = CIFS_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) tlink = cifs_sb_tlink(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) if (IS_ERR(tlink))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) return PTR_ERR(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) tcon = tlink_tcon(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) xid = get_xid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) full_path = build_path_from_dentry(direntry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) if (full_path == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) goto mkdir_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) server = tcon->ses->server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) if ((server->ops->posix_mkdir) && (tcon->posix_extensions)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) rc = server->ops->posix_mkdir(xid, inode, mode, tcon, full_path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) d_drop(direntry); /* for time being always refresh inode info */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) goto mkdir_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) if (cap_unix(tcon->ses) && (CIFS_UNIX_POSIX_PATH_OPS_CAP &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) le64_to_cpu(tcon->fsUnixInfo.Capability))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) rc = cifs_posix_mkdir(inode, direntry, mode, full_path, cifs_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) tcon, xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) if (rc != -EOPNOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) goto mkdir_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) if (!server->ops->mkdir) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) rc = -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) goto mkdir_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) /* BB add setting the equivalent of mode via CreateX w/ACLs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) rc = server->ops->mkdir(xid, inode, mode, tcon, full_path, cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) cifs_dbg(FYI, "cifs_mkdir returned 0x%x\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) d_drop(direntry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) goto mkdir_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) /* TODO: skip this for smb2/smb3 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) rc = cifs_mkdir_qinfo(inode, direntry, mode, full_path, cifs_sb, tcon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) mkdir_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) * Force revalidate to get parent dir info when needed since cached
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) * attributes are invalid now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) CIFS_I(inode)->time = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) kfree(full_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) free_xid(xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) cifs_put_tlink(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) int cifs_rmdir(struct inode *inode, struct dentry *direntry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) unsigned int xid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) struct cifs_sb_info *cifs_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) struct tcon_link *tlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) struct cifs_tcon *tcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) struct TCP_Server_Info *server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) char *full_path = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) struct cifsInodeInfo *cifsInode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) cifs_dbg(FYI, "cifs_rmdir, inode = 0x%p\n", inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) xid = get_xid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) full_path = build_path_from_dentry(direntry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) if (full_path == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) goto rmdir_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) cifs_sb = CIFS_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) tlink = cifs_sb_tlink(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) if (IS_ERR(tlink)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) rc = PTR_ERR(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) goto rmdir_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) tcon = tlink_tcon(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) server = tcon->ses->server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) if (!server->ops->rmdir) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) rc = -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) cifs_put_tlink(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) goto rmdir_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) if (tcon->nodelete) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) rc = -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) cifs_put_tlink(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) goto rmdir_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) rc = server->ops->rmdir(xid, tcon, full_path, cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) cifs_put_tlink(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) if (!rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) spin_lock(&d_inode(direntry)->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) i_size_write(d_inode(direntry), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) clear_nlink(d_inode(direntry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) spin_unlock(&d_inode(direntry)->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) cifsInode = CIFS_I(d_inode(direntry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) /* force revalidate to go get info when needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) cifsInode->time = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) cifsInode = CIFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) * Force revalidate to get parent dir info when needed since cached
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) * attributes are invalid now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) cifsInode->time = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) d_inode(direntry)->i_ctime = inode->i_ctime = inode->i_mtime =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) rmdir_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) kfree(full_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) free_xid(xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) cifs_do_rename(const unsigned int xid, struct dentry *from_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) const char *from_path, struct dentry *to_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) const char *to_path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) struct cifs_sb_info *cifs_sb = CIFS_SB(from_dentry->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) struct tcon_link *tlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) struct cifs_tcon *tcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) struct TCP_Server_Info *server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) struct cifs_fid fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) struct cifs_open_parms oparms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) int oplock, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) tlink = cifs_sb_tlink(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) if (IS_ERR(tlink))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) return PTR_ERR(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) tcon = tlink_tcon(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) server = tcon->ses->server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) if (!server->ops->rename)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) /* try path-based rename first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) rc = server->ops->rename(xid, tcon, from_path, to_path, cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) * Don't bother with rename by filehandle unless file is busy and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) * source. Note that cross directory moves do not work with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) * rename by filehandle to various Windows servers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) if (rc == 0 || rc != -EBUSY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) goto do_rename_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) /* Don't fall back to using SMB on SMB 2+ mount */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) if (server->vals->protocol_id != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) goto do_rename_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) /* open-file renames don't work across directories */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) if (to_dentry->d_parent != from_dentry->d_parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) goto do_rename_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) oparms.tcon = tcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) oparms.cifs_sb = cifs_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) /* open the file to be renamed -- we need DELETE perms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) oparms.desired_access = DELETE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) oparms.create_options = cifs_create_options(cifs_sb, CREATE_NOT_DIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) oparms.disposition = FILE_OPEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) oparms.path = from_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) oparms.fid = &fid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) oparms.reconnect = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) rc = CIFS_open(xid, &oparms, &oplock, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) if (rc == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) rc = CIFSSMBRenameOpenFile(xid, tcon, fid.netfid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) (const char *) to_dentry->d_name.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) cifs_sb->local_nls, cifs_remap(cifs_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) CIFSSMBClose(xid, tcon, fid.netfid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) do_rename_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) if (rc == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) d_move(from_dentry, to_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) cifs_put_tlink(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) cifs_rename2(struct inode *source_dir, struct dentry *source_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) struct inode *target_dir, struct dentry *target_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) char *from_name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) char *to_name = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) struct cifs_sb_info *cifs_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) struct tcon_link *tlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) struct cifs_tcon *tcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) FILE_UNIX_BASIC_INFO *info_buf_source = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) FILE_UNIX_BASIC_INFO *info_buf_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) unsigned int xid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) int rc, tmprc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) if (flags & ~RENAME_NOREPLACE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) cifs_sb = CIFS_SB(source_dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) tlink = cifs_sb_tlink(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) if (IS_ERR(tlink))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) return PTR_ERR(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) tcon = tlink_tcon(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) xid = get_xid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) * we already have the rename sem so we do not need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) * grab it again here to protect the path integrity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) from_name = build_path_from_dentry(source_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) if (from_name == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) goto cifs_rename_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) to_name = build_path_from_dentry(target_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) if (to_name == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) goto cifs_rename_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) rc = cifs_do_rename(xid, source_dentry, from_name, target_dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) to_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) * No-replace is the natural behavior for CIFS, so skip unlink hacks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) if (flags & RENAME_NOREPLACE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) goto cifs_rename_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) if (rc == -EEXIST && tcon->unix_ext) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) * Are src and dst hardlinks of same inode? We can only tell
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) * with unix extensions enabled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) info_buf_source =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) kmalloc_array(2, sizeof(FILE_UNIX_BASIC_INFO),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) if (info_buf_source == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) goto cifs_rename_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) info_buf_target = info_buf_source + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) tmprc = CIFSSMBUnixQPathInfo(xid, tcon, from_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) info_buf_source,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) cifs_sb->local_nls,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) cifs_remap(cifs_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) if (tmprc != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) goto unlink_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) tmprc = CIFSSMBUnixQPathInfo(xid, tcon, to_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) info_buf_target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) cifs_sb->local_nls,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) cifs_remap(cifs_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) if (tmprc == 0 && (info_buf_source->UniqueId ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) info_buf_target->UniqueId)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) /* same file, POSIX says that this is a noop */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) goto cifs_rename_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) * else ... BB we could add the same check for Windows by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) * checking the UniqueId via FILE_INTERNAL_INFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) unlink_target:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) /* Try unlinking the target dentry if it's not negative */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) if (d_really_is_positive(target_dentry) && (rc == -EACCES || rc == -EEXIST)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) if (d_is_dir(target_dentry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) tmprc = cifs_rmdir(target_dir, target_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) tmprc = cifs_unlink(target_dir, target_dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) if (tmprc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) goto cifs_rename_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) rc = cifs_do_rename(xid, source_dentry, from_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) target_dentry, to_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) /* force revalidate to go get info when needed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) CIFS_I(source_dir)->time = CIFS_I(target_dir)->time = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) source_dir->i_ctime = source_dir->i_mtime = target_dir->i_ctime =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) target_dir->i_mtime = current_time(source_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) cifs_rename_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) kfree(info_buf_source);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) kfree(from_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) kfree(to_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) free_xid(xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) cifs_put_tlink(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) static bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) cifs_inode_needs_reval(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) struct cifsInodeInfo *cifs_i = CIFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) if (cifs_i->time == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) if (CIFS_CACHE_READ(cifs_i))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) if (!lookupCacheEnabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) if (!cifs_sb->actimeo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) if (!time_in_range(jiffies, cifs_i->time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) cifs_i->time + cifs_sb->actimeo))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) /* hardlinked files w/ noserverino get "special" treatment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SERVER_INUM) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) S_ISREG(inode->i_mode) && inode->i_nlink != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) * Zap the cache. Called when invalid_mapping flag is set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) cifs_invalidate_mapping(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) if (inode->i_mapping && inode->i_mapping->nrpages != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) rc = invalidate_inode_pages2(inode->i_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) cifs_dbg(VFS, "%s: Could not invalidate inode %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) __func__, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) cifs_fscache_reset_inode_cookie(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) * cifs_wait_bit_killable - helper for functions that are sleeping on bit locks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) * @word: long word containing the bit lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) cifs_wait_bit_killable(struct wait_bit_key *key, int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) freezable_schedule_unsafe();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) if (signal_pending_state(mode, current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) return -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) cifs_revalidate_mapping(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) unsigned long *flags = &CIFS_I(inode)->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) /* swapfiles are not supposed to be shared */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) if (IS_SWAPFILE(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) rc = wait_on_bit_lock_action(flags, CIFS_INO_LOCK, cifs_wait_bit_killable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) TASK_KILLABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) if (test_and_clear_bit(CIFS_INO_INVALID_MAPPING, flags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) rc = cifs_invalidate_mapping(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) set_bit(CIFS_INO_INVALID_MAPPING, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) clear_bit_unlock(CIFS_INO_LOCK, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) smp_mb__after_atomic();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264) wake_up_bit(flags, CIFS_INO_LOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) cifs_zap_mapping(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) set_bit(CIFS_INO_INVALID_MAPPING, &CIFS_I(inode)->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) return cifs_revalidate_mapping(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) int cifs_revalidate_file_attr(struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) struct inode *inode = file_inode(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) struct cifsFileInfo *cfile = (struct cifsFileInfo *) filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) if (!cifs_inode_needs_reval(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) if (tlink_tcon(cfile->tlink)->unix_ext)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) rc = cifs_get_file_info_unix(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) rc = cifs_get_file_info(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) int cifs_revalidate_dentry_attr(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) unsigned int xid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) struct inode *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) struct super_block *sb = dentry->d_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) char *full_path = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) if (inode == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) if (!cifs_inode_needs_reval(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) xid = get_xid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) /* can not safely grab the rename sem here if rename calls revalidate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) since that would deadlock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) full_path = build_path_from_dentry(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) if (full_path == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) cifs_dbg(FYI, "Update attributes: %s inode 0x%p count %d dentry: 0x%p d_time %ld jiffies %ld\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) full_path, inode, inode->i_count.counter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320) dentry, cifs_get_time(dentry), jiffies);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) again:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) if (cifs_sb_master_tcon(CIFS_SB(sb))->posix_extensions)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) rc = smb311_posix_get_inode_info(&inode, full_path, sb, xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) else if (cifs_sb_master_tcon(CIFS_SB(sb))->unix_ext)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) rc = cifs_get_inode_info_unix(&inode, full_path, sb, xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) rc = cifs_get_inode_info(&inode, full_path, NULL, sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) xid, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) if (rc == -EAGAIN && count++ < 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) goto again;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) kfree(full_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) free_xid(xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) int cifs_revalidate_file(struct file *filp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) struct inode *inode = file_inode(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) rc = cifs_revalidate_file_attr(filp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) return cifs_revalidate_mapping(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) /* revalidate a dentry's inode attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) int cifs_revalidate_dentry(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) struct inode *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) rc = cifs_revalidate_dentry_attr(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) return cifs_revalidate_mapping(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) int cifs_getattr(const struct path *path, struct kstat *stat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) u32 request_mask, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) struct dentry *dentry = path->dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) struct cifs_sb_info *cifs_sb = CIFS_SB(dentry->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) struct inode *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) * We need to be sure that all dirty pages are written and the server
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) * has actual ctime, mtime and file length.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) if ((request_mask & (STATX_CTIME | STATX_MTIME | STATX_SIZE | STATX_BLOCKS)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) !CIFS_CACHE_READ(CIFS_I(inode)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) inode->i_mapping && inode->i_mapping->nrpages != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) rc = filemap_fdatawait(inode->i_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) mapping_set_error(inode->i_mapping, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) if ((flags & AT_STATX_SYNC_TYPE) == AT_STATX_FORCE_SYNC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) CIFS_I(inode)->time = 0; /* force revalidate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) * If the caller doesn't require syncing, only sync if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) * necessary (e.g. due to earlier truncate or setattr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) * invalidating the cached metadata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) if (((flags & AT_STATX_SYNC_TYPE) != AT_STATX_DONT_SYNC) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) (CIFS_I(inode)->time == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) rc = cifs_revalidate_dentry_attr(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) generic_fillattr(inode, stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) stat->blksize = cifs_sb->bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) stat->ino = CIFS_I(inode)->uniqueid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) /* old CIFS Unix Extensions doesn't return create time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) if (CIFS_I(inode)->createtime) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) stat->result_mask |= STATX_BTIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) stat->btime =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) cifs_NTtimeToUnix(cpu_to_le64(CIFS_I(inode)->createtime));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) stat->attributes_mask |= (STATX_ATTR_COMPRESSED | STATX_ATTR_ENCRYPTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) if (CIFS_I(inode)->cifsAttrs & FILE_ATTRIBUTE_COMPRESSED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) stat->attributes |= STATX_ATTR_COMPRESSED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) if (CIFS_I(inode)->cifsAttrs & FILE_ATTRIBUTE_ENCRYPTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) stat->attributes |= STATX_ATTR_ENCRYPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) * If on a multiuser mount without unix extensions or cifsacl being
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) * enabled, and the admin hasn't overridden them, set the ownership
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) * to the fsuid/fsgid of the current process.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) !(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) !tcon->unix_ext) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_UID))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) stat->uid = current_fsuid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_OVERR_GID))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) stat->gid = current_fsgid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) int cifs_fiemap(struct inode *inode, struct fiemap_extent_info *fei, u64 start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) u64 len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) struct cifsInodeInfo *cifs_i = CIFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) struct cifs_sb_info *cifs_sb = CIFS_SB(cifs_i->vfs_inode.i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) struct TCP_Server_Info *server = tcon->ses->server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) struct cifsFileInfo *cfile;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) * We need to be sure that all dirty pages are written as they
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) * might fill holes on the server.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) if (!CIFS_CACHE_READ(CIFS_I(inode)) && inode->i_mapping &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) inode->i_mapping->nrpages != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) rc = filemap_fdatawait(inode->i_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) mapping_set_error(inode->i_mapping, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) cfile = find_readable_file(cifs_i, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) if (cfile == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) if (server->ops->fiemap) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) rc = server->ops->fiemap(tcon, cfile, fei, start, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) cifsFileInfo_put(cfile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) cifsFileInfo_put(cfile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) return -ENOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) int cifs_truncate_page(struct address_space *mapping, loff_t from)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) pgoff_t index = from >> PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) unsigned offset = from & (PAGE_SIZE - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) page = grab_cache_page(mapping, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) if (!page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) zero_user_segment(page, offset, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) void cifs_setsize(struct inode *inode, loff_t offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) struct cifsInodeInfo *cifs_i = CIFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) i_size_write(inode, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) /* Cached inode must be refreshed on truncate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) cifs_i->time = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) truncate_pagecache(inode, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) cifs_set_file_size(struct inode *inode, struct iattr *attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) unsigned int xid, char *full_path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) struct cifsFileInfo *open_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) struct cifsInodeInfo *cifsInode = CIFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) struct tcon_link *tlink = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) struct cifs_tcon *tcon = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) struct TCP_Server_Info *server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) * To avoid spurious oplock breaks from server, in the case of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) * inodes that we already have open, avoid doing path based
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) * setting of file size if we can do it by handle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) * This keeps our caching token (oplock) and avoids timeouts
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) * when the local oplock break takes longer to flush
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) * writebehind data than the SMB timeout for the SetPathInfo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) * request would allow
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) open_file = find_writable_file(cifsInode, FIND_WR_FSUID_ONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) if (open_file) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) tcon = tlink_tcon(open_file->tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) server = tcon->ses->server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527) if (server->ops->set_file_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) rc = server->ops->set_file_size(xid, tcon, open_file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) attrs->ia_size, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) rc = -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) cifsFileInfo_put(open_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) cifs_dbg(FYI, "SetFSize for attrs rc = %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) if (!rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) goto set_size_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540) if (tcon == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) tlink = cifs_sb_tlink(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) if (IS_ERR(tlink))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) return PTR_ERR(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) tcon = tlink_tcon(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) server = tcon->ses->server;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549) * Set file size by pathname rather than by handle either because no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) * valid, writeable file handle for it was found or because there was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) * an error setting it by handle.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553) if (server->ops->set_path_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) rc = server->ops->set_path_size(xid, tcon, full_path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555) attrs->ia_size, cifs_sb, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) rc = -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558) cifs_dbg(FYI, "SetEOF by path (setattrs) rc = %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560) if (tlink)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) cifs_put_tlink(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) set_size_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564) if (rc == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) cifsInode->server_eof = attrs->ia_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) cifs_setsize(inode, attrs->ia_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) * i_blocks is not related to (i_size / i_blksize), but instead
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) * 512 byte (2**9) size is required for calculating num blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) * Until we can query the server for actual allocation size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) * this is best estimate we have for blocks allocated for a file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572) * Number of blocks must be rounded up so size 1 is not 0 blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574) inode->i_blocks = (512 - 1 + attrs->ia_size) >> 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) * The man page of truncate says if the size changed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) * then the st_ctime and st_mtime fields for the file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579) * are updated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581) attrs->ia_ctime = attrs->ia_mtime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) attrs->ia_valid |= ATTR_CTIME | ATTR_MTIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) cifs_truncate_page(inode->i_mapping, inode->i_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) unsigned int xid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595) char *full_path = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) struct inode *inode = d_inode(direntry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) struct cifsInodeInfo *cifsInode = CIFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598) struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) struct tcon_link *tlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) struct cifs_tcon *pTcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) struct cifs_unix_set_info_args *args = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) struct cifsFileInfo *open_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) cifs_dbg(FYI, "setattr_unix on file %pd attrs->ia_valid=0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) direntry, attrs->ia_valid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) xid = get_xid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) attrs->ia_valid |= ATTR_FORCE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) rc = setattr_prepare(direntry, attrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) full_path = build_path_from_dentry(direntry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617) if (full_path == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) * Attempt to flush data before changing attributes. We need to do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) * this for ATTR_SIZE and ATTR_MTIME for sure, and if we change the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) * ownership or mode then we may also need to do this. Here, we take
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) * the safe way out and just do the flush on all setattr requests. If
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) * the flush returns error, store it to report later and continue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) * BB: This should be smarter. Why bother flushing pages that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) * will be truncated anyway? Also, should we error out here if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) * the flush returns error?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633) rc = filemap_write_and_wait(inode->i_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) if (is_interrupt_error(rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) rc = -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) mapping_set_error(inode->i_mapping, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) if (attrs->ia_valid & ATTR_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) rc = cifs_set_file_size(inode, attrs, xid, full_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) if (rc != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) /* skip mode change if it's just for clearing setuid/setgid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649) if (attrs->ia_valid & (ATTR_KILL_SUID|ATTR_KILL_SGID))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) attrs->ia_valid &= ~ATTR_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) args = kmalloc(sizeof(*args), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653) if (args == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) /* set up the struct */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) if (attrs->ia_valid & ATTR_MODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) args->mode = attrs->ia_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) args->mode = NO_CHANGE_64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) if (attrs->ia_valid & ATTR_UID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) args->uid = attrs->ia_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) args->uid = INVALID_UID; /* no change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669) if (attrs->ia_valid & ATTR_GID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) args->gid = attrs->ia_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) args->gid = INVALID_GID; /* no change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) if (attrs->ia_valid & ATTR_ATIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) args->atime = cifs_UnixTimeToNT(attrs->ia_atime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) args->atime = NO_CHANGE_64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679) if (attrs->ia_valid & ATTR_MTIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) args->mtime = cifs_UnixTimeToNT(attrs->ia_mtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) args->mtime = NO_CHANGE_64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684) if (attrs->ia_valid & ATTR_CTIME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) args->ctime = cifs_UnixTimeToNT(attrs->ia_ctime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687) args->ctime = NO_CHANGE_64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) args->device = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) open_file = find_writable_file(cifsInode, FIND_WR_FSUID_ONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) if (open_file) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) u16 nfid = open_file->fid.netfid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) u32 npid = open_file->pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) pTcon = tlink_tcon(open_file->tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) rc = CIFSSMBUnixSetFileInfo(xid, pTcon, args, nfid, npid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) cifsFileInfo_put(open_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) tlink = cifs_sb_tlink(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699) if (IS_ERR(tlink)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) rc = PTR_ERR(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) pTcon = tlink_tcon(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) rc = CIFSSMBUnixSetPathInfo(xid, pTcon, full_path, args,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705) cifs_sb->local_nls,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) cifs_remap(cifs_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) cifs_put_tlink(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713) if ((attrs->ia_valid & ATTR_SIZE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) attrs->ia_size != i_size_read(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715) truncate_setsize(inode, attrs->ia_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) setattr_copy(inode, attrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) /* force revalidate when any of these times are set since some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) of the fs types (eg ext3, fat) do not have fine enough
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722) time granularity to match protocol, and we do not have a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) a way (yet) to query the server fs's time granularity (and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) whether it rounds times down).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) if (attrs->ia_valid & (ATTR_MTIME | ATTR_CTIME))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) cifsInode->time = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) kfree(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) kfree(full_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731) free_xid(xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) unsigned int xid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) kuid_t uid = INVALID_UID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) kgid_t gid = INVALID_GID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741) struct inode *inode = d_inode(direntry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) struct cifsInodeInfo *cifsInode = CIFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) struct cifsFileInfo *wfile;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745) struct cifs_tcon *tcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) char *full_path = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) int rc = -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) __u32 dosattr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) __u64 mode = NO_CHANGE_64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) xid = get_xid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) cifs_dbg(FYI, "setattr on file %pd attrs->ia_valid 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) direntry, attrs->ia_valid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NO_PERM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) attrs->ia_valid |= ATTR_FORCE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759) rc = setattr_prepare(direntry, attrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) free_xid(xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) full_path = build_path_from_dentry(direntry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) if (full_path == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) free_xid(xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) * Attempt to flush data before changing attributes. We need to do
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) * this for ATTR_SIZE and ATTR_MTIME. If the flush of the data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) * returns error, store it to report later and continue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) * BB: This should be smarter. Why bother flushing pages that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) * will be truncated anyway? Also, should we error out here if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779) * the flush returns error? Do we need to check for ATTR_MTIME_SET flag?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) if (attrs->ia_valid & (ATTR_MTIME | ATTR_SIZE | ATTR_CTIME)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782) rc = filemap_write_and_wait(inode->i_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) if (is_interrupt_error(rc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) rc = -ERESTARTSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785) goto cifs_setattr_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) mapping_set_error(inode->i_mapping, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792) if ((attrs->ia_valid & ATTR_MTIME) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) !(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_NOSSYNC)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) rc = cifs_get_writable_file(cifsInode, FIND_WR_ANY, &wfile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) if (!rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) tcon = tlink_tcon(wfile->tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797) rc = tcon->ses->server->ops->flush(xid, tcon, &wfile->fid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) cifsFileInfo_put(wfile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) goto cifs_setattr_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) } else if (rc != -EBADF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) goto cifs_setattr_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) if (attrs->ia_valid & ATTR_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) rc = cifs_set_file_size(inode, attrs, xid, full_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) if (rc != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) goto cifs_setattr_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813) if (attrs->ia_valid & ATTR_UID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) uid = attrs->ia_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) if (attrs->ia_valid & ATTR_GID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817) gid = attrs->ia_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MODE_FROM_SID)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821) if (uid_valid(uid) || gid_valid(gid)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) rc = id_mode_to_cifs_acl(inode, full_path, NO_CHANGE_64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) uid, gid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) cifs_dbg(FYI, "%s: Setting id failed with error: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) __func__, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) goto cifs_setattr_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831) if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_SET_UID))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) attrs->ia_valid &= ~(ATTR_UID | ATTR_GID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) /* skip mode change if it's just for clearing setuid/setgid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) if (attrs->ia_valid & (ATTR_KILL_SUID|ATTR_KILL_SGID))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) attrs->ia_valid &= ~ATTR_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) if (attrs->ia_valid & ATTR_MODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839) mode = attrs->ia_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_CIFS_ACL) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MODE_FROM_SID)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843) rc = id_mode_to_cifs_acl(inode, full_path, mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) INVALID_UID, INVALID_GID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) cifs_dbg(FYI, "%s: Setting ACL failed with error: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) __func__, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) goto cifs_setattr_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) if (((mode & S_IWUGO) == 0) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) (cifsInode->cifsAttrs & ATTR_READONLY) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) dosattr = cifsInode->cifsAttrs | ATTR_READONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) /* fix up mode if we're not using dynperm */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) if ((cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) attrs->ia_mode = inode->i_mode & ~S_IWUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859) } else if ((mode & S_IWUGO) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) (cifsInode->cifsAttrs & ATTR_READONLY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) dosattr = cifsInode->cifsAttrs & ~ATTR_READONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) /* Attributes of 0 are ignored */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) if (dosattr == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) dosattr |= ATTR_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) /* reset local inode permissions to normal */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869) attrs->ia_mode &= ~(S_IALLUGO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) if (S_ISDIR(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) attrs->ia_mode |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) cifs_sb->mnt_dir_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) attrs->ia_mode |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) cifs_sb->mnt_file_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) } else if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_DYNPERM)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878) /* ignore mode change - ATTR_READONLY hasn't changed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) attrs->ia_valid &= ~ATTR_MODE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883) if (attrs->ia_valid & (ATTR_MTIME|ATTR_ATIME|ATTR_CTIME) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) ((attrs->ia_valid & ATTR_MODE) && dosattr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) rc = cifs_set_file_info(inode, attrs, xid, full_path, dosattr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) /* BB: check for rc = -EOPNOTSUPP and switch to legacy mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) /* Even if error on time set, no sense failing the call if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) the server would set the time to a reasonable value anyway,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) and this check ensures that we are not being called from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891) sys_utimes in which case we ought to fail the call back to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) the user when the server rejects the call */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) if ((rc) && (attrs->ia_valid &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) (ATTR_MODE | ATTR_GID | ATTR_UID | ATTR_SIZE)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) /* do not need local check to inode_check_ok since the server does
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899) that */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) goto cifs_setattr_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) if ((attrs->ia_valid & ATTR_SIZE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) attrs->ia_size != i_size_read(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905) truncate_setsize(inode, attrs->ia_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) setattr_copy(inode, attrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910) cifs_setattr_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) kfree(full_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) free_xid(xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) cifs_setattr(struct dentry *direntry, struct iattr *attrs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) struct cifs_sb_info *cifs_sb = CIFS_SB(direntry->d_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) struct cifs_tcon *pTcon = cifs_sb_master_tcon(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) int rc, retries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) if (pTcon->unix_ext)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) rc = cifs_setattr_unix(direntry, attrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) rc = cifs_setattr_nounix(direntry, attrs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) retries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) } while (is_retryable_error(rc) && retries < 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) /* BB: add cifs_setattr_legacy for really old servers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) void cifs_delete_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) cifs_dbg(FYI, "In cifs_delete_inode, inode = 0x%p\n", inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) /* may have to add back in if and when safe distributed caching of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) directories added e.g. via FindNotify */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) #endif