Skip to content

Commit d33b98f

Browse files
Stephen Warrenaxboe
authored andcommitted
block: partition: msdos: provide UUIDs for partitions
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 <swarren@nvidia.com> Cc: Tejun Heo <tj@kernel.org> Cc: Will Drewry <wad@chromium.org> Cc: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 283f8fc commit d33b98f

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

‎block/partitions/msdos.c‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ static int aix_magic_present(struct parsed_partitions *state, unsigned char *p)
9494
return ret;
9595
}
9696

97+
static void set_info(struct parsed_partitions *state, int slot,
98+
u32 disksig)
99+
{
100+
struct partition_meta_info *info = &state->parts[slot].info;
101+
102+
snprintf(info->uuid, sizeof(info->uuid), "%08x-%02x", disksig,
103+
slot);
104+
info->volname[0] = 0;
105+
state->parts[slot].has_info = true;
106+
}
107+
97108
/*
98109
* Create devices for each logical partition in an extended partition.
99110
* The logical partitions form a linked list, with each entry being
@@ -106,7 +117,8 @@ static int aix_magic_present(struct parsed_partitions *state, unsigned char *p)
106117
*/
107118

108119
static void parse_extended(struct parsed_partitions *state,
109-
sector_t first_sector, sector_t first_size)
120+
sector_t first_sector, sector_t first_size,
121+
u32 disksig)
110122
{
111123
struct partition *p;
112124
Sector sect;
@@ -166,6 +178,7 @@ static void parse_extended(struct parsed_partitions *state,
166178
}
167179

168180
put_partition(state, state->next, next, size);
181+
set_info(state, state->next, disksig);
169182
if (SYS_IND(p) == LINUX_RAID_PARTITION)
170183
state->parts[state->next].flags = ADDPART_FLAG_RAID;
171184
loopct = 0;
@@ -437,6 +450,7 @@ int msdos_partition(struct parsed_partitions *state)
437450
struct partition *p;
438451
struct fat_boot_sector *fb;
439452
int slot;
453+
u32 disksig;
440454

441455
data = read_part_sector(state, 0, &sect);
442456
if (!data)
@@ -491,6 +505,8 @@ int msdos_partition(struct parsed_partitions *state)
491505
#endif
492506
p = (struct partition *) (data + 0x1be);
493507

508+
disksig = le32_to_cpup((__le32 *)(data + 0x1b8));
509+
494510
/*
495511
* Look for partitions in two passes:
496512
* First find the primary and DOS-type extended partitions.
@@ -515,11 +531,12 @@ int msdos_partition(struct parsed_partitions *state)
515531
put_partition(state, slot, start, n);
516532

517533
strlcat(state->pp_buf, " <", PAGE_SIZE);
518-
parse_extended(state, start, size);
534+
parse_extended(state, start, size, disksig);
519535
strlcat(state->pp_buf, " >", PAGE_SIZE);
520536
continue;
521537
}
522538
put_partition(state, slot, start, size);
539+
set_info(state, slot, disksig);
523540
if (SYS_IND(p) == LINUX_RAID_PARTITION)
524541
state->parts[slot].flags = ADDPART_FLAG_RAID;
525542
if (SYS_IND(p) == DM6_PARTITION)

‎init/do_mounts.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ static dev_t devt_from_partuuid(const char *uuid_str)
189189
* used when disk name of partitioned disk ends on a digit.
190190
* 6) PARTUUID=00112233-4455-6677-8899-AABBCCDDEEFF representing the
191191
* unique id of a partition if the partition table provides it.
192+
* The UUID may be either an EFI/GPT UUID, or refer to an MSDOS
193+
* partition using the format SSSSSSSS-PP, where SSSSSSSS is a zero-
194+
* filled hex representation of the 32-bit "NT disk signature", and PP
195+
* is a zero-filled hex representation of the 1-based partition number.
192196
* 7) PARTUUID=<UUID>/PARTNROFF=<int> to select a partition in relation to
193197
* a partition with a known unique id.
194198
*

0 commit comments

Comments
 (0)