Changes by: flatcap
Update of /cvsroot/linux-ntfs/dynamic-disk/linux/fs/partitions
In directory usw-pr-cvs1:/tmp/cvs-serv28355/linux/fs/partitions
Modified Files:
ldm.c
Log Message:
minor fixes
Index: ldm.c
===================================================================
RCS file: /cvsroot/linux-ntfs/dynamic-disk/linux/fs/partitions/ldm.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -U2 -r1.57 -r1.58
--- ldm.c 9 Feb 2002 18:10:08 -0000 1.57
+++ ldm.c 17 Feb 2002 22:16:13 -0000 1.58
@@ -77,9 +77,8 @@
vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
- printk(LDM_DEBUG "(DEBUG) (%s, %d): %s: %s\n",
+ printk(LDM_DEBUG "(DEBUG) (%s, %d): %s: %s",
file, line, function ? function : "", buf);
}
#endif
-
/**
* ldm_parse_hexbyte - Convert a ASCII hex number to a byte
@@ -94,4 +93,6 @@
int h;
+ BUG_ON (!src);
+
/* high part */
if ((a = src[0] - '0') <= '9'-'0') h = a;
@@ -110,8 +111,8 @@
/**
* ldm_parse_guid - Convert GUID from ASCII to binary
- * @src: 36 char string on the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
- * @dest: memory block to hold binary GUID (16 bytes)
+ * @src: A 36 char string of the form fa50ff2b-f2e8-45de-83fa-65417f2f49ba
+ * @dest: Memory block to hold binary GUID (16 bytes)
*
- * NB not NULL terminated!
+ * N.B. The GUID need not be NULL terminated.
*
* Return: TRUE @dest contains binary GUID
@@ -120,18 +121,20 @@
static BOOL ldm_parse_guid (const u8 *src, u8 *dest)
{
- const int size[] = { 4, 2, 2, 2, 6 };
+ static const int size[] = { 4, 2, 2, 2, 6 };
int i, j, v;
- if (src[8] != '-' || src[13] != '-' ||
- src[18] != '-' || src[23] != '-')
+ BUG_ON (!src || !dest);
+
+ if ((src[8] != '-') || (src[13] != '-') ||
+ (src[18] != '-') || (src[23] != '-'))
return FALSE;
- for (j = 0; j < 5; j++) {
+ for (j = 0; j < 5; j++, src++) {
for (i = 0; i < size[j]; i++, src+=2, dest++) {
- if ((v = ldm_parse_hexbyte(src)) < 0)
- return 0;
+ v = ldm_parse_hexbyte (src);
+ if (v < 0)
+ return FALSE;
*dest = v;
}
- src++;
}
@@ -139,4 +142,5 @@
}
+
/**
* ldm_parse_privhead - Read the LDM Database PRIVHEAD structure
@@ -177,6 +181,8 @@
ph->logical_disk_size = BE64 (data + 0x0123);
if ((ph->logical_disk_size == 0) ||
- (ph->logical_disk_start + ph->logical_disk_size > ph->config_start))
+ (ph->logical_disk_start + ph->logical_disk_size > ph->config_start)) {
+ printk (LDM_ERR "PRIVHEAD disk size doesn't match real disk size\n");
return FALSE;
+ }
if (!ldm_parse_guid (data + 0x0030, ph->disk_id)) {
@@ -351,28 +357,33 @@
struct partition *p;
int i;
+ BOOL result = FALSE;
- if ((data = read_dev_sector (bdev, 0, §)) == 0)
- return FALSE; // FIXME error message?
+ BUG_ON (!bdev);
+
+ data = read_dev_sector (bdev, 0, §);
+ if (!data) {
+ printk (LDM_CRIT "Disk read failed.\n");
+ return FALSE;
+ }
if (*(u16*) (data + 0x01FE) != cpu_to_le16 (MSDOS_LABEL_MAGIC)) {
ldm_debug ("No MS-DOS partition found.\n");
- put_dev_sector(sect);
- return FALSE;
+ goto out;
}
p = (struct partition*)(data + 0x01BE);
for (i = 0; i < 4; i++, p++)
- if (SYS_IND(p) == WIN2K_DYNAMIC_PARTITION)
+ if (SYS_IND(p) == WIN2K_DYNAMIC_PARTITION) {
+ result = TRUE;
break;
+ }
+ if (result)
+ ldm_debug ("Parsed partition table successfully.\n");
+ else
+ ldm_debug ("Found an MS-DOS partition, not a dynamic disk.\n");
+out:
put_dev_sector(sect);
- if (i == 4) {
- ldm_debug(
- "Found a basic MS-DOS partition, not a dynamic disk.\n");
- return FALSE;
- }
-
- ldm_debug ("Parsed partition table successfully.\n");
- return TRUE;
+ return result;
}
@@ -391,11 +402,20 @@
unsigned long first_sector, struct privhead *ph1)
{
+ struct privhead *ph[3] = { ph1, NULL, NULL };
+ static const int off[3] = { OFF_PRIVHEAD1, OFF_PRIVHEAD2, OFF_PRIVHEAD3 };
Sector sect;
u8 *data;
- struct privhead ph2, ph3;
- struct privhead *ph[3] = {ph1, &ph2, &ph3};
- const int off[3] = {OFF_PRIVHEAD1, OFF_PRIVHEAD2, OFF_PRIVHEAD3};
+ BOOL result = FALSE;
int i;
+ BUG_ON (!bdev || !ph1);
+
+ ph[1] = kmalloc (sizeof (*ph[1]), GFP_KERNEL);
+ ph[2] = kmalloc (sizeof (*ph[2]), GFP_KERNEL);
+ if (!ph[1] || !ph[2]) {
+ printk (LDM_CRIT "Out of memory\n");
+ goto out;
+ }
+
/* off[1 & 2] are relative to ph[0]->config_start */
ph[0]->config_start = 0;
@@ -404,16 +424,14 @@
// FIXME can ph 3 fail on odd-sized disks?
for (i = 0; i < 3; i++) {
- BOOL r;
data = read_dev_sector (bdev,
first_sector + ph[0]->config_start + off[i], §);
if (!data) {
printk (LDM_CRIT "Disk read failed.\n");
- return FALSE;
+ goto out;
}
- r = ldm_parse_privhead(data, ph[i]);
+ result = ldm_parse_privhead(data, ph[i]);
put_dev_sector (sect);
-
- if (!r)
- return FALSE;
+ if (!result)
+ goto out; /* Already logged */
}
@@ -422,9 +440,13 @@
!ldm_compare_privheads (ph[0], ph[2])) {
printk (LDM_CRIT "Primary and backup PRIVHEADs don't match.\n");
- return FALSE;
+ goto out;
}
ldm_debug ("Validated PRIVHEADs successfully.\n");
- return TRUE;
+ result = TRUE;
+out:
+ kfree (ph[1]);
+ kfree (ph[2]);
+ return result;
}
@@ -446,23 +468,32 @@
Sector sect;
u8 *data;
- struct tocblock toc2, toc3, toc4;
- struct tocblock* tb[4] = {toc1, &toc2, &toc3, &toc4};
- const int off[4] = {
- OFF_TOCBLOCK1, OFF_TOCBLOCK2, OFF_TOCBLOCK3, OFF_TOCBLOCK4};
+ struct tocblock *tb[4] = { toc1, NULL, NULL, NULL };
+ static const int off[4] = {
+ OFF_TOCBLOCK1, OFF_TOCBLOCK2, OFF_TOCBLOCK3, OFF_TOCBLOCK4 };
+ BOOL result = FALSE;
int i;
+ BUG_ON (!bdev || !toc1);
+
+ tb[1] = kmalloc (sizeof (*tb[1]), GFP_KERNEL);
+ tb[2] = kmalloc (sizeof (*tb[2]), GFP_KERNEL);
+ tb[3] = kmalloc (sizeof (*tb[3]), GFP_KERNEL);
+ if (!tb[1] || !tb[2] || !tb[3]) {
+ printk (LDM_CRIT "Out of memory\n");
+ goto out;
+ }
+
/* Read and parse all four toc's. */
for (i = 0; i < 4; i++)
{
- BOOL r;
- if (!(data = read_dev_sector (bdev, base + off[i], §))) {
+ data = read_dev_sector (bdev, base + off[i], §);
+ if (!data) {
printk (LDM_CRIT "Disk read failed.\n");
- return FALSE;
+ goto out;
}
- r = ldm_parse_tocblock (data, tb[i]);
+ result = ldm_parse_tocblock (data, tb[i]);
put_dev_sector (sect);
-
- if (!r)
- return FALSE;
+ if (!result)
+ goto out;
}
@@ -472,9 +503,14 @@
!ldm_compare_tocblocks (tb[0], tb[3])) {
printk (LDM_CRIT "The TOCBLOCKs don't match.\n");
- return FALSE;
+ goto out;
}
ldm_debug ("Validated TOCBLOCKs successfully.\n");
- return TRUE;
+ result = TRUE;
+out:
+ kfree (tb[1]);
+ kfree (tb[2]);
+ kfree (tb[3]);
+ return result;
}
@@ -498,5 +534,8 @@
BOOL result;
- if ((data = read_dev_sector (bdev, base + OFF_VMDB, §)) == 0) {
+ BUG_ON (!bdev || !vm);
+
+ data = read_dev_sector (bdev, base + OFF_VMDB, §);
+ if (!data) {
printk (LDM_CRIT "Disk read failed.\n");
return FALSE;
@@ -520,4 +559,6 @@
list_t *item;
+ BUG_ON (!lh_vl);
+
list_for_each (item, lh_vl) {
struct vblk *vb = list_entry (item, struct vblk, list);
@@ -595,5 +636,5 @@
int minor;
- BUG_ON (!hd || !disk);
+ BUG_ON (!hd || !ldb || !disk);
/**
@@ -619,17 +660,19 @@
if (!ldm_create_partition(hd, minor,
part->start + ldb->ph.logical_disk_start, part->size))
- continue;
+ continue; /* Already logged */
minor++;
#ifdef CONFIG_BLK_DEV_MD
/* Try to get parent component */
- if ((c = ldm_find_vblk(&ldb->v_comp, part->parent_id)) == 0)
+ c = ldm_find_vblk(&ldb->v_comp, part->parent_id);
+ if (c == NULL)
continue;
/* Try to get parent volume */
- if ((v = ldm_find_vblk(&ldb->v_volu, c->vblk.comp.parent_id)) == 0)
+ v = ldm_find_vblk(&ldb->v_volu, c->vblk.comp.parent_id);
+ if (v == NULL);
continue;
/* Notify md of RAID autodetect part types */
- if (v && v->vblk.volu.partition_type == LINUX_RAID_PARTITION) {
+ if (v->vblk.volu.partition_type == LINUX_RAID_PARTITION) {
md_autodetect_dev(dev);
continue;
@@ -902,6 +945,8 @@
ldm_get_vstr (buffer + 0x18 + rel_diskid, disk->alt_name,
sizeof (disk->alt_name));
- if (!ldm_parse_guid (buffer + 0x19 + rel_name, disk->disk_id))
+ if (!ldm_parse_guid (buffer + 0x19 + rel_name, disk->disk_id)) {
+ printk (LDM_ERR "VBLK DISK contains an invalid GUID.\n");
return FALSE;
+ }
return TRUE;
@@ -1054,5 +1099,5 @@
struct page *page, BOOL recycled)
{
- BOOL result;
+ BOOL result = FALSE;
BUG_ON (!buffer || !vb);
@@ -1062,5 +1107,5 @@
if (MAGIC_VBLK != BE32 (buffer)) {
- ldm_debug("Not a valid VBLK, missing magic number.\n");
+ printk (LDM_ERR "Not a valid VBLK, missing magic number.\n");
return FALSE;
}
@@ -1075,5 +1120,5 @@
if (vb->rec_count == 0) {
- ldm_debug("record count is 0, skipping.\n");
+ printk (LDM_ERR "record count is 0, skipping.\n");
return FALSE;
}
@@ -1116,9 +1161,7 @@
result = ldm_parse_volu (buffer, buflen, vb); break;
default:
- ldm_debug("Unknown VBLK type: 0x%02x.\n", vb->type);
- result = FALSE;
+ /* Nothing to do, will be logged later */
}
-
if (!result)
printk (LDM_ERR "Failed to parse VBLK 0x%llx (type: 0x%02x).\n",
@@ -1139,9 +1182,9 @@
* Place vblk in correct list by examining type.
* All extended vblk's are placed in a special list for later processing.
- * Partitions and fragments is added in sorted order.
+ * Partitions and fragments are added in sorted order.
*
* Strange vblk's should've been removed in ldm_parse_vblk
- * This function returns void because it currently can't fail.
*
+ * Return: none
*/
static void ldm_ldmdb_add(struct vblk *vb, struct ldmdb *ldb)
@@ -1149,6 +1192,9 @@
list_t *item;
- /* If vb is part of a multiple-record vblk, we sort it into the pool by
- group and record number */
+ BUG_ON (!vb || !ldb);
+ //FIXME ldm_debugs?
+
+ /* If @vb is part of a multiple-record vblk, add it to the pool.
+ The pool is sorted by group and record number. */
if (vb->rec_count > 1) {
list_for_each (item, &ldb->v_extpool) {
@@ -1216,4 +1262,6 @@
u8 *ptr;
+ BUG_ON (!ldb);
+
if (list_empty(&ldb->v_extpool))
return 1;
@@ -1228,5 +1276,5 @@
struct vblk *v = list_entry (item, struct vblk, list);
if (v->rec_num!=rec || v->rec_count!=nrec || v->group!=group)
- break;
+ break; /* Don't log this, we've found the next group */
rec++;
}
@@ -1248,6 +1296,7 @@
/* Allocate memory buffer to hold the concatenated data */
- if ((data = kmalloc (ldb->vm.vblk_size * nrec, GFP_KERNEL)) == 0) {
- printk (LDM_CRIT "Out of memory in combine vblks.\n");
+ data = kmalloc (ldb->vm.vblk_size * nrec, GFP_KERNEL);
+ if (!data) {
+ printk (LDM_CRIT "Out of memory.\n");
return -1;
}
@@ -1261,4 +1310,6 @@
list_for_each (item, &ldb->v_extpool) {
struct vblk *v = list_entry (item, struct vblk, list);
+ if (v->group != group)
+ break;
memcpy(ptr, v->vblk.ext.data, v->vblk.ext.size);
ptr += v->vblk.ext.size;
@@ -1302,4 +1353,6 @@
int failed = 0;
+ BUG_ON (!bdev || !ldb);
+
/* FIXME what about overrun x%y!=0, can it actually happen? */
/* Loop through sectors */
@@ -1324,5 +1377,5 @@
continue;
- vl = (struct vblk*)kmalloc (sizeof (*vl), GFP_KERNEL);
+ vl = kmalloc (sizeof (*vl), GFP_KERNEL);
if (!vl) {
printk (LDM_CRIT "Out of memory in get vblks.\n");
@@ -1338,4 +1391,5 @@
}
+ /* Each VBLK we cache keeps a refcount to page */
put_dev_sector(sect);
if (failed)
@@ -1344,8 +1398,9 @@
/* Combine and parse vblk entries with multiple records */
+ // FIXME wouldn't this while be better in combine itself?
while ( (i = ldm_combine_vblks(ldb)) == 0 ) {}
if (i < 0) /* already logged */
- return 0;
+ return FALSE;
return TRUE;
@@ -1367,4 +1422,6 @@
list_t *item;
+ BUG_ON (!ldb);
+
list_for_each (item, &ldb->v_disk) {
struct vblk *v = list_entry (item, struct vblk, list);
@@ -1386,4 +1443,6 @@
list_t *item;
+ BUG_ON (!lh_vl);
+
list_for_each (item, lh_vl) {
struct vblk *v = list_entry (item, struct vblk, list);
@@ -1417,6 +1476,6 @@
unsigned long first_sector, int first_minor)
{
- struct tocblock toc;
- struct ldmdb ldb;
+ struct tocblock *toc;
+ struct ldmdb *ldb;
struct vblk *disk;
unsigned long base;
@@ -1429,37 +1488,42 @@
return 0;
+ toc = kmalloc (sizeof (*toc), GFP_KERNEL);
+ ldb = kmalloc (sizeof (*ldb), GFP_KERNEL);
+ if (!toc || !ldb) {
+ printk (LDM_CRIT "Out of memory\n");
+ goto out;
+ }
+
/* Parse and check privheads. */
- if (!ldm_validate_privheads (bdev, first_sector, &ldb.ph))
- return -1;
+ if (!ldm_validate_privheads (bdev, first_sector, &ldb->ph))
+ goto out;
/* All further references are relative to base (database start). */
- base = first_sector + ldb.ph.config_start;
+ base = first_sector + ldb->ph.config_start;
/* Parse and check tocs and vmdb. */
- if (!ldm_validate_tocblocks (bdev, base, &toc) ||
- !ldm_validate_vmdb (bdev, base, &ldb.vm))
- return -1;
+ if (!ldm_validate_tocblocks (bdev, base, toc) ||
+ !ldm_validate_vmdb (bdev, base, &ldb->vm))
+ goto out;
-#if 1
// FIXME: Why do we wan't this partition ??
/* Create the LDM database device. */
- if (!ldm_create_partition (hd, first_minor++, base, ldb.ph.config_size))
- goto cleanup;
-#endif
+ if (!ldm_create_partition (hd, first_minor++, base, ldb->ph.config_size))
+ goto out;
/* Initialize vblk lists in ldmdb struct */
- INIT_LIST_HEAD(&ldb.v_dgrp);
- INIT_LIST_HEAD(&ldb.v_disk);
- INIT_LIST_HEAD(&ldb.v_volu);
- INIT_LIST_HEAD(&ldb.v_comp);
- INIT_LIST_HEAD(&ldb.v_part);
- INIT_LIST_HEAD(&ldb.v_extpool);
+ INIT_LIST_HEAD(&ldb->v_dgrp);
+ INIT_LIST_HEAD(&ldb->v_disk);
+ INIT_LIST_HEAD(&ldb->v_volu);
+ INIT_LIST_HEAD(&ldb->v_comp);
+ INIT_LIST_HEAD(&ldb->v_part);
+ INIT_LIST_HEAD(&ldb->v_extpool);
- if (!ldm_get_vblks (bdev, base, &ldb)) {
+ if (!ldm_get_vblks (bdev, base, ldb)) {
printk (LDM_CRIT "get buffers failed\n");
goto cleanup;
}
- disk = ldm_get_disk_objid (&ldb);
+ disk = ldm_get_disk_objid (ldb);
if (!disk) {
printk (LDM_CRIT "can't find this disk\n");
@@ -1469,5 +1533,5 @@
/* Finally, create the data partition devices. */
if (ldm_create_data_partitions (hd, first_sector, first_minor,
- &ldb, disk)) {
+ ldb, disk)) {
ldm_debug ("Parsed LDM database successfully.\n");
err = 1;
@@ -1476,11 +1540,15 @@
cleanup:
- ldm_free_vblks(&ldb.v_dgrp);
- ldm_free_vblks(&ldb.v_disk);
- ldm_free_vblks(&ldb.v_volu);
- ldm_free_vblks(&ldb.v_comp);
- ldm_free_vblks(&ldb.v_part);
- ldm_free_vblks(&ldb.v_extpool);
+ ldm_free_vblks(&ldb->v_dgrp);
+ ldm_free_vblks(&ldb->v_disk);
+ ldm_free_vblks(&ldb->v_volu);
+ ldm_free_vblks(&ldb->v_comp);
+ ldm_free_vblks(&ldb->v_part);
+ ldm_free_vblks(&ldb->v_extpool);
+out:
+ kfree (toc);
+ kfree (ldb);
return err;
}
+
|