linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] smbinfo: Add SETCOMPRESSION support
@ 2019-10-03 23:29 Ronnie Sahlberg
  2019-10-04  0:24 ` Pavel Shilovskiy
  0 siblings, 1 reply; 2+ messages in thread
From: Ronnie Sahlberg @ 2019-10-03 23:29 UTC (permalink / raw)
  To: linux-cifs; +Cc: Pavel Shilovsky, Ronnie Sahlberg

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
---
 smbinfo.c   | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
 smbinfo.rst |  2 ++
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/smbinfo.c b/smbinfo.c
index b4d497b..049a4f2 100644
--- a/smbinfo.c
+++ b/smbinfo.c
@@ -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
--- 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
-- 
2.13.6


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-10-04  0:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-03 23:29 [PATCH] smbinfo: Add SETCOMPRESSION support Ronnie Sahlberg
2019-10-04  0:24 ` Pavel Shilovskiy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).