death to trailing whitespace
[openafs.git] / src / viced / check_sysid.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 /*  check_sysid.c     - Verify and display the sysid file.               */
11 /*  Date: 10/21/97                                                       */
12 /*                                                                       */
13 /* ********************************************************************* */
14
15 #include <afsconfig.h>
16 #include <afs/param.h>
17
18
19 #include <fcntl.h>
20 #include <errno.h>
21 #include <afs/vldbint.h>
22
23 #define SYSIDMAGIC      0x88aabbcc
24 #define SYSIDVERSION    1
25
26 struct versionStamp {           /* Stolen from <afs/volume.h> */
27     int magic;
28     int version;
29 };
30
31 int
32 main(int argc, char **argv)
33 {
34     int fd, size, i;
35
36     struct versionStamp vs;
37     afsUUID uuid;
38     int nentries;
39     int addr;
40
41     if ((argc != 2) || (strcmp(argv[1], "-h") == 0)) {
42         printf("Usage: check_sysid <sysid_file>\n");
43         exit((argc != 2) ? 1 : 0);
44     }
45
46     fd = open(argv[1], O_RDONLY, 0);
47     if (fd < 0) {
48         printf("Unable to open file '%s'. Errno = %d\n", argv[1], errno);
49         exit(2);
50     }
51
52     /* Read the Version Stamp */
53     size = read(fd, (char *)&vs, sizeof(vs));
54     if (size != sizeof(vs)) {
55         printf("Unable to read versionStamp. Size = %d. Errno = %d\n", size,
56                errno);
57     }
58     printf("versionStamp.magic   = 0x%x %s\n", vs.magic,
59            (vs.magic == SYSIDMAGIC) ? "" : "(should be 0x88aabbc)");
60     printf("versionStamp.version = 0x%x %s\n", vs.version,
61            (vs.version == SYSIDVERSION) ? "" : "(should be 0x1)");
62
63     /* Read the uuid.
64      * Look at util/uuid.c afs_uuid_create() to see how it is created.
65      */
66     size = read(fd, (char *)&uuid, sizeof(uuid));
67     if (size != sizeof(uuid)) {
68         printf("Unable to read afsUUID. Size = %d. Errno = %d\n", size,
69                errno);
70         exit(3);
71     }
72     printf("UUID.time(hi.mid.low)= 0x%03x.%04x.%08x\n",
73            uuid.time_hi_and_version & 0x0fff, uuid.time_mid & 0xffff,
74            uuid.time_low);
75     printf("UUID.version         = %d (0x%01x)\n",
76            (uuid.time_hi_and_version >> 12) & 0xf,
77            (uuid.time_hi_and_version >> 12) & 0xf);
78     printf("UUID.clock(hi.low)   = 0x%02x.%02x\n",
79            uuid.clock_seq_hi_and_reserved & 0x3f, uuid.clock_seq_low & 0xff);
80     printf("UUID.reserved        = %d (0x%02x)\n",
81            (uuid.clock_seq_hi_and_reserved >> 6) & 0x3,
82            (uuid.clock_seq_hi_and_reserved >> 6) & 0x3);
83     printf("UUID.node            = %02x.%02x.%02x.%02x.%02x.%02x\n",
84            uuid.node[0] & 0xff, uuid.node[1] & 0xff, uuid.node[2] & 0xff,
85            uuid.node[3] & 0xff, uuid.node[4] & 0xff, uuid.node[5] & 0xff);
86
87     /* Read the number of addresses recorded in the sysid */
88     size = read(fd, (char *)&nentries, sizeof(int));
89     if (size != sizeof(int)) {
90         printf("Unable to read nentries. Size = %d. Errno = %d\n", size,
91                errno);
92         exit(4);
93     }
94     printf("Number of addreses   = %d (0x%x)\n", nentries, nentries);
95
96     /* Now read in each of the addresses */
97     for (i = 0; i < nentries; i++) {
98         size = read(fd, (char *)&addr, sizeof(int));
99         if (size != sizeof(int)) {
100             printf("Unable to read IP Address %d. Size = %d. Errno = %d\n",
101                    i + 1, size, errno);
102             exit(5);
103         }
104         printf("Address              = %d.%d.%d.%d (0x%x)\n",
105                (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff,
106                (addr) & 0xff, addr);
107     }
108
109     close(fd);
110     return 0;
111 }