afsconfig-and-rcsid-all-around-20010705
[openafs.git] / src / sys / iopen.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afs/param.h>
11 #include <afsconfig.h>
12
13 RCSID("$Header$");
14
15 #include <sys/types.h>
16 #include <sys/stat.h>
17 #include <sys/file.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include "afssyscalls.h"
21 #ifdef AFS_HPUX_ENV
22 #include <sys/mknod.h>
23 #endif
24
25 #include "AFS_component_version_number.c"
26
27 void Usage(void)
28 {
29     printf("Usage: iopen <partition> <inode>\n");
30     printf("iopen opens file by inode, then tries to read it, printing it to stdout.\n");
31     exit(1);
32 }
33
34 main(argc,argv)
35 char **argv;
36 {
37     char *part;
38     char buf[5];
39     int fd,n;
40     struct stat status;
41     Inode ino;
42
43     if (argc != 3) Usage();
44
45     part = argv[1];
46 #ifdef AFS_64BIT_IOPS_ENV
47     ino = strtoull(argv[2], NULL, 10);
48 #else
49     ino = atoi(argv[2]);
50 #endif
51
52     if (stat(part, &status) == -1) {
53         perror("stat");
54         exit(1);
55     }
56     printf("ino=%lld\n", ino);
57     printf("About to iopen(dev=(%d,%d), inode=%s, mode=%d\n",
58         major(status.st_dev), minor(status.st_dev), PrintInode(NULL, ino),
59            O_RDONLY);
60     fflush(stdout);
61     fd = IOPEN(status.st_dev, ino, O_RDONLY);
62     if (fd == -1) {
63         perror("iopen");
64         exit(1);
65     }
66     printf("iopen successful, fd=%d\n", fd);
67     while ((n = read(fd, buf, 5)) > 0)
68         write(1,buf,n);
69     if (n<0)
70         perror("read");
71     exit(0);
72 }