]> git.ipfire.org Git - thirdparty/mdadm.git/blob - Detail.c
mdadm-0.8
[thirdparty/mdadm.git] / Detail.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 "md_p.h"
32 #include "md_u.h"
33
34 int Detail(char *dev, int brief)
35 {
36 /*
37 * Print out details for an md array by using
38 * GET_ARRAY_INFO and GET_DISK_INFO ioctl calls
39 */
40
41 int fd = open(dev, O_RDONLY, 0);
42 int vers;
43 mdu_array_info_t array;
44 int d;
45 time_t atime;
46 char *c;
47
48 mdp_super_t super;
49 int have_super = 0;
50
51 if (fd < 0) {
52 fprintf(stderr, Name ": cannot open %s: %s\n",
53 dev, strerror(errno));
54 return 1;
55 }
56 vers = md_get_version(fd);
57 if (vers < 0) {
58 fprintf(stderr, Name ": %s does not appear to be an md device\n",
59 dev);
60 close(fd);
61 return 1;
62 }
63 if (vers < 9000) {
64 fprintf(stderr, Name ": cannot get detail for md device %s: driver version too old.\n",
65 dev);
66 close(fd);
67 return 1;
68 }
69 if (ioctl(fd, GET_ARRAY_INFO, &array)<0) {
70 if (errno == ENODEV)
71 fprintf(stderr, Name ": md device %s does not appear to be active.\n",
72 dev);
73 else
74 fprintf(stderr, Name ": cannot get array detail for %s: %s\n",
75 dev, strerror(errno));
76 close(fd);
77 return 1;
78 }
79 /* Ok, we have some info to print... */
80 c = map_num(pers, array.level);
81 if (brief)
82 printf("ARRAY %s level=%s disks=%d", dev, c?c:"-unknown-",array.raid_disks );
83 else {
84 unsigned long array_size;
85 unsigned long long larray_size;
86 #ifdef BLKGETSIZE64
87 if (ioctl(fd, BLKGETSIZE64, &larray_size)==0)
88 ;
89 else
90 #endif
91 if (ioctl(fd, BLKGETSIZE, &array_size)==0)
92 larray_size = array_size<<9;
93 else larray_size = 0;
94
95 printf("%s:\n", dev);
96 printf(" Version : %02d.%02d.%02d\n",
97 array.major_version, array.minor_version, array.patch_version);
98 atime = array.ctime;
99 printf(" Creation Time : %.24s\n", ctime(&atime));
100 printf(" Raid Level : %s\n", c?c:"-unknown-");
101 if (larray_size)
102 printf(" Array Size : %ld%s\n", (long)(larray_size>>10), human_size(larray_size));
103 if (array.level >= 1)
104 printf(" Device Size : %d%s\n", array.size, human_size((long long)array.size<<10));
105 printf(" Raid Disks : %d\n", array.raid_disks);
106 printf(" Total Disks : %d\n", array.nr_disks);
107 printf("Preferred Minor : %d\n", array.md_minor);
108 printf(" Persistance : Superblock is %spersistant\n",
109 array.not_persistent?"not ":"");
110 printf("\n");
111 atime = array.utime;
112 printf(" Update Time : %.24s\n", ctime(&atime));
113 printf(" State : %s, %serrors\n",
114 (array.state&(1<<MD_SB_CLEAN))?"clean":"dirty",
115 (array.state&(1<<MD_SB_ERRORS))?"":"no-");
116 printf(" Active Drives : %d\n", array.active_disks);
117 printf(" Working Drives : %d\n", array.working_disks);
118 printf(" Failed Drives : %d\n", array.failed_disks);
119 printf(" Spare Drives : %d\n", array.spare_disks);
120 printf("\n");
121 if (array.level == 5) {
122 c = map_num(r5layout, array.layout);
123 printf(" Layout : %s\n", c?c:"-unknown-");
124 }
125 switch (array.level) {
126 case 0:
127 case 4:
128 case 5:
129 printf(" Chunk Size : %dK\n", array.chunk_size/1024);
130 break;
131 case -1:
132 printf(" Rounding : %dK\n", array.chunk_size/1024);
133 break;
134 default: break;
135 }
136
137 printf("\n");
138 printf(" Number Major Minor RaidDisk State\n");
139 }
140 for (d= 0; d<MD_SB_DISKS; d++) {
141 mdu_disk_info_t disk;
142 char *dv;
143 disk.number = d;
144 if (ioctl(fd, GET_DISK_INFO, &disk) < 0) {
145 if (d < array.raid_disks)
146 fprintf(stderr, Name ": cannot get disk detail for disk %d: %s\n",
147 d, strerror(errno));
148 continue;
149 }
150 if (d >= array.raid_disks &&
151 disk.major == 0 &&
152 disk.minor == 0)
153 continue;
154 if (!brief) {
155 printf(" %5d %5d %5d %5d ",
156 disk.number, disk.major, disk.minor, disk.raid_disk);
157 if (disk.state & (1<<MD_DISK_FAULTY)) printf(" faulty");
158 if (disk.state & (1<<MD_DISK_ACTIVE)) printf(" active");
159 if (disk.state & (1<<MD_DISK_SYNC)) printf(" sync");
160 if (disk.state & (1<<MD_DISK_REMOVED)) printf(" removed");
161 }
162 if ((dv=map_dev(disk.major, disk.minor))) {
163 if (!brief) printf(" %s", dv);
164 if (!have_super) {
165 /* try to read the superblock from this device
166 * to get more info
167 */
168 int fd = open(dv, O_RDONLY);
169 if (fd >=0 &&
170 load_super(fd, &super) ==0 &&
171 super.ctime == array.ctime &&
172 super.level == array.level)
173 have_super = 1;
174 }
175 }
176 if (!brief) printf("\n");
177 }
178 if (have_super) {
179 if (brief) printf(" UUID=");
180 else printf(" UUID : ");
181 if (super.minor_version >= 90)
182 printf("%08x:%08x:%08x:%08x", super.set_uuid0, super.set_uuid1,
183 super.set_uuid2, super.set_uuid3);
184 else
185 printf("%08x", super.set_uuid0);
186 if (!brief) printf("\n");
187 }
188 if (brief) printf("\n");
189 return 0;
190 }