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 | 14e562a | 2018-09-03 13:33:50 +1000 | [diff] [blame] | 59 | struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE]; |
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}; |
Ronnie Sahlberg | bb43551 | 2018-09-03 13:33:49 +1000 | [diff] [blame] | 64 | unsigned int size[2]; |
| 65 | void *data[2]; |
| 66 | struct smb2_file_rename_info rename_info; |
| 67 | struct smb2_file_link_info link_info; |
| 68 | int len; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 69 | |
| 70 | if (smb3_encryption_required(tcon)) |
| 71 | flags |= CIFS_TRANSFORM_REQ; |
| 72 | |
| 73 | memset(rqst, 0, sizeof(rqst)); |
| 74 | resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER; |
| 75 | memset(rsp_iov, 0, sizeof(rsp_iov)); |
| 76 | |
| 77 | /* Open */ |
| 78 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); |
| 79 | if (!utf16_path) |
| 80 | return -ENOMEM; |
| 81 | |
| 82 | oparms.tcon = tcon; |
| 83 | oparms.desired_access = desired_access; |
| 84 | oparms.disposition = create_disposition; |
| 85 | oparms.create_options = create_options; |
Steve French | 4d5bdf2 | 2018-08-28 16:14:21 -0500 | [diff] [blame] | 86 | if (backup_cred(cifs_sb)) |
| 87 | oparms.create_options |= CREATE_OPEN_BACKUP_INTENT; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 88 | oparms.fid = &fid; |
| 89 | oparms.reconnect = false; |
| 90 | |
| 91 | memset(&open_iov, 0, sizeof(open_iov)); |
| 92 | rqst[num_rqst].rq_iov = open_iov; |
| 93 | rqst[num_rqst].rq_nvec = SMB2_CREATE_IOV_SIZE; |
| 94 | rc = SMB2_open_init(tcon, &rqst[num_rqst], &oplock, &oparms, |
| 95 | utf16_path); |
| 96 | kfree(utf16_path); |
| 97 | if (rc) |
| 98 | goto finished; |
| 99 | |
| 100 | smb2_set_next_command(server, &rqst[num_rqst++]); |
| 101 | |
| 102 | /* Operation */ |
| 103 | switch (command) { |
| 104 | case SMB2_OP_QUERY_INFO: |
| 105 | memset(&qi_iov, 0, sizeof(qi_iov)); |
| 106 | rqst[num_rqst].rq_iov = qi_iov; |
| 107 | rqst[num_rqst].rq_nvec = 1; |
| 108 | |
| 109 | rc = SMB2_query_info_init(tcon, &rqst[num_rqst], COMPOUND_FID, |
| 110 | COMPOUND_FID, FILE_ALL_INFORMATION, |
| 111 | SMB2_O_INFO_FILE, 0, |
| 112 | sizeof(struct smb2_file_all_info) + |
Ronnie Sahlberg | f5b05d6 | 2018-10-07 19:19:58 -0500 | [diff] [blame] | 113 | PATH_MAX * 2, 0, NULL); |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 114 | smb2_set_next_command(server, &rqst[num_rqst]); |
| 115 | smb2_set_related(&rqst[num_rqst++]); |
| 116 | break; |
Ronnie Sahlberg | 47dd959 | 2018-09-03 13:33:43 +1000 | [diff] [blame] | 117 | case SMB2_OP_DELETE: |
| 118 | break; |
Ronnie Sahlberg | f733e39 | 2018-09-03 13:33:42 +1000 | [diff] [blame] | 119 | case SMB2_OP_MKDIR: |
| 120 | /* |
| 121 | * Directories are created through parameters in the |
| 122 | * SMB2_open() call. |
| 123 | */ |
| 124 | break; |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame] | 125 | case SMB2_OP_RMDIR: |
| 126 | memset(&si_iov, 0, sizeof(si_iov)); |
| 127 | rqst[num_rqst].rq_iov = si_iov; |
| 128 | rqst[num_rqst].rq_nvec = 1; |
| 129 | |
| 130 | size[0] = 8; |
| 131 | data[0] = &delete_pending[0]; |
| 132 | |
| 133 | rc = SMB2_set_info_init(tcon, &rqst[num_rqst], COMPOUND_FID, |
| 134 | COMPOUND_FID, current->tgid, |
| 135 | FILE_DISPOSITION_INFORMATION, |
| 136 | SMB2_O_INFO_FILE, 0, data, size); |
| 137 | smb2_set_next_command(server, &rqst[num_rqst]); |
| 138 | smb2_set_related(&rqst[num_rqst++]); |
| 139 | break; |
Ronnie Sahlberg | f7bfe04 | 2018-09-03 13:33:46 +1000 | [diff] [blame] | 140 | case SMB2_OP_SET_EOF: |
| 141 | memset(&si_iov, 0, sizeof(si_iov)); |
| 142 | rqst[num_rqst].rq_iov = si_iov; |
| 143 | rqst[num_rqst].rq_nvec = 1; |
| 144 | |
| 145 | size[0] = 8; /* sizeof __le64 */ |
| 146 | data[0] = ptr; |
| 147 | |
| 148 | rc = SMB2_set_info_init(tcon, &rqst[num_rqst], COMPOUND_FID, |
| 149 | COMPOUND_FID, current->tgid, |
| 150 | FILE_END_OF_FILE_INFORMATION, |
| 151 | SMB2_O_INFO_FILE, 0, data, size); |
| 152 | smb2_set_next_command(server, &rqst[num_rqst]); |
| 153 | smb2_set_related(&rqst[num_rqst++]); |
| 154 | break; |
Ronnie Sahlberg | dcbf910 | 2018-09-03 13:33:48 +1000 | [diff] [blame] | 155 | case SMB2_OP_SET_INFO: |
| 156 | memset(&si_iov, 0, sizeof(si_iov)); |
| 157 | rqst[num_rqst].rq_iov = si_iov; |
| 158 | rqst[num_rqst].rq_nvec = 1; |
| 159 | |
Ronnie Sahlberg | bb43551 | 2018-09-03 13:33:49 +1000 | [diff] [blame] | 160 | |
Ronnie Sahlberg | dcbf910 | 2018-09-03 13:33:48 +1000 | [diff] [blame] | 161 | size[0] = sizeof(FILE_BASIC_INFO); |
| 162 | data[0] = ptr; |
| 163 | |
| 164 | rc = SMB2_set_info_init(tcon, &rqst[num_rqst], COMPOUND_FID, |
| 165 | COMPOUND_FID, current->tgid, |
| 166 | FILE_BASIC_INFORMATION, |
| 167 | SMB2_O_INFO_FILE, 0, data, size); |
| 168 | smb2_set_next_command(server, &rqst[num_rqst]); |
| 169 | smb2_set_related(&rqst[num_rqst++]); |
| 170 | break; |
Ronnie Sahlberg | bb43551 | 2018-09-03 13:33:49 +1000 | [diff] [blame] | 171 | case SMB2_OP_RENAME: |
| 172 | memset(&si_iov, 0, sizeof(si_iov)); |
| 173 | rqst[num_rqst].rq_iov = si_iov; |
| 174 | rqst[num_rqst].rq_nvec = 2; |
| 175 | |
| 176 | len = (2 * UniStrnlen((wchar_t *)ptr, PATH_MAX)); |
| 177 | |
| 178 | rename_info.ReplaceIfExists = 1; |
| 179 | rename_info.RootDirectory = 0; |
| 180 | rename_info.FileNameLength = cpu_to_le32(len); |
| 181 | |
| 182 | size[0] = sizeof(struct smb2_file_rename_info); |
| 183 | data[0] = &rename_info; |
| 184 | |
| 185 | size[1] = len + 2 /* null */; |
| 186 | data[1] = (__le16 *)ptr; |
| 187 | |
| 188 | rc = SMB2_set_info_init(tcon, &rqst[num_rqst], COMPOUND_FID, |
| 189 | COMPOUND_FID, current->tgid, |
| 190 | FILE_RENAME_INFORMATION, |
| 191 | SMB2_O_INFO_FILE, 0, data, size); |
| 192 | smb2_set_next_command(server, &rqst[num_rqst]); |
| 193 | smb2_set_related(&rqst[num_rqst++]); |
| 194 | break; |
| 195 | case SMB2_OP_HARDLINK: |
| 196 | memset(&si_iov, 0, sizeof(si_iov)); |
| 197 | rqst[num_rqst].rq_iov = si_iov; |
| 198 | rqst[num_rqst].rq_nvec = 2; |
| 199 | |
| 200 | len = (2 * UniStrnlen((wchar_t *)ptr, PATH_MAX)); |
| 201 | |
| 202 | link_info.ReplaceIfExists = 0; |
| 203 | link_info.RootDirectory = 0; |
| 204 | link_info.FileNameLength = cpu_to_le32(len); |
| 205 | |
| 206 | size[0] = sizeof(struct smb2_file_link_info); |
| 207 | data[0] = &link_info; |
| 208 | |
| 209 | size[1] = len + 2 /* null */; |
| 210 | data[1] = (__le16 *)ptr; |
| 211 | |
| 212 | rc = SMB2_set_info_init(tcon, &rqst[num_rqst], COMPOUND_FID, |
| 213 | COMPOUND_FID, current->tgid, |
| 214 | FILE_LINK_INFORMATION, |
| 215 | SMB2_O_INFO_FILE, 0, data, size); |
| 216 | smb2_set_next_command(server, &rqst[num_rqst]); |
| 217 | smb2_set_related(&rqst[num_rqst++]); |
| 218 | break; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 219 | default: |
| 220 | cifs_dbg(VFS, "Invalid command\n"); |
| 221 | rc = -EINVAL; |
| 222 | } |
| 223 | if (rc) |
| 224 | goto finished; |
| 225 | |
| 226 | /* Close */ |
| 227 | memset(&close_iov, 0, sizeof(close_iov)); |
| 228 | rqst[num_rqst].rq_iov = close_iov; |
| 229 | rqst[num_rqst].rq_nvec = 1; |
| 230 | rc = SMB2_close_init(tcon, &rqst[num_rqst], COMPOUND_FID, |
| 231 | COMPOUND_FID); |
| 232 | smb2_set_related(&rqst[num_rqst++]); |
| 233 | if (rc) |
| 234 | goto finished; |
| 235 | |
| 236 | rc = compound_send_recv(xid, ses, flags, num_rqst, rqst, |
| 237 | resp_buftype, rsp_iov); |
| 238 | |
| 239 | finished: |
| 240 | SMB2_open_free(&rqst[0]); |
| 241 | switch (command) { |
| 242 | case SMB2_OP_QUERY_INFO: |
| 243 | if (rc == 0) { |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame] | 244 | qi_rsp = (struct smb2_query_info_rsp *) |
| 245 | rsp_iov[1].iov_base; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 246 | rc = smb2_validate_and_copy_iov( |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame] | 247 | le16_to_cpu(qi_rsp->OutputBufferOffset), |
| 248 | le32_to_cpu(qi_rsp->OutputBufferLength), |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 249 | &rsp_iov[1], sizeof(struct smb2_file_all_info), |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame] | 250 | ptr); |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 251 | } |
| 252 | if (rqst[1].rq_iov) |
| 253 | SMB2_query_info_free(&rqst[1]); |
| 254 | if (rqst[2].rq_iov) |
| 255 | SMB2_close_free(&rqst[2]); |
| 256 | break; |
Ronnie Sahlberg | 47dd959 | 2018-09-03 13:33:43 +1000 | [diff] [blame] | 257 | case SMB2_OP_DELETE: |
Ronnie Sahlberg | f733e39 | 2018-09-03 13:33:42 +1000 | [diff] [blame] | 258 | case SMB2_OP_MKDIR: |
| 259 | if (rqst[1].rq_iov) |
| 260 | SMB2_close_free(&rqst[1]); |
| 261 | break; |
Ronnie Sahlberg | bb43551 | 2018-09-03 13:33:49 +1000 | [diff] [blame] | 262 | case SMB2_OP_HARDLINK: |
| 263 | case SMB2_OP_RENAME: |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame] | 264 | case SMB2_OP_RMDIR: |
Ronnie Sahlberg | dcbf910 | 2018-09-03 13:33:48 +1000 | [diff] [blame] | 265 | case SMB2_OP_SET_EOF: |
| 266 | case SMB2_OP_SET_INFO: |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame] | 267 | if (rqst[1].rq_iov) |
| 268 | SMB2_set_info_free(&rqst[1]); |
| 269 | if (rqst[2].rq_iov) |
| 270 | SMB2_close_free(&rqst[2]); |
| 271 | break; |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 272 | } |
| 273 | free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base); |
| 274 | free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base); |
| 275 | free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base); |
| 276 | return rc; |
| 277 | } |
| 278 | |
Pavel Shilovsky | f0df737 | 2012-09-18 16:20:26 -0700 | [diff] [blame] | 279 | void |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 280 | move_smb2_info_to_cifs(FILE_ALL_INFO *dst, struct smb2_file_all_info *src) |
| 281 | { |
| 282 | memcpy(dst, src, (size_t)(&src->CurrentByteOffset) - (size_t)src); |
| 283 | dst->CurrentByteOffset = src->CurrentByteOffset; |
| 284 | dst->Mode = src->Mode; |
| 285 | dst->AlignmentRequirement = src->AlignmentRequirement; |
| 286 | dst->IndexNumber1 = 0; /* we don't use it */ |
| 287 | } |
| 288 | |
| 289 | int |
| 290 | smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, |
| 291 | struct cifs_sb_info *cifs_sb, const char *full_path, |
Pavel Shilovsky | eb85d94b | 2013-10-23 17:49:47 +0400 | [diff] [blame] | 292 | FILE_ALL_INFO *data, bool *adjust_tz, bool *symlink) |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 293 | { |
| 294 | int rc; |
| 295 | struct smb2_file_all_info *smb2_data; |
Steve French | 61351d6 | 2018-10-19 00:32:41 -0500 | [diff] [blame] | 296 | __u32 create_options = 0; |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 297 | |
| 298 | *adjust_tz = false; |
Pavel Shilovsky | eb85d94b | 2013-10-23 17:49:47 +0400 | [diff] [blame] | 299 | *symlink = false; |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 300 | |
Pavel Shilovsky | 1bbe499 | 2014-08-22 13:32:11 +0400 | [diff] [blame] | 301 | smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2, |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 302 | GFP_KERNEL); |
| 303 | if (smb2_data == NULL) |
| 304 | return -ENOMEM; |
Steve French | 61351d6 | 2018-10-19 00:32:41 -0500 | [diff] [blame] | 305 | if (backup_cred(cifs_sb)) |
| 306 | create_options |= CREATE_OPEN_BACKUP_INTENT; |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 307 | |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 308 | rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, |
Steve French | 61351d6 | 2018-10-19 00:32:41 -0500 | [diff] [blame] | 309 | FILE_READ_ATTRIBUTES, FILE_OPEN, create_options, |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 310 | smb2_data, SMB2_OP_QUERY_INFO); |
Pavel Shilovsky | eb85d94b | 2013-10-23 17:49:47 +0400 | [diff] [blame] | 311 | if (rc == -EOPNOTSUPP) { |
| 312 | *symlink = true; |
Steve French | 61351d6 | 2018-10-19 00:32:41 -0500 | [diff] [blame] | 313 | create_options |= OPEN_REPARSE_POINT; |
| 314 | |
Pavel Shilovsky | eb85d94b | 2013-10-23 17:49:47 +0400 | [diff] [blame] | 315 | /* Failed on a symbolic link - query a reparse point info */ |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 316 | rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, |
| 317 | FILE_READ_ATTRIBUTES, FILE_OPEN, |
Steve French | 61351d6 | 2018-10-19 00:32:41 -0500 | [diff] [blame] | 318 | create_options, smb2_data, |
Ronnie Sahlberg | c5a5f38 | 2018-09-03 13:33:41 +1000 | [diff] [blame] | 319 | SMB2_OP_QUERY_INFO); |
Pavel Shilovsky | eb85d94b | 2013-10-23 17:49:47 +0400 | [diff] [blame] | 320 | } |
Pavel Shilovsky | be4cb9e | 2011-12-29 17:06:33 +0400 | [diff] [blame] | 321 | if (rc) |
| 322 | goto out; |
| 323 | |
| 324 | move_smb2_info_to_cifs(data, smb2_data); |
| 325 | out: |
| 326 | kfree(smb2_data); |
| 327 | return rc; |
| 328 | } |
Pavel Shilovsky | a0e7318 | 2011-07-19 12:56:37 +0400 | [diff] [blame] | 329 | |
| 330 | int |
| 331 | smb2_mkdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name, |
| 332 | struct cifs_sb_info *cifs_sb) |
| 333 | { |
Ronnie Sahlberg | f733e39 | 2018-09-03 13:33:42 +1000 | [diff] [blame] | 334 | return smb2_compound_op(xid, tcon, cifs_sb, name, |
| 335 | FILE_WRITE_ATTRIBUTES, FILE_CREATE, |
| 336 | CREATE_NOT_FILE, NULL, SMB2_OP_MKDIR); |
Pavel Shilovsky | a0e7318 | 2011-07-19 12:56:37 +0400 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | void |
| 340 | smb2_mkdir_setinfo(struct inode *inode, const char *name, |
| 341 | struct cifs_sb_info *cifs_sb, struct cifs_tcon *tcon, |
| 342 | const unsigned int xid) |
| 343 | { |
| 344 | FILE_BASIC_INFO data; |
| 345 | struct cifsInodeInfo *cifs_i; |
| 346 | u32 dosattrs; |
| 347 | int tmprc; |
| 348 | |
| 349 | memset(&data, 0, sizeof(data)); |
| 350 | cifs_i = CIFS_I(inode); |
| 351 | dosattrs = cifs_i->cifsAttrs | ATTR_READONLY; |
| 352 | data.Attributes = cpu_to_le32(dosattrs); |
Ronnie Sahlberg | dcbf910 | 2018-09-03 13:33:48 +1000 | [diff] [blame] | 353 | tmprc = smb2_compound_op(xid, tcon, cifs_sb, name, |
| 354 | FILE_WRITE_ATTRIBUTES, FILE_CREATE, |
| 355 | CREATE_NOT_FILE, &data, SMB2_OP_SET_INFO); |
Pavel Shilovsky | a0e7318 | 2011-07-19 12:56:37 +0400 | [diff] [blame] | 356 | if (tmprc == 0) |
| 357 | cifs_i->cifsAttrs = dosattrs; |
| 358 | } |
Pavel Shilovsky | 1a500f0 | 2012-07-10 16:14:38 +0400 | [diff] [blame] | 359 | |
| 360 | int |
| 361 | smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name, |
| 362 | struct cifs_sb_info *cifs_sb) |
| 363 | { |
Ronnie Sahlberg | c2e0fe3 | 2018-09-03 13:33:45 +1000 | [diff] [blame] | 364 | return smb2_compound_op(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN, |
| 365 | CREATE_NOT_FILE, |
| 366 | NULL, SMB2_OP_RMDIR); |
Pavel Shilovsky | 1a500f0 | 2012-07-10 16:14:38 +0400 | [diff] [blame] | 367 | } |
Pavel Shilovsky | cbe6f43 | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 368 | |
| 369 | int |
| 370 | smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *name, |
| 371 | struct cifs_sb_info *cifs_sb) |
| 372 | { |
Ronnie Sahlberg | 47dd959 | 2018-09-03 13:33:43 +1000 | [diff] [blame] | 373 | return smb2_compound_op(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN, |
| 374 | CREATE_DELETE_ON_CLOSE | OPEN_REPARSE_POINT, |
| 375 | NULL, SMB2_OP_DELETE); |
Pavel Shilovsky | cbe6f43 | 2012-09-18 16:20:25 -0700 | [diff] [blame] | 376 | } |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 377 | |
Pavel Shilovsky | 568798c | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 378 | static int |
| 379 | smb2_set_path_attr(const unsigned int xid, struct cifs_tcon *tcon, |
| 380 | const char *from_name, const char *to_name, |
| 381 | struct cifs_sb_info *cifs_sb, __u32 access, int command) |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 382 | { |
| 383 | __le16 *smb2_to_name = NULL; |
| 384 | int rc; |
| 385 | |
| 386 | smb2_to_name = cifs_convert_path_to_utf16(to_name, cifs_sb); |
| 387 | if (smb2_to_name == NULL) { |
| 388 | rc = -ENOMEM; |
| 389 | goto smb2_rename_path; |
| 390 | } |
| 391 | |
Ronnie Sahlberg | bb43551 | 2018-09-03 13:33:49 +1000 | [diff] [blame] | 392 | rc = smb2_compound_op(xid, tcon, cifs_sb, from_name, access, |
| 393 | FILE_OPEN, 0, smb2_to_name, command); |
Pavel Shilovsky | 35143eb | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 394 | smb2_rename_path: |
| 395 | kfree(smb2_to_name); |
| 396 | return rc; |
| 397 | } |
Pavel Shilovsky | 568798c | 2012-09-18 16:20:31 -0700 | [diff] [blame] | 398 | |
| 399 | int |
| 400 | smb2_rename_path(const unsigned int xid, struct cifs_tcon *tcon, |
| 401 | const char *from_name, const char *to_name, |
| 402 | struct cifs_sb_info *cifs_sb) |
| 403 | { |
| 404 | return smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb, |
| 405 | DELETE, SMB2_OP_RENAME); |
| 406 | } |
| 407 | |
| 408 | int |
| 409 | smb2_create_hardlink(const unsigned int xid, struct cifs_tcon *tcon, |
| 410 | const char *from_name, const char *to_name, |
| 411 | struct cifs_sb_info *cifs_sb) |
| 412 | { |
| 413 | return smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb, |
| 414 | FILE_READ_ATTRIBUTES, SMB2_OP_HARDLINK); |
| 415 | } |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 416 | |
| 417 | int |
| 418 | smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon, |
| 419 | const char *full_path, __u64 size, |
| 420 | struct cifs_sb_info *cifs_sb, bool set_alloc) |
| 421 | { |
| 422 | __le64 eof = cpu_to_le64(size); |
Ronnie Sahlberg | f7bfe04 | 2018-09-03 13:33:46 +1000 | [diff] [blame] | 423 | |
| 424 | return smb2_compound_op(xid, tcon, cifs_sb, full_path, |
| 425 | FILE_WRITE_DATA, FILE_OPEN, 0, &eof, |
| 426 | SMB2_OP_SET_EOF); |
Pavel Shilovsky | c839ff2 | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 427 | } |
Pavel Shilovsky | 1feeaac | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 428 | |
| 429 | int |
| 430 | smb2_set_file_info(struct inode *inode, const char *full_path, |
| 431 | FILE_BASIC_INFO *buf, const unsigned int xid) |
| 432 | { |
| 433 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); |
| 434 | struct tcon_link *tlink; |
| 435 | int rc; |
| 436 | |
Steve French | 18dd8e1 | 2016-09-26 14:23:08 -0500 | [diff] [blame] | 437 | if ((buf->CreationTime == 0) && (buf->LastAccessTime == 0) && |
Steve French | fd09b7d | 2018-08-02 20:28:18 -0500 | [diff] [blame] | 438 | (buf->LastWriteTime == 0) && (buf->ChangeTime == 0) && |
Steve French | 18dd8e1 | 2016-09-26 14:23:08 -0500 | [diff] [blame] | 439 | (buf->Attributes == 0)) |
| 440 | return 0; /* would be a no op, no sense sending this */ |
| 441 | |
Pavel Shilovsky | 1feeaac | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 442 | tlink = cifs_sb_tlink(cifs_sb); |
| 443 | if (IS_ERR(tlink)) |
| 444 | return PTR_ERR(tlink); |
Steve French | 18dd8e1 | 2016-09-26 14:23:08 -0500 | [diff] [blame] | 445 | |
Ronnie Sahlberg | dcbf910 | 2018-09-03 13:33:48 +1000 | [diff] [blame] | 446 | rc = smb2_compound_op(xid, tlink_tcon(tlink), cifs_sb, full_path, |
| 447 | FILE_WRITE_ATTRIBUTES, FILE_OPEN, 0, buf, |
| 448 | SMB2_OP_SET_INFO); |
Pavel Shilovsky | 1feeaac | 2012-09-18 16:20:32 -0700 | [diff] [blame] | 449 | cifs_put_tlink(tlink); |
| 450 | return rc; |
| 451 | } |