summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRonnie Sahlberg <lsahlber@redhat.com>2019-10-04 09:29:02 +1000
committerPavel Shilovsky <pshilov@microsoft.com>2019-10-03 17:21:02 -0700
commit07c5812c062ac584511f244f91fcdfd5d08c8b68 (patch)
treef0eca91c23e45d560af7633426fe7989c6f0b951
parent6df98da5cd3fbb33f6f535c6784f037bbadadb84 (diff)
downloadcifs-utils-07c5812c062ac584511f244f91fcdfd5d08c8b68.tar.gz
cifs-utils-07c5812c062ac584511f244f91fcdfd5d08c8b68.tar.bz2
cifs-utils-07c5812c062ac584511f244f91fcdfd5d08c8b68.zip
smbinfo: Add SETCOMPRESSION support
Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
-rw-r--r--smbinfo.c48
-rw-r--r--smbinfo.rst2
2 files changed, 49 insertions, 1 deletions
diff --git a/smbinfo.c b/smbinfo.c
index 2aa5eee..636f1bd 100644
--- a/smbinfo.c
+++ b/smbinfo.c
@@ -101,6 +101,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"
@@ -311,6 +313,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;
@@ -1175,17 +1201,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;
@@ -1232,6 +1276,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
--- a/smbinfo.rst
+++ b/smbinfo.rst
@@ -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