]> git.ipfire.org Git - thirdparty/mdadm.git/blob - Examine.c
4ed4f6b75c7041bd549913f8b02a42696644a5fc
[thirdparty/mdadm.git] / Examine.c
1 /*
2 * mdctl - manage Linux "md" devices aka RAID arrays.
3 *
4 * Copyright (C) 2001 Neil Brown <neilb@cse.unsw.edu.au>
5 *
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * Author: Neil Brown
22 * Email: <neilb@cse.unsw.edu.au>
23 * Paper: Neil Brown
24 * School of Computer Science and Engineering
25 * The University of New South Wales
26 * Sydney, 2052
27 * Australia
28 */
29
30 #include "mdctl.h"
31
32 #if ! defined(__BIG_ENDIAN) && ! defined(__LITTLE_ENDIAN)
33 #error no endian defined
34 #endif
35 #include "md_u.h"
36 #include "md_p.h"
37 int Examine(char *dev)
38 {
39
40 /* Read the raid superblock from a device and
41 * display important content.
42 *
43 * If cannot be found, print reason: too small, bad magic
44 *
45 * Print:
46 * version, ctime, level, size, raid+spare+
47 * prefered minor
48 * uuid
49 *
50 * utime, state etc
51 *
52 */
53 int fd = open(dev, O_RDONLY);
54 time_t atime;
55 mdp_super_t super;
56 int d;
57 char *c;
58 int rv;
59
60 if (fd < 0) {
61 fprintf(stderr,Name ": cannot open %s: %s\n",
62 dev, strerror(errno));
63 return 1;
64 }
65
66 rv = load_super(fd, &super);
67 close(fd);
68 switch(rv) {
69 case 1:
70 fprintf(stderr, Name ": cannot find device size for %s: %s\n",
71 dev, strerror(errno));
72 return 1;
73 case 2:
74 /* fprintf(stderr, Name ": %s is too small for md: size is %ld sectors\n",
75 dev, size);
76 */
77 fprintf(stderr, Name ": %s is too small for md\n",
78 dev);
79 return 1;
80 case 3:
81 fprintf(stderr, Name ": Cannot seek to superblock on %s: %s\n",
82 dev, strerror(errno));
83 return 1;
84 case 4:
85 fprintf(stderr, Name ": Cannot read superblock on %s\n",
86 dev);
87 return 1;
88 case 5:
89 fprintf(stderr, Name ": No super block found on %s (Expected magic %08x, got %08x)\n",
90 dev, MD_SB_MAGIC, super.md_magic);
91 return 1;
92 case 6:
93 fprintf(stderr, Name ": Cannot interpret superblock on %s - version is %d\n",
94 dev, super.major_version);
95 return 1;
96 }
97
98 /* Ok, its good enough to try, though the checksum could be wrong */
99 printf("%s:\n",dev);
100 printf(" Magic : %08x\n", super.md_magic);
101 printf(" Version : %02d.%02d.%02d\n", super.major_version, super.minor_version,
102 super.patch_version);
103 if (super.minor_version >= 90)
104 printf(" UUID : %08x:%08x:%08x:%08x\n", super.set_uuid0, super.set_uuid1,
105 super.set_uuid2, super.set_uuid3);
106 else
107 printf(" UUID : %08x\n", super.set_uuid0);
108
109 atime = super.ctime;
110 printf(" Creation Time : %.24s\n", ctime(&atime));
111 c=map_num(pers, super.level);
112 printf(" Raid Level : %s\n", c?c:"-unknown-");
113 printf(" Size : %d\n", super.size);
114 printf(" Raid Disks : %d\n", super.raid_disks);
115 printf(" Total Disks : %d\n", super.nr_disks);
116 printf("Preferred Minor : %d\n", super.md_minor);
117 printf("\n");
118 atime = super.utime;
119 printf(" Update Time : %.24s\n", ctime(&atime));
120 printf(" State : %s, %serrors\n",
121 (super.state&(1<<MD_SB_CLEAN))?"clean":"dirty",
122 (super.state&(1<<MD_SB_ERRORS))?"":"no-");
123 printf(" Active Drives : %d\n", super.active_disks);
124 printf(" Working Drives : %d\n", super.working_disks);
125 printf(" Failed Drives : %d\n", super.failed_disks);
126 printf(" Spare Drives : %d\n", super.spare_disks);
127 if (calc_sb_csum(&super) == super.sb_csum)
128 printf(" Checksum : %x - correct\n", super.sb_csum);
129 else
130 printf(" Checksum : %x - expected %x\n", super.sb_csum, calc_sb_csum(&super));
131 printf(" Events : %d.%d\n", super.events_hi, super.events_lo);
132 printf("\n");
133 if (super.level == 5) {
134 c = map_num(r5layout, super.layout);
135 printf(" Layout : %s\n", c?c:"-unknown-");
136 }
137 switch(super.level) {
138 case 0:
139 case 4:
140 case 5:
141 printf(" Chunk Size : %dK\n", super.chunk_size/1024);
142 break;
143 case -1:
144 printf(" Rounding : %dK\n", super.chunk_size/1024);
145 break;
146 default: break;
147 }
148 printf("\n");
149 printf(" Number Major Minor RaidDisk State\n");
150 for (d= -1; d<(signed int)super.nr_disks; d++) {
151 mdp_disk_t *dp;
152 char *dv;
153 char nb[5];
154 if (d>=0) dp = &super.disks[d];
155 else dp = &super.this_disk;
156 sprintf(nb, "%4d", d);
157 printf("%4s %5d %5d %5d %5d ", d < 0 ? "this" : nb,
158 dp->number, dp->major, dp->minor, dp->raid_disk);
159 if (dp->state & (1<<MD_DISK_FAULTY)) printf(" faulty");
160 if (dp->state & (1<<MD_DISK_ACTIVE)) printf(" active");
161 if (dp->state & (1<<MD_DISK_SYNC)) printf(" sync");
162 if (dp->state & (1<<MD_DISK_REMOVED)) printf(" removed");
163 if ((dv=map_dev(dp->major, dp->minor)))
164 printf(" %s", dv);
165 printf("\n");
166 }
167 return 0;
168 }