Changes by: jkemi
Update of /cvsroot/linux-ntfs/dynamic-disk/linux/fs/partitions
In directory usw-pr-cvs1:/tmp/cvs-serv25481
Modified Files:
ldm.c ldm.h
Log Message:
Removed left-overs, restored compare_privhead(), new text output macros. Removed all nasty "string " "concatenations".
Index: ldm.c
===================================================================
RCS file: /cvsroot/linux-ntfs/dynamic-disk/linux/fs/partitions/ldm.c,v
retrieving revision 1.60
retrieving revision 1.61
diff -U2 -r1.60 -r1.61
--- ldm.c 24 Feb 2002 21:21:23 -0000 1.60
+++ ldm.c 27 Feb 2002 15:56:09 -0000 1.61
@@ -45,6 +45,5 @@
#endif
-typedef enum
-{
+typedef enum {
FALSE = 0,
TRUE = 1
@@ -59,4 +58,5 @@
* driver was compiled with debug enabled. Otherwise, the call turns into a NOP.
*/
+
#ifndef CONFIG_LDM_DEBUG
# define ldm_debug(f, a...) do {} while (0)
@@ -64,22 +64,40 @@
#else
# define DEBUG_ON BUG_ON
- static void _ldm_debug (const char *file, int line, const char *function,
- const char *fmt, ...) __attribute__ ((format (printf, 4, 5)));
-# define ldm_debug(f, a...) \
- _ldm_debug(__FILE__, __LINE__, __FUNCTION__, f, ##a)
+# define ldm_debug(f, a...) \
+ _ldm_printf (LDM_LVL_DEBUG, __FILE__, __LINE__, __func__, f, ##a)
+#endif
+
+#define ldm_crit(f, a...) \
+ _ldm_printf (LDM_LVL_CRIT, __FILE__, __LINE__, __func__, f, ##a)
+
+#define ldm_error(f, a...) \
+ _ldm_printf (LDM_LVL_ERR, __FILE__, __LINE__, __func__, f, ##a)
-static void _ldm_debug (const char *file, int line, const char *function,
- const char *fmt, ...)
+#define ldm_info(f, a...) \
+ _ldm_printf (LDM_LVL_INFO, __FILE__, __LINE__, __func__, f, ##a)
+
+__attribute__ ((format (printf, 5, 6)))
+static void _ldm_printf (unsigned level, const char *file, int line,
+ const char *function, const char *fmt, ...)
{
static char buf[128];
va_list args;
+ static const char *const prefix[] = {
+ KERN_CRIT, KERN_ERR, KERN_INFO, KERN_DEBUG, ""};
+ static const char *const label[] = {
+ "CRITICAL", "ERROR", "INFO", "DEBUG", ""};
va_start(args, fmt);
vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
- printk(LDM_DEBUG "(DEBUG) (%s, %d): %s: %s",
- file, line, function ? function : "", buf);
+
+ // FIXME: is it possible to make __FILE__ less detailed?
+ file = "ldm.c";
+ if (level > LDM_LVL_NONE)
+ level = LDM_LVL_NONE;
+
+ printk("%s(%s) (%s @ %d): %s(): %s", prefix[level], label[level],
+ file, line, function, buf);
}
-#endif
/**
@@ -135,8 +153,9 @@
return TRUE;
}
-/* FIXME: Why doesn't this work ??
+// FIXME: Why doesn't this work ??
+/*
static BOOL ldm_parse_guid (const u8 *src, u8 *dest)
{
- u16 *tmp;
+ u16 *tmp = (u16*)dest;
DEBUG_ON (!src || !dest);
@@ -146,7 +165,8 @@
return FALSE;
- tmp = (u16*) dest;
- return (8 == sscanf (src, "%04hx%04hx-%04hx-%04hx-%04hx-%04hx%04hx%04hx",
- tmp, tmp+1, tmp+2, tmp+3, tmp+4, tmp+5, tmp+6, tmp+7));
+ return (
+ 8 == sscanf (src, "%04hx%04hx-%04hx-%04hx-%04hx-%04hx%04hx%04hx",
+ tmp, tmp+1, tmp+2, tmp+3, tmp+4, tmp+5, tmp+6, tmp+7)
+ );
}
*/
@@ -168,13 +188,14 @@
if (MAGIC_PRIVHEAD != BE64 (data)) {
- printk (LDM_ERR "Cannot find PRIVHEAD structure. LDM database "
- "is corrupt. Aborting.\n");
+ ldm_error ("Cannot find PRIVHEAD structure. LDM database is"
+ " corrupt. Aborting.\n");
return FALSE;
}
+
ph->ver_major = BE16 (data + 0x000C);
ph->ver_minor = BE16 (data + 0x000E);
if ((ph->ver_major != 2) || (ph->ver_minor != 11)) {
- printk (LDM_ERR "Expected PRIVHEAD version %d.%d, got %d.%d. "
- "Aborting.\n", 2, 11, ph->ver_major, ph->ver_minor);
+ ldm_error ("Expected PRIVHEAD version %d.%d, got %d.%d."
+ " Aborting.\n", 2, 11, ph->ver_major, ph->ver_minor);
return FALSE;
}
@@ -183,7 +204,7 @@
if (ph->config_size != LDM_DB_SIZE) { /* 1 MiB in sectors. */
/* Warn the user and continue, carefully */
- printk (LDM_INFO "Database is normally %u bytes, it claims to "
- "be %llu bytes.\n", LDM_DB_SIZE, (unsigned long long)
- ph->config_size);
+ ldm_info ("Database is normally %u bytes, it claims to "
+ "be %llu bytes.\n", LDM_DB_SIZE,
+ (unsigned long long)ph->config_size );
}
ph->logical_disk_start = BE64 (data + 0x011B);
@@ -191,10 +212,10 @@
if ((ph->logical_disk_size == 0) ||
(ph->logical_disk_start + ph->logical_disk_size > ph->config_start)) {
- printk (LDM_ERR "PRIVHEAD disk size doesn't match real disk size\n");
+ ldm_error ("PRIVHEAD disk size doesn't match real disk size\n");
return FALSE;
}
if (!ldm_parse_guid (data + 0x0030, ph->disk_id)) {
- printk (LDM_ERR "PRIVHEAD contains an invalid GUID.\n");
+ ldm_error ("PRIVHEAD contains an invalid GUID.\n");
return FALSE;
}
@@ -225,6 +246,5 @@
if (MAGIC_TOCBLOCK != BE64 (data)) {
- printk (LDM_CRIT "Cannot find TOCBLOCK, database may be "
- "corrupt.\n");
+ ldm_crit ("Cannot find TOCBLOCK, database may be corrupt.\n");
return FALSE;
}
@@ -236,6 +256,6 @@
if (strncmp (toc->bitmap1_name, TOC_BITMAP1,
sizeof (toc->bitmap1_name)) != 0) {
- printk (LDM_CRIT "TOCBLOCK's first bitmap should be '%s', but "
- "is '%s'.\n", TOC_BITMAP1, toc->bitmap1_name);
+ ldm_crit ("TOCBLOCK's first bitmap is '%s', should be '%s'.\n",
+ TOC_BITMAP1, toc->bitmap1_name);
return FALSE;
}
@@ -246,6 +266,6 @@
if (strncmp (toc->bitmap2_name, TOC_BITMAP2,
sizeof (toc->bitmap2_name)) != 0) {
- printk (LDM_CRIT "TOCBLOCK's second bitmap should be '%s', "
- "but is '%s'.\n", TOC_BITMAP2, toc->bitmap2_name);
+ ldm_crit ("TOCBLOCK's second bitmap is '%s', should be '%s'.\n",
+ TOC_BITMAP2, toc->bitmap2_name);
return FALSE;
}
@@ -273,6 +293,5 @@
if (MAGIC_VMDB != BE32 (data)) {
- printk (LDM_CRIT "Cannot find the VMDB, database may be "
- "corrupt.\n");
+ ldm_crit ("Cannot find the VMDB, database may be corrupt.\n");
return FALSE;
}
@@ -280,5 +299,5 @@
vm->ver_minor = BE16 (data + 0x14);
if ((vm->ver_major != 4) || (vm->ver_minor != 10)) {
- printk (LDM_ERR "Expected VMDB version %d.%d, got %d.%d. "
+ ldm_error ("Expected VMDB version %d.%d, got %d.%d. "
"Aborting.\n", 4, 10, vm->ver_major, vm->ver_minor);
return FALSE;
@@ -304,5 +323,4 @@
* FALSE Different
*/
-/*
static BOOL ldm_compare_privheads (const struct privhead *ph1,
const struct privhead *ph2)
@@ -318,10 +336,4 @@
!memcmp(ph1->disk_id, ph2->disk_id, GUID_SIZE));
}
-*/
-static inline BOOL ldm_compare_privheads (const struct privhead *ph1,
- const struct privhead *ph2)
-{
- return (memcmp(ph1, ph2, sizeof(struct privhead)) == 0);
-}
/**
@@ -379,5 +391,5 @@
data = read_dev_sector (bdev, 0, §);
if (!data) {
- printk (LDM_CRIT "Disk read failed.\n");
+ ldm_crit ("Disk read failed.\n");
return FALSE;
}
@@ -430,5 +442,5 @@
ph[2] = kmalloc (sizeof (*ph[2]), GFP_KERNEL);
if (!ph[1] || !ph[2]) {
- printk (LDM_CRIT "Out of memory\n");
+ ldm_crit ("Out of memory\n");
goto out;
}
@@ -443,5 +455,5 @@
first_sector + ph[0]->config_start + off[i], §);
if (!data) {
- printk (LDM_CRIT "Disk read failed.\n");
+ ldm_crit ("Disk read failed.\n");
goto out;
}
@@ -455,5 +467,5 @@
if (!ldm_compare_privheads (ph[0], ph[1]) ||
!ldm_compare_privheads (ph[0], ph[2])) {
- printk (LDM_CRIT "Primary and backup PRIVHEADs don't match.\n");
+ ldm_crit ("Primary and backup PRIVHEADs don't match.\n");
goto out;
}
@@ -496,5 +508,5 @@
tb[3] = kmalloc (sizeof (*tb[3]), GFP_KERNEL);
if (!tb[1] || !tb[2] || !tb[3]) {
- printk (LDM_CRIT "Out of memory\n");
+ ldm_crit ("Out of memory\n");
goto out;
}
@@ -505,5 +517,5 @@
data = read_dev_sector (bdev, base + off[i], §);
if (!data) {
- printk (LDM_CRIT "Disk read failed.\n");
+ ldm_crit ("Disk read failed.\n");
goto out;
}
@@ -518,5 +530,5 @@
!ldm_compare_tocblocks (tb[0], tb[2]) ||
!ldm_compare_tocblocks (tb[0], tb[3])) {
- printk (LDM_CRIT "The TOCBLOCKs don't match.\n");
+ ldm_crit ("The TOCBLOCKs don't match.\n");
goto out;
}
@@ -554,5 +566,5 @@
data = read_dev_sector (bdev, base + OFF_VMDB, §);
if (!data) {
- printk (LDM_CRIT "Disk read failed.\n");
+ ldm_crit ("Disk read failed.\n");
return FALSE;
}
@@ -612,6 +624,5 @@
disk_minor = (minor >> hd->minor_shift) << hd->minor_shift;
if ((start < 1) || ((start + size) > hd->part[disk_minor].nr_sects)) {
- printk (LDM_CRIT "Partition exceeds physical disk. "
- "Aborting.\n");
+ ldm_crit ("Partition exceeds physical disk. Aborting.\n");
return FALSE;
}
@@ -780,5 +791,5 @@
tmp = (tmp << 8) | *block++;
} else {
- printk (LDM_ERR "Illegal length %d.\n", length);
+ ldm_error ("Illegal length %d.\n", length);
}
return tmp;
@@ -810,6 +821,6 @@
length = block[0];
if (length >= buflen) {
- printk (LDM_ERR "String too long for buffer (%d/%d). "
- "Truncating.\n", length, buflen);
+ ldm_error ("String too long for buffer (%d/%d). Truncating.\n",
+ length, buflen);
length = buflen - 1;
}
@@ -961,5 +972,5 @@
sizeof (disk->alt_name));
if (!ldm_parse_guid (buffer + 0x19 + rel_name, disk->disk_id)) {
- printk (LDM_ERR "VBLK DISK contains an invalid GUID.\n");
+ ldm_error ("VBLK DISK contains an invalid GUID.\n");
return FALSE;
}
@@ -1162,5 +1173,5 @@
if (!result)
- printk (LDM_ERR "Failed to parse VBLK 0x%llx (type: 0x%02x).\n",
+ ldm_error ("Failed to parse VBLK 0x%llx (type: 0x%02x).\n",
vb->obj_id, vb->type);
else
@@ -1266,5 +1277,5 @@
/* Sanity check vblk header. */
if (vbh->nrec > FRAG_MAX || vbh->rec >= vbh->nrec) {
- printk (LDM_ERR "Invalid VBLK header.\n");
+ ldm_error ("Invalid VBLK header.\n");
bad = TRUE;
}
@@ -1276,5 +1287,5 @@
bad = TRUE;
else if (vbh->nrec != f->nrec || FRAG_GETMAP(f, vbh->rec)) {
- printk (LDM_ERR "Inconsistent VBLK fragments!\n");
+ ldm_error ("Inconsistent VBLK fragments!\n");
bad = TRUE;
}
@@ -1287,5 +1298,5 @@
f = kmalloc(sizeof (struct frags) + nrec * size, GFP_KERNEL);
if (!f) {
- printk (LDM_ERR "out of memory.\n");
+ ldm_error ("out of memory.\n");
return -1;
}
@@ -1329,7 +1340,4 @@
struct vblk* vb = 0;
BOOL result;
- int count = 0;
-
- ldm_debug("MARKER!!!\n");
list_for_each_safe(item, tmp, list) {
@@ -1343,5 +1351,5 @@
for (i = 0; i < f->nrec; i++)
if (!FRAG_GETMAP(f, i)) {
- printk (LDM_ERR "VBLK group %lu is incomplete.\n",
+ ldm_error ("VBLK group %lu is incomplete.\n",
(unsigned long)f->group);
goto entry_done;
@@ -1352,5 +1360,5 @@
vb = kmalloc (sizeof(struct vblk), GFP_KERNEL);
if (!vb) {
- printk (LDM_ERR "out of memory!\n");
+ ldm_error ("out of memory!\n");
result = FALSE;
goto out;
@@ -1361,5 +1369,4 @@
ldm_ldmdb_add(vb, ldb);
vb = 0;
- count++;
}
/* else - Already logged */
@@ -1374,6 +1381,4 @@
kfree (vb);
- ldm_debug("Parsed %d multipart VBLK records.\n", count);
-
return result;
}
@@ -1417,5 +1422,5 @@
data = read_dev_sector (bdev, base + OFF_VMDB + s, §);
if (!data) {
- printk (LDM_CRIT "Disk read failed in get buffers.\n");
+ ldm_crit ("Disk read failed in get buffers.\n");
goto out;
}
@@ -1428,5 +1433,5 @@
if (!ldm_parse_vblk_head (block, &vbh) ) {
- printk (LDM_ERR "not a VBLK\n");
+ ldm_error ("not a VBLK\n");
goto out;
}
@@ -1446,5 +1451,5 @@
vb = kmalloc (sizeof(struct vblk), GFP_KERNEL);
if (!vb) {
- printk (LDM_CRIT "Out of memory in get vblks.\n");
+ ldm_crit ("Out of memory in get vblks.\n");
goto out;
}
@@ -1555,5 +1560,5 @@
ldb = kmalloc (sizeof (*ldb), GFP_KERNEL);
if (!toc || !ldb) {
- printk (LDM_CRIT "Out of memory\n");
+ ldm_crit ("Out of memory\n");
goto out;
}
@@ -1584,5 +1589,5 @@
if (!ldm_get_vblks (bdev, base, ldb)) {
- printk (LDM_CRIT "get buffers failed\n");
+ ldm_crit ("get buffers failed\n");
goto cleanup;
}
@@ -1590,5 +1595,5 @@
disk = ldm_get_disk_objid (ldb);
if (!disk) {
- printk (LDM_CRIT "can't find this disk\n");
+ ldm_crit ("can't find this disk\n");
goto cleanup;
}
Index: ldm.h
===================================================================
RCS file: /cvsroot/linux-ntfs/dynamic-disk/linux/fs/partitions/ldm.h,v
retrieving revision 1.35
retrieving revision 1.36
diff -U2 -r1.35 -r1.36
--- ldm.h 24 Feb 2002 21:21:23 -0000 1.35
+++ ldm.h 27 Feb 2002 15:56:10 -0000 1.36
@@ -33,8 +33,11 @@
/* Borrowed from kernel.h. */
-#define LDM_CRIT KERN_CRIT __FUNCTION__ "(): " /* critical conditions */
-#define LDM_ERR KERN_ERR __FUNCTION__ "(): " /* error conditions */
-#define LDM_INFO KERN_INFO __FUNCTION__ "(): " /* informative messages */
-#define LDM_DEBUG KERN_DEBUG __FUNCTION__ "(): " /* debug-level messages */
+enum {
+ LDM_LVL_CRIT, /* critical conditions */
+ LDM_LVL_ERR, /* error conditions */
+ LDM_LVL_INFO, /* informative messages */
+ LDM_LVL_DEBUG, /* debug-level messages */
+ LDM_LVL_NONE
+};
/* Magic numbers in CPU format. */
@@ -132,5 +135,5 @@
u64 config_size;
u8 disk_id[GUID_SIZE];
-} __attribute__ ((packed)); /* For memcmp() compare. */
+};
struct tocblock { /* We have exactly two bitmaps. */
|