Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 1 | /* |
| 2 | * fs/cifs/smb2inode.c |
| 3 | * |
| 4 | * Copyright (C) International Business Machines Corp., 2002, 2011 |
| 5 | * Etersoft, 2012 |
| 6 | * Author(s): Pavel Shilovsky (pshilovsky@samba.org), |
| 7 | * Steve French (sfrench@us.ibm.com) |
| 8 | * |
| 9 | * This library is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU Lesser General Public License as published |
| 11 | * by the Free Software Foundation; either version 2.1 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This library is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 17 | * the GNU Lesser General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU Lesser General Public License |
| 20 | * along with this library; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 | */ |
| 23 | #include <linux/fs.h> |
| 24 | #include <linux/stat.h> |
| 25 | #include <linux/slab.h> |
| 26 | #include <linux/pagemap.h> |
| 27 | #include <asm/div64.h> |
| 28 | #include "cifsfs.h" |
| 29 | #include "cifspdu.h" |
| 30 | #include "cifsglob.h" |
| 31 | #include "cifsproto.h" |
| 32 | #include "cifs_debug.h" |
| 33 | #include "cifs_fs_sb.h" |
| 34 | #include "cifs_unicode.h" |
| 35 | #include "fscache.h" |
| 36 | #include "smb2glob.h" |
| 37 | #include "smb2pdu.h" |
| 38 | #include "smb2proto.h" |
| 39 | |
| 40 | static int |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 41 | smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, |
| 42 | struct cifs_sb_info *cifs_sb, const char *full_path, |
| 43 | __u32 desired_access, __u32 create_disposition, |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame^] | 44 | __u32 create_options, void *ptr, int command) |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 45 | { |
| 46 | int rc; |
| 47 | __le16 *utf16_path = NULL; |
| 48 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
| 49 | struct cifs_open_parms oparms; |
| 50 | struct cifs_fid fid; |
| 51 | struct cifs_ses *ses = tcon->ses; |
| 52 | struct TCP_Server_Info *server = ses->server; |
| 53 | int num_rqst = 0; |
| 54 | struct smb_rqst rqst[3]; |
| 55 | int resp_buftype[3]; |
| 56 | struct kvec rsp_iov[3]; |
| 57 | struct kvec open_iov[SMB2_CREATE_IOV_SIZE]; |
| 58 | struct kvec qi_iov[1]; |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame^] | 59 | struct kvec si_iov[2]; /* 1 + potential padding. */ |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 60 | struct kvec close_iov[1]; |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame^] | 61 | struct smb2_query_info_rsp *qi_rsp = NULL; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 62 | int flags = 0; |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame^] | 63 | __u8 delete_pending[8] = {1, 0, 0, 0, 0, 0, 0, 0}; |
| 64 | unsigned int size[1]; |
| 65 | void *data[1]; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 66 | |
| 67 | if (smb3_encryption_required(tcon)) |
| 68 | flags |= CIFS_TRANSFORM_REQ; |
| 69 | |
| 70 | memset(rqst, 0, sizeof(rqst)); |
| 71 | resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER; |
| 72 | memset(rsp_iov, 0, sizeof(rsp_iov)); |
| 73 | |
| 74 | /* Open */ |
| 75 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); |
| 76 | if (!utf16_path) |
| 77 | return -ENOMEM; |
| 78 | |
| 79 | oparms.tcon = tcon; |
| 80 | oparms.desired_access = desired_access; |
| 81 | oparms.disposition = create_disposition; |
| 82 | oparms.create_options = create_options; |
| 83 | oparms.fid = &fid; |
| 84 | oparms.reconnect = false; |
| 85 | |
| 86 | memset(&open_iov, 0, sizeof(open_iov)); |
| 87 | rqst[num_rqst].rq_iov = open_iov; |
| 88 | rqst[num_rqst].rq_nvec = SMB2_CREATE_IOV_SIZE; |
| 89 | rc = SMB2_open_init(tcon, &rqst[num_rqst], &oplock, &oparms, |
| 90 | utf16_path); |
| 91 | kfree(utf16_path); |
| 92 | if (rc) |
| 93 | goto finished; |
| 94 | |
| 95 | smb2_set_next_command(server, &rqst[num_rqst++]); |
| 96 | |
| 97 | /* Operation */ |
| 98 | switch (command) { |
| 99 | case SMB2_OP_QUERY_INFO: |
| 100 | memset(&qi_iov, 0, sizeof(qi_iov)); |
| 101 | rqst[num_rqst].rq_iov = qi_iov; |
| 102 | rqst[num_rqst].rq_nvec = 1; |
| 103 | |
| 104 | rc = SMB2_query_info_init(tcon, &rqst[num_rqst], COMPOUND_FID, |
| 105 | COMPOUND_FID, FILE_ALL_INFORMATION, |
| 106 | SMB2_O_INFO_FILE, 0, |
| 107 | sizeof(struct smb2_file_all_info) + |
| 108 | PATH_MAX * 2); |
| 109 | smb2_set_next_command(server, &rqst[num_rqst]); |
| 110 | smb2_set_related(&rqst[num_rqst++]); |
| 111 | break; |
Ronnie Sahlberg | 47dd959 | 2018-09-03 13:33:43 +1000 | [diff] [blame] | 112 | case SMB2_OP_DELETE: |
| 113 | break; |
Ronnie Sahlberg | f733e39 | 2018-09-03 13:33:42 +1000 | [diff] [blame] | 114 | case SMB2_OP_MKDIR: |
| 115 | /* |
| 116 | * Directories are created through parameters in the |
| 117 | * SMB2_open() call. |
| 118 | */ |
| 119 | break; |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame^] | 120 | case SMB2_OP_RMDIR: |
| 121 | memset(&si_iov, 0, sizeof(si_iov)); |
| 122 | rqst[num_rqst].rq_iov = si_iov; |
| 123 | rqst[num_rqst].rq_nvec = 1; |
| 124 | |
| 125 | size[0] = 8; |
| 126 | data[0] = &delete_pending[0]; |
| 127 | |
| 128 | rc = SMB2_set_info_init(tcon, &rqst[num_rqst], COMPOUND_FID, |
| 129 | COMPOUND_FID, current->tgid, |
| 130 | FILE_DISPOSITION_INFORMATION, |
| 131 | SMB2_O_INFO_FILE, 0, data, size); |
| 132 | smb2_set_next_command(server, &rqst[num_rqst]); |
| 133 | smb2_set_related(&rqst[num_rqst++]); |
| 134 | break; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 135 | default: |
| 136 | cifs_dbg(VFS, "Invalid command\n"); |
| 137 | rc = -EINVAL; |
| 138 | } |
| 139 | if (rc) |
| 140 | goto finished; |
| 141 | |
| 142 | /* Close */ |
| 143 | memset(&close_iov, 0, sizeof(close_iov)); |
| 144 | rqst[num_rqst].rq_iov = close_iov; |
| 145 | rqst[num_rqst].rq_nvec = 1; |
| 146 | rc = SMB2_close_init(tcon, &rqst[num_rqst], COMPOUND_FID, |
| 147 | COMPOUND_FID); |
| 148 | smb2_set_related(&rqst[num_rqst++]); |
| 149 | if (rc) |
| 150 | goto finished; |
| 151 | |
| 152 | rc = compound_send_recv(xid, ses, flags, num_rqst, rqst, |
| 153 | resp_buftype, rsp_iov); |
| 154 | |
| 155 | finished: |
| 156 | SMB2_open_free(&rqst[0]); |
| 157 | switch (command) { |
| 158 | case SMB2_OP_QUERY_INFO: |
| 159 | if (rc == 0) { |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame^] | 160 | qi_rsp = (struct smb2_query_info_rsp *) |
| 161 | rsp_iov[1].iov_base; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 162 | rc = smb2_validate_and_copy_iov( |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame^] | 163 | le16_to_cpu(qi_rsp->OutputBufferOffset), |
| 164 | le32_to_cpu(qi_rsp->OutputBufferLength), |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 165 | &rsp_iov[1], sizeof(struct smb2_file_all_info), |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame^] | 166 | ptr); |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 167 | } |
| 168 | if (rqst[1].rq_iov) |
| 169 | SMB2_query_info_free(&rqst[1]); |
| 170 | if (rqst[2].rq_iov) |
| 171 | SMB2_close_free(&rqst[2]); |
| 172 | break; |
Ronnie Sahlberg | 47dd959 | 2018-09-03 13:33:43 +1000 | [diff] [blame] | 173 | case SMB2_OP_DELETE: |
Ronnie Sahlberg | f733e39 | 2018-09-03 13:33:42 +1000 | [diff] [blame] | 174 | case SMB2_OP_MKDIR: |
| 175 | if (rqst[1].rq_iov) |
| 176 | SMB2_close_free(&rqst[1]); |
| 177 | break; |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame^] | 178 | case SMB2_OP_RMDIR: |
| 179 | if (rqst[1].rq_iov) |
| 180 | SMB2_set_info_free(&rqst[1]); |
| 181 | if (rqst[2].rq_iov) |
| 182 | SMB2_close_free(&rqst[2]); |
| 183 | break; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 184 | } |
| 185 | free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base); |
| 186 | free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base); |
| 187 | free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base); |
| 188 | return rc; |
| 189 | } |
| 190 | |
| 191 | static int |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 192 | smb2_open_op_close(const unsigned int xid, struct cifs_tcon *tcon, |
| 193 | struct cifs_sb_info *cifs_sb, const char *full_path, |
| 194 | __u32 desired_access, __u32 create_disposition, |
Pavel Shilovsky | ca81983 | 2013-07-05 12:21:26 +0400 | [diff] [blame] | 195 | __u32 create_options, void *data, int command) |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 196 | { |
| 197 | int rc, tmprc = 0; |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 198 | __le16 *utf16_path = NULL; |
Pavel Shilovsky | 2e44b28 | 2012-09-18 16:20:33 -0700 | [diff] [blame] | 199 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 200 | struct cifs_open_parms oparms; |
| 201 | struct cifs_fid fid; |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 202 | bool use_cached_root_handle = false; |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 203 | |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 204 | if ((strcmp(full_path, "") == 0) && (create_options == 0) && |
| 205 | (desired_access == FILE_READ_ATTRIBUTES) && |
| 206 | (create_disposition == FILE_OPEN) && |
| 207 | (tcon->nohandlecache == false)) { |
| 208 | rc = open_shroot(xid, tcon, &fid); |
| 209 | if (rc == 0) |
| 210 | use_cached_root_handle = true; |
| 211 | } |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 212 | |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 213 | if (use_cached_root_handle == false) { |
| 214 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); |
| 215 | if (!utf16_path) |
| 216 | return -ENOMEM; |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 217 | |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 218 | oparms.tcon = tcon; |
| 219 | oparms.desired_access = desired_access; |
| 220 | oparms.disposition = create_disposition; |
| 221 | oparms.create_options = create_options; |
| 222 | oparms.fid = &fid; |
| 223 | oparms.reconnect = false; |
| 224 | |
Ronnie Sahlberg | 9d874c3 | 2018-06-08 13:21:18 +1000 | [diff] [blame] | 225 | rc = SMB2_open(xid, &oparms, utf16_path, &oplock, NULL, NULL, |
| 226 | NULL); |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 227 | if (rc) { |
| 228 | kfree(utf16_path); |
| 229 | return rc; |
| 230 | } |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | switch (command) { |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 234 | case SMB2_OP_RENAME: |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 235 | tmprc = SMB2_rename(xid, tcon, fid.persistent_fid, |
| 236 | fid.volatile_fid, (__le16 *)data); |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 237 | break; |
Pavel Shilovsky | 568798c | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 238 | case SMB2_OP_HARDLINK: |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 239 | tmprc = SMB2_set_hardlink(xid, tcon, fid.persistent_fid, |
| 240 | fid.volatile_fid, (__le16 *)data); |
Pavel Shilovsky | 568798c | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 241 | break; |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 242 | case SMB2_OP_SET_EOF: |
Pavel Shilovsky | 064f604 | 2013-07-09 18:20:30 +0400 | [diff] [blame] | 243 | tmprc = SMB2_set_eof(xid, tcon, fid.persistent_fid, |
| 244 | fid.volatile_fid, current->tgid, |
Steve French | f29ebb4 | 2014-07-19 21:44:58 -0500 | [diff] [blame] | 245 | (__le64 *)data, false); |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 246 | break; |
Pavel Shilovsky | 1feeaac | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 247 | case SMB2_OP_SET_INFO: |
Ronnie Sahlberg | ba8ca11 | 2018-09-03 13:33:44 +1000 | [diff] [blame] | 248 | tmprc = SMB2_set_basic_info(xid, tcon, fid.persistent_fid, |
| 249 | fid.volatile_fid, |
| 250 | (FILE_BASIC_INFO *)data); |
Pavel Shilovsky | 1feeaac | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 251 | break; |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 252 | default: |
Joe Perches | f96637b | 2013-05-04 22:12:25 -0500 | [diff] [blame] | 253 | cifs_dbg(VFS, "Invalid command\n"); |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 254 | break; |
| 255 | } |
| 256 | |
Ronnie Sahlberg | 9da6ec7 | 2018-07-31 08:48:22 +1000 | [diff] [blame] | 257 | if (use_cached_root_handle) |
| 258 | close_shroot(&tcon->crfid); |
| 259 | else |
Steve French | 3d4ef9a | 2018-04-25 22:19:09 -0500 | [diff] [blame] | 260 | rc = SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid); |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 261 | if (tmprc) |
| 262 | rc = tmprc; |
| 263 | kfree(utf16_path); |
| 264 | return rc; |
| 265 | } |
| 266 | |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 267 | void |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 268 | move_smb2_info_to_cifs(FILE_ALL_INFO *dst, struct smb2_file_all_info *src) |
| 269 | { |
| 270 | memcpy(dst, src, (size_t)(&src->CurrentByteOffset) - (size_t)src); |
| 271 | dst->CurrentByteOffset = src->CurrentByteOffset; |
| 272 | dst->Mode = src->Mode; |
| 273 | dst->AlignmentRequirement = src->AlignmentRequirement; |
| 274 | dst->IndexNumber1 = 0; /* we don't use it */ |
| 275 | } |
| 276 | |
| 277 | int |
| 278 | smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, |
| 279 | struct cifs_sb_info *cifs_sb, const char *full_path, |
Pavel Shilovsky | eb85d94b | 2013-10-23 17:49:47 +0400 | [diff] [blame] | 280 | FILE_ALL_INFO *data, bool *adjust_tz, bool *symlink) |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 281 | { |
| 282 | int rc; |
| 283 | struct smb2_file_all_info *smb2_data; |
| 284 | |
| 285 | *adjust_tz = false; |
Pavel Shilovsky | eb85d94b | 2013-10-23 17:49:47 +0400 | [diff] [blame] | 286 | *symlink = false; |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 287 | |
Pavel Shilovsky | 1bbe499 | 2014-08-22 13:32:11 +0400 | [diff] [blame] | 288 | smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2, |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 289 | GFP_KERNEL); |
| 290 | if (smb2_data == NULL) |
| 291 | return -ENOMEM; |
| 292 | |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 293 | rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, |
| 294 | FILE_READ_ATTRIBUTES, FILE_OPEN, 0, |
| 295 | smb2_data, SMB2_OP_QUERY_INFO); |
Pavel Shilovsky | eb85d94b | 2013-10-23 17:49:47 +0400 | [diff] [blame] | 296 | if (rc == -EOPNOTSUPP) { |
| 297 | *symlink = true; |
| 298 | /* Failed on a symbolic link - query a reparse point info */ |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 299 | rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, |
| 300 | FILE_READ_ATTRIBUTES, FILE_OPEN, |
| 301 | OPEN_REPARSE_POINT, smb2_data, |
| 302 | SMB2_OP_QUERY_INFO); |
Pavel Shilovsky | eb85d94b | 2013-10-23 17:49:47 +0400 | [diff] [blame] | 303 | } |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 304 | if (rc) |
| 305 | goto out; |
| 306 | |
| 307 | move_smb2_info_to_cifs(data, smb2_data); |
| 308 | out: |
| 309 | kfree(smb2_data); |
| 310 | return rc; |
| 311 | } |
Pavel Shilovsky | a0e7318 | 2011-07-19 12:56:37 +0400 | [diff] [blame] | 312 | |
| 313 | int |
| 314 | smb2_mkdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name, |
| 315 | struct cifs_sb_info *cifs_sb) |
| 316 | { |
Ronnie Sahlberg | f733e39 | 2018-09-03 13:33:42 +1000 | [diff] [blame] | 317 | return smb2_compound_op(xid, tcon, cifs_sb, name, |
| 318 | FILE_WRITE_ATTRIBUTES, FILE_CREATE, |
| 319 | CREATE_NOT_FILE, NULL, SMB2_OP_MKDIR); |
Pavel Shilovsky | a0e7318 | 2011-07-19 12:56:37 +0400 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | void |
| 323 | smb2_mkdir_setinfo(struct inode *inode, const char *name, |
| 324 | struct cifs_sb_info *cifs_sb, struct cifs_tcon *tcon, |
| 325 | const unsigned int xid) |
| 326 | { |
| 327 | FILE_BASIC_INFO data; |
| 328 | struct cifsInodeInfo *cifs_i; |
| 329 | u32 dosattrs; |
| 330 | int tmprc; |
| 331 | |
| 332 | memset(&data, 0, sizeof(data)); |
| 333 | cifs_i = CIFS_I(inode); |
| 334 | dosattrs = cifs_i->cifsAttrs | ATTR_READONLY; |
| 335 | data.Attributes = cpu_to_le32(dosattrs); |
| 336 | tmprc = smb2_open_op_close(xid, tcon, cifs_sb, name, |
Pavel Shilovsky | ca81983 | 2013-07-05 12:21:26 +0400 | [diff] [blame] | 337 | FILE_WRITE_ATTRIBUTES, FILE_CREATE, |
Pavel Shilovsky | a0e7318 | 2011-07-19 12:56:37 +0400 | [diff] [blame] | 338 | CREATE_NOT_FILE, &data, SMB2_OP_SET_INFO); |
| 339 | if (tmprc == 0) |
| 340 | cifs_i->cifsAttrs = dosattrs; |
| 341 | } |
Pavel Shilovsky | 1a500f0 | 2012-07-10 16:14:38 +0400 | [diff] [blame] | 342 | |
| 343 | int |
| 344 | smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name, |
| 345 | struct cifs_sb_info *cifs_sb) |
| 346 | { |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame^] | 347 | return smb2_compound_op(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN, |
| 348 | CREATE_NOT_FILE, |
| 349 | NULL, SMB2_OP_RMDIR); |
Pavel Shilovsky | 1a500f0 | 2012-07-10 16:14:38 +0400 | [diff] [blame] | 350 | } |
Pavel Shilovsky | cbe6f43 | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 351 | |
| 352 | int |
| 353 | smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *name, |
| 354 | struct cifs_sb_info *cifs_sb) |
| 355 | { |
Ronnie Sahlberg | 47dd959 | 2018-09-03 13:33:43 +1000 | [diff] [blame] | 356 | return smb2_compound_op(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN, |
| 357 | CREATE_DELETE_ON_CLOSE | OPEN_REPARSE_POINT, |
| 358 | NULL, SMB2_OP_DELETE); |
Pavel Shilovsky | cbe6f43 | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 359 | } |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 360 | |
Pavel Shilovsky | 568798c | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 361 | static int |
| 362 | smb2_set_path_attr(const unsigned int xid, struct cifs_tcon *tcon, |
| 363 | const char *from_name, const char *to_name, |
| 364 | struct cifs_sb_info *cifs_sb, __u32 access, int command) |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 365 | { |
| 366 | __le16 *smb2_to_name = NULL; |
| 367 | int rc; |
| 368 | |
| 369 | smb2_to_name = cifs_convert_path_to_utf16(to_name, cifs_sb); |
| 370 | if (smb2_to_name == NULL) { |
| 371 | rc = -ENOMEM; |
| 372 | goto smb2_rename_path; |
| 373 | } |
| 374 | |
Pavel Shilovsky | 568798c | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 375 | rc = smb2_open_op_close(xid, tcon, cifs_sb, from_name, access, |
Pavel Shilovsky | ca81983 | 2013-07-05 12:21:26 +0400 | [diff] [blame] | 376 | FILE_OPEN, 0, smb2_to_name, command); |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 377 | smb2_rename_path: |
| 378 | kfree(smb2_to_name); |
| 379 | return rc; |
| 380 | } |
Pavel Shilovsky | 568798c | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 381 | |
| 382 | int |
| 383 | smb2_rename_path(const unsigned int xid, struct cifs_tcon *tcon, |
| 384 | const char *from_name, const char *to_name, |
| 385 | struct cifs_sb_info *cifs_sb) |
| 386 | { |
| 387 | return smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb, |
| 388 | DELETE, SMB2_OP_RENAME); |
| 389 | } |
| 390 | |
| 391 | int |
| 392 | smb2_create_hardlink(const unsigned int xid, struct cifs_tcon *tcon, |
| 393 | const char *from_name, const char *to_name, |
| 394 | struct cifs_sb_info *cifs_sb) |
| 395 | { |
| 396 | return smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb, |
| 397 | FILE_READ_ATTRIBUTES, SMB2_OP_HARDLINK); |
| 398 | } |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 399 | |
| 400 | int |
| 401 | smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon, |
| 402 | const char *full_path, __u64 size, |
| 403 | struct cifs_sb_info *cifs_sb, bool set_alloc) |
| 404 | { |
| 405 | __le64 eof = cpu_to_le64(size); |
| 406 | return smb2_open_op_close(xid, tcon, cifs_sb, full_path, |
Pavel Shilovsky | ca81983 | 2013-07-05 12:21:26 +0400 | [diff] [blame] | 407 | FILE_WRITE_DATA, FILE_OPEN, 0, &eof, |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 408 | SMB2_OP_SET_EOF); |
| 409 | } |
Pavel Shilovsky | 1feeaac | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 410 | |
| 411 | int |
| 412 | smb2_set_file_info(struct inode *inode, const char *full_path, |
| 413 | FILE_BASIC_INFO *buf, const unsigned int xid) |
| 414 | { |
| 415 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
| 416 | struct tcon_link *tlink; |
| 417 | int rc; |
| 418 | |
Steve French | 18dd8e1 | 2016-09-26 14:23:08 -0500 | [diff] [blame] | 419 | if ((buf->CreationTime == 0) && (buf->LastAccessTime == 0) && |
Steve French | fd09b7d | 2018-08-02 20:28:18 -0500 | [diff] [blame] | 420 | (buf->LastWriteTime == 0) && (buf->ChangeTime == 0) && |
Steve French | 18dd8e1 | 2016-09-26 14:23:08 -0500 | [diff] [blame] | 421 | (buf->Attributes == 0)) |
| 422 | return 0; /* would be a no op, no sense sending this */ |
| 423 | |
Pavel Shilovsky | 1feeaac | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 424 | tlink = cifs_sb_tlink(cifs_sb); |
| 425 | if (IS_ERR(tlink)) |
| 426 | return PTR_ERR(tlink); |
Steve French | 18dd8e1 | 2016-09-26 14:23:08 -0500 | [diff] [blame] | 427 | |
Pavel Shilovsky | 1feeaac | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 428 | rc = smb2_open_op_close(xid, tlink_tcon(tlink), cifs_sb, full_path, |
Pavel Shilovsky | ca81983 | 2013-07-05 12:21:26 +0400 | [diff] [blame] | 429 | FILE_WRITE_ATTRIBUTES, FILE_OPEN, 0, buf, |
Pavel Shilovsky | 1feeaac | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 430 | SMB2_OP_SET_INFO); |
| 431 | cifs_put_tlink(tlink); |
| 432 | return rc; |
| 433 | } |