CIFS: Add SMB2 support for set_file_size
authorPavel Shilovsky <pshilovsky@samba.org>
Tue, 18 Sep 2012 23:20:32 +0000 (16:20 -0700)
committerSteve French <smfrench@gmail.com>
Tue, 25 Sep 2012 02:46:29 +0000 (21:46 -0500)
Signed-off-by: Pavel Shilovsky <pshilovsky@samba.org>
Signed-off-by: Steve French <smfrench@gmail.com>
fs/cifs/smb2glob.h
fs/cifs/smb2inode.c
fs/cifs/smb2ops.c
fs/cifs/smb2pdu.c
fs/cifs/smb2pdu.h
fs/cifs/smb2proto.h

index 21555d8744fd02e6db5fd272af13cd369ebba40a..05d429b1c37eed340b5975c3eea3de99cedd99a6 100644 (file)
@@ -41,6 +41,7 @@
 #define SMB2_OP_RENAME 6
 #define SMB2_OP_DELETE 7
 #define SMB2_OP_HARDLINK 8
+#define SMB2_OP_SET_EOF 9
 
 /* Used when constructing chained read requests. */
 #define CHAINED_REQUEST 1
index 1921c9c87ccdd9438d910906043397b59b1261bd..2905830922936c41ab86b16c0f3827b2bfcd9402 100644 (file)
@@ -82,6 +82,10 @@ smb2_open_op_close(const unsigned int xid, struct cifs_tcon *tcon,
                tmprc = SMB2_set_hardlink(xid, tcon, persistent_fid,
                                          volatile_fid, (__le16 *)data);
                break;
+       case SMB2_OP_SET_EOF:
+               tmprc = SMB2_set_eof(xid, tcon, persistent_fid, volatile_fid,
+                                    current->tgid, (__le64 *)data);
+               break;
        default:
                cERROR(1, "Invalid command");
                break;
@@ -217,3 +221,14 @@ smb2_create_hardlink(const unsigned int xid, struct cifs_tcon *tcon,
        return smb2_set_path_attr(xid, tcon, from_name, to_name, cifs_sb,
                                  FILE_READ_ATTRIBUTES, SMB2_OP_HARDLINK);
 }
+
+int
+smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon,
+                  const char *full_path, __u64 size,
+                  struct cifs_sb_info *cifs_sb, bool set_alloc)
+{
+       __le64 eof = cpu_to_le64(size);
+       return smb2_open_op_close(xid, tcon, cifs_sb, full_path,
+                                 FILE_WRITE_DATA, FILE_OPEN, 0, 0, &eof,
+                                 SMB2_OP_SET_EOF);
+}
index 75693e983e76cb2bca6fb5184f04e8629b0a90a8..e0daf3a4dcc2406ed9c9c17e301133de4222b361 100644 (file)
@@ -415,6 +415,15 @@ smb2_sync_write(const unsigned int xid, struct cifsFileInfo *cfile,
        return SMB2_write(xid, parms, written, iov, nr_segs);
 }
 
