Changes by: flatcap
Update of /cvsroot/linux-ntfs/dynamic-disk/test
In directory usw-pr-cvs1:/tmp/cvs-serv4491/test
Modified Files:
Makefile ldminfo.c ldminfo.h
Added Files:
copy.c
Log Message:
changed ldminfo copy option to remove assumptions
--- NEW FILE ---
/**
* ldminfo - Part of the Linux-NTFS project.
*
* Copyright (C) 2001 Richard Russon <ld...@fl...>
*
* Documentation is available at http://linux-ntfs.sourceforge.net/ldm
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program (in the main directory of the Linux-NTFS source
* in the file COPYING); if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "ldminfo.h"
#define BUFSIZE_BITS 12
#define BUFSIZE (1 << BUFSIZE_BITS)
/**
* copy_database - Save the LDM Database to a file
*/
void copy_database (char *file, int device, long long size)
{
unsigned char *buffer;
int fpart = 0; /* Partition table + primary PRIVHEAD */
int fdata = 0; /* LDM Database */
if (!file)
return;
buffer = kmalloc (BUFSIZE, GFP_KERNEL);
if (!buffer)
return;
sprintf (buffer, "%.58s.part", basename (file));
fpart = open64 (buffer, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fpart < 0) {
printf ("Couldn't open output file: %s\n", buffer);
goto out;
}
sprintf (buffer, "%.58s.data", basename (file));
fdata = open64 (buffer, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
if (fdata < 0) {
printf ("Couldn't open output file: %s\n", buffer);
goto out;
}
/* First copy the partition table and primary PRIVHEAD to fpart */
if (lseek64 (device, 0, SEEK_SET) < 0) {
printf ("lseek to %d failed\n", 0);
goto out;
}
if (read (device, buffer, BUFSIZE) < BUFSIZE) {
printf ("Couldn't read the partition table and primary PRIVHEAD\n");
goto out;
}
if (write (fpart, buffer, BUFSIZE) < BUFSIZE) {
printf ("Couldn't write the partition table and primary PRIVHEAD\n");
goto out;
}
if (strncmp (buffer + 3072, "PRIVHEAD", 8) == 0) {
long long ph;
ph = BE64 (buffer + 3072 + 0x12B);
ph += BE64 (buffer + 3072 + 0x133);
ph <<= 9;
if (ph != size) {
printf ("The device appears to be %llu bytes long, but the PRIVHEAD reckons it's %llu bytes.\n", size, ph);
}
}
size -= 1048576; /* 1 MiB */
if (lseek64 (device, size, SEEK_SET) < 0) {
printf ("lseek to %lld failed\n", size);
goto out;
}
while (read (device, buffer, BUFSIZE) > 0) {
if (write (fdata, buffer, BUFSIZE) < 0) {
printf ("Couldn't write to data file\n");
goto out;
}
}
printf ("Successfully copied the LDM data\n");
out:
kfree (buffer);
close (fpart);
close (fdata);
}
Index: Makefile
===================================================================
RCS file: /cvsroot/linux-ntfs/dynamic-disk/test/Makefile,v
retrieving revision 1.11
retrieving revision 1.12
diff -U2 -r1.11 -r1.12
--- Makefile 9 Feb 2002 13:46:46 -0000 1.11
+++ Makefile 23 Feb 2002 16:38:51 -0000 1.12
@@ -1,9 +1,9 @@
# Copyright (C) 2001 Richard Russon
-SRC = compat.c dump.c ldminfo.c sparse.c
+SRC = compat.c copy.c dump.c ldminfo.c sparse.c
OBJ = $(SRC:.c=.o)
LDMDEP = ../linux/fs/partitions/partitions.o
-INFODEP = $(LDMDEP) compat.o dump.o ldminfo.o
+INFODEP = $(LDMDEP) compat.o copy.o dump.o ldminfo.o
OUT = ldminfo sparse
Index: ldminfo.c
===================================================================
RCS file: /cvsroot/linux-ntfs/dynamic-disk/test/ldminfo.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -U2 -r1.21 -r1.22
--- ldminfo.c 17 Feb 2002 22:13:34 -0000 1.21
+++ ldminfo.c 23 Feb 2002 16:38:51 -0000 1.22
@@ -78,51 +78,4 @@
/**
- * copy_database - Save the LDM Database to a file
- */
-void copy_database (char *file, kdev_t dev)
-{
- struct buffer_head *bh;
- char buffer[64];
- long long size;
- int fout, minor, i;
- kdev_t devdb;
-
- if (!file)
- return;
-
- sprintf (buffer, "%.58s.dump", basename (file));
-
- fout = open64 (buffer, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
- if (fout < 0) {
- printf ("Couldn't open output file: %s\n", buffer);
- return;
- }
-
- minor = minor (dev) + 1; /* Minor of LDM Database */
- devdb = mk_kdev (major (dev), minor);
- size = hd[minor].nr_sects;
-
- for (i = 0; i < size; i++) {
- bh = ldm_bread (devdb, i, 512);
- if (!bh) {
- printk ("Couldn't read from device: %s\n", file);
- goto dv_close;
- }
-
- if (write (fout, bh->b_data, 512) < 0) {
- printf ("Couldn't write to file: %s\n", buffer);
- brelse (bh);
- goto dv_close;
- }
-
- brelse (bh);
- }
-
- printf ("Saved to %s\n", buffer);
-dv_close:
- close (fout);
-}
-
-/**
* ldm_partition2
*
@@ -185,5 +138,4 @@
int dump = 0;
int copy = 0;
- int usedb = 0;
int help = 0;
struct block_device bdev;
@@ -193,5 +145,4 @@
else if (strcmp (argv[a], "--dump") == 0) dump++;
else if (strcmp (argv[a], "--copy") == 0) copy++;
- //else if (strcmp (argv[a], "--usedb") == 0) usedb++;
else if (strcmp (argv[a], "--debug") == 0) debug++;
else if (strcmp (argv[a], "--help") == 0) help++;
@@ -200,5 +151,5 @@
}
- if (help || (argc - info - dump - copy - usedb - debug) < 2) {
+ if (help || (argc - info - dump - copy - debug) < 2) {
printf ("\nUsage:\n %s [options] device ...\n", argv[0]);
printf ("\nOptions:\n"
@@ -206,5 +157,4 @@
" --dump The contents of the database in detail\n"
" --copy Write the database to a file\n"
- //" --usedb Work with a database file or device\n"
" --debug Display lots of debugging information\n"
" --help Show this short help\n\n");
@@ -220,12 +170,4 @@
continue;
- /* Initialize vblk list 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);
-
device = open64 (argv[a], O_RDONLY);
if (device < 0) {
@@ -240,5 +182,18 @@
}
- toc = (struct tocblock*)kmalloc (sizeof (*toc), GFP_KERNEL);
+ if (copy) {
+ copy_database (argv[a], device, size);
+ goto close;
+ }
+
+ /* Initialize vblk list 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);
+
+ toc = kmalloc (sizeof (*toc), GFP_KERNEL);
if (!toc) {
printk (LDM_CRIT "Not enough memory for required buffers.\n");
@@ -259,7 +214,8 @@
ldm_partition2 (&hd_gendisk, &bdev, &ldb, toc, minor + 1);
- if (dump) dump_database (argv[a], toc, &ldb);
- else if (copy) copy_database (argv[a], drive);
- else dump_info (argv[a], maxminor);
+ if (dump)
+ dump_database (argv[a], toc, &ldb);
+ else
+ dump_info (argv[a], maxminor);
ldm_free_vblks(&ldb.v_dgrp);
@@ -271,5 +227,5 @@
free_structs:
kfree (toc);
-
+close:
close (device);
device = 0;
Index: ldminfo.h
===================================================================
RCS file: /cvsroot/linux-ntfs/dynamic-disk/test/ldminfo.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -U2 -r1.11 -r1.12
--- ldminfo.h 17 Feb 2002 22:13:34 -0000 1.11
+++ ldminfo.h 23 Feb 2002 16:38:51 -0000 1.12
@@ -71,4 +71,5 @@
void dump_database (char *name, struct tocblock *toc, struct ldmdb *ldb);
+void copy_database (char *file, int fd, long long size);
struct buffer_head * ldm_bread (kdev_t dev, int block, int size);
|