Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Fixes to the BFS filesystem driver

I found a few bugs in the BFS driver. Detailed description of the bugs as
well as the steps to reproduce the errors are given in the kernel bugzilla.
Please follow these links for more information:

http://bugzilla.kernel.org/show_bug.cgi?id=9363
http://bugzilla.kernel.org/show_bug.cgi?id=9364
http://bugzilla.kernel.org/show_bug.cgi?id=9365
http://bugzilla.kernel.org/show_bug.cgi?id=9366

This patch fixes the bugs described above. Besides, the patch introduces
coding style changes to make the BFS driver conform to the requirements
specified for Linux kernel code. Finally, I made a few cosmetic changes
such as removal of trivial debug output.

Also, the patch removes the fields `si_lf_ioff' and `si_lf_sblk' of the
in-core superblock structure. These fields are initialized but never
actually used.

If you are wondering why I need BFS, here is the answer: I am using this
driver in the context of Linux kernel classes I am teaching in the Moscow
State University and in the International Institute of Information
Technology in Pune, India.

Signed-off-by: Dmitri Vorobiev <dmitri.vorobiev@gmail.com>
Cc: Tigran Aivazian <tigran@veritas.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Dmitri Vorobiev and committed by
Linus Torvalds
f433dc56 cfb52856

+184 -155
+1 -3
fs/bfs/bfs.h
··· 14 14 unsigned long si_blocks; 15 15 unsigned long si_freeb; 16 16 unsigned long si_freei; 17 - unsigned long si_lf_ioff; 18 - unsigned long si_lf_sblk; 19 17 unsigned long si_lf_eblk; 20 18 unsigned long si_lasti; 21 19 unsigned long * si_imap; ··· 37 39 38 40 static inline struct bfs_inode_info *BFS_I(struct inode *inode) 39 41 { 40 - return list_entry(inode, struct bfs_inode_info, vfs_inode); 42 + return container_of(inode, struct bfs_inode_info, vfs_inode); 41 43 } 42 44 43 45
+78 -68
fs/bfs/dir.c
··· 21 21 #define dprintf(x...) 22 22 #endif 23 23 24 - static int bfs_add_entry(struct inode * dir, const unsigned char * name, int namelen, int ino); 25 - static struct buffer_head * bfs_find_entry(struct inode * dir, 26 - const unsigned char * name, int namelen, struct bfs_dirent ** res_dir); 24 + static int bfs_add_entry(struct inode *dir, const unsigned char *name, 25 + int namelen, int ino); 26 + static struct buffer_head *bfs_find_entry(struct inode *dir, 27 + const unsigned char *name, int namelen, 28 + struct bfs_dirent **res_dir); 27 29 28 - static int bfs_readdir(struct file * f, void * dirent, filldir_t filldir) 30 + static int bfs_readdir(struct file *f, void *dirent, filldir_t filldir) 29 31 { 30 - struct inode * dir = f->f_path.dentry->d_inode; 31 - struct buffer_head * bh; 32 - struct bfs_dirent * de; 32 + struct inode *dir = f->f_path.dentry->d_inode; 33 + struct buffer_head *bh; 34 + struct bfs_dirent *de; 33 35 unsigned int offset; 34 36 int block; 35 37 36 38 lock_kernel(); 37 39 38 - if (f->f_pos & (BFS_DIRENT_SIZE-1)) { 39 - printf("Bad f_pos=%08lx for %s:%08lx\n", (unsigned long)f->f_pos, 40 - dir->i_sb->s_id, dir->i_ino); 40 + if (f->f_pos & (BFS_DIRENT_SIZE - 1)) { 41 + printf("Bad f_pos=%08lx for %s:%08lx\n", 42 + (unsigned long)f->f_pos, 43 + dir->i_sb->s_id, dir->i_ino); 41 44 unlock_kernel(); 42 45 return -EBADF; 43 46 } 44 47 45 48 while (f->f_pos < dir->i_size) { 46 - offset = f->f_pos & (BFS_BSIZE-1); 49 + offset = f->f_pos & (BFS_BSIZE - 1); 47 50 block = BFS_I(dir)->i_sblock + (f->f_pos >> BFS_BSIZE_BITS); 48 51 bh = sb_bread(dir->i_sb, block); 49 52 if (!bh) { ··· 57 54 de = (struct bfs_dirent *)(bh->b_data + offset); 58 55 if (de->ino) { 59 56 int size = strnlen(de->name, BFS_NAMELEN); 60 - if (filldir(dirent, de->name, size, f->f_pos, le16_to_cpu(de->ino), DT_UNKNOWN) < 0) { 57 + if (filldir(dirent, de->name, size, f->f_pos, 58 + le16_to_cpu(de->ino), 59 + DT_UNKNOWN) < 0) { 61 60 brelse(bh); 62 61 unlock_kernel(); 63 62 return 0; ··· 67 62 } 68 63 offset += BFS_DIRENT_SIZE; 69 64 f->f_pos += BFS_DIRENT_SIZE; 70 - } while (offset < BFS_BSIZE && f->f_pos < dir->i_size); 65 + } while ((offset < BFS_BSIZE) && (f->f_pos < dir->i_size)); 71 66 brelse(bh); 72 67 } 73 68 ··· 83 78 84 79 extern void dump_imap(const char *, struct super_block *); 85 80 86 - static int bfs_create(struct inode * dir, struct dentry * dentry, int mode, 87 - struct nameidata *nd) 81 + static int bfs_create(struct inode *dir, struct dentry *dentry, int mode, 82 + struct nameidata *nd) 88 83 { 89 84 int err; 90 - struct inode * inode; 91 - struct super_block * s = dir->i_sb; 92 - struct bfs_sb_info * info = BFS_SB(s); 85 + struct inode *inode; 86 + struct super_block *s = dir->i_sb; 87 + struct bfs_sb_info *info = BFS_SB(s); 93 88 unsigned long ino; 94 89 95 90 inode = new_inode(s); ··· 102 97 iput(inode); 103 98 return -ENOSPC; 104 99 } 105 - set_bit(ino, info->si_imap); 100 + set_bit(ino, info->si_imap); 106 101 info->si_freei--; 107 102 inode->i_uid = current->fsuid; 108 103 inode->i_gid = (dir->i_mode & S_ISGID) ? dir->i_gid : current->fsgid; ··· 118 113 BFS_I(inode)->i_eblock = 0; 119 114 insert_inode_hash(inode); 120 115 mark_inode_dirty(inode); 121 - dump_imap("create",s); 116 + dump_imap("create", s); 122 117 123 - err = bfs_add_entry(dir, dentry->d_name.name, dentry->d_name.len, inode->i_ino); 118 + err = bfs_add_entry(dir, dentry->d_name.name, dentry->d_name.len, 119 + inode->i_ino); 124 120 if (err) { 125 121 inode_dec_link_count(inode); 126 122 iput(inode); ··· 133 127 return 0; 134 128 } 135 129 136 - static struct dentry * bfs_lookup(struct inode * dir, struct dentry * dentry, struct nameidata *nd) 130 + static struct dentry *bfs_lookup(struct inode *dir, struct dentry *dentry, 131 + struct nameidata *nd) 137 132 { 138 - struct inode * inode = NULL; 139 - struct buffer_head * bh; 140 - struct bfs_dirent * de; 133 + struct inode *inode = NULL; 134 + struct buffer_head *bh; 135 + struct bfs_dirent *de; 141 136 142 137 if (dentry->d_name.len > BFS_NAMELEN) 143 138 return ERR_PTR(-ENAMETOOLONG); ··· 159 152 return NULL; 160 153 } 161 154 162 - static int bfs_link(struct dentry * old, struct inode * dir, struct dentry * new) 155 + static int bfs_link(struct dentry *old, struct inode *dir, 156 + struct dentry *new) 163 157 { 164 - struct inode * inode = old->d_inode; 158 + struct inode *inode = old->d_inode; 165 159 int err; 166 160 167 161 lock_kernel(); 168 - err = bfs_add_entry(dir, new->d_name.name, new->d_name.len, inode->i_ino); 162 + err = bfs_add_entry(dir, new->d_name.name, new->d_name.len, 163 + inode->i_ino); 169 164 if (err) { 170 165 unlock_kernel(); 171 166 return err; ··· 181 172 return 0; 182 173 } 183 174 184 - 185 - static int bfs_unlink(struct inode * dir, struct dentry * dentry) 175 + static int bfs_unlink(struct inode *dir, struct dentry *dentry) 186 176 { 187 177 int error = -ENOENT; 188 - struct inode * inode; 189 - struct buffer_head * bh; 190 - struct bfs_dirent * de; 178 + struct inode *inode; 179 + struct buffer_head *bh; 180 + struct bfs_dirent *de; 191 181 192 182 inode = dentry->d_inode; 193 183 lock_kernel(); 194 184 bh = bfs_find_entry(dir, dentry->d_name.name, dentry->d_name.len, &de); 195 - if (!bh || le16_to_cpu(de->ino) != inode->i_ino) 185 + if (!bh || (le16_to_cpu(de->ino) != inode->i_ino)) 196 186 goto out_brelse; 197 187 198 188 if (!inode->i_nlink) { 199 - printf("unlinking non-existent file %s:%lu (nlink=%d)\n", inode->i_sb->s_id, 200 - inode->i_ino, inode->i_nlink); 189 + printf("unlinking non-existent file %s:%lu (nlink=%d)\n", 190 + inode->i_sb->s_id, inode->i_ino, 191 + inode->i_nlink); 201 192 inode->i_nlink = 1; 202 193 } 203 194 de->ino = 0; ··· 214 205 return error; 215 206 } 216 207 217 - static int bfs_rename(struct inode * old_dir, struct dentry * old_dentry, 218 - struct inode * new_dir, struct dentry * new_dentry) 208 + static int bfs_rename(struct inode *old_dir, struct dentry *old_dentry, 209 + struct inode *new_dir, struct dentry *new_dentry) 219 210 { 220 - struct inode * old_inode, * new_inode; 221 - struct buffer_head * old_bh, * new_bh; 222 - struct bfs_dirent * old_de, * new_de; 211 + struct inode *old_inode, *new_inode; 212 + struct buffer_head *old_bh, *new_bh; 213 + struct bfs_dirent *old_de, *new_de; 223 214 int error = -ENOENT; 224 215 225 216 old_bh = new_bh = NULL; ··· 232 223 old_dentry->d_name.name, 233 224 old_dentry->d_name.len, &old_de); 234 225 235 - if (!old_bh || le16_to_cpu(old_de->ino) != old_inode->i_ino) 226 + if (!old_bh || (le16_to_cpu(old_de->ino) != old_inode->i_ino)) 236 227 goto end_rename; 237 228 238 229 error = -EPERM; ··· 248 239 if (!new_bh) { 249 240 error = bfs_add_entry(new_dir, 250 241 new_dentry->d_name.name, 251 - new_dentry->d_name.len, old_inode->i_ino); 242 + new_dentry->d_name.len, 243 + old_inode->i_ino); 252 244 if (error) 253 245 goto end_rename; 254 246 } ··· 278 268 .rename = bfs_rename, 279 269 }; 280 270 281 - static int bfs_add_entry(struct inode * dir, const unsigned char * name, int namelen, int ino) 271 + static int bfs_add_entry(struct inode *dir, const unsigned char *name, 272 + int namelen, int ino) 282 273 { 283 - struct buffer_head * bh; 284 - struct bfs_dirent * de; 285 - int block, sblock, eblock, off, eoff; 274 + struct buffer_head *bh; 275 + struct bfs_dirent *de; 276 + int block, sblock, eblock, off, pos; 286 277 int i; 287 278 288 279 dprintf("name=%s, namelen=%d\n", name, namelen); ··· 295 284 296 285 sblock = BFS_I(dir)->i_sblock; 297 286 eblock = BFS_I(dir)->i_eblock; 298 - eoff = dir->i_size % BFS_BSIZE; 299 - for (block=sblock; block<=eblock; block++) { 287 + for (block = sblock; block <= eblock; block++) { 300 288 bh = sb_bread(dir->i_sb, block); 301 - if(!bh) 289 + if (!bh) 302 290 return -ENOSPC; 303 - for (off=0; off<BFS_BSIZE; off+=BFS_DIRENT_SIZE) { 291 + for (off = 0; off < BFS_BSIZE; off += BFS_DIRENT_SIZE) { 304 292 de = (struct bfs_dirent *)(bh->b_data + off); 305 - if (block==eblock && off>=eoff) { 306 - /* Do not read/interpret the garbage in the end of eblock. */ 307 - de->ino = 0; 308 - } 309 293 if (!de->ino) { 310 - if ((block-sblock)*BFS_BSIZE + off >= dir->i_size) { 294 + pos = (block - sblock) * BFS_BSIZE + off; 295 + if (pos >= dir->i_size) { 311 296 dir->i_size += BFS_DIRENT_SIZE; 312 297 dir->i_ctime = CURRENT_TIME_SEC; 313 298 } 314 299 dir->i_mtime = CURRENT_TIME_SEC; 315 300 mark_inode_dirty(dir); 316 301 de->ino = cpu_to_le16((u16)ino); 317 - for (i=0; i<BFS_NAMELEN; i++) 318 - de->name[i] = (i < namelen) ? name[i] : 0; 302 + for (i = 0; i < BFS_NAMELEN; i++) 303 + de->name[i] = 304 + (i < namelen) ? name[i] : 0; 319 305 mark_buffer_dirty(bh); 320 306 brelse(bh); 321 307 return 0; ··· 323 315 return -ENOSPC; 324 316 } 325 317 326 - static inline int bfs_namecmp(int len, const unsigned char * name, const char * buffer) 318 + static inline int bfs_namecmp(int len, const unsigned char *name, 319 + const char *buffer) 327 320 { 328 - if (len < BFS_NAMELEN && buffer[len]) 321 + if ((len < BFS_NAMELEN) && buffer[len]) 329 322 return 0; 330 323 return !memcmp(name, buffer, len); 331 324 } 332 325 333 - static struct buffer_head * bfs_find_entry(struct inode * dir, 334 - const unsigned char * name, int namelen, struct bfs_dirent ** res_dir) 326 + static struct buffer_head *bfs_find_entry(struct inode *dir, 327 + const unsigned char *name, int namelen, 328 + struct bfs_dirent **res_dir) 335 329 { 336 - unsigned long block, offset; 337 - struct buffer_head * bh; 338 - struct bfs_dirent * de; 330 + unsigned long block = 0, offset = 0; 331 + struct buffer_head *bh = NULL; 332 + struct bfs_dirent *de; 339 333 340 334 *res_dir = NULL; 341 335 if (namelen > BFS_NAMELEN) 342 336 return NULL; 343 - bh = NULL; 344 - block = offset = 0; 337 + 345 338 while (block * BFS_BSIZE + offset < dir->i_size) { 346 339 if (!bh) { 347 340 bh = sb_bread(dir->i_sb, BFS_I(dir)->i_sblock + block); ··· 353 344 } 354 345 de = (struct bfs_dirent *)(bh->b_data + offset); 355 346 offset += BFS_DIRENT_SIZE; 356 - if (le16_to_cpu(de->ino) && bfs_namecmp(namelen, name, de->name)) { 347 + if (le16_to_cpu(de->ino) && 348 + bfs_namecmp(namelen, name, de->name)) { 357 349 *res_dir = de; 358 350 return bh; 359 351 }
+41 -21
fs/bfs/file.c
··· 2 2 * fs/bfs/file.c 3 3 * BFS file operations. 4 4 * Copyright (C) 1999,2000 Tigran Aivazian <tigran@veritas.com> 5 + * 6 + * Make the file block allocation algorithm understand the size 7 + * of the underlying block device. 8 + * Copyright (C) 2007 Dmitri Vorobiev <dmitri.vorobiev@gmail.com> 9 + * 5 10 */ 6 11 7 12 #include <linux/fs.h> ··· 32 27 .splice_read = generic_file_splice_read, 33 28 }; 34 29 35 - static int bfs_move_block(unsigned long from, unsigned long to, struct super_block *sb) 30 + static int bfs_move_block(unsigned long from, unsigned long to, 31 + struct super_block *sb) 36 32 { 37 33 struct buffer_head *bh, *new; 38 34 ··· 49 43 } 50 44 51 45 static int bfs_move_blocks(struct super_block *sb, unsigned long start, 52 - unsigned long end, unsigned long where) 46 + unsigned long end, unsigned long where) 53 47 { 54 48 unsigned long i; 55 49 56 50 dprintf("%08lx-%08lx->%08lx\n", start, end, where); 57 51 for (i = start; i <= end; i++) 58 52 if(bfs_move_block(i, where + i, sb)) { 59 - dprintf("failed to move block %08lx -> %08lx\n", i, where + i); 53 + dprintf("failed to move block %08lx -> %08lx\n", i, 54 + where + i); 60 55 return -EIO; 61 56 } 62 57 return 0; 63 58 } 64 59 65 - static int bfs_get_block(struct inode * inode, sector_t block, 66 - struct buffer_head * bh_result, int create) 60 + static int bfs_get_block(struct inode *inode, sector_t block, 61 + struct buffer_head *bh_result, int create) 67 62 { 68 63 unsigned long phys; 69 64 int err; ··· 72 65 struct bfs_sb_info *info = BFS_SB(sb); 73 66 struct bfs_inode_info *bi = BFS_I(inode); 74 67 struct buffer_head *sbh = info->si_sbh; 75 - 76 - if (block > info->si_blocks) 77 - return -EIO; 78 68 79 69 phys = bi->i_sblock + block; 80 70 if (!create) { ··· 83 79 return 0; 84 80 } 85 81 86 - /* if the file is not empty and the requested block is within the range 87 - of blocks allocated for this file, we can grant it */ 88 - if (inode->i_size && phys <= bi->i_eblock) { 82 + /* 83 + * If the file is not empty and the requested block is within the 84 + * range of blocks allocated for this file, we can grant it. 85 + */ 86 + if (bi->i_sblock && (phys <= bi->i_eblock)) { 89 87 dprintf("c=%d, b=%08lx, phys=%08lx (interim block granted)\n", 90 88 create, (unsigned long)block, phys); 91 89 map_bh(bh_result, sb, phys); 92 90 return 0; 93 91 } 94 92 95 - /* the rest has to be protected against itself */ 93 + /* The file will be extended, so let's see if there is enough space. */ 94 + if (phys >= info->si_blocks) 95 + return -ENOSPC; 96 + 97 + /* The rest has to be protected against itself. */ 96 98 lock_kernel(); 97 99 98 - /* if the last data block for this file is the last allocated 99 - block, we can extend the file trivially, without moving it 100 - anywhere */ 100 + /* 101 + * If the last data block for this file is the last allocated 102 + * block, we can extend the file trivially, without moving it 103 + * anywhere. 104 + */ 101 105 if (bi->i_eblock == info->si_lf_eblk) { 102 106 dprintf("c=%d, b=%08lx, phys=%08lx (simple extension)\n", 103 107 create, (unsigned long)block, phys); ··· 118 106 goto out; 119 107 } 120 108 121 - /* Ok, we have to move this entire file to the next free block */ 109 + /* Ok, we have to move this entire file to the next free block. */ 122 110 phys = info->si_lf_eblk + 1; 123 - if (bi->i_sblock) { /* if data starts on block 0 then there is no data */ 111 + if (phys + block >= info->si_blocks) { 112 + err = -ENOSPC; 113 + goto out; 114 + } 115 + 116 + if (bi->i_sblock) { 124 117 err = bfs_move_blocks(inode->i_sb, bi->i_sblock, 125 - bi->i_eblock, phys); 118 + bi->i_eblock, phys); 126 119 if (err) { 127 - dprintf("failed to move ino=%08lx -> fs corruption\n", inode->i_ino); 120 + dprintf("failed to move ino=%08lx -> fs corruption\n", 121 + inode->i_ino); 128 122 goto out; 129 123 } 130 124 } else ··· 142 124 phys += block; 143 125 info->si_lf_eblk = bi->i_eblock = phys; 144 126 145 - /* this assumes nothing can write the inode back while we are here 146 - * and thus update inode->i_blocks! (XXX)*/ 127 + /* 128 + * This assumes nothing can write the inode back while we are here 129 + * and thus update inode->i_blocks! (XXX) 130 + */ 147 131 info->si_freeb -= bi->i_eblock - bi->i_sblock + 1 - inode->i_blocks; 148 132 mark_inode_dirty(inode); 149 133 mark_buffer_dirty(sbh);
+64 -63
fs/bfs/inode.c
··· 30 30 #define dprintf(x...) 31 31 #endif 32 32 33 - void dump_imap(const char *prefix, struct super_block * s); 33 + void dump_imap(const char *prefix, struct super_block *s); 34 34 35 - static void bfs_read_inode(struct inode * inode) 35 + static void bfs_read_inode(struct inode *inode) 36 36 { 37 37 unsigned long ino = inode->i_ino; 38 - struct bfs_inode * di; 39 - struct buffer_head * bh; 38 + struct bfs_inode *di; 39 + struct buffer_head *bh; 40 40 int block, off; 41 41 42 - if (ino < BFS_ROOT_INO || ino > BFS_SB(inode->i_sb)->si_lasti) { 42 + if ((ino < BFS_ROOT_INO) || (ino > BFS_SB(inode->i_sb)->si_lasti)) { 43 43 printf("Bad inode number %s:%08lx\n", inode->i_sb->s_id, ino); 44 44 make_bad_inode(inode); 45 45 return; 46 46 } 47 47 48 - block = (ino - BFS_ROOT_INO)/BFS_INODES_PER_BLOCK + 1; 48 + block = (ino - BFS_ROOT_INO) / BFS_INODES_PER_BLOCK + 1; 49 49 bh = sb_bread(inode->i_sb, block); 50 50 if (!bh) { 51 - printf("Unable to read inode %s:%08lx\n", inode->i_sb->s_id, ino); 51 + printf("Unable to read inode %s:%08lx\n", inode->i_sb->s_id, 52 + ino); 52 53 make_bad_inode(inode); 53 54 return; 54 55 } ··· 57 56 off = (ino - BFS_ROOT_INO) % BFS_INODES_PER_BLOCK; 58 57 di = (struct bfs_inode *)bh->b_data + off; 59 58 60 - inode->i_mode = 0x0000FFFF & le32_to_cpu(di->i_mode); 59 + inode->i_mode = 0x0000FFFF & le32_to_cpu(di->i_mode); 61 60 if (le32_to_cpu(di->i_vtype) == BFS_VDIR) { 62 61 inode->i_mode |= S_IFDIR; 63 62 inode->i_op = &bfs_dir_inops; ··· 71 70 72 71 BFS_I(inode)->i_sblock = le32_to_cpu(di->i_sblock); 73 72 BFS_I(inode)->i_eblock = le32_to_cpu(di->i_eblock); 73 + BFS_I(inode)->i_dsk_ino = le16_to_cpu(di->i_ino); 74 74 inode->i_uid = le32_to_cpu(di->i_uid); 75 75 inode->i_gid = le32_to_cpu(di->i_gid); 76 76 inode->i_nlink = le32_to_cpu(di->i_nlink); 77 77 inode->i_size = BFS_FILESIZE(di); 78 78 inode->i_blocks = BFS_FILEBLOCKS(di); 79 - if (inode->i_size || inode->i_blocks) dprintf("Registered inode with %lld size, %ld blocks\n", inode->i_size, inode->i_blocks); 80 79 inode->i_atime.tv_sec = le32_to_cpu(di->i_atime); 81 80 inode->i_mtime.tv_sec = le32_to_cpu(di->i_mtime); 82 81 inode->i_ctime.tv_sec = le32_to_cpu(di->i_ctime); 83 82 inode->i_atime.tv_nsec = 0; 84 83 inode->i_mtime.tv_nsec = 0; 85 84 inode->i_ctime.tv_nsec = 0; 86 - BFS_I(inode)->i_dsk_ino = le16_to_cpu(di->i_ino); /* can be 0 so we store a copy */ 87 85 88 86 brelse(bh); 89 87 } 90 88 91 - static int bfs_write_inode(struct inode * inode, int unused) 89 + static int bfs_write_inode(struct inode *inode, int unused) 92 90 { 93 91 unsigned int ino = (u16)inode->i_ino; 94 92 unsigned long i_sblock; 95 - struct bfs_inode * di; 96 - struct buffer_head * bh; 93 + struct bfs_inode *di; 94 + struct buffer_head *bh; 97 95 int block, off; 98 96 99 97 dprintf("ino=%08x\n", ino); 100 98 101 - if (ino < BFS_ROOT_INO || ino > BFS_SB(inode->i_sb)->si_lasti) { 99 + if ((ino < BFS_ROOT_INO) || (ino > BFS_SB(inode->i_sb)->si_lasti)) { 102 100 printf("Bad inode number %s:%08x\n", inode->i_sb->s_id, ino); 103 101 return -EIO; 104 102 } 105 103 106 104 lock_kernel(); 107 - block = (ino - BFS_ROOT_INO)/BFS_INODES_PER_BLOCK + 1; 105 + block = (ino - BFS_ROOT_INO) / BFS_INODES_PER_BLOCK + 1; 108 106 bh = sb_bread(inode->i_sb, block); 109 107 if (!bh) { 110 - printf("Unable to read inode %s:%08x\n", inode->i_sb->s_id, ino); 108 + printf("Unable to read inode %s:%08x\n", 109 + inode->i_sb->s_id, ino); 111 110 unlock_kernel(); 112 111 return -EIO; 113 112 } 114 113 115 - off = (ino - BFS_ROOT_INO)%BFS_INODES_PER_BLOCK; 114 + off = (ino - BFS_ROOT_INO) % BFS_INODES_PER_BLOCK; 116 115 di = (struct bfs_inode *)bh->b_data + off; 117 116 118 117 if (ino == BFS_ROOT_INO) ··· 134 133 di->i_eoffset = cpu_to_le32(i_sblock * BFS_BSIZE + inode->i_size - 1); 135 134 136 135 mark_buffer_dirty(bh); 137 - dprintf("Written ino=%d into %d:%d\n",le16_to_cpu(di->i_ino),block,off); 138 136 brelse(bh); 139 137 unlock_kernel(); 140 138 return 0; 141 139 } 142 140 143 - static void bfs_delete_inode(struct inode * inode) 141 + static void bfs_delete_inode(struct inode *inode) 144 142 { 145 143 unsigned long ino = inode->i_ino; 146 - struct bfs_inode * di; 147 - struct buffer_head * bh; 144 + struct bfs_inode *di; 145 + struct buffer_head *bh; 148 146 int block, off; 149 - struct super_block * s = inode->i_sb; 150 - struct bfs_sb_info * info = BFS_SB(s); 151 - struct bfs_inode_info * bi = BFS_I(inode); 147 + struct super_block *s = inode->i_sb; 148 + struct bfs_sb_info *info = BFS_SB(s); 149 + struct bfs_inode_info *bi = BFS_I(inode); 152 150 153 151 dprintf("ino=%08lx\n", ino); 154 152 155 153 truncate_inode_pages(&inode->i_data, 0); 156 154 157 - if (ino < BFS_ROOT_INO || ino > info->si_lasti) { 155 + if ((ino < BFS_ROOT_INO) || (ino > info->si_lasti)) { 158 156 printf("invalid ino=%08lx\n", ino); 159 157 return; 160 158 } ··· 162 162 inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME_SEC; 163 163 lock_kernel(); 164 164 mark_inode_dirty(inode); 165 - block = (ino - BFS_ROOT_INO)/BFS_INODES_PER_BLOCK + 1; 165 + 166 + block = (ino - BFS_ROOT_INO) / BFS_INODES_PER_BLOCK + 1; 166 167 bh = sb_bread(s, block); 167 168 if (!bh) { 168 - printf("Unable to read inode %s:%08lx\n", inode->i_sb->s_id, ino); 169 + printf("Unable to read inode %s:%08lx\n", 170 + inode->i_sb->s_id, ino); 169 171 unlock_kernel(); 170 172 return; 171 173 } 172 - off = (ino - BFS_ROOT_INO)%BFS_INODES_PER_BLOCK; 173 - di = (struct bfs_inode *) bh->b_data + off; 174 + off = (ino - BFS_ROOT_INO) % BFS_INODES_PER_BLOCK; 175 + di = (struct bfs_inode *)bh->b_data + off; 176 + memset((void *)di, 0, sizeof(struct bfs_inode)); 177 + mark_buffer_dirty(bh); 178 + brelse(bh); 179 + 174 180 if (bi->i_dsk_ino) { 175 - info->si_freeb += 1 + bi->i_eblock - bi->i_sblock; 181 + info->si_freeb += BFS_FILEBLOCKS(bi); 176 182 info->si_freei++; 177 183 clear_bit(ino, info->si_imap); 178 184 dump_imap("delete_inode", s); 179 185 } 180 - di->i_ino = 0; 181 - di->i_sblock = 0; 182 - mark_buffer_dirty(bh); 183 - brelse(bh); 184 186 185 - /* if this was the last file, make the previous 186 - block "last files last block" even if there is no real file there, 187 - saves us 1 gap */ 188 - if (info->si_lf_eblk == BFS_I(inode)->i_eblock) { 189 - info->si_lf_eblk = BFS_I(inode)->i_sblock - 1; 187 + /* 188 + * If this was the last file, make the previous block 189 + * "last block of the last file" even if there is no 190 + * real file there, saves us 1 gap. 191 + */ 192 + if (info->si_lf_eblk == bi->i_eblock) { 193 + info->si_lf_eblk = bi->i_sblock - 1; 190 194 mark_buffer_dirty(info->si_sbh); 191 195 } 192 196 unlock_kernel(); ··· 232 228 unlock_kernel(); 233 229 } 234 230 235 - static struct kmem_cache * bfs_inode_cachep; 231 + static struct kmem_cache *bfs_inode_cachep; 236 232 237 233 static struct inode *bfs_alloc_inode(struct super_block *sb) 238 234 { ··· 283 279 .statfs = bfs_statfs, 284 280 }; 285 281 286 - void dump_imap(const char *prefix, struct super_block * s) 282 + void dump_imap(const char *prefix, struct super_block *s) 287 283 { 288 284 #ifdef DEBUG 289 285 int i; ··· 291 287 292 288 if (!tmpbuf) 293 289 return; 294 - for (i=BFS_SB(s)->si_lasti; i>=0; i--) { 295 - if (i > PAGE_SIZE-100) break; 290 + for (i = BFS_SB(s)->si_lasti; i >= 0; i--) { 291 + if (i > PAGE_SIZE - 100) break; 296 292 if (test_bit(i, BFS_SB(s)->si_imap)) 297 293 strcat(tmpbuf, "1"); 298 294 else 299 295 strcat(tmpbuf, "0"); 300 296 } 301 - printk(KERN_ERR "BFS-fs: %s: lasti=%08lx <%s>\n", prefix, BFS_SB(s)->si_lasti, tmpbuf); 297 + printf("BFS-fs: %s: lasti=%08lx <%s>\n", 298 + prefix, BFS_SB(s)->si_lasti, tmpbuf); 302 299 free_page((unsigned long)tmpbuf); 303 300 #endif 304 301 } 305 302 306 303 static int bfs_fill_super(struct super_block *s, void *data, int silent) 307 304 { 308 - struct buffer_head * bh; 309 - struct bfs_super_block * bfs_sb; 310 - struct inode * inode; 305 + struct buffer_head *bh; 306 + struct bfs_super_block *bfs_sb; 307 + struct inode *inode; 311 308 unsigned i, imap_len; 312 - struct bfs_sb_info * info; 309 + struct bfs_sb_info *info; 313 310 314 311 info = kzalloc(sizeof(*info), GFP_KERNEL); 315 312 if (!info) ··· 334 329 335 330 s->s_magic = BFS_MAGIC; 336 331 info->si_sbh = bh; 337 - info->si_lasti = (le32_to_cpu(bfs_sb->s_start) - BFS_BSIZE)/sizeof(struct bfs_inode) 338 - + BFS_ROOT_INO - 1; 339 - 340 - imap_len = info->si_lasti/8 + 1; 332 + info->si_lasti = (le32_to_cpu(bfs_sb->s_start) - BFS_BSIZE) / 333 + sizeof(struct bfs_inode) 334 + + BFS_ROOT_INO - 1; 335 + imap_len = (info->si_lasti / 8) + 1; 341 336 info->si_imap = kzalloc(imap_len, GFP_KERNEL); 342 337 if (!info->si_imap) 343 338 goto out; 344 - for (i=0; i<BFS_ROOT_INO; i++) 339 + for (i = 0; i < BFS_ROOT_INO; i++) 345 340 set_bit(i, info->si_imap); 346 341 347 342 s->s_op = &bfs_sops; ··· 357 352 goto out; 358 353 } 359 354 360 - info->si_blocks = (le32_to_cpu(bfs_sb->s_end) + 1)>>BFS_BSIZE_BITS; /* for statfs(2) */ 361 - info->si_freeb = (le32_to_cpu(bfs_sb->s_end) + 1 - le32_to_cpu(bfs_sb->s_start))>>BFS_BSIZE_BITS; 355 + info->si_blocks = (le32_to_cpu(bfs_sb->s_end) + 1) >> BFS_BSIZE_BITS; 356 + info->si_freeb = (le32_to_cpu(bfs_sb->s_end) + 1 357 + - le32_to_cpu(bfs_sb->s_start)) >> BFS_BSIZE_BITS; 362 358 info->si_freei = 0; 363 359 info->si_lf_eblk = 0; 364 - info->si_lf_sblk = 0; 365 - info->si_lf_ioff = 0; 366 360 bh = NULL; 367 - for (i=BFS_ROOT_INO; i<=info->si_lasti; i++) { 361 + for (i = BFS_ROOT_INO; i <= info->si_lasti; i++) { 368 362 struct bfs_inode *di; 369 - int block = (i - BFS_ROOT_INO)/BFS_INODES_PER_BLOCK + 1; 363 + int block = (i - BFS_ROOT_INO) / BFS_INODES_PER_BLOCK + 1; 370 364 int off = (i - BFS_ROOT_INO) % BFS_INODES_PER_BLOCK; 371 365 unsigned long sblock, eblock; 372 366 ··· 388 384 389 385 sblock = le32_to_cpu(di->i_sblock); 390 386 eblock = le32_to_cpu(di->i_eblock); 391 - if (eblock > info->si_lf_eblk) { 387 + if (eblock > info->si_lf_eblk) 392 388 info->si_lf_eblk = eblock; 393 - info->si_lf_sblk = sblock; 394 - info->si_lf_ioff = BFS_INO2OFF(i); 395 - } 396 389 } 397 390 brelse(bh); 398 391 if (!(s->s_flags & MS_RDONLY)) {