sdutil Add list_part_dos command
All checks were successful
Build documentation / build-and-deploy (push) Successful in 3m41s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 3m41s
This commit is contained in:
@@ -8,8 +8,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <system.h>
|
#include <system.h>
|
||||||
|
|
||||||
#define COMMAND_MAX 32
|
|
||||||
|
|
||||||
struct dos_pte {
|
struct dos_pte {
|
||||||
uint8_t drive_attrs;
|
uint8_t drive_attrs;
|
||||||
uint8_t chs_start_addr[3];
|
uint8_t chs_start_addr[3];
|
||||||
@@ -98,11 +96,37 @@ static void start_part_dos (void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void list_part_dos (const char* dev_name) {
|
||||||
|
struct dos_mbr mbr;
|
||||||
|
memset (&mbr, 0, sizeof (mbr));
|
||||||
|
|
||||||
|
size_t sector = 0;
|
||||||
|
size_t sector_count = 1;
|
||||||
|
int r = device_do (dev_name, XDRV_READ, §or, §or_count, &mbr, NULL);
|
||||||
|
mprintf ("Finished reading. Result: %s (%d)\n", str_status[r < 0 ? -r : r], r);
|
||||||
|
|
||||||
|
if (!(mbr.valid_sign[0] == 0x55 && mbr.valid_sign[1] == 0xAA)) {
|
||||||
|
mprintf ("ERROR invalid Master Boot Record!\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* clang-format off */
|
||||||
|
mprintf ("\n\n-------------------------------------------------------\n");
|
||||||
|
mprintf ("Summary (%s):\n", dev_name);
|
||||||
|
mprintf ("Partition 0: start LBA = %u, sector count = %zu\n",mbr.ptes[0].start_lba, mbr.ptes[0].sector_count);
|
||||||
|
mprintf ("Partition 1: start LBA = %u, sector count = %zu\n",mbr.ptes[1].start_lba, mbr.ptes[1].sector_count);
|
||||||
|
mprintf ("Partition 2: start LBA = %u, sector count = %zu\n",mbr.ptes[2].start_lba, mbr.ptes[2].sector_count);
|
||||||
|
mprintf ("Partition 3: start LBA = %u, sector count = %zu\n",mbr.ptes[3].start_lba, mbr.ptes[3].sector_count);
|
||||||
|
/* clang-format on */
|
||||||
|
}
|
||||||
|
|
||||||
void app_main (void) {
|
void app_main (void) {
|
||||||
libprocess_self_init ();
|
libprocess_self_init ();
|
||||||
|
|
||||||
char commandbuf[COMMAND_MAX];
|
char commandbuf[32];
|
||||||
commandbuf[0] = '\0';
|
commandbuf[0] = '\0';
|
||||||
|
char devnamebuf[64];
|
||||||
|
devnamebuf[0] = '\0';
|
||||||
|
|
||||||
if (env_get (process_get_pgid (), "C", (void*)commandbuf, sizeof (commandbuf)) != ST_OK) {
|
if (env_get (process_get_pgid (), "C", (void*)commandbuf, sizeof (commandbuf)) != ST_OK) {
|
||||||
mprintf ("ERROR C=???. No command provided\n");
|
mprintf ("ERROR C=???. No command provided\n");
|
||||||
@@ -111,5 +135,14 @@ void app_main (void) {
|
|||||||
|
|
||||||
if (strcmp (commandbuf, "part_dos") == 0) {
|
if (strcmp (commandbuf, "part_dos") == 0) {
|
||||||
start_part_dos ();
|
start_part_dos ();
|
||||||
|
} else if (strcmp (commandbuf, "list_part_dos") == 0) {
|
||||||
|
if (env_get (process_get_pgid (), "dev", (void*)devnamebuf, sizeof (devnamebuf)) != ST_OK) {
|
||||||
|
mprintf ("ERROR dev=???. No device name provided for list_part_dos\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
list_part_dos (devnamebuf);
|
||||||
|
} else {
|
||||||
|
mprintf ("ERROR C=%s. Unknown command\n", commandbuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user