Changes by: flatcap
Update of /cvsroot/linux-ntfs/dynamic-disk/linux/fs/partitions
In directory usw-pr-cvs1:/tmp/cvs-serv20391/linux/fs/partitions
Modified Files:
ldm.c ldm.h
Log Message:
first wave of tidyups
Index: ldm.c
===================================================================
RCS file: /cvsroot/linux-ntfs/dynamic-disk/linux/fs/partitions/ldm.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -U2 -r1.5 -r1.6
--- ldm.c 2001/06/20 03:38:09 1.5
+++ ldm.c 2001/06/21 01:08:45 1.6
@@ -33,4 +33,6 @@
#include "msdos.h"
+/*----------------------------------------------------------------------------*/
+
/* Get a variable-width number
* The width is stored in a byte before the number */
@@ -53,4 +55,5 @@
static u8 * get_vstr (u8 *block)
{
+ /* XXX get rid of the static buffer in favour of a parameter? */
static u8 buffer[256];
u8 length = 0;
@@ -65,4 +68,6 @@
}
+/*----------------------------------------------------------------------------*/
+
/* We're looking for an MSDOS-style partition table with one entry in it:
* 0x42, which works like an extended partition. Detail will be placed in pt.*/
@@ -73,5 +78,4 @@
if (!buffer || !pt)
return 0;
-
if (*(u16*) (buffer + 0x01FE) != cpu_to_le16 (MSDOS_LABEL_MAGIC))
return 0;
@@ -103,5 +107,5 @@
ph->config_start = BE64 (buffer + 0x012B);
ph->config_size = BE64 (buffer + 0x0133);
- if (ph->config_size != 2048) /* 1 Mb */
+ if (ph->config_size != LDM_DB_SIZE) /* 1 MiB */
return 0;
@@ -169,8 +173,6 @@
if (!buffer || !vb)
return 0;
-
if (MAGIC_VBLK != BE32 (buffer))
return 0;
-
if (BE16 (buffer+14) == 0) /* record not in use */
return 0;
@@ -191,4 +193,6 @@
}
+/*----------------------------------------------------------------------------*/
+
/* validate the range, then put an entry into the kernel's partition table
* start and size are numbers of sectors */
@@ -207,11 +211,4 @@
}
-#if 0
-struct buffer_head * get_device_block (kdev_t dev, int sector)
-{
- return NULL;
-}
-#endif
-
/* find the primary private header, locate the LDM database,
* then create a partition to wrap it */
@@ -224,5 +221,5 @@
goto cdp_end;
- if (!(bh = bread (dev, OFF_PRIVHEAD1, 1024)))
+ if (!(bh = bread (dev, OFF_PRIVHEAD1, LDM_BLOCKSIZE)))
goto cdp_end;
@@ -237,29 +234,88 @@
return ret;
}
+
+/*----------------------------------------------------------------------------*/
-#ifdef XXX
-static inline struct buffer_head *
-get_partition_table_block(struct gendisk *hd, int minor, int blocknr)
+/* We already have one privhead from the beginning of the disk.
+ * Now we compare the two other copies for safety. */
+int validate_privheads (kdev_t dev, struct privhead *ph)
{
- kdev_t dev = MKDEV(hd->major, minor);
- return bread(dev, blocknr, get_ptable_blocksize(dev));
+ struct buffer_head *bh;
+ struct privhead ph2;
+ struct privhead ph3;
+ int ret = 0;
+
+ if (!(bh = bread (dev, OFF_PRIVHEAD2, LDM_BLOCKSIZE)))
+ goto vp_end;
+ if (!parse_privhead (bh->b_data, &ph2))
+ goto vp_free;
+ brelse (bh);
+
+ if (!(bh = bread (dev, OFF_PRIVHEAD3, LDM_BLOCKSIZE)))
+ goto vp_end;
+ if (!parse_privhead (bh->b_data + 0x0200, &ph3))
+ goto vp_free;
+
+ /* XXX Compare the privheads */
+
+ ret = 1;
+vp_free:
+ brelse (bh);
+vp_end:
+ return ret;
}
-#endif
+/* Find and compare the four Tables Of Contents */
+int validate_tocblocks (kdev_t devdb, struct tocblock *toc1)
+{
+ struct buffer_head *bh;
+ struct tocblock toc2;
+ struct tocblock toc3;
+ struct tocblock toc4;
+ int ret = 0;
+
+ if (!(bh = bread (devdb, OFF_TOCBLOCK1, LDM_BLOCKSIZE)))
+ goto vt_end;
+ if (!parse_tocblock (bh->b_data + 0x0200, toc1))
+ goto vt_free;
+ brelse (bh);
+
+ if (!(bh = bread (devdb, OFF_TOCBLOCK2, LDM_BLOCKSIZE)))
+ goto vt_end;
+ if (!parse_tocblock (bh->b_data, &toc2))
+ goto vt_free;
+ brelse (bh);
+
+ if (!(bh = bread (devdb, OFF_TOCBLOCK3, LDM_BLOCKSIZE)))
+ goto vt_end;
+ if (!parse_tocblock (bh->b_data + 0x0200, &toc3))
+ goto vt_free;
+ brelse (bh);
+
+ if (!(bh = bread (devdb, OFF_TOCBLOCK4, LDM_BLOCKSIZE)))
+ goto vt_end;
+ if (!parse_tocblock (bh->b_data, &toc4))
+ goto vt_free;
+
+ /* XXX When we know more about the TOCBLOCK we'll be able to check more */
+
+ ret = 1;
+vt_free:
+ brelse (bh);
+vt_end:
+ return ret;
+}
+
+/*----------------------------------------------------------------------------*/
+
/* 1 = match, 0 = no match, -1 = error */
int ldm_partition(struct gendisk *hd, kdev_t dev,
unsigned long first_sector, int first_part_minor)
{
- /* what about first_sector, first_part_minor? */
/* demote the "sector counts" to ints? -- limit of 1Tb */
struct buffer_head *bh;
struct ldmpart pt;
- struct privhead ph1;
- struct privhead ph2;
- struct privhead ph3;
- struct tocblock toc1;
- struct tocblock toc2;
- struct tocblock toc3;
- struct tocblock toc4;
+ struct privhead ph;
+ struct tocblock toc;
struct vmdb vm;
struct vblk vb;
@@ -270,14 +326,15 @@
int j;
int k;
- int minor = first_part_minor + LDM_FIRST_PART - 1;
+ int vpb;
+ int vbs;
+ int minor = MINOR(dev) + LDM_FIRST_PART;
kdev_t devdb;
- if (get_ptable_blocksize (dev) != 1024)
+ if (get_ptable_blocksize (dev) != LDM_BLOCKSIZE) /* 1024 bytes */
goto end;
-
if (get_hardsect_size (dev) != 512)
goto end;
- if (!(bh = bread (dev, 0, 1024)))
+ if (!(bh = bread (dev, 0, LDM_BLOCKSIZE)))
{
if (warn_no_part)
@@ -286,58 +343,27 @@
}
+ /* We don't actually use 'pt' yet, but it could be used to range check
+ * the other partitions. */
if (!parse_part_table (bh->b_data, &pt))
goto free;
brelse (bh);
-
ret = -1; /* Any problem after here are OUR problem */
- if (!create_db_partition (hd, dev, &ph1))
+ /* create a dedicated partition for our database */
+ if (!create_db_partition (hd, dev, &ph))
goto free;
- /* we now have a dedicated partition for our database */
devdb = MKDEV (MAJOR(dev), MINOR(dev)+LDM_DB_PART);
- if (!(bh = bread (devdb, OFF_PRIVHEAD2, 1024)))
+ if (!validate_privheads (devdb, &ph))
goto end;
- if (!parse_privhead (bh->b_data, &ph2))
- goto free;
- brelse (bh);
-
- if (!(bh = bread (devdb, OFF_PRIVHEAD3, 1024)))
+ if (!validate_tocblocks (devdb, &toc))
goto end;
- if (!parse_privhead (bh->b_data + 0x0200, &ph3))
- goto free;
- brelse (bh);
/*-----------------------------------------------------*/
- if (!(bh = bread (devdb, OFF_TOCBLOCK1, 1024)))
- goto end;
- if (!parse_tocblock (bh->b_data + 0x0200, &toc1))
- goto free;
- brelse (bh);
-
- if (!(bh = bread (devdb, OFF_TOCBLOCK2, 1024)))
- goto end;
- if (!parse_tocblock (bh->b_data, &toc2))
- goto free;
- brelse (bh);
- if (!(bh = bread (devdb, OFF_TOCBLOCK3, 1024)))
+ if (!(bh = bread (devdb, OFF_VMDB, LDM_BLOCKSIZE)))
goto end;
- if (!parse_tocblock (bh->b_data + 0x0200, &toc3))
- goto free;
- brelse (bh);
-
- if (!(bh = bread (devdb, OFF_TOCBLOCK4, 1024)))
- goto end;
- if (!parse_tocblock (bh->b_data, &toc4))
- goto free;
- brelse (bh);
-
- /*-----------------------------------------------------*/
-
- if (!(bh = bread (devdb, OFF_VMDB, 1024)))
- goto end;
if (!parse_vmdb (bh->b_data + 0x200, &vm))
goto end;
@@ -345,17 +371,21 @@
/*-----------------------------------------------------*/
+ vbs = vm.vblk_size;
+ vpb = LDM_BLOCKSIZE / vbs; /* VBLKs per LDM Block */
+
// take into account size and offset in vmdb
- j = vm.last_vblk_seq / 8;
+ j = vm.last_vblk_seq / vpb;
- // first find the correct disk
+ /* The database contains an entry for every partition on
+ * every disk. We must search for THIS disk. */
for (i = 0; i < j; i++)
{
brelse (bh);
- if (!(bh = bread (devdb, OFF_VBLK+i, 1024)))
+ if (!(bh = bread (devdb, OFF_VBLK+i, LDM_BLOCKSIZE)))
goto end;
data = bh->b_data;
- for (k = 0; k < 8; k++)
+ for (k = 0; k < vpb; k++)
{
int rel_objid;
@@ -365,6 +395,6 @@
u8 *block;
- block = data + 0x80*k;
- if (block[19] != VBLK_DISK)
+ block = data + vbs*k; /* 80 PARAMETER */
+ if (block[19] != VBLK_DISK) /* 19 const */
continue;
@@ -377,5 +407,5 @@
disk_id = get_vstr (block+0x18+rel_name);
- if (strcmp (disk_id, ph1.disk_id) == 0)
+ if (strcmp (disk_id, ph.disk_id) == 0)
{
dk.obj_id = get_vnum (block+0x18);
@@ -389,28 +419,30 @@
goto free;
found:
+ /* Finally we have the disk id, so we can decide which partitions
+ * belong to us. For each match create a partition entry. */
printk (" <");
for (i = 0; i < j; i++)
{
brelse (bh);
- if (!(bh = bread (devdb, OFF_VBLK+i, 1024)))
- goto end;
+ if (!(bh = bread (devdb, OFF_VBLK+i, LDM_BLOCKSIZE)))
+ goto end; /* no " >" */
data = bh->b_data;
- for (k = 0; k < 8; k++)
+ for (k = 0; k < vpb; k++)
{
u8 *block;
- block = data + 0x80*k;
- if (block[19] != VBLK_PART)
+ block = data + vbs*k;
+ if (block[19] != VBLK_PART) /*19 CONST */
continue;
- if (!parse_vblk (&ph1, data+(0x80*k), &vb))
- goto free;
+ if (!parse_vblk (&ph, data+(vbs*k), &vb))
+ goto free; /* no " >" */
if (dk.obj_id != vb.disk_id)
continue;
- if (create_partition (hd, minor, vb.start_sector + ph1.log_disk_start, vb.num_sectors))
+ if (create_partition (hd, minor, vb.start_sector + ph.log_disk_start, vb.num_sectors))
minor++;
}
@@ -424,54 +456,3 @@
return ret;
}
-
-#if 0
- minor = ((minor + hd->max_p) & ~(hd->max_p - 1)) - 1; /* round up */
- hd->part[minor].start_sect = ph1.config_start;
- hd->part[minor].nr_sects = ph1.config_size;
-
- //if (data)...?
- /* find the three copies of the private header
- * and verify that they are identical */
- //LDM_FIRST_PART
-
-#define isprint(a) ((a >=' ')&&(a <= '~'))
- if (0)
- {
- int offset = 0;
- printk ("%02x %02x %02x %02x %02x %02x %02x %02x - %c%c%c%c%c%c%c%c\n", data[offset+0], data[offset+1], data[offset+2], data[offset+3], data[offset+4], data[offset+5], data[offset+6], data[offset+7], isprint (data[offset+0]) ? data[offset+0] : '.', isprint (data[offset+1]) ? data[offset+1] : '.', isprint (data[offset+2]) ? data[offset+2] : '.', isprint (data[offset+3]) ? data[offset+3] : '.', isprint (data[offset+4]) ? data[offset+4] : '.', isprint (data[offset+5]) ? data[offset+5] : '.', isprint (data[offset+6]) ? data[offset+6] : '.', isprint (data[offset+7]) ? data[offset+7] : '.');
- offset += 128;
- printk ("\n");
- }
-
-void dump_sectors (kdev_t dev, int block, int size)
-{
- struct buffer_head *bh;
- u8 *data;
- int i, off = 0;
-
- if (!(bh = bread (dev, block, size)))
- return;
-
- printk ("block = %d, size = %d\n", block, size);
-
- data = bh->b_data;
-
- for (i = 0; i < size/512; i++, off+=512)
- {
- printk ("%d %02x %02x %02x %02x\n", i, data[off+0], data[off+1], data[off+2], data[off+3]);
- }
- printk ("\n");
-
- bforget (bh);
-}
-
- set_blocksize (dev, 512);
- if (!(bh = bread (dev, 1, 512)))
- return -1;
-
- if (bh->b_data[0] != 1)
- return 0;
- bforget (bh);
-
-#endif
Index: ldm.h
===================================================================
RCS file: /cvsroot/linux-ntfs/dynamic-disk/linux/fs/partitions/ldm.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -U2 -r1.3 -r1.4
--- ldm.h 2001/06/20 02:55:42 1.3
+++ ldm.h 2001/06/21 01:08:45 1.4
@@ -59,4 +59,7 @@
#define OFF_VBLK 9
+#define LDM_BLOCKSIZE 1024
+#define LDM_DB_SIZE 2048 /* sectors == 1 MiB */
+
#define WIN2K_DYNAMIC_PARTITION 0x42 /* Formerly SFS */
|