Commit da3bcef0 authored by Mike Hibler's avatar Mike Hibler
Browse files

Get rid of the hacky code to figure out what special file was associated

with every DOS partition.  It was only used by NTFS and has been replaced
by equally hacky changes to the NTFS library.

The benefit of the latter is that it at least works all the time on
Linux and all FreeBSD versions.
parent 46689499
......@@ -12,7 +12,6 @@ extern int secsize;
extern int slicemode;
extern int dorelocs;
extern char *slicename(int slice, u_int32_t offset, u_int32_t size, int type);
extern off_t devlseek(int fd, off_t off, int whence);
extern ssize_t devread(int fd, void *buf, size_t nbytes);
extern void addskip(uint32_t start, uint32_t size);
......
......@@ -98,8 +98,6 @@ int read_raw(void);
int compress_image(void);
void usage(void);
static void getsliceinfo(char *disk, int diskfd);
static SLICEMAP_PROCESS_PROTO(read_slice);
struct slicemap fsmap[] = {
......@@ -436,7 +434,6 @@ main(argc, argv)
perror(infilename);
exit(1);
}
getsliceinfo(infilename, infd);
if (slicetype != 0) {
rval = read_slice(-1, slicetype, 0, 0, infilename, infd);
......@@ -556,13 +553,8 @@ read_image(u_int32_t bbstart, int pstart, u_int32_t extstart)
else
start += bbstart;
#endif
fprintf(stderr, " start %9d, size %9d",
fprintf(stderr, " start %9d, size %9d\n",
start, doslabel.parts[i].dp_size);
fprintf(stderr, ", slicedev %s\n",
slicename(bsdix,
bbstart + doslabel.parts[i].dp_start,
doslabel.parts[i].dp_size,
doslabel.parts[i].dp_typ)?:"<none>");
}
fprintf(stderr, "\n");
}
......@@ -656,103 +648,6 @@ read_image(u_int32_t bbstart, int pstart, u_int32_t extstart)
return rval;
}
/*
* Read the kernel slice information to get a mapping of special file
* to slice. This is currently only used for NTFS.
*/
static struct dsinfo {
u_int32_t offset;
u_int32_t size;
int type;
char name[20];
} sliceinfo[MAXSLICES];
static int sliceinfosize = 0;
#if defined(__FreeBSD__) && __FreeBSD__ < 5
#include <sys/diskslice.h>
#endif
static void
getsliceinfo(char *disk, int diskfd)
{
int si, gotit = 0;
#ifdef DIOCGSLICEINFO
struct diskslices dsinfo;
int i;
if (ioctl(diskfd, DIOCGSLICEINFO, &dsinfo) == 0) {
for (si = 0, i = BASE_SLICE; i < dsinfo.dss_nslices; si++,i++) {
sliceinfo[si].offset = dsinfo.dss_slices[i].ds_offset;
sliceinfo[si].size = dsinfo.dss_slices[i].ds_size;
sliceinfo[si].type = dsinfo.dss_slices[i].ds_type;
snprintf(sliceinfo[si].name, sizeof(sliceinfo[si].name),
"%ss%d", disk, si+1);
sliceinfosize++;
}
gotit++;
}
#endif
/*
* XXX If we didn't get it above, guess the name for primary partitions.
* It is only extended partitions where the naming isn't obvious.
*/
if (!gotit) {
fprintf(stderr,
"WARNING: Could not acquire slice device names "
"from kernel, guessing...\n");
for (si = 0; si < 4; si++) {
sliceinfo[si].offset = 0;
sliceinfo[si].size = 0;
sliceinfo[si].type = 0;
snprintf(sliceinfo[si].name, sizeof(sliceinfo[si].name),
#ifdef linux
"%s%d",
#else
"%ss%d",
#endif
disk, si+1);
sliceinfosize++;
}
}
if (debug > 1) {
fprintf(stderr, "Slice special files:\n");
for (si = 0; si < sliceinfosize; si++)
fprintf(stderr, " %s: off=%9u size=%9u type=%02d\n",
sliceinfo[si].name,
sliceinfo[si].offset,
sliceinfo[si].size,
sliceinfo[si].type);
fprintf(stderr, "\n");
}
}
/*
* Find a disk special with the indicated parameters
*/
char *
slicename(int slice, u_int32_t offset, u_int32_t size, int type)
{
int si;
for (si = 0; si < sliceinfosize; si++)
if (sliceinfo[si].offset == offset &&
sliceinfo[si].size == size &&
sliceinfo[si].type == type)
return sliceinfo[si].name;
/*
* XXX use the slice number to pick
*/
if (slice < 4 && sliceinfo[slice].type == 0 &&
sliceinfo[slice].offset == 0 && sliceinfo[slice].size == 0 &&
sliceinfo[slice].name != 0)
return sliceinfo[slice].name;
return 0;
}
/*
* For a raw image (something we know nothing about), we report the size
......
/*
* EMULAB-COPYRIGHT
* Copyright (c) 2000-2003 University of Utah and the Flux Group.
* Copyright (c) 2000-2004 University of Utah and the Flux Group.
* All rights reserved.
*/
......@@ -314,8 +314,8 @@ read_ntfsslice(int slice, int stype, u_int32_t start, u_int32_t size,
void *buf;
struct ntfs_cluster *cfree;
struct ntfs_cluster *tmp;
char *name;
ntfs_volume *vol;
s64 offset;
/* Check to make sure the types the NTFS lib defines are what they
claim*/
......@@ -327,20 +327,15 @@ read_ntfsslice(int slice, int stype, u_int32_t start, u_int32_t size,
* The NTFS library needs the /dev name of the partition to examine.
*/
if (slice < 0)
name = openname;
offset = 0LL;
else
name = slicename(slice, start, size, DOSPTYP_NTFS);
if (name == NULL) {
fprintf(stderr,
"Could not locate special file for NTFS slice %d\n",
slice+1);
return 1;
}
offset = sectobytes(start);
if (debug)
fprintf(stderr, "Using %s for NTFS slice %d\n", name, slice+1);
fprintf(stderr, "Using %s at offset %qu for NTFS slice %d\n",
openname, offset, slice+1);
/*The volume must be mounted to find out what clusters are free*/
if(!(vol = ntfs_mount(name, MS_RDONLY))) {
perror(name);
if(!(vol = ntfs_mount_with_offset(openname, MS_RDONLY, offset))) {
perror(openname);
fprintf(stderr, "Failed to read superblock information. "
"Not a valid NTFS partition\n");
return 1;
......@@ -363,7 +358,7 @@ read_ntfsslice(int slice, int stype, u_int32_t start, u_int32_t size,
fprintf(stderr, " P%d (NTFS v%u.%u)\n",
slice + 1 /* DOS Numbering */,
vol->major_ver,vol->minor_ver);
fprintf(stderr, " %s",name);
fprintf(stderr, " %s",openname);
fprintf(stderr, " start %10d, size %10d\n", start, size);
fprintf(stderr, " Sector size: %u, Cluster size: %u\n",
vol->sector_size, vol->cluster_size);
......
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