Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / mdadm / Examine.c
bloba7bbbdbe5f892c05583289bb4aec7cff424409be
1 /*
2 * mdadm - manage Linux "md" devices aka RAID arrays.
4 * Copyright (C) 2001-2006 Neil Brown <neilb@suse.de>
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
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
30 #include "mdadm.h"
31 #include "dlink.h"
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,
39 int SparcAdjust, struct supertype *forcest,
40 char *homehost)
43 /* Read the raid superblock from a device and
44 * display important content.
46 * If cannot be found, print reason: too small, bad magic
48 * Print:
49 * version, ctime, level, size, raid+spare+
50 * prefered minor
51 * uuid
53 * utime, state etc
55 * If (brief) gather devices for same array and just print a mdadm.conf line including devices=
56 * if devlist==NULL, use conf_get_devs()
58 int fd;
59 void *super = NULL;
60 int rv = 0;
61 int err = 0;
63 struct array {
64 void *super;
65 struct supertype *st;
66 struct mdinfo info;
67 void *devs;
68 struct array *next;
69 int spares;
70 } *arrays = NULL;
72 for (; devlist ; devlist=devlist->next) {
73 struct supertype *st = forcest;
75 fd = dev_open(devlist->devname, O_RDONLY);
76 if (fd < 0) {
77 if (!scan) {
78 fprintf(stderr,Name ": cannot open %s: %s\n",
79 devlist->devname, strerror(errno));
80 rv = 1;
82 err = 1;
84 else {
85 if (!st)
86 st = guess_super(fd);
87 if (st)
88 err = st->ss->load_super(st, fd, &super, (brief||scan)?NULL:devlist->devname);
89 else {
90 if (!brief) {
91 fprintf(stderr, Name ": No md superblock detected on %s.\n", devlist->devname);
92 rv = 1;
94 err = 1;
96 close(fd);
98 if (err)
99 continue;
101 if (SparcAdjust)
102 st->ss->update_super(NULL, super, "sparc2.2", devlist->devname, 0, 0, NULL);
103 /* Ok, its good enough to try, though the checksum could be wrong */
104 if (brief) {
105 struct array *ap;
106 char *d;
107 for (ap=arrays; ap; ap=ap->next) {
108 if (st->ss == ap->st->ss && st->ss->compare_super(&ap->super, super)==0)
109 break;
111 if (!ap) {
112 ap = malloc(sizeof(*ap));
113 ap->super = super;
114 ap->devs = dl_head();
115 ap->next = arrays;
116 ap->spares = 0;
117 ap->st = st;
118 arrays = ap;
119 st->ss->getinfo_super(&ap->info, super);
120 } else {
121 st->ss->getinfo_super(&ap->info, super);
122 free(super);
124 if (!(ap->info.disk.state & MD_DISK_SYNC))
125 ap->spares++;
126 d = dl_strdup(devlist->devname);
127 dl_add(ap->devs, d);
128 } else {
129 printf("%s:\n",devlist->devname);
130 st->ss->examine_super(super, homehost);
131 free(super);
134 if (brief) {
135 struct array *ap;
136 for (ap=arrays; ap; ap=ap->next) {
137 char sep='=';
138 char *d;
139 ap->st->ss->brief_examine_super(ap->super);
140 if (ap->spares) printf(" spares=%d", ap->spares);
141 if (brief > 1) {
142 printf(" devices");
143 for (d=dl_next(ap->devs); d!= ap->devs; d=dl_next(d)) {
144 printf("%c%s", sep, d);
145 sep=',';
148 free(ap->super);
149 /* FIXME free ap */
150 if (ap->spares || brief > 1)
151 printf("\n");
154 return rv;