+static int
+smb2_set_file_size(const unsigned int xid, struct cifs_tcon *tcon,
+                  struct cifsFileInfo *cfile, __u64 size, bool set_alloc)
+{
+       __le64 eof = cpu_to_le64(size);
+       return SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
+                           cfile->fid.volatile_fid, cfile->pid, &eof);
+}
+
 struct smb_version_operations smb21_operations = {
        .setup_request = smb2_setup_request,
        .setup_async_request = smb2_setup_async_request,
@@ -446,6 +455,8 @@ struct smb_version_operations smb21_operations = {
        .query_path_info = smb2_query_path_info,
        .get_srv_inum = smb2_get_srv_inum,
        .query_file_info = smb2_query_file_info,
+       .set_path_size = smb2_set_path_size,
+       .set_file_size = smb2_set_file_size,
        .build_path_to_root = smb2_build_path_to_root,
        .mkdir = smb2_mkdir,
        .mkdir_setinfo = smb2_mkdir_setinfo,
index a684c4ab42d619d9248633025060192f9b29a925..74a8381400b15516ed43f693c15f9700c3a7a656 100644 (file)
@@ -1605,7 +1605,7 @@ SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,
 
 static int
 send_set_info(const unsigned int xid, struct cifs_tcon *tcon,
-              u64 persistent_fid, u64 volatile_fid, int info_class,
+              u64 persistent_fid, u64 volatile_fid, u32 pid, int info_class,
               unsigned int num, void **data, unsigned int *size)
 {
        struct smb2_set_info_req *req;
@@ -1635,6 +1635,8 @@ send_set_info(const unsigned int xid, struct cifs_tcon *tcon,
                return rc;
        }
 
+       req->hdr.ProcessId = cpu_to_le32(pid);
+
        req->InfoType = SMB2_O_INFO_FILE;
        req->FileInfoClass = info_class;
        req->PersistentFileId = persistent_fid;
@@ -1705,7 +1707,8 @@ SMB2_rename(const unsigned int xid, struct cifs_tcon *tcon,
        size[1] = len + 2 /* null */;
 
        rc = send_set_info(xid, tcon, persistent_fid, volatile_fid,
-                          FILE_RENAME_INFORMATION, 2, data, size);
+                          current->tgid, FILE_RENAME_INFORMATION, 2, data,
+                          size);
        kfree(data);
        return rc;
 }
@@ -1736,7 +1739,24 @@ SMB2_set_hardlink(const unsigned int xid, struct cifs_tcon *tcon,
        size[1] = len + 2 /* null */;
 
        rc = send_set_info(xid, tcon, persistent_fid, volatile_fid,
-                          FILE_LINK_INFORMATION, 2, data, size);
+                          current->tgid, FILE_LINK_INFORMATION, 2, data, size);
        kfree(data);
        return rc;
 }
+
+int
+SMB2_set_eof(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
+            u64 volatile_fid, u32 pid, __le64 *eof)
+{
+       struct smb2_file_eof_info info;
+       void *data;
+       unsigned int size;
+
+       info.EndOfFile = *eof;
+
+       data = &info;
+       size = sizeof(struct smb2_file_eof_info);
+
+       return send_set_info(xid, tcon, persistent_fid, volatile_fid, pid,
+                            FILE_END_OF_FILE_INFORMATION, 1, &data, &size);
+}
index 0f3c4828cd00111b2e052d57138b806eaba5c035..d775941f552abd9f98fa576bd24f5fcdad5808a6 100644 (file)
@@ -690,4 +690,8 @@ struct smb2_file_all_info { /* data block encoding of response to level 18 */
        char   FileName[1];
 } __packed; /* level 18 Query */
 
+struct smb2_file_eof_info { /* encoding of request for level 10 */
+       __le64 EndOfFile; /* new end of file value */
+} __packed; /* level 20 Set */
+
 #endif                         /* _SMB2PDU_H */
index 99f6945c86437e506601ce01f756661f53f0409c..3d48662795306a0d489bcdeb75169c6d679dae1a 100644 (file)
@@ -56,6 +56,9 @@ extern int smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
                                struct cifs_sb_info *cifs_sb,
                                const char *full_path, FILE_ALL_INFO *data,
                                bool *adjust_tz);
+extern int smb2_set_path_size(const unsigned int xid, struct cifs_tcon *tcon,
+                             const char *full_path, __u64 size,
+                             struct cifs_sb_info *cifs_sb, bool set_alloc);
 extern int smb2_mkdir(const unsigned int xid, struct cifs_tcon *tcon,
                      const char *name, struct cifs_sb_info *cifs_sb);
 extern void smb2_mkdir_setinfo(struct inode *inode, const char *full_path,
@@ -118,5 +121,8 @@ extern int SMB2_rename(const unsigned int xid, struct cifs_tcon *tcon,
 extern int SMB2_set_hardlink(const unsigned int xid, struct cifs_tcon *tcon,
                             u64 persistent_fid, u64 volatile_fid,
                             __le16 *target_file);
+extern int SMB2_set_eof(const unsigned int xid, struct cifs_tcon *tcon,
+                       u64 persistent_fid, u64 volatile_fid, u32 pid,
+                       __le64 *eof);
 
 #endif                 /* _SMB2PROTO_H */
This page took 0.084108 seconds and 5 git commands to generate.