bfs: fix endianness, signedness; add trivial bugfix
PATCH 1/1 bfs: fix endianness, signedness; add trivial bugfix
* Makes BFS code endianness-clean.
* Fixes some signedness warnings.
* Fixes a problem in fs/bfs/inode.c:164 where inodes not synced to disk don't get fully marked as clean. Here's how to reproduce it:
# mount -o loop -t bfs /bfs.img /mnt # df -i /mnt Filesystem Inodes IUsed IFree IUse% Mounted on /bfs.img 48 1 47 3% /mnt # df -k /mnt Filesystem 1K-blocks Used Available Use% Mounted on /bfs.img 512 5 508 1% /mnt # cp 60k-archive.zip /mnt/mt.zip # df -k /mnt Filesystem 1K-blocks Used Available Use% Mounted on /bfs.img 512 65 447 13% /mnt # df -i /mnt Filesystem Inodes IUsed IFree IUse% Mounted on /bfs.img 48 2 46 5% /mnt # rm /mnt/mt.zip # echo $? 0
[If the unlink happens before the buffers flush, the following happens:]
# df -i /mnt Filesystem Inodes IUsed IFree IUse% Mounted on /bfs.img 48 2 46 5% /mnt # df -k /mnt Filesystem 1K-blocks Used Available Use% Mounted on /bfs.img 512 65 447 13% /mnt
fs/bfs/bfs.h | 1 fs/bfs/dir.c | 25 ++++++------ fs/bfs/file.c | 23 ++++++----- fs/bfs/inode.c | 100 ++++++++++++++++++++++++++----------------------- include/linux/bfs_fs.h | 23 +++++------ 5 files changed, 92 insertions(+), 80 deletions(-)
Signed-off-by Andrew Stribblehill <[email protected]>
fs/bfs/bfs.h +0 -1
@@ -20,7 +20,6 @@unsigned long si_lasti;unsigned long * si_imap;struct buffer_head * si_sbh;/* buffer header w/superblock */ -struct bfs_super_block * si_bfs_sb;/* superblock in si_sbh->b_data */ };/*
fs/bfs/dir.c +13 -12
@@ -2,6 +2,7 @@* fs/bfs/dir.c * BFS directory operations. * Copyright (C) 1999,2000 Tigran Aivazian <[email protected]> +* Made endianness-clean by Andrew Stribblehill <[email protected]> 2005 */ #include <linux/time.h>
@@ -20,9 +21,9 @@ #define dprintf(x...)#endif -static int bfs_add_entry (struct inode * dir,const char * name,int namelen,int ino); +static int bfs_add_entry (struct inode * dir,const unsigned char * name,int namelen,int ino);static struct buffer_head *bfs_find_entry (struct inode * dir, -const char * name,int namelen,struct bfs_dirent ** res_dir); +const unsigned char * name,int namelen,struct bfs_dirent ** res_dir);static int bfs_readdir (struct file * f,void * dirent,filldir_t filldir) {
@@ -53,7 +54,7 @@ de = (struct bfs_dirent *)(bh->b_data + offset);if (de->ino) {int size =strnlen (de->name,BFS_NAMELEN ); -if (filldir (dirent, de->name, size, f->f_pos, de->ino,DT_UNKNOWN ) <0 ) { +if (filldir (dirent, de->name, size, f->f_pos,le16_to_cpu (de->ino),DT_UNKNOWN ) <0 ) {brelse (bh);unlock_kernel ();return 0 ;
@@ -107,7 +108,7 @@ inode->i_mapping->a_ops = &bfs_aops; inode->i_mode = mode; inode->i_ino = ino; -BFS_I (inode)->i_dsk_ino = ino; +BFS_I (inode)->i_dsk_ino =cpu_to_le16 (ino);BFS_I (inode)->i_sblock =0 ;BFS_I (inode)->i_eblock =0 ;insert_inode_hash (inode);
@@ -139,7 +140,7 @@lock_kernel (); bh =bfs_find_entry (dir, dentry->d_name.name, dentry->d_name.len, &de);if (bh) { -unsigned long ino =le32_to_cpu (de->ino); +unsigned long ino = (unsigned long )le16_to_cpu (de->ino);brelse (bh); inode =iget (dir->i_sb, ino);if (!inode) {
@@ -183,7 +184,7 @@ inode = dentry->d_inode;lock_kernel (); bh =bfs_find_entry (dir, dentry->d_name.name, dentry->d_name.len, &de); -if (!bh || de->ino != inode->i_ino) +if (!bh ||le16_to_cpu (de->ino) != inode->i_ino) goto out_brelse;if (!inode->i_nlink) {
@@ -224,7 +225,7 @@ old_dentry->d_name.name, old_dentry->d_name.len, &old_de); -if (!old_bh || old_de->ino != old_inode->i_ino) +if (!old_bh ||le16_to_cpu (old_de->ino) != old_inode->i_ino) goto end_rename; error = -EPERM ;
@@ -270,7 +271,7 @@ .rename = bfs_rename, }; -static int bfs_add_entry (struct inode * dir,const char * name,int namelen,int ino) +static int bfs_add_entry (struct inode * dir,const unsigned char * name,int namelen,int ino) {struct buffer_head * bh;struct bfs_dirent * de;
@@ -304,7 +305,7 @@ } dir->i_mtime =CURRENT_TIME_SEC ;mark_inode_dirty (dir); - de->ino = ino; + de->ino =cpu_to_le16 ((u16 )ino);for (i=0 ; i<BFS_NAMELEN ; i++) de->name[i] = (i < namelen) ? name[i] :0 ;mark_buffer_dirty (bh);
@@ -317,7 +318,7 @@return -ENOSPC ; } -static inline int bfs_namecmp (int len,const char * name,const char * buffer) +static inline int bfs_namecmp (int len,const unsigned char * name,const char * buffer) {if (len <BFS_NAMELEN && buffer[len])return 0 ;
@@ -325,7 +326,7 @@ }static struct buffer_head *bfs_find_entry (struct inode * dir, -const char * name,int namelen,struct bfs_dirent ** res_dir) +const unsigned char * name,int namelen,struct bfs_dirent ** res_dir) {unsigned long block, offset;struct buffer_head * bh;
@@ -346,7 +347,7 @@ } de = (struct bfs_dirent *)(bh->b_data + offset); offset +=BFS_DIRENT_SIZE ; -if (de->ino &&bfs_namecmp (namelen, name, de->name)) { +if (le16_to_cpu (de->ino) &&bfs_namecmp (namelen, name, de->name)) { *res_dir = de;return bh; }
fs/bfs/file.c +13 -10
@@ -40,8 +40,8 @@return 0 ; } -static int bfs_move_blocks (struct super_block *sb,unsigned long start,unsigned long end, -unsigned long where) +static int bfs_move_blocks (struct super_block *sb,unsigned long start, +unsigned long end,unsigned long where) {unsigned long i;
@@ -57,20 +57,21 @@static int bfs_get_block (struct inode * inode,sector_t block,struct buffer_head * bh_result,int create) { -long phys; +unsigned long phys;int err;struct super_block *sb = inode->i_sb;struct bfs_sb_info *info =BFS_SB (sb);struct bfs_inode_info *bi =BFS_I (inode);struct buffer_head *sbh = info->si_sbh; -if (block <0 || block > info->si_blocks) +if (block > info->si_blocks)return -EIO ; phys = bi->i_sblock + block;if (!create) {if (phys <= bi->i_eblock) { -dprintf ("c=%d, b=%08lx, phys=%08lx (granted)\n" , create, block, phys); +dprintf ("c=%d, b=%08lx, phys=%09lx (granted)\n" , + create, (unsigned long )block, phys);map_bh (bh_result, sb, phys); }return 0 ;
@@ -80,7 +81,7 @@of blocks allocated for this file, we can grant it */ if (inode->i_size && phys <= bi->i_eblock) {dprintf ("c=%d, b=%08lx, phys=%08lx (interim block granted)\n" , - create, block, phys); + create, (unsigned long )block, phys);map_bh (bh_result, sb, phys);return 0 ; }
@@ -88,11 +89,12 @@/* the rest has to be protected against itself */ lock_kernel (); -/* if the last data block for this file is the last allocated block, we can -extend the file trivially, without moving it anywhere */ +/* if the last data block for this file is the last allocated +block, we can extend the file trivially, without moving it +anywhere */ if (bi->i_eblock == info->si_lf_eblk) {dprintf ("c=%d, b=%08lx, phys=%08lx (simple extension)\n" , - create, block, phys); + create, (unsigned long )block, phys);map_bh (bh_result, sb, phys); info->si_freeb -= phys - bi->i_eblock; info->si_lf_eblk = bi->i_eblock = phys;
@@ -114,7 +116,8 @@ }else err =0 ; -dprintf ("c=%d, b=%08lx, phys=%08lx (moved)\n" , create, block, phys); +dprintf ("c=%d, b=%08lx, phys=%08lx (moved)\n" , + create, (unsigned long )block, phys); bi->i_sblock = phys; phys += block; info->si_lf_eblk = bi->i_eblock = phys;
fs/bfs/inode.c +54 -46
209 lines not on this page · raw message
include/linux/bfs_fs.h +12 -11
@@ -14,8 +14,9 @@#define BFS_INODES_PER_BLOCK 8/* SVR4 vnode type values (bfs_inode->i_vtype) */ -#define BFS_VDIR 2 -#define BFS_VREG 1 +#define BFS_VDIR 2L +#define BFS_VREG 1L +/* BFS inode layout on disk */ struct bfs_inode {
@@ -58,22 +59,22 @@ __u32 s_padding[118]; }; -#define BFS_NZFILESIZE (ip) \ - (((ip)->i_eoffset + 1) - (ip)->i_sblock * BFS_BSIZE) - -#define BFS_FILESIZE (ip) \ - ((ip)->i_sblock == 0 ? 0 : BFS_NZFILESIZE(ip)) - -#define BFS_FILEBLOCKS (ip) \ - ((ip)->i_sblock == 0 ? 0 : ((ip)->i_eblock + 1) - (ip)->i_sblock)#define BFS_OFF2INO (offset) \ ((((offset) - BFS_BSIZE) / sizeof(struct bfs_inode)) + BFS_ROOT_INO)#define BFS_INO2OFF (ino) \ ((__u32)(((ino) - BFS_ROOT_INO) * sizeof(struct bfs_inode)) + BFS_BSIZE) +#define BFS_NZFILESIZE (ip) \ + ((cpu_to_le32((ip)->i_eoffset) + 1) - cpu_to_le32((ip)->i_sblock) * BFS_BSIZE) + +#define BFS_FILESIZE (ip) \ + ((ip)->i_sblock == 0 ? 0 : BFS_NZFILESIZE(ip)) +#define BFS_FILEBLOCKS (ip) \ + ((ip)->i_sblock == 0 ? 0 : (cpu_to_le32((ip)->i_eblock) + 1) - cpu_to_le32((ip)->i_sblock))#define BFS_UNCLEAN (bfs_sb, sb) \ - ((bfs_sb->s_from != -1) && (bfs_sb->s_to != -1) && !(sb->s_flags & MS_RDONLY)) + ((cpu_to_le32(bfs_sb->s_from) != -1) && (cpu_to_le32(bfs_sb->s_to) != -1) && !(sb->s_flags & MS_RDONLY)) +#endif /* _LINUX_BFS_FS_H */
Signature · 3 lines
FAEROES SOUTHEAST ICELAND SOUTHWEST 4 OR 5 BACKING SOUTH 6 TO GALE 8, BECOMING CYCLONIC LATER IN SOUTHEAST ICELAND. RAIN OR SHOWERS. MODERATE OR GOOD