Commit ab1c2d36 authored by Mike Hibler's avatar Mike Hibler

Before I realized it wasn't really needed, I hacked in the -n option

to treat the given slice as an NTFS.  Analogous to -b for bsd and -l
for linux.

Clean up a little lint in the NTFS code too
parent 3b2cadd2
......@@ -201,7 +201,9 @@ that
is a BSD slice. Should be used only when the device does not contain
a DOS partition table and really does contains a BSD filesystem.
Incompatible with
.Fl l .
.Fl l
and
.Fl n .
.It Fl c Ar count
Explicitly tell
.Nm
......@@ -239,7 +241,20 @@ that
is a Linux filesystem slice. Should be used only when the device does
not contain a DOS partition table and really does contains a Linux filesystem.
Incompatible with
.Fl b .
.Fl b
and
.Fl n .
.It Fl n
Tells
.Nm
that
.Ar device
is an NTFS slice. Should be used only when the device does not contain
a DOS partition table and really does contains an NT filesystem.
Incompatible with
.Fl b
and
.Fl l .
.It Fl X
Try e(X)tremely hard to read data from the input device,
returning success even if a read fails.
......
......@@ -322,10 +322,11 @@ main(argc, argv)
char *outfilename = 0;
int linuxfs = 0;
int bsdfs = 0;
int ntfs = 0;
int rawmode = 0;
extern char build_info[];
while ((ch = getopt(argc, argv, "vlbdihrs:c:z:oI:1F:DR:X")) != -1)
while ((ch = getopt(argc, argv, "vlbndihrs:c:z:oI:1F:DR:X")) != -1)
switch(ch) {
case 'v':
version++;
......@@ -345,6 +346,9 @@ main(argc, argv)
case 'b':
bsdfs++;
break;
case 'n':
ntfs++;
break;
case 'o':
dots++;
break;
......@@ -409,8 +413,8 @@ main(argc, argv)
"the slice (-s) option\n\n");
usage();
}
if (linuxfs && bsdfs) {
fprintf(stderr, "Cannot specify linux and bsd together!\n\n");
if (linuxfs + bsdfs + ntfs > 1) {
fprintf(stderr, "-b, -l, and -n are mutually exclusive!\n\n");
usage();
}
if (!info && argc != 2) {
......@@ -434,6 +438,10 @@ main(argc, argv)
#ifndef linux
else if (bsdfs)
rval = read_bsdslice(0, 0, 0, DOSPTYP_386BSD);
#ifdef WITH_NTFS
else if (ntfs)
rval = read_ntfsslice(0, 0, 0, infilename);
#endif
else if (rawmode)
rval = read_raw();
else
......@@ -1482,16 +1490,21 @@ read_ntfsslice(int slice, u_int32_t start, u_int32_t size, char *openname)
assert(sizeof(s32) == 4);
assert(sizeof(u64) == 8);
assert(sizeof(u32) == 4);
length = strlen(openname);
name = malloc(length+3);
/*Our NTFS Library code needs the /dev name of the partion to
/*Our NTFS Library code needs the /dev name of the partition to
* examine. The following line is FreeBSD specific code.*/
sprintf(name,"%ss%d",openname,slice + 1);
if (slice != 0) {
length = strlen(openname);
name = malloc(length+3);
sprintf(name,"%ss%d",openname,slice + 1);
} else
name = openname;
/*The volume must be mounted to find out what clusters are free*/
if(!(vol = ntfs_mount(name, MS_RDONLY))) {
fprintf(stderr,"When mounting %s\n",name);
perror("Failed to read superblock information. Not a valid "
"NTFS partition\n");
perror(name);
fprintf(stderr, "Failed to read superblock information. "
"Not a valid NTFS partition\n");
if (name != openname)
free(name);
return -1;
}
/*A bitmap of free clusters is in the $DATA attribute of the
......@@ -1536,8 +1549,10 @@ read_ntfsslice(int slice, u_int32_t start, u_int32_t size, char *openname)
exit(1);
}
/*Free NTFS malloc'd memory*/
assert(name && "Programming Error, name should be freed here");
free(name);
if (name != openname) {
assert(name && "Programming Error, name should be freed here");
free(name);
}
assert(buf && "Programming Error, buf should be freed here");
free(buf);
assert(cfree && "Programming Error, "
......@@ -1593,8 +1608,10 @@ char *usagestr =
"\n"
" Debugging options (not to be used by mere mortals!)\n"
" -d Turn on debugging. Multiple -d options increase output\n"
" -l Linux slice only. Input must be a Linux slice image\n"
" -b FreeBSD slice only. Input must be a FreeBSD slice image\n";
" -b FreeBSD slice only. Input must be a FreeBSD FFS slice\n"
" -l Linux slice only. Input must be a Linux EXT2FS slice\n"
" -n NTFS slice only. Input must be an NTFS slice\n";
void
usage()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment