/* vi:set shiftwidth=2 cindent tabstop=2: */ /* * vxtools - Tools for accessing Veritas Journaled FileSystem (VxFS) * Copyright (c) 1999 Martin Hinner * * vxcd.c: Change the current directory * * 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] [directory]\n" "\n" "Report bugs to \n"; int main (int argc, char **argv) { int ch; char *argv0 = argv[0]; char device[0x100], cwd[0x100]; int subpart; int ino; struct vxfs_inode *inode; 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); } strcat (cwd, "/"); if (argv[0][0] == '/') strcpy (cwd, argv[0]); else strcat (cwd, argv[0]); if ((ino = vxlookup (cwd)) < 0) { fprintf (stderr, "%s: Directory %s not found\n", argv0, argv[0]); exit (1); } inode = vxiget (ino); if (inode == 0) { fprintf (stderr, "%s: Cannot get inode %u\n", argv0, ino); exit (1); } if (!VXFS_ISDIR (inode)) { fprintf (stderr, "%s: %s: Not a directory\n", argv0, argv[0]); exit (1); } vxiput (inode); vxsavecwd (device, subpart, cwd); return 0; }