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 extern long long lseek64(int, long long, int);
21 int main(int argc
, char *argv
[])
25 unsigned long long offset
;
28 fprintf(stderr
, "Usage: swap_super device\n");
31 fd
= open(argv
[1], O_RDWR
);
36 if (ioctl(fd
, BLKGETSIZE
, &size
)) {
40 offset
= MD_NEW_SIZE_SECTORS(size
) * 512LL;
41 if (lseek64(fd
, offset
, 0) < 0LL) {
45 if (read(fd
, super
, 4096) != 4096) {
51 for (i
=0; i
< 4096 ; i
+=4) {
53 super
[i
] = super
[i
+3];
56 super
[i
+1]=super
[i
+2];
59 /* swap the u64 events counters */
61 /* events_hi and events_lo */
62 char t
=super
[32*4+7*4 +i
];
63 super
[32*4+7*4 +i
] = super
[32*4+8*4 +i
];
64 super
[32*4+8*4 +i
] = t
;
66 /* cp_events_hi and cp_events_lo */
68 super
[32*4+9*4 +i
] = super
[32*4+10*4 +i
];
69 super
[32*4+10*4 +i
] = t
;
73 if (lseek64(fd
, offset
, 0) < 0LL) {
77 if (write(fd
, super
, 4096) != 4096) {