add -i (inode format) support to df command
This commit is contained in:
parent
a210aa7e23
commit
e20e2eaa54
|
@ -48,8 +48,19 @@ public class Df extends SigarCommandBase {
|
|||
"Mounted on",
|
||||
"Type"
|
||||
};
|
||||
//df -i
|
||||
private static final String[] IHEADER = new String[] {
|
||||
"Filesystem",
|
||||
"Inodes",
|
||||
"IUsed",
|
||||
"IFree",
|
||||
"IUse%",
|
||||
"Mounted on",
|
||||
"Type"
|
||||
};
|
||||
|
||||
private GetlineCompleter completer;
|
||||
private boolean opt_i;
|
||||
|
||||
public Df(Shell shell) {
|
||||
super(shell);
|
||||
|
@ -67,7 +78,7 @@ public class Df extends SigarCommandBase {
|
|||
}
|
||||
|
||||
protected boolean validateArgs(String[] args) {
|
||||
return args.length <= 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getSyntaxArgs() {
|
||||
|
@ -79,31 +90,42 @@ public class Df extends SigarCommandBase {
|
|||
}
|
||||
|
||||
public void printHeader() {
|
||||
printf(HEADER);
|
||||
printf(this.opt_i ? IHEADER : HEADER);
|
||||
}
|
||||
|
||||
public void output(String[] args) throws SigarException {
|
||||
if (args.length == 1) {
|
||||
this.opt_i = false;
|
||||
ArrayList sys = new ArrayList();
|
||||
|
||||
if (args.length > 0) {
|
||||
FileSystemMap mounts = this.proxy.getFileSystemMap();
|
||||
String name = FileCompleter.expand(args[0]);
|
||||
for (int i=0; i<args.length; i++) {
|
||||
String arg = args[i];
|
||||
if (arg.equals("-i")) {
|
||||
this.opt_i = true;
|
||||
continue;
|
||||
}
|
||||
String name = FileCompleter.expand(arg);
|
||||
FileSystem fs = mounts.getMountPoint(name);
|
||||
|
||||
if (fs != null) {
|
||||
printHeader();
|
||||
output(fs);
|
||||
return;
|
||||
}
|
||||
|
||||
throw new SigarException(args[0] +
|
||||
if (fs == null) {
|
||||
throw new SigarException(arg +
|
||||
" No such file or directory");
|
||||
}
|
||||
else {
|
||||
FileSystem[] fslist = this.proxy.getFileSystemList();
|
||||
printHeader();
|
||||
for (int i=0; i<fslist.length; i++) {
|
||||
output(fslist[i]);
|
||||
sys.add(fs);
|
||||
}
|
||||
}
|
||||
if (sys.size() == 0) {
|
||||
FileSystem[] fslist = this.proxy.getFileSystemList();
|
||||
for (int i=0; i<fslist.length; i++) {
|
||||
sys.add(fslist[i]);
|
||||
}
|
||||
}
|
||||
|
||||
printHeader();
|
||||
for (int i=0; i<sys.size(); i++) {
|
||||
output((FileSystem)sys.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
public void output(FileSystem fs) throws SigarException {
|
||||
|
@ -119,12 +141,26 @@ public class Df extends SigarCommandBase {
|
|||
}
|
||||
}
|
||||
usage = this.sigar.getFileSystemUsage(fs.getDirName());
|
||||
|
||||
if (this.opt_i) {
|
||||
used = usage.getFiles() - usage.getFreeFiles();
|
||||
avail = usage.getFreeFiles();
|
||||
total = usage.getFiles();
|
||||
if (total == 0) {
|
||||
pct = 0;
|
||||
}
|
||||
else {
|
||||
long u100 = used * 100;
|
||||
pct = u100 / total +
|
||||
((u100 % total != 0) ? 1 : 0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
used = usage.getTotal() - usage.getFree();
|
||||
avail = usage.getAvail();
|
||||
total = usage.getTotal();
|
||||
|
||||
pct = (long)(usage.getUsePercent() * 100);
|
||||
}
|
||||
} catch (SigarException e) {
|
||||
//e.g. on win32 D:\ fails with "Device not ready"
|
||||
//if there is no cd in the drive.
|
||||
|
@ -152,8 +188,8 @@ public class Df extends SigarCommandBase {
|
|||
printf(items);
|
||||
}
|
||||
|
||||
private static String formatSize(long size) {
|
||||
return Sigar.formatSize(size * 1024);
|
||||
private String formatSize(long size) {
|
||||
return this.opt_i ? String.valueOf(size) : Sigar.formatSize(size * 1024);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
|
Loading…
Reference in New Issue