/* IBM_PROLOG_BEGIN_TAG */ /* This is an automatically generated prolog. */ /* */ /* */ /* */ /* Licensed Materials - Property of IBM */ /* */ /* (C) COPYRIGHT International Business Machines Corp. 2002,2006 */ /* All Rights Reserved */ /* */ /* US Government Users Restricted Rights - Use, duplication or */ /* disclosure restricted by GSA ADP Schedule Contract with IBM Corp. */ /* */ /* IBM_PROLOG_END_TAG */ /*==================================================================== * * tsinode command: list all inodes. * * Syntax: tsinode pathname [startinode [endinode]] * * The "pathname" parameter should be the directory where the root of * the filesystem/snapshot is found. * *==================================================================*/ #include #include #include #include #include extern char *basename(char *); static int headerPrinted = 0; /* print usage message and exit */ static void usage(char *argv0) { fprintf(stderr, "Usage: %s pathname [startinode [endinode]]\n", basename(argv0)); exit(1); } char * pmode(mode_t aflag, char *buf) { /* these arrays are declared static to allow initializations */ static int m0[] = { 1, S_IREAD>>0, 'r', '-' }; static int m1[] = { 1, S_IWRITE>>0, 'w', '-' }; static int m2[] = { 3, S_ISUID|S_IEXEC, 's', S_IEXEC, 'x', S_ISUID, 'S', '-' }; static int m3[] = { 1, S_IREAD>>3, 'r', '-' }; static int m4[] = { 1, S_IWRITE>>3, 'w', '-' }; static int m5[] = { 3, S_ISGID|(S_IEXEC>>3), 's', S_IEXEC>>3, 'x', S_ISGID, 'S', '-' }; static int m6[] = { 1, S_IREAD>>6, 'r', '-' }; static int m7[] = { 1, S_IWRITE>>6, 'w', '-' }; static int m8[] = { 3, S_ISVTX|(S_IEXEC>>6), 't', S_IEXEC>>6, 'x', S_ISVTX, 'T', '-' }; static int *m[] = { m0, m1, m2, m3, m4, m5, m6, m7, m8 }; int i, j, n; int *p; buf[0] = S_ISREG(aflag)? '-': S_ISDIR(aflag)? 'd': S_ISLNK(aflag)? 'l': S_ISFIFO(aflag)? 'p': S_ISCHR(aflag)? 'c': S_ISBLK(aflag)? 'b': S_ISSOCK(aflag)? 's': '?'; for (i = 0; i <= 8; i++) { for (n = m[i][0], j = 1; n > 0; n--, j+=2) { p = m[i]; if ((aflag & p[j]) == p[j]) { j++; break; } } buf[i+1] = p[j]; } buf[10] = '\0'; return buf; } #define DevMajor(x) ((unsigned)(x)>>16) #define DevMinor(x) ((x)&0xFFFF) static void print_vattr(gpfs_iscan_t *iscanP, const gpfs_iattr_t *iattrP) { int rc; long long space; char mbuf[32]; char buf[1025]; char nbuf[GPFS_MAXNAMLEN+1]; char *bufP = buf; if (!headerPrinted) { headerPrinted = 1; printf(" inode gen uid gid size space mode nlink atime mtime ctime flags\n"); } if (iattrP->ia_flags & GPFS_IAFLAG_ERROR) { printf("%9d Invalid\n", iattrP->ia_inode); return; } /* Dump contents of Inode */ bufP += sprintf(bufP, "%9d %9d %6d %6d %10lld", iattrP->ia_inode, iattrP->ia_gen, iattrP->ia_uid, iattrP->ia_gid, iattrP->ia_size); space = iattrP->ia_blocks * 512; bufP += sprintf(bufP, " %10lld %s", space, pmode(iattrP->ia_mode, mbuf)); bufP += sprintf(bufP, " %d %9d.%09d %9d.%09d %9d.%09d", iattrP->ia_nlink, iattrP->ia_atime.tv_sec, iattrP->ia_atime.tv_nsec, iattrP->ia_mtime.tv_sec, iattrP->ia_mtime.tv_nsec, iattrP->ia_ctime.tv_sec, iattrP->ia_ctime.tv_nsec); if (S_ISBLK(iattrP->ia_mode) || S_ISCHR(iattrP->ia_mode)) bufP += sprintf(bufP, " device=%d,%d", DevMajor(iattrP->ia_rdev), DevMinor(iattrP->ia_rdev)); if (iattrP->ia_blocksize != 262144) bufP += sprintf(bufP, " blk=%d", iattrP->ia_blocksize); if (iattrP->ia_modsnapid != 0) bufP += sprintf(bufP, " modsnap=%d", iattrP->ia_modsnapid); if (iattrP->ia_xperm) { bufP += sprintf(bufP, " extperms=0x%X", iattrP->ia_xperm); if (iattrP->ia_xperm & GPFS_IAXPERM_ACL) bufP += sprintf(bufP, ",acl"); if (iattrP->ia_xperm & GPFS_IAXPERM_XATTR) bufP += sprintf(bufP, ",xa"); if (iattrP->ia_xperm & GPFS_IAXPERM_DMATTR) bufP += sprintf(bufP, ",dm"); if (iattrP->ia_xperm & GPFS_IAXPERM_DOSATTR) bufP += sprintf(bufP, ",dos"); if (iattrP->ia_xperm & GPFS_IAXPERM_RPATTR) bufP += sprintf(bufP, ",rp"); } if (iattrP->ia_flags & GPFS_IAFLAG_USRQUOTA) bufP += sprintf(bufP, " userquota"); if (iattrP->ia_flags & GPFS_IAFLAG_GRPQUOTA) bufP += sprintf(bufP, " groupquota"); if (iattrP->ia_flags & GPFS_IAFLAG_REPLMETA) bufP += sprintf(bufP, " replmeta"); if (iattrP->ia_flags & GPFS_IAFLAG_REPLDATA) bufP += sprintf(bufP, " repldata"); if (iattrP->ia_flags & GPFS_IAFLAG_EXPOSED) bufP += sprintf(bufP, " exposed"); if (iattrP->ia_flags & GPFS_IAFLAG_ILLREPLICATED) bufP += sprintf(bufP, " illReplicated"); if (iattrP->ia_flags & GPFS_IAFLAG_UNBALANCED) bufP += sprintf(bufP, " unbalanced"); if (iattrP->ia_flags & GPFS_IAFLAG_DATAUPDATEMISS) bufP += sprintf(bufP, " dataUpdateMiss"); if (iattrP->ia_flags & GPFS_IAFLAG_METAUPDATEMISS) bufP += sprintf(bufP, " metaUpdateMiss"); if (iattrP->ia_flags & GPFS_IAFLAG_ILLPLACED) bufP += sprintf(bufP, " illPlaced"); if (iattrP->ia_flags & GPFS_IAFLAG_COMANAGED) bufP += sprintf(bufP, " coManaged"); rc = gpfs_igetfilesetname(iscanP, iattrP->ia_filesetid, nbuf, sizeof(nbuf)); if (rc != 0) { rc = errno; bufP += sprintf(bufP, " gpfs_igetfilesetname:%s", strerror(rc)); } else if (strlen(nbuf) > 0 && strcmp(nbuf,"root") != 0) bufP += sprintf(bufP, " fileset=%s", nbuf); rc = gpfs_igetstoragepool(iscanP, iattrP->ia_datapoolid, nbuf, sizeof(nbuf)); if (rc != 0) { rc = errno; bufP += sprintf(bufP, " gpfs_igetstoragepool:%s", strerror(rc)); } else if (strcmp(nbuf,"system") != 0) bufP += sprintf(bufP, " datapool='%s'", nbuf); printf("%s\n", buf); } static int read_inodes(const char *fnameP, gpfs_ino_t startinode, gpfs_ino_t endinode) { int rc = 0; const gpfs_iattr_t *iattrP; gpfs_iscan_t *iscanP = NULL; gpfs_fssnap_handle_t *fsP = NULL; fsP = gpfs_get_fssnaphandle_by_path(fnameP); if (fsP == NULL) { rc = errno; fprintf(stderr, "gpfs_get_fshandle_by_path: %s\n", strerror(rc)); goto exit; } iscanP = gpfs_open_inodescan(fsP, NULL, NULL); if (iscanP == NULL) { rc = errno; fprintf(stderr, "gpfs_open_inodescan: %s\n", strerror(rc)); goto exit; } if (startinode > 0) { rc = gpfs_seek_inode(iscanP, startinode); if (rc != 0) { rc = errno; fprintf(stderr, "gpfs_seek_inode: %s\n", strerror(rc)); goto exit; } } while (1) { rc = gpfs_next_inode(iscanP, endinode, &iattrP); if (rc != 0) { rc = errno; fprintf(stderr, "gpfs_next_inode: %s\n", strerror(rc)); goto exit; } if ((iattrP == NULL) || (iattrP->ia_inode > endinode)) break; print_vattr(iscanP, iattrP); } exit: if (iscanP) gpfs_close_inodescan(iscanP); if (fsP) gpfs_free_fssnaphandle(fsP); return rc; } /* main */ int main(int argc, char *argv[]) { int rc; gpfs_ino_t startinode = 0; gpfs_ino_t endinode = 0x7FFFFFFF; /* if no files were specified, there is nothing to do */ if (argc < 2 || argc > 4) usage(argv[0]); if (argc > 2) { startinode = (gpfs_ino_t) atoi(argv[2]); if (startinode < 0) startinode = 0; } if (argc > 3) { endinode = (gpfs_ino_t) atoi(argv[3]); if (endinode < 0) endinode = 0x7FFFFFFF; } rc = read_inodes(argv[1], startinode, endinode); return rc; }