Skip to content

Commit fac92be

Browse files
Andrew StribblehillLinus Torvalds
authored andcommitted
[PATCH] 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 Signed-off-by: Andrew Stribblehill <ads@wompom.org> Cc: <tigran@veritas.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 383f283 commit fac92be

5 files changed

Lines changed: 93 additions & 81 deletions

File tree

‎fs/bfs/bfs.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ struct bfs_sb_info {
2020
unsigned long si_lasti;
2121
unsigned long * si_imap;
2222
struct buffer_head * si_sbh; /* buffer header w/superblock */
23-
struct bfs_super_block * si_bfs_sb; /* superblock in si_sbh->b_data */
2423
};
2524

2625
/*

‎fs/bfs/dir.c‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* fs/bfs/dir.c
33
* BFS directory operations.
44
* Copyright (C) 1999,2000 Tigran Aivazian <tigran@veritas.com>
5+
* Made endianness-clean by Andrew Stribblehill <ads@wompom.org> 2005
56
*/
67

78
#include <linux/time.h>
@@ -20,9 +21,9 @@
2021
#define dprintf(x...)
2122
#endif
2223

23-
static int bfs_add_entry(struct inode * dir, const char * name, int namelen, int ino);
24+
static int bfs_add_entry(struct inode * dir, const unsigned char * name, int namelen, int ino);
2425
static struct buffer_head * bfs_find_entry(struct inode * dir,
25-
const char * name, int namelen, struct bfs_dirent ** res_dir);
26+
const unsigned char * name, int namelen, struct bfs_dirent ** res_dir);
2627

