linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pavel Shilovskiy <pshilov@microsoft.com>
To: Ronnie Sahlberg <lsahlber@redhat.com>,
	linux-cifs <linux-cifs@vger.kernel.org>
Subject: RE: [PATCH] smbinfo: Add SETCOMPRESSION support
Date: Fri, 4 Oct 2019 00:24:01 +0000	[thread overview]
Message-ID: <BY5PR21MB1395A1A4810389587DC128FAB69E0@BY5PR21MB1395.namprd21.prod.outlook.com> (raw)
In-Reply-To: <20191003232902.16332-1-lsahlber@redhat.com>

Merged, thanks!

Best regards,
Pavel Shilovsky

-----Original Message-----
From: Ronnie Sahlberg <lsahlber@redhat.com> 
Sent: Thursday, October 3, 2019 4:29 PM
To: linux-cifs <linux-cifs@vger.kernel.org>
Cc: Pavel Shilovskiy <pshilov@microsoft.com>; Ronnie Sahlberg <lsahlber@redhat.com>
Subject: [PATCH] smbinfo: Add SETCOMPRESSION support

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


      reply	other threads:[~2019-10-04  0:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-03 23:29 [PATCH] smbinfo: Add SETCOMPRESSION support Ronnie Sahlberg
2019-10-04  0:24 ` Pavel Shilovskiy [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BY5PR21MB1395A1A4810389587DC128FAB69E0@BY5PR21MB1395.namprd21.prod.outlook.com \
    --to=pshilov@microsoft.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=lsahlber@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).