Package: discus / 0.2.9-6

20_bts-312262_reserved_space.diff Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
Descriptio: Take into account space reserved for root.
Author: Sandro Tosi <morph@debian.org>
Bug-Debian: http://bugs.debian.org/312262
Forwarded: no
Last-Update: 2011-10-18

--- a/discus
+++ b/discus
@@ -28,7 +28,7 @@
 ##  Define version number and create options object with internal settings.
 
 VERSION = "0.2.9"
-opts = {"placing": 0, "vfsing": 1}
+opts = {"placing": 0, "vfsing": 1, "reserved": 0}
 
 
 ##  Import modules used.
@@ -156,7 +156,7 @@
 
 	def percentage(self):
 		try:
-			percent = (1.0 - (1.0 * self.free_root / self.total)) * 100
+			percent = (1.0 - (1.0 * self.free / self.total)) * 100
 		except ZeroDivisionError:
 			percent = 0.0
 		
@@ -209,8 +209,14 @@
 			stats = os.statvfs(mount)
 			blocksize = int(stats[F_FRSIZE])
 			self.total = int(stats[F_BLOCKS]) * (blocksize / 1024.0)
-			self.free_root = int(stats[F_BFREE]) * (blocksize / 1024.0)
-			self.free = int(stats[F_BAVAIL]) * (blocksize / 1024.0)
+			# if we have to take care of reserved space for root, then use
+			# available blocks (but keep counting free space with all free blocks)
+			if opts["reserved"]:
+				self.free = int(stats[F_BAVAIL]) * (blocksize / 1024.0)
+				self.used = self.total - int(stats[F_BFREE]) * (blocksize / 1024.0)
+			else:
+				self.free = int(stats[F_BFREE]) * (blocksize / 1024.0)
+				self.used = self.total - int(stats[F_BFREE]) * (blocksize / 1024.0)
 		else:
 
 			##  External stat program.
@@ -223,10 +229,12 @@
 			stats = string.split(stats)
 			blocksize = int(stats[8])
 			self.total = int(stats[5]) * (blocksize / 1024.0)
-			self.free_root = int(stats[6]) * (blocksize / 1024.0)
-			self.free = int(stats[7]) * (blocksize / 1024.0)
-
-		self.used = self.total - self.free_root
+			if opts["reserved"]:
+				self.free = int(stats[7]) * (blocksize / 1024.0)
+				self.used = self.total - int(stats[7]) * (blocksize / 1024.0)
+			else:
+				self.free = int(stats[6]) * (blocksize / 1024.0)
+				self.used = self.total - int(stats[7]) * (blocksize / 1024.0)
 
 
 	##  Don't let long names mess up the display: shorten them
@@ -266,6 +274,7 @@
                     assumes -s
  -d              show device instead of graph
  -c              disable color
+ -r              count reserved space as used
 """ % VERSION
 
 	else:
@@ -282,7 +291,7 @@
 	##  Read the command line options provided by the user.
 
 	try:
-		options, args = getopt.getopt(sys.argv[1:], "p:tgmksdcvh",
+		options, args = getopt.getopt(sys.argv[1:], "p:tgmksdcrvh",
 			["help", "version"])
 	except:
 		help()
@@ -356,6 +365,9 @@
 
 		if option in ["-h", "--help"]:
 			help()
+
+		if option == "-r":
+			opts["reserved"] = 1
 	
 
 
@@ -429,7 +441,7 @@
 		mount,
 		"Total",
 		"Used",
-		"Free",
+		"Avail",
 		"Prcnt",
 		graph
 	) + color("clear")
--- a/discus.1
+++ b/discus.1
@@ -52,6 +52,10 @@
 .TP
 .B \-v, \-\-version
 Show version of program.
+.TP
+.B \-r
+Takes into account even the reserved space to root; it will be counted in percentage and in available columns only (Used is for real used space).
+.SH FILES
 .SH FILES
 .BR /etc/discusrc,
 .BR $HOME/.discusrc