3 // authors, in order of contribution:
4 // jonas.sundstrom@kirilla.com
5 // axeld@pinc-software.de
10 #include <Directory.h>
23 PrintFlag(uint32 deviceFlags
, uint32 testFlag
, const char *yes
, const char *no
)
25 printf(deviceFlags
& testFlag
? yes
: no
);
30 PrintMountPoint(dev_t device
, bool verbose
)
32 char mount
[B_PATH_NAME_LENGTH
];
35 BVolume
volume(device
);
37 if (volume
.GetRootDirectory(&root
) == B_OK
) {
38 BPath
path(&root
, NULL
);
39 if (path
.InitCheck() == B_OK
)
40 strlcpy(mount
, path
.Path(), sizeof(mount
));
42 strlcpy(mount
, "?", sizeof(mount
));
46 printf(" Mounted at: %s\n", mount
);
48 printf("%-15s ", mount
);
49 if (strlen(mount
) > 15)
50 printf("\n%15s ", "");
56 PrintType(const char *fileSystem
)
59 strlcpy(type
, fileSystem
, sizeof(type
));
66 ByteString(int64 numBlocks
, int64 blockSize
)
68 double blocks
= 1. * numBlocks
* blockSize
;
69 static char string
[64];
72 sprintf(string
, "%" B_PRId64
, numBlocks
* blockSize
);
74 const char *units
[] = {"K", "M", "G", NULL
};
80 } while (blocks
>= 1024 && units
[i
+ 1]);
82 sprintf(string
, "%.1f%s", blocks
, units
[i
]);
90 PrintBlocks(int64 blocks
, int64 blockSize
, bool showBlocks
)
95 sprintf(temp
, "%" B_PRId64
, blocks
* (blockSize
/ 1024));
97 strcpy(temp
, ByteString(blocks
, blockSize
));
104 PrintVerbose(dev_t device
)
107 if (fs_stat_dev(device
, &info
) != B_OK
) {
108 fprintf(stderr
, "Could not stat fs: %s\n", strerror(errno
));
112 printf(" Device No.: %" B_PRIdDEV
"\n", info
.dev
);
113 PrintMountPoint(info
.dev
, true);
114 printf(" Volume Name: \"%s\"\n", info
.volume_name
);
115 printf(" File System: %s\n", info
.fsh_name
);
116 printf(" Device: %s\n", info
.device_name
);
119 PrintFlag(info
.flags
, B_FS_HAS_QUERY
, "Q", "-");
120 PrintFlag(info
.flags
, B_FS_HAS_ATTR
, "A", "-");
121 PrintFlag(info
.flags
, B_FS_HAS_MIME
, "M", "-");
122 PrintFlag(info
.flags
, B_FS_IS_SHARED
, "S", "-");
123 PrintFlag(info
.flags
, B_FS_IS_PERSISTENT
, "P", "-");
124 PrintFlag(info
.flags
, B_FS_IS_REMOVABLE
, "R", "-");
125 PrintFlag(info
.flags
, B_FS_IS_READONLY
, "-", "W");
127 printf("\n I/O Size: %10s (%" B_PRIdOFF
" byte)\n",
128 ByteString(info
.io_size
, 1), info
.io_size
);
129 printf(" Block Size: %10s (%" B_PRIdOFF
" byte)\n",
130 ByteString(info
.block_size
, 1), info
.block_size
);
131 printf(" Total Blocks: %10s (%" B_PRIdOFF
" blocks)\n",
132 ByteString(info
.total_blocks
, info
.block_size
), info
.total_blocks
);
133 printf(" Free Blocks: %10s (%" B_PRIdOFF
" blocks)\n",
134 ByteString(info
.free_blocks
, info
.block_size
), info
.free_blocks
);
135 printf(" Total Nodes: %" B_PRIdOFF
"\n", info
.total_nodes
);
136 printf(" Free Nodes: %" B_PRIdOFF
"\n", info
.free_nodes
);
137 printf(" Root Inode: %" B_PRIdINO
"\n", info
.root
);
142 PrintCompact(dev_t device
, bool showBlocks
, bool all
)
145 if (fs_stat_dev(device
, &info
) != B_OK
)
148 if (!all
&& (info
.flags
& B_FS_IS_PERSISTENT
) == 0)
151 PrintMountPoint(info
.dev
, false);
152 PrintType(info
.fsh_name
);
153 PrintBlocks(info
.total_blocks
, info
.block_size
, showBlocks
);
154 PrintBlocks(info
.free_blocks
, info
.block_size
, showBlocks
);
157 PrintFlag(info
.flags
, B_FS_HAS_QUERY
, "Q", "-");
158 PrintFlag(info
.flags
, B_FS_HAS_ATTR
, "A", "-");
159 PrintFlag(info
.flags
, B_FS_HAS_MIME
, "M", "-");
160 PrintFlag(info
.flags
, B_FS_IS_SHARED
, "S", "-");
161 PrintFlag(info
.flags
, B_FS_IS_PERSISTENT
, "P", "-");
162 PrintFlag(info
.flags
, B_FS_IS_REMOVABLE
, "R", "-");
163 PrintFlag(info
.flags
, B_FS_IS_READONLY
, "-", "W");
165 printf(" %s\n", info
.device_name
);
170 ShowUsage(const char *programName
)
172 printf("usage: %s [--help | --blocks, -b | -all, -a] [<path-to-device>]\n"
173 " -a, --all\tinclude all file systems, also those not visible from Tracker\n"
174 " -b, --blocks\tshow device size in blocks of 1024 bytes\n"
175 "If <path-to-device> is used, detailed info for that device only will be listed.\n"
178 " A: has attribute\n"
181 " P: is persistent (visible in Tracker)\n"
183 " W: is writable\n", programName
);
189 main(int argc
, char **argv
)
191 char *programName
= argv
[0];
192 if (strrchr(programName
, '/'))
193 programName
= strrchr(programName
, '/') + 1;
195 bool showBlocks
= false;
202 while (*++arg
&& isalpha(*arg
)) {
211 ShowUsage(programName
);
216 if (!strcmp(arg
, "all"))
218 else if (!strcmp(arg
, "blocks"))
221 ShowUsage(programName
);
227 // Do we already have a device? Then let's print out detailed info about that
229 if (argv
[0] != NULL
) {
230 PrintVerbose(dev_for_path(argv
[0]));
234 // If not, then just iterate over all devices and give a compact summary
236 printf("Mount Type Total Free Flags Device\n"
237 "--------------- -------- --------- --------- ------- --------------------------\n");
240 while ((device
= next_dev(&cookie
)) >= B_OK
) {
241 PrintCompact(device
, showBlocks
, all
);