]> git.ipfire.org Git - thirdparty/mdadm.git/blob - Examine.c
Separate sueprblock handling into separate file
[thirdparty/mdadm.git] / Examine.c
1 /*
2 * mdadm - manage Linux "md" devices aka RAID arrays.
3 *
4 * Copyright (C) 2001-2002 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 "mdadm.h"
31 #include "dlink.h"
32
33 #if ! defined(__BIG_ENDIAN) && ! defined(__LITTLE_ENDIAN)
34 #error no endian defined
35 #endif
36 #include "md_u.h"
37 #include "md_p.h"
38 int Examine(mddev_dev_t devlist, int brief, int scan, int SparcAdjust)
39 {
40
41 /* Read the raid superblock from a device and
42 * display important content.
43 *
44 * If cannot be found, print reason: too small, bad magic
45 *
46 * Print:
47 * version, ctime, level, size, raid+spare+
48 * prefered minor
49 * uuid
50 *
51 * utime, state etc
52 *
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(
55 */
56 int fd;
57 void *super = NULL;
58 int rv = 0;
59 int err;
60
61 struct array {
62 void *super;
63 struct mdinfo info;
64 void *devs;
65 struct array *next;
66 int spares;
67 } *arrays = NULL;
68
69 for (; devlist ; devlist=devlist->next) {
70 fd = open(devlist->devname, O_RDONLY);
71 if (fd < 0) {
72 if (!scan)
73 fprintf(stderr,Name ": cannot open %s: %s\n",
74 devlist->devname, strerror(errno));
75 err = 1;
76 }
77 else {
78 err = load_super0(fd, &super, (brief||scan)?NULL:devlist->devname);
79 close(fd);
80 }
81 if (err)
82 continue;
83 if (err) rv =1;
84
85 if (SparcAdjust)
86 update_super0(NULL, super, "sparc2.2", devlist->devname, 0);
87 /* Ok, its good enough to try, though the checksum could be wrong */
88 if (brief) {
89 struct array *ap;
90 char *d;
91 for (ap=arrays; ap; ap=ap->next) {
92 if (compare_super0(&ap->super, super)==0)
93 break;
94 }
95 if (!ap) {
96 ap = malloc(sizeof(*ap));
97 ap->super = super;
98 ap->devs = dl_head();
99 ap->next = arrays;
100 ap->spares = 0;
101 arrays = ap;
102 getinfo_super0(&ap->info, super);
103 } else {
104 getinfo_super0(&ap->info, super);
105 free(super);
106 }
107 if (!(ap->info.disk.state & MD_DISK_SYNC))
108 ap->spares++;
109 d = dl_strdup(devlist->devname);
110 dl_add(ap->devs, d);
111 } else {
112 printf("%s:\n",devlist->devname);
113 examine_super0(super);
114 free(super);
115 }
116 }
117 if (brief) {
118 struct array *ap;
119 for (ap=arrays; ap; ap=ap->next) {
120 char sep='=';
121 char *d;
122 brief_examine_super0(ap->super);
123 if (ap->spares) printf(" spares=%d", ap->spares);
124 printf(" devices");
125 for (d=dl_next(ap->devs); d!= ap->devs; d=dl_next(d)) {
126 printf("%c%s", sep, d);
127 sep=',';
128 }
129 free(ap->super);
130 /* FIXME free ap */
131 printf("\n");
132 }
133 }
134 return rv;
135 }