]>
git.ipfire.org Git - thirdparty/mdadm.git/blob - swap_super.c
7 * This is a tiny test program to endian-swap
8 * the superblock on a given device.
9 * We simply read 4k from where the superblock should be
10 * do the swap, and write it back
11 * Don't use this on a real array, use mdadm.
14 #define MD_RESERVED_BYTES (64 * 1024)
15 #define MD_RESERVED_SECTORS (MD_RESERVED_BYTES / 512)
17 #define MD_NEW_SIZE_SECTORS(x) ((x & ~(MD_RESERVED_SECTORS - 1)) - MD_RESERVED_SECTORS)
19 main(int argc
, char *argv
[])
23 unsigned long long offset
;
26 fprintf(stderr
, "Usage: swap_super device\n");
29 fd
= open(argv
[1], O_RDWR
);
34 if (ioctl(fd
, BLKGETSIZE
, &size
)) {
38 offset
= MD_NEW_SIZE_SECTORS(size
) * 512LL;
39 if (lseek64(fd
, offset
, 0) < 0LL) {
43 if (read(fd
, super
, 4096) != 4096) {
49 for (i
=0; i
< 4096 ; i
+=4) {
51 super
[i
] = super
[i
+3];
54 super
[i
+1]=super
[i
+2];
57 /* swap the u64 events counters */
59 /* events_hi and events_lo */
60 char t
=super
[32*4+7*4 +i
];
61 super
[32*4+7*4 +i
] = super
[32*4+8*4 +i
];
62 super
[32*4+8*4 +i
] = t
;
64 /* cp_events_hi and cp_events_lo */
66 super
[32*4+9*4 +i
] = super
[32*4+10*4 +i
];
67 super
[32*4+10*4 +i
] = t
;
71 if (lseek64(fd
, offset
, 0) < 0LL) {
75 if (write(fd
, super
, 4096) != 4096) {