diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2003-01-04 11:56:06 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2003-01-04 11:56:06 +0000 |
commit | 4dcc2ddfccc364826fb6f485a28625df34464b46 (patch) | |
tree | 59fe6c1386b57674696abb53f26b138c9d26cd8f | |
parent | 2c24bb80f9f2e226f212c48d600bdf64956fc972 (diff) | |
download | busybox-w32-4dcc2ddfccc364826fb6f485a28625df34464b46.tar.gz busybox-w32-4dcc2ddfccc364826fb6f485a28625df34464b46.tar.bz2 busybox-w32-4dcc2ddfccc364826fb6f485a28625df34464b46.zip |
fdisk writable feature, allows compilation of a small fdisk that can
only read partition table, by Vladimir N. Oleynik
-rw-r--r-- | util-linux/Config.in | 18 | ||||
-rw-r--r-- | util-linux/fdisk.c | 422 |
2 files changed, 254 insertions, 186 deletions
diff --git a/util-linux/Config.in b/util-linux/Config.in index 0c84c77af..2494e6e1c 100644 --- a/util-linux/Config.in +++ b/util-linux/Config.in | |||
@@ -44,38 +44,46 @@ config CONFIG_FDISK | |||
44 | help | 44 | help |
45 | Please submit a patch to add help text for this item. | 45 | Please submit a patch to add help text for this item. |
46 | 46 | ||
47 | config CONFIG_FEATURE_FDISK_WRITABLE | ||
48 | bool " Write support" | ||
49 | default y | ||
50 | depends on CONFIG_FDISK | ||
51 | help | ||
52 | Allow changes to be written to disk, without this you | ||
53 | will only be able to view the partition table. | ||
54 | |||
47 | config CONFIG_FEATURE_AIX_LABEL | 55 | config CONFIG_FEATURE_AIX_LABEL |
48 | bool " Support AIX disklabels" | 56 | bool " Support AIX disklabels" |
49 | default n | 57 | default n |
50 | depends on CONFIG_FDISK | 58 | depends on CONFIG_FDISK && CONFIG_FEATURE_FDISK_WRITABLE |
51 | help | 59 | help |
52 | Please submit a patch to add help text for this item. | 60 | Please submit a patch to add help text for this item. |
53 | 61 | ||
54 | config CONFIG_FEATURE_SGI_LABEL | 62 | config CONFIG_FEATURE_SGI_LABEL |
55 | bool " Support SGI disklabels" | 63 | bool " Support SGI disklabels" |
56 | default n | 64 | default n |
57 | depends on CONFIG_FDISK | 65 | depends on CONFIG_FDISK && CONFIG_FEATURE_FDISK_WRITABLE |
58 | help | 66 | help |
59 | Please submit a patch to add help text for this item. | 67 | Please submit a patch to add help text for this item. |
60 | 68 | ||
61 | config CONFIG_FEATURE_SUN_LABEL | 69 | config CONFIG_FEATURE_SUN_LABEL |
62 | bool " Support SUN disklabels" | 70 | bool " Support SUN disklabels" |
63 | default n | 71 | default n |
64 | depends on CONFIG_FDISK | 72 | depends on CONFIG_FDISK && CONFIG_FEATURE_FDISK_WRITABLE |
65 | help | 73 | help |
66 | Please submit a patch to add help text for this item. | 74 | Please submit a patch to add help text for this item. |
67 | 75 | ||
68 | config CONFIG_FEATURE_OSF_LABEL | 76 | config CONFIG_FEATURE_OSF_LABEL |
69 | bool " Support BSD disklabels" | 77 | bool " Support BSD disklabels" |
70 | default n | 78 | default n |
71 | depends on CONFIG_FDISK | 79 | depends on CONFIG_FDISK && CONFIG_FEATURE_FDISK_WRITABLE |
72 | help | 80 | help |
73 | Please submit a patch to add help text for this item. | 81 | Please submit a patch to add help text for this item. |
74 | 82 | ||
75 | config CONFIG_FEATURE_FDISK_ADVANCED | 83 | config CONFIG_FEATURE_FDISK_ADVANCED |
76 | bool " Support expert mode" | 84 | bool " Support expert mode" |
77 | default n | 85 | default n |
78 | depends on CONFIG_FDISK | 86 | depends on CONFIG_FDISK && CONFIG_FEATURE_FDISK_WRITABLE |
79 | help | 87 | help |
80 | Please submit a patch to add help text for this item. | 88 | Please submit a patch to add help text for this item. |
81 | 89 | ||
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c index 916ab1fd8..696e64c7d 100644 --- a/util-linux/fdisk.c +++ b/util-linux/fdisk.c | |||
@@ -47,7 +47,7 @@ | |||
47 | #include <stdint.h> /* for uint32_t, uint16_t, uint8_t, int16_t, etc */ | 47 | #include <stdint.h> /* for uint32_t, uint16_t, uint8_t, int16_t, etc */ |
48 | 48 | ||
49 | /* Copied from linux/major.h */ | 49 | /* Copied from linux/major.h */ |
50 | #define FLOPPY_MAJOR 2 | 50 | #define FLOPPY_MAJOR 2 |
51 | 51 | ||
52 | #include <sys/utsname.h> | 52 | #include <sys/utsname.h> |
53 | 53 | ||
@@ -128,7 +128,6 @@ static char MBRbuffer[MAX_SECTOR_SIZE]; | |||
128 | static int sun_label; /* looking at sun disklabel */ | 128 | static int sun_label; /* looking at sun disklabel */ |
129 | #else | 129 | #else |
130 | #define sun_label 0 | 130 | #define sun_label 0 |
131 | #define check_sun_label() 0 | ||
132 | #endif | 131 | #endif |
133 | #ifdef CONFIG_FEATURE_SGI_LABEL | 132 | #ifdef CONFIG_FEATURE_SGI_LABEL |
134 | static int sgi_label; /* looking at sgi disklabel */ | 133 | static int sgi_label; /* looking at sgi disklabel */ |
@@ -152,7 +151,6 @@ static int possibly_osf_label; | |||
152 | static uint heads, sectors, cylinders; | 151 | static uint heads, sectors, cylinders; |
153 | static void update_units(void); | 152 | static void update_units(void); |
154 | 153 | ||
155 | static const char *partition_type(unsigned char type); | ||
156 | 154 | ||
157 | /* | 155 | /* |
158 | * return partition name - uses static storage unless buf is supplied | 156 | * return partition name - uses static storage unless buf is supplied |
@@ -212,27 +210,24 @@ enum failure { | |||
212 | 210 | ||
213 | enum action {fdisk, require, try_only, create_empty_dos, create_empty_sun}; | 211 | enum action {fdisk, require, try_only, create_empty_dos, create_empty_sun}; |
214 | 212 | ||
215 | struct geom { | ||
216 | unsigned int heads; | ||
217 | unsigned int sectors; | ||
218 | unsigned int cylinders; | ||
219 | }; | ||
220 | |||
221 | static const char *disk_device; | 213 | static const char *disk_device; |
222 | static char *line_ptr; | ||
223 | static int fd; /* the disk */ | 214 | static int fd; /* the disk */ |
224 | static int partitions = 4; /* maximum partition + 1 */ | 215 | static int partitions = 4; /* maximum partition + 1 */ |
225 | static uint display_in_cyl_units = 1; | 216 | static uint display_in_cyl_units = 1; |
226 | static uint units_per_sector = 1; | 217 | static uint units_per_sector = 1; |
218 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
219 | static char *line_ptr; | ||
227 | static void change_units(void); | 220 | static void change_units(void); |
228 | static void fdisk_fatal(enum failure why) __attribute__ ((noreturn)); | 221 | static void reread_partition_table(int leave); |
229 | static void get_geometry(struct geom *); | 222 | static void delete_partition(int i); |
230 | static int get_boot(enum action what); | ||
231 | static int get_partition(int warn, int max); | 223 | static int get_partition(int warn, int max); |
232 | static void list_types(const struct systypes *sys); | 224 | static void list_types(const struct systypes *sys); |
233 | static void reread_partition_table(int leave); | ||
234 | static int valid_part_table_flag(const unsigned char *b); | ||
235 | static uint read_int(uint low, uint dflt, uint high, uint base, char *mesg); | 225 | static uint read_int(uint low, uint dflt, uint high, uint base, char *mesg); |
226 | #endif | ||
227 | static const char *partition_type(unsigned char type); | ||
228 | static void fdisk_fatal(enum failure why) __attribute__ ((noreturn)); | ||
229 | static void get_geometry(void); | ||
230 | static int get_boot(enum action what); | ||
236 | 231 | ||
237 | #define PLURAL 0 | 232 | #define PLURAL 0 |
238 | #define SINGULAR 1 | 233 | #define SINGULAR 1 |
@@ -276,13 +271,15 @@ static unsigned int get_nr_sects(const struct partition *p); | |||
276 | static struct pte { | 271 | static struct pte { |
277 | struct partition *part_table; /* points into sectorbuffer */ | 272 | struct partition *part_table; /* points into sectorbuffer */ |
278 | struct partition *ext_pointer; /* points into sectorbuffer */ | 273 | struct partition *ext_pointer; /* points into sectorbuffer */ |
274 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
279 | char changed; /* boolean */ | 275 | char changed; /* boolean */ |
276 | #endif | ||
280 | uint offset; /* disk sector number */ | 277 | uint offset; /* disk sector number */ |
281 | char *sectorbuffer; /* disk sector contents */ | 278 | char *sectorbuffer; /* disk sector contents */ |
282 | } ptes[MAXIMUM_PARTS]; | 279 | } ptes[MAXIMUM_PARTS]; |
283 | 280 | ||
284 | static char line_buffer[LINE_LENGTH]; | ||
285 | 281 | ||
282 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
286 | static void | 283 | static void |
287 | set_all_unchanged(void) { | 284 | set_all_unchanged(void) { |
288 | int i; | 285 | int i; |
@@ -295,7 +292,7 @@ static void | |||
295 | set_changed(int i) { | 292 | set_changed(int i) { |
296 | ptes[i].changed = 1; | 293 | ptes[i].changed = 1; |
297 | } | 294 | } |
298 | 295 | #endif /* CONFIG_FEATURE_FDISK_WRITABLE */ | |
299 | 296 | ||
300 | #if defined(CONFIG_FEATURE_SGI_LABEL) || defined(CONFIG_FEATURE_OSF_LABEL) | 297 | #if defined(CONFIG_FEATURE_SGI_LABEL) || defined(CONFIG_FEATURE_OSF_LABEL) |
301 | static struct partition * | 298 | static struct partition * |
@@ -312,6 +309,14 @@ str_units(int n) { /* n==1: use singular */ | |||
312 | return display_in_cyl_units ? _("cylinders") : _("sectors"); | 309 | return display_in_cyl_units ? _("cylinders") : _("sectors"); |
313 | } | 310 | } |
314 | 311 | ||
312 | static int | ||
313 | valid_part_table_flag(const unsigned char *b) { | ||
314 | return (b[510] == 0x55 && b[511] == 0xaa); | ||
315 | } | ||
316 | |||
317 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
318 | static char line_buffer[LINE_LENGTH]; | ||
319 | |||
315 | /* read line; return 0 or first char */ | 320 | /* read line; return 0 or first char */ |
316 | static int | 321 | static int |
317 | read_line(void) | 322 | read_line(void) |
@@ -324,7 +329,6 @@ read_line(void) | |||
324 | if (feof(stdin)) | 329 | if (feof(stdin)) |
325 | got_eof++; /* user typed ^D ? */ | 330 | got_eof++; /* user typed ^D ? */ |
326 | if (got_eof >= 3) { | 331 | if (got_eof >= 3) { |
327 | fflush(stdout); | ||
328 | fprintf(stderr, _("\ngot EOF thrice - exiting..\n")); | 332 | fprintf(stderr, _("\ngot EOF thrice - exiting..\n")); |
329 | exit(1); | 333 | exit(1); |
330 | } | 334 | } |
@@ -375,6 +379,7 @@ read_hex(const struct systypes *sys) | |||
375 | } | 379 | } |
376 | } | 380 | } |
377 | } | 381 | } |
382 | #endif /* CONFIG_FEATURE_FDISK_WRITABLE */ | ||
378 | 383 | ||
379 | #ifdef CONFIG_FEATURE_AIX_LABEL | 384 | #ifdef CONFIG_FEATURE_AIX_LABEL |
380 | /* | 385 | /* |
@@ -1194,60 +1199,59 @@ static void | |||
1194 | xbsd_print_disklabel (int show_all) { | 1199 | xbsd_print_disklabel (int show_all) { |
1195 | struct xbsd_disklabel *lp = &xbsd_dlabel; | 1200 | struct xbsd_disklabel *lp = &xbsd_dlabel; |
1196 | struct xbsd_partition *pp; | 1201 | struct xbsd_partition *pp; |
1197 | FILE *f = stdout; | ||
1198 | int i, j; | 1202 | int i, j; |
1199 | 1203 | ||
1200 | if (show_all) { | 1204 | if (show_all) { |
1201 | #if defined (__alpha__) | 1205 | #if defined (__alpha__) |
1202 | fprintf(f, "# %s:\n", disk_device); | 1206 | printf("# %s:\n", disk_device); |
1203 | #else | 1207 | #else |
1204 | fprintf(f, "# %s:\n", partname(disk_device, xbsd_part_index+1, 0)); | 1208 | printf("# %s:\n", partname(disk_device, xbsd_part_index+1, 0)); |
1205 | #endif | 1209 | #endif |
1206 | if ((unsigned) lp->d_type < BSD_DKMAXTYPES) | 1210 | if ((unsigned) lp->d_type < BSD_DKMAXTYPES) |
1207 | fprintf(f, _("type: %s\n"), xbsd_dktypenames[lp->d_type]); | 1211 | printf(_("type: %s\n"), xbsd_dktypenames[lp->d_type]); |
1208 | else | 1212 | else |
1209 | fprintf(f, _("type: %d\n"), lp->d_type); | 1213 | printf(_("type: %d\n"), lp->d_type); |
1210 | fprintf(f, _("disk: %.*s\n"), (int) sizeof(lp->d_typename), lp->d_typename); | 1214 | printf(_("disk: %.*s\n"), (int) sizeof(lp->d_typename), lp->d_typename); |
1211 | fprintf(f, _("label: %.*s\n"), (int) sizeof(lp->d_packname), lp->d_packname); | 1215 | printf(_("label: %.*s\n"), (int) sizeof(lp->d_packname), lp->d_packname); |
1212 | fprintf(f, _("flags:")); | 1216 | printf(_("flags:")); |
1213 | if (lp->d_flags & BSD_D_REMOVABLE) | 1217 | if (lp->d_flags & BSD_D_REMOVABLE) |
1214 | fprintf(f, _(" removable")); | 1218 | printf(_(" removable")); |
1215 | if (lp->d_flags & BSD_D_ECC) | 1219 | if (lp->d_flags & BSD_D_ECC) |
1216 | fprintf(f, _(" ecc")); | 1220 | printf(_(" ecc")); |
1217 | if (lp->d_flags & BSD_D_BADSECT) | 1221 | if (lp->d_flags & BSD_D_BADSECT) |
1218 | fprintf(f, _(" badsect")); | 1222 | printf(_(" badsect")); |
1219 | fprintf(f, "\n"); | 1223 | printf("\n"); |
1220 | /* On various machines the fields of *lp are short/int/long */ | 1224 | /* On various machines the fields of *lp are short/int/long */ |
1221 | /* In order to avoid problems, we cast them all to long. */ | 1225 | /* In order to avoid problems, we cast them all to long. */ |
1222 | fprintf(f, _("bytes/sector: %ld\n"), (long) lp->d_secsize); | 1226 | printf(_("bytes/sector: %ld\n"), (long) lp->d_secsize); |
1223 | fprintf(f, _("sectors/track: %ld\n"), (long) lp->d_nsectors); | 1227 | printf(_("sectors/track: %ld\n"), (long) lp->d_nsectors); |
1224 | fprintf(f, _("tracks/cylinder: %ld\n"), (long) lp->d_ntracks); | 1228 | printf(_("tracks/cylinder: %ld\n"), (long) lp->d_ntracks); |
1225 | fprintf(f, _("sectors/cylinder: %ld\n"), (long) lp->d_secpercyl); | 1229 | printf(_("sectors/cylinder: %ld\n"), (long) lp->d_secpercyl); |
1226 | fprintf(f, _("cylinders: %ld\n"), (long) lp->d_ncylinders); | 1230 | printf(_("cylinders: %ld\n"), (long) lp->d_ncylinders); |
1227 | fprintf(f, _("rpm: %d\n"), lp->d_rpm); | 1231 | printf(_("rpm: %d\n"), lp->d_rpm); |
1228 | fprintf(f, _("interleave: %d\n"), lp->d_interleave); | 1232 | printf(_("interleave: %d\n"), lp->d_interleave); |
1229 | fprintf(f, _("trackskew: %d\n"), lp->d_trackskew); | 1233 | printf(_("trackskew: %d\n"), lp->d_trackskew); |
1230 | fprintf(f, _("cylinderskew: %d\n"), lp->d_cylskew); | 1234 | printf(_("cylinderskew: %d\n"), lp->d_cylskew); |
1231 | fprintf(f, _("headswitch: %ld\t\t# milliseconds\n"), | 1235 | printf(_("headswitch: %ld\t\t# milliseconds\n"), |
1232 | (long) lp->d_headswitch); | 1236 | (long) lp->d_headswitch); |
1233 | fprintf(f, _("track-to-track seek: %ld\t# milliseconds\n"), | 1237 | printf(_("track-to-track seek: %ld\t# milliseconds\n"), |
1234 | (long) lp->d_trkseek); | 1238 | (long) lp->d_trkseek); |
1235 | fprintf(f, _("drivedata: ")); | 1239 | printf(_("drivedata: ")); |
1236 | for (i = NDDATA - 1; i >= 0; i--) | 1240 | for (i = NDDATA - 1; i >= 0; i--) |
1237 | if (lp->d_drivedata[i]) | 1241 | if (lp->d_drivedata[i]) |
1238 | break; | 1242 | break; |
1239 | if (i < 0) | 1243 | if (i < 0) |
1240 | i = 0; | 1244 | i = 0; |
1241 | for (j = 0; j <= i; j++) | 1245 | for (j = 0; j <= i; j++) |
1242 | fprintf(f, "%ld ", (long) lp->d_drivedata[j]); | 1246 | printf("%ld ", (long) lp->d_drivedata[j]); |
1243 | } | 1247 | } |
1244 | fprintf (f, _("\n%d partitions:\n"), lp->d_npartitions); | 1248 | printf(_("\n%d partitions:\n"), lp->d_npartitions); |
1245 | fprintf (f, _("# start end size fstype [fsize bsize cpg]\n")); | 1249 | printf(_("# start end size fstype [fsize bsize cpg]\n")); |
1246 | pp = lp->d_partitions; | 1250 | pp = lp->d_partitions; |
1247 | for (i = 0; i < lp->d_npartitions; i++, pp++) { | 1251 | for (i = 0; i < lp->d_npartitions; i++, pp++) { |
1248 | if (pp->p_size) { | 1252 | if (pp->p_size) { |
1249 | if (display_in_cyl_units && lp->d_secpercyl) { | 1253 | if (display_in_cyl_units && lp->d_secpercyl) { |
1250 | fprintf(f, " %c: %8ld%c %8ld%c %8ld%c ", | 1254 | printf(" %c: %8ld%c %8ld%c %8ld%c ", |
1251 | 'a' + i, | 1255 | 'a' + i, |
1252 | (long) pp->p_offset / lp->d_secpercyl + 1, | 1256 | (long) pp->p_offset / lp->d_secpercyl + 1, |
1253 | (pp->p_offset % lp->d_secpercyl) ? '*' : ' ', | 1257 | (pp->p_offset % lp->d_secpercyl) ? '*' : ' ', |
@@ -1257,33 +1261,33 @@ xbsd_print_disklabel (int show_all) { | |||
1257 | (long) pp->p_size / lp->d_secpercyl, | 1261 | (long) pp->p_size / lp->d_secpercyl, |
1258 | (pp->p_size % lp->d_secpercyl) ? '*' : ' '); | 1262 | (pp->p_size % lp->d_secpercyl) ? '*' : ' '); |
1259 | } else { | 1263 | } else { |
1260 | fprintf(f, " %c: %8ld %8ld %8ld ", | 1264 | printf(" %c: %8ld %8ld %8ld ", |
1261 | 'a' + i, | 1265 | 'a' + i, |
1262 | (long) pp->p_offset, | 1266 | (long) pp->p_offset, |
1263 | (long) pp->p_offset + pp->p_size - 1, | 1267 | (long) pp->p_offset + pp->p_size - 1, |
1264 | (long) pp->p_size); | 1268 | (long) pp->p_size); |
1265 | } | 1269 | } |
1266 | if ((unsigned) pp->p_fstype < BSD_FSMAXTYPES) | 1270 | if ((unsigned) pp->p_fstype < BSD_FSMAXTYPES) |
1267 | fprintf(f, "%8.8s", xbsd_fstypes[pp->p_fstype].name); | 1271 | printf("%8.8s", xbsd_fstypes[pp->p_fstype].name); |
1268 | else | 1272 | else |
1269 | fprintf(f, "%8x", pp->p_fstype); | 1273 | printf("%8x", pp->p_fstype); |
1270 | switch (pp->p_fstype) { | 1274 | switch (pp->p_fstype) { |
1271 | case BSD_FS_UNUSED: | 1275 | case BSD_FS_UNUSED: |
1272 | fprintf(f, " %5ld %5ld %5.5s ", | 1276 | printf(" %5ld %5ld %5.5s ", |
1273 | (long) pp->p_fsize, (long) pp->p_fsize * pp->p_frag, ""); | 1277 | (long) pp->p_fsize, (long) pp->p_fsize * pp->p_frag, ""); |
1274 | break; | 1278 | break; |
1275 | 1279 | ||
1276 | case BSD_FS_BSDFFS: | 1280 | case BSD_FS_BSDFFS: |
1277 | fprintf(f, " %5ld %5ld %5d ", | 1281 | printf(" %5ld %5ld %5d ", |
1278 | (long) pp->p_fsize, (long) pp->p_fsize * pp->p_frag, | 1282 | (long) pp->p_fsize, (long) pp->p_fsize * pp->p_frag, |
1279 | pp->p_cpg); | 1283 | pp->p_cpg); |
1280 | break; | 1284 | break; |
1281 | 1285 | ||
1282 | default: | 1286 | default: |
1283 | fprintf(f, "%22.22s", ""); | 1287 | printf("%22.22s", ""); |
1284 | break; | 1288 | break; |
1285 | } | 1289 | } |
1286 | fprintf(f, "\n"); | 1290 | printf("\n"); |
1287 | } | 1291 | } |
1288 | } | 1292 | } |
1289 | } | 1293 | } |
@@ -1550,9 +1554,8 @@ xbsd_dkcksum (struct xbsd_disklabel *lp) { | |||
1550 | static int | 1554 | static int |
1551 | xbsd_initlabel (struct partition *p, struct xbsd_disklabel *d, int pindex) { | 1555 | xbsd_initlabel (struct partition *p, struct xbsd_disklabel *d, int pindex) { |
1552 | struct xbsd_partition *pp; | 1556 | struct xbsd_partition *pp; |
1553 | struct geom g; | ||
1554 | 1557 | ||
1555 | get_geometry (&g); | 1558 | get_geometry (); |
1556 | bzero (d, sizeof (struct xbsd_disklabel)); | 1559 | bzero (d, sizeof (struct xbsd_disklabel)); |
1557 | 1560 | ||
1558 | d -> d_magic = BSD_DISKMAGIC; | 1561 | d -> d_magic = BSD_DISKMAGIC; |
@@ -1572,10 +1575,10 @@ xbsd_initlabel (struct partition *p, struct xbsd_disklabel *d, int pindex) { | |||
1572 | d -> d_flags = 0; | 1575 | d -> d_flags = 0; |
1573 | #endif | 1576 | #endif |
1574 | d -> d_secsize = SECTOR_SIZE; /* bytes/sector */ | 1577 | d -> d_secsize = SECTOR_SIZE; /* bytes/sector */ |
1575 | d -> d_nsectors = g.sectors; /* sectors/track */ | 1578 | d -> d_nsectors = sectors; /* sectors/track */ |
1576 | d -> d_ntracks = g.heads; /* tracks/cylinder (heads) */ | 1579 | d -> d_ntracks = heads; /* tracks/cylinder (heads) */ |
1577 | d -> d_ncylinders = g.cylinders; | 1580 | d -> d_ncylinders = cylinders; |
1578 | d -> d_secpercyl = g.sectors * g.heads;/* sectors/cylinder */ | 1581 | d -> d_secpercyl = sectors * heads;/* sectors/cylinder */ |
1579 | if (d -> d_secpercyl == 0) | 1582 | if (d -> d_secpercyl == 0) |
1580 | d -> d_secpercyl = 1; /* avoid segfaults */ | 1583 | d -> d_secpercyl = 1; /* avoid segfaults */ |
1581 | d -> d_secperunit = d -> d_secpercyl * d -> d_ncylinders; | 1584 | d -> d_secperunit = d -> d_secpercyl * d -> d_ncylinders; |
@@ -1957,7 +1960,6 @@ static void | |||
1957 | sgi_list_table( int xtra ) { | 1960 | sgi_list_table( int xtra ) { |
1958 | int i, w; | 1961 | int i, w; |
1959 | int kpi = 0; /* kernel partition ID */ | 1962 | int kpi = 0; /* kernel partition ID */ |
1960 | const char *type; | ||
1961 | 1963 | ||
1962 | w = strlen( disk_device ); | 1964 | w = strlen( disk_device ); |
1963 | 1965 | ||
@@ -1998,8 +2000,7 @@ sgi_list_table( int xtra ) { | |||
1998 | /* end */ (long) scround(start+len)-1, | 2000 | /* end */ (long) scround(start+len)-1, |
1999 | /* no odd flag on end */ (long) len, | 2001 | /* no odd flag on end */ (long) len, |
2000 | /* type id */ sgi_get_sysid(i), | 2002 | /* type id */ sgi_get_sysid(i), |
2001 | /* type name */ (type = partition_type(sgi_get_sysid(i))) | 2003 | /* type name */ partition_type(sgi_get_sysid(i))); |
2002 | ? type : _("Unknown")); | ||
2003 | } | 2004 | } |
2004 | } | 2005 | } |
2005 | printf(_("----- Bootinfo -----\nBootfile: %s\n" | 2006 | printf(_("----- Bootinfo -----\nBootfile: %s\n" |
@@ -3192,7 +3193,6 @@ sun_change_sysid(int i, int sys) { | |||
3192 | static void | 3193 | static void |
3193 | sun_list_table(int xtra) { | 3194 | sun_list_table(int xtra) { |
3194 | int i, w; | 3195 | int i, w; |
3195 | const char *type; | ||
3196 | 3196 | ||
3197 | w = strlen(disk_device); | 3197 | w = strlen(disk_device); |
3198 | if (xtra) | 3198 | if (xtra) |
@@ -3231,8 +3231,7 @@ sun_list_table(int xtra) { | |||
3231 | /* end */ (long) scround(start+len), | 3231 | /* end */ (long) scround(start+len), |
3232 | /* odd flag on end */ (long) len / 2, len & 1 ? '+' : ' ', | 3232 | /* odd flag on end */ (long) len / 2, len & 1 ? '+' : ' ', |
3233 | /* type id */ sunlabel->infos[i].id, | 3233 | /* type id */ sunlabel->infos[i].id, |
3234 | /* type name */ (type = partition_type(sunlabel->infos[i].id)) | 3234 | /* type name */ partition_type(sunlabel->infos[i].id)); |
3235 | ? type : _("Unknown")); | ||
3236 | } | 3235 | } |
3237 | } | 3236 | } |
3238 | } | 3237 | } |
@@ -3297,52 +3296,27 @@ sun_write_table(void) { | |||
3297 | static const struct systypes i386_sys_types[] = { | 3296 | static const struct systypes i386_sys_types[] = { |
3298 | {"\x00" "Empty"}, | 3297 | {"\x00" "Empty"}, |
3299 | {"\x01" "FAT12"}, | 3298 | {"\x01" "FAT12"}, |
3300 | {"\x02" "XENIX root"}, | ||
3301 | {"\x03" "XENIX usr"}, | ||
3302 | {"\x04" "FAT16 <32M"}, | 3299 | {"\x04" "FAT16 <32M"}, |
3303 | {"\x05" "Extended"}, /* DOS 3.3+ extended partition */ | 3300 | {"\x05" "Extended"}, /* DOS 3.3+ extended partition */ |
3304 | {"\x06" "FAT16"}, /* DOS 16-bit >=32M */ | 3301 | {"\x06" "FAT16"}, /* DOS 16-bit >=32M */ |
3305 | {"\x07" "HPFS/NTFS"}, /* OS/2 IFS, eg, HPFS or NTFS or QNX */ | 3302 | {"\x07" "HPFS/NTFS"}, /* OS/2 IFS, eg, HPFS or NTFS or QNX */ |
3306 | {"\x08" "AIX"}, /* AIX boot (AIX -- PS/2 port) or SplitDrive */ | ||
3307 | {"\x09" "AIX bootable"}, /* AIX data or Coherent */ | ||
3308 | {"\x0a" "OS/2 Boot Manager"},/* OS/2 Boot Manager */ | 3303 | {"\x0a" "OS/2 Boot Manager"},/* OS/2 Boot Manager */ |
3309 | {"\x0b" "Win95 FAT32"}, | 3304 | {"\x0b" "Win95 FAT32"}, |
3310 | {"\x0c" "Win95 FAT32 (LBA)"},/* LBA really is `Extended Int 13h' */ | 3305 | {"\x0c" "Win95 FAT32 (LBA)"},/* LBA really is `Extended Int 13h' */ |
3311 | {"\x0e" "Win95 FAT16 (LBA)"}, | 3306 | {"\x0e" "Win95 FAT16 (LBA)"}, |
3312 | {"\x0f" "Win95 Ext'd (LBA)"}, | 3307 | {"\x0f" "Win95 Ext'd (LBA)"}, |
3313 | {"\x10" "OPUS"}, | ||
3314 | {"\x11" "Hidden FAT12"}, | 3308 | {"\x11" "Hidden FAT12"}, |
3315 | {"\x12" "Compaq diagnostics"}, | 3309 | {"\x12" "Compaq diagnostics"}, |
3316 | {"\x14" "Hidden FAT16 <32M"}, | 3310 | {"\x14" "Hidden FAT16 <32M"}, |
3317 | {"\x16" "Hidden FAT16"}, | 3311 | {"\x16" "Hidden FAT16"}, |
3318 | {"\x17" "Hidden HPFS/NTFS"}, | 3312 | {"\x17" "Hidden HPFS/NTFS"}, |
3319 | {"\x18" "AST SmartSleep"}, | ||
3320 | {"\x1b" "Hidden Win95 FAT32"}, | 3313 | {"\x1b" "Hidden Win95 FAT32"}, |
3321 | {"\x1c" "Hidden Win95 FAT32 (LBA)"}, | 3314 | {"\x1c" "Hidden Win95 FAT32 (LBA)"}, |
3322 | {"\x1e" "Hidden Win95 FAT16 (LBA)"}, | 3315 | {"\x1e" "Hidden Win95 FAT16 (LBA)"}, |
3323 | {"\x24" "NEC DOS"}, | ||
3324 | {"\x39" "Plan 9"}, | ||
3325 | {"\x3c" "PartitionMagic recovery"}, | 3316 | {"\x3c" "PartitionMagic recovery"}, |
3326 | {"\x40" "Venix 80286"}, | ||
3327 | {"\x41" "PPC PReP Boot"}, | 3317 | {"\x41" "PPC PReP Boot"}, |
3328 | {"\x42" "SFS"}, | 3318 | {"\x42" "SFS"}, |
3329 | {"\x4d" "QNX4.x"}, | ||
3330 | {"\x4e" "QNX4.x 2nd part"}, | ||
3331 | {"\x4f" "QNX4.x 3rd part"}, | ||
3332 | {"\x50" "OnTrack DM"}, | ||
3333 | {"\x51" "OnTrack DM6 Aux1"}, /* (or Novell) */ | ||
3334 | {"\x52" "CP/M"}, /* CP/M or Microport SysV/AT */ | ||
3335 | {"\x53" "OnTrack DM6 Aux3"}, | ||
3336 | {"\x54" "OnTrackDM6"}, | ||
3337 | {"\x55" "EZ-Drive"}, | ||
3338 | {"\x56" "Golden Bow"}, | ||
3339 | {"\x5c" "Priam Edisk"}, | ||
3340 | {"\x61" "SpeedStor"}, | ||
3341 | {"\x63" "GNU HURD or SysV"}, /* GNU HURD or Mach or Sys V/386 (such as ISC UNIX) */ | 3319 | {"\x63" "GNU HURD or SysV"}, /* GNU HURD or Mach or Sys V/386 (such as ISC UNIX) */ |
3342 | {"\x64" "Novell Netware 286"}, | ||
3343 | {"\x65" "Novell Netware 386"}, | ||
3344 | {"\x70" "DiskSecure Multi-Boot"}, | ||
3345 | {"\x75" "PC/IX"}, | ||
3346 | {"\x80" "Old Minix"}, /* Minix 1.4a and earlier */ | 3320 | {"\x80" "Old Minix"}, /* Minix 1.4a and earlier */ |
3347 | {"\x81" "Minix / old Linux"},/* Minix 1.4b and later */ | 3321 | {"\x81" "Minix / old Linux"},/* Minix 1.4b and later */ |
3348 | {"\x82" "Linux swap"}, /* also Solaris */ | 3322 | {"\x82" "Linux swap"}, /* also Solaris */ |
@@ -3352,20 +3326,54 @@ static const struct systypes i386_sys_types[] = { | |||
3352 | {"\x86" "NTFS volume set"}, | 3326 | {"\x86" "NTFS volume set"}, |
3353 | {"\x87" "NTFS volume set"}, | 3327 | {"\x87" "NTFS volume set"}, |
3354 | {"\x8e" "Linux LVM"}, | 3328 | {"\x8e" "Linux LVM"}, |
3355 | {"\x93" "Amoeba"}, | ||
3356 | {"\x94" "Amoeba BBT"}, /* (bad block table) */ | ||
3357 | {"\x9f" "BSD/OS"}, /* BSDI */ | 3329 | {"\x9f" "BSD/OS"}, /* BSDI */ |
3358 | {"\xa0" "IBM Thinkpad hibernation"}, | 3330 | {"\xa0" "IBM Thinkpad hibernation"}, |
3359 | {"\xa5" "FreeBSD"}, /* various BSD flavours */ | 3331 | {"\xa5" "FreeBSD"}, /* various BSD flavours */ |
3360 | {"\xa6" "OpenBSD"}, | 3332 | {"\xa6" "OpenBSD"}, |
3361 | {"\xa7" "NeXTSTEP"}, | ||
3362 | {"\xa8" "Darwin UFS"}, | 3333 | {"\xa8" "Darwin UFS"}, |
3363 | {"\xa9" "NetBSD"}, | 3334 | {"\xa9" "NetBSD"}, |
3364 | {"\xab" "Darwin boot"}, | 3335 | {"\xab" "Darwin boot"}, |
3365 | {"\xb7" "BSDI fs"}, | 3336 | {"\xb7" "BSDI fs"}, |
3366 | {"\xb8" "BSDI swap"}, | 3337 | {"\xb8" "BSDI swap"}, |
3367 | {"\xbb" "Boot Wizard hidden"}, | ||
3368 | {"\xbe" "Solaris boot"}, | 3338 | {"\xbe" "Solaris boot"}, |
3339 | {"\xeb" "BeOS fs"}, | ||
3340 | {"\xee" "EFI GPT"}, /* Intel EFI GUID Partition Table */ | ||
3341 | {"\xef" "EFI (FAT-12/16/32)"},/* Intel EFI System Partition */ | ||
3342 | {"\xf0" "Linux/PA-RISC boot"},/* Linux/PA-RISC boot loader */ | ||
3343 | {"\xf2" "DOS secondary"}, /* DOS 3.3+ secondary */ | ||
3344 | {"\xfd" "Linux raid autodetect"},/* New (2.2.x) raid partition with | ||
3345 | autodetect using persistent | ||
3346 | superblock */ | ||
3347 | #ifdef CONFIG_WEIRD_PARTITION_TYPES | ||
3348 | {"\x02" "XENIX root"}, | ||
3349 | {"\x03" "XENIX usr"}, | ||
3350 | {"\x08" "AIX"}, /* AIX boot (AIX -- PS/2 port) or SplitDrive */ | ||
3351 | {"\x09" "AIX bootable"}, /* AIX data or Coherent */ | ||
3352 | {"\x10" "OPUS"}, | ||
3353 | {"\x18" "AST SmartSleep"}, | ||
3354 | {"\x24" "NEC DOS"}, | ||
3355 | {"\x39" "Plan 9"}, | ||
3356 | {"\x40" "Venix 80286"}, | ||
3357 | {"\x4d" "QNX4.x"}, | ||
3358 | {"\x4e" "QNX4.x 2nd part"}, | ||
3359 | {"\x4f" "QNX4.x 3rd part"}, | ||
3360 | {"\x50" "OnTrack DM"}, | ||
3361 | {"\x51" "OnTrack DM6 Aux1"}, /* (or Novell) */ | ||
3362 | {"\x52" "CP/M"}, /* CP/M or Microport SysV/AT */ | ||
3363 | {"\x53" "OnTrack DM6 Aux3"}, | ||
3364 | {"\x54" "OnTrackDM6"}, | ||
3365 | {"\x55" "EZ-Drive"}, | ||
3366 | {"\x56" "Golden Bow"}, | ||
3367 | {"\x5c" "Priam Edisk"}, | ||
3368 | {"\x61" "SpeedStor"}, | ||
3369 | {"\x64" "Novell Netware 286"}, | ||
3370 | {"\x65" "Novell Netware 386"}, | ||
3371 | {"\x70" "DiskSecure Multi-Boot"}, | ||
3372 | {"\x75" "PC/IX"}, | ||
3373 | {"\x93" "Amoeba"}, | ||
3374 | {"\x94" "Amoeba BBT"}, /* (bad block table) */ | ||
3375 | {"\xa7" "NeXTSTEP"}, | ||
3376 | {"\xbb" "Boot Wizard hidden"}, | ||
3369 | {"\xc1" "DRDOS/sec (FAT-12)"}, | 3377 | {"\xc1" "DRDOS/sec (FAT-12)"}, |
3370 | {"\xc4" "DRDOS/sec (FAT-16 < 32M)"}, | 3378 | {"\xc4" "DRDOS/sec (FAT-16 < 32M)"}, |
3371 | {"\xc6" "DRDOS/sec (FAT-16)"}, | 3379 | {"\xc6" "DRDOS/sec (FAT-16)"}, |
@@ -3380,23 +3388,15 @@ static const struct systypes i386_sys_types[] = { | |||
3380 | {"\xe3" "DOS R/O"}, /* DOS R/O or SpeedStor */ | 3388 | {"\xe3" "DOS R/O"}, /* DOS R/O or SpeedStor */ |
3381 | {"\xe4" "SpeedStor"}, /* SpeedStor 16-bit FAT extended | 3389 | {"\xe4" "SpeedStor"}, /* SpeedStor 16-bit FAT extended |
3382 | partition < 1024 cyl. */ | 3390 | partition < 1024 cyl. */ |
3383 | {"\xeb" "BeOS fs"}, | ||
3384 | {"\xee" "EFI GPT"}, /* Intel EFI GUID Partition Table */ | ||
3385 | {"\xef" "EFI (FAT-12/16/32)"},/* Intel EFI System Partition */ | ||
3386 | {"\xf0" "Linux/PA-RISC boot"},/* Linux/PA-RISC boot loader */ | ||
3387 | {"\xf1" "SpeedStor"}, | 3391 | {"\xf1" "SpeedStor"}, |
3388 | {"\xf4" "SpeedStor"}, /* SpeedStor large partition */ | 3392 | {"\xf4" "SpeedStor"}, /* SpeedStor large partition */ |
3389 | {"\xf2" "DOS secondary"}, /* DOS 3.3+ secondary */ | ||
3390 | {"\xfd" "Linux raid autodetect"},/* New (2.2.x) raid partition with | ||
3391 | autodetect using persistent | ||
3392 | superblock */ | ||
3393 | {"\xfe" "LANstep"}, /* SpeedStor >1024 cyl. or LANstep */ | 3393 | {"\xfe" "LANstep"}, /* SpeedStor >1024 cyl. or LANstep */ |
3394 | {"\xff" "BBT"}, /* Xenix Bad Block Table */ | 3394 | {"\xff" "BBT"}, /* Xenix Bad Block Table */ |
3395 | #endif | ||
3395 | { 0 } | 3396 | { 0 } |
3396 | }; | 3397 | }; |
3397 | 3398 | ||
3398 | 3399 | ||
3399 | static void delete_partition(int i); | ||
3400 | 3400 | ||
3401 | /* A valid partition table sector ends in 0x55 0xaa */ | 3401 | /* A valid partition table sector ends in 0x55 0xaa */ |
3402 | static unsigned int | 3402 | static unsigned int |
@@ -3404,11 +3404,8 @@ part_table_flag(const char *b) { | |||
3404 | return ((uint) b[510]) + (((uint) b[511]) << 8); | 3404 | return ((uint) b[510]) + (((uint) b[511]) << 8); |
3405 | } | 3405 | } |
3406 | 3406 | ||
3407 | static int | ||
3408 | valid_part_table_flag(const unsigned char *b) { | ||
3409 | return (b[510] == 0x55 && b[511] == 0xaa); | ||
3410 | } | ||
3411 | 3407 | ||
3408 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
3412 | static void | 3409 | static void |
3413 | write_part_table_flag(char *b) { | 3410 | write_part_table_flag(char *b) { |
3414 | b[510] = 0x55; | 3411 | b[510] = 0x55; |
@@ -3424,6 +3421,7 @@ store4_little_endian(unsigned char *cp, unsigned int val) { | |||
3424 | cp[2] = ((val >> 16) & 0xff); | 3421 | cp[2] = ((val >> 16) & 0xff); |
3425 | cp[3] = ((val >> 24) & 0xff); | 3422 | cp[3] = ((val >> 24) & 0xff); |
3426 | } | 3423 | } |
3424 | #endif /* CONFIG_FEATURE_FDISK_WRITABLE */ | ||
3427 | 3425 | ||
3428 | static unsigned int | 3426 | static unsigned int |
3429 | read4_little_endian(const unsigned char *cp) { | 3427 | read4_little_endian(const unsigned char *cp) { |
@@ -3431,20 +3429,24 @@ read4_little_endian(const unsigned char *cp) { | |||
3431 | + ((uint)(cp[2]) << 16) + ((uint)(cp[3]) << 24); | 3429 | + ((uint)(cp[2]) << 16) + ((uint)(cp[3]) << 24); |
3432 | } | 3430 | } |
3433 | 3431 | ||
3432 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
3434 | static void | 3433 | static void |
3435 | set_start_sect(struct partition *p, unsigned int start_sect) { | 3434 | set_start_sect(struct partition *p, unsigned int start_sect) { |
3436 | store4_little_endian(p->start4, start_sect); | 3435 | store4_little_endian(p->start4, start_sect); |
3437 | } | 3436 | } |
3437 | #endif | ||
3438 | 3438 | ||
3439 | static unsigned int | 3439 | static unsigned int |
3440 | get_start_sect(const struct partition *p) { | 3440 | get_start_sect(const struct partition *p) { |
3441 | return read4_little_endian(p->start4); | 3441 | return read4_little_endian(p->start4); |
3442 | } | 3442 | } |
3443 | 3443 | ||
3444 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
3444 | static void | 3445 | static void |
3445 | set_nr_sects(struct partition *p, unsigned int nr_sects) { | 3446 | set_nr_sects(struct partition *p, unsigned int nr_sects) { |
3446 | store4_little_endian(p->size4, nr_sects); | 3447 | store4_little_endian(p->size4, nr_sects); |
3447 | } | 3448 | } |
3449 | #endif | ||
3448 | 3450 | ||
3449 | static unsigned int | 3451 | static unsigned int |
3450 | get_nr_sects(const struct partition *p) { | 3452 | get_nr_sects(const struct partition *p) { |
@@ -3457,9 +3459,12 @@ static int type_open = O_RDWR; | |||
3457 | 3459 | ||
3458 | static int ext_index, /* the prime extended partition */ | 3460 | static int ext_index, /* the prime extended partition */ |
3459 | listing, /* no aborts for fdisk -l */ | 3461 | listing, /* no aborts for fdisk -l */ |
3460 | nowarn, /* no warnings for fdisk -l/-s */ | 3462 | dos_compatible_flag = ~0; |
3461 | dos_compatible_flag = ~0, | 3463 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE |
3462 | dos_changed; | 3464 | static int dos_changed; |
3465 | static int nowarn; /* no warnings for fdisk -l/-s */ | ||
3466 | #endif | ||
3467 | |||
3463 | 3468 | ||
3464 | 3469 | ||
3465 | static uint user_cylinders, user_heads, user_sectors; | 3470 | static uint user_cylinders, user_heads, user_sectors; |
@@ -3516,29 +3521,27 @@ seek_sector(uint secno) { | |||
3516 | fdisk_fatal(unable_to_seek); | 3521 | fdisk_fatal(unable_to_seek); |
3517 | } | 3522 | } |
3518 | 3523 | ||
3519 | static void | 3524 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE |
3520 | read_sector(uint secno, char *buf) { | ||
3521 | seek_sector(secno); | ||
3522 | if (read(fd, buf, sector_size) != sector_size) | ||
3523 | fdisk_fatal(unable_to_read); | ||
3524 | } | ||
3525 | |||
3526 | static void | 3525 | static void |
3527 | write_sector(uint secno, char *buf) { | 3526 | write_sector(uint secno, char *buf) { |
3528 | seek_sector(secno); | 3527 | seek_sector(secno); |
3529 | if (write(fd, buf, sector_size) != sector_size) | 3528 | if (write(fd, buf, sector_size) != sector_size) |
3530 | fdisk_fatal(unable_to_write); | 3529 | fdisk_fatal(unable_to_write); |
3531 | } | 3530 | } |
3531 | #endif | ||
3532 | 3532 | ||
3533 | /* Allocate a buffer and read a partition table sector */ | 3533 | /* Allocate a buffer and read a partition table sector */ |
3534 | static void | 3534 | static void |
3535 | read_pte(int pno, uint offset) { | 3535 | read_pte(struct pte *pe, uint offset) { |
3536 | struct pte *pe = &ptes[pno]; | ||
3537 | 3536 | ||
3538 | pe->offset = offset; | 3537 | pe->offset = offset; |
3539 | pe->sectorbuffer = (char *) xmalloc(sector_size); | 3538 | pe->sectorbuffer = (char *) xmalloc(sector_size); |
3540 | read_sector(offset, pe->sectorbuffer); | 3539 | seek_sector(offset); |
3540 | if (read(fd, pe->sectorbuffer, sector_size) != sector_size) | ||
3541 | fdisk_fatal(unable_to_read); | ||
3542 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
3541 | pe->changed = 0; | 3543 | pe->changed = 0; |
3544 | #endif | ||
3542 | pe->part_table = pe->ext_pointer = NULL; | 3545 | pe->part_table = pe->ext_pointer = NULL; |
3543 | } | 3546 | } |
3544 | 3547 | ||
@@ -3547,6 +3550,7 @@ get_partition_start(const struct pte *pe) { | |||
3547 | return pe->offset + get_start_sect(pe->part_table); | 3550 | return pe->offset + get_start_sect(pe->part_table); |
3548 | } | 3551 | } |
3549 | 3552 | ||
3553 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
3550 | /* | 3554 | /* |
3551 | * Avoid warning about DOS partitions when no DOS partition was changed. | 3555 | * Avoid warning about DOS partitions when no DOS partition was changed. |
3552 | * Here a heuristic "is probably dos partition". | 3556 | * Here a heuristic "is probably dos partition". |
@@ -3638,6 +3642,8 @@ menu(void) { | |||
3638 | #endif | 3642 | #endif |
3639 | } | 3643 | } |
3640 | } | 3644 | } |
3645 | #endif /* CONFIG_FEATURE_FDISK_WRITABLE */ | ||
3646 | |||
3641 | 3647 | ||
3642 | #ifdef CONFIG_FEATURE_FDISK_ADVANCED | 3648 | #ifdef CONFIG_FEATURE_FDISK_ADVANCED |
3643 | static void | 3649 | static void |
@@ -3720,19 +3726,7 @@ xmenu(void) { | |||
3720 | } | 3726 | } |
3721 | #endif /* ADVANCED mode */ | 3727 | #endif /* ADVANCED mode */ |
3722 | 3728 | ||
3723 | 3729 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | |
3724 | static int | ||
3725 | get_sysid(int i) { | ||
3726 | return ( | ||
3727 | #ifdef CONFIG_FEATURE_SUN_LABEL | ||
3728 | sun_label ? sunlabel->infos[i].id : | ||
3729 | #endif | ||
3730 | #ifdef CONFIG_FEATURE_SGI_LABEL | ||
3731 | sgi_label ? sgi_get_sysid(i) : | ||
3732 | #endif | ||
3733 | ptes[i].part_table->sys_ind); | ||
3734 | } | ||
3735 | |||
3736 | static const struct systypes * | 3730 | static const struct systypes * |
3737 | get_sys_types(void) { | 3731 | get_sys_types(void) { |
3738 | return ( | 3732 | return ( |
@@ -3744,6 +3738,9 @@ get_sys_types(void) { | |||
3744 | #endif | 3738 | #endif |
3745 | i386_sys_types); | 3739 | i386_sys_types); |
3746 | } | 3740 | } |
3741 | #else | ||
3742 | #define get_sys_types() i386_sys_types | ||
3743 | #endif /* CONFIG_FEATURE_FDISK_WRITABLE */ | ||
3747 | 3744 | ||
3748 | static const char *partition_type(unsigned char type) | 3745 | static const char *partition_type(unsigned char type) |
3749 | { | 3746 | { |
@@ -3754,7 +3751,21 @@ static const char *partition_type(unsigned char type) | |||
3754 | if (types[i].name[0] == type) | 3751 | if (types[i].name[0] == type) |
3755 | return types[i].name + 1; | 3752 | return types[i].name + 1; |
3756 | 3753 | ||
3757 | return NULL; | 3754 | return _("Unknown"); |
3755 | } | ||
3756 | |||
3757 | |||
3758 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
3759 | static int | ||
3760 | get_sysid(int i) { | ||
3761 | return ( | ||
3762 | #ifdef CONFIG_FEATURE_SUN_LABEL | ||
3763 | sun_label ? sunlabel->infos[i].id : | ||
3764 | #endif | ||
3765 | #ifdef CONFIG_FEATURE_SGI_LABEL | ||
3766 | sgi_label ? sgi_get_sysid(i) : | ||
3767 | #endif | ||
3768 | ptes[i].part_table->sys_ind); | ||
3758 | } | 3769 | } |
3759 | 3770 | ||
3760 | void list_types(const struct systypes *sys) | 3771 | void list_types(const struct systypes *sys) |
@@ -3771,7 +3782,7 @@ void list_types(const struct systypes *sys) | |||
3771 | 3782 | ||
3772 | do { | 3783 | do { |
3773 | printf("%c%2x %-15.15s", i ? ' ' : '\n', | 3784 | printf("%c%2x %-15.15s", i ? ' ' : '\n', |
3774 | sys[next].name[0], sys[next].name + 1); | 3785 | sys[next].name[0], partition_type(sys[next].name[0])); |
3775 | next = last[i++] + done; | 3786 | next = last[i++] + done; |
3776 | if (i > 3 || next >= last[i]) { | 3787 | if (i > 3 || next >= last[i]) { |
3777 | i = 0; | 3788 | i = 0; |
@@ -3780,6 +3791,7 @@ void list_types(const struct systypes *sys) | |||
3780 | } while (done < last[0]); | 3791 | } while (done < last[0]); |
3781 | putchar('\n'); | 3792 | putchar('\n'); |
3782 | } | 3793 | } |
3794 | #endif /* CONFIG_FEATURE_FDISK_WRITABLE */ | ||
3783 | 3795 | ||
3784 | static int | 3796 | static int |
3785 | is_cleared_partition(const struct partition *p) { | 3797 | is_cleared_partition(const struct partition *p) { |
@@ -3792,18 +3804,10 @@ static void | |||
3792 | clear_partition(struct partition *p) { | 3804 | clear_partition(struct partition *p) { |
3793 | if (!p) | 3805 | if (!p) |
3794 | return; | 3806 | return; |
3795 | p->boot_ind = 0; | 3807 | memset(p, 0, sizeof(struct partition)); |
3796 | p->head = 0; | ||
3797 | p->sector = 0; | ||
3798 | p->cyl = 0; | ||
3799 | p->sys_ind = 0; | ||
3800 | p->end_head = 0; | ||
3801 | p->end_sector = 0; | ||
3802 | p->end_cyl = 0; | ||
3803 | set_start_sect(p,0); | ||
3804 | set_nr_sects(p,0); | ||
3805 | } | 3808 | } |
3806 | 3809 | ||
3810 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
3807 | static void | 3811 | static void |
3808 | set_partition(int i, int doext, uint start, uint stop, int sysid) { | 3812 | set_partition(int i, int doext, uint start, uint stop, int sysid) { |
3809 | struct partition *p; | 3813 | struct partition *p; |
@@ -3828,6 +3832,7 @@ set_partition(int i, int doext, uint start, uint stop, int sysid) { | |||
3828 | set_hsc(p->end_head, p->end_sector, p->end_cyl, stop); | 3832 | set_hsc(p->end_head, p->end_sector, p->end_cyl, stop); |
3829 | ptes[i].changed = 1; | 3833 | ptes[i].changed = 1; |
3830 | } | 3834 | } |
3835 | #endif | ||
3831 | 3836 | ||
3832 | static int | 3837 | static int |
3833 | test_c(const char **m, const char *mesg) { | 3838 | test_c(const char **m, const char *mesg) { |
@@ -3855,9 +3860,13 @@ warn_geometry(void) { | |||
3855 | prev = test_c(&m, _("cylinders")); | 3860 | prev = test_c(&m, _("cylinders")); |
3856 | if (!m) | 3861 | if (!m) |
3857 | return 0; | 3862 | return 0; |
3858 | fprintf(stderr, | 3863 | |
3859 | _("%s%s.\nYou can do this from the extra functions menu.\n"), | 3864 | fprintf(stderr, "%s%s.\n" |
3860 | prev ? _(" and ") : " ", m); | 3865 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE |
3866 | "You can do this from the extra functions menu.\n" | ||
3867 | #endif | ||
3868 | , prev ? _(" and ") : " ", m); | ||
3869 | |||
3861 | return 1; | 3870 | return 1; |
3862 | } | 3871 | } |
3863 | 3872 | ||
@@ -3871,6 +3880,7 @@ static void update_units(void) | |||
3871 | units_per_sector = 1; /* in sectors */ | 3880 | units_per_sector = 1; /* in sectors */ |
3872 | } | 3881 | } |
3873 | 3882 | ||
3883 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
3874 | static void | 3884 | static void |
3875 | warn_cylinders(void) { | 3885 | warn_cylinders(void) { |
3876 | if (dos_label && cylinders > 1024 && !nowarn) | 3886 | if (dos_label && cylinders > 1024 && !nowarn) |
@@ -3883,6 +3893,7 @@ warn_cylinders(void) { | |||
3883 | " (e.g., DOS FDISK, OS/2 FDISK)\n"), | 3893 | " (e.g., DOS FDISK, OS/2 FDISK)\n"), |
3884 | cylinders); | 3894 | cylinders); |
3885 | } | 3895 | } |
3896 | #endif | ||
3886 | 3897 | ||
3887 | static void | 3898 | static void |
3888 | read_extended(int ext) { | 3899 | read_extended(int ext) { |
@@ -3909,16 +3920,17 @@ read_extended(int ext) { | |||
3909 | this program uses arrays of size MAXIMUM_PARTS. | 3920 | this program uses arrays of size MAXIMUM_PARTS. |
3910 | Do not try to `improve' this test. */ | 3921 | Do not try to `improve' this test. */ |
3911 | struct pte *pre = &ptes[partitions-1]; | 3922 | struct pte *pre = &ptes[partitions-1]; |
3912 | 3923 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | |
3913 | fprintf(stderr, | 3924 | fprintf(stderr, |
3914 | _("Warning: deleting partitions after %d\n"), | 3925 | _("Warning: deleting partitions after %d\n"), |
3915 | partitions); | 3926 | partitions); |
3916 | clear_partition(pre->ext_pointer); | ||
3917 | pre->changed = 1; | 3927 | pre->changed = 1; |
3928 | #endif | ||
3929 | clear_partition(pre->ext_pointer); | ||
3918 | return; | 3930 | return; |
3919 | } | 3931 | } |
3920 | 3932 | ||
3921 | read_pte(partitions, extended_offset + get_start_sect(p)); | 3933 | read_pte(pe, extended_offset + get_start_sect(p)); |
3922 | 3934 | ||
3923 | if (!extended_offset) | 3935 | if (!extended_offset) |
3924 | extended_offset = get_start_sect(p); | 3936 | extended_offset = get_start_sect(p); |
@@ -3962,6 +3974,7 @@ read_extended(int ext) { | |||
3962 | partitions++; | 3974 | partitions++; |
3963 | } | 3975 | } |
3964 | 3976 | ||
3977 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
3965 | /* remove empty links */ | 3978 | /* remove empty links */ |
3966 | remove: | 3979 | remove: |
3967 | for (i = 4; i < partitions; i++) { | 3980 | for (i = 4; i < partitions; i++) { |
@@ -3974,8 +3987,10 @@ read_extended(int ext) { | |||
3974 | goto remove; /* numbering changed */ | 3987 | goto remove; /* numbering changed */ |
3975 | } | 3988 | } |
3976 | } | 3989 | } |
3990 | #endif | ||
3977 | } | 3991 | } |
3978 | 3992 | ||
3993 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
3979 | static void | 3994 | static void |
3980 | create_doslabel(void) { | 3995 | create_doslabel(void) { |
3981 | int i; | 3996 | int i; |
@@ -4007,7 +4022,7 @@ create_doslabel(void) { | |||
4007 | set_changed(0); | 4022 | set_changed(0); |
4008 | get_boot(create_empty_dos); | 4023 | get_boot(create_empty_dos); |
4009 | } | 4024 | } |
4010 | 4025 | #endif /* CONFIG_FEATURE_FDISK_WRITABLE */ | |
4011 | 4026 | ||
4012 | static void | 4027 | static void |
4013 | get_sectorsize(void) { | 4028 | get_sectorsize(void) { |
@@ -4022,7 +4037,7 @@ get_sectorsize(void) { | |||
4022 | } | 4037 | } |
4023 | } | 4038 | } |
4024 | 4039 | ||
4025 | static void | 4040 | static inline void |
4026 | get_kernel_geometry(void) { | 4041 | get_kernel_geometry(void) { |
4027 | struct hd_geometry geometry; | 4042 | struct hd_geometry geometry; |
4028 | 4043 | ||
@@ -4035,7 +4050,7 @@ get_kernel_geometry(void) { | |||
4035 | 4050 | ||
4036 | static void | 4051 | static void |
4037 | get_partition_table_geometry(void) { | 4052 | get_partition_table_geometry(void) { |
4038 | unsigned char *bufp = MBRbuffer; | 4053 | const unsigned char *bufp = MBRbuffer; |
4039 | struct partition *p; | 4054 | struct partition *p; |
4040 | int i, h, s, hh, ss; | 4055 | int i, h, s, hh, ss; |
4041 | int first = 1; | 4056 | int first = 1; |
@@ -4066,7 +4081,7 @@ get_partition_table_geometry(void) { | |||
4066 | } | 4081 | } |
4067 | 4082 | ||
4068 | void | 4083 | void |
4069 | get_geometry(struct geom *g) { | 4084 | get_geometry(void) { |
4070 | int sec_fac; | 4085 | int sec_fac; |
4071 | unsigned long longsectors; | 4086 | unsigned long longsectors; |
4072 | 4087 | ||
@@ -4101,12 +4116,6 @@ get_geometry(struct geom *g) { | |||
4101 | if (!cylinders) | 4116 | if (!cylinders) |
4102 | cylinders = user_cylinders; | 4117 | cylinders = user_cylinders; |
4103 | 4118 | ||
4104 | if (g) { | ||
4105 | g->heads = heads; | ||
4106 | g->sectors = sectors; | ||
4107 | g->cylinders = cylinders; | ||
4108 | } | ||
4109 | |||
4110 | total_number_of_sectors = longsectors; | 4119 | total_number_of_sectors = longsectors; |
4111 | } | 4120 | } |
4112 | 4121 | ||
@@ -4129,14 +4138,19 @@ get_boot(enum action what) { | |||
4129 | pe->ext_pointer = NULL; | 4138 | pe->ext_pointer = NULL; |
4130 | pe->offset = 0; | 4139 | pe->offset = 0; |
4131 | pe->sectorbuffer = MBRbuffer; | 4140 | pe->sectorbuffer = MBRbuffer; |
4141 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
4132 | pe->changed = (what == create_empty_dos); | 4142 | pe->changed = (what == create_empty_dos); |
4143 | #endif | ||
4133 | } | 4144 | } |
4134 | 4145 | ||
4146 | #ifdef CONFIG_FEATURE_SUN_LABEL | ||
4135 | if (what == create_empty_sun && check_sun_label()) | 4147 | if (what == create_empty_sun && check_sun_label()) |
4136 | return 0; | 4148 | return 0; |
4149 | #endif | ||
4137 | 4150 | ||
4138 | memset(MBRbuffer, 0, 512); | 4151 | memset(MBRbuffer, 0, 512); |
4139 | 4152 | ||
4153 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
4140 | if (what == create_empty_dos) | 4154 | if (what == create_empty_dos) |
4141 | goto got_dos_table; /* skip reading disk */ | 4155 | goto got_dos_table; /* skip reading disk */ |
4142 | 4156 | ||
@@ -4155,13 +4169,21 @@ get_boot(enum action what) { | |||
4155 | return 1; | 4169 | return 1; |
4156 | fdisk_fatal(unable_to_read); | 4170 | fdisk_fatal(unable_to_read); |
4157 | } | 4171 | } |
4172 | #else | ||
4173 | if ((fd = open(disk_device, O_RDONLY)) < 0) | ||
4174 | return 1; | ||
4175 | if (512 != read(fd, MBRbuffer, 512)) | ||
4176 | return 1; | ||
4177 | #endif | ||
4158 | 4178 | ||
4159 | get_geometry(NULL); | 4179 | get_geometry(); |
4160 | 4180 | ||
4161 | update_units(); | 4181 | update_units(); |
4162 | 4182 | ||
4183 | #ifdef CONFIG_FEATURE_SUN_LABEL | ||
4163 | if (check_sun_label()) | 4184 | if (check_sun_label()) |
4164 | return 0; | 4185 | return 0; |
4186 | #endif | ||
4165 | 4187 | ||
4166 | #ifdef CONFIG_FEATURE_SGI_LABEL | 4188 | #ifdef CONFIG_FEATURE_SGI_LABEL |
4167 | if (check_sgi_label()) | 4189 | if (check_sgi_label()) |
@@ -4185,9 +4207,14 @@ get_boot(enum action what) { | |||
4185 | } | 4207 | } |
4186 | #endif | 4208 | #endif |
4187 | 4209 | ||
4210 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
4188 | got_dos_table: | 4211 | got_dos_table: |
4212 | #endif | ||
4189 | 4213 | ||
4190 | if (!valid_part_table_flag(MBRbuffer)) { | 4214 | if (!valid_part_table_flag(MBRbuffer)) { |
4215 | #ifndef CONFIG_FEATURE_FDISK_WRITABLE | ||
4216 | return -1; | ||
4217 | #else | ||
4191 | switch(what) { | 4218 | switch(what) { |
4192 | case fdisk: | 4219 | case fdisk: |
4193 | fprintf(stderr, | 4220 | fprintf(stderr, |
@@ -4202,20 +4229,23 @@ got_dos_table: | |||
4202 | create_doslabel(); | 4229 | create_doslabel(); |
4203 | #endif | 4230 | #endif |
4204 | return 0; | 4231 | return 0; |
4205 | case require: | ||
4206 | return -1; | ||
4207 | case try_only: | 4232 | case try_only: |
4208 | return -1; | 4233 | return -1; |
4209 | case create_empty_dos: | 4234 | case create_empty_dos: |
4235 | #ifdef CONFIG_FEATURE_SUN_LABEL | ||
4210 | case create_empty_sun: | 4236 | case create_empty_sun: |
4237 | #endif | ||
4211 | break; | 4238 | break; |
4212 | default: | 4239 | default: |
4213 | fprintf(stderr, _("Internal error\n")); | 4240 | fprintf(stderr, _("Internal error\n")); |
4214 | exit(1); | 4241 | exit(1); |
4215 | } | 4242 | } |
4243 | #endif /* CONFIG_FEATURE_FDISK_WRITABLE */ | ||
4216 | } | 4244 | } |
4217 | 4245 | ||
4246 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
4218 | warn_cylinders(); | 4247 | warn_cylinders(); |
4248 | #endif | ||
4219 | warn_geometry(); | 4249 | warn_geometry(); |
4220 | 4250 | ||
4221 | for (i = 0; i < 4; i++) { | 4251 | for (i = 0; i < 4; i++) { |
@@ -4238,13 +4268,16 @@ got_dos_table: | |||
4238 | _("Warning: invalid flag 0x%04x of partition " | 4268 | _("Warning: invalid flag 0x%04x of partition " |
4239 | "table %d will be corrected by w(rite)\n"), | 4269 | "table %d will be corrected by w(rite)\n"), |
4240 | part_table_flag(pe->sectorbuffer), i + 1); | 4270 | part_table_flag(pe->sectorbuffer), i + 1); |
4271 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
4241 | pe->changed = 1; | 4272 | pe->changed = 1; |
4273 | #endif | ||
4242 | } | 4274 | } |
4243 | } | 4275 | } |
4244 | 4276 | ||
4245 | return 0; | 4277 | return 0; |
4246 | } | 4278 | } |
4247 | 4279 | ||
4280 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
4248 | /* | 4281 | /* |
4249 | * Print the message MESG, then read an integer between LOW and HIGH (inclusive). | 4282 | * Print the message MESG, then read an integer between LOW and HIGH (inclusive). |
4250 | * If the user hits Enter, DFLT is returned. | 4283 | * If the user hits Enter, DFLT is returned. |
@@ -4525,7 +4558,6 @@ delete_partition(int i) { | |||
4525 | 4558 | ||
4526 | static void | 4559 | static void |
4527 | change_sysid(void) { | 4560 | change_sysid(void) { |
4528 | const char *temp; | ||
4529 | int i, sys, origsys; | 4561 | int i, sys, origsys; |
4530 | struct partition *p; | 4562 | struct partition *p; |
4531 | 4563 | ||
@@ -4590,8 +4622,7 @@ change_sysid(void) { | |||
4590 | p->sys_ind = sys; | 4622 | p->sys_ind = sys; |
4591 | printf (_("Changed system type of partition %d " | 4623 | printf (_("Changed system type of partition %d " |
4592 | "to %x (%s)\n"), i + 1, sys, | 4624 | "to %x (%s)\n"), i + 1, sys, |
4593 | (temp = partition_type(sys)) ? temp : | 4625 | partition_type(sys)); |
4594 | _("Unknown")); | ||
4595 | ptes[i].changed = 1; | 4626 | ptes[i].changed = 1; |
4596 | if (is_dos_partition(origsys) || | 4627 | if (is_dos_partition(origsys) || |
4597 | is_dos_partition(sys)) | 4628 | is_dos_partition(sys)) |
@@ -4600,6 +4631,8 @@ change_sysid(void) { | |||
4600 | } | 4631 | } |
4601 | } | 4632 | } |
4602 | } | 4633 | } |
4634 | #endif /* CONFIG_FEATURE_FDISK_WRITABLE */ | ||
4635 | |||
4603 | 4636 | ||
4604 | /* check_consistency() and long2chs() added Sat Mar 6 12:28:16 1993, | 4637 | /* check_consistency() and long2chs() added Sat Mar 6 12:28:16 1993, |
4605 | * faith@cs.unc.edu, based on code fragments from pfdisk by Gordon W. Ross, | 4638 | * faith@cs.unc.edu, based on code fragments from pfdisk by Gordon W. Ross, |
@@ -4694,8 +4727,7 @@ list_disk_geometry(void) { | |||
4694 | if (units_per_sector == 1) | 4727 | if (units_per_sector == 1) |
4695 | printf(_(", total %lu sectors"), | 4728 | printf(_(", total %lu sectors"), |
4696 | total_number_of_sectors / (sector_size/512)); | 4729 | total_number_of_sectors / (sector_size/512)); |
4697 | printf("\n"); | 4730 | printf(_("\nUnits = %s of %d * %d = %d bytes\n\n"), |
4698 | printf(_("Units = %s of %d * %d = %d bytes\n\n"), | ||
4699 | str_units(PLURAL), | 4731 | str_units(PLURAL), |
4700 | units_per_sector, sector_size, units_per_sector * sector_size); | 4732 | units_per_sector, sector_size, units_per_sector * sector_size); |
4701 | } | 4733 | } |
@@ -4799,7 +4831,6 @@ fix_chain_of_logicals(void) { | |||
4799 | } | 4831 | } |
4800 | 4832 | ||
4801 | 4833 | ||
4802 | |||
4803 | static void | 4834 | static void |
4804 | fix_partition_table_order(void) { | 4835 | fix_partition_table_order(void) { |
4805 | struct pte *pei, *pek; | 4836 | struct pte *pei, *pek; |
@@ -4842,7 +4873,6 @@ fix_partition_table_order(void) { | |||
4842 | static void | 4873 | static void |
4843 | list_table(int xtra) { | 4874 | list_table(int xtra) { |
4844 | const struct partition *p; | 4875 | const struct partition *p; |
4845 | const char *type; | ||
4846 | int i, w; | 4876 | int i, w; |
4847 | 4877 | ||
4848 | #ifdef CONFIG_FEATURE_SUN_LABEL | 4878 | #ifdef CONFIG_FEATURE_SUN_LABEL |
@@ -4905,8 +4935,7 @@ list_table(int xtra) { | |||
4905 | - (psects ? 1 : 0)), | 4935 | - (psects ? 1 : 0)), |
4906 | /* odd flag on end */ (long) pblocks, podd ? '+' : ' ', | 4936 | /* odd flag on end */ (long) pblocks, podd ? '+' : ' ', |
4907 | /* type id */ p->sys_ind, | 4937 | /* type id */ p->sys_ind, |
4908 | /* type name */ (type = partition_type(p->sys_ind)) ? | 4938 | /* type name */ partition_type(p->sys_ind)); |
4909 | type : _("Unknown")); | ||
4910 | check_consistency(p, i); | 4939 | check_consistency(p, i); |
4911 | } | 4940 | } |
4912 | } | 4941 | } |
@@ -4947,6 +4976,7 @@ x_list_table(int extend) { | |||
4947 | } | 4976 | } |
4948 | #endif | 4977 | #endif |
4949 | 4978 | ||
4979 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
4950 | static void | 4980 | static void |
4951 | fill_bounds(uint *first, uint *last) { | 4981 | fill_bounds(uint *first, uint *last) { |
4952 | int i; | 4982 | int i; |
@@ -5362,6 +5392,7 @@ reread_partition_table(int leave) { | |||
5362 | exit(!!i); | 5392 | exit(!!i); |
5363 | } | 5393 | } |
5364 | } | 5394 | } |
5395 | #endif /* CONFIG_FEATURE_FDISK_WRITABLE */ | ||
5365 | 5396 | ||
5366 | #ifdef CONFIG_FEATURE_FDISK_ADVANCED | 5397 | #ifdef CONFIG_FEATURE_FDISK_ADVANCED |
5367 | #define MAX_PER_LINE 16 | 5398 | #define MAX_PER_LINE 16 |
@@ -5600,8 +5631,10 @@ try(const char *device, int user_specified) { | |||
5600 | } else { | 5631 | } else { |
5601 | close(fd); | 5632 | close(fd); |
5602 | list_table(0); | 5633 | list_table(0); |
5634 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
5603 | if (!sun_label && partitions > 4) | 5635 | if (!sun_label && partitions > 4) |
5604 | delete_partition(ext_index); | 5636 | delete_partition(ext_index); |
5637 | #endif | ||
5605 | } | 5638 | } |
5606 | } else { | 5639 | } else { |
5607 | /* Ignore other errors, since we try IDE | 5640 | /* Ignore other errors, since we try IDE |
@@ -5631,21 +5664,29 @@ tryprocpt(void) { | |||
5631 | for (s = ptname; *s; s++); | 5664 | for (s = ptname; *s; s++); |
5632 | if (isdigit(s[-1])) | 5665 | if (isdigit(s[-1])) |
5633 | continue; | 5666 | continue; |
5634 | snprintf(devname, sizeof(devname), "/dev/%s", ptname); | 5667 | sprintf(devname, "/dev/%s", ptname); |
5635 | try(devname, 0); | 5668 | try(devname, 0); |
5636 | } | 5669 | } |
5670 | #ifdef CONFIG_FEATURE_CLEAN_UP | ||
5637 | fclose(procpt); | 5671 | fclose(procpt); |
5672 | #endif | ||
5638 | } | 5673 | } |
5639 | 5674 | ||
5675 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
5640 | static void | 5676 | static void |
5641 | unknown_command(int c) { | 5677 | unknown_command(int c) { |
5642 | printf(_("%c: unknown command\n"), c); | 5678 | printf(_("%c: unknown command\n"), c); |
5643 | } | 5679 | } |
5680 | #endif | ||
5644 | 5681 | ||
5645 | int fdisk_main(int argc, char **argv) { | 5682 | int fdisk_main(int argc, char **argv) { |
5646 | int j, c; | 5683 | int c; |
5647 | int optl = 0, opts = 0; | 5684 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE |
5648 | 5685 | int optl = 0; | |
5686 | #endif | ||
5687 | #ifdef CONFIG_FEATURE_FDISK_BLKSIZE | ||
5688 | int opts = 0; | ||
5689 | #endif | ||
5649 | /* | 5690 | /* |
5650 | * Calls: | 5691 | * Calls: |
5651 | * fdisk -v | 5692 | * fdisk -v |
@@ -5656,7 +5697,11 @@ int fdisk_main(int argc, char **argv) { | |||
5656 | * Options -C, -H, -S set the geometry. | 5697 | * Options -C, -H, -S set the geometry. |
5657 | * | 5698 | * |
5658 | */ | 5699 | */ |
5659 | while ((c = getopt(argc, argv, "b:C:H:lsS:uvV")) != -1) { | 5700 | while ((c = getopt(argc, argv, "b:C:H:lS:uvV" |
5701 | #ifdef CONFIG_FEATURE_FDISK_BLKSIZE | ||
5702 | "s" | ||
5703 | #endif | ||
5704 | )) != -1) { | ||
5660 | switch (c) { | 5705 | switch (c) { |
5661 | case 'b': | 5706 | case 'b': |
5662 | /* Ugly: this sector size is really per device, | 5707 | /* Ugly: this sector size is really per device, |
@@ -5684,11 +5729,15 @@ int fdisk_main(int argc, char **argv) { | |||
5684 | user_sectors = 0; | 5729 | user_sectors = 0; |
5685 | break; | 5730 | break; |
5686 | case 'l': | 5731 | case 'l': |
5732 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
5687 | optl = 1; | 5733 | optl = 1; |
5734 | #endif | ||
5688 | break; | 5735 | break; |
5736 | #ifdef CONFIG_FEATURE_FDISK_BLKSIZE | ||
5689 | case 's': | 5737 | case 's': |
5690 | opts = 1; | 5738 | opts = 1; |
5691 | break; | 5739 | break; |
5740 | #endif | ||
5692 | case 'u': | 5741 | case 'u': |
5693 | display_in_cyl_units = 0; | 5742 | display_in_cyl_units = 0; |
5694 | break; | 5743 | break; |
@@ -5710,8 +5759,10 @@ int fdisk_main(int argc, char **argv) { | |||
5710 | " be used with one specified device\n")); | 5759 | " be used with one specified device\n")); |
5711 | #endif | 5760 | #endif |
5712 | 5761 | ||
5762 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
5713 | if (optl) { | 5763 | if (optl) { |
5714 | nowarn = 1; | 5764 | nowarn = 1; |
5765 | #endif | ||
5715 | type_open = O_RDONLY; | 5766 | type_open = O_RDONLY; |
5716 | if (argc > optind) { | 5767 | if (argc > optind) { |
5717 | int k; | 5768 | int k; |
@@ -5729,10 +5780,14 @@ int fdisk_main(int argc, char **argv) { | |||
5729 | tryprocpt(); | 5780 | tryprocpt(); |
5730 | } | 5781 | } |
5731 | return 0; | 5782 | return 0; |
5783 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
5732 | } | 5784 | } |
5785 | #endif | ||
5733 | 5786 | ||
5787 | #ifdef CONFIG_FEATURE_FDISK_BLKSIZE | ||
5734 | if (opts) { | 5788 | if (opts) { |
5735 | long size; | 5789 | long size; |
5790 | int j; | ||
5736 | 5791 | ||
5737 | nowarn = 1; | 5792 | nowarn = 1; |
5738 | type_open = O_RDONLY; | 5793 | type_open = O_RDONLY; |
@@ -5755,7 +5810,9 @@ int fdisk_main(int argc, char **argv) { | |||
5755 | } | 5810 | } |
5756 | return 0; | 5811 | return 0; |
5757 | } | 5812 | } |
5813 | #endif | ||
5758 | 5814 | ||
5815 | #ifdef CONFIG_FEATURE_FDISK_WRITABLE | ||
5759 | if (argc-optind == 1) | 5816 | if (argc-optind == 1) |
5760 | disk_device = argv[optind]; | 5817 | disk_device = argv[optind]; |
5761 | else | 5818 | else |
@@ -5828,9 +5885,11 @@ int fdisk_main(int argc, char **argv) { | |||
5828 | unknown_command(c); | 5885 | unknown_command(c); |
5829 | break; | 5886 | break; |
5830 | case 'd': | 5887 | case 'd': |
5831 | j = get_existing_partition(1, partitions); | 5888 | { |
5832 | if (j >= 0) | 5889 | int j = get_existing_partition(1, partitions); |
5833 | delete_partition(j); | 5890 | if (j >= 0) |
5891 | delete_partition(j); | ||
5892 | } | ||
5834 | break; | 5893 | break; |
5835 | case 'i': | 5894 | case 'i': |
5836 | #ifdef CONFIG_FEATURE_SGI_LABEL | 5895 | #ifdef CONFIG_FEATURE_SGI_LABEL |
@@ -5894,4 +5953,5 @@ int fdisk_main(int argc, char **argv) { | |||
5894 | } | 5953 | } |
5895 | } | 5954 | } |
5896 | return 0; | 5955 | return 0; |
5956 | #endif /* CONFIG_FEATURE_FDISK_WRITABLE */ | ||
5897 | } | 5957 | } |