return rc;
#if !defined (__alpha__) && !defined (__powerpc__) && !defined (__hppa__)
- begin = get_start_sect(xbsd_part);
- end = begin + get_nr_sects(xbsd_part) - 1;
+ begin = dos_partition_get_start(xbsd_part);
+ end = begin + dos_partition_get_size(xbsd_part) - 1;
#else
begin = 0;
end = xbsd_dlabel.d_secperunit - 1;
if (p && is_bsd_partition_type(p->sys_ind)) {
xbsd_part = p;
xbsd_part_index = t;
- ss = get_start_sect(xbsd_part);
+ ss = dos_partition_get_start(xbsd_part);
/* TODO - partname uses static buffer!!! */
cxt->dev_path = partname(cxt->parent->dev_path, t+1, 0);
sector = 0;
alpha_bootblock_checksum(disklabelbuffer);
#else
- sector = get_start_sect(xbsd_part);
+ sector = dos_partition_get_start(xbsd_part);
#endif
if (lseek(cxt->dev_fd, (off_t) sector * SECTOR_SIZE, SEEK_SET) == -1) {
fdisk_warn(cxt, _("seek failed %s"), cxt->dev_path);
d -> d_npartitions = 4;
pp = &d -> d_partitions[2]; /* Partition C should be
the NetBSD partition */
- pp -> p_offset = get_start_sect(p);
- pp -> p_size = get_nr_sects(p);
+ pp -> p_offset = dos_partition_get_start(p);
+ pp -> p_size = dos_partition_get_size(p);
pp -> p_fstype = BSD_FS_UNUSED;
pp = &d -> d_partitions[3]; /* Partition D should be
the whole disk */
/* p is used only to get the starting sector */
#if !defined (__alpha__)
- sector = (p ? get_start_sect(p) : 0);
+ sector = (p ? dos_partition_get_start(p) : 0);
#elif defined (__alpha__)
sector = 0;
#endif
unsigned int sector;
#if !defined (__alpha__) && !defined (__powerpc__) && !defined (__hppa__)
- sector = get_start_sect(p) + BSD_LABELSECTOR;
+ sector = dos_partition_get_start(p) + BSD_LABELSECTOR;
#else
sector = BSD_LABELSECTOR;
#endif
p = dos_get_pt_entry(k);
- xbsd_dlabel.d_partitions[i].p_size = get_nr_sects(p);
- xbsd_dlabel.d_partitions[i].p_offset = get_start_sect(p);
+ xbsd_dlabel.d_partitions[i].p_size = dos_partition_get_size(p);
+ xbsd_dlabel.d_partitions[i].p_offset = dos_partition_get_start(p);
xbsd_dlabel.d_partitions[i].p_fstype = xbsd_translate_fstype(p->sys_ind);
}
#endif
pe->pt_entry = pe->ex_entry = NULL;
}
-static void mbr_set_id(unsigned char *b, unsigned int id)
-{
- store4_little_endian(&b[440], id);
-}
-
-static void mbr_set_magic(unsigned char *b)
-{
- b[510] = 0x55;
- b[511] = 0xaa;
-}
-
-int mbr_is_valid_magic(unsigned char *b)
-{
- return (b[510] == 0x55 && b[511] == 0xaa);
-}
-
-static unsigned int mbr_get_id(const unsigned char *b)
-{
- return read4_little_endian(&b[440]);
-}
static void clear_partition(struct dos_partition *p)
{
p->eh = 0;
p->es = 0;
p->ec = 0;
- set_start_sect(p,0);
- set_nr_sects(p,0);
+ dos_partition_set_start(p,0);
+ dos_partition_set_size(p,0);
}
void dos_init(struct fdisk_context *cxt)
/* delete this link in the chain */
p = ptes[partnum-1].ex_entry;
*p = *q;
- set_start_sect(p, get_start_sect(q));
- set_nr_sects(p, get_nr_sects(q));
+ dos_partition_set_start(p, dos_partition_get_start(q));
+ dos_partition_set_size(p, dos_partition_get_size(q));
ptes[partnum-1].changed = 1;
} else if (cxt->label->nparts_max > 5) { /* 5 will be moved to 4 */
/* the first logical in a longer chain */
struct pte *pete = &ptes[5];
if (pete->pt_entry) /* prevent SEGFAULT */
- set_start_sect(pete->pt_entry,
+ dos_partition_set_start(pete->pt_entry,
get_partition_start(pete) -
extended_offset);
pete->offset = extended_offset;
pex->ex_entry = pex->pt_entry;
p = pex->pt_entry;
- if (!get_start_sect(p)) {
+ if (!dos_partition_get_start(p)) {
fprintf(stderr,
_("Bad offset in primary extended partition\n"));
return;
return;
}
- read_pte(cxt, cxt->label->nparts_max, extended_offset + get_start_sect(p));
+ read_pte(cxt, cxt->label->nparts_max, extended_offset + dos_partition_get_start(p));
if (!extended_offset)
- extended_offset = get_start_sect(p);
+ extended_offset = dos_partition_get_start(p);
q = p = pt_offset(pe->sectorbuffer, 0);
- for (i = 0; i < 4; i++, p++) if (get_nr_sects(p)) {
+ for (i = 0; i < 4; i++, p++) if (dos_partition_get_size(p)) {
if (IS_EXTENDED (p->sys_ind)) {
if (pe->ex_entry)
fprintf(stderr,
for (i = 4; i < cxt->label->nparts_max; i++) {
struct pte *pe = &ptes[i];
- if (!get_nr_sects(pe->pt_entry) &&
+ if (!dos_partition_get_size(pe->pt_entry) &&
(cxt->label->nparts_max > 5 || ptes[4].pt_entry->sys_ind)) {
printf(_("omitting empty partition (%zd)\n"), i+1);
dos_delete_partition(cxt, i);
}
p->boot_ind = 0;
p->sys_ind = sysid;
- set_start_sect(p, start - offset);
- set_nr_sects(p, stop - start + 1);
+ dos_partition_set_start(p, start - offset);
+ dos_partition_set_size(p, stop - start + 1);
if (!doext) {
struct fdisk_parttype *t = fdisk_get_parttype_from_code(cxt, sysid);
last[i] = 0;
} else {
first[i] = get_partition_start(pe);
- last[i] = first[i] + get_nr_sects(p) - 1;
+ last[i] = first[i] + dos_partition_get_size(p) - 1;
}
}
}
if (extended_offset) {
first[ext_index] = extended_offset;
- last[ext_index] = get_start_sect(q) +
- get_nr_sects(q) - 1;
+ last[ext_index] = dos_partition_get_start(q) +
+ dos_partition_get_size(q) - 1;
}
} else {
start = extended_offset + cxt->first_lba;
- limit = get_start_sect(q) + get_nr_sects(q) - 1;
+ limit = dos_partition_get_start(q) + dos_partition_get_size(q) - 1;
}
if (fdisk_context_use_cylinders(cxt))
for (i = 0; i < cxt->label->nparts_max; i++)
pes = p->es & 0x3f;
/* compute logical beginning (c, h, s) */
- long2chs(cxt, get_start_sect(p), &lbc, &lbh, &lbs);
+ long2chs(cxt, dos_partition_get_start(p), &lbc, &lbh, &lbs);
/* compute logical ending (c, h, s) */
- long2chs(cxt, get_start_sect(p) + get_nr_sects(p) - 1, &lec, &leh, &les);
+ long2chs(cxt, dos_partition_get_start(p) + dos_partition_get_size(p) - 1, &lec, &leh, &les);
/* Same physical / logical beginning? */
if (cxt->geom.cylinders <= 1024 && (pbc != lbc || pbh != lbh || pbs != lbs)) {
if (extended_offset) {
struct pte *pex = &ptes[ext_index];
- sector_t e_last = get_start_sect(pex->pt_entry) +
- get_nr_sects(pex->pt_entry) - 1;
+ sector_t e_last = dos_partition_get_start(pex->pt_entry) +
+ dos_partition_get_size(pex->pt_entry) - 1;
for (i = 4; i < cxt->label->nparts_max; i++) {
total++;
p = pe->pt_entry;
if (p && !is_cleared_partition(p)) {
- unsigned int psects = get_nr_sects(p);
+ unsigned int psects = dos_partition_get_size(p);
unsigned int pblocks = psects;
unsigned int podd = 0;
struct fdisk_parttype *type =
cylinder(p->bs, p->bc), p->eh,
sector(p->es),
cylinder(p->es, p->ec),
- (unsigned long) get_start_sect(p),
- (unsigned long) get_nr_sects(p), p->sys_ind);
+ (unsigned long) dos_partition_get_start(p),
+ (unsigned long) dos_partition_get_size(p), p->sys_ind);
if (p->sys_ind) {
check_consistency(cxt, p, i);
fdisk_warn_alignment(cxt, get_partition_start(pe), i);
ptes[j].offset = ojj;
ptes[j+1].offset = oj;
pj = ptes[j].pt_entry;
- set_start_sect(pj, get_start_sect(pj)+oj-ojj);
+ dos_partition_set_start(pj, dos_partition_get_start(pj)+oj-ojj);
pjj = ptes[j+1].pt_entry;
- set_start_sect(pjj, get_start_sect(pjj)+ojj-oj);
- set_start_sect(ptes[j-1].ex_entry,
+ dos_partition_set_start(pjj, dos_partition_get_start(pjj)+ojj-oj);
+ dos_partition_set_start(ptes[j-1].ex_entry,
ojj-extended_offset);
- set_start_sect(ptes[j].ex_entry,
+ dos_partition_set_start(ptes[j].ex_entry,
oj-extended_offset);
goto stage1;
}
for (j = 4; j < cxt->label->nparts_max - 1; j++) {
pj = ptes[j].pt_entry;
pjj = ptes[j+1].pt_entry;
- sj = get_start_sect(pj);
- sjj = get_start_sect(pjj);
+ sj = dos_partition_get_start(pj);
+ sjj = dos_partition_get_start(pjj);
oj = ptes[j].offset;
ojj = ptes[j+1].offset;
if (oj+sj > ojj+sjj) {
tmp = *pj;
*pj = *pjj;
*pjj = tmp;
- set_start_sect(pj, ojj+sjj-oj);
- set_start_sect(pjj, oj+sj-ojj);
+ dos_partition_set_start(pj, ojj+sjj-oj);
+ dos_partition_set_start(pjj, oj+sj-ojj);
goto stage2;
}
}
if (warn_geometry(cxt))
return;
- if (!p->sys_ind || !get_nr_sects(p) || IS_EXTENDED (p->sys_ind)) {
+ if (!p->sys_ind || !dos_partition_get_size(p) || IS_EXTENDED (p->sys_ind)) {
printf(_("Partition %d has no data area\n"), i + 1);
return;
}
if (!prev_p)
continue;
- end = get_partition_start(prev_pe) + get_nr_sects(prev_p);
+ end = get_partition_start(prev_pe) + dos_partition_get_size(prev_p);
if (!is_cleared_partition(prev_p) &&
end > free_start && end <= curr_start)
free_start = end;
}
- last = get_partition_start(pe) + get_nr_sects(p) - 1;
+ last = get_partition_start(pe) + dos_partition_get_size(p) - 1;
if (fdisk_ask_number(cxt, free_start, curr_start, last,
_("New beginning of data"), &res))
return;
new = res - pe->offset;
- if (new != get_nr_sects(p)) {
- unsigned int sects = get_nr_sects(p) + get_start_sect(p) - new;
- set_nr_sects(p, sects);
- set_start_sect(p, new);
+ if (new != dos_partition_get_size(p)) {
+ unsigned int sects = dos_partition_get_size(p) + dos_partition_get_start(p) - new;
+ dos_partition_set_size(p, sects);
+ dos_partition_set_start(p, new);
pe->changed = 1;
}
}
return ((unsigned int) b[510]) + (((unsigned int) b[511]) << 8);
}
-
-/* start_sect and nr_sects are stored little endian on all machines */
-/* moreover, they are not aligned correctly */
-static inline void store4_little_endian(unsigned char *cp, unsigned int val)
-{
- cp[0] = (val & 0xff);
- cp[1] = ((val >> 8) & 0xff);
- cp[2] = ((val >> 16) & 0xff);
- cp[3] = ((val >> 24) & 0xff);
-}
-
-static inline unsigned int read4_little_endian(const unsigned char *cp)
-{
- return (unsigned int)(cp[0]) + ((unsigned int)(cp[1]) << 8)
- + ((unsigned int)(cp[2]) << 16)
- + ((unsigned int)(cp[3]) << 24);
-}
-
-static inline sector_t get_nr_sects(struct dos_partition *p)
-{
- return read4_little_endian(p->nr_sects);
-}
-
-static inline void set_nr_sects(struct dos_partition *p, sector_t nr_sects)
-{
- store4_little_endian(p->nr_sects, nr_sects);
-}
-
-static inline void set_start_sect(struct dos_partition *p, unsigned int start_sect)
-{
- store4_little_endian(p->start_sect, start_sect);
-}
-
-static inline sector_t get_start_sect(struct dos_partition *p)
-{
- return read4_little_endian(p->start_sect);
-}
-
static inline sector_t get_partition_start(struct pte *pe)
{
- return pe->offset + get_start_sect(pe->pt_entry);
+ return pe->offset + dos_partition_get_start(pe->pt_entry);
}
static inline int is_cleared_partition(struct dos_partition *p)
{
return !(!p || p->boot_ind || p->bh || p->bs || p->bc ||
p->sys_ind || p->eh || p->es || p->ec ||
- get_start_sect(p) || get_nr_sects(p));
+ dos_partition_get_start(p) || dos_partition_get_size(p));
}
extern struct dos_partition *dos_get_pt_entry(int);
extern void dos_move_begin(struct fdisk_context *cxt, int i);
extern void dos_toggle_active(struct fdisk_context *cxt, int i);
-extern int mbr_is_valid_magic(unsigned char *b);
-
#define is_dos_compatible(_x) \
(fdisk_is_disklabel(_x, DOS) && \
fdisk_dos_is_compatible(fdisk_context_get_label(_x, NULL)))
#define MBR_PT_OFFSET 0x1be
/* assemble badly aligned little endian integer */
-static inline unsigned int __dos_assemble4le(const unsigned char *p)
+static inline unsigned int __dos_assemble_4le(const unsigned char *p)
{
return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
}
p[3] = ((val >> 24) & 0xff);
}
-static inline unsigned int dos_partition_start(struct dos_partition *p)
+static inline unsigned int dos_partition_get_start(struct dos_partition *p)
{
- return __dos_assemble4le(&(p->start_sect[0]));
+ return __dos_assemble_4le(&(p->start_sect[0]));
}
-static inline unsigned int dos_partition_size(struct dos_partition *p)
+static inline void dos_partition_set_start(struct dos_partition *p, unsigned int n)
{
- return __dos_assemble4le(&(p->nr_sects[0]));
+ __dos_store_4le(p->start_sect, n);
}
-static inline int is_valid_mbr_signature(const unsigned char *mbr)
+static inline unsigned int dos_partition_get_size(struct dos_partition *p)
+{
+ return __dos_assemble_4le(&(p->nr_sects[0]));
+}
+
+static inline void dos_partition_set_size(struct dos_partition *p, unsigned int n)
+{
+ __dos_store_4le(p->nr_sects, n);
+}
+
+static inline int mbr_is_valid_magic(const unsigned char *mbr)
{
return mbr[510] == 0x55 && mbr[511] == 0xaa ? 1 : 0;
}
-static inline unsigned int dos_parttable_id(const unsigned char *mbr)
+static inline void mbr_set_magic(unsigned char *b)
+{
+ b[510] = 0x55;
+ b[511] = 0xaa;
+}
+
+static inline unsigned int mbr_get_id(const unsigned char *mbr)
+{
+ return __dos_assemble_4le(&mbr[440]);
+}
+
+static inline void mbr_set_id(unsigned char *b, unsigned int id)
{
- return __dos_assemble4le(&mbr[440]);
+ __dos_store_4le(&b[440], id);
}
enum {
if (!data)
goto leave; /* malformed partition? */
- if (!is_valid_mbr_signature(data))
+ if (!mbr_is_valid_magic(data))
goto leave;
p0 = (struct dos_partition *) (data + MBR_PT_OFFSET);
blkid_partition par;
/* the start is relative to the parental ext.partition */
- start = dos_partition_start(p) * ssf;
- size = dos_partition_size(p) * ssf;
+ start = dos_partition_get_start(p) * ssf;
+ size = dos_partition_get_size(p) * ssf;
abs_start = cur_start + start; /* absolute start */
if (!size || is_extended(p))
* is junk.
*/
for (p = p0, i = 0; i < 4; i++, p++) {
- start = dos_partition_start(p) * ssf;
- size = dos_partition_size(p) * ssf;
+ start = dos_partition_get_start(p) * ssf;
+ size = dos_partition_get_size(p) * ssf;
if (size && is_extended(p))
break;
blkid_probe_use_wiper(pr, MBR_PT_OFFSET,
512 - MBR_PT_OFFSET);
- id = dos_parttable_id(data);
+ id = mbr_get_id(data);
if (id)
snprintf(idstr, sizeof(idstr), "%08x", id);
for (p = p0, i = 0; i < 4; i++, p++) {
blkid_partition par;
- start = dos_partition_start(p) * ssf;
- size = dos_partition_size(p) * ssf;
+ start = dos_partition_get_start(p) * ssf;
+ size = dos_partition_get_size(p) * ssf;
if (!size) {
/* Linux kernel ignores empty partitions, but partno for
/* Parse logical partitions */
for (p = p0, i = 0; i < 4; i++, p++) {
- start = dos_partition_start(p) * ssf;
- size = dos_partition_size(p) * ssf;
+ start = dos_partition_get_start(p) * ssf;
+ size = dos_partition_get_size(p) * ssf;
if (!size)
continue;
for (p = p0, i = 0; i < 4; i++, p++) {
size_t n;
- if (!dos_partition_size(p) || is_extended(p))
+ if (!dos_partition_get_size(p) || is_extended(p))
continue;
for (n = 0; n < ARRAY_SIZE(dos_nested); n++) {