]>
Commit | Line | Data |
---|---|---|
64c4757e NB |
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 | #include "md_u.h" | |
33 | #include "md_p.h" | |
34 | int Examine(char *dev) | |
35 | { | |
36 | ||
37 | /* Read the raid superblock from a device and | |
38 | * display important content. | |
39 | * | |
40 | * If cannot be found, print reason: too small, bad magic | |
41 | * | |
42 | * Print: | |
43 | * version, ctime, level, size, raid+spare+ | |
44 | * prefered minor | |
45 | * uuid | |
46 | * | |
47 | * utime, state etc | |
48 | * | |
49 | */ | |
50 | int fd = open(dev, O_RDONLY, 0); | |
51 | time_t atime; | |
52 | mdp_super_t super; | |
53 | int d; | |
54 | int rv; | |
55 | ||
56 | if (fd < 0) { | |
57 | fprintf(stderr,"mdctl: cannot open %s: %s\n", | |
58 | dev, strerror(errno)); | |
59 | return 1; | |
60 | } | |
61 | ||
62 | rv = load_super(fd, &super); | |
63 | close(fd); | |
64 | switch(rv) { | |
65 | case 1: | |
66 | fprintf(stderr, "mdctl: cannot find device size for %s: %s\n", | |
67 | dev, strerror(errno)); | |
68 | return 1; | |
69 | case 2: | |
70 | /* fprintf(stderr, "mdctl: %s is too small for md: size is %ld sectors\n", | |
71 | dev, size); | |
72 | */ | |
73 | fprintf(stderr, "mdctl: %s is too small for md\n", | |
74 | dev); | |
75 | return 1; | |
76 | case 3: | |
77 | fprintf(stderr, "mdctl: Cannot seek to superblock on %s: %s\n", | |
78 | dev, strerror(errno)); | |
79 | return 1; | |
80 | case 4: | |
81 | fprintf(stderr, "mdctl: Cannot read superblock on %s\n", | |
82 | dev); | |
83 | return 1; | |
84 | case 5: | |
85 | fprintf(stderr, "mdctl: No super block found on %s (Expected magic %08x, got %08x)\n", | |
86 | dev, MD_SB_MAGIC, super.md_magic); | |
87 | return 1; | |
88 | case 6: | |
89 | fprintf(stderr, "mdctl: Cannot interpret superblock on %s - version is %d\n", | |
90 | dev, super.major_version); | |
91 | return 1; | |
92 | } | |
93 | ||
94 | /* Ok, its good enough to try, though the checksum could be wrong */ | |
95 | printf("%s:\n",dev); | |
96 | printf(" Magic : %08x\n", super.md_magic); | |
97 | printf(" Version : %02d.%02d.%02d\n", super.major_version, super.minor_version, | |
98 | super.patch_version); | |
99 | if (super.minor_version >= 90) | |
100 | printf(" UUID : %08x:%08x:%08x:%08x\n", super.set_uuid0, super.set_uuid1, | |
101 | super.set_uuid2, super.set_uuid3); | |
102 | else | |
103 | printf(" UUID : %08x\n", super.set_uuid0); | |
104 | ||
105 | atime = super.ctime; | |
106 | printf(" Creation Time : %.24s\n", ctime(&atime)); | |
107 | printf(" Raid Level : %d\n", super.level); | |
108 | printf(" Size : %d\n", super.size); | |
109 | printf(" Raid Disks : %d\n", super.raid_disks); | |
110 | printf(" Total Disks : %d\n", super.nr_disks); | |
111 | printf("Preferred Minor : %d\n", super.md_minor); | |
112 | printf("\n"); | |
113 | atime = super.utime; | |
114 | printf(" Update Time : %.24s\n", ctime(&atime)); | |
115 | printf(" State : %s, %serrors\n", | |
116 | (super.state&(1<<MD_SB_CLEAN))?"clean":"dirty", | |
117 | (super.state&(1<<MD_SB_ERRORS))?"":"no-"); | |
118 | printf(" Active Drives : %d\n", super.active_disks); | |
119 | printf(" Working Drives : %d\n", super.working_disks); | |
120 | printf(" Failed Drives : %d\n", super.failed_disks); | |
121 | printf(" Spare Drives : %d\n", super.spare_disks); | |
122 | printf(" - checksum not checked yet - \n"); | |
123 | printf(" Events : %d.%d\n", super.events_hi, super.events_lo); | |
124 | printf("\n"); | |
125 | printf(" Layout : %d\n", super.layout); | |
126 | printf(" Chunk Size : %dK\n", super.chunk_size/1024); | |
127 | printf("\n"); | |
128 | printf(" Number Major Minor RaidDisk State\n"); | |
129 | for (d= -1; d<(signed int)super.nr_disks; d++) { | |
130 | mdp_disk_t *dp; | |
131 | char nb[5]; | |
132 | if (d>=0) dp = &super.disks[d]; | |
133 | else dp = &super.this_disk; | |
134 | sprintf(nb, "%4d", d); | |
135 | printf("%4s %5d %5d %5d %5d ", d < 0 ? "this" : nb, | |
136 | dp->number, dp->major, dp->minor, dp->raid_disk); | |
137 | if (dp->state & (1<<MD_DISK_FAULTY)) printf(" faulty"); | |
138 | if (dp->state & (1<<MD_DISK_ACTIVE)) printf(" active"); | |
139 | if (dp->state & (1<<MD_DISK_SYNC)) printf(" sync"); | |
140 | if (dp->state & (1<<MD_DISK_REMOVED)) printf(" removed"); | |
141 | printf("\n"); | |
142 | } | |
143 | return 0; | |
144 | } |