The branch, master has been updated
       via  74ff89a torture/ioctl: add simple FSCTL_FILE_LEVEL_TRIM test
       via  5776904 idl: FSCTL_FILE_LEVEL_TRIM request & response structs
       via  97a2d83 torture: test FS_SECTOR_SIZE_INFORMATION queries
       via  d1e664f s4/ntvfs: support FS_SECTOR_SIZE_INFORMATION query-info
       via  664dca2 s4/client: add FS_SECTOR_SIZE_INFORMATION query support
       via  ba9fd54 s3/smbd: support FS_SECTOR_SIZE_INFORMATION query-info
       via  8fb488c smbd/trans2: function scope qfsinfo bytes_per_sector
      from  8421c40 s4:kdc: fix realm for outgoing trusts in 
samba_kdc_trust_message2entry()

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 74ff89a7e32ad46275fb9fe54d3e23c69d925ca7
Author: David Disseldorp <[email protected]>
Date:   Thu Mar 12 11:01:17 2015 +0100

    torture/ioctl: add simple FSCTL_FILE_LEVEL_TRIM test
    
    This test writes out a 128K file and then attempts to trim the first
    half of the file. Trim support is first detected using an
    FS_SECTOR_SIZE_INFORMATION query-info request. If the server doesn't
    support trim, then the test is skipped.
    
    Signed-off-by: David Disseldorp <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>
    
    Autobuild-User(master): Jeremy Allison <[email protected]>
    Autobuild-Date(master): Wed Mar 18 21:32:47 CET 2015 on sn-devel-104

commit 5776904defab1148027232bcc826c811e1a889f9
Author: David Disseldorp <[email protected]>
Date:   Wed Mar 11 14:50:16 2015 +0100

    idl: FSCTL_FILE_LEVEL_TRIM request & response structs
    
    As defined in MS-FSCC 2.3.73 - 2.3.74.
    
    Signed-off-by: David Disseldorp <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>

commit 97a2d83662550d2b754c2b0f0e4775054aa16bcd
Author: David Disseldorp <[email protected]>
Date:   Fri Mar 13 01:06:26 2015 +0100

    torture: test FS_SECTOR_SIZE_INFORMATION queries
    
    The smb2.fsinfo test is run against ntvfs and s3fs. With both now
    offering support for the FS_SECTOR_SIZE_INFORMATION query-info level,
    it can be added to the existing level enumeration.
    
    Signed-off-by: David Disseldorp <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>

commit d1e664f154553e4e2a7a64ff18fcbe979359ab73
Author: David Disseldorp <[email protected]>
Date:   Fri Mar 13 01:00:51 2015 +0100

    s4/ntvfs: support FS_SECTOR_SIZE_INFORMATION query-info
    
    Return the same values as used by s3fs.
    
    Signed-off-by: David Disseldorp <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>

commit 664dca2b44c96a6ef1fd5fb920adbf274a3a6c01
Author: David Disseldorp <[email protected]>
Date:   Fri Mar 13 00:46:21 2015 +0100

    s4/client: add FS_SECTOR_SIZE_INFORMATION query support
    
    Signed-off-by: David Disseldorp <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>

commit ba9fd54bdf32009f725006660bb81965885501b9
Author: David Disseldorp <[email protected]>
Date:   Fri Mar 13 00:34:58 2015 +0100

    s3/smbd: support FS_SECTOR_SIZE_INFORMATION query-info
    
    The FS_SECTOR_SIZE_INFORMATION query-info level reports sector alignment
    information for an underlying share volume, as well as NO_SEEK_PENALTY
    and TRIM_ENABLED flags useful for SSD / thin-provisioned storage
    detection.
    
    Signed-off-by: David Disseldorp <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>

commit 8fb488cbcd25ab8d8552fc13e450cc54974303bc
Author: David Disseldorp <[email protected]>
Date:   Thu Mar 12 17:02:56 2015 +0100

    smbd/trans2: function scope qfsinfo bytes_per_sector
    
    It's needed for multiple info levels.
    
    Signed-off-by: David Disseldorp <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>

