libblkid: move MBR definitions to include/pt-mbr.h
This commit is contained in:
parent
f540fe15c3
commit
f917738efa
|
@ -1,6 +1,43 @@
|
|||
#ifndef UTIL_LINUX_PT_MBR_H
|
||||
#define UTIL_LINUX_PT_MBR_H
|
||||
|
||||
struct dos_partition {
|
||||
unsigned char boot_ind; /* 0x80 - active */
|
||||
unsigned char bh, bs, bc; /* begin CHS */
|
||||
unsigned char sys_type;
|
||||
unsigned char eh, es, ec; /* end CHS */
|
||||
unsigned char start_sect[4];
|
||||
unsigned char nr_sects[4];
|
||||
} __attribute__((packed));
|
||||
|
||||
#define MBR_PT_OFFSET 0x1be
|
||||
|
||||
/* assemble badly aligned little endian integer */
|
||||
static inline unsigned int __dos_assemble4le(const unsigned char *p)
|
||||
{
|
||||
return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
|
||||
}
|
||||
|
||||
static inline unsigned int dos_partition_start(struct dos_partition *p)
|
||||
{
|
||||
return __dos_assemble4le(&(p->start_sect[0]));
|
||||
}
|
||||
|
||||
static inline unsigned int dos_partition_size(struct dos_partition *p)
|
||||
{
|
||||
return __dos_assemble4le(&(p->nr_sects[0]));
|
||||
}
|
||||
|
||||
static inline int is_valid_mbr_signature(const unsigned char *mbr)
|
||||
{
|
||||
return mbr[510] == 0x55 && mbr[511] == 0xaa ? 1 : 0;
|
||||
}
|
||||
|
||||
static inline unsigned int dos_parttable_id(const unsigned char *mbr)
|
||||
{
|
||||
return __dos_assemble4le(&mbr[440]);
|
||||
}
|
||||
|
||||
enum {
|
||||
MBR_EMPTY_PARTITION = 0x00,
|
||||
MBR_FAT12_PARTITION = 0x01,
|
||||
|
|
|
@ -32,7 +32,6 @@ libblkid_la_SOURCES = \
|
|||
libblkid/src/partitions/aix.h \
|
||||
libblkid/src/partitions/bsd.c \
|
||||
libblkid/src/partitions/dos.c \
|
||||
libblkid/src/partitions/dos.h \
|
||||
libblkid/src/partitions/gpt.c \
|
||||
libblkid/src/partitions/mac.c \
|
||||
libblkid/src/partitions/minix.c \
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#include "partitions.h"
|
||||
#include "dos.h"
|
||||
#include "aix.h"
|
||||
|
||||
/* see superblocks/vfat.c */
|
||||
|
@ -61,7 +60,7 @@ static int parse_dos_extended(blkid_probe pr, blkid_parttable tab,
|
|||
if (!is_valid_mbr_signature(data))
|
||||
goto leave;
|
||||
|
||||
p0 = (struct dos_partition *) (data + BLKID_MSDOS_PT_OFFSET);
|
||||
p0 = (struct dos_partition *) (data + MBR_PT_OFFSET);
|
||||
|
||||
/* Usually, the first entry is the real data partition,
|
||||
* the 2nd entry is the next extended partition, or empty,
|
||||
|
@ -160,7 +159,7 @@ static int probe_dos_pt(blkid_probe pr,
|
|||
goto nothing;
|
||||
}
|
||||
|
||||
p0 = (struct dos_partition *) (data + BLKID_MSDOS_PT_OFFSET);
|
||||
p0 = (struct dos_partition *) (data + MBR_PT_OFFSET);
|
||||
|
||||
/*
|
||||
* Reject PT where boot indicator is not 0 or 0x80.
|
||||
|
@ -181,8 +180,8 @@ static int probe_dos_pt(blkid_probe pr,
|
|||
}
|
||||
}
|
||||
|
||||
blkid_probe_use_wiper(pr, BLKID_MSDOS_PT_OFFSET,
|
||||
512 - BLKID_MSDOS_PT_OFFSET);
|
||||
blkid_probe_use_wiper(pr, MBR_PT_OFFSET,
|
||||
512 - MBR_PT_OFFSET);
|
||||
|
||||
id = dos_parttable_id(data);
|
||||
if (id)
|
||||
|
@ -207,7 +206,7 @@ static int probe_dos_pt(blkid_probe pr,
|
|||
ssf = blkid_probe_get_sectorsize(pr) / 512;
|
||||
|
||||
/* allocate a new partition table */
|
||||
tab = blkid_partlist_new_parttable(ls, "dos", BLKID_MSDOS_PT_OFFSET);
|
||||
tab = blkid_partlist_new_parttable(ls, "dos", MBR_PT_OFFSET);
|
||||
if (!tab)
|
||||
goto err;
|
||||
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
#ifndef BLKID_PARTITIONS_DOS_H
|
||||
#define BLKID_PARTITIONS_DOS_H
|
||||
|
||||
struct dos_partition {
|
||||
unsigned char boot_ind; /* 0x80 - active */
|
||||
unsigned char bh, bs, bc; /* begin CHS */
|
||||
unsigned char sys_type;
|
||||
unsigned char eh, es, ec; /* end CHS */
|
||||
unsigned char start_sect[4];
|
||||
unsigned char nr_sects[4];
|
||||
} __attribute__((packed));
|
||||
|
||||
#define BLKID_MSDOS_PT_OFFSET 0x1be
|
||||
|
||||
/* assemble badly aligned little endian integer */
|
||||
static inline unsigned int assemble4le(const unsigned char *p)
|
||||
{
|
||||
return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
|
||||
}
|
||||
|
||||
static inline unsigned int dos_partition_start(struct dos_partition *p)
|
||||
{
|
||||
return assemble4le(&(p->start_sect[0]));
|
||||
}
|
||||
|
||||
static inline unsigned int dos_partition_size(struct dos_partition *p)
|
||||
{
|
||||
return assemble4le(&(p->nr_sects[0]));
|
||||
}
|
||||
|
||||
static inline int is_valid_mbr_signature(const unsigned char *mbr)
|
||||
{
|
||||
return mbr[510] == 0x55 && mbr[511] == 0xaa ? 1 : 0;
|
||||
}
|
||||
|
||||
static inline unsigned int dos_parttable_id(const unsigned char *mbr)
|
||||
{
|
||||
return assemble4le(&mbr[440]);
|
||||
}
|
||||
|
||||
#endif /* BLKID_PARTITIONS_DOS_H */
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
#include "partitions.h"
|
||||
#include "crc32.h"
|
||||
#include "dos.h"
|
||||
|
||||
#define GPT_PRIMARY_LBA 1
|
||||
|
||||
|
@ -173,7 +172,7 @@ static int is_pmbr_valid(blkid_probe pr)
|
|||
if (!is_valid_mbr_signature(data))
|
||||
goto failed;
|
||||
|
||||
p = (struct dos_partition *) (data + BLKID_MSDOS_PT_OFFSET);
|
||||
p = (struct dos_partition *) (data + MBR_PT_OFFSET);
|
||||
|
||||
for (i = 0; i < 4; i++, p++) {
|
||||
if (p->sys_type == MBR_GPT_PARTITION)
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#include "partitions.h"
|
||||
#include "dos.h"
|
||||
#include "minix.h"
|
||||
|
||||
static int probe_minix_pt(blkid_probe pr,
|
||||
|
@ -47,9 +46,9 @@ static int probe_minix_pt(blkid_probe pr,
|
|||
/* caller does not ask for details about partitions */
|
||||
return 0;
|
||||
|
||||
p = (struct dos_partition *) (data + BLKID_MSDOS_PT_OFFSET);
|
||||
p = (struct dos_partition *) (data + MBR_PT_OFFSET);
|
||||
|
||||
tab = blkid_partlist_new_parttable(ls, "minix", BLKID_MSDOS_PT_OFFSET);
|
||||
tab = blkid_partlist_new_parttable(ls, "minix", MBR_PT_OFFSET);
|
||||
if (!tab)
|
||||
goto err;
|
||||
|
||||
|
|
Loading…
Reference in New Issue