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) {
50 for (i=0; i < 4096 ; i+=4) {
52 super[i] = super[i+3];
55 super[i+1]=super[i+2];
58 /* swap the u64 events counters */
60 /* events_hi and events_lo */
61 char t=super[32*4+7*4 +i];
62 super[32*4+7*4 +i] = super[32*4+8*4 +i];
63 super[32*4+8*4 +i] = t;
65 /* cp_events_hi and cp_events_lo */
67 super[32*4+9*4 +i] = super[32*4+10*4 +i];
68 super[32*4+10*4 +i] = t;
71 if (lseek64(fd, offset, 0) < 0LL) {
75 if (write(fd, super, 4096) != 4096) {