Skip to content

Commit

Permalink
block: partition: msdos: provide UUIDs for partitions
Browse files Browse the repository at this point in the history
The MSDOS/MBR partition table includes a 32-bit unique ID, often referred
to as the NT disk signature.  When combined with a partition number within
the table, this can form a unique ID similar in concept to EFI/GPT's
partition UUID.  Constructing and recording this value in struct
partition_meta_info allows MSDOS partitions to be referred to on the
kernel command-line using the following syntax:

root=PARTUUID=0002dd75-01

Signed-off-by: Stephen Warren <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: Will Drewry <[email protected]>
Cc: Kay Sievers <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
nvswarren authored and axboe committed Nov 23, 2012
1 parent 283f8fc commit d33b98f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
21 changes: 19 additions & 2 deletions block/partitions/msdos.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ static int aix_magic_present(struct parsed_partitions *state, unsigned char *p)
return ret;
}

static void set_info(struct parsed_partitions *state, int slot,
u32 disksig)
{
struct partition_meta_info *info = &state->parts[slot].info;

snprintf(info->uuid, sizeof(info->uuid), "%08x-%02x", disksig,
slot);
info->volname[0] = 0;
state->parts[slot].has_info = true;
}

/*
* Create devices for each logical partition in an extended partition.
* The logical partitions form a linked list, with each entry being
Expand All @@ -106,7 +117,8 @@ static int aix_magic_present(struct parsed_partitions *state, unsigned char *p)
*/

static void parse_extended(struct parsed_partitions *state,
sector_t first_sector, sector_t first_size)
sector_t first_sector, sector_t first_size,
u32 disksig)
{
struct partition *p;
Sector sect;
Expand Down Expand Up @@ -166,6 +178,7 @@ static void parse_extended(struct parsed_partitions *state,
}

put_partition(state, state->next, next, size);
set_info(state, state->next, disksig);
if (SYS_IND(p) == LINUX_RAID_PARTITION)
state->parts[state->next].flags = ADDPART_FLAG_RAID;
loopct = 0;
Expand Down Expand Up @@ -437,6 +450,7 @@ int msdos_partition(struct parsed_partitions *state)
struct partition *p;
struct fat_boot_sector *fb;
int slot;
u32 disksig;

data = read_part_sector(state, 0, &sect);
if (!data)
Expand Down Expand Up @@ -491,6 +505,8 @@ int msdos_partition(struct parsed_partitions *state)
#endif
p = (struct partition *) (data + 0x1be);

disksig = le32_to_cpup((__le32 *)(data + 0x1b8));

/*
* Look for partitions in two passes:
* First find the primary and DOS-type extended partitions.
Expand All @@ -515,11 +531,12 @@ int msdos_partition(struct parsed_partitions *state)
put_partition(state, slot, start, n);

strlcat(state->pp_buf, " <", PAGE_SIZE);
parse_extended(state, start, size);
parse_extended(state, start, size, disksig);
strlcat(state->pp_buf, " >", PAGE_SIZE);
continue;
}
put_partition(state, slot, start, size);
set_info(state, slot, disksig);
if (SYS_IND(p) == LINUX_RAID_PARTITION)
state->parts[slot].flags = ADDPART_FLAG_RAID;
if (SYS_IND(p) == DM6_PARTITION)
Expand Down
4 changes: 4 additions & 0 deletions init/do_mounts.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ static dev_t devt_from_partuuid(const char *uuid_str)
* used when disk name of partitioned disk ends on a digit.
* 6) PARTUUID=00112233-4455-6677-8899-AABBCCDDEEFF representing the
* unique id of a partition if the partition table provides it.
* The UUID may be either an EFI/GPT UUID, or refer to an MSDOS
* partition using the format SSSSSSSS-PP, where SSSSSSSS is a zero-
* filled hex representation of the 32-bit "NT disk signature", and PP
* is a zero-filled hex representation of the 1-based partition number.
* 7) PARTUUID=<UUID>/PARTNROFF=<int> to select a partition in relation to
* a partition with a known unique id.
*
Expand Down

0 comments on commit d33b98f

Please sign in to comment.