fdisk.c (246e7a2b6494cd991b08ac669ed761ecea0cc98c) fdisk.c (fbcfcbbc5b5ce3a62649fe988fa15a5740a3df03)
1/*
2 * Mach Operating System
3 * Copyright (c) 1992 Carnegie Mellon University
4 * All Rights Reserved.
5 *
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the

--- 53 unchanged lines hidden (view full) ---

62 *
63 * 14-Dec-89 Robert Baron (rvb) at Carnegie-Mellon University
64 * Copyright (c) 1989 Robert. V. Baron
65 * Created.
66 */
67
68#define Decimal(str, ans, tmp, maxval) if (decimal(str, &tmp, ans, maxval)) ans = tmp
69
1/*
2 * Mach Operating System
3 * Copyright (c) 1992 Carnegie Mellon University
4 * All Rights Reserved.
5 *
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the

--- 53 unchanged lines hidden (view full) ---

62 *
63 * 14-Dec-89 Robert Baron (rvb) at Carnegie-Mellon University
64 * Copyright (c) 1989 Robert. V. Baron
65 * Created.
66 */
67
68#define Decimal(str, ans, tmp, maxval) if (decimal(str, &tmp, ans, maxval)) ans = tmp
69
70#define RoundCyl(x) ((((x) + cylsecs - 1) / cylsecs) * cylsecs)
71
72#define MAX_SEC_SIZE 2048 /* maximum section size that is supported */
73#define MIN_SEC_SIZE 512 /* the sector size to start sensing at */
74static int secsize = 0; /* the sensed sector size */
75
76static char *disk;
77
78static int cyls, sectors, heads, cylsecs;
79static u_int32_t disksecs;

--- 302 unchanged lines hidden (view full) ---

