]> git.ipfire.org Git - thirdparty/mdadm.git/blame - Query.c
Add device files created with --auto to list of known device files.
[thirdparty/mdadm.git] / Query.c
CommitLineData
e0d19036
NB
1/*
2 * mdadm - manage Linux "md" devices aka RAID arrays.
3 *
4 * Copyright (C) 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
34int Query(char *dev)
35{
36 /* Give a brief description of the device,
37 * whether it is an md device and whether it has
38 * a superblock
39 */
40 int fd = open(dev, O_RDONLY, 0);
41 int vers;
42 int ioctlerr;
43 int superror, superrno;
4b1ac34b 44 struct mdinfo info;
e0d19036 45 mdu_array_info_t array;
4b1ac34b 46 void *super;
82d9eba6 47 struct supertype *st = NULL;
4b1ac34b 48
e0d19036
NB
49 unsigned long long larray_size;
50 unsigned long array_size;
51 struct stat stb;
52 char *mddev;
53 mdu_disk_info_t disc;
54 char *activity;
55
56 if (fd < 0){
57 fprintf(stderr, Name ": cannot open %s: %s\n",
58 dev, strerror(errno));
59 return 1;
60 }
61
62 vers = md_get_version(fd);
63 if (ioctl(fd, GET_ARRAY_INFO, &array)<0)
64 ioctlerr = errno;
65 else ioctlerr = 0;
e0d19036
NB
66
67 fstat(fd, &stb);
68
69 if (vers>=9000 && !ioctlerr) {
70#ifdef BLKGETSIZE64
71 if (ioctl(fd, BLKGETSIZE64, &larray_size)==0)
72 ;
73 else
74#endif
b83d95f3
NB
75 if (ioctl(fd, BLKGETSIZE, &array_size)==0) {
76 larray_size = array_size;
77 larray_size <<= 9;
78 } else larray_size = 0;
e0d19036 79 }
e0d19036
NB
80
81 if (vers < 0)
82 printf("%s: is not an md array\n", dev);
83 else if (vers < 9000)
84 printf("%s: is an md device, but kernel cannot provide details\n", dev);
85 else if (ioctlerr == ENODEV)
86 printf("%s: is an md device which is not active\n", dev);
87 else if (ioctlerr)
88 printf("%s: is an md device, but gives \"%s\" when queried\n",
89 dev, strerror(ioctlerr));
90 else {
91 printf("%s: %s %s %d devices, %d spare%s. Use mdadm --detail for more detail.\n",
92 dev,
93 human_size_brief(larray_size),
94 map_num(pers, array.level),
95 array.raid_disks,
96 array.spare_disks, array.spare_disks==1?"":"s");
97 }
82d9eba6
NB
98 st = guess_super(fd);
99 if (st) {
100 superror = st->ss->load_super(st, fd, &super, dev);
f9ce90ba
NB
101 superrno = errno;
102 } else
103 superror = -1;
4b1ac34b
NB
104 close(fd);
105 if (superror == 0) {
e0d19036 106 /* array might be active... */
82d9eba6 107 st->ss->getinfo_super(&info, super);
4b1ac34b
NB
108 mddev = get_md_name(info.array.md_minor);
109 disc.number = info.disk.number;
0320ea45 110 activity = "undetected";
e0d19036
NB
111 if (mddev && (fd = open(mddev, O_RDONLY))>=0) {
112 if (md_get_version(fd) >= 9000 &&
113 ioctl(fd, GET_ARRAY_INFO, &array)>= 0) {
114 if (ioctl(fd, GET_DISK_INFO, &disc) >= 0 &&
0df46c2a 115 makedev((unsigned)disc.major,(unsigned)disc.minor) == stb.st_rdev)
e0d19036
NB
116 activity = "active";
117 else
118 activity = "mismatch";
119 }
120 close(fd);
121 }
122 printf("%s: device %d in %d device %s %s md%d. Use mdadm --examine for more detail.\n",
123 dev,
4b1ac34b 124 info.disk.number, info.array.raid_disks,
e0d19036 125 activity,
4b1ac34b
NB
126 map_num(pers, info.array.level),
127 info.array.md_minor);
e0d19036
NB
128 }
129 return 0;
130}
131
132