hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/fs/bfs/inode.c
....@@ -1,10 +1,10 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * fs/bfs/inode.c
34 * BFS superblock and inode operations.
4
- * Copyright (C) 1999-2006 Tigran Aivazian <aivazian.tigran@gmail.com>
5
+ * Copyright (C) 1999-2018 Tigran Aivazian <aivazian.tigran@gmail.com>
56 * From fs/minix, Copyright (C) 1991, 1992 Linus Torvalds.
6
- *
7
- * Made endianness-clean by Andrew Stribblehill <ads@wompom.org>, 2005.
7
+ * Made endianness-clean by Andrew Stribblehill <ads@wompom.org>, 2005.
88 */
99
1010 #include <linux/module.h>
....@@ -22,6 +22,7 @@
2222 MODULE_AUTHOR("Tigran Aivazian <aivazian.tigran@gmail.com>");
2323 MODULE_DESCRIPTION("SCO UnixWare BFS filesystem for Linux");
2424 MODULE_LICENSE("GPL");
25
+MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
2526
2627 #undef DEBUG
2728
....@@ -118,12 +119,12 @@
118119 {
119120 struct bfs_sb_info *info = BFS_SB(inode->i_sb);
120121 unsigned int ino = (u16)inode->i_ino;
121
- unsigned long i_sblock;
122
+ unsigned long i_sblock;
122123 struct bfs_inode *di;
123124 struct buffer_head *bh;
124125 int err = 0;
125126
126
- dprintf("ino=%08x\n", ino);
127
+ dprintf("ino=%08x\n", ino);
127128
128129 di = find_inode(inode->i_sb, ino, &bh);
129130 if (IS_ERR(di))
....@@ -144,7 +145,7 @@
144145 di->i_atime = cpu_to_le32(inode->i_atime.tv_sec);
145146 di->i_mtime = cpu_to_le32(inode->i_mtime.tv_sec);
146147 di->i_ctime = cpu_to_le32(inode->i_ctime.tv_sec);
147
- i_sblock = BFS_I(inode)->i_sblock;
148
+ i_sblock = BFS_I(inode)->i_sblock;
148149 di->i_sblock = cpu_to_le32(i_sblock);
149150 di->i_eblock = cpu_to_le32(BFS_I(inode)->i_eblock);
150151 di->i_eoffset = cpu_to_le32(i_sblock * BFS_BSIZE + inode->i_size - 1);
....@@ -188,13 +189,13 @@
188189 mark_buffer_dirty(bh);
189190 brelse(bh);
190191
191
- if (bi->i_dsk_ino) {
192
+ if (bi->i_dsk_ino) {
192193 if (bi->i_sblock)
193194 info->si_freeb += bi->i_eblock + 1 - bi->i_sblock;
194195 info->si_freei++;
195196 clear_bit(ino, info->si_imap);
196
- bfs_dump_imap("delete_inode", s);
197
- }
197
+ bfs_dump_imap("evict_inode", s);
198
+ }
198199
199200 /*
200201 * If this was the last file, make the previous block
....@@ -214,7 +215,6 @@
214215 return;
215216
216217 mutex_destroy(&info->bfs_lock);
217
- kfree(info->si_imap);
218218 kfree(info);
219219 s->s_fs_info = NULL;
220220 }
....@@ -230,8 +230,7 @@
230230 buf->f_bfree = buf->f_bavail = info->si_freeb;
231231 buf->f_files = info->si_lasti + 1 - BFS_ROOT_INO;
232232 buf->f_ffree = info->si_freei;
233
- buf->f_fsid.val[0] = (u32)id;
234
- buf->f_fsid.val[1] = (u32)(id >> 32);
233
+ buf->f_fsid = u64_to_fsid(id);
235234 buf->f_namelen = BFS_NAMELEN;
236235 return 0;
237236 }
....@@ -247,15 +246,9 @@
247246 return &bi->vfs_inode;
248247 }
249248
250
-static void bfs_i_callback(struct rcu_head *head)
249
+static void bfs_free_inode(struct inode *inode)
251250 {
252
- struct inode *inode = container_of(head, struct inode, i_rcu);
253251 kmem_cache_free(bfs_inode_cachep, BFS_I(inode));
254
-}
255
-
256
-static void bfs_destroy_inode(struct inode *inode)
257
-{
258
- call_rcu(&inode->i_rcu, bfs_i_callback);
259252 }
260253
261254 static void init_once(void *foo)
....@@ -289,7 +282,7 @@
289282
290283 static const struct super_operations bfs_sops = {
291284 .alloc_inode = bfs_alloc_inode,
292
- .destroy_inode = bfs_destroy_inode,
285
+ .free_inode = bfs_free_inode,
293286 .write_inode = bfs_write_inode,
294287 .evict_inode = bfs_evict_inode,
295288 .put_super = bfs_put_super,
....@@ -311,8 +304,7 @@
311304 else
312305 strcat(tmpbuf, "0");
313306 }
314
- printf("BFS-fs: %s: lasti=%08lx <%s>\n",
315
- prefix, BFS_SB(s)->si_lasti, tmpbuf);
307
+ printf("%s: lasti=%08lx <%s>\n", prefix, BFS_SB(s)->si_lasti, tmpbuf);
316308 free_page((unsigned long)tmpbuf);
317309 #endif
318310 }
....@@ -322,7 +314,7 @@
322314 struct buffer_head *bh, *sbh;
323315 struct bfs_super_block *bfs_sb;
324316 struct inode *inode;
325
- unsigned i, imap_len;
317
+ unsigned i;
326318 struct bfs_sb_info *info;
327319 int ret = -EINVAL;
328320 unsigned long i_sblock, i_eblock, i_eoff, s_size;
....@@ -332,6 +324,8 @@
332324 return -ENOMEM;
333325 mutex_init(&info->bfs_lock);
334326 s->s_fs_info = info;
327
+ s->s_time_min = 0;
328
+ s->s_time_max = U32_MAX;
335329
336330 sb_set_blocksize(s, BFS_BSIZE);
337331
....@@ -341,8 +335,7 @@
341335 bfs_sb = (struct bfs_super_block *)sbh->b_data;
342336 if (le32_to_cpu(bfs_sb->s_magic) != BFS_MAGIC) {
343337 if (!silent)
344
- printf("No BFS filesystem on %s (magic=%08x)\n",
345
- s->s_id, le32_to_cpu(bfs_sb->s_magic));
338
+ printf("No BFS filesystem on %s (magic=%08x)\n", s->s_id, le32_to_cpu(bfs_sb->s_magic));
346339 goto out1;
347340 }
348341 if (BFS_UNCLEAN(bfs_sb, s) && !silent)
....@@ -351,18 +344,16 @@
351344 s->s_magic = BFS_MAGIC;
352345
353346 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");
347
+ le32_to_cpu(bfs_sb->s_start) < sizeof(struct bfs_super_block) + sizeof(struct bfs_dirent)) {
348
+ printf("Superblock is corrupted on %s\n", s->s_id);
356349 goto out1;
357350 }
358351
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);
352
+ info->si_lasti = (le32_to_cpu(bfs_sb->s_start) - BFS_BSIZE) / sizeof(struct bfs_inode) + BFS_ROOT_INO - 1;
353
+ if (info->si_lasti == BFS_MAX_LASTI)
354
+ printf("NOTE: filesystem %s was created with 512 inodes, the real maximum is 511, mounting anyway\n", s->s_id);
355
+ else if (info->si_lasti > BFS_MAX_LASTI) {
356
+ printf("Impossible last inode number %lu > %d on %s\n", info->si_lasti, BFS_MAX_LASTI, s->s_id);
366357 goto out1;
367358 }
368359 for (i = 0; i < BFS_ROOT_INO; i++)
....@@ -372,26 +363,25 @@
372363 inode = bfs_iget(s, BFS_ROOT_INO);
373364 if (IS_ERR(inode)) {
374365 ret = PTR_ERR(inode);
375
- goto out2;
366
+ goto out1;
376367 }
377368 s->s_root = d_make_root(inode);
378369 if (!s->s_root) {
379370 ret = -ENOMEM;
380
- goto out2;
371
+ goto out1;
381372 }
382373
383374 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;
375
+ info->si_freeb = (le32_to_cpu(bfs_sb->s_end) + 1 - le32_to_cpu(bfs_sb->s_start)) >> BFS_BSIZE_BITS;
386376 info->si_freei = 0;
387377 info->si_lf_eblk = 0;
388378
389379 /* can we read the last block? */
390380 bh = sb_bread(s, info->si_blocks - 1);
391381 if (!bh) {
392
- printf("Last block not available: %lu\n", info->si_blocks - 1);
382
+ printf("Last block not available on %s: %lu\n", s->s_id, info->si_blocks - 1);
393383 ret = -EIO;
394
- goto out3;
384
+ goto out2;
395385 }
396386 brelse(bh);
397387
....@@ -425,11 +415,11 @@
425415 (i_eoff != le32_to_cpu(-1) && i_eoff > s_size) ||
426416 i_sblock * BFS_BSIZE > i_eoff) {
427417
428
- printf("Inode 0x%08x corrupted\n", i);
418
+ printf("Inode 0x%08x corrupted on %s\n", i, s->s_id);
429419
430420 brelse(bh);
431421 ret = -EIO;
432
- goto out3;
422
+ goto out2;
433423 }
434424
435425 if (!di->i_ino) {
....@@ -445,14 +435,12 @@
445435 }
446436 brelse(bh);
447437 brelse(sbh);
448
- bfs_dump_imap("read_super", s);
438
+ bfs_dump_imap("fill_super", s);
449439 return 0;
450440
451
-out3:
441
+out2:
452442 dput(s->s_root);
453443 s->s_root = NULL;
454
-out2:
455
- kfree(info->si_imap);
456444 out1:
457445 brelse(sbh);
458446 out:
....@@ -482,7 +470,7 @@
482470 int err = init_inodecache();
483471 if (err)
484472 goto out1;
485
- err = register_filesystem(&bfs_fs_type);
473
+ err = register_filesystem(&bfs_fs_type);
486474 if (err)
487475 goto out;
488476 return 0;