Changes by: flatcap
Update of /cvsroot/linux-ntfs/dynamic-disk/linux/fs/partitions
In directory usw-pr-cvs1:/tmp/cvs-serv16411/linux/fs/partitions
Modified Files:
ldm.c ldm.h
Log Message:
remove some junk and start tidying Jakob's new code
Index: ldm.c
===================================================================
RCS file: /cvsroot/linux-ntfs/dynamic-disk/linux/fs/partitions/ldm.c,v
retrieving revision 1.64
retrieving revision 1.65
diff -U2 -r1.64 -r1.65
--- ldm.c 9 Mar 2002 01:58:42 -0000 1.64
+++ ldm.c 12 Mar 2002 05:35:53 -0000 1.65
@@ -58,5 +58,4 @@
* driver was compiled with debug enabled. Otherwise, the call turns into a NOP.
*/
-
#ifndef CONFIG_LDM_DEBUG
# define ldm_debug(...) do {} while (0)
@@ -154,5 +153,6 @@
}
// FIXME: Why doesn't this work ??
-/*
+/**
+ *
static BOOL ldm_parse_guid (const u8 *src, u8 *dest)
{
@@ -172,5 +172,4 @@
*/
-
/**
* ldm_parse_privhead - Read the LDM Database PRIVHEAD structure
@@ -251,5 +250,5 @@
}
strncpy (toc->bitmap1_name, data + 0x24, sizeof (toc->bitmap1_name));
- toc->bitmap1_name[sizeof (toc->bitmap1_name) - 1] = (u8)'\0';
+ toc->bitmap1_name[sizeof (toc->bitmap1_name) - 1] = (u8)'\0'; // FIXME
toc->bitmap1_start = BE64 (data + 0x2E);
toc->bitmap1_size = BE64 (data + 0x36);
@@ -262,5 +261,5 @@
}
strncpy (toc->bitmap2_name, data + 0x46, sizeof (toc->bitmap2_name));
- toc->bitmap2_name[sizeof (toc->bitmap2_name) - 1] = (u8)'\0';
+ toc->bitmap2_name[sizeof (toc->bitmap2_name) - 1] = (u8)'\0'; // FIXME
toc->bitmap2_start = BE64 (data + 0x50);
toc->bitmap2_size = BE64 (data + 0x58);
@@ -440,4 +439,5 @@
DEBUG_ON (!bdev || !ph1);
+ // FIXME coalesce
ph[1] = kmalloc (sizeof (*ph[1]), GFP_KERNEL);
ph[2] = kmalloc (sizeof (*ph[2]), GFP_KERNEL);
@@ -505,4 +505,5 @@
DEBUG_ON (!bdev || !toc1);
+ // FIXME coalesce
tb[1] = kmalloc (sizeof (*tb[1]), GFP_KERNEL);
tb[2] = kmalloc (sizeof (*tb[2]), GFP_KERNEL);
@@ -707,4 +708,5 @@
}
/* Register to LDM_MD */
+ //FIXME chunk size is in a vblk and must be read
ldm_md_addpart(v->vblk.volu.guid, c->obj_id,
c->vblk.comp.type, part->partnum,
@@ -788,10 +790,10 @@
length = *block++;
- if (length && length <= 8) {
+ if (length && length <= 8)
while (length--)
tmp = (tmp << 8) | *block++;
- } else {
+ else
ldm_error ("Illegal length %d.\n", length);
- }
+
return tmp;
}
@@ -869,8 +871,6 @@
len += VBLK_SIZE_COMP;
- if (len != BE32 (buffer + 0x14)) {
- printk ("len (COMP): calc = 0x%02x, read = 0x%02x\n", len, BE32 (buffer + 0x14));
+ if (len != BE32 (buffer + 0x14))
return FALSE;
- }
comp = &vb->vblk.comp;
@@ -919,8 +919,6 @@
len += VBLK_SIZE_DGR1;
- if (len != BE32 (buffer + 0x14)) {
- printk ("len (DGR1): calc = 0x%02x, read = 0x%02x\n", len, BE32 (buffer + 0x14));
+ if (len != BE32 (buffer + 0x14))
return FALSE;
- }
dgrp = &vb->vblk.dgrp;
@@ -965,8 +963,6 @@
len += VBLK_SIZE_DGR2;
- if (len != BE32 (buffer + 0x14)) {
- printk ("len (DGR2): calc = 0x%02x, read = 0x%02x\n", len, BE32 (buffer + 0x14));
+ if (len != BE32 (buffer + 0x14))
return FALSE;
- }
dgrp = &vb->vblk.dgrp;
@@ -1003,8 +999,6 @@
len += VBLK_SIZE_DSK1;
- if (len != BE32 (buffer + 0x14)) {
- printk ("len (DSK1): calc = 0x%02x, read = 0x%02x\n", len, BE32 (buffer + 0x14));
+ if (len != BE32 (buffer + 0x14))
return FALSE;
- }
disk = &vb->vblk.disk;
@@ -1044,8 +1038,6 @@
len += VBLK_SIZE_DSK2;
- if (len != BE32 (buffer + 0x14)) {
- printk ("len (DSK2): calc = 0x%02x, read = 0x%02x\n", len, BE32 (buffer + 0x14));
+ if (len != BE32 (buffer + 0x14))
return FALSE;
- }
disk = &vb->vblk.disk;
@@ -1089,8 +1081,6 @@
len += VBLK_SIZE_PART;
- if (len != BE32 (buffer + 0x14)) {
- printk ("len (COMP): calc = 0x%02x, read = 0x%02x\n", len, BE32 (buffer + 0x14));
+ if (len != BE32 (buffer + 0x14))
return FALSE;
- }
part = &vb->vblk.part;
@@ -1157,8 +1147,6 @@
len += VBLK_SIZE_VOLU;
- if (len != BE32 (buffer + 0x14)) {
- printk ("len (VOLU): calc = 0x%02x, read = 0x%02x (0x%02x)\n", len, BE32 (buffer + 0x14), buffer[0x12]);
+ if (len != BE32 (buffer + 0x14))
return FALSE;
- }
volu = &vb->vblk.volu;
@@ -1190,10 +1178,12 @@
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);
+ vbh->rec = BE16 (src + 0x0C);
+ vbh->nrec = BE16 (src + 0x0E);
return TRUE;
@@ -1221,6 +1211,10 @@
BOOL result = FALSE;
- if (ldm_out_of_range (buffer, buflen, 0x18))
+ DEBUG_ON (!src || !vb);
+
+ if (ldm_out_of_range (buffer, buflen, 0x18)) {
+ // FIXME logging
return FALSE;
+ }
vb->flags = buffer[0x12];
@@ -1246,10 +1240,10 @@
}
- if (!result)
- ldm_error ("Failed to parse VBLK 0x%llx (type: 0x%02x).\n",
- vb->obj_id, vb->type);
- else
+ if (result)
ldm_debug ("Parsed VBLK 0x%llx (type: 0x%02x) ok.\n",
(unsigned long long) vb->obj_id, vb->type);
+ else
+ ldm_error ("Failed to parse VBLK 0x%llx (type: 0x%02x).\n",
+ vb->obj_id, vb->type);
return result;
@@ -1289,5 +1283,5 @@
return;
case VBLK_PART:
- /* Sort by partition start sector */
+ /* Sort by partition's start sector */
list_for_each(item, &ldb->v_part) {
struct vblk *v = list_entry(item, struct vblk, list);
@@ -1308,10 +1302,12 @@
* @list: List of fragments.
*/
-static inline struct frags* ldm_frag_find(list_t* list, u32 group)
+static inline struct frags *ldm_frag_find(list_t *list, u32 group)
{
- list_t* item;
+ list_t *item;
+
+ DEBUG_ON (!list);
list_for_each(item, list) {
- struct frags* f = list_entry(item, struct frags, list);
+ struct frags *f = list_entry(item, struct frags, list);
if (f->group == group)
return f;
@@ -1320,9 +1316,15 @@
}
-static inline void ldm_frag_listfree(list_t* list)
+/**
+ * ldm_frag_listfree -
+ */
+static inline void ldm_frag_listfree(list_t *list)
{
list_t *item, *tmp;
+
+ DEBUG_ON (!list);
+
list_for_each_safe(item, tmp, list)
- kfree( list_entry(item, struct frags, list) );
+ kfree (list_entry(item, struct frags, list));
INIT_LIST_HEAD(list);
@@ -1343,32 +1345,33 @@
* -1 error.
*/
-static int ldm_frag_add(list_t* list, const struct vblk_head* vbh,
- const u8* data, int size)
+static int ldm_frag_add(list_t *list, const struct vblk_head *vbh,
+ const u8 *data, int size)
{
BOOL bad = FALSE;
- struct frags* f;
+ struct frags *f;
+
+ DEBUG_ON (!list || !vbh || !data);
/* Sanity check vblk header. */
if (vbh->nrec > FRAG_MAX || vbh->rec >= vbh->nrec) {
ldm_error ("Invalid VBLK header.\n");
- bad = TRUE;
+ bad = TRUE; // FIXME shouldn't we return?
}
/* Try to find previous entry. */
- if ((f = ldm_frag_find(list, vbh->group) )) {
+ if ((f = ldm_frag_find(list, vbh->group))) {
/* More sanity checking. */
- if (FRAG_GETBAD(f))
+ if (FRAG_GETBAD(f)) {
bad = TRUE;
- else if (vbh->nrec != f->nrec || FRAG_GETMAP(f, vbh->rec)) {
+ // FIXME has this been logged already?
+ } else if (vbh->nrec != f->nrec || FRAG_GETMAP(f, vbh->rec)) {
ldm_error ("Inconsistent VBLK fragments!\n");
bad = TRUE;
}
- }
- /* Not found, create a new entry in list. */
- else {
+ } else { /* Not found, create a new entry in list. */
const int nrec = (bad) ? 0 : vbh->nrec;
/* Allocate memory */
- f = kmalloc(sizeof (struct frags) + nrec * size, GFP_KERNEL);
+ f = kmalloc(sizeof (*f) + nrec * size, GFP_KERNEL);
if (!f) {
ldm_crit ("Out of memory.\n");
@@ -1388,5 +1391,4 @@
if (bad)
FRAG_SETBAD(f);
-
/* Copy data */
else {
@@ -1395,5 +1397,5 @@
}
- return bad;
+ return !bad;
}
@@ -1409,12 +1411,14 @@
* FALSE
*/
-static BOOL ldm_frag_commit(list_t* list, int size, struct ldmdb* ldb)
+static BOOL ldm_frag_commit(list_t *list, int size, struct ldmdb *ldb)
{
list_t *item, *tmp;
- struct vblk* vb = 0;
+ struct vblk *vb = NULL;
BOOL result;
+ DEBUG_ON (!list || !ldb);
+
list_for_each_safe(item, tmp, list) {
- struct frags* f = list_entry(item, struct frags, list);
+ struct frags *f = list_entry(item, struct frags, list);
int i;
@@ -1432,5 +1436,5 @@
/* Allocate memory for VBLK if necessary. */
if (!vb)
- vb = kmalloc (sizeof(struct vblk), GFP_KERNEL);
+ vb = kmalloc (sizeof(*vb), GFP_KERNEL);
if (!vb) {
ldm_crit ("Out of memory.\n");
@@ -1442,5 +1446,5 @@
if (ldm_parse_vblk (f->data, size * f->nrec, vb)) {
ldm_ldmdb_add(vb, ldb);
- vb = 0;
+ vb = NULL;
}
/* else - Already logged */
@@ -1450,8 +1454,6 @@
}
result = TRUE;
-
out:
- if (vb)
- kfree (vb);
+ kfree (vb);
return result;
@@ -1479,6 +1481,6 @@
const int body_size = ldb->vm.vblk_size - 0x10;
LIST_HEAD(fraglist);
- struct vblk *vb = 0;
- u8 *data = 0;
+ struct vblk *vb = NULL;
+ u8 *data = NULL;
Sector sect;
int s;
@@ -1489,6 +1491,5 @@
/* FIXME what about overrun x%y!=0, can it actually happen? */
/* Loop through sectors */
- for (s = skip; s < finish; s++)
- {
+ for (s = skip; s < finish; s++) {
int i;
if (data)
@@ -1506,10 +1507,10 @@
struct vblk_head vbh;
- if (!ldm_parse_vblk_head (block, &vbh) ) {
+ if (!ldm_parse_vblk_head (block, &vbh)) {
ldm_error ("not a VBLK\n");
goto out;
}
- if (vbh.nrec == 0)
+ if (vbh.nrec == 0) /* Not in use */
continue;
@@ -1523,5 +1524,5 @@
/* Allocate memory for vblk */
if (!vb)
- vb = kmalloc (sizeof(struct vblk), GFP_KERNEL);
+ vb = kmalloc (sizeof(*vb), GFP_KERNEL);
if (!vb) {
ldm_crit ("Out of memory in get vblks.\n");
@@ -1532,5 +1533,5 @@
if (ldm_parse_vblk (body_data, body_size, vb)) {
ldm_ldmdb_add(vb, ldb);
- vb = 0;
+ vb = NULL;
}
/* else - Already logged */
@@ -1540,8 +1541,6 @@
/* Combine fragments. */
result = ldm_frag_commit(&fraglist, body_size, ldb);
-
out:
- if (vb)
- kfree(vb);
+ kfree(vb);
if (data)
put_dev_sector(sect);
@@ -1588,4 +1587,5 @@
{
list_t *item, *tmp;
+
DEBUG_ON (!lh);
@@ -1596,4 +1596,5 @@
}
+
/**
* ldm_partition - Find out whether a device is a dynamic disk and handle it
@@ -1650,5 +1651,4 @@
goto out;
- // 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))
@@ -1693,2 +1693,3 @@
return err;
}
+
Index: ldm.h
===================================================================
RCS file: /cvsroot/linux-ntfs/dynamic-disk/linux/fs/partitions/ldm.h,v
retrieving revision 1.37
retrieving revision 1.38
diff -U2 -r1.37 -r1.38
--- ldm.h 9 Mar 2002 01:58:42 -0000 1.37
+++ ldm.h 12 Mar 2002 05:35:53 -0000 1.38
@@ -115,12 +115,4 @@
/* Borrowed from msdos.c. */
#define SYS_IND(p) (get_unaligned(&p->sys_ind))
-#define NR_SECTS(p) ({ __typeof__(p->nr_sects) __a = \
- get_unaligned(&p->nr_sects); \
- le32_to_cpu(__a); \
- })
-#define START_SECT(p) ({ __typeof__(p->start_sect) __a = \
- get_unaligned(&p->start_sect); \
- le32_to_cpu(__a); \
- })
/* VBLK Fragment handling */
@@ -140,8 +132,6 @@
};
-
/* In memory LDM database structures. */
-#define DISK_ID_SIZE 64 /* Size in bytes. */
#define GUID_SIZE 16
|