382
383 if (I_flag) {
384 read_s0();
385 reset_boot();
386 partp = &mboot.parts[0];
387 partp->dp_typ = DOSPTYP_386BSD;
388 partp->dp_flag = ACTIVE;
389 partp->dp_start = dos_sectors;
70#define MAX_SEC_SIZE 2048 /* maximum section size that is supported */
71#define MIN_SEC_SIZE 512 /* the sector size to start sensing at */
72static int secsize = 0; /* the sensed sector size */
73
74static char *disk;
75
76static int cyls, sectors, heads, cylsecs;
77static u_int32_t disksecs;

--- 302 unchanged lines hidden (view full) ---

380
381 if (I_flag) {
382 read_s0();
383 reset_boot();
384 partp = &mboot.parts[0];
385 partp->dp_typ = DOSPTYP_386BSD;
386 partp->dp_flag = ACTIVE;
387 partp->dp_start = dos_sectors;
390 partp->dp_size = (disksecs / dos_cylsecs) * dos_cylsecs -
388 partp->dp_size = rounddown(disksecs, dos_cylsecs) -
391 dos_sectors;
392 dos(partp);
393 if (v_flag)
394 print_s0();
395 if (!t_flag)
396 write_s0();
397 exit(0);
398 }

--- 136 unchanged lines hidden (view full) ---

535init_sector0(unsigned long start)
536{
537 struct dos_partition *partp = &mboot.parts[0];
538
539 init_boot();
540
541 partp->dp_typ = DOSPTYP_386BSD;
542 partp->dp_flag = ACTIVE;
389 dos_sectors;
390 dos(partp);
391 if (v_flag)
392 print_s0();
393 if (!t_flag)
394 write_s0();
395 exit(0);
396 }

--- 136 unchanged lines hidden (view full) ---

533init_sector0(unsigned long start)
534{
535 struct dos_partition *partp = &mboot.parts[0];
536
537 init_boot();
538
539 partp->dp_typ = DOSPTYP_386BSD;
540 partp->dp_flag = ACTIVE;
543 start = ((start + dos_sectors - 1) / dos_sectors) * dos_sectors;
541 start = roundup(start, dos_sectors);
544 if(start == 0)
545 start = dos_sectors;
546 partp->dp_start = start;
542 if(start == 0)
543 start = dos_sectors;
544 partp->dp_start = start;
547 partp->dp_size = (disksecs / dos_cylsecs) * dos_cylsecs - start;
545 partp->dp_size = rounddown(disksecs, dos_cylsecs) - start;
548
549 dos(partp);
550}
551
552static void
553change_part(int i)
554{
555 struct dos_partition *partp = &mboot.parts[i - 1];

--- 627 unchanged lines hidden (view full) ---

1183 struct dos_partition *prev_partp;
1184 prev_partp = ((struct dos_partition *)
1185 &mboot.parts) + i - 1;
1186 if (prev_partp->dp_typ != 0)
1187 partp->dp_start = prev_partp->dp_start +
1188 prev_partp->dp_size;
1189 }
1190 if (partp->dp_start % dos_sectors != 0) {
546
547 dos(partp);
548}
549
550static void
551change_part(int i)
552{
553 struct dos_partition *partp = &mboot.parts[i - 1];

--- 627 unchanged lines hidden (view full) ---

1181 struct dos_partition *prev_partp;
1182 prev_partp = ((struct dos_partition *)
1183 &mboot.parts) + i - 1;
1184 if (prev_partp->dp_typ != 0)
1185 partp->dp_start = prev_partp->dp_start +
1186 prev_partp->dp_size;
1187 }
1188 if (partp->dp_start % dos_sectors != 0) {
1191 prev_head_boundary = partp->dp_start /
1192 dos_sectors * dos_sectors;
1189 prev_head_boundary = rounddown(partp->dp_start,
1190 dos_sectors);
1193 partp->dp_start = prev_head_boundary +
1194 dos_sectors;
1195 }
1196 } else {
1197 partp->dp_start = str2sectors(command->args[2].arg_str);
1198 if (partp->dp_start == NO_DISK_SECTORS)
1199 break;
1200 }
1201 } else
1202 partp->dp_start = command->args[2].arg_val;
1203
1204 if (command->args[3].arg_str != NULL) {
1205 if (strcmp(command->args[3].arg_str, "*") == 0)
1191 partp->dp_start = prev_head_boundary +
1192 dos_sectors;
1193 }
1194 } else {
1195 partp->dp_start = str2sectors(command->args[2].arg_str);
1196 if (partp->dp_start == NO_DISK_SECTORS)
1197 break;
1198 }
1199 } else
1200 partp->dp_start = command->args[2].arg_val;
1201
1202 if (command->args[3].arg_str != NULL) {
1203 if (strcmp(command->args[3].arg_str, "*") == 0)
1206 partp->dp_size = ((disksecs / dos_cylsecs) *
1207 dos_cylsecs) - partp->dp_start;
1204 partp->dp_size = rounddown(disksecs, dos_cylsecs) -
1205 partp->dp_start;
1208 else {
1209 partp->dp_size = str2sectors(command->args[3].arg_str);
1210 if (partp->dp_size == NO_DISK_SECTORS)
1211 break;
1212 }
1206 else {
1207 partp->dp_size = str2sectors(command->args[3].arg_str);
1208 if (partp->dp_size == NO_DISK_SECTORS)
1209 break;
1210 }
1213 prev_cyl_boundary = ((partp->dp_start + partp->dp_size) /
1214 dos_cylsecs) * dos_cylsecs;
1211 prev_cyl_boundary = rounddown(partp->dp_start + partp->dp_size,
1212 dos_cylsecs);
1215 if (prev_cyl_boundary > partp->dp_start)
1216 partp->dp_size = prev_cyl_boundary - partp->dp_start;
1217 } else
1218 partp->dp_size = command->args[3].arg_val;
1219
1220 max_end = partp->dp_start + partp->dp_size;
1221
1222 if (partp->dp_typ == 0) {

--- 7 unchanged lines hidden (view full) ---

1230 status = 1;
1231 break;
1232 }
1233
1234 /*
1235 * Adjust start upwards, if necessary, to fall on a head boundary.
1236 */
1237 if (partp->dp_start % dos_sectors != 0) {
1213 if (prev_cyl_boundary > partp->dp_start)
1214 partp->dp_size = prev_cyl_boundary - partp->dp_start;
1215 } else
1216 partp->dp_size = command->args[3].arg_val;
1217
1218 max_end = partp->dp_start + partp->dp_size;
1219
1220 if (partp->dp_typ == 0) {

--- 7 unchanged lines hidden (view full) ---

1228 status = 1;
1229 break;
1230 }
1231
1232 /*
1233 * Adjust start upwards, if necessary, to fall on a head boundary.
1234 */
1235 if (partp->dp_start % dos_sectors != 0) {
1238 prev_head_boundary = partp->dp_start / dos_sectors * dos_sectors;
1236 prev_head_boundary = rounddown(partp->dp_start, dos_sectors);
1239 if (max_end < dos_sectors ||
1240 prev_head_boundary > max_end - dos_sectors) {
1241 /*
1242 * Can't go past end of partition
1243 */
1244 warnx(
1245 "ERROR line %d: unable to adjust start of partition %d to fall on\n\
1246 a head boundary",

--- 7 unchanged lines hidden (view full) ---

1254 (u_int)(prev_head_boundary + dos_sectors));
1255 partp->dp_start = prev_head_boundary + dos_sectors;
1256 }
1257
1258 /*
1259 * Adjust size downwards, if necessary, to fall on a cylinder
1260 * boundary.
1261 */
1237 if (max_end < dos_sectors ||
1238 prev_head_boundary > max_end - dos_sectors) {
1239 /*
1240 * Can't go past end of partition
1241 */
1242 warnx(
1243 "ERROR line %d: unable to adjust start of partition %d to fall on\n\
1244 a head boundary",

--- 7 unchanged lines hidden (view full) ---

1252 (u_int)(prev_head_boundary + dos_sectors));
1253 partp->dp_start = prev_head_boundary + dos_sectors;
1254 }
1255
1256 /*
1257 * Adjust size downwards, if necessary, to fall on a cylinder
1258 * boundary.
1259 */
1262 prev_cyl_boundary =
1263 ((partp->dp_start + partp->dp_size) / dos_cylsecs) * dos_cylsecs;
1260 prev_cyl_boundary = rounddown(partp->dp_start + partp->dp_size,
1261 dos_cylsecs);
1264 if (prev_cyl_boundary > partp->dp_start)
1265 adj_size = prev_cyl_boundary - partp->dp_start;
1266 else {
1267 warnx(
1268 "ERROR: could not adjust partition to start on a head boundary\n\
1269 and end on a cylinder boundary.");
1270 return (0);
1271 }

--- 174 unchanged lines hidden (view full) ---

1446 warnx("WARNING: this may confuse the BIOS or some operating systems");
1447 if (!ok("Correct this automatically?"))
1448 return (1);
1449
1450 /*
1451 * Adjust start upwards, if necessary, to fall on a head boundary.
1452 */
1453 if (start % dos_sectors != 0) {
1262 if (prev_cyl_boundary > partp->dp_start)
1263 adj_size = prev_cyl_boundary - partp->dp_start;
1264 else {
1265 warnx(
1266 "ERROR: could not adjust partition to start on a head boundary\n\
1267 and end on a cylinder boundary.");
1268 return (0);
1269 }

--- 174 unchanged lines hidden (view full) ---

1444 warnx("WARNING: this may confuse the BIOS or some operating systems");
1445 if (!ok("Correct this automatically?"))
1446 return (1);
1447
1448 /*
1449 * Adjust start upwards, if necessary, to fall on a head boundary.
1450 */
1451 if (start % dos_sectors != 0) {
1454 prev_head_boundary = start / dos_sectors * dos_sectors;
1452 prev_head_boundary = rounddown(start, dos_sectors);
1455 if (max_end < dos_sectors ||
1456 prev_head_boundary >= max_end - dos_sectors) {
1457 /*
1458 * Can't go past end of partition
1459 */
1460 warnx(
1461 "ERROR: unable to adjust start of partition to fall on a head boundary");
1462 return (0);
1463 }
1464 start = prev_head_boundary + dos_sectors;
1465 }
1466
1467 /*
1468 * Adjust size downwards, if necessary, to fall on a cylinder
1469 * boundary.
1470 */
1453 if (max_end < dos_sectors ||
1454 prev_head_boundary >= max_end - dos_sectors) {
1455 /*
1456 * Can't go past end of partition
1457 */
1458 warnx(
1459 "ERROR: unable to adjust start of partition to fall on a head boundary");
1460 return (0);
1461 }
1462 start = prev_head_boundary + dos_sectors;
1463 }
1464
1465 /*
1466 * Adjust size downwards, if necessary, to fall on a cylinder
1467 * boundary.
1468 */
1471 prev_cyl_boundary = ((start + size) / dos_cylsecs) * dos_cylsecs;
1469 prev_cyl_boundary = rounddown(start + size, dos_cylsecs);
1472 if (prev_cyl_boundary > start)
1473 size = prev_cyl_boundary - start;
1474 else {
1475 warnx("ERROR: could not adjust partition to start on a head boundary\n\
1476 and end on a cylinder boundary.");
1477 return (0);
1478 }
1479

--- 55 unchanged lines hidden ---
1470 if (prev_cyl_boundary > start)
1471 size = prev_cyl_boundary - start;
1472 else {
1473 warnx("ERROR: could not adjust partition to start on a head boundary\n\
1474 and end on a cylinder boundary.");
1475 return (0);
1476 }
1477

--- 55 unchanged lines hidden ---