Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

block: merge partition-generic.c and check.c

Merge block/partition-generic.c and block/partitions/check.c into
a single block/partitions/core.c as the content is closely related
and both files are tiny.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
387048bf 3f4fc59c

+166 -202
+1 -2
block/Makefile
··· 8 8 blk-exec.o blk-merge.o blk-softirq.o blk-timeout.o \ 9 9 blk-lib.o blk-mq.o blk-mq-tag.o blk-stat.o \ 10 10 blk-mq-sysfs.o blk-mq-cpumap.o blk-mq-sched.o ioctl.o \ 11 - genhd.o partition-generic.o ioprio.o \ 12 - badblocks.o partitions/ blk-rq-qos.o 11 + genhd.o ioprio.o badblocks.o partitions/ blk-rq-qos.o 13 12 14 13 obj-$(CONFIG_BOUNCE) += bounce.o 15 14 obj-$(CONFIG_BLK_SCSI_REQUEST) += scsi_ioctl.o
+164 -14
block/partition-generic.c block/partitions/core.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 2 /* 3 - * Code extracted from drivers/block/genhd.c 4 - * Copyright (C) 1991-1998 Linus Torvalds 5 - * Re-organised Feb 1998 Russell King 6 - * 7 - * We now have independent partition support from the 8 - * block drivers, which allows all the partition code to 9 - * be grouped in one location, and it to be mostly self 10 - * contained. 3 + * Copyright (C) 1991-1998 Linus Torvalds 4 + * Re-organised Feb 1998 Russell King 11 5 */ 12 - 13 - #include <linux/init.h> 14 - #include <linux/module.h> 15 6 #include <linux/fs.h> 16 7 #include <linux/slab.h> 17 - #include <linux/kmod.h> 18 8 #include <linux/ctype.h> 19 9 #include <linux/genhd.h> 10 + #include <linux/vmalloc.h> 20 11 #include <linux/blktrace_api.h> 21 12 #include <linux/raid/detect.h> 22 - #include "blk.h" 13 + #include "../blk.h" 14 + #include "check.h" 23 15 24 - #include "partitions/check.h" 16 + static int (*check_part[])(struct parsed_partitions *) = { 17 + /* 18 + * Probe partition formats with tables at disk address 0 19 + * that also have an ADFS boot block at 0xdc0. 20 + */ 21 + #ifdef CONFIG_ACORN_PARTITION_ICS 22 + adfspart_check_ICS, 23 + #endif 24 + #ifdef CONFIG_ACORN_PARTITION_POWERTEC 25 + adfspart_check_POWERTEC, 26 + #endif 27 + #ifdef CONFIG_ACORN_PARTITION_EESOX 28 + adfspart_check_EESOX, 29 + #endif 30 + 31 + /* 32 + * Now move on to formats that only have partition info at 33 + * disk address 0xdc0. Since these may also have stale 34 + * PC/BIOS partition tables, they need to come before 35 + * the msdos entry. 36 + */ 37 + #ifdef CONFIG_ACORN_PARTITION_CUMANA 38 + adfspart_check_CUMANA, 39 + #endif 40 + #ifdef CONFIG_ACORN_PARTITION_ADFS 41 + adfspart_check_ADFS, 42 + #endif 43 + 44 + #ifdef CONFIG_CMDLINE_PARTITION 45 + cmdline_partition, 46 + #endif 47 + #ifdef CONFIG_EFI_PARTITION 48 + efi_partition, /* this must come before msdos */ 49 + #endif 50 + #ifdef CONFIG_SGI_PARTITION 51 + sgi_partition, 52 + #endif 53 + #ifdef CONFIG_LDM_PARTITION 54 + ldm_partition, /* this must come before msdos */ 55 + #endif 56 + #ifdef CONFIG_MSDOS_PARTITION 57 + msdos_partition, 58 + #endif 59 + #ifdef CONFIG_OSF_PARTITION 60 + osf_partition, 61 + #endif 62 + #ifdef CONFIG_SUN_PARTITION 63 + sun_partition, 64 + #endif 65 + #ifdef CONFIG_AMIGA_PARTITION 66 + amiga_partition, 67 + #endif 68 + #ifdef CONFIG_ATARI_PARTITION 69 + atari_partition, 70 + #endif 71 + #ifdef CONFIG_MAC_PARTITION 72 + mac_partition, 73 + #endif 74 + #ifdef CONFIG_ULTRIX_PARTITION 75 + ultrix_partition, 76 + #endif 77 + #ifdef CONFIG_IBM_PARTITION 78 + ibm_partition, 79 + #endif 80 + #ifdef CONFIG_KARMA_PARTITION 81 + karma_partition, 82 + #endif 83 + #ifdef CONFIG_SYSV68_PARTITION 84 + sysv68_partition, 85 + #endif 86 + NULL 87 + }; 88 + 89 + static struct parsed_partitions *allocate_partitions(struct gendisk *hd) 90 + { 91 + struct parsed_partitions *state; 92 + int nr; 93 + 94 + state = kzalloc(sizeof(*state), GFP_KERNEL); 95 + if (!state) 96 + return NULL; 97 + 98 + nr = disk_max_parts(hd); 99 + state->parts = vzalloc(array_size(nr, sizeof(state->parts[0]))); 100 + if (!state->parts) { 101 + kfree(state); 102 + return NULL; 103 + } 104 + 105 + state->limit = nr; 106 + 107 + return state; 108 + } 109 + 110 + static void free_partitions(struct parsed_partitions *state) 111 + { 112 + vfree(state->parts); 113 + kfree(state); 114 + } 115 + 116 + static struct parsed_partitions *check_partition(struct gendisk *hd, 117 + struct block_device *bdev) 118 + { 119 + struct parsed_partitions *state; 120 + int i, res, err; 121 + 122 + state = allocate_partitions(hd); 123 + if (!state) 124 + return NULL; 125 + state->pp_buf = (char *)__get_free_page(GFP_KERNEL); 126 + if (!state->pp_buf) { 127 + free_partitions(state); 128 + return NULL; 129 + } 130 + state->pp_buf[0] = '\0'; 131 + 132 + state->bdev = bdev; 133 + disk_name(hd, 0, state->name); 134 + snprintf(state->pp_buf, PAGE_SIZE, " %s:", state->name); 135 + if (isdigit(state->name[strlen(state->name)-1])) 136 + sprintf(state->name, "p"); 137 + 138 + i = res = err = 0; 139 + while (!res && check_part[i]) { 140 + memset(state->parts, 0, state->limit * sizeof(state->parts[0])); 141 + res = check_part[i++](state); 142 + if (res < 0) { 143 + /* 144 + * We have hit an I/O error which we don't report now. 145 + * But record it, and let the others do their job. 146 + */ 147 + err = res; 148 + res = 0; 149 + } 150 + 151 + } 152 + if (res > 0) { 153 + printk(KERN_INFO "%s", state->pp_buf); 154 + 155 + free_page((unsigned long)state->pp_buf); 156 + return state; 157 + } 158 + if (state->access_beyond_eod) 159 + err = -ENOSPC; 160 + /* 161 + * The partition is unrecognized. So report I/O errors if there were any 162 + */ 163 + if (err) 164 + res = err; 165 + if (res) { 166 + strlcat(state->pp_buf, 167 + " unable to read partition table\n", PAGE_SIZE); 168 + printk(KERN_INFO "%s", state->pp_buf); 169 + } 170 + 171 + free_page((unsigned long)state->pp_buf); 172 + free_partitions(state); 173 + return ERR_PTR(res); 174 + } 25 175 26 176 static ssize_t part_partition_show(struct device *dev, 27 177 struct device_attribute *attr, char *buf)
+1 -2
block/partitions/Makefile
··· 3 3 # Makefile for the linux kernel. 4 4 # 5 5 6 - obj-$(CONFIG_BLOCK) := check.o 7 - 6 + obj-$(CONFIG_BLOCK) += core.o 8 7 obj-$(CONFIG_ACORN_PARTITION) += acorn.o 9 8 obj-$(CONFIG_AMIGA_PARTITION) += amiga.o 10 9 obj-$(CONFIG_ATARI_PARTITION) += atari.o
-179
block/partitions/check.c
··· 1 - // SPDX-License-Identifier: GPL-2.0 2 - /* 3 - * fs/partitions/check.c 4 - * 5 - * Code extracted from drivers/block/genhd.c 6 - * Copyright (C) 1991-1998 Linus Torvalds 7 - * Re-organised Feb 1998 Russell King 8 - * 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 12 - * contained. 13 - * 14 - * Added needed MAJORS for new pairs, {hdi,hdj}, {hdk,hdl} 15 - */ 16 - 17 - #include <linux/slab.h> 18 - #include <linux/vmalloc.h> 19 - #include <linux/ctype.h> 20 - #include <linux/genhd.h> 21 - 22 - #include "check.h" 23 - 24 - static int (*check_part[])(struct parsed_partitions *) = { 25 - /* 26 - * Probe partition formats with tables at disk address 0 27 - * that also have an ADFS boot block at 0xdc0. 28 - */ 29 - #ifdef CONFIG_ACORN_PARTITION_ICS 30 - adfspart_check_ICS, 31 - #endif 32 - #ifdef CONFIG_ACORN_PARTITION_POWERTEC 33 - adfspart_check_POWERTEC, 34 - #endif 35 - #ifdef CONFIG_ACORN_PARTITION_EESOX 36 - adfspart_check_EESOX, 37 - #endif 38 - 39 - /* 40 - * Now move on to formats that only have partition info at 41 - * disk address 0xdc0. Since these may also have stale 42 - * PC/BIOS partition tables, they need to come before 43 - * the msdos entry. 44 - */ 45 - #ifdef CONFIG_ACORN_PARTITION_CUMANA 46 - adfspart_check_CUMANA, 47 - #endif 48 - #ifdef CONFIG_ACORN_PARTITION_ADFS 49 - adfspart_check_ADFS, 50 - #endif 51 - 52 - #ifdef CONFIG_CMDLINE_PARTITION 53 - cmdline_partition, 54 - #endif 55 - #ifdef CONFIG_EFI_PARTITION 56 - efi_partition, /* this must come before msdos */ 57 - #endif 58 - #ifdef CONFIG_SGI_PARTITION 59 - sgi_partition, 60 - #endif 61 - #ifdef CONFIG_LDM_PARTITION 62 - ldm_partition, /* this must come before msdos */ 63 - #endif 64 - #ifdef CONFIG_MSDOS_PARTITION 65 - msdos_partition, 66 - #endif 67 - #ifdef CONFIG_OSF_PARTITION 68 - osf_partition, 69 - #endif 70 - #ifdef CONFIG_SUN_PARTITION 71 - sun_partition, 72 - #endif 73 - #ifdef CONFIG_AMIGA_PARTITION 74 - amiga_partition, 75 - #endif 76 - #ifdef CONFIG_ATARI_PARTITION 77 - atari_partition, 78 - #endif 79 - #ifdef CONFIG_MAC_PARTITION 80 - mac_partition, 81 - #endif 82 - #ifdef CONFIG_ULTRIX_PARTITION 83 - ultrix_partition, 84 - #endif 85 - #ifdef CONFIG_IBM_PARTITION 86 - ibm_partition, 87 - #endif 88 - #ifdef CONFIG_KARMA_PARTITION 89 - karma_partition, 90 - #endif 91 - #ifdef CONFIG_SYSV68_PARTITION 92 - sysv68_partition, 93 - #endif 94 - NULL 95 - }; 96 - 97 - static struct parsed_partitions *allocate_partitions(struct gendisk *hd) 98 - { 99 - struct parsed_partitions *state; 100 - int nr; 101 - 102 - state = kzalloc(sizeof(*state), GFP_KERNEL); 103 - if (!state) 104 - return NULL; 105 - 106 - nr = disk_max_parts(hd); 107 - state->parts = vzalloc(array_size(nr, sizeof(state->parts[0]))); 108 - if (!state->parts) { 109 - kfree(state); 110 - return NULL; 111 - } 112 - 113 - state->limit = nr; 114 - 115 - return state; 116 - } 117 - 118 - void free_partitions(struct parsed_partitions *state) 119 - { 120 - vfree(state->parts); 121 - kfree(state); 122 - } 123 - 124 - struct parsed_partitions * 125 - check_partition(struct gendisk *hd, struct block_device *bdev) 126 - { 127 - struct parsed_partitions *state; 128 - int i, res, err; 129 - 130 - state = allocate_partitions(hd); 131 - if (!state) 132 - return NULL; 133 - state->pp_buf = (char *)__get_free_page(GFP_KERNEL); 134 - if (!state->pp_buf) { 135 - free_partitions(state); 136 - return NULL; 137 - } 138 - state->pp_buf[0] = '\0'; 139 - 140 - state->bdev = bdev; 141 - disk_name(hd, 0, state->name); 142 - snprintf(state->pp_buf, PAGE_SIZE, " %s:", state->name); 143 - if (isdigit(state->name[strlen(state->name)-1])) 144 - sprintf(state->name, "p"); 145 - 146 - i = res = err = 0; 147 - while (!res && check_part[i]) { 148 - memset(state->parts, 0, state->limit * sizeof(state->parts[0])); 149 - res = check_part[i++](state); 150 - if (res < 0) { 151 - /* We have hit an I/O error which we don't report now. 152 - * But record it, and let the others do their job. 153 - */ 154 - err = res; 155 - res = 0; 156 - } 157 - 158 - } 159 - if (res > 0) { 160 - printk(KERN_INFO "%s", state->pp_buf); 161 - 162 - free_page((unsigned long)state->pp_buf); 163 - return state; 164 - } 165 - if (state->access_beyond_eod) 166 - err = -ENOSPC; 167 - if (err) 168 - /* The partition is unrecognized. So report I/O errors if there were any */ 169 - res = err; 170 - if (res) { 171 - strlcat(state->pp_buf, 172 - " unable to read partition table\n", PAGE_SIZE); 173 - printk(KERN_INFO "%s", state->pp_buf); 174 - } 175 - 176 - free_page((unsigned long)state->pp_buf); 177 - free_partitions(state); 178 - return ERR_PTR(res); 179 - }
-5
block/partitions/check.h
··· 23 23 char *pp_buf; 24 24 }; 25 25 26 - void free_partitions(struct parsed_partitions *state); 27 - 28 - struct parsed_partitions * 29 - check_partition(struct gendisk *, struct block_device *); 30 - 31 26 typedef struct { 32 27 struct page *v; 33 28 } Sector;