smbinfo: add filecompressioninfo subcommand
Subsystems (2)
[email protected]
reviewerPATCH 1/1 smbinfo: add filecompressioninfo subcommand
From: ChenXiaoSong <[email protected]>
Example:
./smbinfo filecompressioninfo /mnt/file
Compressed File Size: 104857600
Compression Format: 2 (LZNT1)
Compression Unit Shift: 0
Chunk Shift: 0
Cluster Shift: 0
Signed-off-by ChenXiaoSong <[email protected]>
--- bash-completion/smbinfo | 9 ++++++--- smbinfo | 33 +++++++++++++++++++++++++++++++++ smbinfo.rst | 2 ++ 3 files changed, 41 insertions(+), 3 deletions(-)
bash-completion/smbinfo +6 -3
@@ -16,6 +16,7 @@ smb_info() filepositioninfo filestandardinfo filestreaminfo + filecompressioninfo fsctl-getobjid getcompression setcompression
@@ -28,9 +29,11 @@ smb_info() '-v'|'-h') return 0 ;; - 'fileaccessinfo'|'filealigninfo'|'fileallinfo'|'filebasicinfo'|'fileeainfo'|'filefsfullsizeinfo'|\ - 'fileinternalinfo'|'filemodeinfo'|'filepositioninfo'|'filestandardinfo'|'filestreaminfo'|'fsctl-getobjid'|\ - 'getcompression'|'setcompression'|'list-snapshots'|'quota'|'secdesc'|'keys'|'gettconinfo') + 'fileaccessinfo'|'filealigninfo'|'fileallinfo'|'filebasicinfo'|'fileeainfo'|\ + 'filefsfullsizeinfo'|'fileinternalinfo'|'filemodeinfo'|'filepositioninfo'|\ + 'filestandardinfo'|'filestreaminfo'|'filecompressioninfo'|'fsctl-getobjid'|\ + 'getcompression'|'setcompression'|'list-snapshots'|'quota'|'secdesc'|'keys'|\ + 'gettconinfo') local IFS=$'\n' compopt -o filenames COMPREPLY=( $(compgen -f -o dirnames -- ${cur:-""}) )
smbinfo +33 -0
@@ -31,6 +31,12 @@ import threading VERBOSE = False +# InfoType values +SMB2_O_INFO_FILE = 0x01 + +# QUERY INFO levels +FILE_COMPRESSION_INFORMATION = 28 + # ioctl ctl codes CIFS_QUERY_INFO = 0xc018cf07 CIFS_ENUMERATE_SNAPSHOTS = 0x800ccf06
@@ -263,6 +269,10 @@ def main(): sap.add_argument("file") sap.set_defaults(func=cmd_filestreaminfo) + sap = subp.add_parser("filecompressioninfo", help="Prints FileCompressionInfo for a cifs file") + sap.add_argument("file") + sap.set_defaults(func=cmd_filecompressioninfo) + sap = subp.add_parser("fsctl-getobjid", help="Prints the objectid of the file and GUID of the underlying volume.") sap.add_argument("file") sap.set_defaults(func=cmd_fsctl_getobjid)
@@ -809,6 +819,29 @@ def print_filestreaminfo(buf): offset+=next_offset +def cmd_filecompressioninfo(args): + qi = QueryInfoStruct(info_type=SMB2_O_INFO_FILE, + file_info_class=FILE_COMPRESSION_INFORMATION, + input_buffer_length=16) + try: + fd = os.open(args.file, os.O_RDONLY) + buf = qi.ioctl(fd) + except Exception as e: + print("syscall failed: %s"%e) + return False + + comp_size, fmt, unit_shift, chunk_shift, cluster_shift = struct.unpack_from('<QHBBB', buf, 0) + print("Compressed File Size: %d"%comp_size) + fmt_name = "UNKNOWN" + for val, name in COMPRESSION_TYPES: + if fmt == val: + fmt_name = name + break + print("Compression Format: %d (%s)"%(fmt, fmt_name)) + print("Compression Unit Shift: %d"%unit_shift) + print("Chunk Shift: %d"%chunk_shift) + print("Cluster Shift: %d"%cluster_shift) + class KeyDebugInfoStruct: def __init__(self): self.suid = bytearray()
smbinfo.rst +2 -0
@@ -67,6 +67,8 @@ COMMAND `filestreaminfo`: Prints the FileStreamInformation class +`filecompressioninfo`: Prints the FileCompressionInformation class + `fsctl-getobjid`: Prints the ObjectID `getcompression`: Prints the compression setting for the file.
Signature · 1 line
2.54.0
Steve French
Appliedmerged into smb3-utils for-next branch
I also tested it out to Windows and worked fine.
Quoted 120 lines · On Mon, Jun 8, 2026 at 4:28 AM <[email protected]> wrote:
From: ChenXiaoSong <[email protected]>
Example:
./smbinfo filecompressioninfo
/mnt/file
Compressed File Size: 104857600
Compression Format: 2 (LZNT1)
Compression Unit Shift: 0
Chunk Shift: 0
Cluster Shift: 0Signed-off-by ChenXiaoSong <[email protected]>--- bash-completion/smbinfo | 9 ++++++--- smbinfo | 33 +++++++++++++++++++++++++++++++++ smbinfo.rst | 2 ++ 3 files changed, 41 insertions(+), 3 deletions(-)bash-completion/smbinfo +6
-3@@ -16,6 +16,7 @@ smb_info() filepositioninfo filestandardinfo filestreaminfo + filecompressioninfo fsctl-getobjid getcompression setcompression@@ -28,9 +29,11 @@ smb_info() '-v'|'-h') return 0 ;; - 'fileaccessinfo'|'filealigninfo'|'fileallinfo'|'filebasicinfo'|'fileeainfo'|'filefsfullsizeinfo'|\ - 'fileinternalinfo'|'filemodeinfo'|'filepositioninfo'|'filestandardinfo'|'filestreaminfo'|'fsctl-getobjid'|\ - 'getcompression'|'setcompression'|'list-snapshots'|'quota'|'secdesc'|'keys'|'gettconinfo') + 'fileaccessinfo'|'filealigninfo'|'fileallinfo'|'filebasicinfo'|'fileeainfo'|\ + 'filefsfullsizeinfo'|'fileinternalinfo'|'filemodeinfo'|'filepositioninfo'|\ + 'filestandardinfo'|'filestreaminfo'|'filecompressioninfo'|'fsctl-getobjid'|\ + 'getcompression'|'setcompression'|'list-snapshots'|'quota'|'secdesc'|'keys'|\ + 'gettconinfo') local IFS=$'\n' compopt -o filenames COMPREPLY=( $(compgen -f -o dirnames -- ${cur:-""}) )smbinfo +33
-0@@ -31,6 +31,12 @@ import threading VERBOSE = False +# InfoType values +SMB2_O_INFO_FILE = 0x01 + +# QUERY INFO levels +FILE_COMPRESSION_INFORMATION = 28 + # ioctl ctl codes CIFS_QUERY_INFO = 0xc018cf07 CIFS_ENUMERATE_SNAPSHOTS = 0x800ccf06@@ -263,6 +269,10 @@ def main(): sap.add_argument("file") sap.set_defaults(func=cmd_filestreaminfo) + sap = subp.add_parser("filecompressioninfo", help="Prints FileCompressionInfo for a cifs file") + sap.add_argument("file") + sap.set_defaults(func=cmd_filecompressioninfo) + sap = subp.add_parser("fsctl-getobjid", help="Prints the objectid of the file and GUID of the underlying volume.") sap.add_argument("file") sap.set_defaults(func=cmd_fsctl_getobjid)@@ -809,6 +819,29 @@ def print_filestreaminfo(buf): offset+=next_offset +def cmd_filecompressioninfo(args): + qi = QueryInfoStruct(info_type=SMB2_O_INFO_FILE, + file_info_class=FILE_COMPRESSION_INFORMATION, + input_buffer_length=16) + try: + fd = os.open(args.file, os.O_RDONLY) + buf = qi.ioctl(fd) + except Exception as e: + print("syscall failed: %s"%e) + return False + + comp_size, fmt, unit_shift, chunk_shift, cluster_shift = struct.unpack_from('<QHBBB', buf, 0) + print("Compressed File Size: %d"%comp_size) + fmt_name = "UNKNOWN" + for val, name in COMPRESSION_TYPES: + if fmt == val: + fmt_name = name + break + print("Compression Format: %d (%s)"%(fmt, fmt_name)) + print("Compression Unit Shift: %d"%unit_shift) + print("Chunk Shift: %d"%chunk_shift) + print("Cluster Shift: %d"%cluster_shift) + class KeyDebugInfoStruct: def __init__(self): self.suid = bytearray()smbinfo.rst +2
-1@@ -67,6 +67,8 @@ COMMAND `filestreaminfo`: Prints the FileStreamInformation class +`filecompressioninfo`: Prints the FileCompressionInformation class + `fsctl-getobjid`: Prints the ObjectID `getcompression`: Prints the compression setting for the file. --2.54.0
Signature · 3 lines
Thanks, Steve