2728
static int bfs_readdir(struct file * f, void * dirent, filldir_t filldir)
2829
{
@@ -53,7 +54,7 @@ static int bfs_readdir(struct file * f, void * dirent, filldir_t filldir)
5354
de = (struct bfs_dirent *)(bh->b_data + offset);
5455
if (de->ino) {
5556
int size = strnlen(de->name, BFS_NAMELEN);
56-
if (filldir(dirent, de->name, size, f->f_pos, de->ino, DT_UNKNOWN) < 0) {
57+
if (filldir(dirent, de->name, size, f->f_pos, le16_to_cpu(de->ino), DT_UNKNOWN) < 0) {
5758
brelse(bh);
5859
unlock_kernel();
5960
return 0;
@@ -107,7 +108,7 @@ static int bfs_create(struct inode * dir, struct dentry * dentry, int mode,
107108
inode->i_mapping->a_ops = &bfs_aops;
108109
inode->i_mode = mode;
109110
inode->i_ino = ino;
110-
BFS_I(inode)->i_dsk_ino = ino;
111+
BFS_I(inode)->i_dsk_ino = cpu_to_le16(ino);
111112
BFS_I(inode)->i_sblock = 0;
112113
BFS_I(inode)->i_eblock = 0;
113114
insert_inode_hash(inode);
@@ -139,7 +140,7 @@ static struct dentry * bfs_lookup(struct inode * dir, struct dentry * dentry, st
139140
lock_kernel();
140141
bh = bfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len, &de);
141142
if (bh) {
142-
unsigned long ino = le32_to_cpu(de->ino);
143+
unsigned long ino = (unsigned long)le16_to_cpu(de->ino);
143144
brelse(bh);
144145
inode = iget(dir->i_sb, ino);
145146
if (!inode) {
@@ -183,7 +184,7 @@ static int bfs_unlink(struct inode * dir, struct dentry * dentry)
183184
inode = dentry->d_inode;
184185
lock_kernel();
185186
bh = bfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len, &de);
186-
if (!bh || de->ino != inode->i_ino)
187+
if (!bh || le16_to_cpu(de->ino) != inode->i_ino)
187188
goto out_brelse;
188189

189190
if (!inode->i_nlink) {
@@ -224,7 +225,7 @@ static int bfs_rename(struct inode * old_dir, struct dentry * old_dentry,
224225
old_dentry->d_name.name,
225226
old_dentry->d_name.len, &old_de);
226227

227-
if (!old_bh || old_de->ino != old_inode->i_ino)
228+
if (!old_bh || le16_to_cpu(old_de->ino) != old_inode->i_ino)
228229
goto end_rename;
229230

230231
error = -EPERM;
@@ -270,7 +271,7 @@ struct inode_operations bfs_dir_inops = {
270271
.rename = bfs_rename,
271272
};
272273

273-
static int bfs_add_entry(struct inode * dir, const char * name, int namelen, int ino)
274+
static int bfs_add_entry(struct inode * dir, const unsigned char * name, int namelen, int ino)
274275
{
275276
struct buffer_head * bh;
276277
struct bfs_dirent * de;
@@ -304,7 +305,7 @@ static int bfs_add_entry(struct inode * dir, const char * name, int namelen, int
304305
}
305306
dir->i_mtime = CURRENT_TIME_SEC;
306307
mark_inode_dirty(dir);
307-
de->ino = ino;
308+
de->ino = cpu_to_le16((u16)ino);
308309
for (i=0; i<BFS_NAMELEN; i++)
309310
de->name[i] = (i < namelen) ? name[i] : 0;
310311
mark_buffer_dirty(bh);
@@ -317,15 +318,15 @@ static int bfs_add_entry(struct inode * dir, const char * name, int namelen, int
317318
return -ENOSPC;
318319
}
319320

320-
static inline int bfs_namecmp(int len, const char * name, const char * buffer)
321+
static inline int bfs_namecmp(int len, const unsigned char * name, const char * buffer)
321322
{
322323
if (len < BFS_NAMELEN && buffer[len])
323324
return 0;
324325
return !memcmp(name, buffer, len);
325326
}
326327

327328
static struct buffer_head * bfs_find_entry(struct inode * dir,
328-
const char * name, int namelen, struct bfs_dirent ** res_dir)
329+
const unsigned char * name, int namelen, struct bfs_dirent ** res_dir)
329330
{
330331
unsigned long block, offset;
331332
struct buffer_head * bh;
@@ -346,7 +347,7 @@ static struct buffer_head * bfs_find_entry(struct inode * dir,
346347
}
347348
de = (struct bfs_dirent *)(bh->b_data + offset);
348349
offset += BFS_DIRENT_SIZE;
349-
if (de->ino && bfs_namecmp(namelen, name, de->name)) {
350+
if (le16_to_cpu(de->ino) && bfs_namecmp(namelen, name, de->name)) {
350351
*res_dir = de;
351352
return bh;
352353
}

‎fs/bfs/file.c‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ static int bfs_move_block(unsigned long from, unsigned long to, struct super_blo
4040
return 0;
4141
}
4242

43-
static int bfs_move_blocks(struct super_block *sb, unsigned long start, unsigned long end,
44-
unsigned long where)
43+
static int bfs_move_blocks(struct super_block *sb, unsigned long start,
44+
unsigned long end, unsigned long where)
4545
{
4646
unsigned long i;
4747

@@ -57,20 +57,21 @@ static int bfs_move_blocks(struct super_block *sb, unsigned long start, unsigned
5757
static int bfs_get_block(struct inode * inode, sector_t block,
5858
struct buffer_head * bh_result, int create)
5959
{
60-
long phys;
60+
unsigned long phys;
6161
int err;
6262
struct super_block *sb = inode->i_sb;
6363
struct bfs_sb_info *info = BFS_SB(sb);
6464
struct bfs_inode_info *bi = BFS_I(inode);
6565
struct buffer_head *sbh = info->si_sbh;
6666

67-
if (block < 0 || block > info->si_blocks)
67+
if (block > info->si_blocks)
6868
return -EIO;
6969

7070
phys = bi->i_sblock + block;
7171
if (!create) {
7272
if (phys <= bi->i_eblock) {
73-
dprintf("c=%d, b=%08lx, phys=%08lx (granted)\n", create, block, phys);
73+
dprintf("c=%d, b=%08lx, phys=%09lx (granted)\n",
74+
create, (unsigned long)block, phys);
7475
map_bh(bh_result, sb, phys);
7576
}
7677
return 0;
@@ -80,19 +81,20 @@ static int bfs_get_block(struct inode * inode, sector_t block,
8081
of blocks allocated for this file, we can grant it */
8182
if (inode->i_size && phys <= bi->i_eblock) {
8283
dprintf("c=%d, b=%08lx, phys=%08lx (interim block granted)\n",
83-
create, block, phys);
84+
create, (unsigned long)block, phys);
8485
map_bh(bh_result, sb, phys);
8586
return 0;
8687
}
8788

8889
/* the rest has to be protected against itself */
8990
lock_kernel();
9091

91-
/* if the last data block for this file is the last allocated block, we can
92-
extend the file trivially, without moving it anywhere */
92+
/* if the last data block for this file is the last allocated
93+
block, we can extend the file trivially, without moving it
94+
anywhere */
9395
if (bi->i_eblock == info->si_lf_eblk) {
9496
dprintf("c=%d, b=%08lx, phys=%08lx (simple extension)\n",
95-
create, block, phys);
97+
create, (unsigned long)block, phys);
9698
map_bh(bh_result, sb, phys);
9799
info->si_freeb -= phys - bi->i_eblock;
98100
info->si_lf_eblk = bi->i_eblock = phys;
@@ -114,7 +116,8 @@ static int bfs_get_block(struct inode * inode, sector_t block,
114116
} else
115117
err = 0;
116118

117-
dprintf("c=%d, b=%08lx, phys=%08lx (moved)\n", create, block, phys);
119+
dprintf("c=%d, b=%08lx, phys=%08lx (moved)\n",
120+
create, (unsigned long)block, phys);
118121
bi->i_sblock = phys;
119122
phys += block;
120123
info->si_lf_eblk = bi->i_eblock = phys;

0 commit comments

Comments
 (0)