1
1
/*
2
2
* fs/bfs/inode.c
3
3
* BFS superblock and inode operations.
4
- * Copyright (C) 1999-2006 Tigran Aivazian <[email protected] >
4
+ * Copyright (C) 1999-2018 Tigran Aivazian <[email protected] >
5
5
* From fs/minix, Copyright (C) 1991, 1992 Linus Torvalds.
6
- *
7
- * Made endianness-clean by Andrew Stribblehill <[email protected] >, 2005.
6
+ * Made endianness-clean by Andrew Stribblehill <[email protected] >, 2005.
8
7
*/
9
8
10
9
#include <linux/module.h>
@@ -118,12 +117,12 @@ static int bfs_write_inode(struct inode *inode, struct writeback_control *wbc)
118
117
{
119
118
struct bfs_sb_info * info = BFS_SB (inode -> i_sb );
120
119
unsigned int ino = (u16 )inode -> i_ino ;
121
- unsigned long i_sblock ;
120
+ unsigned long i_sblock ;
122
121
struct bfs_inode * di ;
123
122
struct buffer_head * bh ;
124
123
int err = 0 ;
125
124
126
- dprintf ("ino=%08x\n" , ino );
125
+ dprintf ("ino=%08x\n" , ino );
127
126
128
127
di = find_inode (inode -> i_sb , ino , & bh );
129
128
if (IS_ERR (di ))
@@ -144,7 +143,7 @@ static int bfs_write_inode(struct inode *inode, struct writeback_control *wbc)
144
143
di -> i_atime = cpu_to_le32 (inode -> i_atime .tv_sec );
145
144
di -> i_mtime = cpu_to_le32 (inode -> i_mtime .tv_sec );
146
145
di -> i_ctime = cpu_to_le32 (inode -> i_ctime .tv_sec );
147
- i_sblock = BFS_I (inode )-> i_sblock ;
146
+ i_sblock = BFS_I (inode )-> i_sblock ;
148
147
di -> i_sblock = cpu_to_le32 (i_sblock );
149
148
di -> i_eblock = cpu_to_le32 (BFS_I (inode )-> i_eblock );
150
149
di -> i_eoffset = cpu_to_le32 (i_sblock * BFS_BSIZE + inode -> i_size - 1 );
@@ -188,13 +187,13 @@ static void bfs_evict_inode(struct inode *inode)
188
187
mark_buffer_dirty (bh );
189
188
brelse (bh );
190
189
191
- if (bi -> i_dsk_ino ) {
190
+ if (bi -> i_dsk_ino ) {
192
191
if (bi -> i_sblock )
193
192
info -> si_freeb += bi -> i_eblock + 1 - bi -> i_sblock ;
194
193
info -> si_freei ++ ;
195
194
clear_bit (ino , info -> si_imap );
196
- bfs_dump_imap ("delete_inode " , s );
197
- }
195
+ bfs_dump_imap ("evict_inode " , s );
196
+ }
198
197
199
198
/*
200
199
* If this was the last file, make the previous block
@@ -214,7 +213,6 @@ static void bfs_put_super(struct super_block *s)
214
213
return ;
215
214
216
215
mutex_destroy (& info -> bfs_lock );
217
- kfree (info -> si_imap );
218
216
kfree (info );
219
217
s -> s_fs_info = NULL ;
220
218
}
@@ -311,8 +309,7 @@ void bfs_dump_imap(const char *prefix, struct super_block *s)
311
309
else
312
310
strcat (tmpbuf , "0" );
313
311
}
314
- printf ("BFS-fs: %s: lasti=%08lx <%s>\n" ,
315
- prefix , BFS_SB (s )-> si_lasti , tmpbuf );
312
+ printf ("%s: lasti=%08lx <%s>\n" , prefix , BFS_SB (s )-> si_lasti , tmpbuf );
316
313
free_page ((unsigned long )tmpbuf );
317
314
#endif
318
315
}
@@ -322,7 +319,7 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
322
319
struct buffer_head * bh , * sbh ;
323
320
struct bfs_super_block * bfs_sb ;
324
321
struct inode * inode ;
325
- unsigned i , imap_len ;
322
+ unsigned i ;
326
323
struct bfs_sb_info * info ;
327
324
int ret = - EINVAL ;
328
325
unsigned long i_sblock , i_eblock , i_eoff , s_size ;
@@ -341,8 +338,7 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
341
338
bfs_sb = (struct bfs_super_block * )sbh -> b_data ;
342
339
if (le32_to_cpu (bfs_sb -> s_magic ) != BFS_MAGIC ) {
343
340
if (!silent )
344
- printf ("No BFS filesystem on %s (magic=%08x)\n" ,
345
- s -> s_id , le32_to_cpu (bfs_sb -> s_magic ));
341
+ printf ("No BFS filesystem on %s (magic=%08x)\n" , s -> s_id , le32_to_cpu (bfs_sb -> s_magic ));
346
342
goto out1 ;
347
343
}
348
344
if (BFS_UNCLEAN (bfs_sb , s ) && !silent )
@@ -351,18 +347,16 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
351
347
s -> s_magic = BFS_MAGIC ;
352
348
353
349
if (le32_to_cpu (bfs_sb -> s_start ) > le32_to_cpu (bfs_sb -> s_end ) ||
354
- le32_to_cpu (bfs_sb -> s_start ) < BFS_BSIZE ) {
355
- printf ("Superblock is corrupted\n" );
350
+ le32_to_cpu (bfs_sb -> s_start ) < sizeof ( struct bfs_super_block ) + sizeof ( struct bfs_dirent ) ) {
351
+ printf ("Superblock is corrupted on %s \n" , s -> s_id );
356
352
goto out1 ;
357
353
}
358
354
359
- info -> si_lasti = (le32_to_cpu (bfs_sb -> s_start ) - BFS_BSIZE ) /
360
- sizeof (struct bfs_inode )
361
- + BFS_ROOT_INO - 1 ;
362
- imap_len = (info -> si_lasti / 8 ) + 1 ;
363
- info -> si_imap = kzalloc (imap_len , GFP_KERNEL | __GFP_NOWARN );
364
- if (!info -> si_imap ) {
365
- printf ("Cannot allocate %u bytes\n" , imap_len );
355
+ info -> si_lasti = (le32_to_cpu (bfs_sb -> s_start ) - BFS_BSIZE ) / sizeof (struct bfs_inode ) + BFS_ROOT_INO - 1 ;
356
+ if (info -> si_lasti == BFS_MAX_LASTI )
357
+ printf ("WARNING: filesystem %s was created with 512 inodes, the real maximum is 511, mounting anyway\n" , s -> s_id );
358
+ else if (info -> si_lasti > BFS_MAX_LASTI ) {
359
+ printf ("Impossible last inode number %lu > %d on %s\n" , info -> si_lasti , BFS_MAX_LASTI , s -> s_id );
366
360
goto out1 ;
367
361
}
368
362
for (i = 0 ; i < BFS_ROOT_INO ; i ++ )
@@ -372,26 +366,25 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
372
366
inode = bfs_iget (s , BFS_ROOT_INO );
373
367
if (IS_ERR (inode )) {
374
368
ret = PTR_ERR (inode );
375
- goto out2 ;
369
+ goto out1 ;
376
370
}
377
371
s -> s_root = d_make_root (inode );
378
372
if (!s -> s_root ) {
379
373
ret = - ENOMEM ;
380
- goto out2 ;
374
+ goto out1 ;
381
375
}
382
376
383
377
info -> si_blocks = (le32_to_cpu (bfs_sb -> s_end ) + 1 ) >> BFS_BSIZE_BITS ;
384
- info -> si_freeb = (le32_to_cpu (bfs_sb -> s_end ) + 1
385
- - le32_to_cpu (bfs_sb -> s_start )) >> BFS_BSIZE_BITS ;
378
+ info -> si_freeb = (le32_to_cpu (bfs_sb -> s_end ) + 1 - le32_to_cpu (bfs_sb -> s_start )) >> BFS_BSIZE_BITS ;
386
379
info -> si_freei = 0 ;
387
380
info -> si_lf_eblk = 0 ;
388
381
389
382
/* can we read the last block? */
390
383
bh = sb_bread (s , info -> si_blocks - 1 );
391
384
if (!bh ) {
392
- printf ("Last block not available: %lu\n" , info -> si_blocks - 1 );
385
+ printf ("Last block not available on %s : %lu\n" , s -> s_id , info -> si_blocks - 1 );
393
386
ret = - EIO ;
394
- goto out3 ;
387
+ goto out2 ;
395
388
}
396
389
brelse (bh );
397
390
@@ -425,11 +418,11 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
425
418
(i_eoff != le32_to_cpu (-1 ) && i_eoff > s_size ) ||
426
419
i_sblock * BFS_BSIZE > i_eoff ) {
427
420
428
- printf ("Inode 0x%08x corrupted\n" , i );
421
+ printf ("Inode 0x%08x corrupted on %s \n" , i , s -> s_id );
429
422
430
423
brelse (bh );
431
424
ret = - EIO ;
432
- goto out3 ;
425
+ goto out2 ;
433
426
}
434
427
435
428
if (!di -> i_ino ) {
@@ -445,14 +438,12 @@ static int bfs_fill_super(struct super_block *s, void *data, int silent)
445
438
}
446
439
brelse (bh );
447
440
brelse (sbh );
448
- bfs_dump_imap ("read_super " , s );
441
+ bfs_dump_imap ("fill_super " , s );
449
442
return 0 ;
450
443
451
- out3 :
444
+ out2 :
452
445
dput (s -> s_root );
453
446
s -> s_root = NULL ;
454
- out2 :
455
- kfree (info -> si_imap );
456
447
out1 :
457
448
brelse (sbh );
458
449
out :
@@ -482,7 +473,7 @@ static int __init init_bfs_fs(void)
482
473
int err = init_inodecache ();
483
474
if (err )
484
475
goto out1 ;
485
- err = register_filesystem (& bfs_fs_type );
476
+ err = register_filesystem (& bfs_fs_type );
486
477
if (err )
487
478
goto out ;
488
479
return 0 ;
0 commit comments