smbinfo: Add SETCOMPRESSION support
Subsystems (2)
PATCH 1/1 smbinfo: Add SETCOMPRESSION support
Signed-off-by Ronnie Sahlberg <[email protected]>
--- smbinfo.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- smbinfo.rst | 2 ++ 2 files changed, 49 insertions(+), 1 deletion(-)
smbinfo.c +47 -1
@@ -91,6 +91,8 @@ usage(char *name)" Prints the objectid of the file and GUID of the underlying volume.\n" " getcompression:\n" " Prints the compression setting for the file.\n" +" setcompression <no|default|lznt1>:\n" +" Sets the compression level for the file.\n" " list-snapshots:\n" " List the previous versions of the volume that backs this file.\n" " quota:\n"
@@ -299,6 +301,30 @@ getcompression(int f) }static void +setcompression (int f,uint16_t level) +{ +struct smb_query_info *qi; + + qi =malloc (sizeof (struct smb_query_info ) +2 ); +memset (qi,0 ,sizeof (qi) +2 ); + qi->info_type =0x9c040 ; + qi->file_info_class =0 ; + qi->additional_information =0 ; + qi->output_buffer_length =2 ; + qi->flags =PASSTHRU_FSCTL ; + + level =htole16 (level); +memcpy (&qi[1 ], &level,2 ); + +if (ioctl (f,CIFS_QUERY_INFO , qi) <0 ) { +fprintf (stderr,"ioctl failed with %s\n" ,strerror (errno)); +exit (1 ); + } + +free (qi); +} + +static void print_fileaccessinfo (uint8_t *sd,int type) {uint32_t access_flags;
@@ -1126,17 +1152,35 @@ list_snapshots(int f)free (buf); } +static int +parse_compression (const char *arg) +{ +if (!strcmp (arg,"no" )) +return 0 ; +else if (!strcmp (arg,"default" )) +return 1 ; +else if (!strcmp (arg,"lznt1" )) +return 2 ; + +fprintf (stderr,"compression must be no|default|lznt1\n" ); +exit (10 ); +} +int main (int argc,char *argv[]) {int c;int f; +int compression =1 ;if (argc <2 ) {short_usage (argv[0 ]); } -while ((c =getopt_long (argc, argv,"vVh" ,NULL ,NULL )) !=-1 ) { +while ((c =getopt_long (argc, argv,"c:vVh" ,NULL ,NULL )) !=-1 ) {switch (c) { +case 'c' : + compression =parse_compression (optarg); +break ;case 'v' :printf ("smbinfo version %s\n" ,VERSION );return 0 ;
@@ -1183,6 +1227,8 @@ int main(int argc, char *argv[])fsctlgetobjid (f); else if (!strcmp(argv[optind], "getcompression")) getcompression(f); + else if (!strcmp(argv[optind], "setcompression")) + setcompression(f, compression); else if (!strcmp(argv[optind], "list-snapshots")) list_snapshots(f); else if (!strcmp(argv[optind], "quota"))
smbinfo.rst +2 -0
@@ -69,6 +69,8 @@ COMMAND `getcompression`: Prints the compression setting for the file. +`setcompression -c <no|default|lznt1>`: Sets the compression setting for the file. + `list-snapshots`: Lists the previous versions of the volume that backs this file `quota`: Print the quota for the volume in the form
Signature · 1 line
2.13.6
Pavel Shilovskiy
AppliedMerged, thanks!
Best regards,
Pavel Shilovsky
-----Original Message-----
From: Ronnie Sahlberg <[email protected]>
Sent: Thursday, October 3, 2019 4:29 PM
To: linux-cifs <[email protected]>
Cc: Pavel Shilovskiy <[email protected]>; Ronnie Sahlberg <[email protected]>
Subject: [PATCH] smbinfo: Add SETCOMPRESSION support
Signed-off-by Ronnie Sahlberg <[email protected]>
--- smbinfo.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- smbinfo.rst | 2 ++ 2 files changed, 49 insertions(+), 1 deletion(-)
smbinfo.c +47 -1
@@ -91,6 +91,8 @@ usage(char *name)" Prints the objectid of the file and GUID of the underlying volume.\n" " getcompression:\n" " Prints the compression setting for the file.\n" +" setcompression <no|default|lznt1>:\n" +" Sets the compression level for the file.\n" " list-snapshots:\n" " List the previous versions of the volume that backs this file.\n" " quota:\n"
@@ -299,6 +301,30 @@ getcompression(int f) }static void +setcompression (int f,uint16_t level) +{ +struct smb_query_info *qi; + + qi =malloc (sizeof (struct smb_query_info ) +2 ); +memset (qi,0 ,sizeof (qi) +2 ); + qi->info_type =0x9c040 ; + qi->file_info_class =0 ; + qi->additional_information =0 ; + qi->output_buffer_length =2 ; + qi->flags =PASSTHRU_FSCTL ; + + level =htole16 (level); +memcpy (&qi[1 ], &level,2 ); + +if (ioctl (f,CIFS_QUERY_INFO , qi) <0 ) { +fprintf (stderr,"ioctl failed with %s\n" ,strerror (errno)); +exit (1 ); + } + +free (qi); +} + +static void print_fileaccessinfo (uint8_t *sd,int type) {uint32_t access_flags;
@@ -1126,17 +1152,35 @@ list_snapshots(int f)free (buf); } +static int +parse_compression (const char *arg) +{ +if (!strcmp (arg,"no" )) +return 0 ; +else if (!strcmp (arg,"default" )) +return 1 ; +else if (!strcmp (arg,"lznt1" )) +return 2 ; + +fprintf (stderr,"compression must be no|default|lznt1\n" ); +exit (10 ); +} +int main (int argc,char *argv[]) {int c;int f; +int compression =1 ;if (argc <2 ) {short_usage (argv[0 ]); } -while ((c =getopt_long (argc, argv,"vVh" ,NULL ,NULL )) !=-1 ) { +while ((c =getopt_long (argc, argv,"c:vVh" ,NULL ,NULL )) !=-1 ) {switch (c) { +case 'c' : + compression =parse_compression (optarg); +break ;case 'v' :printf ("smbinfo version %s\n" ,VERSION );return 0 ;
@@ -1183,6 +1227,8 @@ int main(int argc, char *argv[])fsctlgetobjid (f); else if (!strcmp(argv[optind], "getcompression")) getcompression(f); + else if (!strcmp(argv[optind], "setcompression")) + setcompression(f, compression); else if (!strcmp(argv[optind], "list-snapshots")) list_snapshots(f); else if (!strcmp(argv[optind], "quota")) diff --git a/smbinfo.rst b/smbinfo.rst index 500ce0e..c8f76e6 100644
smbinfo.rst +2 -0
@@ -69,6 +69,8 @@ COMMAND `getcompression`: Prints the compression setting for the file. +`setcompression -c <no|default|lznt1>`: Sets the compression setting for the file. + `list-snapshots`: Lists the previous versions of the volume that backs this file `quota`: Print the quota for the volume in the form
--
2.13.6