/*++
/* NAME
/*	icat 1
/* SUMMARY
/*	copy files by inode number
/* SYNOPSIS
/*	\fBicat\fR [\fB-hv\fR] \fIdevice\fR \fIinode\fR ...
/* DESCRIPTION
/*	\fBicat\fR opens the named \fIdevice\fR and copies the files
/*	with the specified \fIinode\fR numbers to standard output.
/*
/*	\fBicat\fR can operate on both disk special files and on
/*	regular files containing a disk image.
/*	With UNIX FFS, using a raw disk device gives better efficiency
/*	than using a block device.
/*	With LINUX ext2fs, \fBicat\fR does not support access via the
/*	raw disk device interface.
/*
/*	 Options:
/* .IP \fB-h\fR
/*	Skip over holes in files, so that absolute address information
/*	is lost.  By default, \fBicat\fR copies holes as blocks of null
/*	bytes.
/* .IP \fB-v\fR
/*	Enable verbose mode, for debugging purposes.
/* BUGS
/*	\fBicat\fR currently supports only one file system type,
/*	namely, the default file system type of the system it was
/*	compiled for.
/* LICENSE
/*	This software is distributed under the IBM Public License.
/* AUTHOR(S)
/*	Wietse Venema
/*	IBM T.J. Watson Research
/*	P.O. Box 704
/*	Yorktown Heights, NY 10598, USA
/*--*/

#include "fs_tools.h"
#include "error.h"

/* usage - explain and terminate */

static void usage()
{
    error("usage: %s device inum...", progname);
}

int     main(int argc, char **argv)
{
    FS_INFO *fs;
    char   *cp;
    INUM_T  inum;
    int     flags = FS_FLAG_ALLOC | FS_FLAG_UNALLOC;
    int     ch;

    progname = argv[0];

    while ((ch = getopt(argc, argv, "hv")) > 0) {
	switch (ch) {
	default:
	    usage();
	case 'h':
	    flags &= ~FS_FLAG_UNALLOC;
	    break;
	case 'v':
	    verbose++;
	    break;
	}
    }

    if (argc < optind + 2)
	usage();

    fs = fs_open(argv[optind], DEF_FSTYPE);

    while (argv[++optind]) {
	inum = STRTOUL(argv[optind], &cp, 0);
	if (*cp || cp == argv[optind])
	    usage();
	fs_copy_file(fs, inum, flags);
    }
    fs->close(fs);
    exit(0);
}
