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