]>
git.ipfire.org Git - thirdparty/mdadm.git/blob - Examine.c
961d60ed2c6ea62cd186a7846e97b4f52a1d602d
2 * mdadm - manage Linux "md" devices aka RAID arrays.
4 * Copyright (C) 2001-2002 Neil Brown <neilb@cse.unsw.edu.au>
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.
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.
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
22 * Email: <neilb@cse.unsw.edu.au>
24 * School of Computer Science and Engineering
25 * The University of New South Wales
33 #if ! defined(__BIG_ENDIAN) && ! defined(__LITTLE_ENDIAN)
34 #error no endian defined
38 int Examine(mddev_dev_t devlist
, int brief
, int scan
)
41 /* Read the raid superblock from a device and
42 * display important content.
44 * If cannot be found, print reason: too small, bad magic
47 * version, ctime, level, size, raid+spare+
53 * If (brief) gather devices for same array and just print a mdadm.conf line including devices=
54 * if devlist==NULL, use conf_get_devs(
70 for (; devlist
; devlist
=devlist
->next
) {
71 fd
= open(devlist
->devname
, O_RDONLY
);
74 fprintf(stderr
,Name
": cannot open %s: %s\n",
75 devlist
->devname
, strerror(errno
));
79 err
= load_super(fd
, &super
);
82 if (err
&& (brief
||scan
))
87 fprintf(stderr
, Name
": cannot find device size for %s: %s\n",
88 devlist
->devname
, strerror(errno
));
91 /* fprintf(stderr, Name ": %s is too small for md: size is %ld sectors\n",
92 devlist->devname, size);
94 fprintf(stderr
, Name
": %s is too small for md\n",
98 fprintf(stderr
, Name
": Cannot seek to superblock on %s: %s\n",
99 devlist
->devname
, strerror(errno
));
102 fprintf(stderr
, Name
": Cannot read superblock on %s\n",
106 fprintf(stderr
, Name
": No super block found on %s (Expected magic %08x, got %08x)\n",
107 devlist
->devname
, MD_SB_MAGIC
, super
.md_magic
);
110 fprintf(stderr
, Name
": Cannot interpret superblock on %s - version is %d\n",
111 devlist
->devname
, super
.major_version
);
115 /* Ok, its good enough to try, though the checksum could be wrong */
119 for (ap
=arrays
; ap
; ap
=ap
->next
) {
120 if (compare_super(&ap
->super
, &super
)==0)
124 ap
= malloc(sizeof(*ap
));
126 ap
->devs
= dl_head();
130 d
= dl_strdup(devlist
->devname
);
133 printf("%s:\n",devlist
->devname
);
134 printf(" Magic : %08x\n", super
.md_magic
);
135 printf(" Version : %02d.%02d.%02d\n", super
.major_version
, super
.minor_version
,
136 super
.patch_version
);
137 if (super
.minor_version
>= 90)
138 printf(" UUID : %08x:%08x:%08x:%08x\n", super
.set_uuid0
, super
.set_uuid1
,
139 super
.set_uuid2
, super
.set_uuid3
);
141 printf(" UUID : %08x\n", super
.set_uuid0
);
144 printf(" Creation Time : %.24s\n", ctime(&atime
));
145 c
=map_num(pers
, super
.level
);
146 printf(" Raid Level : %s\n", c
?c
:"-unknown-");
147 printf(" Device Size : %d%s\n", super
.size
, human_size((long long)super
.size
<<10));
148 printf(" Raid Disks : %d\n", super
.raid_disks
);
149 printf(" Total Disks : %d\n", super
.nr_disks
);
150 printf("Preferred Minor : %d\n", super
.md_minor
);
153 printf(" Update Time : %.24s\n", ctime(&atime
));
154 printf(" State : %s, %serrors\n",
155 (super
.state
&(1<<MD_SB_CLEAN
))?"clean":"dirty",
156 (super
.state
&(1<<MD_SB_ERRORS
))?"":"no-");
157 printf(" Active Drives : %d\n", super
.active_disks
);
158 printf(" Working Drives : %d\n", super
.working_disks
);
159 printf(" Failed Drives : %d\n", super
.failed_disks
);
160 printf(" Spare Drives : %d\n", super
.spare_disks
);
161 if (calc_sb_csum(&super
) == super
.sb_csum
)
162 printf(" Checksum : %x - correct\n", super
.sb_csum
);
164 printf(" Checksum : %x - expected %x\n", super
.sb_csum
, calc_sb_csum(&super
));
165 printf(" Events : %d.%d\n", super
.events_hi
, super
.events_lo
);
167 if (super
.level
== 5) {
168 c
= map_num(r5layout
, super
.layout
);
169 printf(" Layout : %s\n", c
?c
:"-unknown-");
171 switch(super
.level
) {
175 printf(" Chunk Size : %dK\n", super
.chunk_size
/1024);
178 printf(" Rounding : %dK\n", super
.chunk_size
/1024);
183 printf(" Number Major Minor RaidDisk State\n");
184 for (d
= -1; d
<(signed int)(super
.raid_disks
+super
.spare_disks
); d
++) {
188 if (d
>=0) dp
= &super
.disks
[d
];
189 else dp
= &super
.this_disk
;
190 sprintf(nb
, "%4d", d
);
191 printf("%4s %5d %5d %5d %5d ", d
< 0 ? "this" : nb
,
192 dp
->number
, dp
->major
, dp
->minor
, dp
->raid_disk
);
193 if (dp
->state
& (1<<MD_DISK_FAULTY
)) printf(" faulty");
194 if (dp
->state
& (1<<MD_DISK_ACTIVE
)) printf(" active");
195 if (dp
->state
& (1<<MD_DISK_SYNC
)) printf(" sync");
196 if (dp
->state
& (1<<MD_DISK_REMOVED
)) printf(" removed");
197 if ((dv
=map_dev(dp
->major
, dp
->minor
)))
205 for (ap
=arrays
; ap
; ap
=ap
->next
) {
207 char *c
=map_num(pers
, ap
->super
.level
);
209 printf("ARRAY /dev/md%d level=%s disks=%d UUID=",
210 ap
->super
.md_minor
, c
?c
:"-unknown-", ap
->super
.raid_disks
);
211 if (ap
->super
.minor_version
>= 90)
212 printf("%08x:%08x:%08x:%08x", ap
->super
.set_uuid0
, ap
->super
.set_uuid1
,
213 ap
->super
.set_uuid2
, ap
->super
.set_uuid3
);
215 printf("%08x", ap
->super
.set_uuid0
);
216 printf("\n devices");
217 for (d
=dl_next(ap
->devs
); d
!= ap
->devs
; d
=dl_next(d
)) {
218 printf("%c%s", sep
, d
);