/* vi:set tabstop=2 shiftwidth=2 cindent: */ /* * libvxfs - library for reading Veritas Journaled FileSystem (VxFS) * Copyright (c) 1999 Martin Hinner * * inode.c: VxFS inode routines * * 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 struct vxfs_inode * vxblkiget (int extent, int ino) { void *block; struct vxfs_inode *inode; block = vxread (extent + ((ino * VXFS_ISIZE) / vxbsize), 1); if (!block) { if (vxverbose) printf ("Unable to read block\n"); return 0; } inode = (struct vxfs_inode *) malloc (sizeof (struct vxfs_inode)); memcpy (inode, (char *) block + ((ino % (vxbsize / VXFS_ISIZE)) * VXFS_ISIZE), sizeof (struct vxfs_inode)); return inode; } struct vxfs_inode * _vxiget (int ino, struct vxfs_inode *ilist) { void *block; struct vxfs_inode *inode; block = vxiread (ilist, (ino * VXFS_ISIZE) / vxbsize, 1); if (!block) { if (vxverbose) printf ("Cannot read block!\n"); return 0; } inode = (struct vxfs_inode *) malloc (sizeof (struct vxfs_inode)); if (!inode) { if (vxverbose) printf ("No mem!\n"); return 0; } memcpy (inode, (char *) block + ((ino % (vxbsize / VXFS_ISIZE)) * VXFS_ISIZE), sizeof (struct vxfs_inode)); free (block); return inode; } struct vxfs_inode * vxiget (int ino) { return _vxiget(ino, vxilistino); } struct vxfs_inode * vxigetstructural (int ino) { return _vxiget(ino, vxstructuralilistino); } void vxiput (struct vxfs_inode *ino) { free (ino); } static struct { int mode; char *name; } itypes[] = { {0, "Unused"}, {VXFS_IFIFO, "Named pipe"}, {VXFS_IFCHR, "Character device"}, {VXFS_IFDIR, "Directory"}, {VXFS_IFNAM, "Xenix device?"}, {VXFS_IFBLK, "Block device"}, {VXFS_IFREG, "Regular file"}, {VXFS_IFCMP, "Compressed file?"}, {VXFS_IFLNK, "Symlink"}, {VXFS_IFSOC, "Socket"}, {VXFS_IFBLK, "Block device"}, {VXFS_IFFSH, "Fileset header"}, {VXFS_IFILT, "Inode list"}, {VXFS_IFIAU, "Inode allocation unit"}, {VXFS_IFCUT, "Current usage table"}, {VXFS_IFATT, "Attr. inode"}, {VXFS_IFLCT, "Link count table"}, {VXFS_IFIAT, "Indirect attribute file"}, {VXFS_IFEMR, "Extent map reorg. file"}, {VXFS_IFQUO, "BSD quota file"}, {VXFS_IFPTI, "\"Pass through\" inode"}, {VXFS_IFLAB, "Device label file"}, {VXFS_IFOLT, "OLT file"}, {VXFS_IFEMP, "Extent map file"}, {VXFS_IFEAU, "Extent AU file"}, {VXFS_IFAUS, "Extent AU summary file"}, {VXFS_IFDEV, "Device config file"}, {0,0} }; void vxidump (struct vxfs_inode *ino) { int i; int flag; printf ("-----Inode dump-----\n"); printf ("mode=%08x ", ino->mode); flag = 0; for (i=0;itypes[i].name;i++) if (itypes[i].mode == (ino->mode & 0xfffff000)) { printf("(%s)\n",itypes[i].name); flag = 1; } if (!flag) printf("(UNKNOWN)\n"); printf ("nlink:%u uid:%u gid:%u\n", ino->nlink, ino->uid, ino->gid); printf ("size=%Lx blocks=%u\n", ino->size, ino->blocks); printf ("atime=%x.%x mtime=%x.%x ctime=%x.%x\n", ino->atime, ino->autime, ino->ctime, ino->cutime, ino->mtime, ino->mutime); printf ("orgtype=%u\n", ino->orgtype); switch (ino->orgtype) { case VXFS_ORG_IMMED: printf("Immed organization:\n"); break; case VXFS_ORG_EXT4: printf ("Ext4 organization:\n"); printf (" indsize = %u\n", ino->org.ext4.indsize); printf (" Direct: "); for (i = 0; i < VXFS_NDADDR; i++) printf ("[%u,%u] ", ino->org.ext4.direct[i].extent, ino->org.ext4.direct[i].size); printf ("\n"); printf (" Indirect: [%u] Double indirect: [%u]\n", ino->org.ext4.indirect, ino->org.ext4.dblindirect); break; case VXFS_ORG_TYPED: printf("Typed organization:\n"); for (i=0;iorg.typed[i].hdr>>VXFS_TYPED_TYPESHIFT)); printf("ofs=0x%lx ",(long long)(ino->org.typed[i].hdr & VXFS_TYPED_OFFSETMASK)); printf("block=0x%x ",ino->org.typed[i].block); printf("size=0x%x]\n", ino->org.typed[i].size); } break; default: printf ("Unknown organization\n"); } }