linux-cifs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ronnie Sahlberg <lsahlber@redhat.com>
To: linux-cifs <linux-cifs@vger.kernel.org>
Cc: Steve French <smfrench@gmail.com>,
	Pavel Shilovsky <pshilov@microsoft.com>,
	Ronnie Sahlberg <lsahlber@redhat.com>
Subject: [PATCH 1/2] smbinfo: add GETCOMPRESSION support
Date: Thu, 11 Apr 2019 12:23:06 +1000	[thread overview]
Message-ID: <20190411022307.26463-2-lsahlber@redhat.com> (raw)
In-Reply-To: <20190411022307.26463-1-lsahlber@redhat.com>

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

diff --git a/smbinfo.c b/smbinfo.c
index 4bc503a..db569b2 100644
--- a/smbinfo.c
+++ b/smbinfo.c
@@ -87,6 +87,8 @@ usage(char *name)
 		"      Prints FileStandardInfo for a cifs file.\n"
 		"  fsctl-getobjid:\n"
 		"      Prints the objectid of the file and GUID of the underlying volume.\n"
+		"  getcompression:\n"
+		"      Prints the compression setting for the file.\n"
 		"  list-snapshots:\n"
 		"      List the previous versions of the volume that backs this file.\n"
 		"  quota:\n"
@@ -243,6 +245,50 @@ fsctlgetobjid(int f)
 }
 
 static void
+print_getcompression(uint8_t *sd)
+{
+	uint16_t u16;
+
+	memcpy(&u16, &sd[0], 2);
+	u16 = le16toh(u16);
+
+	printf("Compression: ");
+	switch (u16) {
+	case 0:
+		printf("(0) NONE\n");
+		break;
+	case 2:
+		printf("(2) LZNT1\n");
+		break;
+	default:
+		printf("(%d) UNKNOWN\n", u16);
+		break;
+	}
+}
+
+static void
+getcompression(int f)
+{
+	struct smb_query_info *qi;
+
+	qi = malloc(sizeof(struct smb_query_info) + 2);
+	memset(qi, 0, sizeof(qi) + 2);
+	qi->info_type = 0x9003c;
+	qi->file_info_class = 0;
+	qi->additional_information = 0;
+	qi->input_buffer_length = 2;
+	qi->flags = PASSTHRU_FSCTL;
+
+	if (ioctl(f, CIFS_QUERY_INFO, qi) < 0) {
+		fprintf(stderr, "ioctl failed with %s\n", strerror(errno));
+		exit(1);
+	}
+	print_getcompression((uint8_t *)(&qi[1]));
+
+	free(qi);
+}
+
+static void
 print_fileaccessinfo(uint8_t *sd, int type)
 {
 	uint32_t access_flags;
@@ -1118,6 +1164,8 @@ int main(int argc, char *argv[])
 		filestandardinfo(f);
 	else if (!strcmp(argv[optind], "fsctl-getobjid"))
 		fsctlgetobjid(f);
+	else if (!strcmp(argv[optind], "getcompression"))
+		getcompression(f);
 	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 0c96050..ca99b07 100644
--- a/smbinfo.rst
+++ b/smbinfo.rst
@@ -64,6 +64,8 @@ COMMAND
 
 `fsctl-getobjid`: Prints the ObjectID
 
+`getcompression`: Prints 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-04-11  2:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-11  2:23 [PATCH 0/2] Add get/set compression support to smbinfo Ronnie Sahlberg
2019-04-11  2:23 ` Ronnie Sahlberg [this message]
2019-05-07 22:54   ` [PATCH 1/2] smbinfo: add GETCOMPRESSION support Pavel Shilovsky
2019-04-11  2:23 ` [PATCH 2/2] smbinfo: Add SETCOMPRESSION support Ronnie Sahlberg
2019-04-17 21:47   ` Pavel Shilovsky
2019-05-07 22:45     ` Pavel Shilovsky

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=20190411022307.26463-2-lsahlber@redhat.com \
    --to=lsahlber@redhat.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=pshilov@microsoft.com \
    --cc=smfrench@gmail.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).