^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * linux/fs/minix/inode.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 1991, 1992 Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 1996 Gertjan van Wingerde
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Minix V2 fs support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Modified for 680x0 by Andreas Schwab
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Updated to filesystem version 3 by Daniel Aragones
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "minix.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/buffer_head.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/highuid.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/vfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/writeback.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static int minix_write_inode(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) struct writeback_control *wbc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) static int minix_statfs(struct dentry *dentry, struct kstatfs *buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static int minix_remount (struct super_block * sb, int * flags, char * data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static void minix_evict_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) truncate_inode_pages_final(&inode->i_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) if (!inode->i_nlink) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) inode->i_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) minix_truncate(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) invalidate_inode_buffers(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) clear_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) if (!inode->i_nlink)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) minix_free_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static void minix_put_super(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct minix_sb_info *sbi = minix_sb(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (!sb_rdonly(sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) if (sbi->s_version != MINIX_V3) /* s_state is now out from V3 sb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) sbi->s_ms->s_state = sbi->s_mount_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) mark_buffer_dirty(sbi->s_sbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) for (i = 0; i < sbi->s_imap_blocks; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) brelse(sbi->s_imap[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) for (i = 0; i < sbi->s_zmap_blocks; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) brelse(sbi->s_zmap[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) brelse (sbi->s_sbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) kfree(sbi->s_imap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) sb->s_fs_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) kfree(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static struct kmem_cache * minix_inode_cachep;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static struct inode *minix_alloc_inode(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct minix_inode_info *ei;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) ei = kmem_cache_alloc(minix_inode_cachep, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (!ei)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return &ei->vfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) static void minix_free_in_core_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) kmem_cache_free(minix_inode_cachep, minix_i(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) static void init_once(void *foo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) struct minix_inode_info *ei = (struct minix_inode_info *) foo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) inode_init_once(&ei->vfs_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) static int __init init_inodecache(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) minix_inode_cachep = kmem_cache_create("minix_inode_cache",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) sizeof(struct minix_inode_info),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) 0, (SLAB_RECLAIM_ACCOUNT|
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) SLAB_MEM_SPREAD|SLAB_ACCOUNT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) init_once);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) if (minix_inode_cachep == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) static void destroy_inodecache(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * Make sure all delayed rcu free inodes are flushed before we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * destroy cache.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) rcu_barrier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) kmem_cache_destroy(minix_inode_cachep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static const struct super_operations minix_sops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) .alloc_inode = minix_alloc_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) .free_inode = minix_free_in_core_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) .write_inode = minix_write_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) .evict_inode = minix_evict_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) .put_super = minix_put_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) .statfs = minix_statfs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) .remount_fs = minix_remount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static int minix_remount (struct super_block * sb, int * flags, char * data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct minix_sb_info * sbi = minix_sb(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct minix_super_block * ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) sync_filesystem(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) ms = sbi->s_ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if ((bool)(*flags & SB_RDONLY) == sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (*flags & SB_RDONLY) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) if (ms->s_state & MINIX_VALID_FS ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) !(sbi->s_mount_state & MINIX_VALID_FS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /* Mounting a rw partition read-only. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (sbi->s_version != MINIX_V3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) ms->s_state = sbi->s_mount_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) mark_buffer_dirty(sbi->s_sbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /* Mount a partition which is read-only, read-write. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (sbi->s_version != MINIX_V3) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) sbi->s_mount_state = ms->s_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) ms->s_state &= ~MINIX_VALID_FS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) sbi->s_mount_state = MINIX_VALID_FS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) mark_buffer_dirty(sbi->s_sbh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (!(sbi->s_mount_state & MINIX_VALID_FS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) printk("MINIX-fs warning: remounting unchecked fs, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) "running fsck is recommended\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) else if ((sbi->s_mount_state & MINIX_ERROR_FS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) printk("MINIX-fs warning: remounting fs with errors, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) "running fsck is recommended\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static bool minix_check_superblock(struct super_block *sb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct minix_sb_info *sbi = minix_sb(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (sbi->s_imap_blocks == 0 || sbi->s_zmap_blocks == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * s_max_size must not exceed the block mapping limitation. This check
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * is only needed for V1 filesystems, since V2/V3 support an extra level
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * of indirect blocks which places the limit well above U32_MAX.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if (sbi->s_version == MINIX_V1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) sb->s_maxbytes > (7 + 512 + 512*512) * BLOCK_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) static int minix_fill_super(struct super_block *s, void *data, int silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) struct buffer_head **map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct minix_super_block *ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct minix3_super_block *m3s = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) unsigned long i, block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct inode *root_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) struct minix_sb_info *sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) int ret = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) sbi = kzalloc(sizeof(struct minix_sb_info), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (!sbi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) s->s_fs_info = sbi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) BUILD_BUG_ON(32 != sizeof (struct minix_inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) BUILD_BUG_ON(64 != sizeof(struct minix2_inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (!sb_set_blocksize(s, BLOCK_SIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) goto out_bad_hblock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if (!(bh = sb_bread(s, 1)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) goto out_bad_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) ms = (struct minix_super_block *) bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) sbi->s_ms = ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) sbi->s_sbh = bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) sbi->s_mount_state = ms->s_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) sbi->s_ninodes = ms->s_ninodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) sbi->s_nzones = ms->s_nzones;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) sbi->s_imap_blocks = ms->s_imap_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) sbi->s_zmap_blocks = ms->s_zmap_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) sbi->s_firstdatazone = ms->s_firstdatazone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) sbi->s_log_zone_size = ms->s_log_zone_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) s->s_maxbytes = ms->s_max_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) s->s_magic = ms->s_magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (s->s_magic == MINIX_SUPER_MAGIC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) sbi->s_version = MINIX_V1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) sbi->s_dirsize = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) sbi->s_namelen = 14;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) s->s_max_links = MINIX_LINK_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) } else if (s->s_magic == MINIX_SUPER_MAGIC2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) sbi->s_version = MINIX_V1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) sbi->s_dirsize = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) sbi->s_namelen = 30;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) s->s_max_links = MINIX_LINK_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) } else if (s->s_magic == MINIX2_SUPER_MAGIC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) sbi->s_version = MINIX_V2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) sbi->s_nzones = ms->s_zones;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) sbi->s_dirsize = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) sbi->s_namelen = 14;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) s->s_max_links = MINIX2_LINK_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) } else if (s->s_magic == MINIX2_SUPER_MAGIC2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) sbi->s_version = MINIX_V2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) sbi->s_nzones = ms->s_zones;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) sbi->s_dirsize = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) sbi->s_namelen = 30;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) s->s_max_links = MINIX2_LINK_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) } else if ( *(__u16 *)(bh->b_data + 24) == MINIX3_SUPER_MAGIC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) m3s = (struct minix3_super_block *) bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) s->s_magic = m3s->s_magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) sbi->s_imap_blocks = m3s->s_imap_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) sbi->s_zmap_blocks = m3s->s_zmap_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) sbi->s_firstdatazone = m3s->s_firstdatazone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) sbi->s_log_zone_size = m3s->s_log_zone_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) s->s_maxbytes = m3s->s_max_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) sbi->s_ninodes = m3s->s_ninodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) sbi->s_nzones = m3s->s_zones;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) sbi->s_dirsize = 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) sbi->s_namelen = 60;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) sbi->s_version = MINIX_V3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) sbi->s_mount_state = MINIX_VALID_FS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) sb_set_blocksize(s, m3s->s_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) s->s_max_links = MINIX2_LINK_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) goto out_no_fs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (!minix_check_superblock(s))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) goto out_illegal_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) * Allocate the buffer map to keep the superblock small.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) i = (sbi->s_imap_blocks + sbi->s_zmap_blocks) * sizeof(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) map = kzalloc(i, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) if (!map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) goto out_no_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) sbi->s_imap = &map[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) sbi->s_zmap = &map[sbi->s_imap_blocks];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) block=2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) for (i=0 ; i < sbi->s_imap_blocks ; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (!(sbi->s_imap[i]=sb_bread(s, block)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) goto out_no_bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) block++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) for (i=0 ; i < sbi->s_zmap_blocks ; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) if (!(sbi->s_zmap[i]=sb_bread(s, block)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) goto out_no_bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) block++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) minix_set_bit(0,sbi->s_imap[0]->b_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) minix_set_bit(0,sbi->s_zmap[0]->b_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) /* Apparently minix can create filesystems that allocate more blocks for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * the bitmaps than needed. We simply ignore that, but verify it didn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * create one with not enough blocks and bail out if so.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) block = minix_blocks_needed(sbi->s_ninodes, s->s_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) if (sbi->s_imap_blocks < block) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) printk("MINIX-fs: file system does not have enough "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) "imap blocks allocated. Refusing to mount.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) goto out_no_bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) block = minix_blocks_needed(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) (sbi->s_nzones - sbi->s_firstdatazone + 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) s->s_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) if (sbi->s_zmap_blocks < block) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) printk("MINIX-fs: file system does not have enough "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) "zmap blocks allocated. Refusing to mount.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) goto out_no_bitmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) /* set up enough so that it can read an inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) s->s_op = &minix_sops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) s->s_time_min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) s->s_time_max = U32_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) root_inode = minix_iget(s, MINIX_ROOT_INO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) if (IS_ERR(root_inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) ret = PTR_ERR(root_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) goto out_no_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) s->s_root = d_make_root(root_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) if (!s->s_root)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) goto out_no_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) if (!sb_rdonly(s)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) if (sbi->s_version != MINIX_V3) /* s_state is now out from V3 sb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) ms->s_state &= ~MINIX_VALID_FS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) mark_buffer_dirty(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) if (!(sbi->s_mount_state & MINIX_VALID_FS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) printk("MINIX-fs: mounting unchecked file system, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) "running fsck is recommended\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) else if (sbi->s_mount_state & MINIX_ERROR_FS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) printk("MINIX-fs: mounting file system with errors, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) "running fsck is recommended\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) out_no_root:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) printk("MINIX-fs: get root inode failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) goto out_freemap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) out_no_bitmap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) printk("MINIX-fs: bad superblock or unable to read bitmaps\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) out_freemap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) for (i = 0; i < sbi->s_imap_blocks; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) brelse(sbi->s_imap[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) for (i = 0; i < sbi->s_zmap_blocks; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) brelse(sbi->s_zmap[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) kfree(sbi->s_imap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) goto out_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) out_no_map:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) printk("MINIX-fs: can't allocate map\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) goto out_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) out_illegal_sb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) printk("MINIX-fs: bad superblock\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) goto out_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) out_no_fs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) if (!silent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) printk("VFS: Can't find a Minix filesystem V1 | V2 | V3 "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) "on device %s.\n", s->s_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) out_release:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) out_bad_hblock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) printk("MINIX-fs: blocksize too small for device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) out_bad_sb:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) printk("MINIX-fs: unable to read superblock\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) s->s_fs_info = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) kfree(sbi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) static int minix_statfs(struct dentry *dentry, struct kstatfs *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) struct super_block *sb = dentry->d_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) struct minix_sb_info *sbi = minix_sb(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) buf->f_type = sb->s_magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) buf->f_bsize = sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) buf->f_blocks = (sbi->s_nzones - sbi->s_firstdatazone) << sbi->s_log_zone_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) buf->f_bfree = minix_count_free_blocks(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) buf->f_bavail = buf->f_bfree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) buf->f_files = sbi->s_ninodes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) buf->f_ffree = minix_count_free_inodes(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) buf->f_namelen = sbi->s_namelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) buf->f_fsid = u64_to_fsid(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) static int minix_get_block(struct inode *inode, sector_t block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) struct buffer_head *bh_result, int create)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) if (INODE_VERSION(inode) == MINIX_V1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) return V1_minix_get_block(inode, block, bh_result, create);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) return V2_minix_get_block(inode, block, bh_result, create);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) static int minix_writepage(struct page *page, struct writeback_control *wbc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) return block_write_full_page(page, minix_get_block, wbc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) static int minix_readpage(struct file *file, struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) return block_read_full_page(page,minix_get_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) int minix_prepare_chunk(struct page *page, loff_t pos, unsigned len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) return __block_write_begin(page, pos, len, minix_get_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) static void minix_write_failed(struct address_space *mapping, loff_t to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) struct inode *inode = mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) if (to > inode->i_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) truncate_pagecache(inode, inode->i_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) minix_truncate(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) static int minix_write_begin(struct file *file, struct address_space *mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) loff_t pos, unsigned len, unsigned flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) struct page **pagep, void **fsdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) ret = block_write_begin(mapping, pos, len, flags, pagep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) minix_get_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) if (unlikely(ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) minix_write_failed(mapping, pos + len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) static sector_t minix_bmap(struct address_space *mapping, sector_t block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) return generic_block_bmap(mapping,block,minix_get_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) static const struct address_space_operations minix_aops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) .readpage = minix_readpage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) .writepage = minix_writepage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) .write_begin = minix_write_begin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) .write_end = generic_write_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) .bmap = minix_bmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) static const struct inode_operations minix_symlink_inode_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) .get_link = page_get_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) .getattr = minix_getattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) void minix_set_inode(struct inode *inode, dev_t rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) if (S_ISREG(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) inode->i_op = &minix_file_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) inode->i_fop = &minix_file_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) inode->i_mapping->a_ops = &minix_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) } else if (S_ISDIR(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) inode->i_op = &minix_dir_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) inode->i_fop = &minix_dir_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) inode->i_mapping->a_ops = &minix_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) } else if (S_ISLNK(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) inode->i_op = &minix_symlink_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) inode_nohighmem(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) inode->i_mapping->a_ops = &minix_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) init_special_inode(inode, inode->i_mode, rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) * The minix V1 function to read an inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) static struct inode *V1_minix_iget(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) struct buffer_head * bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) struct minix_inode * raw_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) struct minix_inode_info *minix_inode = minix_i(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) raw_inode = minix_V1_raw_inode(inode->i_sb, inode->i_ino, &bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) if (!raw_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) iget_failed(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) return ERR_PTR(-EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) if (raw_inode->i_nlinks == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) printk("MINIX-fs: deleted inode referenced: %lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) iget_failed(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) return ERR_PTR(-ESTALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) inode->i_mode = raw_inode->i_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) i_uid_write(inode, raw_inode->i_uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) i_gid_write(inode, raw_inode->i_gid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) set_nlink(inode, raw_inode->i_nlinks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) inode->i_size = raw_inode->i_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) inode->i_mtime.tv_sec = inode->i_atime.tv_sec = inode->i_ctime.tv_sec = raw_inode->i_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) inode->i_mtime.tv_nsec = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) inode->i_atime.tv_nsec = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) inode->i_ctime.tv_nsec = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) inode->i_blocks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) for (i = 0; i < 9; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) minix_inode->u.i1_data[i] = raw_inode->i_zone[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) minix_set_inode(inode, old_decode_dev(raw_inode->i_zone[0]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) unlock_new_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) * The minix V2 function to read an inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) static struct inode *V2_minix_iget(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) struct buffer_head * bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) struct minix2_inode * raw_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) struct minix_inode_info *minix_inode = minix_i(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) raw_inode = minix_V2_raw_inode(inode->i_sb, inode->i_ino, &bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) if (!raw_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) iget_failed(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) return ERR_PTR(-EIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) if (raw_inode->i_nlinks == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) printk("MINIX-fs: deleted inode referenced: %lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) iget_failed(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) return ERR_PTR(-ESTALE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) inode->i_mode = raw_inode->i_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) i_uid_write(inode, raw_inode->i_uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) i_gid_write(inode, raw_inode->i_gid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) set_nlink(inode, raw_inode->i_nlinks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) inode->i_size = raw_inode->i_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) inode->i_mtime.tv_sec = raw_inode->i_mtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) inode->i_atime.tv_sec = raw_inode->i_atime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) inode->i_ctime.tv_sec = raw_inode->i_ctime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) inode->i_mtime.tv_nsec = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) inode->i_atime.tv_nsec = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) inode->i_ctime.tv_nsec = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) inode->i_blocks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) for (i = 0; i < 10; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) minix_inode->u.i2_data[i] = raw_inode->i_zone[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) minix_set_inode(inode, old_decode_dev(raw_inode->i_zone[0]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) unlock_new_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) * The global function to read an inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) struct inode *minix_iget(struct super_block *sb, unsigned long ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) inode = iget_locked(sb, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) if (!(inode->i_state & I_NEW))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) if (INODE_VERSION(inode) == MINIX_V1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) return V1_minix_iget(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) return V2_minix_iget(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) * The minix V1 function to synchronize an inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) static struct buffer_head * V1_minix_update_inode(struct inode * inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) struct buffer_head * bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) struct minix_inode * raw_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) struct minix_inode_info *minix_inode = minix_i(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) raw_inode = minix_V1_raw_inode(inode->i_sb, inode->i_ino, &bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) if (!raw_inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) raw_inode->i_mode = inode->i_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) raw_inode->i_uid = fs_high2lowuid(i_uid_read(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) raw_inode->i_gid = fs_high2lowgid(i_gid_read(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) raw_inode->i_nlinks = inode->i_nlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) raw_inode->i_size = inode->i_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) raw_inode->i_time = inode->i_mtime.tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) raw_inode->i_zone[0] = old_encode_dev(inode->i_rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) else for (i = 0; i < 9; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) raw_inode->i_zone[i] = minix_inode->u.i1_data[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) mark_buffer_dirty(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) return bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) * The minix V2 function to synchronize an inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) static struct buffer_head * V2_minix_update_inode(struct inode * inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) struct buffer_head * bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) struct minix2_inode * raw_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) struct minix_inode_info *minix_inode = minix_i(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) raw_inode = minix_V2_raw_inode(inode->i_sb, inode->i_ino, &bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) if (!raw_inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) raw_inode->i_mode = inode->i_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) raw_inode->i_uid = fs_high2lowuid(i_uid_read(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) raw_inode->i_gid = fs_high2lowgid(i_gid_read(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) raw_inode->i_nlinks = inode->i_nlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) raw_inode->i_size = inode->i_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) raw_inode->i_mtime = inode->i_mtime.tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) raw_inode->i_atime = inode->i_atime.tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) raw_inode->i_ctime = inode->i_ctime.tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) raw_inode->i_zone[0] = old_encode_dev(inode->i_rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) else for (i = 0; i < 10; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) raw_inode->i_zone[i] = minix_inode->u.i2_data[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) mark_buffer_dirty(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) return bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) static int minix_write_inode(struct inode *inode, struct writeback_control *wbc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) if (INODE_VERSION(inode) == MINIX_V1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) bh = V1_minix_update_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) bh = V2_minix_update_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) if (wbc->sync_mode == WB_SYNC_ALL && buffer_dirty(bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) sync_dirty_buffer(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) if (buffer_req(bh) && !buffer_uptodate(bh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) printk("IO error syncing minix inode [%s:%08lx]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) inode->i_sb->s_id, inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) err = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) brelse (bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) int minix_getattr(const struct path *path, struct kstat *stat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) u32 request_mask, unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) struct super_block *sb = path->dentry->d_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) struct inode *inode = d_inode(path->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) generic_fillattr(inode, stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) if (INODE_VERSION(inode) == MINIX_V1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) stat->blocks = (BLOCK_SIZE / 512) * V1_minix_blocks(stat->size, sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) stat->blocks = (sb->s_blocksize / 512) * V2_minix_blocks(stat->size, sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) stat->blksize = sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) * The function that is called for file truncation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) void minix_truncate(struct inode * inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) if (INODE_VERSION(inode) == MINIX_V1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) V1_minix_truncate(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) V2_minix_truncate(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) static struct dentry *minix_mount(struct file_system_type *fs_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) int flags, const char *dev_name, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) return mount_bdev(fs_type, flags, dev_name, data, minix_fill_super);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) static struct file_system_type minix_fs_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) .name = "minix",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) .mount = minix_mount,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) .kill_sb = kill_block_super,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) .fs_flags = FS_REQUIRES_DEV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) MODULE_ALIAS_FS("minix");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) static int __init init_minix_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) int err = init_inodecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) goto out1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) err = register_filesystem(&minix_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) destroy_inodecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) out1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) static void __exit exit_minix_fs(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) unregister_filesystem(&minix_fs_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) destroy_inodecache();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) module_init(init_minix_fs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) module_exit(exit_minix_fs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) MODULE_IMPORT_NS(ANDROID_GKI_VFS_EXPORT_ONLY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)