Add -f file support. Useful to search for partitions on disk images.

This commit is contained in:
xtraeme 2006-09-07 00:48:21 +00:00
parent beafae096b
commit 7aa92d971b
2 changed files with 53 additions and 27 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: scan_ffs.8,v 1.7 2006/08/12 10:14:22 ghen Exp $
.\" $NetBSD: scan_ffs.8,v 1.8 2006/09/07 00:48:21 xtraeme Exp $
.\" OpenBSD: scan_ffs.8,v 1.13 2004/12/14 00:04:21 jmc Exp
.\"
.\" Copyright (c) 2005 Juan Romero Pardines
@ -25,24 +25,25 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd September 10, 2005
.Dd September 7, 2006
.Dt SCAN_FFS 8
.Os
.Sh NAME
.Nm scan_ffs ,
.Nm scan_lfs
.Nd find FFSv1/FFSv2/LFS partitions on a disk
.Nd find FFSv1/FFSv2/LFS partitions on a disk or file
.Sh SYNOPSIS
.Nm
.Op Fl lv
.Op Fl f Ar file
.Op Fl e Ar end
.Op Fl s Ar start
.Ar device
.Sh DESCRIPTION
.Nm
will take a raw disk device that covers the whole disk and will find
all possible FFSv[12]/LFS partitions, independent of block sizes, on
the disk.
will take a raw disk device that covers the whole disk or a file
and will find all possible FFSv[12]/LFS partitions, independent
of block sizes on it.
It will show the file system type (FFSv1, FFSv2, or LFS), size, and
offset.
Also it has an option to show the values with a disklabel-alike
@ -57,6 +58,8 @@ The
argument specifies the last sector that will be searched.
Default is the last sector of
.Ar device .
.It Fl f Ar file
Path to a file containing possible partitions inside of it.
.It Fl l
Print out a string looking much like the input to disklabel.
With a little massaging, this output can usually be used by
@ -94,6 +97,8 @@ program first appeared in
.Ox 2.3
and then in
.Nx 3.1 .
Support for searching in files was added in
.Nx 4.0 .
.Sh AUTHORS
.An -nosplit
.Nm

View File

@ -1,4 +1,4 @@
/* $NetBSD: scan_ffs.c,v 1.9 2005/09/02 17:48:40 xtraeme Exp $ */
/* $NetBSD: scan_ffs.c,v 1.10 2006/09/07 00:48:21 xtraeme Exp $ */
/*
* Copyright (c) 2005 The NetBSD Foundation, Inc.
@ -77,7 +77,7 @@
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: scan_ffs.c,v 1.9 2005/09/02 17:48:40 xtraeme Exp $");
__RCSID("$NetBSD: scan_ffs.c,v 1.10 2006/09/07 00:48:21 xtraeme Exp $");
#endif /* not lint */
#include <sys/types.h>
@ -153,6 +153,7 @@ struct sblockinfo {
static daddr_t blk, lastblk;
static int eflag = 0;
static int fflag = 0;
static int flags = 0;
static int sbaddr = 0; /* counter for the LFS superblocks */
@ -374,7 +375,7 @@ lfs_scan(int n)
static int
scan_disk(int fd, daddr_t beg, daddr_t end, int fflags)
{
u_int8_t buf[SBLOCKSIZE * SBCOUNT];
uint8_t buf[SBLOCKSIZE * SBCOUNT];
int n, fstype;
n = fstype = 0;
@ -423,7 +424,8 @@ static void
usage(void)
{
(void)fprintf(stderr,
"Usage: %s [-lv] [-s start] [-e end] device\n", getprogname());
"Usage: %s [-f file] [-lv] [-s start] [-e end] "
"device\n", getprogname());
exit(EXIT_FAILURE);
}
@ -432,16 +434,23 @@ int
main(int argc, char **argv)
{
int ch, fd;
const char *fpath;
daddr_t end = -1, beg = 0;
struct disklabel dl;
fpath = NULL;
setprogname(*argv);
while ((ch = getopt(argc, argv, "e:ls:v")) != -1)
while ((ch = getopt(argc, argv, "e:f:ls:v")) != -1)
switch(ch) {
case 'e':
eflag = 1;
end = atoi(optarg);
break;
case 'f':
fflag = 1;
fpath = optarg;
break;
case 'l':
flags |= LABELS;
break;
@ -459,27 +468,39 @@ main(int argc, char **argv)
argc -= optind;
argv += optind;
if (argc != 1)
usage();
if (fflag) {
struct stat stp;
fd = opendisk(argv[0], O_RDONLY, device, sizeof(device), 0);
if (stat(fpath, &stp))
err(1, "Cannot stat `%s'", fpath);
if (!eflag)
end = (unsigned)stp.st_size;
fd = open(fpath, O_RDONLY);
} else {
if (argc != 1)
usage();
fd = opendisk(argv[0], O_RDONLY, device, sizeof(device), 0);
if (ioctl(fd, DIOCGDINFO, &dl) == -1) {
warn("Couldn't retrieve disklabel");
(void)memset(&dl, 0, sizeof(dl));
dl.d_secperunit = 0x7fffffff;
} else {
(void)printf("Disk: %s\n", dl.d_typename);
(void)printf("Total sectors on disk: %" PRIu32 "\n\n",
dl.d_secperunit);
}
}
if (!eflag && !fflag)
end = dl.d_secperunit; /* default to max sectors */
if (fd == -1)
err(1, "Cannot open `%s'", device);
/* NOTREACHED */
if (ioctl(fd, DIOCGDINFO, &dl) == -1) {
warn("Couldn't retrieve disklabel");
(void)memset(&dl, 0, sizeof(dl));
dl.d_secperunit = 0x7fffffff;
} else {
(void)printf("Disk: %s\n", dl.d_typename);
(void)printf("Total sectors on disk: %" PRIu32 "\n\n",
dl.d_secperunit);
}
if (!eflag)
end = dl.d_secperunit; /* default to max sectors */
return scan_disk(fd, beg, end, flags);
}