Changeset View
Changeset View
Standalone View
Standalone View
sbin/fdisk/fdisk.c
Show First 20 Lines • Show All 443 Lines • ▼ Show 20 Lines | if (f_flag) { | ||||
} | } | ||||
} | } | ||||
} | } | ||||
exit(0); | exit(0); | ||||
} | } | ||||
static void | static void | ||||
usage() | usage(void) | ||||
{ | { | ||||
fprintf(stderr, "%s%s", | fprintf(stderr, "%s%s", | ||||
"usage: fdisk [-BIaipqstu] [-b bootcode] [-1234] [disk]\n", | "usage: fdisk [-BIaipqstu] [-b bootcode] [-1234] [disk]\n", | ||||
" fdisk -f configfile [-itv] [disk]\n"); | " fdisk -f configfile [-itv] [disk]\n"); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
static void | static void | ||||
▲ Show 20 Lines • Show All 144 Lines • ▼ Show 20 Lines | if (ok("Explicitly specify beg/end address ?")) | ||||
dos(partp); | dos(partp); | ||||
print_part(partp); | print_part(partp); | ||||
} while (!ok("Are we happy with this entry?")); | } while (!ok("Are we happy with this entry?")); | ||||
} | } | ||||
} | } | ||||
static void | static void | ||||
print_params() | print_params(void) | ||||
{ | { | ||||
printf("parameters extracted from in-core disklabel are:\n"); | printf("parameters extracted from in-core disklabel are:\n"); | ||||
printf("cylinders=%d heads=%d sectors/track=%d (%d blks/cyl)\n\n" | printf("cylinders=%d heads=%d sectors/track=%d (%d blks/cyl)\n\n" | ||||
,cyls,heads,sectors,cylsecs); | ,cyls,heads,sectors,cylsecs); | ||||
if (dos_cyls > 1023 || dos_heads > 255 || dos_sectors > 63) | if (dos_cyls > 1023 || dos_heads > 255 || dos_sectors > 63) | ||||
printf("Figures below won't work with BIOS for partitions not in cyl 1\n"); | printf("Figures below won't work with BIOS for partitions not in cyl 1\n"); | ||||
printf("parameters to be used for BIOS calculations are:\n"); | printf("parameters to be used for BIOS calculations are:\n"); | ||||
printf("cylinders=%d heads=%d sectors/track=%d (%d blks/cyl)\n\n" | printf("cylinders=%d heads=%d sectors/track=%d (%d blks/cyl)\n\n" | ||||
Show All 34 Lines | setactive: | ||||
} while (!ok("Are you happy with this choice")); | } while (!ok("Are you happy with this choice")); | ||||
for (i = 0; i < NDOSPART; i++) | for (i = 0; i < NDOSPART; i++) | ||||
partp[i].dp_flag = 0; | partp[i].dp_flag = 0; | ||||
if (active > 0 && active <= NDOSPART) | if (active > 0 && active <= NDOSPART) | ||||
partp[active-1].dp_flag = ACTIVE; | partp[active-1].dp_flag = ACTIVE; | ||||
} | } | ||||
static void | static void | ||||
change_code() | change_code(void) | ||||
{ | { | ||||
if (ok("Do you want to change the boot code?")) | if (ok("Do you want to change the boot code?")) | ||||
init_boot(); | init_boot(); | ||||
} | } | ||||
void | void | ||||
get_params_to_use() | get_params_to_use(void) | ||||
{ | { | ||||
int tmp; | int tmp; | ||||
print_params(); | print_params(); | ||||
if (ok("Do you want to change our idea of what BIOS thinks ?")) | if (ok("Do you want to change our idea of what BIOS thinks ?")) | ||||
{ | { | ||||
do | do | ||||
{ | { | ||||
Decimal("BIOS's idea of #cylinders", dos_cyls, tmp, 0); | Decimal("BIOS's idea of #cylinders", dos_cyls, tmp, 0); | ||||
▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | write_disk(off_t sector, void *buf) | ||||
if (geom_class_available("PART") != 0) | if (geom_class_available("PART") != 0) | ||||
warnx("Failed to write MBR. Try to use gpart(8)."); | warnx("Failed to write MBR. Try to use gpart(8)."); | ||||
else | else | ||||
warnx("Failed to write sector zero"); | warnx("Failed to write sector zero"); | ||||
return(EINVAL); | return(EINVAL); | ||||
} | } | ||||
static int | static int | ||||
get_params() | get_params(void) | ||||
{ | { | ||||
int error; | int error; | ||||
u_int u; | u_int u; | ||||
off_t o; | off_t o; | ||||
error = ioctl(fd, DIOCGFWSECTORS, &u); | error = ioctl(fd, DIOCGFWSECTORS, &u); | ||||
if (error == 0) | if (error == 0) | ||||
sectors = dos_sectors = u; | sectors = dos_sectors = u; | ||||
Show All 21 Lines | get_params(void) | ||||
else | else | ||||
disksecs = NO_DISK_SECTORS; | disksecs = NO_DISK_SECTORS; | ||||
cyls = dos_cyls = o / (u * dos_heads * dos_sectors); | cyls = dos_cyls = o / (u * dos_heads * dos_sectors); | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
read_s0() | read_s0(void) | ||||
{ | { | ||||
int i; | int i; | ||||
mboot.bootinst_size = secsize; | mboot.bootinst_size = secsize; | ||||
if (mboot.bootinst != NULL) | if (mboot.bootinst != NULL) | ||||
free(mboot.bootinst); | free(mboot.bootinst); | ||||
if ((mboot.bootinst = malloc(mboot.bootinst_size)) == NULL) { | if ((mboot.bootinst = malloc(mboot.bootinst_size)) == NULL) { | ||||
warnx("unable to allocate buffer to read fdisk " | warnx("unable to allocate buffer to read fdisk " | ||||
Show All 12 Lines | read_s0(void) | ||||
for (i = 0; i < NDOSPART; i++) | for (i = 0; i < NDOSPART; i++) | ||||
dos_partition_dec( | dos_partition_dec( | ||||
&mboot.bootinst[DOSPARTOFF + i * DOSPARTSIZE], | &mboot.bootinst[DOSPARTOFF + i * DOSPARTSIZE], | ||||
&mboot.parts[i]); | &mboot.parts[i]); | ||||
return 0; | return 0; | ||||
} | } | ||||
static int | static int | ||||
write_s0() | write_s0(void) | ||||
{ | { | ||||
int sector, i; | int sector, i; | ||||
if (iotest) { | if (iotest) { | ||||
print_s0(); | print_s0(); | ||||
return 0; | return 0; | ||||
} | } | ||||
for(i = 0; i < NDOSPART; i++) | for(i = 0; i < NDOSPART; i++) | ||||
▲ Show 20 Lines • Show All 620 Lines • Show Last 20 Lines |