source: gpfs_3.1_ker2.6.20/lpp/mmfs/samples/util/tsinode.c @ 16

Last change on this file since 16 was 16, checked in by rock, 16 years ago
File size: 8.3 KB
Line 
1/* IBM_PROLOG_BEGIN_TAG                                                   */
2/* This is an automatically generated prolog.                             */
3/*                                                                        */
4/*                                                                        */
5/*                                                                        */
6/* Licensed Materials - Property of IBM                                   */
7/*                                                                        */
8/* (C) COPYRIGHT International Business Machines Corp. 2002,2006          */
9/* All Rights Reserved                                                    */
10/*                                                                        */
11/* US Government Users Restricted Rights - Use, duplication or            */
12/* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.      */
13/*                                                                        */
14/* IBM_PROLOG_END_TAG                                                     */
15
16/*====================================================================
17 *
18 * tsinode command: list all inodes.
19 *
20 * Syntax: tsinode pathname [startinode [endinode]]
21 *
22 *   The "pathname" parameter should be the directory where the root of
23 *   the filesystem/snapshot is found.
24 *
25 *==================================================================*/
26#include <stdlib.h>
27#include <stdio.h>
28#include <errno.h>
29#include <string.h>
30
31#include <gpfs.h>
32
33extern char *basename(char *);
34
35static int headerPrinted = 0;
36/* print usage message and exit */
37static void usage(char *argv0)
38{
39  fprintf(stderr, "Usage: %s pathname [startinode [endinode]]\n", basename(argv0));
40  exit(1);
41}
42
43char *
44pmode(mode_t aflag, char *buf)
45{
46  /* these arrays are declared static to allow initializations */
47  static int      m0[] = { 1, S_IREAD>>0, 'r', '-' };
48  static int      m1[] = { 1, S_IWRITE>>0, 'w', '-' };
49  static int      m2[] = { 3, S_ISUID|S_IEXEC, 's', S_IEXEC, 'x', S_ISUID, 'S', '-' };
50  static int      m3[] = { 1, S_IREAD>>3, 'r', '-' };
51  static int      m4[] = { 1, S_IWRITE>>3, 'w', '-' };
52  static int      m5[] = { 3, S_ISGID|(S_IEXEC>>3), 's',
53                              S_IEXEC>>3, 'x', S_ISGID, 'S', '-' };
54  static int      m6[] = { 1, S_IREAD>>6, 'r', '-' };
55  static int      m7[] = { 1, S_IWRITE>>6, 'w', '-' };
56  static int      m8[] = { 3, S_ISVTX|(S_IEXEC>>6), 't', S_IEXEC>>6, 'x', S_ISVTX, 'T', '-' };
57  static int  *m[] = { m0, m1, m2, m3, m4, m5, m6, m7, m8 };
58
59  int i, j, n;
60  int *p;
61
62  buf[0] = S_ISREG(aflag)?  '-':
63    S_ISDIR(aflag)?  'd':
64    S_ISLNK(aflag)?  'l':
65    S_ISFIFO(aflag)? 'p':
66    S_ISCHR(aflag)?  'c':
67    S_ISBLK(aflag)?  'b':
68    S_ISSOCK(aflag)? 's': '?';
69  for (i = 0; i <= 8; i++)
70  {
71    for (n = m[i][0], j = 1; n > 0; n--, j+=2)
72    {
73      p = m[i];
74      if ((aflag & p[j]) == p[j])
75      {
76        j++;
77        break;
78      }
79    }
80    buf[i+1] = p[j];
81  }
82  buf[10] = '\0';
83  return buf;
84}
85
86#define DevMajor(x) ((unsigned)(x)>>16)
87#define DevMinor(x) ((x)&0xFFFF)
88
89static void
90print_vattr(gpfs_iscan_t *iscanP,
91            const gpfs_iattr_t *iattrP)
92{
93  int rc;
94  long long space;
95  char mbuf[32];
96  char buf[1025];
97  char nbuf[GPFS_MAXNAMLEN+1];
98  char *bufP = buf;
99
100  if (!headerPrinted)
101  {
102    headerPrinted = 1;
103    printf("    inode       gen    uid    gid       size      space     mode nlink      atime               mtime               ctime        flags\n");
104  }
105
106  if (iattrP->ia_flags & GPFS_IAFLAG_ERROR)
107  {
108    printf("%9d Invalid\n", iattrP->ia_inode);
109    return;
110  }
111
112  /* Dump contents of Inode */
113  bufP += sprintf(bufP, "%9d %9d %6d %6d %10lld",
114                  iattrP->ia_inode, iattrP->ia_gen, iattrP->ia_uid,
115                  iattrP->ia_gid, iattrP->ia_size);
116  space = iattrP->ia_blocks * 512;
117  bufP += sprintf(bufP, " %10lld %s", space, pmode(iattrP->ia_mode, mbuf));
118
119  bufP += sprintf(bufP, " %d %9d.%09d %9d.%09d %9d.%09d",
120                  iattrP->ia_nlink,
121                  iattrP->ia_atime.tv_sec, iattrP->ia_atime.tv_nsec,
122                  iattrP->ia_mtime.tv_sec, iattrP->ia_mtime.tv_nsec,
123                  iattrP->ia_ctime.tv_sec, iattrP->ia_ctime.tv_nsec);
124
125  if (S_ISBLK(iattrP->ia_mode)  ||  S_ISCHR(iattrP->ia_mode))
126    bufP += sprintf(bufP, " device=%d,%d",
127                    DevMajor(iattrP->ia_rdev),
128                    DevMinor(iattrP->ia_rdev));
129
130  if (iattrP->ia_blocksize != 262144)
131    bufP += sprintf(bufP, " blk=%d", iattrP->ia_blocksize);
132
133  if (iattrP->ia_modsnapid != 0)
134    bufP += sprintf(bufP, " modsnap=%d", iattrP->ia_modsnapid);
135
136  if (iattrP->ia_xperm)
137  {
138    bufP += sprintf(bufP, " extperms=0x%X", iattrP->ia_xperm);
139    if (iattrP->ia_xperm & GPFS_IAXPERM_ACL)
140      bufP += sprintf(bufP, ",acl");
141    if (iattrP->ia_xperm & GPFS_IAXPERM_XATTR)
142      bufP += sprintf(bufP, ",xa");
143    if (iattrP->ia_xperm & GPFS_IAXPERM_DMATTR)
144      bufP += sprintf(bufP, ",dm");
145    if (iattrP->ia_xperm & GPFS_IAXPERM_DOSATTR)
146      bufP += sprintf(bufP, ",dos");
147    if (iattrP->ia_xperm & GPFS_IAXPERM_RPATTR)
148      bufP += sprintf(bufP, ",rp");
149  }
150
151  if (iattrP->ia_flags & GPFS_IAFLAG_USRQUOTA)
152    bufP += sprintf(bufP, " userquota");
153  if (iattrP->ia_flags & GPFS_IAFLAG_GRPQUOTA)
154    bufP += sprintf(bufP, " groupquota");
155
156  if (iattrP->ia_flags & GPFS_IAFLAG_REPLMETA)
157    bufP += sprintf(bufP, " replmeta");
158  if (iattrP->ia_flags & GPFS_IAFLAG_REPLDATA)
159    bufP += sprintf(bufP, " repldata");
160
161  if (iattrP->ia_flags & GPFS_IAFLAG_EXPOSED)
162    bufP += sprintf(bufP, " exposed");
163  if (iattrP->ia_flags & GPFS_IAFLAG_ILLREPLICATED)
164    bufP += sprintf(bufP, " illReplicated");
165  if (iattrP->ia_flags & GPFS_IAFLAG_UNBALANCED)
166    bufP += sprintf(bufP, " unbalanced");
167  if (iattrP->ia_flags & GPFS_IAFLAG_DATAUPDATEMISS)
168    bufP += sprintf(bufP, " dataUpdateMiss");
169  if (iattrP->ia_flags & GPFS_IAFLAG_METAUPDATEMISS)
170    bufP += sprintf(bufP, " metaUpdateMiss");
171  if (iattrP->ia_flags & GPFS_IAFLAG_ILLPLACED)
172    bufP += sprintf(bufP, " illPlaced");
173  if (iattrP->ia_flags & GPFS_IAFLAG_COMANAGED)
174    bufP += sprintf(bufP, " coManaged");
175
176  rc = gpfs_igetfilesetname(iscanP, iattrP->ia_filesetid,
177                            nbuf, sizeof(nbuf));
178  if (rc != 0)
179  {
180    rc = errno;
181    bufP += sprintf(bufP, " gpfs_igetfilesetname:%s", strerror(rc));
182  }
183  else if (strlen(nbuf) > 0 && strcmp(nbuf,"root") != 0)
184    bufP += sprintf(bufP, " fileset=%s", nbuf);
185
186  rc = gpfs_igetstoragepool(iscanP, iattrP->ia_datapoolid,
187                            nbuf, sizeof(nbuf));
188  if (rc != 0)
189  {
190    rc = errno;
191    bufP += sprintf(bufP, " gpfs_igetstoragepool:%s", strerror(rc));
192  }
193  else if (strcmp(nbuf,"system") != 0)
194    bufP += sprintf(bufP, " datapool='%s'", nbuf);
195
196  printf("%s\n", buf);
197}
198
199static int read_inodes(const char *fnameP,
200                       gpfs_ino_t startinode, gpfs_ino_t endinode)
201{
202  int rc = 0;
203  const gpfs_iattr_t *iattrP;
204  gpfs_iscan_t *iscanP = NULL;
205  gpfs_fssnap_handle_t *fsP = NULL;
206
207  fsP = gpfs_get_fssnaphandle_by_path(fnameP);
208  if (fsP == NULL)
209  {
210    rc = errno;
211    fprintf(stderr, "gpfs_get_fshandle_by_path: %s\n", strerror(rc));
212    goto exit;
213  }
214
215  iscanP = gpfs_open_inodescan(fsP, NULL, NULL);
216  if (iscanP == NULL)
217  {
218    rc = errno;
219    fprintf(stderr, "gpfs_open_inodescan: %s\n", strerror(rc));
220    goto exit;
221  }
222
223  if (startinode > 0)
224  {
225    rc = gpfs_seek_inode(iscanP, startinode);
226    if (rc != 0)
227    {
228      rc = errno;
229      fprintf(stderr, "gpfs_seek_inode: %s\n", strerror(rc));
230      goto exit;
231    }
232  }
233
234  while (1)
235  {
236    rc = gpfs_next_inode(iscanP, endinode, &iattrP);
237    if (rc != 0)
238    {
239      rc = errno;
240      fprintf(stderr, "gpfs_next_inode: %s\n", strerror(rc));
241      goto exit;
242    }
243    if ((iattrP == NULL) ||
244        (iattrP->ia_inode > endinode))
245      break;
246
247    print_vattr(iscanP, iattrP);
248  }
249
250exit:
251  if (iscanP)
252    gpfs_close_inodescan(iscanP);
253  if (fsP)
254    gpfs_free_fssnaphandle(fsP);
255
256  return rc;
257}
258
259/* main */
260int main(int argc, char *argv[])
261{
262  int rc;
263  gpfs_ino_t startinode = 0;
264  gpfs_ino_t endinode = 0x7FFFFFFF;
265
266  /* if no files were specified, there is nothing to do */
267  if (argc < 2 || argc > 4)
268    usage(argv[0]);
269
270  if (argc > 2)
271  {
272    startinode = (gpfs_ino_t) atoi(argv[2]);
273    if (startinode < 0)
274      startinode = 0;
275  }
276  if (argc > 3)
277  {
278    endinode = (gpfs_ino_t) atoi(argv[3]);
279    if (endinode < 0)
280      endinode = 0x7FFFFFFF;
281  }
282
283  rc = read_inodes(argv[1], startinode, endinode);
284  return rc;
285}
Note: See TracBrowser for help on using the repository browser.