diff options
author | Andrew Stribblehill <a.d.stribblehill@durham.ac.uk> | 2005-09-09 16:02:04 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2005-09-09 16:57:32 -0400 |
commit | fac92becdaecff64dd91daab0292c5131de92f0d (patch) | |
tree | 6c91bdbbe527682813d7c27ed13bdb0531298146 /fs/bfs | |
parent | 383f2835eb9afb723af71850037b2f074ac9db60 (diff) |
[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>
Diffstat (limited to 'fs/bfs')
-rw-r--r-- | fs/bfs/bfs.h | 1 | ||||
-rw-r--r-- | fs/bfs/dir.c | 25 | ||||
-rw-r--r-- | fs/bfs/file.c | 23 | ||||
-rw-r--r-- | fs/bfs/inode.c | 102 |
4 files changed, 81 insertions, 70 deletions
diff --git a/fs/bfs/bfs.h b/fs/bfs/bfs.h index 1020dbc88bec..1fbc53f14aba 100644 --- a/fs/bfs/bfs.h +++ b/fs/bfs/bfs.h | |||
@@ -20,7 +20,6 @@ struct bfs_sb_info { | |||
20 | unsigned long si_lasti; | 20 | unsigned long si_lasti; |
21 | unsigned long * si_imap; | 21 | unsigned long * si_imap; |
22 | struct buffer_head * si_sbh; /* buffer header w/superblock */ | 22 | struct buffer_head * si_sbh; /* buffer header w/superblock */ |
23 | struct bfs_super_block * si_bfs_sb; /* superblock in si_sbh->b_data */ | ||
24 | }; | 23 | }; |
25 | 24 | ||
26 | /* | 25 | /* |
diff --git a/fs/bfs/dir.c b/fs/bfs/dir.c index 5a1e5ce057ff..e240c335eb23 100644 --- a/fs/bfs/dir.c +++ b/fs/bfs/dir.c | |||
@@ -2,6 +2,7 @@ | |||
2 | * fs/bfs/dir.c | 2 | * fs/bfs/dir.c |
3 | * BFS directory operations. | 3 | * BFS directory operations. |
4 | * Copyright (C) 1999,2000 Tigran Aivazian <tigran@veritas.com> | 4 | * Copyright (C) 1999,2000 Tigran Aivazian <tigran@veritas.com> |
5 | * Made endianness-clean by Andrew Stribblehill <ads@wompom.org> 2005 | ||
5 | */ | 6 | */ |
6 | 7 | ||
7 | #include <linux/time.h> | 8 | #include <linux/time.h> |
@@ -20,9 +21,9 @@ | |||
20 | #define dprintf(x...) | 21 | #define dprintf(x...) |
21 | #endif | 22 | #endif |
22 | 23 | ||
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); |
24 | static struct buffer_head * bfs_find_entry(struct inode * dir, | 25 | 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); |
26 | 27 | ||
27 | static int bfs_readdir(struct file * f, void * dirent, filldir_t filldir) | 28 | static int bfs_readdir(struct file * f, void * dirent, filldir_t filldir) |
28 | { | 29 | { |
@@ -53,7 +54,7 @@ static int bfs_readdir(struct file * f, void * dirent, filldir_t filldir) | |||
53 | de = (struct bfs_dirent *)(bh->b_data + offset); | 54 | de = (struct bfs_dirent *)(bh->b_data + offset); |
54 | if (de->ino) { | 55 | if (de->ino) { |
55 | int size = strnlen(de->name, BFS_NAMELEN); | 56 | 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) { |
57 | brelse(bh); | 58 | brelse(bh); |
58 | unlock_kernel(); | 59 | unlock_kernel(); |
59 | return 0; | 60 | return 0; |
@@ -107,7 +108,7 @@ static int bfs_create(struct inode * dir, struct dentry * dentry, int mode, | |||
107 | inode->i_mapping->a_ops = &bfs_aops; | 108 | inode->i_mapping->a_ops = &bfs_aops; |
108 | inode->i_mode = mode; | 109 | inode->i_mode = mode; |
109 | inode->i_ino = ino; | 110 | inode->i_ino = ino; |
110 | BFS_I(inode)->i_dsk_ino = ino; | 111 | BFS_I(inode)->i_dsk_ino = cpu_to_le16(ino); |
111 | BFS_I(inode)->i_sblock = 0; | 112 | BFS_I(inode)->i_sblock = 0; |
112 | BFS_I(inode)->i_eblock = 0; | 113 | BFS_I(inode)->i_eblock = 0; |
113 | insert_inode_hash(inode); | 114 | insert_inode_hash(inode); |
@@ -139,7 +140,7 @@ static struct dentry * bfs_lookup(struct inode * dir, struct dentry * dentry, st | |||
139 | lock_kernel(); | 140 | lock_kernel(); |
140 | bh = bfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len, &de); | 141 | bh = bfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len, &de); |
141 | if (bh) { | 142 | if (bh) { |
142 | unsigned long ino = le32_to_cpu(de->ino); | 143 | unsigned long ino = (unsigned long)le16_to_cpu(de->ino); |
143 | brelse(bh); | 144 | brelse(bh); |
144 | inode = iget(dir->i_sb, ino); | 145 | inode = iget(dir->i_sb, ino); |
145 | if (!inode) { | 146 | if (!inode) { |
@@ -183,7 +184,7 @@ static int bfs_unlink(struct inode * dir, struct dentry * dentry) | |||
183 | inode = dentry->d_inode; | 184 | inode = dentry->d_inode; |
184 | lock_kernel(); | 185 | lock_kernel(); |
185 | bh = bfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len, &de); | 186 | 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) |
187 | goto out_brelse; | 188 | goto out_brelse; |
188 | 189 | ||
189 | if (!inode->i_nlink) { | 190 | if (!inode->i_nlink) { |
@@ -224,7 +225,7 @@ static int bfs_rename(struct inode * old_dir, struct dentry * old_dentry, | |||
224 | old_dentry->d_name.name, | 225 | old_dentry->d_name.name, |
225 | old_dentry->d_name.len, &old_de); | 226 | old_dentry->d_name.len, &old_de); |
226 | 227 | ||
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) |
228 | goto end_rename; | 229 | goto end_rename; |
229 | 230 | ||
230 | error = -EPERM; | 231 | error = -EPERM; |
@@ -270,7 +271,7 @@ struct inode_operations bfs_dir_inops = { | |||
270 | .rename = bfs_rename, | 271 | .rename = bfs_rename, |
271 | }; | 272 | }; |
272 | 273 | ||
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) |
274 | { | 275 | { |
275 | struct buffer_head * bh; | 276 | struct buffer_head * bh; |
276 | struct bfs_dirent * de; | 277 | struct bfs_dirent * de; |
@@ -304,7 +305,7 @@ static int bfs_add_entry(struct inode * dir, const char * name, int namelen, int | |||
304 | } | 305 | } |
305 | dir->i_mtime = CURRENT_TIME_SEC; | 306 | dir->i_mtime = CURRENT_TIME_SEC; |
306 | mark_inode_dirty(dir); | 307 | mark_inode_dirty(dir); |
307 | de->ino = ino; | 308 | de->ino = cpu_to_le16((u16)ino); |
308 | for (i=0; i<BFS_NAMELEN; i++) | 309 | for (i=0; i<BFS_NAMELEN; i++) |
309 | de->name[i] = (i < namelen) ? name[i] : 0; | 310 | de->name[i] = (i < namelen) ? name[i] : 0; |
310 | mark_buffer_dirty(bh); | 311 | mark_buffer_dirty(bh); |
@@ -317,7 +318,7 @@ static int bfs_add_entry(struct inode * dir, const char * name, int namelen, int | |||
317 | return -ENOSPC; | 318 | return -ENOSPC; |
318 | } | 319 | } |
319 | 320 | ||
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) |
321 | { | 322 | { |
322 | if (len < BFS_NAMELEN && buffer[len]) | 323 | if (len < BFS_NAMELEN && buffer[len]) |
323 | return 0; | 324 | return 0; |
@@ -325,7 +326,7 @@ static inline int bfs_namecmp(int len, const char * name, const char * buffer) | |||
325 | } | 326 | } |
326 | 327 | ||
327 | static struct buffer_head * bfs_find_entry(struct inode * dir, | 328 | 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) |
329 | { | 330 | { |
330 | unsigned long block, offset; | 331 | unsigned long block, offset; |
331 | struct buffer_head * bh; | 332 | struct buffer_head * bh; |
@@ -346,7 +347,7 @@ static struct buffer_head * bfs_find_entry(struct inode * dir, | |||
346 | } | 347 | } |
347 | de = (struct bfs_dirent *)(bh->b_data + offset); | 348 | de = (struct bfs_dirent *)(bh->b_data + offset); |
348 | offset += BFS_DIRENT_SIZE; | 349 | 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)) { |
350 | *res_dir = de; | 351 | *res_dir = de; |
351 | return bh; | 352 | return bh; |
352 | } | 353 | } |
diff --git a/fs/bfs/file.c b/fs/bfs/file.c index 747fd1ea55e0..807723b65daf 100644 --- a/fs/bfs/file.c +++ b/fs/bfs/file.c | |||
@@ -40,8 +40,8 @@ static int bfs_move_block(unsigned long from, unsigned long to, struct super_blo | |||
40 | return 0; | 40 | return 0; |
41 | } | 41 | } |
42 | 42 | ||
43 | static int bfs_move_blocks(struct super_block *sb, unsigned long start, unsigned long end, | 43 | static int bfs_move_blocks(struct super_block *sb, unsigned long start, |
44 | unsigned long where) | 44 | unsigned long end, unsigned long where) |
45 | { | 45 | { |
46 | unsigned long i; | 46 | unsigned long i; |
47 | 47 | ||
@@ -57,20 +57,21 @@ static int bfs_move_blocks(struct super_block *sb, unsigned long start, unsigned | |||
57 | static int bfs_get_block(struct inode * inode, sector_t block, | 57 | static int bfs_get_block(struct inode * inode, sector_t block, |
58 | struct buffer_head * bh_result, int create) | 58 | struct buffer_head * bh_result, int create) |
59 | { | 59 | { |
60 | long phys; | 60 | unsigned long phys; |
61 | int err; | 61 | int err; |
62 | struct super_block *sb = inode->i_sb; | 62 | struct super_block *sb = inode->i_sb; |
63 | struct bfs_sb_info *info = BFS_SB(sb); | 63 | struct bfs_sb_info *info = BFS_SB(sb); |
64 | struct bfs_inode_info *bi = BFS_I(inode); | 64 | struct bfs_inode_info *bi = BFS_I(inode); |
65 | struct buffer_head *sbh = info->si_sbh; | 65 | struct buffer_head *sbh = info->si_sbh; |
66 | 66 | ||
67 | if (block < 0 || block > info->si_blocks) | 67 | if (block > info->si_blocks) |
68 | return -EIO; | 68 | return -EIO; |
69 | 69 | ||
70 | phys = bi->i_sblock + block; | 70 | phys = bi->i_sblock + block; |
71 | if (!create) { | 71 | if (!create) { |
72 | if (phys <= bi->i_eblock) { | 72 | 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); | ||
74 | map_bh(bh_result, sb, phys); | 75 | map_bh(bh_result, sb, phys); |
75 | } | 76 | } |
76 | return 0; | 77 | return 0; |
@@ -80,7 +81,7 @@ static int bfs_get_block(struct inode * inode, sector_t block, | |||
80 | of blocks allocated for this file, we can grant it */ | 81 | of blocks allocated for this file, we can grant it */ |
81 | if (inode->i_size && phys <= bi->i_eblock) { | 82 | if (inode->i_size && phys <= bi->i_eblock) { |
82 | dprintf("c=%d, b=%08lx, phys=%08lx (interim block granted)\n", | 83 | dprintf("c=%d, b=%08lx, phys=%08lx (interim block granted)\n", |
83 | create, block, phys); | 84 | create, (unsigned long)block, phys); |
84 | map_bh(bh_result, sb, phys); | 85 | map_bh(bh_result, sb, phys); |
85 | return 0; | 86 | return 0; |
86 | } | 87 | } |
@@ -88,11 +89,12 @@ static int bfs_get_block(struct inode * inode, sector_t block, | |||
88 | /* the rest has to be protected against itself */ | 89 | /* the rest has to be protected against itself */ |
89 | lock_kernel(); | 90 | lock_kernel(); |
90 | 91 | ||
91 | /* if the last data block for this file is the last allocated block, we can | 92 | /* if the last data block for this file is the last allocated |
92 | extend the file trivially, without moving it anywhere */ | 93 | block, we can extend the file trivially, without moving it |
94 | anywhere */ | ||
93 | if (bi->i_eblock == info->si_lf_eblk) { | 95 | if (bi->i_eblock == info->si_lf_eblk) { |
94 | dprintf("c=%d, b=%08lx, phys=%08lx (simple extension)\n", | 96 | dprintf("c=%d, b=%08lx, phys=%08lx (simple extension)\n", |
95 | create, block, phys); | 97 | create, (unsigned long)block, phys); |
96 | map_bh(bh_result, sb, phys); | 98 | map_bh(bh_result, sb, phys); |
97 | info->si_freeb -= phys - bi->i_eblock; | 99 | info->si_freeb -= phys - bi->i_eblock; |
98 | info->si_lf_eblk = bi->i_eblock = phys; | 100 | info->si_lf_eblk = bi->i_eblock = phys; |
@@ -114,7 +116,8 @@ static int bfs_get_block(struct inode * inode, sector_t block, | |||
114 | } else | 116 | } else |
115 | err = 0; | 117 | err = 0; |
116 | 118 | ||
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); | ||
118 | bi->i_sblock = phys; | 121 | bi->i_sblock = phys; |
119 | phys += block; | 122 | phys += block; |
120 | info->si_lf_eblk = bi->i_eblock = phys; | 123 | info->si_lf_eblk = bi->i_eblock = phys; |
diff --git a/fs/bfs/inode.c b/fs/bfs/inode.c index 628c2c1a7d7e..c7b39aa279d7 100644 --- a/fs/bfs/inode.c +++ b/fs/bfs/inode.c | |||
@@ -3,6 +3,8 @@ | |||
3 | * BFS superblock and inode operations. | 3 | * BFS superblock and inode operations. |
4 | * Copyright (C) 1999,2000 Tigran Aivazian <tigran@veritas.com> | 4 | * Copyright (C) 1999,2000 Tigran Aivazian <tigran@veritas.com> |
5 | * From fs/minix, Copyright (C) 1991, 1992 Linus Torvalds. | 5 | * From fs/minix, Copyright (C) 1991, 1992 Linus Torvalds. |
6 | * | ||
7 | * Made endianness-clean by Andrew Stribblehill <ads@wompom.org>, 2005. | ||
6 | */ | 8 | */ |
7 | 9 | ||
8 | #include <linux/module.h> | 10 | #include <linux/module.h> |
@@ -54,46 +56,50 @@ static void bfs_read_inode(struct inode * inode) | |||
54 | off = (ino - BFS_ROOT_INO) % BFS_INODES_PER_BLOCK; | 56 | off = (ino - BFS_ROOT_INO) % BFS_INODES_PER_BLOCK; |
55 | di = (struct bfs_inode *)bh->b_data + off; | 57 | di = (struct bfs_inode *)bh->b_data + off; |
56 | 58 | ||
57 | inode->i_mode = 0x0000FFFF & di->i_mode; | 59 | inode->i_mode = 0x0000FFFF & le32_to_cpu(di->i_mode); |
58 | if (di->i_vtype == BFS_VDIR) { | 60 | if (le32_to_cpu(di->i_vtype) == BFS_VDIR) { |
59 | inode->i_mode |= S_IFDIR; | 61 | inode->i_mode |= S_IFDIR; |
60 | inode->i_op = &bfs_dir_inops; | 62 | inode->i_op = &bfs_dir_inops; |
61 | inode->i_fop = &bfs_dir_operations; | 63 | inode->i_fop = &bfs_dir_operations; |
62 | } else if (di->i_vtype == BFS_VREG) { | 64 | } else if (le32_to_cpu(di->i_vtype) == BFS_VREG) { |
63 | inode->i_mode |= S_IFREG; | 65 | inode->i_mode |= S_IFREG; |
64 | inode->i_op = &bfs_file_inops; | 66 | inode->i_op = &bfs_file_inops; |
65 | inode->i_fop = &bfs_file_operations; | 67 | inode->i_fop = &bfs_file_operations; |
66 | inode->i_mapping->a_ops = &bfs_aops; | 68 | inode->i_mapping->a_ops = &bfs_aops; |
67 | } | 69 | } |
68 | 70 | ||
69 | inode->i_uid = di->i_uid; | 71 | BFS_I(inode)->i_sblock = le32_to_cpu(di->i_sblock); |
70 | inode->i_gid = di->i_gid; | 72 | BFS_I(inode)->i_eblock = le32_to_cpu(di->i_eblock); |
71 | inode->i_nlink = di->i_nlink; | 73 | inode->i_uid = le32_to_cpu(di->i_uid); |
74 | inode->i_gid = le32_to_cpu(di->i_gid); | ||
75 | inode->i_nlink = le32_to_cpu(di->i_nlink); | ||
72 | inode->i_size = BFS_FILESIZE(di); | 76 | inode->i_size = BFS_FILESIZE(di); |
73 | inode->i_blocks = BFS_FILEBLOCKS(di); | 77 | inode->i_blocks = BFS_FILEBLOCKS(di); |
78 | if (inode->i_size || inode->i_blocks) dprintf("Registered inode with %lld size, %ld blocks\n", inode->i_size, inode->i_blocks); | ||
74 | inode->i_blksize = PAGE_SIZE; | 79 | inode->i_blksize = PAGE_SIZE; |
75 | inode->i_atime.tv_sec = di->i_atime; | 80 | inode->i_atime.tv_sec = le32_to_cpu(di->i_atime); |
76 | inode->i_mtime.tv_sec = di->i_mtime; | 81 | inode->i_mtime.tv_sec = le32_to_cpu(di->i_mtime); |
77 | inode->i_ctime.tv_sec = di->i_ctime; | 82 | inode->i_ctime.tv_sec = le32_to_cpu(di->i_ctime); |
78 | inode->i_atime.tv_nsec = 0; | 83 | inode->i_atime.tv_nsec = 0; |
79 | inode->i_mtime.tv_nsec = 0; | 84 | inode->i_mtime.tv_nsec = 0; |
80 | inode->i_ctime.tv_nsec = 0; | 85 | inode->i_ctime.tv_nsec = 0; |
81 | BFS_I(inode)->i_dsk_ino = di->i_ino; /* can be 0 so we store a copy */ | 86 | BFS_I(inode)->i_dsk_ino = le16_to_cpu(di->i_ino); /* can be 0 so we store a copy */ |
82 | BFS_I(inode)->i_sblock = di->i_sblock; | ||
83 | BFS_I(inode)->i_eblock = di->i_eblock; | ||
84 | 87 | ||
85 | brelse(bh); | 88 | brelse(bh); |
86 | } | 89 | } |
87 | 90 | ||
88 | static int bfs_write_inode(struct inode * inode, int unused) | 91 | static int bfs_write_inode(struct inode * inode, int unused) |
89 | { | 92 | { |
90 | unsigned long ino = inode->i_ino; | 93 | unsigned int ino = (u16)inode->i_ino; |
94 | unsigned long i_sblock; | ||
91 | struct bfs_inode * di; | 95 | struct bfs_inode * di; |
92 | struct buffer_head * bh; | 96 | struct buffer_head * bh; |
93 | int block, off; | 97 | int block, off; |
94 | 98 | ||
99 | dprintf("ino=%08x\n", ino); | ||
100 | |||
95 | if (ino < BFS_ROOT_INO || ino > BFS_SB(inode->i_sb)->si_lasti) { | 101 | if (ino < BFS_ROOT_INO || ino > BFS_SB(inode->i_sb)->si_lasti) { |
96 | printf("Bad inode number %s:%08lx\n", inode->i_sb->s_id, ino); | 102 | printf("Bad inode number %s:%08x\n", inode->i_sb->s_id, ino); |
97 | return -EIO; | 103 | return -EIO; |
98 | } | 104 | } |
99 | 105 | ||
@@ -101,7 +107,7 @@ static int bfs_write_inode(struct inode * inode, int unused) | |||
101 | block = (ino - BFS_ROOT_INO)/BFS_INODES_PER_BLOCK + 1; | 107 | block = (ino - BFS_ROOT_INO)/BFS_INODES_PER_BLOCK + 1; |
102 | bh = sb_bread(inode->i_sb, block); | 108 | bh = sb_bread(inode->i_sb, block); |
103 | if (!bh) { | 109 | if (!bh) { |
104 | printf("Unable to read inode %s:%08lx\n", inode->i_sb->s_id, ino); | 110 | printf("Unable to read inode %s:%08x\n", inode->i_sb->s_id, ino); |
105 | unlock_kernel(); | 111 | unlock_kernel(); |
106 | return -EIO; | 112 | return -EIO; |
107 | } | 113 | } |
@@ -109,24 +115,26 @@ static int bfs_write_inode(struct inode * inode, int unused) | |||
109 | off = (ino - BFS_ROOT_INO)%BFS_INODES_PER_BLOCK; | 115 | off = (ino - BFS_ROOT_INO)%BFS_INODES_PER_BLOCK; |
110 | di = (struct bfs_inode *)bh->b_data + off; | 116 | di = (struct bfs_inode *)bh->b_data + off; |
111 | 117 | ||
112 | if (inode->i_ino == BFS_ROOT_INO) | 118 | if (ino == BFS_ROOT_INO) |
113 | di->i_vtype = BFS_VDIR; | 119 | di->i_vtype = cpu_to_le32(BFS_VDIR); |
114 | else | 120 | else |
115 | di->i_vtype = BFS_VREG; | 121 | di->i_vtype = cpu_to_le32(BFS_VREG); |
116 | 122 | ||
117 | di->i_ino = inode->i_ino; | 123 | di->i_ino = cpu_to_le16(ino); |
118 | di->i_mode = inode->i_mode; | 124 | di->i_mode = cpu_to_le32(inode->i_mode); |
119 | di->i_uid = inode->i_uid; | 125 | di->i_uid = cpu_to_le32(inode->i_uid); |
120 | di->i_gid = inode->i_gid; | 126 | di->i_gid = cpu_to_le32(inode->i_gid); |
121 | di->i_nlink = inode->i_nlink; | 127 | di->i_nlink = cpu_to_le32(inode->i_nlink); |
122 | di->i_atime = inode->i_atime.tv_sec; | 128 | di->i_atime = cpu_to_le32(inode->i_atime.tv_sec); |
123 | di->i_mtime = inode->i_mtime.tv_sec; | 129 | di->i_mtime = cpu_to_le32(inode->i_mtime.tv_sec); |
124 | di->i_ctime = inode->i_ctime.tv_sec; | 130 | di->i_ctime = cpu_to_le32(inode->i_ctime.tv_sec); |
125 | di->i_sblock = BFS_I(inode)->i_sblock; | 131 | i_sblock = BFS_I(inode)->i_sblock; |
126 | di->i_eblock = BFS_I(inode)->i_eblock; | 132 | di->i_sblock = cpu_to_le32(i_sblock); |
127 | di->i_eoffset = di->i_sblock * BFS_BSIZE + inode->i_size - 1; | 133 | di->i_eblock = cpu_to_le32(BFS_I(inode)->i_eblock); |
134 | di->i_eoffset = cpu_to_le32(i_sblock * BFS_BSIZE + inode->i_size - 1); | ||
128 | 135 | ||
129 | mark_buffer_dirty(bh); | 136 | mark_buffer_dirty(bh); |
137 | dprintf("Written ino=%d into %d:%d\n",le16_to_cpu(di->i_ino),block,off); | ||
130 | brelse(bh); | 138 | brelse(bh); |
131 | unlock_kernel(); | 139 | unlock_kernel(); |
132 | return 0; | 140 | return 0; |
@@ -140,13 +148,14 @@ static void bfs_delete_inode(struct inode * inode) | |||
140 | int block, off; | 148 | int block, off; |
141 | struct super_block * s = inode->i_sb; | 149 | struct super_block * s = inode->i_sb; |
142 | struct bfs_sb_info * info = BFS_SB(s); | 150 | struct bfs_sb_info * info = BFS_SB(s); |
151 | struct bfs_inode_info * bi = BFS_I(inode); | ||
143 | 152 | ||
144 | dprintf("ino=%08lx\n", inode->i_ino); | 153 | dprintf("ino=%08lx\n", ino); |
145 | 154 | ||
146 | truncate_inode_pages(&inode->i_data, 0); | 155 | truncate_inode_pages(&inode->i_data, 0); |
147 | 156 | ||
148 | if (inode->i_ino < BFS_ROOT_INO || inode->i_ino > info->si_lasti) { | 157 | if (ino < BFS_ROOT_INO || ino > info->si_lasti) { |
149 | printf("invalid ino=%08lx\n", inode->i_ino); | 158 | printf("invalid ino=%08lx\n", ino); |
150 | return; | 159 | return; |
151 | } | 160 | } |
152 | 161 | ||
@@ -162,13 +171,13 @@ static void bfs_delete_inode(struct inode * inode) | |||
162 | return; | 171 | return; |
163 | } | 172 | } |
164 | off = (ino - BFS_ROOT_INO)%BFS_INODES_PER_BLOCK; | 173 | off = (ino - BFS_ROOT_INO)%BFS_INODES_PER_BLOCK; |
165 | di = (struct bfs_inode *)bh->b_data + off; | 174 | di = (struct bfs_inode *) bh->b_data + off; |
166 | if (di->i_ino) { | 175 | if (bi->i_dsk_ino) { |
167 | info->si_freeb += BFS_FILEBLOCKS(di); | 176 | info->si_freeb += 1 + bi->i_eblock - bi->i_sblock; |
168 | info->si_freei++; | 177 | info->si_freei++; |
169 | clear_bit(di->i_ino, info->si_imap); | 178 | clear_bit(ino, info->si_imap); |
170 | dump_imap("delete_inode", s); | 179 | dump_imap("delete_inode", s); |
171 | } | 180 | } |
172 | di->i_ino = 0; | 181 | di->i_ino = 0; |
173 | di->i_sblock = 0; | 182 | di->i_sblock = 0; |
174 | mark_buffer_dirty(bh); | 183 | mark_buffer_dirty(bh); |
@@ -274,14 +283,14 @@ static struct super_operations bfs_sops = { | |||
274 | 283 | ||
275 | void dump_imap(const char *prefix, struct super_block * s) | 284 | void dump_imap(const char *prefix, struct super_block * s) |
276 | { | 285 | { |
277 | #if 0 | 286 | #ifdef DEBUG |
278 | int i; | 287 | int i; |
279 | char *tmpbuf = (char *)get_zeroed_page(GFP_KERNEL); | 288 | char *tmpbuf = (char *)get_zeroed_page(GFP_KERNEL); |
280 | 289 | ||
281 | if (!tmpbuf) | 290 | if (!tmpbuf) |
282 | return; | 291 | return; |
283 | for (i=BFS_SB(s)->si_lasti; i>=0; i--) { | 292 | for (i=BFS_SB(s)->si_lasti; i>=0; i--) { |
284 | if (i>PAGE_SIZE-100) break; | 293 | if (i > PAGE_SIZE-100) break; |
285 | if (test_bit(i, BFS_SB(s)->si_imap)) | 294 | if (test_bit(i, BFS_SB(s)->si_imap)) |
286 | strcat(tmpbuf, "1"); | 295 | strcat(tmpbuf, "1"); |
287 | else | 296 | else |
@@ -297,7 +306,7 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent) | |||
297 | struct buffer_head * bh; | 306 | struct buffer_head * bh; |
298 | struct bfs_super_block * bfs_sb; | 307 | struct bfs_super_block * bfs_sb; |
299 | struct inode * inode; | 308 | struct inode * inode; |
300 | int i, imap_len; | 309 | unsigned i, imap_len; |
301 | struct bfs_sb_info * info; | 310 | struct bfs_sb_info * info; |
302 | 311 | ||
303 | info = kmalloc(sizeof(*info), GFP_KERNEL); | 312 | info = kmalloc(sizeof(*info), GFP_KERNEL); |
@@ -312,19 +321,18 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent) | |||
312 | if(!bh) | 321 | if(!bh) |
313 | goto out; | 322 | goto out; |
314 | bfs_sb = (struct bfs_super_block *)bh->b_data; | 323 | bfs_sb = (struct bfs_super_block *)bh->b_data; |
315 | if (bfs_sb->s_magic != BFS_MAGIC) { | 324 | if (le32_to_cpu(bfs_sb->s_magic) != BFS_MAGIC) { |
316 | if (!silent) | 325 | if (!silent) |
317 | printf("No BFS filesystem on %s (magic=%08x)\n", | 326 | printf("No BFS filesystem on %s (magic=%08x)\n", |
318 | s->s_id, bfs_sb->s_magic); | 327 | s->s_id, le32_to_cpu(bfs_sb->s_magic)); |
319 | goto out; | 328 | goto out; |
320 | } | 329 | } |
321 | if (BFS_UNCLEAN(bfs_sb, s) && !silent) | 330 | if (BFS_UNCLEAN(bfs_sb, s) && !silent) |
322 | printf("%s is unclean, continuing\n", s->s_id); | 331 | printf("%s is unclean, continuing\n", s->s_id); |
323 | 332 | ||
324 | s->s_magic = BFS_MAGIC; | 333 | s->s_magic = BFS_MAGIC; |
325 | info->si_bfs_sb = bfs_sb; | ||
326 | info->si_sbh = bh; | 334 | info->si_sbh = bh; |
327 | info->si_lasti = (bfs_sb->s_start - BFS_BSIZE)/sizeof(struct bfs_inode) | 335 | info->si_lasti = (le32_to_cpu(bfs_sb->s_start) - BFS_BSIZE)/sizeof(struct bfs_inode) |
328 | + BFS_ROOT_INO - 1; | 336 | + BFS_ROOT_INO - 1; |
329 | 337 | ||
330 | imap_len = info->si_lasti/8 + 1; | 338 | imap_len = info->si_lasti/8 + 1; |
@@ -348,8 +356,8 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent) | |||
348 | goto out; | 356 | goto out; |
349 | } | 357 | } |
350 | 358 | ||
351 | info->si_blocks = (bfs_sb->s_end + 1)>>BFS_BSIZE_BITS; /* for statfs(2) */ | 359 | info->si_blocks = (le32_to_cpu(bfs_sb->s_end) + 1)>>BFS_BSIZE_BITS; /* for statfs(2) */ |
352 | info->si_freeb = (bfs_sb->s_end + 1 - bfs_sb->s_start)>>BFS_BSIZE_BITS; | 360 | info->si_freeb = (le32_to_cpu(bfs_sb->s_end) + 1 - cpu_to_le32(bfs_sb->s_start))>>BFS_BSIZE_BITS; |
353 | info->si_freei = 0; | 361 | info->si_freei = 0; |
354 | info->si_lf_eblk = 0; | 362 | info->si_lf_eblk = 0; |
355 | info->si_lf_sblk = 0; | 363 | info->si_lf_sblk = 0; |