diff --git a/fdisks/fdisk.h b/fdisks/fdisk.h index 5aaf0f2eb..c8f94d331 100644 --- a/fdisks/fdisk.h +++ b/fdisks/fdisk.h @@ -8,30 +8,9 @@ * maybe included when fdisk.c and libfdisk code will be completely spit. */ #include "fdiskP.h" +#include "blkdev.h" -#define DEFAULT_SECTOR_SIZE 512 -#define MAX_SECTOR_SIZE 2048 -#define SECTOR_SIZE 512 /* still used in BSD code */ -#define MAXIMUM_PARTS 60 - -#define ACTIVE_FLAG 0x80 - -#define EXTENDED 0x05 -#define WIN98_EXTENDED 0x0f -#define LINUX_PARTITION 0x81 -#define LINUX_SWAP 0x82 -#define LINUX_NATIVE 0x83 -#define LINUX_EXTENDED 0x85 -#define LINUX_LVM 0x8e -#define LINUX_RAID 0xfd - - -#define LINE_LENGTH 800 - -#define IS_EXTENDED(i) \ - ((i) == EXTENDED || (i) == WIN98_EXTENDED || (i) == LINUX_EXTENDED) - extern void toggle_units(struct fdisk_context *cxt); static inline unsigned long diff --git a/fdisks/fdiskbsdlabel.c b/fdisks/fdiskbsdlabel.c index a1063f08e..6194afda4 100644 --- a/fdisks/fdiskbsdlabel.c +++ b/fdisks/fdiskbsdlabel.c @@ -56,6 +56,8 @@ #include "common.h" #include "fdisk.h" +#include "pt-mbr.h" + #define FREEBSD_PARTITION 0xa5 #define NETBSD_PARTITION 0xa9 #define DKTYPENAMES @@ -610,7 +612,7 @@ static int xbsd_write_bootstrap (struct fdisk_context *cxt) goto done; /* We need a backup of the disklabel (xbsd_dlabel might have changed). */ - d = &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE]; + d = &disklabelbuffer[BSD_LABELSECTOR * DEFAULT_SECTOR_SIZE]; memmove(&dl, d, sizeof(struct xbsd_disklabel)); /* The disklabel will be overwritten by 0's from bootxx anyway */ @@ -642,7 +644,7 @@ static int xbsd_write_bootstrap (struct fdisk_context *cxt) #else sector = dos_partition_get_start(xbsd_part); #endif - if (lseek(cxt->dev_fd, (off_t) sector * SECTOR_SIZE, SEEK_SET) == -1) { + if (lseek(cxt->dev_fd, (off_t) sector * DEFAULT_SECTOR_SIZE, SEEK_SET) == -1) { fdisk_warn(cxt, _("seek failed %s"), cxt->dev_path); rc = -errno; goto done; @@ -774,7 +776,7 @@ static int xbsd_initlabel (struct fdisk_context *cxt, #else d -> d_flags = 0; #endif - d -> d_secsize = SECTOR_SIZE; /* bytes/sector */ + d -> d_secsize = DEFAULT_SECTOR_SIZE; /* bytes/sector */ d -> d_nsectors = cxt->geom.sectors; /* sectors/track */ d -> d_ntracks = cxt->geom.heads; /* tracks/cylinder (heads) */ d -> d_ncylinders = cxt->geom.cylinders; @@ -837,13 +839,13 @@ xbsd_readlabel (struct fdisk_context *cxt, struct dos_partition *p, struct xbsd_ sector = 0; #endif - if (lseek (cxt->dev_fd, (off_t) sector * SECTOR_SIZE, SEEK_SET) == -1) + if (lseek (cxt->dev_fd, (off_t) sector * DEFAULT_SECTOR_SIZE, SEEK_SET) == -1) return 0; if (BSD_BBSIZE != read (cxt->dev_fd, disklabelbuffer, BSD_BBSIZE)) return 0; memmove (d, - &disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET], + &disklabelbuffer[BSD_LABELSECTOR * DEFAULT_SECTOR_SIZE + BSD_LABELOFFSET], sizeof (struct xbsd_disklabel)); if (d -> d_magic != BSD_DISKMAGIC || d -> d_magic2 != BSD_DISKMAGIC) @@ -882,7 +884,7 @@ xbsd_writelabel (struct fdisk_context *cxt, struct dos_partition *p, struct xbsd /* This is necessary if we want to write the bootstrap later, otherwise we'd write the old disklabel with the bootstrap. */ - memmove (&disklabelbuffer[BSD_LABELSECTOR * SECTOR_SIZE + BSD_LABELOFFSET], d, + memmove (&disklabelbuffer[BSD_LABELSECTOR * DEFAULT_SECTOR_SIZE + BSD_LABELOFFSET], d, sizeof (struct xbsd_disklabel)); #if defined (__alpha__) && BSD_LABELSECTOR == 0 @@ -896,7 +898,7 @@ xbsd_writelabel (struct fdisk_context *cxt, struct dos_partition *p, struct xbsd return -errno; } #else - if (lseek (cxt->dev_fd, (off_t) sector * SECTOR_SIZE + BSD_LABELOFFSET, + if (lseek (cxt->dev_fd, (off_t) sector * DEFAULT_SECTOR_SIZE + BSD_LABELOFFSET, SEEK_SET) == -1) { fdisk_warn(cxt, _("seek failed: %d"), cxt->dev_path); return -errno; diff --git a/fdisks/fdiskdoslabel.c b/fdisks/fdiskdoslabel.c index 67199eaea..37d27e2c9 100644 --- a/fdisks/fdiskdoslabel.c +++ b/fdisks/fdiskdoslabel.c @@ -10,9 +10,20 @@ #include "nls.h" #include "randutils.h" #include "common.h" +#include "pt-mbr.h" + #include "fdisk.h" #include "fdiskdoslabel.h" +#define MAXIMUM_PARTS 60 + +#define ACTIVE_FLAG 0x80 + +#define IS_EXTENDED(i) \ + ((i) == MBR_DOS_EXTENDED_PARTITION \ + || (i) == MBR_W95_EXTENDED_PARTITION \ + || (i) == MBR_LINUX_EXTENDED_PARTITION) + /* * per partition table entry data * @@ -742,7 +753,7 @@ static int add_partition(struct fdisk_context *cxt, int n, struct fdisk_parttype first[cxt->label->nparts_max], last[cxt->label->nparts_max]; - sys = t ? t->type : LINUX_NATIVE; + sys = t ? t->type : MBR_LINUX_DATA_PARTITION; if (p && p->sys_ind) { fdisk_warnx(cxt, _("Partition %d is already defined. Delete " @@ -908,10 +919,11 @@ static int add_partition(struct fdisk_context *cxt, int n, struct fdisk_parttype set_partition(cxt, n, 0, start, stop, sys); if (n > 4) { struct pte *pe = self_pte(cxt, n); - set_partition(cxt, n - 1, 1, pe->offset, stop, EXTENDED); + set_partition(cxt, n - 1, 1, pe->offset, stop, + MBR_DOS_EXTENDED_PARTITION); } - if (IS_EXTENDED (sys)) { + if (IS_EXTENDED(sys)) { struct pte *pe4 = self_pte(cxt, 4); struct pte *pen = self_pte(cxt, n); @@ -1079,7 +1091,7 @@ static int dos_verify_disklabel(struct fdisk_context *cxt) struct pte *pe = self_pte(cxt, i); p = self_partition(cxt, i); - if (p->sys_ind && !IS_EXTENDED (p->sys_ind)) { + if (p->sys_ind && !IS_EXTENDED(p->sys_ind)) { check_consistency(cxt, p, i); fdisk_warn_alignment(cxt, get_abs_partition_start(pe), i); if (get_abs_partition_start(pe) < first[i]) @@ -1193,7 +1205,7 @@ static int dos_add_partition( rc = add_partition(cxt, j, t); } else { char buf[16]; - char c, prompt[LINE_LENGTH]; + char c, prompt[BUFSIZ]; int dflt; dflt = (free_primary == 1 && !l->ext_offset) ? 'e' : 'p'; @@ -1228,7 +1240,8 @@ static int dos_add_partition( } else if (c == 'e' && !l->ext_offset) { int j = get_partition_unused_primary(cxt); if (j >= 0) { - t = fdisk_get_parttype_from_code(cxt, EXTENDED); + t = fdisk_get_parttype_from_code(cxt, + MBR_DOS_EXTENDED_PARTITION); rc = add_partition(cxt, j, t); } goto done; diff --git a/fdisks/fdiskdoslabel.h b/fdisks/fdiskdoslabel.h index a0878b225..05ee0a202 100644 --- a/fdisks/fdiskdoslabel.h +++ b/fdisks/fdiskdoslabel.h @@ -1,8 +1,6 @@ #ifndef FDISK_DOS_LABEL_H #define FDISK_DOS_LABEL_H -#include "pt-mbr.h" - extern struct dos_partition *fdisk_dos_get_partition( struct fdisk_context *cxt, size_t i);