Skip to content

Commit 3f24194

Browse files
committed
Improve partition listing output format, add totalsize in GiB. ls command now prints only main partitions with their total size. ls -l prints now also totalsize in GiB as well as slice size
1 parent 7c372f8 commit 3f24194

1 file changed

Lines changed: 26 additions & 9 deletions

File tree

src/hl.c

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,13 @@ int lspart(int lsmode)
176176
int result;
177177
iox_dirent_t dirent;
178178
if (lsmode == 1)
179-
printf("Start (sector) Code Size Timestamp Name\n");
179+
printf("Start (sector) Code Slice Size Timestamp Name\n");
180180
while ((result = iomanX_dread(dh, &dirent)) && result != -1) {
181181

182182
// Equal to, but avoids overflows of: size * 512 / 1024 / 1024;
183183
uint32_t size = dirent.stat.size / 2048;
184+
uint64_t totalsize = (dirent.stat.private_1 + dirent.stat.private_2 * 0x100000000ULL) / 2048;
185+
double sizeInGiB = totalsize / 1024.0;
184186

185187
if (dirent.stat.mode == 0x0000) /* empty partition */
186188
end_symbol[0] = '%';
@@ -199,16 +201,31 @@ int lspart(int lsmode)
199201
sprintf(mod_time, "%04d-%02d-%02d %02d:%02d",
200202
mtime->year, mtime->month, mtime->day,
201203
mtime->hour, mtime->min);
202-
if (lsmode == 0)
203-
printf("%s%s\n",
204-
dirent.name, end_symbol);
205-
else if (lsmode == 1) {
204+
if (lsmode == 0) {
205+
if (dirent.stat.attr == 0 && dirent.stat.mode != 0x0000)
206+
printf("%7.2f GiB %s%s\n", sizeInGiB, dirent.name, end_symbol);
207+
} else if (lsmode == 1) {
208+
printf("%#10x ", dirent.stat.private_5);
206209
if (dirent.stat.private_5 % 0x200000 == 0)
207-
printf("%#11x %4u GB %04X %7uMB %s %s%s\n",
208-
dirent.stat.private_5, dirent.stat.private_5 / 0x200000, dirent.stat.mode, size, mod_time, dirent.name, end_symbol);
210+
printf("%4u GiB", dirent.stat.private_5 / 0x200000);
209211
else
210-
printf("%#11x %04X %7uMB %s %s%s\n",
211-
dirent.stat.private_5, dirent.stat.mode, size, mod_time, dirent.name, end_symbol);
212+
printf(" ");
213+
214+
printf(" %04X", dirent.stat.mode);
215+
if (size < 1024)
216+
printf("%5u MiB", size);
217+
else
218+
printf("%5u GiB", size / 1024);
219+
220+
if (dirent.stat.attr == 0 && dirent.stat.mode != 0x0000) {
221+
if (sizeInGiB == (int)sizeInGiB)
222+
printf(" %4u GiB", (unsigned int)sizeInGiB);
223+
else
224+
printf(" %7.2f GiB", sizeInGiB);
225+
} else {
226+
printf(" ");
227+
}
228+
printf(" %s %s%s\n", mod_time, dirent.name, end_symbol);
212229
}
213230
}
214231

0 commit comments

Comments
 (0)