Commit | Line | Data |
---|---|---|
be4cb9e3 PS |
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 | ||
8191576a SF |
40 | static void |
41 | free_set_inf_compound(struct smb_rqst *rqst) | |
42 | { | |
43 | if (rqst[1].rq_iov) | |
44 | SMB2_set_info_free(&rqst[1]); | |
45 | if (rqst[2].rq_iov) | |
46 | SMB2_close_free(&rqst[2]); | |
47 | } | |
48 | ||
49 | ||
c5a5f38f RS |
50 | static int |
51 | smb2_compound_op(const unsigned int xid, struct cifs_tcon *tcon, | |
52 | struct cifs_sb_info *cifs_sb, const char *full_path, | |
53 | __u32 desired_access, __u32 create_disposition, | |
8de9e86c RS |
54 | __u32 create_options, void *ptr, int command, |
55 | struct cifsFileInfo *cfile) | |
c5a5f38f RS |
56 | { |
57 | int rc; | |
58 | __le16 *utf16_path = NULL; | |
59 | __u8 oplock = SMB2_OPLOCK_LEVEL_NONE; | |
60 | struct cifs_open_parms oparms; | |
61 | struct cifs_fid fid; | |
62 | struct cifs_ses *ses = tcon->ses; | |
c5a5f38f RS |
63 | int num_rqst = 0; |
64 | struct smb_rqst rqst[3]; | |
65 | int resp_buftype[3]; | |
66 | struct kvec rsp_iov[3]; | |
67 | struct kvec open_iov[SMB2_CREATE_IOV_SIZE]; | |
68 | struct kvec qi_iov[1]; | |
14e562ad | 69 | struct kvec si_iov[SMB2_SET_INFO_IOV_SIZE]; |
c5a5f38f | 70 | struct kvec close_iov[1]; |
c2e0fe3f | 71 | struct smb2_query_info_rsp *qi_rsp = NULL; |
c5a5f38f | 72 | int flags = 0; |
c2e0fe3f | 73 | __u8 delete_pending[8] = {1, 0, 0, 0, 0, 0, 0, 0}; |
bb435512 RS |
74 | unsigned int size[2]; |
75 | void *data[2]; | |
76 | struct smb2_file_rename_info rename_info; | |
77 | struct smb2_file_link_info link_info; | |
78 | int len; | |
c5a5f38f RS |
79 | |
80 | if (smb3_encryption_required(tcon)) | |
81 | flags |= CIFS_TRANSFORM_REQ; | |
82 | ||
83 | memset(rqst, 0, sizeof(rqst)); | |
84 | resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER; | |
85 | memset(rsp_iov, 0, sizeof(rsp_iov)); | |
86 | ||
8de9e86c RS |
87 | /* We already have a handle so we can skip the open */ |
88 | if (cfile) | |
89 | goto after_open; | |
90 | ||
c5a5f38f RS |
91 | /* Open */ |
92 | utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb); | |
8de9e86c RS |
93 | if (!utf16_path) { |
94 | rc = -ENOMEM; | |
95 | goto finished; | |
96 | } | |
c5a5f38f RS |
97 | |
98 | oparms.tcon = tcon; | |
99 | oparms.desired_access = desired_access; | |
100 | oparms.disposition = create_disposition; | |
101 | oparms.create_options = create_options; | |
4d5bdf28 SF |
102 | if (backup_cred(cifs_sb)) |
103 | oparms.create_options |= CREATE_OPEN_BACKUP_INTENT; | |
c5a5f38f RS |
104 | oparms.fid = &fid; |
105 | oparms.reconnect = false; | |
106 | ||
107 | memset(&open_iov, 0, sizeof(open_iov)); | |
108 | rqst[num_rqst].rq_iov = open_iov; | |
109 | rqst[num_rqst].rq_nvec = SMB2_CREATE_IOV_SIZE; | |
110 | rc = SMB2_open_init(tcon, &rqst[num_rqst], &oplock, &oparms, | |
111 | utf16_path); | |
112 | kfree(utf16_path); | |
113 | if (rc) | |
114 | goto finished; | |
115 | ||
8de9e86c RS |
116 | smb2_set_next_command(tcon, &rqst[num_rqst]); |
117 | after_open: | |
118 | num_rqst++; | |
119 | rc = 0; | |
c5a5f38f RS |
120 | |
121 | /* Operation */ | |
122 | switch (command) { | |
123 | case SMB2_OP_QUERY_INFO: | |
124 | memset(&qi_iov, 0, sizeof(qi_iov)); | |
125 | rqst[num_rqst].rq_iov = qi_iov; | |
126 | rqst[num_rqst].rq_nvec = 1; | |
127 | ||
496902dc RS |
128 | if (cfile) |
129 | rc = SMB2_query_info_init(tcon, &rqst[num_rqst], | |
130 | cfile->fid.persistent_fid, | |
131 | cfile->fid.volatile_fid, | |
132 | FILE_ALL_INFORMATION, | |
c5a5f38f RS |
133 | SMB2_O_INFO_FILE, 0, |
134 | sizeof(struct smb2_file_all_info) + | |
f5b05d62 | 135 | PATH_MAX * 2, 0, NULL); |
496902dc RS |
136 | else { |
137 | rc = SMB2_query_info_init(tcon, &rqst[num_rqst], | |
138 | COMPOUND_FID, | |
139 | COMPOUND_FID, | |
140 | FILE_ALL_INFORMATION, | |
141 | SMB2_O_INFO_FILE, 0, | |
142 | sizeof(struct smb2_file_all_info) + | |
143 | PATH_MAX * 2, 0, NULL); | |
144 | if (!rc) { | |
145 | smb2_set_next_command(tcon, &rqst[num_rqst]); | |
146 | smb2_set_related(&rqst[num_rqst]); | |
147 | } | |
148 | } | |
149 | ||
88a92c91 RS |
150 | if (rc) |
151 | goto finished; | |
496902dc | 152 | num_rqst++; |
8191576a SF |
153 | trace_smb3_query_info_compound_enter(xid, ses->Suid, tcon->tid, |
154 | full_path); | |
c5a5f38f | 155 | break; |
47dd9597 | 156 | case SMB2_OP_DELETE: |
8191576a | 157 | trace_smb3_delete_enter(xid, ses->Suid, tcon->tid, full_path); |
47dd9597 | 158 | break; |
f733e393 RS |
159 | case SMB2_OP_MKDIR: |
160 | /* | |
161 | * Directories are created through parameters in the | |
162 | * SMB2_open() call. | |
163 | */ | |
8191576a | 164 | trace_smb3_mkdir_enter(xid, ses->Suid, tcon->tid, full_path); |
f733e393 | 165 | break; |
c2e0fe3f RS |
166 | case SMB2_OP_RMDIR: |
167 | memset(&si_iov, 0, sizeof(si_iov)); | |
168 | rqst[num_rqst].rq_iov = si_iov; | |
169 | rqst[num_rqst].rq_nvec = 1; | |
170 | ||
271b9c0c | 171 | size[0] = 1; /* sizeof __u8 See MS-FSCC section 2.4.11 */ |
c2e0fe3f RS |
172 | data[0] = &delete_pending[0]; |
173 | ||
174 | rc = SMB2_set_info_init(tcon, &rqst[num_rqst], COMPOUND_FID, | |
175 | COMPOUND_FID, current->tgid, | |
176 | FILE_DISPOSITION_INFORMATION, | |
177 | SMB2_O_INFO_FILE, 0, data, size); | |
88a92c91 RS |
178 | if (rc) |
179 | goto finished; | |
e77fe73c | 180 | smb2_set_next_command(tcon, &rqst[num_rqst]); |
c2e0fe3f | 181 | smb2_set_related(&rqst[num_rqst++]); |
8191576a | 182 | trace_smb3_rmdir_enter(xid, ses->Suid, tcon->tid, full_path); |
c2e0fe3f | 183 | break; |
f7bfe04b RS |
184 | case SMB2_OP_SET_EOF: |
185 | memset(&si_iov, 0, sizeof(si_iov)); | |
186 | rqst[num_rqst].rq_iov = si_iov; | |
187 | rqst[num_rqst].rq_nvec = 1; | |
188 | ||
189 | size[0] = 8; /* sizeof __le64 */ | |
190 | data[0] = ptr; | |
191 | ||
192 | rc = SMB2_set_info_init(tcon, &rqst[num_rqst], COMPOUND_FID, | |
193 | COMPOUND_FID, current->tgid, | |
194 | FILE_END_OF_FILE_INFORMATION, | |
195 | SMB2_O_INFO_FILE, 0, data, size); | |
88a92c91 RS |
196 | if (rc) |
197 | goto finished; | |
e77fe73c | 198 | smb2_set_next_command(tcon, &rqst[num_rqst]); |
f7bfe04b | 199 | smb2_set_related(&rqst[num_rqst++]); |
8191576a | 200 | trace_smb3_set_eof_enter(xid, ses->Suid, tcon->tid, full_path); |
f7bfe04b | 201 | break; |
dcbf9103 RS |
202 | case SMB2_OP_SET_INFO: |
203 | memset(&si_iov, 0, sizeof(si_iov)); | |
204 | rqst[num_rqst].rq_iov = si_iov; | |
205 | rqst[num_rqst].rq_nvec = 1; | |
206 | ||
bb435512 | 207 | |
dcbf9103 RS |
208 | size[0] = sizeof(FILE_BASIC_INFO); |
209 | data[0] = ptr; | |
210 | ||
dc9300a6 RS |
211 | if (cfile) |
212 | rc = SMB2_set_info_init(tcon, &rqst[num_rqst], | |
213 | cfile->fid.persistent_fid, | |
214 | cfile->fid.volatile_fid, current->tgid, | |
215 | FILE_BASIC_INFORMATION, | |
216 | SMB2_O_INFO_FILE, 0, data, size); | |
217 | else { | |
218 | rc = SMB2_set_info_init(tcon, &rqst[num_rqst], | |
219 | COMPOUND_FID, | |
220 | COMPOUND_FID, current->tgid, | |
221 | FILE_BASIC_INFORMATION, | |
222 | SMB2_O_INFO_FILE, 0, data, size); | |
223 | if (!rc) { | |
224 | smb2_set_next_command(tcon, &rqst[num_rqst]); | |
225 | smb2_set_related(&rqst[num_rqst]); | |
226 | } | |
227 | } | |
228 | ||
88a92c91 RS |
229 | if (rc) |
230 | goto finished; | |
dc9300a6 | 231 | num_rqst++; |
8191576a SF |
232 | trace_smb3_set_info_compound_enter(xid, ses->Suid, tcon->tid, |
233 | full_path); | |
dcbf9103 | 234 | break; |
bb435512 RS |
235 | case SMB2_OP_RENAME: |
236 | memset(&si_iov, 0, sizeof(si_iov)); | |
237 | rqst[num_rqst].rq_iov = si_iov; | |
238 | rqst[num_rqst].rq_nvec = 2; | |
239 | ||
240 | len = (2 * UniStrnlen((wchar_t *)ptr, PATH_MAX)); | |
241 | ||
242 | rename_info.ReplaceIfExists = 1; | |
243 | rename_info.RootDirectory = 0; | |
244 | rename_info.FileNameLength = cpu_to_le32(len); | |
245 | ||
246 | size[0] = sizeof(struct smb2_file_rename_info); | |
247 | data[0] = &rename_info; | |
248 | ||
249 | size[1] = len + 2 /* null */; | |
250 | data[1] = (__le16 *)ptr; | |
251 | ||
8de9e86c RS |
252 | if (cfile) |
253 | rc = SMB2_set_info_init(tcon, &rqst[num_rqst], | |
254 | cfile->fid.persistent_fid, | |
255 | cfile->fid.volatile_fid, | |
256 | current->tgid, FILE_RENAME_INFORMATION, | |
257 | SMB2_O_INFO_FILE, 0, data, size); | |
258 | else { | |
259 | rc = SMB2_set_info_init(tcon, &rqst[num_rqst], | |
260 | COMPOUND_FID, COMPOUND_FID, | |
261 | current->tgid, FILE_RENAME_INFORMATION, | |
bb435512 | 262 | SMB2_O_INFO_FILE, 0, data, size); |
dc9300a6 RS |
263 | if (!rc) { |
264 | smb2_set_next_command(tcon, &rqst[num_rqst]); | |
265 | smb2_set_related(&rqst[num_rqst]); | |
266 | } | |
8de9e86c | 267 | } |
88a92c91 RS |
268 | if (rc) |
269 | goto finished; | |
8de9e86c | 270 | num_rqst++; |
8191576a | 271 | trace_smb3_rename_enter(xid, ses->Suid, tcon->tid, full_path); |
bb435512 RS |
272 | break; |
273 | case SMB2_OP_HARDLINK: | |
274 | memset(&si_iov, 0, sizeof(si_iov)); | |
275 | rqst[num_rqst].rq_iov = si_iov; | |
276 | rqst[num_rqst].rq_nvec = 2; | |
277 | ||
278 | len = (2 * UniStrnlen((wchar_t *)ptr, PATH_MAX)); | |
279 | ||
280 | link_info.ReplaceIfExists = 0; | |
281 | link_info.RootDirectory = 0; | |
282 | link_info.FileNameLength = cpu_to_le32(len); | |
283 | ||
284 | size[0] = sizeof(struct smb2_file_link_info); | |
285 | data[0] = &link_info; | |
286 | ||
287 | size[1] = len + 2 /* null */; | |
288 | data[1] = (__le16 *)ptr; | |
289 | ||
290 | rc = SMB2_set_info_init(tcon, &rqst[num_rqst], COMPOUND_FID, | |
291 | COMPOUND_FID, current->tgid, | |
292 | FILE_LINK_INFORMATION, | |
293 | SMB2_O_INFO_FILE, 0, data, size); | |
88a92c91 RS |
294 | if (rc) |
295 | goto finished; | |
e77fe73c | 296 | smb2_set_next_command(tcon, &rqst[num_rqst]); |
bb435512 | 297 | smb2_set_related(&rqst[num_rqst++]); |
8191576a | 298 | trace_smb3_hardlink_enter(xid, ses->Suid, tcon->tid, full_path); |
bb435512 | 299 | break; |
c5a5f38f RS |
300 | default: |
301 | cifs_dbg(VFS, "Invalid command\n"); | |
302 | rc = -EINVAL; | |
303 | } | |
304 | if (rc) | |
305 | goto finished; | |
306 | ||
8de9e86c RS |
307 | /* We already have a handle so we can skip the close */ |
308 | if (cfile) | |
309 | goto after_close; | |
c5a5f38f RS |
310 | /* Close */ |
311 | memset(&close_iov, 0, sizeof(close_iov)); | |
312 | rqst[num_rqst].rq_iov = close_iov; | |
313 | rqst[num_rqst].rq_nvec = 1; | |
314 | rc = SMB2_close_init(tcon, &rqst[num_rqst], COMPOUND_FID, | |
315 | COMPOUND_FID); | |
8de9e86c | 316 | smb2_set_related(&rqst[num_rqst]); |
c5a5f38f RS |
317 | if (rc) |
318 | goto finished; | |
8de9e86c RS |
319 | after_close: |
320 | num_rqst++; | |
321 | ||
322 | if (cfile) { | |
323 | cifsFileInfo_put(cfile); | |
324 | cfile = NULL; | |
325 | rc = compound_send_recv(xid, ses, flags, num_rqst - 2, | |
326 | &rqst[1], &resp_buftype[1], | |
327 | &rsp_iov[1]); | |
328 | } else | |
329 | rc = compound_send_recv(xid, ses, flags, num_rqst, | |
330 | rqst, resp_buftype, | |
331 | rsp_iov); | |
c5a5f38f RS |
332 | |
333 | finished: | |
8de9e86c RS |
334 | if (cfile) |
335 | cifsFileInfo_put(cfile); | |
336 | ||
c5a5f38f | 337 | SMB2_open_free(&rqst[0]); |
7dcc82c2 SF |
338 | if (rc == -EREMCHG) { |
339 | printk_once(KERN_WARNING "server share %s deleted\n", | |
340 | tcon->treeName); | |
341 | tcon->need_reconnect = true; | |
342 | } | |
343 | ||
c5a5f38f RS |
344 | switch (command) { |
345 | case SMB2_OP_QUERY_INFO: | |
346 | if (rc == 0) { | |
c2e0fe3f RS |
347 | qi_rsp = (struct smb2_query_info_rsp *) |
348 | rsp_iov[1].iov_base; | |
c5a5f38f | 349 | rc = smb2_validate_and_copy_iov( |
c2e0fe3f RS |
350 | le16_to_cpu(qi_rsp->OutputBufferOffset), |
351 | le32_to_cpu(qi_rsp->OutputBufferLength), | |
c5a5f38f | 352 | &rsp_iov[1], sizeof(struct smb2_file_all_info), |
c2e0fe3f | 353 | ptr); |
c5a5f38f RS |
354 | } |
355 | if (rqst[1].rq_iov) | |
356 | SMB2_query_info_free(&rqst[1]); | |
357 | if (rqst[2].rq_iov) | |
358 | SMB2_close_free(&rqst[2]); | |
8191576a SF |
359 | if (rc) |
360 | trace_smb3_query_info_compound_err(xid, ses->Suid, | |
361 | tcon->tid, rc); | |
362 | else | |
363 | trace_smb3_query_info_compound_done(xid, ses->Suid, | |
364 | tcon->tid); | |
c5a5f38f | 365 | break; |
47dd9597 | 366 | case SMB2_OP_DELETE: |
8191576a SF |
367 | if (rc) |
368 | trace_smb3_delete_err(xid, ses->Suid, tcon->tid, rc); | |
369 | else | |
370 | trace_smb3_delete_done(xid, ses->Suid, tcon->tid); | |
371 | if (rqst[1].rq_iov) | |
372 | SMB2_close_free(&rqst[1]); | |
373 | break; | |
f733e393 | 374 | case SMB2_OP_MKDIR: |
8191576a SF |
375 | if (rc) |
376 | trace_smb3_mkdir_err(xid, ses->Suid, tcon->tid, rc); | |
377 | else | |
378 | trace_smb3_mkdir_done(xid, ses->Suid, tcon->tid); | |
f733e393 RS |
379 | if (rqst[1].rq_iov) |
380 | SMB2_close_free(&rqst[1]); | |
381 | break; | |
bb435512 | 382 | case SMB2_OP_HARDLINK: |
8191576a SF |
383 | if (rc) |
384 | trace_smb3_hardlink_err(xid, ses->Suid, tcon->tid, rc); | |
385 | else | |
386 | trace_smb3_hardlink_done(xid, ses->Suid, tcon->tid); | |
387 | free_set_inf_compound(rqst); | |
388 | break; | |
bb435512 | 389 | case SMB2_OP_RENAME: |
8191576a SF |
390 | if (rc) |
391 | trace_smb3_rename_err(xid, ses->Suid, tcon->tid, rc); | |
392 | else | |
393 | trace_smb3_rename_done(xid, ses->Suid, tcon->tid); | |
394 | free_set_inf_compound(rqst); | |
395 | break; | |
c2e0fe3f | 396 | case SMB2_OP_RMDIR: |
8191576a SF |
397 | if (rc) |
398 | trace_smb3_rmdir_err(xid, ses->Suid, tcon->tid, rc); | |
399 | else | |
400 | trace_smb3_rmdir_done(xid, ses->Suid, tcon->tid); | |
401 | free_set_inf_compound(rqst); | |
402 | break; | |
dcbf9103 | 403 | case SMB2_OP_SET_EOF: |
8191576a SF |
404 | if (rc) |
405 | trace_smb3_set_eof_err(xid, ses->Suid, tcon->tid, rc); | |
406 | else | |
407 | trace_smb3_set_eof_done(xid, ses->Suid, tcon->tid); | |
408 | free_set_inf_compound(rqst); | |
409 | break; | |
dcbf9103 | 410 | case SMB2_OP_SET_INFO: |
8191576a SF |
411 | if (rc) |
412 | trace_smb3_set_info_compound_err(xid, ses->Suid, | |
413 | tcon->tid, rc); | |
414 | else | |
415 | trace_smb3_set_info_compound_done(xid, ses->Suid, | |
416 | tcon->tid); | |
417 | free_set_inf_compound(rqst); | |
c2e0fe3f | 418 | break; |
c5a5f38f RS |
419 | } |
420 | free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base); | |
421 | free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base); | |
422 | free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base); | |
423 | return rc; | |
424 | } | |
425 | ||
f0df737e | 426 | void |
be4cb9e3 PS |
427 | move_smb2_info_to_cifs(FILE_ALL_INFO *dst, struct smb2_file_all_info *src) |
428 | { | |
429 | memcpy(dst, src, (size_t)(&src->CurrentByteOffset) - (size_t)src); | |
430 | dst->CurrentByteOffset = src->CurrentByteOffset; | |
431 | dst->Mode = src->Mode; | |
432 | dst->AlignmentRequirement = src->AlignmentRequirement; | |
433 | dst->IndexNumber1 = 0; /* we don't use it */ | |
434 | } | |
435 | ||
436 | int | |
437 | smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon, | |
438 | struct cifs_sb_info *cifs_sb, const char *full_path, | |
eb85d94b | 439 | FILE_ALL_INFO *data, bool *adjust_tz, bool *symlink) |
be4cb9e3 PS |
440 | { |
441 | int rc; | |
442 | struct smb2_file_all_info *smb2_data; | |
61351d6d | 443 | __u32 create_options = 0; |
6a9cbdd1 PS |
444 | struct cifs_fid fid; |
445 | bool no_cached_open = tcon->nohandlecache; | |
496902dc | 446 | struct cifsFileInfo *cfile; |
be4cb9e3 PS |
447 | |
448 | *adjust_tz = false; | |
eb85d94b | 449 | *symlink = false; |
be4cb9e3 | 450 | |
1bbe4997 | 451 | smb2_data = kzalloc(sizeof(struct smb2_file_all_info) + PATH_MAX * 2, |
be4cb9e3 PS |
452 | GFP_KERNEL); |
453 | if (smb2_data == NULL) | |
454 | return -ENOMEM; | |
6a9cbdd1 PS |
455 | |
456 | /* If it is a root and its handle is cached then use it */ | |
457 | if (!strlen(full_path) && !no_cached_open) { | |
458 | rc = open_shroot(xid, tcon, &fid); | |
459 | if (rc) | |
460 | goto out; | |
b0f6df73 RS |
461 | |
462 | if (tcon->crfid.file_all_info_is_valid) { | |
463 | move_smb2_info_to_cifs(data, | |
464 | &tcon->crfid.file_all_info); | |
465 | } else { | |
466 | rc = SMB2_query_info(xid, tcon, fid.persistent_fid, | |
467 | fid.volatile_fid, smb2_data); | |
468 | if (!rc) | |
469 | move_smb2_info_to_cifs(data, smb2_data); | |
470 | } | |
6a9cbdd1 | 471 | close_shroot(&tcon->crfid); |
6a9cbdd1 PS |
472 | goto out; |
473 | } | |
474 | ||
61351d6d SF |
475 | if (backup_cred(cifs_sb)) |
476 | create_options |= CREATE_OPEN_BACKUP_INTENT; | |
be4cb9e3 | 477 | |
496902dc | 478 | cifs_get_readable_path(tcon, full_path, &cfile); |
c5a5f38f | 479 | rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, |
61351d6d | 480 | FILE_READ_ATTRIBUTES, FILE_OPEN, create_options, |
496902dc | 481 | smb2_data, SMB2_OP_QUERY_INFO, cfile); |
eb85d94b PS |
482 | if (rc == -EOPNOTSUPP) { |
483 | *symlink = true; | |
61351d6d SF |
484 | create_options |= OPEN_REPARSE_POINT; |
485 | ||
eb85d94b | 486 | /* Failed on a symbolic link - query a reparse point info */ |
c5a5f38f RS |
487 | rc = smb2_compound_op(xid, tcon, cifs_sb, full_path, |
488 | FILE_READ_ATTRIBUTES, FILE_OPEN, | |
61351d6d | 489 | create_options, smb2_data, |
8de9e86c | 490 | SMB2_OP_QUERY_INFO, NULL); |
eb85d94b | 491 | } |
be4cb9e3 PS |
492 | if (rc) |
493 | goto out; | |
494 | ||
495 | move_smb2_info_to_cifs(data, smb2_data); | |
496 | out: | |
497 | kfree(smb2_data); | |
498 | return rc; | |
499 | } | |
a0e73183 PS |
500 | |
501 | int | |
502 | smb2_mkdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name, | |
503 | struct cifs_sb_info *cifs_sb) | |
504 | { | |
f733e393 RS |
505 | return smb2_compound_op(xid, tcon, cifs_sb, name, |
506 | FILE_WRITE_ATTRIBUTES, FILE_CREATE, | |
8de9e86c | 507 | CREATE_NOT_FILE, NULL, SMB2_OP_MKDIR, NULL); |
a0e73183 PS |
508 | } |
509 | ||
510 | void | |
511 | smb2_mkdir_setinfo(struct inode *inode, const char *name, | |
512 | struct cifs_sb_info *cifs_sb, struct cifs_tcon *tcon, | |
513 | const unsigned int xid) | |
514 | { | |
515 | FILE_BASIC_INFO data; | |
516 | struct cifsInodeInfo *cifs_i; | |
dc9300a6 | 517 | struct cifsFileInfo *cfile; |
a0e73183 PS |
518 | u32 dosattrs; |
519 | int tmprc; | |
520 | ||
521 | memset(&data, 0, sizeof(data)); | |
522 | cifs_i = CIFS_I(inode); | |
523 | dosattrs = cifs_i->cifsAttrs | ATTR_READONLY; | |
524 | data.Attributes = cpu_to_le32(dosattrs); | |
dc9300a6 | 525 | cifs_get_writable_path(tcon, name, &cfile); |
dcbf9103 RS |
526 | tmprc = smb2_compound_op(xid, tcon, cifs_sb, name, |
527 | FILE_WRITE_ATTRIBUTES, FILE_CREATE, | |
8de9e86c | 528 | CREATE_NOT_FILE, &data, SMB2_OP_SET_INFO, |
dc9300a6 | 529 | cfile); |
a0e73183 PS |
530 | if (tmprc == 0) |
531 | cifs_i->cifsAttrs = dosattrs; | |
532 | } | |
1a500f01 PS |
533 | |
534 | int | |
535 | smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name, | |
536 | struct cifs_sb_info *cifs_sb) | |
537 | { | |
c2e0fe3f RS |
538 | return smb2_compound_op(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN, |
539 | CREATE_NOT_FILE, | |
8de9e86c | 540 | NULL, SMB2_OP_RMDIR, NULL); |
1a500f01 | 541 | } |
cbe6f439 PS |
542 | |
543 | int | |
544 | smb2_unlink(const unsigned int xid, struct cifs_tcon *tcon, const char *name, | |
545 | struct cifs_sb_info *cifs_sb) | |
546 | { | |
47dd9597 RS |
547 | return smb2_compound_op(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN, |
548 | CREATE_DELETE_ON_CLOSE | OPEN_REPARSE_POINT, | |
8de9e86c | 549 | NULL, SMB2_OP_DELETE, NULL); |
cbe6f439 | 550 | } |
35143eb5 | 551 | |
568798cc PS |
552 | static int |
553 | smb2_set_path_attr(const unsigned int xid, struct cifs_tcon *tcon, | |
554 | const char *from_name, const char *to_name, | |
8de9e86c RS |
555 | struct cifs_sb_info *cifs_sb, __u32 access, int command, |
556 | struct cifsFileInfo *cfile) | |
35143eb5 PS |
557 | { |
558 | __le16 *smb2_to_name = NULL; | |
559 | int rc; | |
560 | ||
561 | smb2_to_name = cifs_convert_path_to_utf16(to_name, cifs_sb); | |
562 | if (smb2_to_name == NULL) { | |
563 | rc = -ENOMEM; | |
564 | goto smb2_rename_path; | |
565 | } | |
bb435512 | 566 | rc = smb2_compound_op(xid, tcon, cifs_sb, from_name, access, |
8de9e86c | 567 | FILE_OPEN, 0, smb2_to_name, command, cfile); |
35143eb5 PS |
568 | smb2_rename_path: |
569 | kfree(smb2_to_name); | |
570 | return rc; | |
571 | } | |
568798cc PS |
572 | |
573 | int | |
574 | smb2_rename_path(const unsigned int xid, struct cifs_tcon *tcon, | |
575 | const char *from_name, const char *to_name, | |
576 | struct cifs_sb_info *cifs_sb) | |
577 | { | |
8de9e86c RS |
578 | struct cifsFileInfo *cfile; |
579 | ||
580 | cifs_get_writable_path(tcon, from_name, &cfile); | |
581 | ||
582 | return smb2_set_path_attr(xid, tcon, from_name, to_name, | |
583 | cifs_sb, DELETE, SMB2_OP_RENAME, cfile); | |
568798cc PS |
584 | } |
585 | ||
586 | int | |
587 | smb2_create_hardlink(const unsigned int xid, struct cifs_tcon *tcon, | |
588 | const char *from_name, const char *to_name, | |
589 | struct cifs_sb_info *cifs_sb) | |
590 | { | |
591 | return smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb, | |
8de9e86c RS |
592 | FILE_READ_ATTRIBUTES, SMB2_OP_HARDLINK, |
593 | NULL); | |
568798cc | 594 | } |
c839ff24 PS |
595 | |
596 | int | |
597 | smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon, | |
598 | const char *full_path, __u64 size, | |
599 | struct cifs_sb_info *cifs_sb, bool set_alloc) | |
600 | { | |
601 | __le64 eof = cpu_to_le64(size); | |
f7bfe04b RS |
602 | |
603 | return smb2_compound_op(xid, tcon, cifs_sb, full_path, | |
604 | FILE_WRITE_DATA, FILE_OPEN, 0, &eof, | |
8de9e86c | 605 | SMB2_OP_SET_EOF, NULL); |
c839ff24 | 606 | } |
1feeaac7 PS |
607 | |
608 | int | |
609 | smb2_set_file_info(struct inode *inode, const char *full_path, | |
610 | FILE_BASIC_INFO *buf, const unsigned int xid) | |
611 | { | |
612 | struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb); | |
613 | struct tcon_link *tlink; | |
614 | int rc; | |
615 | ||
18dd8e1a | 616 | if ((buf->CreationTime == 0) && (buf->LastAccessTime == 0) && |
fd09b7d3 | 617 | (buf->LastWriteTime == 0) && (buf->ChangeTime == 0) && |
18dd8e1a SF |
618 | (buf->Attributes == 0)) |
619 | return 0; /* would be a no op, no sense sending this */ | |
620 | ||
1feeaac7 PS |
621 | tlink = cifs_sb_tlink(cifs_sb); |
622 | if (IS_ERR(tlink)) | |
623 | return PTR_ERR(tlink); | |
18dd8e1a | 624 | |
dcbf9103 RS |
625 | rc = smb2_compound_op(xid, tlink_tcon(tlink), cifs_sb, full_path, |
626 | FILE_WRITE_ATTRIBUTES, FILE_OPEN, 0, buf, | |
8de9e86c | 627 | SMB2_OP_SET_INFO, NULL); |
1feeaac7 PS |
628 | cifs_put_tlink(tlink); |
629 | return rc; | |
630 | } |