Skip to content

Commit a025f02

Browse files
authored
Merge pull request #53 from AKuHAK/8Mb2
8Mb support, rename support for partitions, improved listing
2 parents ff72a4f + 2d8b89a commit a025f02

2 files changed

Lines changed: 57 additions & 18 deletions

File tree

src/hl.c

Lines changed: 29 additions & 7 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,12 +201,32 @@ 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)
206-
printf("%#8x %04X %7uMB %s %s%s\n",
207-
dirent.stat.private_5, dirent.stat.mode, size, mod_time, dirent.name, end_symbol);
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);
209+
if (dirent.stat.private_5 % 0x200000 == 0)
210+
printf("%4u GiB", dirent.stat.private_5 / 0x200000);
211+
else
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);
229+
}
208230
}
209231

210232
result = iomanX_close(dh);

src/shell.c

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,11 @@ static int do_mkpfs(context_t *ctx, int argc, char *argv[])
246246
static int do_mkpart(context_t *ctx, int arg, char *argv[])
247247
{
248248

249-
static char *sizesString[9] = {
249+
static char *sizesString[13] = {
250+
"8M",
251+
"16M",
252+
"32M",
253+
"64M",
250254
"128M",
251255
"256M",
252256
"512M",
@@ -255,9 +259,14 @@ static int do_mkpart(context_t *ctx, int arg, char *argv[])
255259
"4G",
256260
"8G",
257261
"16G",
258-
"32G"};
262+
"32G",
263+
};
259264

260-
static unsigned int sizesMB[9] = {
265+
static unsigned int sizesMB[13] = {
266+
8,
267+
16,
268+
32,
269+
64,
261270
128,
262271
256,
263272
512,
@@ -266,7 +275,8 @@ static int do_mkpart(context_t *ctx, int arg, char *argv[])
266275
4096,
267276
8192,
268277
16384,
269-
32768};
278+
32768,
279+
};
270280

271281
static char *fsType[7] = {
272282
"MBR",
@@ -275,7 +285,8 @@ static int do_mkpart(context_t *ctx, int arg, char *argv[])
275285
"REISER",
276286
"PFS",
277287
"CFS",
278-
"HDL"};
288+
"HDL",
289+
};
279290

280291
unsigned int size_in_mb = 0;
281292

@@ -580,11 +591,16 @@ static int do_rm(context_t *ctx, int argc, char *argv[])
580591
static int do_rename(context_t *ctx, int argc, char *argv[])
581592
{
582593
char tmp[256];
583-
strcpy(tmp, "pfs0:");
584-
strcat(tmp, ctx->path);
585-
if (tmp[strlen(tmp) - 1] != '/')
586-
strcat(tmp, "/");
594+
if (!ctx->mount)
595+
strcpy(tmp, "hdd0:");
596+
else {
597+
strcpy(tmp, "pfs0:");
598+
strcat(tmp, ctx->path);
599+
if (tmp[strlen(tmp) - 1] != '/')
600+
strcat(tmp, "/");
601+
}
587602
strcat(tmp, argv[1]);
603+
tmp[sizeof(tmp) - 1] = '\0'; // Ensure null-termination
588604
int result = iomanX_rename(tmp, argv[2]);
589605
if (result < 0)
590606
fprintf(stderr, "(!) %s: %s.\n", tmp, strerror(-result));
@@ -615,7 +631,8 @@ static int do_help(context_t *ctx, int argc, char *argv[])
615631
"\tOnly fs type PFS will format partition, other partitions should be formatted by another utilities;\n"
616632
"mount <part_name> - mount a partition;\n"
617633
"umount - un-mount a partition;\n"
618-
"ls [-l] - no mount: list partitions; mount: list files/dirs;\n"
634+
"ls [-l] - no mount: list partitions; mount: list files/dirs; -l: verbose list;\n"
635+
"rename <curr_name> <new_name> - no mount: rename partition; mount: rename a file/dir.\n"
619636
"mkdir <dir_name> - create a new directory;\n"
620637
"rmdir <dir_name> - delete an existing directory;\n"
621638
"pwd - print current PS2 HDD directory;\n"
@@ -663,7 +680,7 @@ static int exec(void *data, int argc, char *argv[])
663680
{"put", 1, need_device + need_mount, &do_put},
664681
{"rm", 1, need_device + need_mount, &do_rm},
665682
{"rmpart", 1, need_device, &do_rmpart},
666-
{"rename", 2, need_device + need_mount, &do_rename},
683+
{"rename", 2, need_device, &do_rename},
667684
{"help", 0, no_req, &do_help},
668685
};
669686
static const size_t CMD_COUNT = sizeof(CMD) / sizeof(CMD[0]);

0 commit comments

Comments
 (0)