[prev in list] [next in list] [prev in thread] [next in thread]
List: linux-ntfs-cvs
Subject: [Linux-NTFS-cvs] CVS: dynamic-disk/linux/fs/partitions ldm.c,1.36,1.37 ldm.h,1.21,1.22
From: Richard Russon <flatcap () users ! sourceforge ! net>
Date: 2001-10-29 19:38:21
[Download RAW message or body]
Changes by: flatcap
Update of /cvsroot/linux-ntfs/dynamic-disk/linux/fs/partitions
In directory usw-pr-cvs1:/tmp/cvs-serv9609/linux/fs/partitions
Modified Files:
ldm.c ldm.h
Log Message:
changed the rest to use bdev's; hacked up test prog to work again.
Index: ldm.c
===================================================================
RCS file: /cvsroot/linux-ntfs/dynamic-disk/linux/fs/partitions/ldm.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -U2 -r1.36 -r1.37
--- ldm.c 2001/10/09 14:50:39 1.36
+++ ldm.c 2001/10/29 19:38:18 1.37
@@ -24,5 +24,5 @@
*/
-#include <asm/types.h>
+#include <linux/types.h>
#include <asm/unaligned.h>
#include <asm/byteorder.h>
@@ -252,29 +252,29 @@
* dynamic disks).
*
- * N.B. The only possible error can come from the bread 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.
+ * 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: 1 @dev is a dynamic disk
* 0 @dev is not a dynamic disk, or an error occurred
*/
-static int ldm_validate_partition_table (const kdev_t dev)
+static int ldm_validate_partition_table (struct block_device* bdev)
{
- struct buffer_head *bh;
+ Sector sect;
+ unsigned char* data;
struct partition *p;
int i, nr_sfs;
int result = 0;
- if (!(bh = bread (dev, 0, LDM_BLOCKSIZE))) {
- if (warn_no_part)
- printk (LDM_ERR "Unable to read partition table.\n");
+ data = read_dev_sector(bdev, 0, §);
+ if (!data)
return 0;
- }
- if (*(u16*) (bh->b_data + 0x01FE) != cpu_to_le16 (MSDOS_LABEL_MAGIC)) {
+
+ if (*(u16*) (data + 0x01FE) != cpu_to_le16 (MSDOS_LABEL_MAGIC)) {
ldm_debug ("No MS-DOS partition found.\n");
goto out;
}
nr_sfs = 0;
- p = (struct partition*) (bh->b_data + 0x01BE);
+ p = (struct partition*)(data + 0x01BE);
for (i = 0; i < 4; i++, p++) {
if (!SYS_IND (p) || SYS_IND (p) == WIN2K_EXTENDED_PARTITION)
@@ -294,5 +294,5 @@
}
out:
- brelse (bh);
+ put_dev_sector(sect);
return result;
}
@@ -309,7 +309,9 @@
* 0 Error
*/
-static int ldm_validate_privheads (const kdev_t dev, const struct privhead *ph1)
+static int ldm_validate_privheads (struct block_device *bdev, unsigned long base,
+ const struct privhead *ph1)
{
- struct buffer_head *bh;
+ Sector sect;
+ unsigned char *data;
struct privhead *ph2, *ph3;
int result = 0;
@@ -326,14 +328,16 @@
/* Read and parse second privhead. */
- if (!(bh = bread (dev, OFF_PRIVHEAD2, LDM_BLOCKSIZE)))
+ data = read_dev_sector (bdev, base + OFF_PRIVHEAD2, §);
+ if (!data)
goto out;
- if (!ldm_parse_privhead (bh->b_data, ph2))
+ if (!ldm_parse_privhead (data, ph2))
goto out;
- brelse (bh);
+ put_dev_sector(sect);
/* Read and parse third privhead. */
- if (!(bh = bread (dev, OFF_PRIVHEAD3, LDM_BLOCKSIZE)))
+ data = read_dev_sector (bdev, base + OFF_PRIVHEAD3, §);
+ if (!data)
goto out;
- if (!ldm_parse_privhead (bh->b_data + 0x0200, ph3))
+ if (!ldm_parse_privhead (data, ph3))
goto out;
@@ -347,6 +351,6 @@
/* We _could_ have checked more. */
out:
- if (bh)
- brelse (bh);
+ if (data)
+ put_dev_sector(sect);
else
printk (LDM_CRIT "Disk read failed in validate_privheads.\n");
@@ -368,7 +372,9 @@
* 0 Error, the contents of @toc1 are undefined
*/
-static int ldm_validate_tocblocks (const kdev_t devdb, struct tocblock *toc1)
+static int ldm_validate_tocblocks (struct block_device *bdev, unsigned long base,
+ struct tocblock *toc1)
{
- struct buffer_head *bh;
+ Sector sect;
+ unsigned char *data;
struct tocblock *toc2, *toc3, *toc4;
int result = 0;
@@ -386,30 +392,23 @@
}
- /* Read and parse first toc. */
- if (!(bh = bread (devdb, OFF_TOCBLOCK1, LDM_BLOCKSIZE)))
- goto out;
- if (!ldm_parse_tocblock (bh->b_data + 0x0200, toc1))
+ /* Read and parse all four toc's. */
+ data = read_dev_sector (bdev, base + OFF_TOCBLOCK1, §);
+ if (!data || !ldm_parse_tocblock (data, toc1))
goto out;
- brelse (bh);
+ put_dev_sector(sect);
- /* Read and parse second toc. */
- if (!(bh = bread (devdb, OFF_TOCBLOCK2, LDM_BLOCKSIZE)))
+ data = read_dev_sector (bdev, base + OFF_TOCBLOCK2, §);
+ if (!data || !ldm_parse_tocblock (data, toc2))
goto out;
- if (!ldm_parse_tocblock (bh->b_data, toc2))
- goto out;
- brelse (bh);
+ put_dev_sector(sect);
- /* Read and parse third toc. */
- if (!(bh = bread (devdb, OFF_TOCBLOCK3, LDM_BLOCKSIZE)))
- goto out;
- if (!ldm_parse_tocblock (bh->b_data + 0x0200, toc3))
+ data = read_dev_sector (bdev, base + OFF_TOCBLOCK3, §);
+ if (!data || !ldm_parse_tocblock (data, toc3))
goto out;
- brelse (bh);
+ put_dev_sector(sect);
- /* Read and parse fourth toc. */
- if (!(bh = bread (devdb, OFF_TOCBLOCK4, LDM_BLOCKSIZE)))
+ data = read_dev_sector (bdev, base + OFF_TOCBLOCK4, §);
+ if (!data || !ldm_parse_tocblock (data, toc4))
goto out;
- if (!ldm_parse_tocblock (bh->b_data, toc4))
- goto out;
if ((!ldm_compare_tocblocks (toc1, toc2)) || /* Compare all tocs. */
@@ -417,5 +416,4 @@
(!ldm_compare_tocblocks (toc1, toc4))) {
printk (LDM_CRIT "The TOCBLOCKs don't match.\n");
- goto out;
} else {
ldm_debug ("Validated TOCBLOCKs successfully.\n");
@@ -423,6 +421,6 @@
}
out:
- if (bh)
- brelse (bh);
+ if (data)
+ put_dev_sector(sect);
else
printk (LDM_CRIT "Disk read failed in validate_tocblocks.\n");
@@ -445,21 +443,24 @@
* 0 Error, contents of @vm are undefined.
*/
-static int ldm_validate_vmdb (const kdev_t dev, struct vmdb *vm)
+static int ldm_validate_vmdb (struct block_device *bdev, unsigned long base,
+ struct vmdb *vm)
{
- struct buffer_head *bh;
- int ret = 0;
-
- if ((bh = bread (dev, OFF_VMDB, LDM_BLOCKSIZE))) {
- ret = ldm_parse_vmdb (bh->b_data + 0x200, vm);
- brelse (bh);
- } else {
- printk (LDM_CRIT "Disk read failed in validate_vmdb.\n");
+ Sector sect;
+ unsigned char *data;
+ int ret;
+
+ data = read_dev_sector(bdev, base + OFF_VMDB, §);
+ if (!data) {
+ printk(LDM_CRIT "Disk read failed in validate_vmdb.\n");
+ return -1;
}
+ ret = ldm_parse_vmdb(data, vm);
+ put_dev_sector(sect);
return ret;
}
/**
- * ldm_find_vmdb - Search a linked list of vblk's for a given object id
- * @vl: Head of a linked list of vblk's
+ * ldm_find_vmdb - Search a linked list of VBLKs for a given object id
+ * @vl: Head of a linked list of VBLKs
* @id: Object id to find
*
@@ -535,21 +536,23 @@
* 0 Error, the device may or may not be a dynamic disk
*/
-static int ldm_create_db_partition (struct gendisk *hd, const kdev_t dev,
- const unsigned long first_sector,
+static int ldm_create_db_partition (struct gendisk *hd,
+ struct block_device* bdev, const unsigned long first_sector,
const int first_minor, struct privhead *ph)
{
- struct buffer_head *bh;
+ Sector sect;
+ unsigned char* data;
int result = 0;
- if (!(bh = bread (dev, OFF_PRIVHEAD1, LDM_BLOCKSIZE))) {
+ data = read_dev_sector(bdev, OFF_PRIVHEAD1, §);
+ if (!data) {
printk (LDM_CRIT __FUNCTION__ "(): Device read failed.\n");
return 0;
}
- if (BE64 (bh->b_data) != MAGIC_PRIVHEAD) {
+ if (BE64 (data) != MAGIC_PRIVHEAD) {
ldm_debug ("Cannot find PRIVHEAD structure. "
"Not a dynamic disk or corrupt LDM Database.\n");
goto out;
}
- if (!ldm_parse_privhead (bh->b_data, ph))
+ if (!ldm_parse_privhead (data, ph))
goto out; /* Already logged */
@@ -557,5 +560,5 @@
first_sector + ph->config_start, ph->config_size);
out:
- brelse (bh);
+ put_dev_sector(sect);
return result;
}
@@ -1035,5 +1038,5 @@
* @dev: The partition containing the VMDB
* @vm: Details about the VMDB
- * @bh: The buffer_head to read from
+ * @FIXME bh: The buffer_head to read from
* @lh_vl: A linked list of single VBLKs
* @lh_el: A linked list of extended VBLKs (to be sorted)
@@ -1046,5 +1049,5 @@
* -1 Error
*/
-static int ldm_get_vblks (kdev_t dev, struct vmdb *vm, struct buffer_head *bh,
+static int ldm_get_vblks (struct block_device *bdev, struct vmdb *vm, unsigned char *data,
struct list_head *lh_vl, struct list_head *lh_el)
{
@@ -1056,8 +1059,8 @@
int size_vblk = vm->vblk_size;
- int num_per = LDM_BLOCKSIZE / vm->vblk_size;;
+ int num_per = 512 / vm->vblk_size;;
for (i = 0; i < num_per; i++) {
- block = bh->b_data + i*size_vblk;
+ block = data + i*size_vblk;
if (MAGIC_VBLK != BE32 (block)) {
@@ -1193,9 +1196,10 @@
* 0 Error
*/
-static int ldm_get_buffers (kdev_t dev, struct vmdb *vm,
- struct list_head *lh_bh, struct list_head *lh_vl)
+static int ldm_get_buffers (struct block_device *bdev, unsigned long base,
+ struct vmdb *vm, struct list_head *lh_bh, struct list_head *lh_vl)
{
struct vblk el; /* extended vblks */
- struct buffer_head *bh;
+ Sector sect;
+ unsigned char *data;
struct buffer_list *bl;
int i;
@@ -1212,5 +1216,5 @@
skip = vm->vblk_offset / vm->vblk_size;
- perbuf = LDM_BLOCKSIZE / vm->vblk_size;
+ perbuf = 512 / vm->vblk_size;
finish = (vm->last_vblk_seq / perbuf) - skip;
@@ -1218,16 +1222,16 @@
for (i = 0; i < finish; i++) {
- bh = bread (dev, i + OFF_VBLK, LDM_BLOCKSIZE);
- if (!bh) {
+ data = read_dev_sector (bdev, base + OFF_VBLK + i, §);
+ if (!data) {
printk (LDM_CRIT "Disk read failed in get buffers.\n");
return 0;
}
- count = ldm_get_vblks (dev, vm, bh, lh_vl, &el.list);
+ count = ldm_get_vblks (bdev, vm, data, lh_vl, &el.list);
if (count < 0) {
- brelse (bh); /* Already logged */
+ put_dev_sector(sect); /* Already logged */
return 0;
} else if (count == 0) {
- brelse (bh); /* empty */
+ put_dev_sector(sect); /* Empty */
continue;
}
@@ -1235,5 +1239,5 @@
bl = (struct buffer_list*) kmalloc (sizeof (*bl), GFP_KERNEL);
if (!bl) {
- brelse (bh);
+ put_dev_sector(sect);
printk (LDM_CRIT "Out of memory in get buffer.\n");
return 0;
@@ -1241,5 +1245,5 @@
INIT_LIST_HEAD (&bl->list);
- bl->bh = bh;
+ bl->bh = sect.v;
list_add_tail (&bl->list, lh_bh);
}
@@ -1358,6 +1362,6 @@
* Or @dev is a dynamic disk, but it may be corrupted
*/
-int ldm_partition (struct gendisk *hd, kdev_t dev, unsigned long first_sector,
- int first_minor)
+int ldm_partition (struct gendisk *hd, struct block_device *bdev,
+ unsigned long first_sector, int first_minor)
{
struct privhead *ph;
@@ -1367,5 +1371,5 @@
struct vblk *vl;
struct vblk *disk;
- kdev_t devdb;
+ unsigned long base;
int err;
@@ -1373,18 +1377,6 @@
return 0;
- if (get_ptable_blocksize (dev) != LDM_BLOCKSIZE) { /* 1024 bytes */
- ldm_debug ("Expected a blocksize of %d bytes, got %d instead."
- "\n", LDM_BLOCKSIZE, get_ptable_blocksize (dev));
- return 0;
- }
-
- if (get_hardsect_size (dev) != 512) {
- ldm_debug ("Expected a sector size of %d bytes, got %d "
- "instead.\n", 512, get_hardsect_size (dev));
- return 0;
- }
-
/* Look for signs of a Dynamic Disk */
- if (!ldm_validate_partition_table (dev))
+ if (!ldm_validate_partition_table (bdev))
return 0;
@@ -1400,13 +1392,14 @@
/* Create the LDM database device. */
- if (!ldm_create_db_partition (hd, dev, first_sector, first_minor, ph))
+ if (!ldm_create_db_partition (hd, bdev, first_sector, first_minor, ph))
goto free_structs; /* FIXME logged? */
+
+ /* FIXME update comment For convenience, work with the LDM database device from now on. */
+ base = hd->part[first_minor].start_sect;
- /* For convenience, work with the LDM database device from now on. */
- devdb = MKDEV (MAJOR (dev), first_minor);
- /* Parse and check: */
- if ((!ldm_validate_privheads (devdb, ph)) || /* backup privheads */
- (!ldm_validate_tocblocks (devdb, toc)) || /* tables of contents */
- (!ldm_validate_vmdb (devdb, vm))) /* vmdb */
+ /* Parse and check: backup privheads; tables of contents; vmdb. */
+ if ((!ldm_validate_privheads (bdev, base, ph)) ||
+ (!ldm_validate_tocblocks (bdev, base, toc)) ||
+ (!ldm_validate_vmdb (bdev, base, vm)))
goto free_structs;
@@ -1422,5 +1415,5 @@
INIT_LIST_HEAD (&vl->list);
- if (!ldm_get_buffers (devdb, vm, &bl->list, &vl->list)) {
+ if (!ldm_get_buffers (bdev, base, vm, &bl->list, &vl->list)) {
printk ("get buffers failed\n");
goto free_lists;
Index: ldm.h
===================================================================
RCS file: /cvsroot/linux-ntfs/dynamic-disk/linux/fs/partitions/ldm.h,v
retrieving revision 1.21
retrieving revision 1.22
diff -U2 -r1.21 -r1.22
--- ldm.h 2001/09/11 23:53:26 1.21
+++ ldm.h 2001/10/29 19:38:19 1.22
@@ -54,20 +54,20 @@
#define LDM_DB_SIZE 2048 /* Size in sectors (= 1MiB). */
-#define OFF_PRIVHEAD1 3 /* Offset of the first privhead
+#define OFF_PRIVHEAD1 6 /* Offset of the first privhead
relative to the start of the
device in units of
LDM_BLOCKSIZE. */
-/* Offsets to structures within the LDM Database in units of LDM_BLOCKSIZE. */
-#define OFF_PRIVHEAD2 928 /* Backup private headers. */
-#define OFF_PRIVHEAD3 1023
-
-#define OFF_TOCBLOCK1 0 /* Tables of contents. */
-#define OFF_TOCBLOCK2 1
-#define OFF_TOCBLOCK3 1022
-#define OFF_TOCBLOCK4 1023
+/* Offsets to structures within the LDM Database in sectors. */
+#define OFF_PRIVHEAD2 1856 /* Backup private headers. */
+#define OFF_PRIVHEAD3 2047
+
+#define OFF_TOCBLOCK1 1 /* Tables of contents. */
+#define OFF_TOCBLOCK2 2
+#define OFF_TOCBLOCK3 2045
+#define OFF_TOCBLOCK4 2046
-#define OFF_VMDB 8 /* List of partitions. */
-#define OFF_VBLK 9
+#define OFF_VMDB 17 /* List of partitions. */
+#define OFF_VBLK 18
#define WIN2K_DYNAMIC_PARTITION 0x42 /* Formerly SFS (Landis). */
@@ -179,8 +179,9 @@
struct list_head list;
struct buffer_head *bh;
+ //unsigned char *data;
};
-int ldm_partition(struct gendisk *hd, kdev_t dev, unsigned long first_sector,
- int first_minor);
+int ldm_partition (struct gendisk *hd, struct block_device *bdev,
+ unsigned long first_sector, int first_minor);
#endif /* _FS_PT_LDM_H_ */
_______________________________________________
Linux-NTFS-cvs mailing list
Linux-NTFS-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-ntfs-cvs
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic