1 // SPDX-License-Identifier: GPL-2.0
3 * fs/partitions/check.c
5 * Code extracted from drivers/block/genhd.c
6 * Copyright (C) 1991-1998 Linus Torvalds
7 * Re-organised Feb 1998 Russell King
9 * We now have independent partition support from the
10 * block drivers, which allows all the partition code to
11 * be grouped in one location, and it to be mostly self
14 * Added needed MAJORS for new pairs, {hdi,hdj}, {hdk,hdl}
17 #include <linux/slab.h>
18 #include <linux/vmalloc.h>
19 #include <linux/ctype.h>
20 #include <linux/genhd.h>
40 int warn_no_part
= 1; /*This is ugly: should make genhd removable media aware*/
42 static int (*check_part
[])(struct parsed_partitions
*) = {
44 * Probe partition formats with tables at disk address 0
45 * that also have an ADFS boot block at 0xdc0.
47 #ifdef CONFIG_ACORN_PARTITION_ICS
50 #ifdef CONFIG_ACORN_PARTITION_POWERTEC
51 adfspart_check_POWERTEC
,
53 #ifdef CONFIG_ACORN_PARTITION_EESOX
58 * Now move on to formats that only have partition info at
59 * disk address 0xdc0. Since these may also have stale
60 * PC/BIOS partition tables, they need to come before
63 #ifdef CONFIG_ACORN_PARTITION_CUMANA
64 adfspart_check_CUMANA
,
66 #ifdef CONFIG_ACORN_PARTITION_ADFS
70 #ifdef CONFIG_CMDLINE_PARTITION
73 #ifdef CONFIG_EFI_PARTITION
74 efi_partition
, /* this must come before msdos */
76 #ifdef CONFIG_SGI_PARTITION
79 #ifdef CONFIG_LDM_PARTITION
80 ldm_partition
, /* this must come before msdos */
82 #ifdef CONFIG_MSDOS_PARTITION
85 #ifdef CONFIG_OSF_PARTITION
88 #ifdef CONFIG_SUN_PARTITION
91 #ifdef CONFIG_AMIGA_PARTITION
94 #ifdef CONFIG_ATARI_PARTITION
97 #ifdef CONFIG_MAC_PARTITION
100 #ifdef CONFIG_ULTRIX_PARTITION
103 #ifdef CONFIG_IBM_PARTITION
106 #ifdef CONFIG_KARMA_PARTITION
109 #ifdef CONFIG_SYSV68_PARTITION
115 static struct parsed_partitions
*allocate_partitions(struct gendisk
*hd
)
117 struct parsed_partitions
*state
;
120 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
124 nr
= disk_max_parts(hd
);
125 state
->parts
= vzalloc(nr
* sizeof(state
->parts
[0]));
136 void free_partitions(struct parsed_partitions
*state
)
142 struct parsed_partitions
*
143 check_partition(struct gendisk
*hd
, struct block_device
*bdev
)
145 struct parsed_partitions
*state
;
148 state
= allocate_partitions(hd
);
151 state
->pp_buf
= (char *)__get_free_page(GFP_KERNEL
);
152 if (!state
->pp_buf
) {
153 free_partitions(state
);
156 state
->pp_buf
[0] = '\0';
159 disk_name(hd
, 0, state
->name
);
160 snprintf(state
->pp_buf
, PAGE_SIZE
, " %s:", state
->name
);
161 if (isdigit(state
->name
[strlen(state
->name
)-1]))
162 sprintf(state
->name
, "p");
165 while (!res
&& check_part
[i
]) {
166 memset(state
->parts
, 0, state
->limit
* sizeof(state
->parts
[0]));
167 res
= check_part
[i
++](state
);
169 /* We have hit an I/O error which we don't report now.
170 * But record it, and let the others do their job.
178 printk(KERN_INFO
"%s", state
->pp_buf
);
180 free_page((unsigned long)state
->pp_buf
);
183 if (state
->access_beyond_eod
)
186 /* The partition is unrecognized. So report I/O errors if there were any */
190 strlcat(state
->pp_buf
,
191 " unable to read partition table\n", PAGE_SIZE
);
192 printk(KERN_INFO
"%s", state
->pp_buf
);
195 free_page((unsigned long)state
->pp_buf
);
196 free_partitions(state
);