-----------------------------------------------------------------------

Summary of changes:
 librpc/idl/ioctl.idl              |  21 ++++++
 source3/include/trans2.h          |   9 +++
 source3/smbd/trans2.c             |  38 +++++++++--
 source4/client/client.c           |  17 +++++
 source4/libcli/raw/interfaces.h   |  20 +++++-
 source4/libcli/raw/rawfsinfo.c    |  21 ++++++
 source4/libcli/raw/trans2.h       |   8 +++
 source4/ntvfs/ntvfs_generic.c     |  16 +++++
 source4/ntvfs/posix/pvfs_fsinfo.c |  15 ++++
 source4/smb_server/blob.c         |  20 ++++++
 source4/torture/smb2/getinfo.c    |   3 +-
 source4/torture/smb2/ioctl.c      | 140 ++++++++++++++++++++++++++++++++++++++
 12 files changed, 320 insertions(+), 8 deletions(-)


Changeset truncated at 500 lines:

diff --git a/librpc/idl/ioctl.idl b/librpc/idl/ioctl.idl
index 5efb9d8..5c3ee6d 100644
--- a/librpc/idl/ioctl.idl
+++ b/librpc/idl/ioctl.idl
@@ -200,3 +200,24 @@ interface resiliency
                uint32 reserved;
        } network_resiliency_request;
 }
+
+interface trim
+{
+       /* MS-FSCC 2.3.73.1 FILE_LEVEL_TRIM_RANGE */
+       typedef [public] struct {
+               hyper off;
+               hyper len;
+       } file_level_trim_range;
+
+       /* MS-FSCC 2.3.73 FSCTL_FILE_LEVEL_TRIM Request */
+       typedef [public] struct {
+               uint32 key;
+               uint32 num_ranges;
+               file_level_trim_range ranges[num_ranges];
+       } fsctl_file_level_trim_req;
+
+       /* MS-FSCC 2.3.74 FSCTL_FILE_LEVEL_TRIM Reply */
+       typedef [public] struct {
+               uint32 num_ranges_processed;
+       } fsctl_file_level_trim_rsp;
+}
diff --git a/source3/include/trans2.h b/source3/include/trans2.h
index 7a8c411..3085344 100644
--- a/source3/include/trans2.h
+++ b/source3/include/trans2.h
@@ -282,6 +282,14 @@ Byte offset   Type     name                description
 #define TYPE_MOUNTED                   0x20
 #define TYPE_VIRTUAL                   0x40
 
+/* SMB_FS_SECTOR_SIZE_INFORMATION values */
+#define SSINFO_FLAGS_ALIGNED_DEVICE                    0x00000001
+#define SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE       0x00000002
+#define SSINFO_FLAGS_NO_SEEK_PENALTY                   0x00000004
+#define SSINFO_FLAGS_TRIM_ENABLED                      0x00000008
+
+#define SSINFO_OFFSET_UNKNOWN                          0xffffffff
+
 /* NT passthrough levels... */
 
 #define SMB_FILE_DIRECTORY_INFORMATION                 1001
@@ -333,6 +341,7 @@ Byte offset   Type     name                description
 #define SMB_FS_QUOTA_INFORMATION                       1006
 #define SMB_FS_FULL_SIZE_INFORMATION                   1007
 #define SMB_FS_OBJECTID_INFORMATION                    1008
+#define SMB_FS_SECTOR_SIZE_INFORMATION                 1011
 
 /* SMB_FS_DEVICE_INFORMATION device types. */
 #define FILE_DEVICE_CD_ROM             0x2
diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c
index a732bac..551643f 100644
--- a/source3/smbd/trans2.c
+++ b/source3/smbd/trans2.c
@@ -3208,6 +3208,7 @@ NTSTATUS smbd_do_qfsinfo(struct smbXsrv_connection *xconn,
        int snum = SNUM(conn);
        const char *fstype = lp_fstype(SNUM(conn));
        const char *filename = NULL;
+       const uint64_t bytes_per_sector = 512;
        uint32 additional_flags = 0;
        struct smb_filename smb_fname;
        SMB_STRUCT_STAT st;
@@ -3260,7 +3261,7 @@ NTSTATUS smbd_do_qfsinfo(struct smbXsrv_connection *xconn,
        switch (info_level) {
                case SMB_INFO_ALLOCATION:
                {
-                       uint64_t 
dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
+                       uint64_t dfree,dsize,bsize,block_size,sectors_per_unit;
                        data_len = 18;
                        df_ret = get_dfree_info(conn, filename, &bsize, &dfree,
                                                &dsize);
@@ -3281,7 +3282,6 @@ NTSTATUS smbd_do_qfsinfo(struct smbXsrv_connection *xconn,
                                dsize *= factor;
                                dfree *= factor;
                        }
-                       bytes_per_sector = 512;
                        sectors_per_unit = bsize/bytes_per_sector;
 
                        DEBUG(5,("smbd_do_qfsinfo : SMB_INFO_ALLOCATION id=%x, 
bsize=%u, cSectorUnit=%u, \
@@ -3412,7 +3412,7 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", 
(unsigned int)st.st_ex_dev, (u
                case SMB_QUERY_FS_SIZE_INFO:
                case SMB_FS_SIZE_INFORMATION:
                {
-                       uint64_t 
dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
+                       uint64_t dfree,dsize,bsize,block_size,sectors_per_unit;
                        data_len = 24;
                        df_ret = get_dfree_info(conn, filename, &bsize, &dfree,
                                                &dsize);
@@ -3432,7 +3432,6 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", 
(unsigned int)st.st_ex_dev, (u
                                dsize *= factor;
                                dfree *= factor;
                        }
-                       bytes_per_sector = 512;
                        sectors_per_unit = bsize/bytes_per_sector;
                        DEBUG(5,("smbd_do_qfsinfo : SMB_QUERY_FS_SIZE_INFO 
bsize=%u, cSectorUnit=%u, \
 cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, 
(unsigned int)sectors_per_unit,
@@ -3447,7 +3446,7 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", 
(unsigned int)bsize, (unsigned
 
                case SMB_FS_FULL_SIZE_INFORMATION:
                {
-                       uint64_t 
dfree,dsize,bsize,block_size,sectors_per_unit,bytes_per_sector;
+                       uint64_t dfree,dsize,bsize,block_size,sectors_per_unit;
                        data_len = 32;
                        df_ret = get_dfree_info(conn, filename, &bsize, &dfree,
                                                &dsize);
@@ -3467,7 +3466,6 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", 
(unsigned int)bsize, (unsigned
                                dsize *= factor;
                                dfree *= factor;
                        }
-                       bytes_per_sector = 512;
                        sectors_per_unit = bsize/bytes_per_sector;
                        DEBUG(5,("smbd_do_qfsinfo : SMB_QUERY_FS_FULL_SIZE_INFO 
bsize=%u, cSectorUnit=%u, \
 cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", (unsigned int)bsize, 
(unsigned int)sectors_per_unit,
@@ -3585,6 +3583,34 @@ cBytesSector=%u, cUnitTotal=%u, cUnitAvail=%d\n", 
(unsigned int)bsize, (unsigned
                        break;
                }
 
+               case SMB_FS_SECTOR_SIZE_INFORMATION:
+               {
+                       data_len = 28;
+                       /*
+                        * These values match a physical Windows Server 2012
+                        * share backed by NTFS atop spinning rust.
+                        */
+                       DEBUG(5, ("SMB_FS_SECTOR_SIZE_INFORMATION:"));
+                       /* logical_bytes_per_sector */
+                       SIVAL(pdata, 0, bytes_per_sector);
+                       /* phys_bytes_per_sector_atomic */
+                       SIVAL(pdata, 4, bytes_per_sector);
+                       /* phys_bytes_per_sector_perf */
+                       SIVAL(pdata, 8, bytes_per_sector);
+                       /* fs_effective_phys_bytes_per_sector_atomic */
+                       SIVAL(pdata, 12, bytes_per_sector);
+                       /* flags */
+                       SIVAL(pdata, 16, SSINFO_FLAGS_ALIGNED_DEVICE
+                               | SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE);
+                       /* byte_off_sector_align */
+                       SIVAL(pdata, 20, 0);
+                       /* byte_off_partition_align */
+                       SIVAL(pdata, 24, 0);
+                       *fixed_portion = 28;
+                       break;
+               }
+
+
                /*
                 * Query the version and capabilities of the CIFS UNIX 
extensions
                 * in use.
diff --git a/source4/client/client.c b/source4/client/client.c
index 2779824..a069443 100644
--- a/source4/client/client.c
+++ b/source4/client/client.c
@@ -1620,6 +1620,7 @@ fsinfo_level_t fsinfo_levels[] = {
        {"quota-information", RAW_QFS_QUOTA_INFORMATION},
        {"fullsize-information", RAW_QFS_FULL_SIZE_INFORMATION},
        {"objectid", RAW_QFS_OBJECTID_INFORMATION},
+       {"sector-size-info", RAW_QFS_SECTOR_SIZE_INFORMATION},
        {NULL, RAW_QFS_GENERIC}
 };
 
@@ -1763,6 +1764,22 @@ static int cmd_fsinfo(struct smbclient_context *ctx, 
const char **args)
                         (unsigned long long) 
fsinfo.objectid_information.out.unknown[4],
                         (unsigned long long) 
fsinfo.objectid_information.out.unknown[5] );
                break;
+       case RAW_QFS_SECTOR_SIZE_INFORMATION:
+               d_printf("\tlogical_bytes_per_sector:                   %u\n",
+                        
(unsigned)fsinfo.sector_size_info.out.logical_bytes_per_sector);
+               d_printf("\tphys_bytes_per_sector_atomic:               %u\n",
+                        
(unsigned)fsinfo.sector_size_info.out.phys_bytes_per_sector_atomic);
+               d_printf("\tphys_bytes_per_sector_perf:                 %u\n",
+                        
(unsigned)fsinfo.sector_size_info.out.phys_bytes_per_sector_perf);
+               d_printf("\tfs_effective_phys_bytes_per_sector_atomic:  %u\n",
+                        
(unsigned)fsinfo.sector_size_info.out.fs_effective_phys_bytes_per_sector_atomic);
+               d_printf("\tflags:                                      0x%x\n",
+                        (unsigned)fsinfo.sector_size_info.out.flags);
+               d_printf("\tbyte_off_sector_align:                      %u\n",
+                        
(unsigned)fsinfo.sector_size_info.out.byte_off_sector_align);
+               d_printf("\tbyte_off_partition_align:                   %u\n",
+                        
(unsigned)fsinfo.sector_size_info.out.byte_off_partition_align);
+               break;
        case RAW_QFS_GENERIC:
                d_printf("\twrong level returned\n");
                break;
diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h
index 5804a6b..7e8258e 100644
--- a/source4/libcli/raw/interfaces.h
+++ b/source4/libcli/raw/interfaces.h
@@ -1167,7 +1167,9 @@ enum smb_fsinfo_level {
                   RAW_QFS_ATTRIBUTE_INFORMATION          = 
SMB_QFS_ATTRIBUTE_INFORMATION,
                   RAW_QFS_QUOTA_INFORMATION              = 
SMB_QFS_QUOTA_INFORMATION,
                   RAW_QFS_FULL_SIZE_INFORMATION          = 
SMB_QFS_FULL_SIZE_INFORMATION,
-                  RAW_QFS_OBJECTID_INFORMATION           = 
SMB_QFS_OBJECTID_INFORMATION};
+                  RAW_QFS_OBJECTID_INFORMATION           = 
SMB_QFS_OBJECTID_INFORMATION,
+                  RAW_QFS_SECTOR_SIZE_INFORMATION        = 
SMB_QFS_SECTOR_SIZE_INFORMATION,
+};
 
 
 /* union for fsinfo() backend call. Note that there are no in
@@ -1331,6 +1333,22 @@ union smb_fsinfo {
                        uint64_t unknown[6];
                } out;
        } objectid_information; 
+
+       /* trans2 RAW_QFS_SECTOR_SIZE_INFORMATION interface */
+       struct {
+               enum smb_fsinfo_level level;
+               struct smb2_handle handle; /* only for smb2 */
+
+               struct {
+                       uint32_t logical_bytes_per_sector;
+                       uint32_t phys_bytes_per_sector_atomic;
+                       uint32_t phys_bytes_per_sector_perf;
+                       uint32_t fs_effective_phys_bytes_per_sector_atomic;
+                       uint32_t flags;
+                       uint32_t byte_off_sector_align;
+                       uint32_t byte_off_partition_align;
+               } out;
+       } sector_size_info;
 };
 
 
diff --git a/source4/libcli/raw/rawfsinfo.c b/source4/libcli/raw/rawfsinfo.c
index 9c03e14..bf149ee 100644
--- a/source4/libcli/raw/rawfsinfo.c
+++ b/source4/libcli/raw/rawfsinfo.c
@@ -226,6 +226,23 @@ NTSTATUS smb_raw_fsinfo_passthru_parse(DATA_BLOB blob, 
TALLOC_CTX *mem_ctx,
                        fsinfo->objectid_information.out.unknown[i] = 
BVAL(blob.data, 16 + i*8);
                }
                break;
+
+       case RAW_QFS_SECTOR_SIZE_INFORMATION:
+               QFS_CHECK_SIZE(28);
+               fsinfo->sector_size_info.out.logical_bytes_per_sector
+                                                       = IVAL(blob.data,  0);
+               fsinfo->sector_size_info.out.phys_bytes_per_sector_atomic
+                                                       = IVAL(blob.data,  4);
+               fsinfo->sector_size_info.out.phys_bytes_per_sector_perf
+                                                       = IVAL(blob.data,  8);
+               
fsinfo->sector_size_info.out.fs_effective_phys_bytes_per_sector_atomic
+                                                       = IVAL(blob.data, 12);
+               fsinfo->sector_size_info.out.flags      = IVAL(blob.data, 16);
+               fsinfo->sector_size_info.out.byte_off_sector_align
+                                                       = IVAL(blob.data, 20);
+               fsinfo->sector_size_info.out.byte_off_partition_align
+                                                       = IVAL(blob.data, 24);
+               break;
        }
                
        default:
@@ -319,6 +336,10 @@ NTSTATUS smb_raw_fsinfo_recv(struct smbcli_request *req,
        case RAW_QFS_OBJECTID_INFORMATION:
                return smb_raw_fsinfo_passthru_parse(blob, mem_ctx, 
                                                     
RAW_QFS_OBJECTID_INFORMATION, fsinfo);
+
+       case RAW_QFS_SECTOR_SIZE_INFORMATION:
+               return smb_raw_fsinfo_passthru_parse(blob, mem_ctx,
+                               RAW_QFS_SECTOR_SIZE_INFORMATION, fsinfo);
        }
 
 failed:
diff --git a/source4/libcli/raw/trans2.h b/source4/libcli/raw/trans2.h
index c1ec3ae..b7cfc6d 100644
--- a/source4/libcli/raw/trans2.h
+++ b/source4/libcli/raw/trans2.h
@@ -63,6 +63,7 @@ Found 4 aliased levels
 #define SMB_QFS_QUOTA_INFORMATION                      1006
 #define SMB_QFS_FULL_SIZE_INFORMATION                  1007
 #define SMB_QFS_OBJECTID_INFORMATION                   1008
+#define SMB_QFS_SECTOR_SIZE_INFORMATION                        1011
 
 
 /* trans2 qfileinfo/qpathinfo */
@@ -283,6 +284,13 @@ Found 0 aliased levels
 #define QFS_TYPE_MOUNTED                       0x20
 #define QFS_TYPE_VIRTUAL                       0x40
 
+/* SMB_QFS_SECTOR_SIZE_INFORMATION values */
+#define QFS_SSINFO_FLAGS_ALIGNED_DEVICE                        0x00000001
+#define QFS_SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE   0x00000002
+#define QFS_SSINFO_FLAGS_NO_SEEK_PENALTY               0x00000004
+#define QFS_SSINFO_FLAGS_TRIM_ENABLED                  0x00000008
+
+#define QFS_SSINFO_OFFSET_UNKNOWN                      0xffffffff
 
 /*
  * Thursby MAC extensions....
diff --git a/source4/ntvfs/ntvfs_generic.c b/source4/ntvfs/ntvfs_generic.c
index d3f7919..4edc31c 100644
--- a/source4/ntvfs/ntvfs_generic.c
+++ b/source4/ntvfs/ntvfs_generic.c
@@ -664,6 +664,22 @@ static NTSTATUS ntvfs_map_fsinfo_finish(struct 
ntvfs_module_context *ntvfs,
                ZERO_STRUCT(fs->objectid_information.out.unknown);
                return NT_STATUS_OK;
 
+       case RAW_QFS_SECTOR_SIZE_INFORMATION:
+               fs->sector_size_info.out.logical_bytes_per_sector
+                                               = fs2->generic.out.block_size;
+               fs->sector_size_info.out.phys_bytes_per_sector_atomic
+                                               = fs2->generic.out.block_size;
+               fs->sector_size_info.out.phys_bytes_per_sector_perf
+                                               = fs2->generic.out.block_size;
+               
fs->sector_size_info.out.fs_effective_phys_bytes_per_sector_atomic
+                                               = fs2->generic.out.block_size;
+               fs->sector_size_info.out.flags
+                                       = QFS_SSINFO_FLAGS_ALIGNED_DEVICE
+                               | QFS_SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE;
+               fs->sector_size_info.out.byte_off_sector_align = 0;
+               fs->sector_size_info.out.byte_off_partition_align = 0;
+               return NT_STATUS_OK;
+
        case RAW_QFS_GENERIC:
        case RAW_QFS_UNIX_INFO:
                return NT_STATUS_INVALID_LEVEL;
diff --git a/source4/ntvfs/posix/pvfs_fsinfo.c 
b/source4/ntvfs/posix/pvfs_fsinfo.c
index 210433b..35256fe 100644
--- a/source4/ntvfs/posix/pvfs_fsinfo.c
+++ b/source4/ntvfs/posix/pvfs_fsinfo.c
@@ -201,6 +201,21 @@ NTSTATUS pvfs_fsinfo(struct ntvfs_module_context *ntvfs,
                fs->objectid_information.out.guid = *pvfs->base_fs_uuid;
                return NT_STATUS_OK;
 
+       case RAW_QFS_SECTOR_SIZE_INFORMATION:
+               fs->sector_size_info.out.logical_bytes_per_sector = block_size;
+               fs->sector_size_info.out.phys_bytes_per_sector_atomic
+                                                               = block_size;
+               fs->sector_size_info.out.phys_bytes_per_sector_perf
+                                                               = block_size;
+               
fs->sector_size_info.out.fs_effective_phys_bytes_per_sector_atomic
+                                                               = block_size;
+               fs->sector_size_info.out.flags
+                                       = QFS_SSINFO_FLAGS_ALIGNED_DEVICE
+                               | QFS_SSINFO_FLAGS_PARTITION_ALIGNED_ON_DEVICE;
+               fs->sector_size_info.out.byte_off_sector_align = 0;
+               fs->sector_size_info.out.byte_off_partition_align = 0;
+               return NT_STATUS_OK;
+
        default:
                break;
        }
diff --git a/source4/smb_server/blob.c b/source4/smb_server/blob.c
index a3e1123..2489329 100644
--- a/source4/smb_server/blob.c
+++ b/source4/smb_server/blob.c
@@ -292,6 +292,26 @@ NTSTATUS smbsrv_push_passthru_fsinfo(TALLOC_CTX *mem_ctx,
 
                return NT_STATUS_OK;
        }
+
+       case RAW_QFS_SECTOR_SIZE_INFORMATION:
+               BLOB_CHECK(smbsrv_blob_grow_data(mem_ctx, blob, 28));
+               SIVAL(blob->data,  0,
+                     fsinfo->sector_size_info.out.logical_bytes_per_sector);
+               SIVAL(blob->data,  4,
+                    fsinfo->sector_size_info.out.phys_bytes_per_sector_atomic);
+               SIVAL(blob->data,  8,
+                     fsinfo->sector_size_info.out.phys_bytes_per_sector_perf);
+               SIVAL(blob->data, 12,
+                     
fsinfo->sector_size_info.out.fs_effective_phys_bytes_per_sector_atomic);
+               SIVAL(blob->data, 16,
+                     fsinfo->sector_size_info.out.flags);
+               SIVAL(blob->data, 20,
+                     fsinfo->sector_size_info.out.byte_off_sector_align);
+               SIVAL(blob->data, 24,
+                     fsinfo->sector_size_info.out.byte_off_partition_align);
+
+               return NT_STATUS_OK;
+
        default:
                return NT_STATUS_INVALID_LEVEL;
        }
diff --git a/source4/torture/smb2/getinfo.c b/source4/torture/smb2/getinfo.c
index 427fdd9..4bf4100 100644
--- a/source4/torture/smb2/getinfo.c
+++ b/source4/torture/smb2/getinfo.c
@@ -70,7 +70,8 @@ static struct {
  { LEVEL(RAW_QFS_ATTRIBUTE_INFORMATION) },
  { LEVEL(RAW_QFS_QUOTA_INFORMATION) },
  { LEVEL(RAW_QFS_FULL_SIZE_INFORMATION) },
- { LEVEL(RAW_QFS_OBJECTID_INFORMATION) }
+ { LEVEL(RAW_QFS_OBJECTID_INFORMATION) },
+ { LEVEL(RAW_QFS_SECTOR_SIZE_INFORMATION) },
 };
 
 #define FNAME "testsmb2_file.dat"
diff --git a/source4/torture/smb2/ioctl.c b/source4/torture/smb2/ioctl.c
index 78bbdd9..8e7f69a 100644
--- a/source4/torture/smb2/ioctl.c
+++ b/source4/torture/smb2/ioctl.c
@@ -4645,6 +4645,144 @@ static bool test_ioctl_sparse_qar_overflow(struct 
torture_context *torture,
        return true;
 }
 
+static NTSTATUS test_ioctl_trim_supported(struct torture_context *torture,
+                                         struct smb2_tree *tree,
+                                         TALLOC_CTX *mem_ctx,
+                                         struct smb2_handle *fh,
+                                         bool *trim_support)
+{
+       NTSTATUS status;
+       union smb_fsinfo info;
+
+       ZERO_STRUCT(info);
+       info.generic.level = RAW_QFS_SECTOR_SIZE_INFORMATION;
+       info.generic.handle = *fh;
+       status = smb2_getinfo_fs(tree, tree, &info);
+       if (NT_STATUS_EQUAL(status, NT_STATUS_INVALID_INFO_CLASS)) {
+               /*
+                * Windows < Server 2012, 8 etc. don't support this info level
+                * or the trim ioctl. Ignore the error and let the caller skip.
+                */
+               *trim_support = false;
+               return NT_STATUS_OK;
+       } else if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
+
+       torture_comment(torture, "sector size info: lb/s=%u, pb/sA=%u, "
+                       "pb/sP=%u, fse/sA=%u, flags=0x%x, bosa=%u, bopa=%u\n",
+           (unsigned)info.sector_size_info.out.logical_bytes_per_sector,
+           (unsigned)info.sector_size_info.out.phys_bytes_per_sector_atomic,
+           (unsigned)info.sector_size_info.out.phys_bytes_per_sector_perf,
+  
(unsigned)info.sector_size_info.out.fs_effective_phys_bytes_per_sector_atomic,
+           (unsigned)info.sector_size_info.out.flags,
+           (unsigned)info.sector_size_info.out.byte_off_sector_align,
+           (unsigned)info.sector_size_info.out.byte_off_partition_align);
+
+       if (info.sector_size_info.out.flags & QFS_SSINFO_FLAGS_TRIM_ENABLED) {
+               *trim_support = true;
+       } else {
+               *trim_support = false;
+       }
+       return NT_STATUS_OK;
+}
+
+static bool test_setup_trim(struct torture_context *torture,
+                           struct smb2_tree *tree,
+                           TALLOC_CTX *mem_ctx,
+                           uint32_t num_ranges,
+                           struct smb2_handle *fh,
+                           uint64_t file_size,
+                           uint32_t desired_access,
+                           struct fsctl_file_level_trim_req *trim_req,
+                           union smb_ioctl *ioctl)
+{
+       bool ok;
+
+       ok = test_setup_create_fill(torture, tree, mem_ctx, FNAME,
+                                   fh, file_size, desired_access,
+                                   FILE_ATTRIBUTE_NORMAL);
+       torture_assert(torture, ok, "src file create fill");
+
+       ZERO_STRUCTPN(ioctl);
+       ioctl->smb2.level = RAW_IOCTL_SMB2;
+       ioctl->smb2.in.file.handle = *fh;
+       ioctl->smb2.in.function = FSCTL_FILE_LEVEL_TRIM;
+       ioctl->smb2.in.max_response_size
+                               = sizeof(struct fsctl_file_level_trim_rsp);
+       ioctl->smb2.in.flags = SMB2_IOCTL_FLAG_IS_FSCTL;
+
+       ZERO_STRUCTPN(trim_req);
+       /* leave key as zero for now. TODO test locking with differing keys */
+       trim_req->num_ranges = num_ranges;
+       trim_req->ranges = talloc_zero_array(mem_ctx,
+                                            struct file_level_trim_range,
+                                            num_ranges);
+       torture_assert(torture, (trim_req->ranges != NULL), "no memory for 
ranges");
+
+       return true;
+}
+
+static bool test_ioctl_trim_simple(struct torture_context *torture,
+                                  struct smb2_tree *tree)
+{
+       struct smb2_handle fh;
+       NTSTATUS status;
+       union smb_ioctl ioctl;
+       bool trim_supported;
+       TALLOC_CTX *tmp_ctx = talloc_new(tree);
+       struct fsctl_file_level_trim_req trim_req;
+       struct fsctl_file_level_trim_rsp trim_rsp;
+       uint64_t trim_chunk_len = 64 * 1024;    /* trim 64K chunks */
+       enum ndr_err_code ndr_ret;
+       bool ok;
+
+       ok = test_setup_trim(torture, tree, tmp_ctx,
+                            1, /* 1 range */
+                            &fh, 2 * trim_chunk_len, /* fill 128K file */
+                            SEC_RIGHTS_FILE_ALL,
+                            &trim_req,
+                            &ioctl);
+       if (!ok) {
+               torture_fail(torture, "setup trim error");
+       }
+


-- 
Samba Shared Repository

Reply via email to