Make Windows pioctl prototypes consistent with Unix
[openafs.git] / src / sys / fixit.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 /*
11 This utility is used to increase the ref count on inodes moved to
12 lost+found by the non-AFS fsck. The program needs to be run once 
13 for every volume located on the partition that was fsck'ed.
14 Procedure:
15      cc -o fixit fixit.c
16      cd /vicepx
17      chmod 600 *
18      foreach volid ( cat <list-of-vol-ids> )
19        fixit lost+found $volid
20        echo $volid
21      end
22      umount <dev>
23      /etc/vfsck <dev>       <<<< AFS Version!
24
25 Non-AFS fsck causes inodes to be moved to lost+found, with names like
26 #<inode-no>. The volumes associated with these inodes will still be
27 available, until the #<inode-no> file is removed. This program simply
28 ups the ref count on the #<inode-no> files, so they're not returned
29 to the free list when the files are removed from lost+found
30 */
31
32 #include <afsconfig.h>
33 #include <afs/param.h>
34
35
36 #include <sys/types.h>
37 #include <sys/file.h>
38 #include <dirent.h>
39 #include <sys/stat.h>
40 #ifdef AFS_HPUX_ENV
41 #include <sys/mknod.h>
42 #endif
43 #include <afs/afs_args.h>
44 #include <afs/afs.h>
45 #include <afs/afssyscalls.h>
46 #include <errno.h>
47
48 #include "AFS_component_version_number.c"
49
50 main(argc, argv)
51      int argc;
52      char **argv;
53 {
54     DIR *tdir;
55     struct stat ts;
56     afs_int32 dev, code;
57     struct dirent *tde;
58
59     int volid;
60
61     if (geteuid() != 0) {
62         printf("must be run as root; sorry\n");
63         exit(1);
64     }
65     code = stat(argv[1], &ts);
66     if (code) {
67         printf("can't stat %s\n", argv[1]);
68         exit(1);
69     }
70     dev = ts.st_dev;
71     tdir = opendir(argv[1]);
72     if (!tdir) {
73         printf("cant open %s\n", argv[1]);
74         exit(1);
75     }
76     volid = atoi(argv[2]);
77     for (tde = readdir(tdir); tde; tde = readdir(tdir)) {
78         if (tde->d_name[0] == '#') {
79             printf("Inode %d\n", tde->d_ino);
80             code = IINC(dev, tde->d_ino, volid);
81             if (code == -1) {
82                 perror("iinc");
83                 printf("errno = %d\n", errno);
84 /* Remove this -- we don't want to exit, because we have to look
85 *  at each inode -- an error here means only that the iinc failed for
86 *  the current volume
87 *                               exit(1);
88 */
89             } else
90                 printf("inode %d restored for volume %d\n", tde->d_ino,
91                        volid);
92         }
93     }
94     exit(0);
95 }