Changes by: flatcap
Update of /cvsroot/linux-ntfs/dynamic-disk/ldminfo
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14084/ldminfo
Added Files:
Makefile README copy.c dump.c ldm.c ldm.h ldminfo.c ldminfo.h
list.h sparse.c types.h
Log Message:
removed kernel compatibility layer, turning ldminfo into a _real_
userspace tool. Ran ldminfo under valgrind to find and fix memory
problems. Turned on all the compiler warnings and fixed them.
--- NEW FILE ---
# Copyright (C) 2001-2005 Richard Russon
CC = gcc
SRC = copy.c dump.c ldm.c ldminfo.c sparse.c
OBJ = $(SRC:.c=.o)
#CFLAGS += -O2
#CFLAGS += -DDEBUG
CFLAGS += -g
CFLAGS += -D_GNU_SOURCE
CFLAGS += -D_FILE_OFFSET_BITS=64
CFLAGS += -pipe
CFLAGS += -Wall
CFLAGS += -W
CFLAGS += -Waggregate-return
CFLAGS += -Wbad-function-cast
CFLAGS += -Wcast-align
CFLAGS += -Wcast-qual
CFLAGS += -Wmissing-declarations
CFLAGS += -Wmissing-prototypes
CFLAGS += -Wpointer-arith
CFLAGS += -Wredundant-decls
CFLAGS += -Wshadow
CFLAGS += -Wsign-compare
CFLAGS += -Wstrict-prototypes
CFLAGS += -Wundef
CFLAGS += -Wwrite-strings
#CFLAGS += -Werror
INFODEP = copy.o dump.o ldm.o ldminfo.o
OUT = ldminfo sparse
all: $(OUT)
.c.o:
$(CC) $(CFLAGS) -c $< -o $@
ldminfo: $(INFODEP)
$(CC) -o ldminfo $^
sparse: sparse.c
$(CC) $(CFLAGS) $< -o $@
clean:
$(RM) $(OUT) $(OBJ)
distclean: clean
$(RM) tags
tags: force
ctags *.[ch]
force:
--- NEW FILE ---
Logical Disk Manager (Dynamic Disk) Tool and Driver.
There are two packages included here. A userland tool to dump the contents of
a Window 2000 LDM Disk. Also there's a Linux Filesystem driver. You need to
know what you're doing to use this.
The packages are part of the Linux-NTFS Project which is hosted on SourceForge:
http://linux-ntfs.sourceforge.net
I've included a prebuilt copy of the tool in the .tar If you want to build it
yourself you need the kernel header files, then "make" should do the trick.
If it doesn't build without errors, then you'll need to know your way around
the kernel to fix things.
LDMInfo can be used in three ways:
ldminfo /dev/hdb Standard partition list
ldminfo --dump /dev/hdb Detailed dump of LDM Database
ldminfo --copy /dev/hdb Write the LDM Database to a file
In addition, you can add the --debug flag. This will show you what's
going on inside the code. Not at all interesting, but vital to help
us debug the application.
The standard partition list looks something like this:
Device | Offset Bytes Sectors MiB | Size Bytes Sectors MiB
-------+--------------------------------+-------------------------------
hdb | 0 0 0 | 21159936 41328 20
hdb1 | 32256 63 0 | 5242880 10240 5
hdb2 | 5275136 10303 5 | 5242880 10240 5
hdb3 | 10518016 20543 10 | 3145728 6144 3
hdb4 | 13663744 26687 13 | 6291456 12288 6
Any bugs / problems / comments, please email me.
Cheers,
FlatCap (Rich)
ld...@fl...
http://linux-ntfs.sourceforge.net
--- NEW FILE ---
/**
* ldminfo - Part of the Linux-NTFS project.
*
* Copyright (C) 2001-2005 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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#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)
{
char *buffer;
int fpart = 0; /* Partition table + primary PRIVHEAD */
int fdata = 0; /* LDM Database */
if (!file)
return;
buffer = malloc (BUFSIZE);
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:
free (buffer);
close (fpart);
close (fdata);
}
--- NEW FILE ---
/**
* ldminfo - Part of the Linux-NTFS project.
*
* Copyright (C) 2001-2005 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"
/**
* print_guid -
*/
static char * print_guid (const u8 *block)
{
static char buffer[40];
memset (buffer, 0, sizeof (buffer));
if (block) {
sprintf (buffer, "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
block[0], block[1], block[2], block[3], block[4], block[5], block[6], block[7],
block[8], block[9], block[10], block[11], block[12], block[13], block[14], block[15]);
}
return buffer;
}
/**
* dump_component -
*/
static void dump_component (struct vblk *vb)
{
struct vblk_comp *comp = &vb->vblk.comp;
printf ("0x%06X: <Component>\n", vb->sequence);
printf (" Name : %s\n", vb->name);
printf (" Object Id : 0x%04llx\n", vb->obj_id);
printf (" Parent Id : 0x%04llx\n", comp->parent_id);
}
/**
* dump_partition -
*/
static void dump_partition (struct vblk *vb)
{
struct vblk_part *part = &vb->vblk.part;;
printf ("0x%06X: <Partition>\n", vb->sequence);
printf (" Name : %s\n", vb->name);
printf (" Object Id : 0x%04llx\n", vb->obj_id);
printf (" Parent Id : 0x%04llx\n", part->parent_id);
printf (" Disk Id : 0x%04llx\n", part->disk_id);
printf (" Start : 0x%llX\n", (unsigned long long) part->start);
printf (" Size : 0x%llX (%llu MB)\n", (unsigned long long) part->size, (unsigned long long) part->size >> 11);
printf (" Volume Off : 0x%llX (%llu MB)\n", (unsigned long long) part->volume_offset, (unsigned long long) part->volume_offset >> 11);
}
/**
* dump_disk -
*/
static void dump_disk (struct vblk *vb)
{
struct vblk_disk *disk = &vb->vblk.disk;
printf ("0x%06X: <Disk>\n", vb->sequence);
printf (" Name : %s\n", vb->name);
printf (" Object Id : 0x%04llx\n", vb->obj_id);
printf (" Disk Id : %s\n", print_guid (disk->disk_id));
if (*disk->alt_name) {
printf (" AltName : %s\n", disk->alt_name);
}
}
/**
* dump_diskgroup -
*/
static void dump_diskgroup (struct vblk *vb)
{
struct vblk_dgrp *dgrp = &vb->vblk.dgrp;
printf ("0x%06X: <DiskGroup>\n", vb->sequence);
printf (" Name : %s\n", vb->name);
printf (" Object Id : 0x%04llx\n", vb->obj_id);
printf (" GUID : %s\n", dgrp->disk_id);
}
/**
* dump_volume -
*/
static void dump_volume (struct vblk *vb)
{
struct vblk_volu *volu = &vb->vblk.volu;
printf ("0x%06X: <Volume>\n", vb->sequence);
printf (" Name : %s\n", vb->name);
printf (" Object Id : 0x%04llx\n", vb->obj_id);
printf (" Volume state: %s\n", volu->volume_state);
printf (" Size : 0x%08llX (%llu MB)\n", (unsigned long long) volu->size, (unsigned long long) volu->size >> 11);
printf (" GUID : %s\n", print_guid (volu->guid));
if (*volu->drive_hint) {
printf (" Drive Hint : %s\n", volu->drive_hint);
}
printf (" Partition : ");
switch (volu->partition_type) {
case 1: printf ("FAT12\n"); break;
case 6: printf ("FAT16\n"); break;
case 7: printf ("NTFS\n"); break;
default: printf ("%d\n", volu->partition_type);
}
}
/**
* dump_vmdb -
*/
static int dump_vmdb (struct ldmdb *ldb)
{
struct list_head *item;
struct vmdb *vm = &ldb->vm;
printf ("VMDB DATABASE HEADER:\n");
printf ("Version : %d/%d\n", vm->ver_major, vm->ver_minor);
printf ("VBLK Size : 0x%X\n", vm->vblk_size);
printf ("Offset to VBLKs : 0x%X\n", vm->vblk_offset);
printf ("Number of VBLKs : 0x%X\n", vm->last_vblk_seq - (vm->vblk_offset / vm->vblk_size));
printf ("\n");
printf ("VBLK DATABASE:\n");
list_for_each (item, &ldb->v_comp) {
dump_component (list_entry (item, struct vblk, list));
}
list_for_each (item, &ldb->v_part) {
dump_partition (list_entry (item, struct vblk, list));
}
list_for_each (item, &ldb->v_disk) {
dump_disk (list_entry (item, struct vblk, list));
}
list_for_each (item, &ldb->v_dgrp) {
dump_diskgroup (list_entry (item, struct vblk, list));
}
list_for_each (item, &ldb->v_volu) {
dump_volume (list_entry (item, struct vblk, list));
}
printf ("\n");
return 0;
}
/**
* dump_privhead -
*/
static int dump_privhead (struct privhead *ph)
{
printf ("PRIVATE HEADER:\n");
printf ("Version : %d.%d\n", ph->ver_major, ph->ver_minor);
if (ph->disk_id)
printf ("Disk Id : %s\n", print_guid (ph->disk_id));
printf ("Logical disk start : 0x%llX\n", (unsigned long long) ph->logical_disk_start);
printf ("Logical disk size : 0x%llX (%llu MB)\n", (unsigned long long) ph->logical_disk_size, (unsigned long long) ph->logical_disk_size>>11);
printf ("Configuration start: 0x%llX\n", (unsigned long long) ph->config_start);
printf ("Configuration size : 0x%llX (%llu MB)\n", (unsigned long long) ph->config_size, (unsigned long long) ph->config_size>>11);
printf ("\n");
return 0;
}
/**
* dump_tocblock -
*/
static int dump_tocblock (struct tocblock *toc)
{
printf ("TOC\n");
printf ("Bitmap name : \"%s\"\n", toc->bitmap1_name);
printf ("Log bitmap start : 0x%llX\n", (unsigned long long) toc->bitmap1_start);
printf ("Log bitmap size : 0x%llX\n", (unsigned long long) toc->bitmap1_size);
printf ("Bitmap name : \"%s\"\n", toc->bitmap2_name);
printf ("Log bitmap start : 0x%llX\n", (unsigned long long) toc->bitmap2_start);
printf ("Log bitmap size : 0x%llX\n", (unsigned long long) toc->bitmap2_size);
return 0;
}
/**
* dump_disks -
*/
static int dump_disks (struct ldmdb *ldb)
{
struct list_head *disk_item, *part_item;
struct vblk *disk_vb, *part_vb;
printf ("PARTITION LAYOUT:\n");
printf ("\n");
list_for_each (disk_item, &ldb->v_disk) {
disk_vb = list_entry (disk_item, struct vblk, list);
printf ("Disk %s:\n", disk_vb->name);
list_for_each (part_item, &ldb->v_part) {
struct vblk_part *part;
part_vb = list_entry (part_item, struct vblk, list);
part = &part_vb->vblk.part;
if (disk_vb->obj_id != part->disk_id)
continue;
printf (" %s ", part_vb->name);
printf ("Offset: 0x%08llX ", part->start);
printf ("Length: 0x%08llX (%llu MB)\n", (unsigned long long) part->size, (unsigned long long) part->size>>11);
}
}
printf ("\n");
return 0;
}
/**
* dump_volumes -
*/
static int dump_volumes (struct ldmdb *ldb)
{
struct list_head *volu_item, *comp_item, *part_item;
struct vblk *volu_vb, *comp_vb, *part_vb;
printf ("VOLUME DEFINITIONS:\n");
printf ("\n");
list_for_each (volu_item, &ldb->v_volu) {
volu_vb = list_entry (volu_item, struct vblk, list);
printf ("%s ", volu_vb->name);
printf ("Size: 0x%08llX (%llu MB)\n", (unsigned long long) volu_vb->vblk.volu.size, (unsigned long long) volu_vb->vblk.volu.size >> 11);
list_for_each (comp_item, &ldb->v_comp) {
comp_vb = list_entry (comp_item, struct vblk, list);
if (volu_vb->obj_id != comp_vb->vblk.comp.parent_id)
continue;
printf (" %s\n", comp_vb->name);
list_for_each (part_item, &ldb->v_part) {
part_vb = list_entry (part_item, struct vblk, list);
if (comp_vb->obj_id != part_vb->vblk.part.parent_id)
continue;
printf (" %s ", part_vb->name);
printf ("VolumeOffset: 0x%08llX ", part_vb->vblk.part.volume_offset);
printf ("Offset: 0x%08llX ", part_vb->vblk.part.start);
printf ("Length: 0x%08llX\n", part_vb->vblk.part.size);
}
}
}
printf ("\n");
return 0;
}
/**
* dump_database -
*/
void dump_database (char *name, struct ldmdb *ldb)
{
printf ("Device: %s\n\n", name);
dump_privhead (&ldb->ph);
dump_tocblock (&ldb->toc);
dump_vmdb (ldb);
dump_disks (ldb);
dump_volumes (ldb);
}
--- NEW FILE ---
/**
* ldm - Support for Windows Logical Disk Manager (Dynamic Disks)
*
* Copyright (C) 2001-2005 Richard Russon
* Copyright (c) 2001-2004 Anton Altaparmakov
* Copyright (C) 2001-2002 Jakob Kemi
*
* Documentation is available at http://linux-ntfs.sf.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.
*
[...1477 lines suppressed...]
goto cleanup;
}
/* Finally, create the data partition devices. */
if (ldm_create_data_partitions (pp, ldb)) {
ldm_debug ("Parsed LDM database successfully.");
result = 1;
}
/* else Already logged */
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);
out:
return result;
}
--- NEW FILE ---
/**
* ldm - Part of the Linux-NTFS project.
*
* Copyright (C) 2001-2005 Richard Russon
* Copyright (C) 2001 Anton Altaparmakov
* Copyright (C) 2001-2002 Jakob Kemi
*
* Documentation is available at http://linux-ntfs.sf.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
*/
#ifndef _FS_PT_LDM_H_
#define _FS_PT_LDM_H_
#define MAX_PART 256
struct parsed_partitions {
char name[40];
struct {
unsigned long from;
unsigned long size;
int flags;
} parts[MAX_PART];
int next;
int limit;
};
#include <stdio.h>
#include <string.h>
#include "list.h"
#include "types.h"
#define BUG_ON(condition) \
do { \
if (condition) { \
printf (KERN_CRIT "BUG in %s(%d) %s [%s]\n", \
__FILE__, __LINE__, __FUNCTION__, #condition); \
exit (1); \
} \
} while(0)
struct partition {
unsigned char boot_ind; /* 0x80 - active */
unsigned char head; /* starting head */
unsigned char sector; /* starting sector */
unsigned char cyl; /* starting cylinder */
unsigned char sys_ind; /* What partition type */
unsigned char end_head; /* end head */
unsigned char end_sector; /* end sector */
unsigned char end_cyl; /* end cylinder */
unsigned int start_sect; /* starting sector counting from 0 */
unsigned int nr_sects; /* nr of sectors in partition */
};
/* Magic numbers in CPU format. */
#define MAGIC_VMDB 0x564D4442 /* VMDB */
#define MAGIC_VBLK 0x56424C4B /* VBLK */
#define MAGIC_PRIVHEAD 0x5052495648454144ULL /* PRIVHEAD */
#define MAGIC_TOCBLOCK 0x544F43424C4F434BULL /* TOCBLOCK */
/* The defined vblk types. */
#define VBLK_VOL5 0x51 /* Volume, version 5 */
#define VBLK_CMP3 0x32 /* Component, version 3 */
#define VBLK_PRT3 0x33 /* Partition, version 3 */
#define VBLK_DSK3 0x34 /* Disk, version 3 */
#define VBLK_DSK4 0x44 /* Disk, version 4 */
#define VBLK_DGR3 0x35 /* Disk Group, version 3 */
#define VBLK_DGR4 0x45 /* Disk Group, version 4 */
/* vblk flags indicating extra information will be present */
#define VBLK_FLAG_COMP_STRIPE 0x10
#define VBLK_FLAG_PART_INDEX 0x08
#define VBLK_FLAG_DGR3_IDS 0x08
#define VBLK_FLAG_DGR4_IDS 0x08
#define VBLK_FLAG_VOLU_ID1 0x08
#define VBLK_FLAG_VOLU_ID2 0x20
#define VBLK_FLAG_VOLU_SIZE 0x80
#define VBLK_FLAG_VOLU_DRIVE 0x02
/* size of a vblk's static parts */
#define VBLK_SIZE_HEAD 16
#define VBLK_SIZE_CMP3 22 /* Name and version */
#define VBLK_SIZE_DGR3 12
#define VBLK_SIZE_DGR4 44
#define VBLK_SIZE_DSK3 12
#define VBLK_SIZE_DSK4 45
#define VBLK_SIZE_PRT3 28
#define VBLK_SIZE_VOL5 59
/* component types */
#define COMP_STRIPE 0x01 /* Stripe-set */
#define COMP_BASIC 0x02 /* Basic disk */
#define COMP_RAID 0x03 /* Raid-set */
/* Other constants. */
#define LDM_DB_SIZE 2048 /* Size in sectors (= 1MiB). */
#define OFF_PRIV1 6 /* Offset of the first privhead
relative to the start of the
device in sectors */
/* Offsets to structures within the LDM Database in sectors. */
#define OFF_PRIV2 1856 /* Backup private headers. */
#define OFF_PRIV3 2047
#define OFF_TOCB1 1 /* Tables of contents. */
#define OFF_TOCB2 2
#define OFF_TOCB3 2045
#define OFF_TOCB4 2046
#define OFF_VMDB 17 /* List of partitions. */
#define WIN_DYNAMIC_PARTITION 0x42 /* Formerly SFS (Landis). */
#define TOC_BITMAP1 "config" /* Names of the two defined */
#define TOC_BITMAP2 "log" /* bitmaps in the TOCBLOCK. */
/* Most numbers we deal with are big-endian and won't be aligned. */
#define BE16(x) ((u16)be16_to_cpu(*(const u16*)(x)))
#define BE32(x) ((u32)be32_to_cpu(*(const u32*)(x)))
#define BE64(x) ((u64)be64_to_cpu(*(const u64*)(x)))
/* Borrowed from msdos.c */
#define SYS_IND(p) ((p)->sys_ind)
struct frag { /* VBLK Fragment handling */
struct list_head list;
u32 group;
u8 num; /* Total number of records */
u8 rec; /* This is record number n */
u8 map; /* Which portions are in use */
u8 data[0];
};
/* In memory LDM database structures. */
#define GUID_SIZE 16
struct privhead { /* Offsets and sizes are in sectors. */
u16 ver_major;
u16 ver_minor;
u64 logical_disk_start;
u64 logical_disk_size;
u64 config_start;
u64 config_size;
u8 disk_id[GUID_SIZE];
};
struct tocblock { /* We have exactly two bitmaps. */
u8 bitmap1_name[16];
u64 bitmap1_start;
u64 bitmap1_size;
u8 bitmap2_name[16];
u64 bitmap2_start;
u64 bitmap2_size;
};
struct vmdb { /* VMDB: The database header */
u16 ver_major;
u16 ver_minor;
u32 vblk_size;
u32 vblk_offset;
u32 last_vblk_seq;
};
struct vblk_comp { /* VBLK Component */
u8 state[16];
u64 parent_id;
u8 type;
u8 children;
u16 chunksize;
};
struct vblk_dgrp { /* VBLK Disk Group */
u8 disk_id[64];
};
struct vblk_disk { /* VBLK Disk */
u8 disk_id[GUID_SIZE];
u8 alt_name[128];
};
struct vblk_part { /* VBLK Partition */
u64 start;
u64 size; /* start, size and vol_off in sectors */
u64 volume_offset;
u64 parent_id;
u64 disk_id;
u8 partnum;
};
struct vblk_volu { /* VBLK Volume */
u8 volume_type[16];
u8 volume_state[16];
u8 guid[16];
u8 drive_hint[4];
u64 size;
u8 partition_type;
};
struct vblk_head { /* VBLK standard header */
u32 group;
u16 rec;
u16 nrec;
};
struct vblk { /* Generalised VBLK */
u8 name[64];
u64 obj_id;
u32 sequence;
u8 flags;
u8 type;
union {
struct vblk_comp comp;
struct vblk_dgrp dgrp;
struct vblk_disk disk;
struct vblk_part part;
struct vblk_volu volu;
} vblk;
struct list_head list;
};
struct ldmdb { /* Cache of the database */
struct privhead ph;
struct tocblock toc;
struct vmdb vm;
struct list_head v_dgrp;
struct list_head v_disk;
struct list_head v_volu;
struct list_head v_comp;
struct list_head v_part;
};
struct parsed_partitions;
struct block_device;
int ldm_partition (int device, struct parsed_partitions *pp, struct ldmdb *ldb);
#endif /* _FS_PT_LDM_H_ */
--- NEW FILE ---
/**
* ldminfo - Part of the Linux-NTFS project.
*
* Copyright (C) 2001-2005 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 <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include "ldminfo.h"
int debug = 0;
/**
* dump_info - Display a list of partitions, a la fdisk
*/
static void dump_info (char *name, struct parsed_partitions *pp)
{
int i;
int numeric;
name = basename (name);
numeric = isdigit (name[strlen (name) - 1]);
printf ("Device | Offset Bytes Sectors MiB | Size Bytes Sectors MiB\n"
"-------------+--------------------------------+-------------------------------\n");
for (i = 0; i < 256; i++) {
char buf[16];
long long start;
long long size;
if (pp->parts[i].size == 0)
break;
if (i)
if (numeric)
sprintf (buf, "%.10sp%d", name, i);
else
sprintf (buf, "%.10s%d", name, i);
else
sprintf (buf, "%.10s", name);
start = pp->parts[i].from; start <<= 9;
size = pp->parts[i].size; size <<= 9;
printf ("%-12.12s | %12lld %10lld %6lld | %12lld %10lld %6lld\n", buf, start, start>>9, start>>20, size, size>>9, size>>20);
}
printf ("\n");
}
/**
* main - ldminfo entry point
*/
int main (int argc, char *argv[])
{
int a;
int info = 0;
int dump = 0;
int copy = 0;
int help = 0;
int ver = 0;
int dev = -1;
struct stat64 st;
struct ldmdb *ldb = NULL;
for (a = 1; a < argc; a++) {
if (strcmp (argv[a], "--info") == 0) info++;
else if (strcmp (argv[a], "--dump") == 0) dump++;
else if (strcmp (argv[a], "--copy") == 0) copy++;
else if (strcmp (argv[a], "--debug") == 0) debug++;
else if (strcmp (argv[a], "--help") == 0) help++;
else if (strcmp (argv[a], "--version") == 0) ver++;
else continue;
argv[a][0] = 0;
}
if (help || (argc - info - dump - copy - debug) < 2) {
printf ("\nUsage:\n %s [options] device ...\n", basename (argv[0]));
printf ("\nOptions:\n"
" --info A concise list of partitions (default)\n"
" --dump The contents of the database in detail\n"
" --copy Write the database to a file\n"
" --debug Display lots of debugging information\n"
" --version display the version number\n"
" --help Show this short help\n\n");
return 1;
}
if (ver) {
printf ("\nldminfo v0.0.8\n\n");
return 1;
}
ldb = malloc (sizeof (*ldb));
if (!ldb) {
printf ("Out of memory\n");
return 1;
}
for (a = 1; a < argc; a++) {
long long size;
struct parsed_partitions pp; //FIXME move to heap
memset (ldb, 0, sizeof (*ldb));
if (!argv[a][0])
continue;
if (stat64 (argv[a], &st)) {
printf ("Couldn't open device (stat): %s\n", argv[a]);
break;
}
if ((!S_ISBLK (st.st_mode)) && (!S_ISREG (st.st_mode))) {
printf ("Couldn't open device (dev/file): %s\n", argv[a]);
break;
}
dev = open64 (argv[a], O_RDONLY);
if (dev < 0) {
printf ("Couldn't open device (open): %s\n", argv[a]);
break;
}
size = lseek64 (dev, 0, SEEK_END);
if (size < 0) {
printf ("Seek failed for device: %s\n", argv[a]);
break;
}
if (copy) {
copy_database (argv[a], dev, 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);
memset (&pp, 0, sizeof (pp));
pp.parts[0].from = 0;
pp.parts[0].size = size >> 9;
pp.limit = 255;
if (ldm_partition (dev, &pp, ldb) != 1) {
printf ("Something went wrong, skipping device '%s'\n", argv[a]);
goto free;
}
if (dump)
dump_database (argv[a], ldb);
else
dump_info (argv[a], &pp);
free:
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);
close:
close (dev);
dev = 0;
}
free (ldb);
if (dev)
close (dev);
return 0;
}
--- NEW FILE ---
#ifndef __LDMINFO_H_
#define __LDMINFO_H_
#include "ldm.h"
#include <byteswap.h>
#include <endian.h>
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define be16_to_cpu(s) bswap_16(s)
#define be32_to_cpu(s) bswap_32(s)
#define be64_to_cpu(s) bswap_64(s)
#define cpu_to_le16
#define cpu_to_le32
#define cpu_to_le64
#else
#define be16_to_cpu
#define be32_to_cpu
#define be64_to_cpu
#define cpu_to_le16(s) bswap_16(s)
#define cpu_to_le32(s) bswap_32(s)
#define cpu_to_le64(s) bswap_64(s)
#endif
extern int debug;
void dump_database (char *name, struct ldmdb *ldb);
void copy_database (char *file, int fd, long long size);
void ldm_free_vblks (struct list_head *vb);
#endif // __LDMINFO_H_
--- NEW FILE ---
#ifndef _LINUX_LIST_H
#define _LINUX_LIST_H
/*
* container_of - cast a member of a structure out to the containing structure
*
* @ptr: the pointer to the member.
* @type: the type of the container struct this is embedded in.
* @member: the name of the member within the struct.
*
*/
#define container_of(ptr, type, member) ({ \
typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
/*
* These are non-NULL pointers that will result in page faults
* under normal circumstances, used to verify that nobody uses
* non-initialized list entries.
*/
#define LIST_POISON1 ((void *) 0x00100100)
#define LIST_POISON2 ((void *) 0x00200200)
/*
* Simple doubly linked list implementation.
*
* Some of the internal functions ("__xxx") are useful when
* manipulating whole lists rather than single entries, as
* sometimes we already know the next/prev entries and we can
* generate better code by using them directly rather than
* using the generic single-entry routines.
*/
struct list_head {
struct list_head *next, *prev;
};
#define LIST_HEAD_INIT(name) { &(name), &(name) }
#define LIST_HEAD(name) \
struct list_head name = LIST_HEAD_INIT(name)
#define INIT_LIST_HEAD(ptr) do { \
(ptr)->next = (ptr); (ptr)->prev = (ptr); \
} while (0)
/*
* Insert a new entry between two known consecutive entries.
*
* This is only for internal list manipulation where we know
* the prev/next entries already!
*/
static inline void __list_add(struct list_head *new,
struct list_head *prev,
struct list_head *next)
{
next->prev = new;
new->next = next;
new->prev = prev;
prev->next = new;
}
/**
* list_add - add a new entry
* @new: new entry to be added
* @head: list head to add it after
*
* Insert a new entry after the specified head.
* This is good for implementing stacks.
*/
static...
[truncated message content] |