/* vi:set shiftwidth=2 cindent tabstop=2: */ /* * vxtools - Tools for accessing Veritas Journaled FileSystem (VxFS) * Copyright (c) 1999 Martin Hinner * * vxcat.c: Concatenate files and print on the standard output * * 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; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Id$ */ #include #include #include #include #include char *usage = "Usage: %s [-dh] [name...]\n" "\n" "Report bugs to \n"; void catfile (char *filename) { int ino; struct vxfs_inode *inode; long long size; int blkno; char *buf; int i; ino = vxlookup (filename); if (ino < 0) { printf ("%s: No such file or directory\n", filename); return; } inode = vxiget (ino); if (inode == NULL) { printf ("%s: Can't get inode %u\n", filename, ino); return; } size = inode->size; blkno = 0; while (size) { buf = (char *) vxiread (inode, blkno, 1); if (buf == NULL) { fprintf (stderr, "%s: vxiread failed at block %u\n", filename, blkno); return; } for (i = 0; i < (size > vxbsize ? vxbsize : size); i++) putchar (buf[i]); free (buf); size -= size > vxbsize ? vxbsize : size; blkno++; } vxiput (inode); } int main (int argc, char **argv) { int ch; char *argv0 = argv[0]; char device[0x100], cwd[0x100]; int subpart; char path[0x100]; vxverboseon (); subpart = 0; while ((ch = getopt (argc, argv, "dhp:")) != -1) { switch (ch) { case 'd': vxdebugon (); break; case 'h': fprintf (stderr, usage, argv0); exit (0); default: fprintf (stderr, usage, argv0); exit (1); } } argc -= optind; argv += optind; if (argc < 1) { fprintf (stderr, usage, argv0); exit (1); } if (vxreadcwd (device, &subpart, cwd) < 0) { fprintf (stderr, "%s: No VxFS filesystem mounted, use vxmount(8)\n", argv0); exit (1); } if (vx_open (device, subpart) < 0) { fprintf (stderr, "%s: Can't mount VxFS %s\n", argv0, device); exit (1); } while (argc--) { if (argv[0][0] == '/') strcpy (path, argv[0]); else { strcpy (path, cwd); strcat (path, "/"); strcat (path, argv[0]); } catfile (path); argv++; } return 0; }