^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * fs/cifs/ioctl.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * vfs operations that deal with io control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) International Business Machines Corp., 2005,2013
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Author(s): Steve French (sfrench@us.ibm.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * This library is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * it under the terms of the GNU Lesser General Public License as published
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * by the Free Software Foundation; either version 2.1 of the License, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * (at your option) any later version.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * This library is distributed in the hope that it will be useful,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * but WITHOUT ANY WARRANTY; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * the GNU Lesser General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * You should have received a copy of the GNU Lesser General Public License
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * along with this library; if not, write to the Free Software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/mount.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include "cifspdu.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include "cifsglob.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include "cifsproto.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include "cifs_debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include "cifsfs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include "cifs_ioctl.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 <linux/btrfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static long cifs_ioctl_query_info(unsigned int xid, struct file *filep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) unsigned long p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct inode *inode = file_inode(filep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct dentry *dentry = filep->f_path.dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) unsigned char *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) __le16 *utf16_path = NULL, root_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) path = build_path_from_dentry(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) if (path == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) cifs_dbg(FYI, "%s %s\n", __func__, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (!path[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) root_path = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) utf16_path = &root_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) utf16_path = cifs_convert_path_to_utf16(path + 1, cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) if (!utf16_path) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) goto ici_exit;
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (tcon->ses->server->ops->ioctl_query_info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) rc = tcon->ses->server->ops->ioctl_query_info(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) xid, tcon, cifs_sb, utf16_path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) filep->private_data ? 0 : 1, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) rc = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) ici_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (utf16_path != &root_path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) kfree(utf16_path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) kfree(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static long cifs_ioctl_copychunk(unsigned int xid, struct file *dst_file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) unsigned long srcfd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct fd src_file;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct inode *src_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) cifs_dbg(FYI, "ioctl copychunk range\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) /* the destination must be opened for writing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (!(dst_file->f_mode & FMODE_WRITE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) cifs_dbg(FYI, "file target not open for write\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) /* check if target volume is readonly and take reference */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) rc = mnt_want_write_file(dst_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) cifs_dbg(FYI, "mnt_want_write failed with rc %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) src_file = fdget(srcfd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (!src_file.file) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) rc = -EBADF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) goto out_drop_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (src_file.file->f_op->unlocked_ioctl != cifs_ioctl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) rc = -EBADF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) cifs_dbg(VFS, "src file seems to be from a different filesystem type\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) goto out_fput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) src_inode = file_inode(src_file.file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if (S_ISDIR(src_inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) goto out_fput;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) rc = cifs_file_copychunk_range(xid, src_file.file, 0, dst_file, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) src_inode->i_size, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (rc > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) out_fput:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) fdput(src_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) out_drop_write:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) mnt_drop_write_file(dst_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static long smb_mnt_get_fsinfo(unsigned int xid, struct cifs_tcon *tcon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) void __user *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) int rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct smb_mnt_fs_info *fsinf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) fsinf = kzalloc(sizeof(struct smb_mnt_fs_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (fsinf == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) fsinf->version = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) fsinf->protocol_id = tcon->ses->server->vals->protocol_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) fsinf->device_characteristics =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) fsinf->device_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) fsinf->fs_attributes = le32_to_cpu(tcon->fsAttrInfo.Attributes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) fsinf->max_path_component =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) fsinf->vol_serial_number = tcon->vol_serial_number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) fsinf->vol_create_time = le64_to_cpu(tcon->vol_create_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) fsinf->share_flags = tcon->share_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) fsinf->share_caps = le32_to_cpu(tcon->capabilities);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) fsinf->sector_flags = tcon->ss_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) fsinf->optimal_sector_size = tcon->perf_sector_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) fsinf->max_bytes_chunk = tcon->max_bytes_chunk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) fsinf->maximal_access = tcon->maximal_access;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) fsinf->cifs_posix_caps = le64_to_cpu(tcon->fsUnixInfo.Capability);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (copy_to_user(arg, fsinf, sizeof(struct smb_mnt_fs_info)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) rc = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) kfree(fsinf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct inode *inode = file_inode(filep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) struct smb3_key_debug_info pkey_inf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) int rc = -ENOTTY; /* strange error - but the precedent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) unsigned int xid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct cifsFileInfo *pSMBFile = filep->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) struct cifs_tcon *tcon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct tcon_link *tlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) struct cifs_sb_info *cifs_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) __u64 ExtAttrBits = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) __u64 caps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) xid = get_xid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) cifs_dbg(FYI, "cifs ioctl 0x%x\n", command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) switch (command) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) case FS_IOC_GETFLAGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (pSMBFile == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) tcon = tlink_tcon(pSMBFile->tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) caps = le64_to_cpu(tcon->fsUnixInfo.Capability);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) #ifdef CONFIG_CIFS_POSIX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (CIFS_UNIX_EXTATTR_CAP & caps) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) __u64 ExtAttrMask = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) rc = CIFSGetExtAttr(xid, tcon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) pSMBFile->fid.netfid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) &ExtAttrBits, &ExtAttrMask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (rc == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) rc = put_user(ExtAttrBits &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) FS_FL_USER_VISIBLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) (int __user *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (rc != EOPNOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) #endif /* CONFIG_CIFS_POSIX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (CIFS_I(inode)->cifsAttrs & ATTR_COMPRESSED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* add in the compressed bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) ExtAttrBits = FS_COMPR_FL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) rc = put_user(ExtAttrBits & FS_FL_USER_VISIBLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) (int __user *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) case FS_IOC_SETFLAGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (pSMBFile == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) tcon = tlink_tcon(pSMBFile->tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) caps = le64_to_cpu(tcon->fsUnixInfo.Capability);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (get_user(ExtAttrBits, (int __user *)arg)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) rc = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * if (CIFS_UNIX_EXTATTR_CAP & caps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * rc = CIFSSetExtAttr(xid, tcon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * pSMBFile->fid.netfid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * extAttrBits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * &ExtAttrMask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * if (rc != EOPNOTSUPP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) /* Currently only flag we can set is compressed flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if ((ExtAttrBits & FS_COMPR_FL) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /* Try to set compress flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if (tcon->ses->server->ops->set_compression) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) rc = tcon->ses->server->ops->set_compression(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) xid, tcon, pSMBFile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) cifs_dbg(FYI, "set compress flag rc %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) case CIFS_IOC_COPYCHUNK_FILE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) rc = cifs_ioctl_copychunk(xid, filep, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) case CIFS_QUERY_INFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) rc = cifs_ioctl_query_info(xid, filep, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) case CIFS_IOC_SET_INTEGRITY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (pSMBFile == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) tcon = tlink_tcon(pSMBFile->tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (tcon->ses->server->ops->set_integrity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) rc = tcon->ses->server->ops->set_integrity(xid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) tcon, pSMBFile);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) rc = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) case CIFS_IOC_GET_MNT_INFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (pSMBFile == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) tcon = tlink_tcon(pSMBFile->tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) rc = smb_mnt_get_fsinfo(xid, tcon, (void __user *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) case CIFS_ENUMERATE_SNAPSHOTS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) if (pSMBFile == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (arg == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) goto cifs_ioc_exit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) tcon = tlink_tcon(pSMBFile->tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) if (tcon->ses->server->ops->enum_snapshots)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) rc = tcon->ses->server->ops->enum_snapshots(xid, tcon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) pSMBFile, (void __user *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) rc = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) case CIFS_DUMP_KEY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) if (pSMBFile == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) if (!capable(CAP_SYS_ADMIN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) rc = -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) tcon = tlink_tcon(pSMBFile->tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) if (!smb3_encryption_required(tcon)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) rc = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) pkey_inf.cipher_type =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) le16_to_cpu(tcon->ses->server->cipher_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) pkey_inf.Suid = tcon->ses->Suid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) memcpy(pkey_inf.auth_key, tcon->ses->auth_key.response,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 16 /* SMB2_NTLMV2_SESSKEY_SIZE */);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) memcpy(pkey_inf.smb3decryptionkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) tcon->ses->smb3decryptionkey, SMB3_SIGN_KEY_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) memcpy(pkey_inf.smb3encryptionkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) tcon->ses->smb3encryptionkey, SMB3_SIGN_KEY_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) if (copy_to_user((void __user *)arg, &pkey_inf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) sizeof(struct smb3_key_debug_info)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) rc = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) case CIFS_IOC_NOTIFY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) if (!S_ISDIR(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) /* Notify can only be done on directories */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) rc = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) cifs_sb = CIFS_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) tlink = cifs_sb_tlink(cifs_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) if (IS_ERR(tlink)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) rc = PTR_ERR(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) tcon = tlink_tcon(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) if (tcon && tcon->ses->server->ops->notify) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) rc = tcon->ses->server->ops->notify(xid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) filep, (void __user *)arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) cifs_dbg(FYI, "ioctl notify rc %d\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) rc = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) cifs_put_tlink(tlink);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) cifs_dbg(FYI, "unsupported ioctl\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) cifs_ioc_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) free_xid(xid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }