int main(int argc, char *argv[]) { int rc; int cmd; int done = 0; // Check arguments if (argc == 1) { devname = "/dev/hd0"; } else if (argc == 2) { devname = argv[1]; } else { printf("usage: fdisk <device>\n"); return 1; } // Open device hdev = open(devname, O_RDWR | O_BINARY); if (hdev < 0) { printf("%s: error %d opening device\n", devname, errno); return 1; } // Get disk geometry rc = ioctl(hdev, IOCTL_GETGEOMETRY, &geom , sizeof(struct geometry)); if (rc < 0) { printf("%s: error %d determining disk geometry\n", devname, errno); close(hdev); return 1; } // Read master boot record rc = read_mbr(); if (rc < 0 && errno != EINVAL) { printf("%s: error %d reading master boot record\n", devname, errno); close(hdev); return 1; } // Ask to create new master boot record if the existing is invalid if (rc < 0 && errno == EINVAL) { printf("%s: invalid master boot record\n", devname); if (ask("create new master boot record (y/n)? ", "yn") == 'y') { memcpy(&mbr, bootrecord, sizeof(mbr)); } } // Read commands printf("(a)dd (b)oot (c)ommit (d)elete (l)ist (m)br (h)elp e(x)it\n"); while (!done) { cmd = ask("fdisk> ", "abcdlmhx?"); switch (cmd) { case 'a': add_partition(); break; case 'b': set_boot_part(); break; case 'c': commit_mbr(); break; case 'd': delete_partition(); break; case 'l': list_partitions(); break; case 'm': clear_mbr(); break; case 'h': case '?': help(); break; case 'x': done = 1; break; } } // Close device close(hdev); return 0; }
void list_mountable_devices(char *device, list_t *list) { int i,n = 0; iox_stat_t stat; char mc_path[6] = "mc0:"; char mass_device[8] = "mass0:"; add_reg_entry(list->entries,"..",n++); if (!strcmp(device,"mc")) { for (i = 0; i < 2; i++) { mc_path[2] = '0' + i; if(!fileXioGetStat(mc_path,&stat)) { add_dir_entry(list->entries,mc_path,n++); } } list->num = n; } if (!strcmp(device,"mass")) { for(i=0; i < 10; i++) { mass_device[4] = '0'+i; if(!(fileXioGetStat(mass_device, &stat) < 0)) { add_dir_entry(list->entries,mass_device,n++); } } // Older versions of the module only support "mass:" if (!n) { if (!(fileXioGetStat("mass:",&stat) < 0)) { add_dir_entry(list->entries,"mass:",n++); } } list->num = n; } if (!strcmp(device,"hdd")) { // Checking for "hdd0:" doesn't work, maybe since it's a block device //if (!(fileXioGetStat("hdd0:",&stat) < 0)) { list_partitions(list); } } if (!strcmp(device,"cdfs")) { //if(!(fileXioGetStat("cdfs:",&stat) < 0)) { add_dir_entry(list->entries,"cdfs:", n++); } CDVD_FlushCache(); refresh_cdfs(); list->num = n; } else { CDVD_Stop(); } }