Standalone mkfs/fsck/xfs2 byte order fixes
authorTormod Volden <debian.tormod@gmail.com>
Sun, 29 Mar 2015 22:05:19 +0000 (00:05 +0200)
committerAlan Cox <alan@linux.intel.com>
Sun, 29 Mar 2015 23:18:16 +0000 (00:18 +0100)
Signed-off-by: Tormod Volden <debian.tormod@gmail.com>
Standalone/fsck.c
Standalone/mkfs.c
Standalone/xfs2.c

index 7bf12e5..6a29bc5 100644 (file)
@@ -264,7 +264,7 @@ void pass2(void)
             superblock.s_tfree = swizzle16(swizzle16(superblock.s_tfree)+1);
             s = swizzle16(superblock.s_nfree);
             superblock.s_free[s++] = swizzle16(j);
-            superblock.s_nfree = s;
+            superblock.s_nfree = swizzle16(s);
         }
     }
 
index 0d9d69a..71793bf 100644 (file)
@@ -114,7 +114,7 @@ void mkfs(uint16_t fsize, uint16_t isize)
 
        /* The inodes are already zeroed out */
        /* create the root dir */
-       inode[ROOTINODE].i_mode = F_DIR | (0777 & MODE_MASK);
+       inode[ROOTINODE].i_mode = swizzle16(F_DIR | (0777 & MODE_MASK));
        inode[ROOTINODE].i_nlink = swizzle16(3);
        inode[ROOTINODE].i_size = swizzle32(64);
        inode[ROOTINODE].i_addr[0] = swizzle16(isize);
index aba3541..16137db 100644 (file)
@@ -315,9 +315,9 @@ int ch_link(inoptr wd, char *oldname, char *newname, inoptr nindex)
 
        /* Update file length to next block */
        if (swizzle32(wd->c_node.i_size) & 511)
-               wd->c_node.i_size =
+               wd->c_node.i_size = swizzle32(
                    swizzle32(wd->c_node.i_size) + 512 -
-                   (swizzle16(wd->c_node.i_size) & 511);
+                   (swizzle32(wd->c_node.i_size) & 511));
 
        return (1);
 }
@@ -468,7 +468,7 @@ unsigned i_alloc(int devno)
 
        _sync();                /* Make on-disk inodes consistent */
        k = 0;
-       for (blk = 2; blk < dev->s_isize; blk++) {
+       for (blk = 2; blk < swizzle16(dev->s_isize); blk++) {
                buf = (struct dinode *) bread(devno, blk, 0);
                for (j = 0; j < 8; j++) {
                        ifnot(buf[j].i_mode || buf[j].i_nlink)
@@ -850,7 +850,7 @@ blkno_t bmap(inoptr ip, blkno_t bn, int rwflg)
         * fetch the address from the inode
         * Create the first indirect block if needed.
         */
-       ifnot(nb = ip->c_node.i_addr[20 - j]) {
+       ifnot(nb = swizzle16(ip->c_node.i_addr[20 - j])) {
                if (rwflg || !(nb = blk_alloc(dev)))
                        return (NULLBLK);
                ip->c_node.i_addr[20 - j] = swizzle16(nb);