Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions src/hl.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,13 @@ int lspart(int lsmode)
int result;
iox_dirent_t dirent;
if (lsmode == 1)
printf("Start (sector) Code Size Timestamp Name\n");
printf("Start (sector) Code Slice Size Timestamp Name\n");
while ((result = iomanX_dread(dh, &dirent)) && result != -1) {

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

if (dirent.stat.mode == 0x0000) /* empty partition */
end_symbol[0] = '%';
Expand All @@ -199,12 +201,32 @@ int lspart(int lsmode)
sprintf(mod_time, "%04d-%02d-%02d %02d:%02d",
mtime->year, mtime->month, mtime->day,
mtime->hour, mtime->min);
if (lsmode == 0)
printf("%s%s\n",
dirent.name, end_symbol);
else if (lsmode == 1)
printf("%#8x %04X %7uMB %s %s%s\n",
dirent.stat.private_5, dirent.stat.mode, size, mod_time, dirent.name, end_symbol);
if (lsmode == 0) {
if (dirent.stat.attr == 0 && dirent.stat.mode != 0x0000)
printf("%7.2f GiB %s%s\n", sizeInGiB, dirent.name, end_symbol);
} else if (lsmode == 1) {
printf("%#10x ", dirent.stat.private_5);
if (dirent.stat.private_5 % 0x200000 == 0)
printf("%4u GiB", dirent.stat.private_5 / 0x200000);
else
printf(" ");

printf(" %04X", dirent.stat.mode);
if (size < 1024)
printf("%5u MiB", size);
else
printf("%5u GiB", size / 1024);

if (dirent.stat.attr == 0 && dirent.stat.mode != 0x0000) {
if (sizeInGiB == (int)sizeInGiB)
printf(" %4u GiB", (unsigned int)sizeInGiB);
else
printf(" %7.2f GiB", sizeInGiB);
} else {
printf(" ");
}
printf(" %s %s%s\n", mod_time, dirent.name, end_symbol);
}
}

result = iomanX_close(dh);
Expand Down
39 changes: 28 additions & 11 deletions src/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,11 @@ static int do_mkpfs(context_t *ctx, int argc, char *argv[])
static int do_mkpart(context_t *ctx, int arg, char *argv[])
{

static char *sizesString[9] = {
static char *sizesString[13] = {
"8M",
"16M",
"32M",
"64M",
"128M",
"256M",
"512M",
Expand All @@ -255,9 +259,14 @@ static int do_mkpart(context_t *ctx, int arg, char *argv[])
"4G",
"8G",
"16G",
"32G"};
"32G",
};

static unsigned int sizesMB[9] = {
static unsigned int sizesMB[13] = {
8,
16,
32,
64,
128,
256,
512,
Expand All @@ -266,7 +275,8 @@ static int do_mkpart(context_t *ctx, int arg, char *argv[])
4096,
8192,
16384,
32768};
32768,
};

static char *fsType[7] = {
"MBR",
Expand All @@ -275,7 +285,8 @@ static int do_mkpart(context_t *ctx, int arg, char *argv[])
"REISER",
"PFS",
"CFS",
"HDL"};
"HDL",
};

unsigned int size_in_mb = 0;

Expand Down Expand Up @@ -580,11 +591,16 @@ static int do_rm(context_t *ctx, int argc, char *argv[])
static int do_rename(context_t *ctx, int argc, char *argv[])
{
char tmp[256];
strcpy(tmp, "pfs0:");
strcat(tmp, ctx->path);
if (tmp[strlen(tmp) - 1] != '/')
strcat(tmp, "/");
if (!ctx->mount)
strcpy(tmp, "hdd0:");
else {
strcpy(tmp, "pfs0:");
strcat(tmp, ctx->path);
if (tmp[strlen(tmp) - 1] != '/')
strcat(tmp, "/");
}
strcat(tmp, argv[1]);
tmp[sizeof(tmp) - 1] = '\0'; // Ensure null-termination
int result = iomanX_rename(tmp, argv[2]);
if (result < 0)
fprintf(stderr, "(!) %s: %s.\n", tmp, strerror(-result));
Expand Down Expand Up @@ -615,7 +631,8 @@ static int do_help(context_t *ctx, int argc, char *argv[])
"\tOnly fs type PFS will format partition, other partitions should be formatted by another utilities;\n"
"mount <part_name> - mount a partition;\n"
"umount - un-mount a partition;\n"
"ls [-l] - no mount: list partitions; mount: list files/dirs;\n"
"ls [-l] - no mount: list partitions; mount: list files/dirs; -l: verbose list;\n"
"rename <curr_name> <new_name> - no mount: rename partition; mount: rename a file/dir.\n"
"mkdir <dir_name> - create a new directory;\n"
"rmdir <dir_name> - delete an existing directory;\n"
"pwd - print current PS2 HDD directory;\n"
Expand Down Expand Up @@ -663,7 +680,7 @@ static int exec(void *data, int argc, char *argv[])
{"put", 1, need_device + need_mount, &do_put},
{"rm", 1, need_device + need_mount, &do_rm},
{"rmpart", 1, need_device, &do_rmpart},
{"rename", 2, need_device + need_mount, &do_rename},
{"rename", 2, need_device, &do_rename},
{"help", 0, no_req, &do_help},
};
static const size_t CMD_COUNT = sizeof(CMD) / sizeof(CMD[0]);
Expand Down
Loading