windows-64bit-printf-sanity-20090218
[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 <afsconfig.h>
11 #include <afs/param.h>
12
13 RCSID
14     ("$Header$");
15
16 #include <sys/types.h>
17 #include <sys/stat.h>
18 #include <sys/file.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include "afssyscalls.h"
22 #ifdef AFS_HPUX_ENV
23 #include <sys/mknod.h>
24 #endif
25
26 #include "AFS_component_version_number.c"
27
28 void
29 Usage(void)
30 {
31     printf("Usage: iopen <partition> <inode>\n");
32     printf
33         ("iopen opens file by inode, then tries to read it, printing it to stdout.\n");
34     exit(1);
35 }
36
37 main(argc, argv)
38      char **argv;
39 {
40     char *part;
41     char buf[5];
42     int fd, n;
43     struct stat status;
44     Inode ino;
45
46     if (argc != 3)
47         Usage();
48
49     part = argv[1];
50 #ifdef AFS_64BIT_IOPS_ENV
51     ino = strtoull(argv[2], NULL, 10);
52 #else
53     ino = atoi(argv[2]);
54 #endif
55
56     if (stat(part, &status) == -1) {
57         perror("stat");
58         exit(1);
59     }
60     printf("ino=%" AFS_INT64_FMT "\n", ino);
61     printf("About to iopen(dev=(%d,%d), inode=%s, mode=%d\n",
62            major(status.st_dev), minor(status.st_dev), PrintInode(NULL, ino),
63            O_RDONLY);
64     fflush(stdout);
65     fd = IOPEN(status.st_dev, ino, O_RDONLY);
66     if (fd == -1) {
67         perror("iopen");
68         exit(1);
69     }
70     printf("iopen successful, fd=%d\n", fd);
71     while ((n = read(fd, buf, 5)) > 0)
72         write(1, buf, n);
73     if (n < 0)
74         perror("read");
75     exit(0);
76 }