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