Commit a22f8253 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] partition parsing cleanup

struct gendisk and partition parsers divorced; all these parsers (IBM style,
disklabel, etc.) just fill the structure they get from check_partitions().

Actual setting the things up (filling hd_struct arrays, telling RAID that
we had found partitions worth a look, etc.) is taken into check_partitions()
and done only when we are done with parsing.  Parsers don't know (or care)
what majors/minors they are dealing with; that knowledge also went to
check_partitions().
parent d6d4f980
......@@ -1254,10 +1254,11 @@ void mfm_setup(char *str, int *ints)
* since if there are any non-ADFS partitions on the disk, this won't work!
* Hence, I want to get rid of this...
*/
void xd_set_geometry(kdev_t dev, unsigned char secsptrack, unsigned char heads,
unsigned long discsize, unsigned int secsize)
void xd_set_geometry(struct block_device *bdev, unsigned char secsptrack,
unsigned char heads, unsigned int secsize)
{
int drive = minor(dev) >> 6;
int drive = MINOR(bdev->bd_dev) >> 6;
unsigned long disksize = bdev->bd_inode->i_size;
if (mfm_info[drive].cylinders == 1) {
mfm_info[drive].sectors = secsptrack;
......@@ -1265,7 +1266,7 @@ void xd_set_geometry(kdev_t dev, unsigned char secsptrack, unsigned char heads,
mfm_info[drive].cylinders = discsize / (secsptrack * heads * secsize);
if ((heads < 1) || (mfm_info[drive].cylinders > 1024)) {
printk("mfm%c: Insane disc shape! Setting to 512/4/32\n",'a' + (dev >> 6));
printk("mfm%c: Insane disc shape! Setting to 512/4/32\n",'a' + drive);
/* These values are fairly arbitary, but are there so that if your
* lucky you can pick apart your disc to find out what is going on -
......
This diff is collapsed.
......@@ -50,6 +50,4 @@ struct ptec_partition {
};
int acorn_partition(struct gendisk *hd, struct block_device *bdev,
unsigned long first_sect, int first_minor);
int acorn_partition(struct parsed_partitions *state, struct block_device *bdev);
......@@ -7,14 +7,7 @@
* Re-organised Feb 1998 Russell King
*/
#include <linux/fs.h>
#include <linux/genhd.h>
#include <linux/kernel.h>
#include <linux/major.h>
#include <linux/string.h>
#include <linux/blk.h>
#include <asm/byteorder.h>
#include <linux/types.h>
#include <linux/affs_hardblocks.h>
#include "check.h"
......@@ -31,14 +24,14 @@ checksum_block(u32 *m, int size)
}
int
amiga_partition(struct gendisk *hd, struct block_device *bdev,
unsigned long first_sector, int first_part_minor)
amiga_partition(struct parsed_partitions *state, struct block_device *bdev)
{
Sector sect;
unsigned char *data;
struct RigidDiskBlock *rdb;
struct PartitionBlock *pb;
int start_sect, nr_sects, blk, part, res = 0;
int slot = 1;
for (blk = 0; ; blk++, put_dev_sector(sect)) {
if (blk == RDB_ALLOCATION_LIMIT)
......@@ -100,8 +93,7 @@ amiga_partition(struct gendisk *hd, struct block_device *bdev,
start_sect = be32_to_cpu(pb->pb_Environment[9]) *
be32_to_cpu(pb->pb_Environment[3]) *
be32_to_cpu(pb->pb_Environment[5]);
add_gd_partition(hd,first_part_minor,start_sect,nr_sects);
first_part_minor++;
put_partition(state,slot++,start_sect,nr_sects);
res = 1;
}
printk("\n");
......
......@@ -2,7 +2,5 @@
* fs/partitions/amiga.h
*/
int
amiga_partition(struct gendisk *hd, struct block_device *bdev,
unsigned long first_sector, int first_part_minor);
int amiga_partition(struct parsed_partitions *state, struct block_device *bdev);
......@@ -7,17 +7,7 @@
* Re-organised Feb 1998 Russell King
*/
#include <linux/fs.h>
#include <linux/genhd.h>
#include <linux/kernel.h>
#include <linux/major.h>
#include <linux/string.h>
#include <linux/blk.h>
#include <linux/ctype.h>
#include <asm/byteorder.h>
#include <asm/system.h>
#include "check.h"
#include "atari.h"
......@@ -40,15 +30,14 @@ static inline int OK_id(char *s)
memcmp (s, "RAW", 3) == 0 ;
}
int atari_partition (struct gendisk *hd, struct block_device *bdev,
unsigned long first_sector, int minor)
int atari_partition(struct parsed_partitions *state, struct block_device *bdev)
{
int m_lim = minor + (1 << hd->minor_shift);
Sector sect;
struct rootsector *rs;
struct partition_info *pi;
u32 extensect;
u32 hd_size;
int slot;
#ifdef ICD_PARTS
int part_fmt = 0; /* 0:unknown, 1:AHDI, 2:ICD/Supra */
#endif
......@@ -58,7 +47,7 @@ int atari_partition (struct gendisk *hd, struct block_device *bdev,
return -1;
/* Verify this is an Atari rootsector: */
hd_size = hd->part[minor - 1].nr_sects;
hd_size = bdev->bd_inode->i_size >> 9;
if (!VALID_PARTITION(&rs->part[0], hd_size) &&
!VALID_PARTITION(&rs->part[1], hd_size) &&
!VALID_PARTITION(&rs->part[2], hd_size) &&
......@@ -74,7 +63,7 @@ int atari_partition (struct gendisk *hd, struct block_device *bdev,
pi = &rs->part[0];
printk (" AHDI");
for (; pi < &rs->part[4] && minor < m_lim; minor++, pi++) {
for (slot = 1; pi < &rs->part[4] && slot < state->limit; slot++, pi++) {
struct rootsector *xrs;
Sector sect2;
ulong partsect;
......@@ -84,7 +73,7 @@ int atari_partition (struct gendisk *hd, struct block_device *bdev,
/* active partition */
if (memcmp (pi->id, "XGM", 3) != 0) {
/* we don't care about other id's */
add_gd_partition (hd, minor, be32_to_cpu(pi->st),
put_partition (state, slot, be32_to_cpu(pi->st),
be32_to_cpu(pi->siz));
continue;
}
......@@ -109,7 +98,7 @@ int atari_partition (struct gendisk *hd, struct block_device *bdev,
break;
}
add_gd_partition(hd, minor,
put_partition(state, slot,
partsect + be32_to_cpu(xrs->part[0].st),
be32_to_cpu(xrs->part[0].siz));
......@@ -126,8 +115,7 @@ int atari_partition (struct gendisk *hd, struct block_device *bdev,
partsect = be32_to_cpu(xrs->part[1].st) + extensect;
put_dev_sector(sect2);
minor++;
if (minor >= m_lim) {
if (++slot == state->limit) {
printk( "\nMaximum number of partitions reached!\n" );
break;
}
......@@ -140,12 +128,12 @@ int atari_partition (struct gendisk *hd, struct block_device *bdev,
/* sanity check: no ICD format if first partition invalid */
if (OK_id(pi->id)) {
printk(" ICD<");
for (; pi < &rs->icdpart[8] && minor < m_lim; minor++, pi++) {
for (; pi < &rs->icdpart[8] && slot < state->limit; slot++, pi++) {
/* accept only GEM,BGM,RAW,LNX,SWP partitions */
if (!((pi->flg & 1) && OK_id(pi->id)))
continue;
part_fmt = 2;
add_gd_partition (hd, minor,
put_partition (state, slot,
be32_to_cpu(pi->st),
be32_to_cpu(pi->siz));
}
......@@ -159,4 +147,3 @@ int atari_partition (struct gendisk *hd, struct block_device *bdev,
return 1;
}
......@@ -31,6 +31,4 @@ struct rootsector
u16 checksum; /* checksum for bootable disks */
} __attribute__((__packed__));
int atari_partition (struct gendisk *hd, struct block_device *bdev,
unsigned long first_sector, int first_part_minor);
int atari_partition(struct parsed_partitions *state, struct block_device *bdev);
......@@ -34,10 +34,13 @@
#include "ultrix.h"
#include "efi.h"
#if CONFIG_BLK_DEV_MD
extern void md_autodetect_dev(kdev_t dev);
#endif
int warn_no_part = 1; /*This is ugly: should make genhd removable media aware*/
static int (*check_part[])(struct gendisk *hd, struct block_device *bdev,
unsigned long first_sect, int first_minor) = {
static int (*check_part[])(struct parsed_partitions *, struct block_device *) = {
#ifdef CONFIG_ACORN_PARTITION
acorn_partition,
#endif
......@@ -199,28 +202,6 @@ char *disk_name (struct gendisk *hd, int minor, char *buf)
return buf;
}
/*
* Add a partitions details to the devices partition description.
*/
void add_gd_partition(struct gendisk *hd, int minor, int start, int size)
{
#ifndef CONFIG_DEVFS_FS
char buf[40];
#endif
hd->part[minor].start_sect = start;
hd->part[minor].nr_sects = size;
#ifdef CONFIG_DEVFS_FS
printk(" p%d", (minor & ((1 << hd->minor_shift) - 1)));
#else
if ((hd->major >= COMPAQ_SMART2_MAJOR+0 && hd->major <= COMPAQ_SMART2_MAJOR+7) ||
(hd->major >= COMPAQ_CISS_MAJOR+0 && hd->major <= COMPAQ_CISS_MAJOR+7))
printk(" p%d", (minor & ((1 << hd->minor_shift) - 1)));
else
printk(" %s", disk_name(hd, minor, buf));
#endif
}
/* Driverfs file support */
static ssize_t partition_device_kdev_read(struct device *driverfs_dev,
char *page, size_t count, loff_t off)
......@@ -351,12 +332,13 @@ void driverfs_remove_partitions(struct gendisk *hd, int minor)
return;
}
static void check_partition(struct gendisk *hd, kdev_t dev, int first_part_minor)
static void check_partition(struct gendisk *hd, kdev_t dev)
{
devfs_handle_t de = NULL;
unsigned long first_sector;
struct block_device *bdev;
char buf[64];
struct parsed_partitions *state;
int i;
first_sector = hd->part[minor(dev)].start_sect;
......@@ -369,14 +351,26 @@ static void check_partition(struct gendisk *hd, kdev_t dev, int first_part_minor
hd->part[minor(dev)].start_sect = 0;
return;
}
if (first_sector != 0)
BUG();
state = kmalloc(sizeof(struct parsed_partitions), GFP_KERNEL);
if (!state)
return;
if (hd->de_arr)
de = hd->de_arr[minor(dev) >> hd->minor_shift];
i = devfs_generate_path (de, buf, sizeof buf);
if (i >= 0)
if (i >= 0) {
printk(KERN_INFO " /dev/%s:", buf + i);
else
printk(KERN_INFO " %s:", disk_name(hd, minor(dev), buf));
sprintf(state->name, "p");
} else {
unsigned n = hd->major;
disk_name(hd, minor(dev), state->name);
printk(KERN_INFO " %s:", state->name);
if (n - COMPAQ_SMART2_MAJOR <= 7 || n - COMPAQ_CISS_MAJOR <= 7)
sprintf(state->name, "p");
}
bdev = bdget(kdev_t_to_nr(dev));
bdev->bd_contains = bdev;
bdev->bd_inode->i_size = (loff_t)hd->part[minor(dev)].nr_sects << 9;
......@@ -395,14 +389,30 @@ static void check_partition(struct gendisk *hd, kdev_t dev, int first_part_minor
bdev->bd_block_size = bsize;
bdev->bd_inode->i_blkbits = blksize_bits(bsize);
}
state->limit = 1<<hd->minor_shift;
for (i = 0; check_part[i]; i++) {
int res;
res = check_part[i](hd, bdev, first_sector, first_part_minor);
if (res) {
if (res < 0 && warn_no_part)
int res, j;
memset(&state->parts, 0, sizeof(state->parts));
res = check_part[i](state, bdev);
if (!res)
continue;
if (res < 0) {
if (warn_no_part)
printk(" unable to read partition table\n");
goto setup_devfs;
}
for (j = 1; j < state->limit; j++) {
hd->part[j + minor(dev)].start_sect =
state->parts[j].from;
hd->part[j + minor(dev)].nr_sects =
state->parts[j].size;
#if CONFIG_BLK_DEV_MD
if (!state->parts[j].flags)
continue;
md_autodetect_dev(mk_kdev(major(dev),minor(dev)+j));
#endif
}
goto setup_devfs;
}
printk(" unknown partition table\n");
......@@ -410,15 +420,14 @@ static void check_partition(struct gendisk *hd, kdev_t dev, int first_part_minor
invalidate_bdev(bdev, 1);
truncate_inode_pages(bdev->bd_inode->i_mapping, 0);
bdput(bdev);
i = first_part_minor - 1;
/* Setup driverfs tree */
if (hd->sizes)
driverfs_create_partitions(hd, i);
driverfs_create_partitions(hd, minor(dev));
else
driverfs_remove_partitions(hd, i);
driverfs_remove_partitions(hd, minor(dev));
devfs_register_partitions (hd, i, hd->sizes ? 0 : 1);
devfs_register_partitions (hd, minor(dev), hd->sizes ? 0 : 1);
}
#ifdef CONFIG_DEVFS_FS
......@@ -564,7 +573,7 @@ void grok_partitions(kdev_t dev, long size)
if (!size)
return;
check_partition(g, mk_kdev(g->major, first_minor), 1 + first_minor);
check_partition(g, mk_kdev(g->major, first_minor));
/*
* We need to set the sizes array before we will be able to access
......@@ -632,28 +641,3 @@ int wipe_partitions(kdev_t dev)
}
return 0;
}
/*
* Make sure that a proposed subpartition is strictly contained inside
* the parent partition. If all is well, call add_gd_partition().
*/
int
check_and_add_subpartition(struct gendisk *hd, int super_minor, int minor,
int sub_start, int sub_size)
{
int start = hd->part[super_minor].start_sect;
int size = hd->part[super_minor].nr_sects;
if (start == sub_start && size == sub_size) {
/* full parent partition, we have it already */
return 0;
}
if (start <= sub_start && start+size >= sub_start+sub_size) {
add_gd_partition(hd, minor, sub_start, sub_size);
return 1;
}
printk("bad subpartition - ignored\n");
return 0;
}
......@@ -5,12 +5,28 @@
* add_gd_partition adds a partitions details to the devices partition
* description.
*/
void add_gd_partition(struct gendisk *hd, int minor, int start, int size);
/*
* check_and_add_subpartition does the same for subpartitions
*/
int check_and_add_subpartition(struct gendisk *hd, int super_minor,
int minor, int sub_start, int sub_size);
enum { MAX_PART = 256 };
struct parsed_partitions {
char name[40];
struct {
unsigned long from;
unsigned long size;
int flags;
} parts[MAX_PART];
int next;
int limit;
};
static inline void
put_partition(struct parsed_partitions *p, int n, int from, int size)
{
if (n < p->limit) {
p->parts[n].from = from;
p->parts[n].size = size;
printk(" %s%d", p->name, n);
}
}
extern int warn_no_part;
This diff is collapsed.
......@@ -112,9 +112,7 @@ typedef struct _legacy_mbr {
} __attribute__ ((packed)) legacy_mbr;
/* Functions */
extern int
efi_partition(struct gendisk *hd, struct block_device *bdev,
unsigned long first_sector, int first_part_minor);
extern int efi_partition(struct parsed_partitions *state, struct block_device *bdev);
#endif
......
......@@ -88,8 +88,7 @@ ibm_ioctl_unopened(struct block_device *bdev, unsigned cmd, unsigned long arg)
/*
*/
int
ibm_partition(struct gendisk *hd, struct block_device *bdev,
unsigned long first_sector, int first_part_minor)
ibm_partition(struct parsed_partitions *state, struct block_device *bdev)
{
int blocksize, offset, size;
dasd_information_t *info;
......@@ -100,9 +99,6 @@ ibm_partition(struct gendisk *hd, struct block_device *bdev,
unsigned char *data;
Sector sect;
if ( first_sector != 0 )
BUG();
if ((info = kmalloc(sizeof(dasd_information_t), GFP_KERNEL)) == NULL)
goto out_noinfo;
if ((geo = kmalloc(sizeof(struct hd_geometry), GFP_KERNEL)) == NULL)
......@@ -155,9 +151,7 @@ ibm_partition(struct gendisk *hd, struct block_device *bdev,
offset = (info->label_block + 1);
size = bdev->bd_inode->i_size >> 9;
}
// add_gd_partition(hd, first_part_minor - 1, 0, size);
add_gd_partition(hd, first_part_minor,
offset*(blocksize >> 9),
put_partition(state, 1, offset*(blocksize >> 9),
size-offset*(blocksize >> 9));
} else if (strncmp(type, "VOL1", 4) == 0) {
/*
......@@ -194,9 +188,9 @@ ibm_partition(struct gendisk *hd, struct block_device *bdev,
offset = cchh2blk(&f1.DS1EXT1.llimit, geo);
size = cchh2blk(&f1.DS1EXT1.ulimit, geo) -
offset + geo->sectors;
if (counter >= (1 << hd->minor_shift))
if (counter >= state->limit)
break;
add_gd_partition(hd, first_part_minor + counter,
put_partition(state, counter + 1,
offset * (blocksize >> 9),
size * (blocksize >> 9));
counter++;
......@@ -212,9 +206,7 @@ ibm_partition(struct gendisk *hd, struct block_device *bdev,
printk("(nonl)/%8s:", name);
offset = (info->label_block + 1);
size = (bdev->bd_inode->i_size >> 9);
// add_gd_partition(hd, first_part_minor - 1, 0, size);
add_gd_partition(hd, first_part_minor,
offset*(blocksize >> 9),
put_partition(state, 1, offset*(blocksize >> 9),
size-offset*(blocksize >> 9));
}
......
int ibm_partition(struct gendisk *, struct block_device *, unsigned long, int);
int ibm_partition(struct parsed_partitions *, struct block_device *);
......@@ -23,12 +23,6 @@
*
* 28/10/2001 - Added sorting of ldm partitions. (AIA)
*/
#include <linux/types.h>
#include <asm/unaligned.h>
#include <asm/byteorder.h>
#include <linux/pagemap.h>
#include <linux/genhd.h>
#include <linux/blkdev.h>
#include <linux/slab.h>
#include "check.h"
#include "ldm.h"
......@@ -57,7 +51,6 @@ static void ldm_debug(const char *f, ...);
#endif /* !CONFIG_LDM_DEBUG */
/* Necessary forward declarations. */
static int create_partition(struct gendisk *, int, int, int);
static int parse_privhead(const u8 *, struct privhead *);
static u64 get_vnum(const u8 *, int *);
static int get_vstr(const u8 *, u8 *, const int);
......@@ -161,8 +154,7 @@ static int parse_vblk(const u8 *buffer, const int buf_size, struct vblk *vb)
/**
* add_partition_to_list - insert partition into a partition list
* @pl: sorted list of partitions
* @hd: gendisk structure to which the data partition belongs
* @disk_minor: minor number of the disk device
* @disk_size: number of sectors on the disk device
* @start: first sector within the disk device
* @size: number of sectors on the partition device
*
......@@ -174,16 +166,15 @@ static int parse_vblk(const u8 *buffer, const int buf_size, struct vblk *vb)
*
* TODO: Add sanity check for overlapping partitions. (AIA)
*/
static int add_partition_to_list(struct list_head *pl, const struct gendisk *hd,
const int disk_minor, const unsigned long start,
static int add_partition_to_list(struct list_head *pl,
const unsigned long disk_size,
const unsigned long start,
const unsigned long size)
{
struct ldm_part *lp, *lptmp;
struct list_head *tmp;
if (!hd->part)
return -1;
if ((start < 1) || ((start + size) > hd->part[disk_minor].nr_sects)) {
if (start < 1 || start + size > disk_size) {
printk(LDM_CRIT "LDM partition exceeds physical disk. "
"Skipping.\n");
return -1;
......@@ -215,7 +206,6 @@ static int add_partition_to_list(struct list_head *pl, const struct gendisk *hd,
/**
* create_data_partitions - create the data partition devices
* @hd: gendisk structure in which to create the data partitions
* @first_sector: first sector within the disk device
* @first_part_minor: first minor number of data partition devices
* @dev: partition device holding the LDM database
* @vm: in memory vmdb structure of @dev
......@@ -234,9 +224,8 @@ static int add_partition_to_list(struct list_head *pl, const struct gendisk *hd,
*
* Return 1 on success and -1 on error.
*/
static int create_data_partitions(struct gendisk *hd,
const unsigned long first_sector, int first_part_minor,
struct block_device *bdev, const struct vmdb *vm,
static int create_data_partitions(struct parsed_partitions *state,
int slot, struct block_device *bdev, const struct vmdb *vm,
const struct privhead *ph, const struct ldmdisk *dk,
unsigned long base)
{
......@@ -249,7 +238,7 @@ static int create_data_partitions(struct gendisk *hd,
int vblk;
int vsize; /* VBLK size. */
int perbuf; /* VBLKs per buffer. */
int buffer, lastbuf, lastofs, err, disk_minor;
int buffer, lastbuf, lastofs, err;
vb = (struct vblk*)kmalloc(sizeof(struct vblk), GFP_KERNEL);
if (!vb)
......@@ -268,11 +257,6 @@ static int create_data_partitions(struct gendisk *hd,
if (OFF_VBLK * LDM_BLOCKSIZE + vm->last_vblk_seq * vsize >
ph->config_size * 512)
goto err_out;
/*
* Get the minor number of the parent device so we can check we don't
* go beyond the end of the device.
*/
disk_minor = (first_part_minor >> hd->minor_shift) << hd->minor_shift;
for (buffer = 0; buffer < lastbuf; buffer++) {
data = read_dev_sector(bdev, base + 2*OFF_VBLK + buffer, &sect);
if (!data)
......@@ -292,8 +276,9 @@ static int create_data_partitions(struct gendisk *hd,
if (dk->obj_id != vb->disk_id)
continue;
/* Ignore invalid partition errors. */
if (add_partition_to_list(&pl, hd, disk_minor,
first_sector + vb->start_sector +
if (add_partition_to_list(&pl,
bdev->bd_inode->i_size>>9,
vb->start_sector +
ph->logical_disk_start,
vb->num_sectors) < -1)
goto brelse_out;
......@@ -306,7 +291,7 @@ static int create_data_partitions(struct gendisk *hd,
printk(" <");
list_for_each(tmp, &pl) {
lp = list_entry(tmp, struct ldm_part, part_list);
add_gd_partition(hd, first_part_minor++, lp->start, lp->size);
put_partition(state, slot++, lp->start, lp->size);
}
printk(" >\n");
if (!list_empty(&pl)) {
......@@ -819,42 +804,6 @@ static int validate_privheads(struct block_device *bdev,
goto out;
}
/**
* create_partition - validate input and create a kernel partition device
* @hd: gendisk structure in which to create partition
* @minor: minor number for device to create
* @start: starting offset of the partition into the parent device
* @size: size of the partition
*
* This validates the range, then puts an entry into the kernel's partition
* table.
*
* @start and @size are numbers of sectors.
*
* Return 1 on succes and -1 on error.
*/
static int create_partition(struct gendisk *hd, const int minor,
const int start, const int size)
{
int disk_minor;
if (!hd->part)
return -1;
/*
* Get the minor number of the parent device so we can check we don't
* go beyond the end of the device.
*/
disk_minor = (minor >> hd->minor_shift) << hd->minor_shift;
if ((start < 1) || ((start + size) > hd->part[disk_minor].nr_sects)) {
printk(LDM_CRIT "LDM Partition exceeds physical disk. "
"Aborting.\n");
return -1;
}
add_gd_partition(hd, minor, start, size);
ldm_debug("Created partition successfully.\n");
return 1;
}
/**
* parse_privhead - parse the LDM database PRIVHEAD structure
* @buffer: LDM database privhead structure loaded from the device
......@@ -901,19 +850,16 @@ static int parse_privhead(const u8 *buffer, struct privhead *ph)
}
/**
* create_db_partition - create a dedicated partition for our database
* @hd: gendisk structure in which to create partition
* find_db_partition - find our database
* @dev: device of which to create partition
* @ph: @dev's LDM database private header
*
* Find the primary private header, locate the LDM database, then create a
* Find the primary private header and the LDM database
* partition to wrap it.
*
* Return 1 on succes, 0 if device is not a dynamic disk and -1 on error.
*/
static int create_db_partition(struct gendisk *hd, struct block_device *bdev,
const unsigned long first_sector, const int first_part_minor,
struct privhead *ph)
static int find_db_partition(struct block_device *bdev, struct privhead *ph)
{
Sector sect;
unsigned char *data;
......@@ -930,10 +876,15 @@ static int create_db_partition(struct gendisk *hd, struct block_device *bdev,
return 0;
}
err = parse_privhead(data, ph);
if (err == 1)
err = create_partition(hd, first_part_minor, first_sector +
ph->config_start, ph->config_size);
put_dev_sector(sect);
if (err <= 0)
return err;
if (ph->config_start < 1 ||
ph->config_start + ph->config_size > bdev->bd_inode->i_size >> 9) {
printk(LDM_CRIT "LDM Partition exceeds physical disk. "
"Aborting.\n");
err = -1;
}
return err;
}
......@@ -990,8 +941,6 @@ static int validate_partition_table(struct block_device *bdev)
* ldm_partition - find out whether a device is a dynamic disk and handle it
* @hd: gendisk structure in which to return the handled disk
* @dev: device we need to look at
* @first_sector: first sector within the device
* @first_part_minor: first minor number of partitions for the device
*
* Description:
*
......@@ -1010,8 +959,7 @@ static int validate_partition_table(struct block_device *bdev)
* 0 if @dev is not a dynamic disk,
* -1 if an error occured.
*/
int ldm_partition(struct gendisk *hd, struct block_device *bdev,
unsigned long first_sector, int first_part_minor)
int ldm_partition(struct parsed_partitions *state, struct block_device *bdev)
{
struct privhead *ph = NULL;
struct tocblock *toc = NULL;
......@@ -1020,8 +968,6 @@ int ldm_partition(struct gendisk *hd, struct block_device *bdev,
unsigned long db_first;
int err;
if (!hd)
return 0;
/* Check the partition table. */
err = validate_partition_table(bdev);
if (err != 1)
......@@ -1029,10 +975,11 @@ int ldm_partition(struct gendisk *hd, struct block_device *bdev,
if (!(ph = (struct privhead*)kmalloc(sizeof(*ph), GFP_KERNEL)))
goto no_mem;
/* Create the LDM database device. */
err = create_db_partition(hd, bdev, first_sector, first_part_minor, ph);
err = find_db_partition(bdev, ph);
if (err != 1)
goto out;
db_first = hd->part[first_part_minor].start_sect;
db_first = ph->config_start;
put_partition(state, 1, db_first, ph->config_size);
/* Check the backup privheads. */
err = validate_privheads(bdev, ph, db_first);
if (err != 1)
......@@ -1056,8 +1003,8 @@ int ldm_partition(struct gendisk *hd, struct block_device *bdev,
if (err != 1)
goto out;
/* Finally, create the data partition devices. */
err = create_data_partitions(hd, first_sector, first_part_minor +
LDM_FIRST_PART_OFFSET, bdev, vm, ph, dk, db_first);
err = create_data_partitions(state, 1 + LDM_FIRST_PART_OFFSET,
bdev, vm, ph, dk, db_first);
if (err == 1)
ldm_debug("Parsed LDM database successfully.\n");
out:
......@@ -1071,4 +1018,3 @@ int ldm_partition(struct gendisk *hd, struct block_device *bdev,
err = -1;
goto out;
}
......@@ -150,8 +150,7 @@ struct ldm_part {
unsigned long size;
};
int ldm_partition(struct gendisk *hd, struct block_device *bdev,
unsigned long first_sector, int first_part_minor);
int ldm_partition(struct parsed_partitions *state, struct block_device *bdev);
#endif /* _FS_PT_LDM_H_ */
......@@ -7,16 +7,7 @@
*/
#include <linux/config.h>
#include <linux/fs.h>
#include <linux/genhd.h>
#include <linux/kernel.h>
#include <linux/major.h>
#include <linux/string.h>
#include <linux/blk.h>
#include <linux/ctype.h>
#include <asm/system.h>
#include "check.h"
#include "mac.h"
......@@ -36,9 +27,9 @@ static inline void mac_fix_string(char *stg, int len)
stg[i] = 0;
}
int mac_partition(struct gendisk *hd, struct block_device *bdev,
unsigned long fsec, int first_part_minor)
int mac_partition(struct parsed_partitions *state, struct block_device *bdev)
{
int slot = 1;
Sector sect;
unsigned char *data;
int blk, blocks_in_map;
......@@ -79,8 +70,8 @@ int mac_partition(struct gendisk *hd, struct block_device *bdev,
part = (struct mac_partition *) (data + pos%512);
if (be16_to_cpu(part->signature) != MAC_PARTITION_MAGIC)
break;
add_gd_partition(hd, first_part_minor,
fsec + be32_to_cpu(part->start_block) * (secsize/512),
put_partition(state, slot,
be32_to_cpu(part->start_block) * (secsize/512),
be32_to_cpu(part->block_count) * (secsize/512));
#ifdef CONFIG_ALL_PPC
......@@ -126,7 +117,7 @@ int mac_partition(struct gendisk *hd, struct block_device *bdev,
}
#endif /* CONFIG_ALL_PPC */
++first_part_minor;
++slot;
}
#ifdef CONFIG_ALL_PPC
if (found_root_goodness)
......@@ -138,4 +129,3 @@ int mac_partition(struct gendisk *hd, struct block_device *bdev,
printk("\n");
return 1;
}
......@@ -41,4 +41,4 @@ struct mac_driver_desc {
/* ... more stuff */
};
int mac_partition(struct gendisk *hd, struct block_device *bdev, unsigned long fsec, int first_part_minor);
int mac_partition(struct parsed_partitions *state, struct block_device *bdev);
This diff is collapsed.
......@@ -4,6 +4,5 @@
#define MSDOS_LABEL_MAGIC 0xAA55
int msdos_partition(struct gendisk *hd, struct block_device *bdev,
unsigned long first_sector, int first_part_minor);
int msdos_partition(struct parsed_partitions *state, struct block_device *bdev);
......@@ -7,23 +7,15 @@
* Re-organised Feb 1998 Russell King
*/
#include <linux/fs.h>
#include <linux/genhd.h>
#include <linux/kernel.h>
#include <linux/major.h>
#include <linux/string.h>
#include <linux/blk.h>
#include "check.h"
#include "osf.h"
int osf_partition(struct gendisk *hd, struct block_device *bdev,
unsigned long first_sector, int current_minor)
int osf_partition(struct parsed_partitions *state, struct block_device *bdev)
{
int i;
int slot = 1;
Sector sect;
unsigned char *data;
int mask = (1 << hd->minor_shift) - 1;
struct disklabel {
u32 d_magic;
u16 d_type,d_subtype;
......@@ -72,16 +64,14 @@ int osf_partition(struct gendisk *hd, struct block_device *bdev,
return 0;
}
for (i = 0 ; i < le16_to_cpu(label->d_npartitions); i++, partition++) {
if ((current_minor & mask) == 0)
if (slot == state->limit)
break;
if (le32_to_cpu(partition->p_size))
add_gd_partition(hd, current_minor,
first_sector+le32_to_cpu(partition->p_offset),
put_partition(state, slot++,
le32_to_cpu(partition->p_offset),
le32_to_cpu(partition->p_size));
current_minor++;
}
printk("\n");
put_dev_sector(sect);
return 1;
}
......@@ -4,6 +4,4 @@
#define DISKLABELMAGIC (0x82564557UL)
int osf_partition(struct gendisk *hd, struct block_device *bdev,
unsigned long first_sector, int current_minor);
int osf_partition(struct parsed_partitions *state, struct block_device *bdev);
......@@ -4,22 +4,13 @@
* Code extracted from drivers/block/genhd.c
*/
#include <linux/fs.h>
#include <linux/genhd.h>
#include <linux/kernel.h>
#include <linux/major.h>
#include <linux/string.h>
#include <linux/blk.h>
#include <asm/byteorder.h>
#include <asm/system.h>
#include "check.h"
#include "sgi.h"
int sgi_partition(struct gendisk *hd, struct block_device *bdev, unsigned long first_sector, int current_minor)
int sgi_partition(struct parsed_partitions *state, struct block_device *bdev)
{
int i, csum, magic;
int slot = 1;
unsigned int *ui, start, blocks, cs;
Sector sect;
struct sgi_disklabel {
......@@ -73,10 +64,8 @@ int sgi_partition(struct gendisk *hd, struct block_device *bdev, unsigned long f
for(i = 0; i < 16; i++, p++) {
blocks = be32_to_cpu(p->num_blocks);
start = be32_to_cpu(p->first_block);
if(!blocks)
continue;
add_gd_partition(hd, current_minor, start, blocks);
current_minor++;
if (blocks)
put_partition(state, slot++, start, blocks);
}
printk("\n");
put_dev_sector(sect);
......
......@@ -2,8 +2,7 @@
* fs/partitions/sgi.h
*/
extern int sgi_partition(struct gendisk *hd, struct block_device *bdev,
unsigned long first_sector, int first_part_minor);
extern int sgi_partition(struct parsed_partitions *state, struct block_device *bdev);
#define SGI_LABEL_MAGIC 0x0be5a941
......@@ -7,21 +7,13 @@
* Re-organised Feb 1998 Russell King
*/
#include <linux/fs.h>
#include <linux/genhd.h>
#include <linux/kernel.h>
#include <linux/major.h>
#include <linux/string.h>
#include <linux/blk.h>
#include <asm/system.h>
#include "check.h"
#include "sun.h"
int sun_partition(struct gendisk *hd, struct block_device *bdev, unsigned long first_sector, int first_part_minor)
int sun_partition(struct parsed_partitions *state, struct block_device *bdev)
{
int i, csum;
int slot = 1;
unsigned short *ush;
Sector sect;
struct sun_disklabel {
......@@ -74,11 +66,10 @@ int sun_partition(struct gendisk *hd, struct block_device *bdev, unsigned long f
unsigned long st_sector;
int num_sectors;
st_sector = first_sector + be32_to_cpu(p->start_cylinder) * spc;
st_sector = be32_to_cpu(p->start_cylinder) * spc;
num_sectors = be32_to_cpu(p->num_sectors);
if (num_sectors)
add_gd_partition(hd, first_part_minor, st_sector, num_sectors);
first_part_minor++;
put_partition(state, slot++, st_sector, num_sectors);
}
printk("\n");
put_dev_sector(sect);
......
......@@ -4,6 +4,4 @@
#define SUN_LABEL_MAGIC 0xDABE
int sun_partition(struct gendisk *hd, struct block_device *bdev,
unsigned long first_sector, int first_part_minor);
int sun_partition(struct parsed_partitions *state, struct block_device *bdev);
......@@ -6,16 +6,9 @@
* Re-organised Jul 1999 Russell King
*/
#include <linux/fs.h>
#include <linux/genhd.h>
#include <linux/kernel.h>
#include <linux/major.h>
#include <linux/blk.h>
#include "check.h"
int ultrix_partition(struct gendisk *hd, struct block_device *bdev,
unsigned long first_sector, int first_part_minor)
int ultrix_partition(struct parsed_partitions *state, struct block_device *bdev)
{
int i;
Sector sect;
......@@ -39,9 +32,9 @@ int ultrix_partition(struct gendisk *hd, struct block_device *bdev,
label = (struct ultrix_disklabel *)(data + 512 - sizeof(*label));
if (label->pt_magic == PT_MAGIC && label->pt_valid == PT_VALID) {
for (i=0; i<8; i++, first_part_minor++)
for (i=0; i<8; i++)
if (label->pt_part[i].pi_nblocks)
add_gd_partition(hd, first_part_minor,
put_partition(state, i+1,
label->pt_part[i].pi_blkoff,
label->pt_part[i].pi_nblocks);
put_dev_sector(sect);
......
......@@ -2,6 +2,4 @@
* fs/partitions/ultrix.h
*/
int ultrix_partition(struct gendisk *hd, struct block_device *bdev,
unsigned long first_sector, int first_part_minor);
int ultrix_partition(struct parsed_partitions *state, struct block_device *bdev);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment