[PATCH] smb2-quota: Simplify code logic for quota entries.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch changes the program name from smb2quota to
smb2-quota and uses a simple code logic for quota entries.

Signed-off-by: Kenneth D'souza <kdsouza@xxxxxxxxxx>
Signed-off-by: Ronnie Sahlberg <lsahlberg@xxxxxxxxxx>
---
 smb2quota.py => smb2-quota.py   | 19 +++++++------------
 smb2quota.rst => smb2-quota.rst |  8 ++++----
 2 files changed, 11 insertions(+), 16 deletions(-)
 rename smb2quota.py => smb2-quota.py (91%)
 rename smb2quota.rst => smb2-quota.rst (89%)

diff --git a/smb2quota.py b/smb2-quota.py
similarity index 91%
rename from smb2quota.py
rename to smb2-quota.py
index 21bf4ff..6d0b8a3 100755
--- a/smb2quota.py
+++ b/smb2-quota.py
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 # coding: utf-8
 #
-# smb2quota is a cmdline tool to display quota information for the
+# smb2-quota is a cmdline tool to display quota information for the
 # Linux SMB client file system (CIFS)
 #
 # Copyright (C) Ronnie Sahlberg (lsahlberg@xxxxxxxxxx) 2019
@@ -34,7 +34,7 @@ ENDC = '\033[m'   # Rest to defaults
 
 def usage():
     print("Usage: %s [-h] <options> <filename>" % sys.argv[0])
-    print("Try 'smb2quota -h' for more information")
+    print("Try 'smb2-quota -h' for more information")
     sys.exit()
 
 
@@ -120,18 +120,13 @@ class QuotaEntry:
 class Quota:
     def __init__(self, buf, flag):
         self.quota = []
-        s = struct.unpack_from('<I', buf, 0)[0]
-        while s:
-            qe = QuotaEntry(buf[0:s], flag)
+        while buf:
+            qe = QuotaEntry(buf, flag)
             self.quota.append(qe)
-            buf = buf[s:]
-            a = s
             s = struct.unpack_from('<I', buf, 0)[0]
             if s == 0:
-                s = a   # Use the last value of s and process it.
-                qe = QuotaEntry(buf[0:s], flag)
-                self.quota.append(qe)
                 break
+            buf = buf[s:]
 
     def __str__(self):
         s = ''
@@ -158,7 +153,7 @@ def parser_check(path, flag):
         fcntl.ioctl(f, CIFS_QUERY_INFO, buf, 1)
         os.close(f)
         if flag == 0:
-            print(BBOLD + " %-7s | %-7s | %-7s | %-7s | %-12s | %s " + ENDC) % (titleused, titlelim, titlethr, titlepercent, titlestatus, titlesid)
+            print((BBOLD + " %-7s | %-7s | %-7s | %-7s | %-12s | %s " + ENDC) % (titleused, titlelim, titlethr, titlepercent, titlestatus, titlesid))
         q = Quota(buf[24:24 + struct.unpack_from('<I', buf, 16)[0]], flag)
         print(q)
     except IOError as reason:
@@ -171,7 +166,7 @@ def main():
     if len(sys.argv) < 2:
         usage()
 
-    parser = argparse.ArgumentParser(description="Please specify an action to perform.", prog="smb2quota")
+    parser = argparse.ArgumentParser(description="Please specify an action to perform.", prog="smb2-quota")
     parser.add_argument("-t", "--tabular", action="store_true", help="print quota information in tabular format")
     parser.add_argument("-c", "--csv",  action="store_true", help="print quota information in csv format")
     parser.add_argument("-l", "--list", action="store_true", help="print quota information in list format")
diff --git a/smb2quota.rst b/smb2-quota.rst
similarity index 89%
rename from smb2quota.rst
rename to smb2-quota.rst
index 24caca8..508b874 100644
--- a/smb2quota.rst
+++ b/smb2-quota.rst
@@ -1,5 +1,5 @@
 ============
-smb2quota
+smb2-quota
 ============
 
 -----------------------------------------------------------------------------------------------------
@@ -11,7 +11,7 @@ Userspace helper to display quota information for the Linux SMB client file syst
 SYNOPSIS
 ********
 
-  smb2quota [-h] {options} {file system object}
+  smb2-quota [-h] {options} {file system object}
 
 ***********
 DESCRIPTION
@@ -19,7 +19,7 @@ DESCRIPTION
 
 This tool is part of the cifs-utils suite.
 
-`smb2quota` is a userspace helper program for the Linux SMB
+`smb2-quota` is a userspace helper program for the Linux SMB
 client file system (CIFS).
 
 This tool works by making an CIFS_QUERY_INFO IOCTL call to the Linux
@@ -49,7 +49,7 @@ SID,Amount Used,Quota Limit,Warning Level
 NOTES
 *****
 
-Kernel support for smb2quota requires the CIFS_QUERY_INFO
+Kernel support for smb2-quota requires the CIFS_QUERY_INFO
 IOCTL which was initially introduced in the 4.20 kernel and is only
 implemented for mount points using SMB2 or above (see mount.cifs(8)
 `vers` option).
-- 
2.21.0





[Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux