]>
git.ipfire.org Git - thirdparty/mdadm.git/blob - super-mbr.c
2 * mdadm - manage Linux "md" devices aka RAID arrays.
4 * Copyright (C) 2010 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
22 * Email: <neil@brown.name>
27 * 'mbr' is a pseudo metadata type for devices which have a
28 * partition table in the Master Boot Record (mbr) also known
29 * as a dos partition table.
31 * Obviously arrays cannot be created or assembled for this type.
32 * It is used to allow a new bare device to have an partition table
33 * added so the member partitions can then be included in other
36 * The meaning operations are:
37 * examine_super, but not brief_examine_super or export_examine
45 static void free_mbr(struct supertype
*st
)
53 static void examine_mbr(struct supertype
*st
, char *homehost
)
55 struct MBR
*sb
= st
->sb
;
58 printf(" MBR Magic : %04x\n", sb
->magic
);
59 for (i
= 0; i
< MBR_PARTITIONS
; i
++)
61 * Have to make every access through sb rather than using a
62 * pointer to the partition table (or an entry), since the
63 * entries are not properly aligned.
65 if (sb
->parts
[i
].blocks_num
)
66 printf("Partition[%d] : %12lu sectors at %12lu (type %02x)\n",
68 (unsigned long)__le32_to_cpu(sb
->parts
[i
].blocks_num
),
69 (unsigned long)__le32_to_cpu(sb
->parts
[i
].first_sect_lba
),
70 sb
->parts
[i
].part_type
);
74 #endif /*MDASSEMBLE */
76 static int load_super_mbr(struct supertype
*st
, int fd
, char *devname
)
82 * 2 record is meaningless
88 if (posix_memalign((void**)&super
, 512, 512) != 0) {
89 pr_err("could not allocate superblock\n");
94 if (read(fd
, super
, sizeof(*super
)) != sizeof(*super
)) {
96 pr_err("Cannot read partition table on %s\n",
102 if (super
->magic
!= MBR_SIGNATURE_MAGIC
) {
104 pr_err("No partition table found on %s\n",
112 if (st
->ss
== NULL
) {
114 st
->minor_version
= 0;
121 static int store_mbr(struct supertype
*st
, int fd
)
123 struct MBR
*old
, *super
;
125 if (posix_memalign((void**)&old
, 512, 512) != 0) {
126 pr_err("could not allocate superblock\n");
131 if (read(fd
, old
, sizeof(*old
)) != sizeof(*old
)) {
137 memcpy(super
->pad
, old
->pad
, sizeof(super
->pad
));
140 if (write(fd
, super
, sizeof(*super
)) != sizeof(*super
))
143 ioctl(fd
, BLKRRPART
, 0);
147 static void getinfo_mbr(struct supertype
*st
, struct mdinfo
*info
, char *map
)
149 struct MBR
*sb
= st
->sb
;
152 memset(&info
->array
, 0, sizeof(info
->array
));
153 memset(&info
->disk
, 0, sizeof(info
->disk
));
154 strcpy(info
->text_version
, "mbr");
155 strcpy(info
->name
, "mbr");
156 info
->component_size
= 0;
158 for (i
= 0; i
< MBR_PARTITIONS
; i
++)
160 * Have to make every access through sb rather than using a
161 * pointer to the partition table (or an entry), since the
162 * entries are not properly aligned.
164 if (sb
->parts
[i
].blocks_num
) {
166 (unsigned long)__le32_to_cpu(sb
->parts
[i
].blocks_num
)
167 + (unsigned long)__le32_to_cpu(sb
->parts
[i
].first_sect_lba
);
168 if (last
> info
->component_size
)
169 info
->component_size
= last
;
174 static struct supertype
*match_metadata_desc(char *arg
)
176 struct supertype
*st
;
178 if (strcmp(arg
, "mbr") != 0)
181 st
= xmalloc(sizeof(*st
));
184 st
->minor_version
= 0;
191 static int validate_geometry(struct supertype
*st
, int level
,
192 int layout
, int raiddisks
,
193 int *chunk
, unsigned long long size
,
194 unsigned long long data_offset
,
195 char *subdev
, unsigned long long *freesize
,
198 pr_err("mbr metadata cannot be used this way\n");
203 struct superswitch mbr
= {
205 .examine_super
= examine_mbr
,
206 .validate_geometry
= validate_geometry
,
208 .match_metadata_desc
= match_metadata_desc
,
209 .load_super
= load_super_mbr
,
210 .store_super
= store_mbr
,
211 .getinfo_super
= getinfo_mbr
,
212 .free_super
= free_mbr
,