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