Changes by: flatcap
Update of /cvsroot/linux-ntfs/dynamic-disk/linux/fs/partitions
In directory usw-pr-cvs1:/tmp/cvs-serv23349/linux/fs/partitions
Modified Files:
ldm.c ldm.h
Log Message:
more shufflings about. more fixmes. nothing significant.
Index: ldm.c
===================================================================
RCS file: /cvsroot/linux-ntfs/dynamic-disk/linux/fs/partitions/ldm.c,v
retrieving revision 1.69
retrieving revision 1.70
diff -U2 -r1.69 -r1.70
--- ldm.c 11 Apr 2002 14:27:39 -0000 1.69
+++ ldm.c 15 Apr 2002 00:14:20 -0000 1.70
@@ -1,4 +1,4 @@
/**
- * ldm - Support for Windows' Logical Disk Manager (Dynamic Disks)
+ * ldm - Support for Windows Logical Disk Manager (Dynamic Disks)
*
* Copyright (C) 2001,2002 Richard Russon <ld...@fl...>
@@ -152,5 +152,5 @@
return TRUE;
}
-// FIXME: Why doesn't this work ??
+
/**
@@ -175,7 +175,12 @@
}
- ph->ver_major = BE16 (data + 0x000C);
- ph->ver_minor = BE16 (data + 0x000E);
- // FIXME move checks to validate_*, maybe later coalesce?
+ ph->ver_major = BE16 (data + 0x000C);
+ ph->ver_minor = BE16 (data + 0x000E);
+ ph->logical_disk_start = BE64 (data + 0x011B);
+ ph->logical_disk_size = BE64 (data + 0x0123);
+ ph->config_start = BE64 (data + 0x012B);
+ ph->config_size = BE64 (data + 0x0133);
+
+ // FIXME move checks to validate_*?
if ((ph->ver_major != 2) || (ph->ver_minor != 11)) {
ldm_error ("Expected PRIVHEAD version %d.%d, got %d.%d."
@@ -183,6 +188,4 @@
return FALSE;
}
- ph->config_start = BE64 (data + 0x012B);
- ph->config_size = BE64 (data + 0x0133);
if (ph->config_size != LDM_DB_SIZE) { /* 1 MiB in sectors. */
/* Warn the user and continue, carefully */
@@ -191,6 +194,4 @@
(unsigned long long)ph->config_size );
}
- ph->logical_disk_start = BE64 (data + 0x011B);
- ph->logical_disk_size = BE64 (data + 0x0123);
if ((ph->logical_disk_size == 0) ||
(ph->logical_disk_start + ph->logical_disk_size > ph->config_start)) {
@@ -200,5 +201,5 @@
if (!ldm_parse_guid (data + 0x0030, ph->disk_id)) {
- ldm_error ("PRIVHEAD contains an invalid GUID.");
+ ldm_error ("PRIVHEAD contains an invalid GUID."); // FIXME too specific?
return FALSE;
}
@@ -295,5 +296,4 @@
}
-
/**
* ldm_compare_privheads - Compare two privhead objects
@@ -345,58 +345,4 @@
}
-
-/**
- * ldm_validate_partition_table - Determine whether bdev might be a dynamic disk
- * @bdev: Device to test
- *
- * This function provides a weak test to decide whether the device is a dynamic
- * disk or not. It looks for an MS-DOS-style partition table containing at
- * least one partition of type 0x42 (formerly SFS, now used by Windows for
- * dynamic disks).
- *
- * N.B. The only possible error can come from the read_dev_sector and that is
- * only likely to happen if the underlying device is strange. If that IS
- * the case we should return zero to let someone else try.
- *
- * Return: TRUE @bdev is a dynamic disk
- * FALSE @bdev is not a dynamic disk, or an error occurred
- */
-static BOOL ldm_validate_partition_table (struct block_device *bdev)
-{
- Sector sect;
- u8 *data;
- struct partition *p;
- int i;
- BOOL result = FALSE;
-
- DEBUG_ON (!bdev);
-
- data = read_dev_sector (bdev, 0, §);
- if (!data) {
- ldm_crit ("Disk read failed.");
- return FALSE;
- }
-
- if (*(u16*) (data + 0x01FE) != cpu_to_le16 (MSDOS_LABEL_MAGIC)) {
- ldm_debug ("No MS-DOS partition table found.");
- goto out;
- }
-
- p = (struct partition*)(data + 0x01BE);
- for (i = 0; i < 4; i++, p++)
- if (SYS_IND(p) == WIN2K_DYNAMIC_PARTITION) {
- result = TRUE;
- break;
- }
-
- if (result)
- ldm_debug ("Parsed partition table successfully.");
- else
- ldm_debug ("Found an MS-DOS partition table, not a dynamic disk.");
-out:
- put_dev_sector(sect);
- return result;
-}
-
/**
* ldm_validate_privheads - Compare the primary privhead with its backups
@@ -445,8 +391,9 @@
put_dev_sector (sect);
if (!result) {
- //if (i < 2)
+ // FIXME it IS already logged, but we don't know _which_ privhead failed
+ if (i < 2)
goto out; /* Already logged */
- //else
- //ldm_info ("Ignoring error");
+ else
+ break; // FIXME ignore for now
}
}
@@ -469,7 +416,7 @@
if (!ldm_compare_privheads (ph[0], ph[1]) ||
!ldm_compare_privheads (ph[0], ph[2])) {
- ldm_crit ("Primary and backup PRIVHEADs don't match.");
- goto out;
+ //ldm_crit ("Primary and backup PRIVHEADs don't match.");
// FIXME ignore this too?
+ //goto out;
}
@@ -511,5 +458,5 @@
ph = &ldb->ph;
tb[0] = &ldb->toc;
- tb[1] = kmalloc (sizeof (*tb[1]), GFP_KERNEL); // FIXME coalesce?
+ tb[1] = kmalloc (sizeof (*tb[1]), GFP_KERNEL); // FIXME coalesce? - maybe not, but do we really need four, why not two?
tb[2] = kmalloc (sizeof (*tb[2]), GFP_KERNEL);
tb[3] = kmalloc (sizeof (*tb[3]), GFP_KERNEL);
@@ -611,4 +558,58 @@
}
+
+/**
+ * ldm_validate_partition_table - Determine whether bdev might be a dynamic disk
+ * @bdev: Device to test
+ *
+ * This function provides a weak test to decide whether the device is a dynamic
+ * disk or not. It looks for an MS-DOS-style partition table containing at
+ * least one partition of type 0x42 (formerly SFS, now used by Windows for
+ * dynamic disks).
+ *
+ * N.B. The only possible error can come from the read_dev_sector and that is
+ * only likely to happen if the underlying device is strange. If that IS
+ * the case we should return zero to let someone else try.
+ *
+ * Return: TRUE @bdev is a dynamic disk
+ * FALSE @bdev is not a dynamic disk, or an error occurred
+ */
+static BOOL ldm_validate_partition_table (struct block_device *bdev)
+{
+ Sector sect;
+ u8 *data;
+ struct partition *p;
+ int i;
+ BOOL result = FALSE;
+
+ DEBUG_ON (!bdev);
+
+ data = read_dev_sector (bdev, 0, §);
+ if (!data) {
+ ldm_crit ("Disk read failed.");
+ return FALSE;
+ }
+
+ if (*(u16*) (data + 0x01FE) != cpu_to_le16 (MSDOS_LABEL_MAGIC)) {
+ ldm_debug ("No MS-DOS partition table found.");
+ goto out;
+ }
+
+ p = (struct partition*)(data + 0x01BE);
+ for (i = 0; i < 4; i++, p++)
+ if (SYS_IND(p) == WIN2K_DYNAMIC_PARTITION) {
+ result = TRUE;
+ break;
+ }
+
+ if (result)
+ ldm_debug ("Parsed partition table successfully.");
+ else
+ ldm_debug ("Found an MS-DOS partition table, not a dynamic disk.");
+out:
+ put_dev_sector(sect);
+ return result;
+}
+
/**
* ldm_find_vblk - Search a linked list of VBLKs for a given object id
@@ -638,4 +639,30 @@
/**
+ * ldm_get_disk_objid - Search a linked list of vblk's for a given Disk Id
+ * @ldb: ldmdb struct
+ *
+ * The LDM Database contains a list of all partitions on all dynamic disks. The
+ * primary PRIVHEAD, at the beginning of the physical disk, tells us the GUID of
+ * this disk. This function searches for the GUID in a linked list of vblk's.
+ *
+ * Return: Pointer, A matching vblk was found
+ * NULL, No match, or an error
+ */
+static struct vblk * ldm_get_disk_objid (const struct ldmdb *ldb)
+{
+ list_t *item;
+
+ DEBUG_ON (!ldb);
+
+ list_for_each (item, &ldb->v_disk) {
+ struct vblk *v = list_entry (item, struct vblk, list);
+ if (!memcmp(v->vblk.disk.disk_id, ldb->ph.disk_id, GUID_SIZE))
+ return v;
+ }
+
+ return NULL;
+}
+
+/**
* ldm_create_partition - Create a kernel partition device
* @hd: gendisk structure in which to create partition
@@ -692,9 +719,10 @@
static BOOL ldm_create_data_partitions (struct gendisk *hd,
unsigned long first_sector, int first_minor,
- const struct ldmdb *ldb, const struct vblk *disk)
+ const struct ldmdb *ldb)
{
// FIXME THIS FUNCTION CANNOT FAIL!
list_t *item;
struct vblk_part *part;
+ struct vblk *disk;
int disk_minor;
int minor;
@@ -702,4 +730,10 @@
DEBUG_ON (!hd || !ldb || !disk);
+ disk = ldm_get_disk_objid (ldb);
+ if (!disk) {
+ ldm_crit ("can't find this disk"); //FIXME
+ return FALSE;
+ }
+
/**
* Get the minor number of the parent device so we can check we don't
@@ -729,10 +763,10 @@
/* Try to get parent component */
c = ldm_find_vblk(&ldb->v_comp, part->parent_id);
- if (c == NULL)
+ if (c == NULL) // FIXME logging
continue;
/* Try to get parent volume */
v = ldm_find_vblk(&ldb->v_volu, c->vblk.comp.parent_id);
- if (v == NULL)
+ if (v == NULL) // FIXME logging
continue;
@@ -912,12 +946,11 @@
ldm_get_vstr (buffer + 0x18 + r_name, comp->state,
sizeof (comp->state));
- comp->type = buffer[0x18 + r_vstate];
- comp->n_childs = ldm_get_vnum (buffer + 0x1D + r_vstate);
+ comp->type = buffer[0x18 + r_vstate];
+ comp->children = ldm_get_vnum (buffer + 0x1D + r_vstate);
comp->parent_id = ldm_get_vnum (buffer + 0x2D + r_child);
- comp->chunksize = (r_stripe)
- ? ldm_get_vnum (buffer + 0x2E + r_parent)
- : 0;
-
+#ifdef CONFIG_BLK_DEV_MD
+ comp->chunksize = (r_stripe) ? ldm_get_vnum (buffer+0x2E+r_parent) : 0;
+#endif
return TRUE;
}
@@ -1045,5 +1078,5 @@
sizeof (disk->alt_name));
if (!ldm_parse_guid (buffer + 0x19 + r_name, disk->disk_id)) {
- ldm_error ("VBLK DISK contains an invalid GUID.");
+ ldm_error ("VBLK DSK3 contains an invalid GUID."); // FIXME do we want to be specific?
return FALSE;
}
@@ -1070,7 +1103,7 @@
DEBUG_ON (!buffer || !vb);
- r_objid = ldm_relative (buffer, buflen, 0x18, 0);
- r_name = ldm_relative (buffer, buflen, 0x18, r_objid);
- len = r_name;
+ r_objid = ldm_relative (buffer, buflen, 0x18, 0);
+ r_name = ldm_relative (buffer, buflen, 0x18, r_objid);
+ len = r_name;
if (len < 0)
return FALSE;
@@ -1206,69 +1239,43 @@
/**
- * ldm_parse_vblk_head - Read a raw VBLK header into a vblk_head structure
- * @src: The block of data being worked on
- * @vbh: In-memory vblk_head in which to return information
- *
- * This function just reads the information necessary for to identify
- * multipart VBLKS.
- *
- * Return: TRUE
- * FALSE
- */
-static BOOL ldm_parse_vblk_head (const u8 *src, struct vblk_head *vbh)
-{
- DEBUG_ON (!src || !vbh);
-
- if (MAGIC_VBLK != BE32 (src))
- return FALSE;
-
- vbh->group = BE32 (src + 0x08);
- vbh->rec = BE16 (src + 0x0C);
- vbh->nrec = BE16 (src + 0x0E);
-
- return TRUE;
-}
-
-/**
* ldm_parse_vblk - Read a raw VBLK object into a vblk structure
- * @src: The block of data being worked on
- * @size: The size of the block of data
+ * @buf: The block of data being worked on
+ * @len: The size of the block of data
* @vb: In-memory vblk in which to return information
*
* Read a raw VBLK object into a vblk structure. This function just reads the
* information common to all VBLK types, then delegates the rest of the work to
- * help functions: ldm_parse_*.
+ * helper functions: ldm_parse_*.
*
* Return: TRUE @vb contains a VBLK
* FALSE @vb contents are not defined
*/
-static BOOL ldm_parse_vblk (const u8 *src, int size, struct vblk *vb)
+static BOOL ldm_parse_vblk (const u8 *buf, int len, struct vblk *vb)
{
- // FIXME: this is ugly.
- /* Compensate for vblk_head. */
- const u8 *buffer = src - VBLK_SIZE_HEAD;
- const int buflen = size + VBLK_SIZE_HEAD;
BOOL result = FALSE;
- DEBUG_ON (!src || !vb);
+ DEBUG_ON (!buf || !vb);
+
+ buf -= VBLK_SIZE_HEAD; /* Skip the header FIXME WHAT? */
+ len += VBLK_SIZE_HEAD;
- if (ldm_out_of_range (buffer, buflen, 0x18)) {
+ if (ldm_out_of_range (buf, len, 0x18)) {
// FIXME logging
return FALSE;
}
- vb->flags = buffer[0x12];
- vb->type = buffer[0x13];
- vb->obj_id = ldm_get_vnum (buffer + 0x18);
- ldm_get_vstr (buffer+0x19+buffer[0x18], vb->name, sizeof (vb->name));
+ vb->flags = buf[0x12];
+ vb->type = buf[0x13];
+ vb->obj_id = ldm_get_vnum (buf + 0x18);
+ ldm_get_vstr (buf+0x19+buf[0x18], vb->name, sizeof (vb->name)); //FIXME use relative?
switch (vb->type) {
- case VBLK_CMP3: result = ldm_parse_cmp3 (buffer, buflen, vb); break;
- case VBLK_DSK3: result = ldm_parse_dsk3 (buffer, buflen, vb); break;
- case VBLK_DSK4: result = ldm_parse_dsk4 (buffer, buflen, vb); break;
- case VBLK_DGR3: result = ldm_parse_dgr3 (buffer, buflen, vb); break;
- case VBLK_DGR4: result = ldm_parse_dgr4 (buffer, buflen, vb); break;
- case VBLK_PRT3: result = ldm_parse_prt3 (buffer, buflen, vb); break;
- case VBLK_VOL5: result = ldm_parse_vol5 (buffer, buflen, vb); break;
+ case VBLK_CMP3: result = ldm_parse_cmp3 (buf, len, vb); break;
+ case VBLK_DSK3: result = ldm_parse_dsk3 (buf, len, vb); break;
+ case VBLK_DSK4: result = ldm_parse_dsk4 (buf, len, vb); break;
+ case VBLK_DGR3: result = ldm_parse_dgr3 (buf, len, vb); break;
+ case VBLK_DGR4: result = ldm_parse_dgr4 (buf, len, vb); break;
+ case VBLK_PRT3: result = ldm_parse_prt3 (buf, len, vb); break;
+ case VBLK_VOL5: result = ldm_parse_vol5 (buf, len, vb); break;
}
@@ -1289,6 +1296,8 @@
* @ldb: ldmdb structure containing VBLK lists
*
- * Place vblk in correct list by type. Partitions are added in sorted order.
+ * Place vblk in correct list by type. Partitions are sorted by offset.
+ *
* Strange vblk's should've been removed in ldm_parse_vblk.
+ * FIXME prereq:vb is already sanity-checked.
*
* Return: none
@@ -1300,5 +1309,5 @@
DEBUG_ON (!vb || !ldb);
- /* Put vblk into the correct list. @vb is already sanity-checked. */
+ /* Put vblk into the correct list. */
switch (vb->type) {
case VBLK_DGR3:
@@ -1317,9 +1326,9 @@
return;
case VBLK_PRT3:
- /* Sort by partition's start sector */
+ /* Sort by the partition's start sector. */
list_for_each(item, &ldb->v_part) {
struct vblk *v = list_entry(item, struct vblk, list);
- if (v->vblk.part.disk_id == vb->vblk.part.disk_id &&
- v->vblk.part.start > vb->vblk.part.start) {
+ if ((v->vblk.part.disk_id == vb->vblk.part.disk_id) &&
+ (v->vblk.part.start > vb->vblk.part.start)) {
list_add_tail(&vb->list, &v->list);
return;
@@ -1521,7 +1530,6 @@
BOOL result = FALSE;
- DEBUG_ON (!bdev || !ldb);
+ DEBUG_ON (!bdev || !ldb); // FIXME useless after deref'ing ldb (above)
- /* FIXME what about overrun x%y!=0, can it actually happen? */
/* Loop through sectors */
for (s = skip; s < finish; s++) {
@@ -1531,5 +1539,5 @@
data = read_dev_sector (bdev, base + OFF_VMDB + s, §);
if (!data) {
- ldm_crit ("Disk read failed in get buffers.");
+ ldm_crit ("Disk read failed in get buffers."); //FIXME
goto out;
}
@@ -1541,13 +1549,17 @@
struct vblk_head vbh;
- if (!ldm_parse_vblk_head (block, &vbh)) {
- ldm_error ("not a VBLK");
+ if (MAGIC_VBLK != BE32 (block)) {
+ ldm_error ("not a VBLK"); //FIXME
goto out;
}
- if (vbh.nrec == 0) /* Not in use */
+ /* Common to all VBLKs */
+ vbh.group = BE32 (block + 0x08);
+ vbh.rec = BE16 (block + 0x0C);
+ vbh.nrec = BE16 (block + 0x0E);
+ if (vbh.nrec == 0) /* Record is not in use */
continue;
- // Record is multipart
+ /* Record is multipart */
if (vbh.nrec > 1) {
if (ldm_frag_add(&fraglist, &vbh, body_data, body_size) < 0)
@@ -1587,30 +1599,4 @@
/**
- * ldm_get_disk_objid - Search a linked list of vblk's for a given Disk Id
- * @ldb: ldmdb struct
- *
- * The LDM Database contains a list of all partitions on all dynamic disks. The
- * primary PRIVHEAD, at the beginning of the physical disk, tells us the GUID of
- * this disk. This function searches for the GUID in a linked list of vblk's.
- *
- * Return: Pointer, A matching vblk was found
- * NULL, No match, or an error
- */
-static struct vblk * ldm_get_disk_objid (const struct ldmdb *ldb)
-{
- list_t *item;
-
- DEBUG_ON (!ldb);
-
- list_for_each (item, &ldb->v_disk) {
- struct vblk *v = list_entry (item, struct vblk, list);
- if (!memcmp(v->vblk.disk.disk_id, ldb->ph.disk_id, GUID_SIZE))
- return v;
- }
-
- return NULL;
-}
-
-/**
* ldm_free_vblks - Free a linked list of vblk's
* @lh: Head of a linked list of struct vblk
@@ -1654,7 +1640,6 @@
unsigned long first_sector, int first_minor)
{
- struct ldmdb *ldb;
- struct vblk *disk;
- unsigned long base;
+ struct ldmdb *ldb;
+ unsigned long base;
int err = -1;
@@ -1662,5 +1647,5 @@
/* Look for signs of a Dynamic Disk */
- if (!ldm_validate_partition_table (bdev))
+ if (!ldm_validate_partition_table (bdev)) // FIXME rename to find_dynamic_disk?
return 0;
@@ -1695,17 +1680,10 @@
if (!ldm_get_vblks (bdev, base, ldb)) {
- ldm_crit ("get buffers failed");
- goto cleanup;
- }
-
- disk = ldm_get_disk_objid (ldb);
- if (!disk) {
- ldm_crit ("can't find this disk");
+ ldm_crit ("get buffers failed"); //FIXME
goto cleanup;
}
/* Finally, create the data partition devices. */
- if (ldm_create_data_partitions (hd, first_sector, first_minor,
- ldb, disk)) {
+ if (ldm_create_data_partitions (hd, first_sector, first_minor, ldb)) {
ldm_debug ("Parsed LDM database successfully.");
err = 1;
Index: ldm.h
===================================================================
RCS file: /cvsroot/linux-ntfs/dynamic-disk/linux/fs/partitions/ldm.h,v
retrieving revision 1.42
retrieving revision 1.43
diff -U2 -r1.42 -r1.43
--- ldm.h 11 Apr 2002 14:29:47 -0000 1.42
+++ ldm.h 15 Apr 2002 00:14:20 -0000 1.43
@@ -72,5 +72,4 @@
/* size of a vblk's static parts */
#define VBLK_SIZE_HEAD 16
-
#define VBLK_SIZE_CMP3 22 /* Name and version */
#define VBLK_SIZE_DGR3 12
@@ -168,6 +167,8 @@
u64 parent_id;
u8 type;
- u8 n_childs;
+ u8 children;
+#ifdef CONFIG_BLK_DEV_MD
u16 chunksize;
+#endif
};
|