VisionFive2 Linux kernel

StarFive Tech Linux Kernel for VisionFive (JH7110) boards (mirror)

More than 9999 Commits   35 Branches   59 Tags
b24413180f560 (Greg Kroah-Hartman 2017-11-01 15:07:57 +0100   1) // SPDX-License-Identifier: GPL-2.0
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   2) /*
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   3)  *  linux/fs/sysv/inode.c
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   4)  *
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   5)  *  minix/inode.c
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   6)  *  Copyright (C) 1991, 1992  Linus Torvalds
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   7)  *
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   8)  *  xenix/inode.c
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700   9)  *  Copyright (C) 1992  Doug Evans
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  10)  *
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  11)  *  coh/inode.c
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  12)  *  Copyright (C) 1993  Pascal Haible, Bruno Haible
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  13)  *
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  14)  *  sysv/inode.c
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  15)  *  Copyright (C) 1993  Paul B. Monday
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  16)  *
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  17)  *  sysv/inode.c
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  18)  *  Copyright (C) 1993  Bruno Haible
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  19)  *  Copyright (C) 1997, 1998  Krzysztof G. Baranowski
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  20)  *
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  21)  *  This file contains code for allocating/freeing inodes and for read/writing
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  22)  *  the superblock.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  23)  */
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  24) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  25) #include <linux/highuid.h>
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  26) #include <linux/slab.h>
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  27) #include <linux/init.h>
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  28) #include <linux/buffer_head.h>
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  29) #include <linux/vfs.h>
a9185b41a4f84 (Christoph Hellwig  2010-03-05 09:21:37 +0100  30) #include <linux/writeback.h>
21acaf8e8da00 (Duane Griffin      2008-12-19 20:47:16 +0000  31) #include <linux/namei.h>
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  32) #include <asm/byteorder.h>
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  33) #include "sysv.h"
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  34) 
ad43ffdeea0a7 (Christoph Hellwig  2009-06-08 10:07:45 +0200  35) static int sysv_sync_fs(struct super_block *sb, int wait)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  36) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  37) 	struct sysv_sb_info *sbi = SYSV_SB(sb);
3e811f053aec6 (Arnd Bergmann      2018-08-21 22:01:13 -0700  38) 	u32 time = (u32)ktime_get_real_seconds(), old_time;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  39) 
c07cb01c45d6f (Marco Stornelli    2012-10-06 12:41:46 +0200  40) 	mutex_lock(&sbi->s_lock);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  41) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  42) 	/*
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  43) 	 * If we are going to write out the super block,
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  44) 	 * then attach current time stamp.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  45) 	 * But if the filesystem was marked clean, keep it clean.
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  46) 	 */
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  47) 	old_time = fs32_to_cpu(sbi, *sbi->s_sb_time);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  48) 	if (sbi->s_type == FSTYPE_SYSV4) {
3e811f053aec6 (Arnd Bergmann      2018-08-21 22:01:13 -0700  49) 		if (*sbi->s_sb_state == cpu_to_fs32(sbi, 0x7c269d38u - old_time))
3e811f053aec6 (Arnd Bergmann      2018-08-21 22:01:13 -0700  50) 			*sbi->s_sb_state = cpu_to_fs32(sbi, 0x7c269d38u - time);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  51) 		*sbi->s_sb_time = cpu_to_fs32(sbi, time);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  52) 		mark_buffer_dirty(sbi->s_bh2);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  53) 	}
ad43ffdeea0a7 (Christoph Hellwig  2009-06-08 10:07:45 +0200  54) 
c07cb01c45d6f (Marco Stornelli    2012-10-06 12:41:46 +0200  55) 	mutex_unlock(&sbi->s_lock);
ad43ffdeea0a7 (Christoph Hellwig  2009-06-08 10:07:45 +0200  56) 
ad43ffdeea0a7 (Christoph Hellwig  2009-06-08 10:07:45 +0200  57) 	return 0;
ad43ffdeea0a7 (Christoph Hellwig  2009-06-08 10:07:45 +0200  58) }
ad43ffdeea0a7 (Christoph Hellwig  2009-06-08 10:07:45 +0200  59) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  60) static int sysv_remount(struct super_block *sb, int *flags, char *data)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  61) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  62) 	struct sysv_sb_info *sbi = SYSV_SB(sb);
eee458936b52b (Artem Bityutskiy   2012-07-03 16:43:27 +0300  63) 
02b9984d64087 (Theodore Ts'o      2014-03-13 10:14:33 -0400  64) 	sync_filesystem(sb);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  65) 	if (sbi->s_forced_ro)
1751e8a6cb935 (Linus Torvalds     2017-11-27 13:05:09 -0800  66) 		*flags |= SB_RDONLY;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  67) 	return 0;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  68) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  69) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  70) static void sysv_put_super(struct super_block *sb)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  71) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  72) 	struct sysv_sb_info *sbi = SYSV_SB(sb);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  73) 
bc98a42c1f7d0 (David Howells      2017-07-17 08:45:34 +0100  74) 	if (!sb_rdonly(sb)) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  75) 		/* XXX ext2 also updates the state here */
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  76) 		mark_buffer_dirty(sbi->s_bh1);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  77) 		if (sbi->s_bh1 != sbi->s_bh2)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  78) 			mark_buffer_dirty(sbi->s_bh2);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  79) 	}
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  80) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  81) 	brelse(sbi->s_bh1);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  82) 	if (sbi->s_bh1 != sbi->s_bh2)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  83) 		brelse(sbi->s_bh2);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  84) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  85) 	kfree(sbi);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  86) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  87) 
726c334223180 (David Howells      2006-06-23 02:02:58 -0700  88) static int sysv_statfs(struct dentry *dentry, struct kstatfs *buf)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  89) {
726c334223180 (David Howells      2006-06-23 02:02:58 -0700  90) 	struct super_block *sb = dentry->d_sb;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  91) 	struct sysv_sb_info *sbi = SYSV_SB(sb);
1c5b45411f93b (Coly Li            2009-04-02 16:59:43 -0700  92) 	u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  93) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  94) 	buf->f_type = sb->s_magic;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  95) 	buf->f_bsize = sb->s_blocksize;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  96) 	buf->f_blocks = sbi->s_ndatazones;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  97) 	buf->f_bavail = buf->f_bfree = sysv_count_free_blocks(sb);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  98) 	buf->f_files = sbi->s_ninodes;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700  99) 	buf->f_ffree = sysv_count_free_inodes(sb);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 100) 	buf->f_namelen = SYSV_NAMELEN;
6d1349c769ea2 (Al Viro            2020-09-18 16:45:50 -0400 101) 	buf->f_fsid = u64_to_fsid(id);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 102) 	return 0;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 103) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 104) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 105) /* 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 106)  * NXI <-> N0XI for PDP, XIN <-> XIN0 for le32, NIX <-> 0NIX for be32
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 107)  */
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 108) static inline void read3byte(struct sysv_sb_info *sbi,
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 109) 	unsigned char * from, unsigned char * to)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 110) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 111) 	if (sbi->s_bytesex == BYTESEX_PDP) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 112) 		to[0] = from[0];
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 113) 		to[1] = 0;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 114) 		to[2] = from[1];
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 115) 		to[3] = from[2];
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 116) 	} else if (sbi->s_bytesex == BYTESEX_LE) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 117) 		to[0] = from[0];
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 118) 		to[1] = from[1];
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 119) 		to[2] = from[2];
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 120) 		to[3] = 0;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 121) 	} else {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 122) 		to[0] = 0;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 123) 		to[1] = from[0];
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 124) 		to[2] = from[1];
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 125) 		to[3] = from[2];
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 126) 	}
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 127) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 128) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 129) static inline void write3byte(struct sysv_sb_info *sbi,
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 130) 	unsigned char * from, unsigned char * to)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 131) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 132) 	if (sbi->s_bytesex == BYTESEX_PDP) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 133) 		to[0] = from[0];
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 134) 		to[1] = from[2];
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 135) 		to[2] = from[3];
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 136) 	} else if (sbi->s_bytesex == BYTESEX_LE) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 137) 		to[0] = from[0];
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 138) 		to[1] = from[1];
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 139) 		to[2] = from[2];
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 140) 	} else {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 141) 		to[0] = from[1];
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 142) 		to[1] = from[2];
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 143) 		to[2] = from[3];
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 144) 	}
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 145) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 146) 
c5ef1c42c51b1 (Arjan van de Ven   2007-02-12 00:55:40 -0800 147) static const struct inode_operations sysv_symlink_inode_operations = {
6b2553918d8b4 (Al Viro            2015-11-17 10:20:54 -0500 148) 	.get_link	= page_get_link,
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 149) 	.getattr	= sysv_getattr,
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 150) };
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 151) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 152) void sysv_set_inode(struct inode *inode, dev_t rdev)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 153) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 154) 	if (S_ISREG(inode->i_mode)) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 155) 		inode->i_op = &sysv_file_inode_operations;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 156) 		inode->i_fop = &sysv_file_operations;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 157) 		inode->i_mapping->a_ops = &sysv_aops;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 158) 	} else if (S_ISDIR(inode->i_mode)) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 159) 		inode->i_op = &sysv_dir_inode_operations;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 160) 		inode->i_fop = &sysv_dir_operations;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 161) 		inode->i_mapping->a_ops = &sysv_aops;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 162) 	} else if (S_ISLNK(inode->i_mode)) {
0ebf7f10d67a7 (Al Viro            2015-11-23 21:11:08 -0500 163) 		inode->i_op = &sysv_symlink_inode_operations;
21fc61c73c390 (Al Viro            2015-11-17 01:07:57 -0500 164) 		inode_nohighmem(inode);
0ebf7f10d67a7 (Al Viro            2015-11-23 21:11:08 -0500 165) 		inode->i_mapping->a_ops = &sysv_aops;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 166) 	} else
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 167) 		init_special_inode(inode, inode->i_mode, rdev);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 168) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 169) 
b8e1343f67460 (David Howells      2008-02-07 00:15:47 -0800 170) struct inode *sysv_iget(struct super_block *sb, unsigned int ino)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 171) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 172) 	struct sysv_sb_info * sbi = SYSV_SB(sb);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 173) 	struct buffer_head * bh;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 174) 	struct sysv_inode * raw_inode;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 175) 	struct sysv_inode_info * si;
b8e1343f67460 (David Howells      2008-02-07 00:15:47 -0800 176) 	struct inode *inode;
b8e1343f67460 (David Howells      2008-02-07 00:15:47 -0800 177) 	unsigned int block;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 178) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 179) 	if (!ino || ino > sbi->s_ninodes) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 180) 		printk("Bad inode number on dev %s: %d is out of range\n",
b8e1343f67460 (David Howells      2008-02-07 00:15:47 -0800 181) 		       sb->s_id, ino);
b8e1343f67460 (David Howells      2008-02-07 00:15:47 -0800 182) 		return ERR_PTR(-EIO);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 183) 	}
b8e1343f67460 (David Howells      2008-02-07 00:15:47 -0800 184) 
b8e1343f67460 (David Howells      2008-02-07 00:15:47 -0800 185) 	inode = iget_locked(sb, ino);
b8e1343f67460 (David Howells      2008-02-07 00:15:47 -0800 186) 	if (!inode)
b8e1343f67460 (David Howells      2008-02-07 00:15:47 -0800 187) 		return ERR_PTR(-ENOMEM);
b8e1343f67460 (David Howells      2008-02-07 00:15:47 -0800 188) 	if (!(inode->i_state & I_NEW))
b8e1343f67460 (David Howells      2008-02-07 00:15:47 -0800 189) 		return inode;
b8e1343f67460 (David Howells      2008-02-07 00:15:47 -0800 190) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 191) 	raw_inode = sysv_raw_inode(sb, ino, &bh);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 192) 	if (!raw_inode) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 193) 		printk("Major problem: unable to read inode from dev %s\n",
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 194) 		       inode->i_sb->s_id);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 195) 		goto bad_inode;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 196) 	}
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 197) 	/* SystemV FS: kludge permissions if ino==SYSV_ROOT_INO ?? */
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 198) 	inode->i_mode = fs16_to_cpu(sbi, raw_inode->i_mode);
a726ecce75896 (Eric W. Biederman  2012-02-10 12:19:23 -0800 199) 	i_uid_write(inode, (uid_t)fs16_to_cpu(sbi, raw_inode->i_uid));
a726ecce75896 (Eric W. Biederman  2012-02-10 12:19:23 -0800 200) 	i_gid_write(inode, (gid_t)fs16_to_cpu(sbi, raw_inode->i_gid));
bfe8684869601 (Miklos Szeredi     2011-10-28 14:13:29 +0200 201) 	set_nlink(inode, fs16_to_cpu(sbi, raw_inode->i_nlink));
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 202) 	inode->i_size = fs32_to_cpu(sbi, raw_inode->i_size);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 203) 	inode->i_atime.tv_sec = fs32_to_cpu(sbi, raw_inode->i_atime);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 204) 	inode->i_mtime.tv_sec = fs32_to_cpu(sbi, raw_inode->i_mtime);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 205) 	inode->i_ctime.tv_sec = fs32_to_cpu(sbi, raw_inode->i_ctime);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 206) 	inode->i_ctime.tv_nsec = 0;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 207) 	inode->i_atime.tv_nsec = 0;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 208) 	inode->i_mtime.tv_nsec = 0;
ba52de123d454 (Theodore Ts'o      2006-09-27 01:50:49 -0700 209) 	inode->i_blocks = 0;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 210) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 211) 	si = SYSV_I(inode);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 212) 	for (block = 0; block < 10+1+1+1; block++)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 213) 		read3byte(sbi, &raw_inode->i_data[3*block],
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 214) 				(u8 *)&si->i_data[block]);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 215) 	brelse(bh);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 216) 	si->i_dir_start_lookup = 0;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 217) 	if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 218) 		sysv_set_inode(inode,
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 219) 			       old_decode_dev(fs32_to_cpu(sbi, si->i_data[0])));
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 220) 	else
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 221) 		sysv_set_inode(inode, 0);
b8e1343f67460 (David Howells      2008-02-07 00:15:47 -0800 222) 	unlock_new_inode(inode);
b8e1343f67460 (David Howells      2008-02-07 00:15:47 -0800 223) 	return inode;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 224) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 225) bad_inode:
b8e1343f67460 (David Howells      2008-02-07 00:15:47 -0800 226) 	iget_failed(inode);
b8e1343f67460 (David Howells      2008-02-07 00:15:47 -0800 227) 	return ERR_PTR(-EIO);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 228) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 229) 
a9185b41a4f84 (Christoph Hellwig  2010-03-05 09:21:37 +0100 230) static int __sysv_write_inode(struct inode *inode, int wait)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 231) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 232) 	struct super_block * sb = inode->i_sb;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 233) 	struct sysv_sb_info * sbi = SYSV_SB(sb);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 234) 	struct buffer_head * bh;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 235) 	struct sysv_inode * raw_inode;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 236) 	struct sysv_inode_info * si;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 237) 	unsigned int ino, block;
05459ca81ac30 (Al Viro            2009-06-07 15:29:45 -0400 238) 	int err = 0;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 239) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 240) 	ino = inode->i_ino;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 241) 	if (!ino || ino > sbi->s_ninodes) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 242) 		printk("Bad inode number on dev %s: %d is out of range\n",
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 243) 		       inode->i_sb->s_id, ino);
05459ca81ac30 (Al Viro            2009-06-07 15:29:45 -0400 244) 		return -EIO;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 245) 	}
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 246) 	raw_inode = sysv_raw_inode(sb, ino, &bh);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 247) 	if (!raw_inode) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 248) 		printk("unable to read i-node block\n");
05459ca81ac30 (Al Viro            2009-06-07 15:29:45 -0400 249) 		return -EIO;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 250) 	}
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 251) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 252) 	raw_inode->i_mode = cpu_to_fs16(sbi, inode->i_mode);
a726ecce75896 (Eric W. Biederman  2012-02-10 12:19:23 -0800 253) 	raw_inode->i_uid = cpu_to_fs16(sbi, fs_high2lowuid(i_uid_read(inode)));
a726ecce75896 (Eric W. Biederman  2012-02-10 12:19:23 -0800 254) 	raw_inode->i_gid = cpu_to_fs16(sbi, fs_high2lowgid(i_gid_read(inode)));
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 255) 	raw_inode->i_nlink = cpu_to_fs16(sbi, inode->i_nlink);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 256) 	raw_inode->i_size = cpu_to_fs32(sbi, inode->i_size);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 257) 	raw_inode->i_atime = cpu_to_fs32(sbi, inode->i_atime.tv_sec);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 258) 	raw_inode->i_mtime = cpu_to_fs32(sbi, inode->i_mtime.tv_sec);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 259) 	raw_inode->i_ctime = cpu_to_fs32(sbi, inode->i_ctime.tv_sec);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 260) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 261) 	si = SYSV_I(inode);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 262) 	if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 263) 		si->i_data[0] = cpu_to_fs32(sbi, old_encode_dev(inode->i_rdev));
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 264) 	for (block = 0; block < 10+1+1+1; block++)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 265) 		write3byte(sbi, (u8 *)&si->i_data[block],
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 266) 			&raw_inode->i_data[3*block]);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 267) 	mark_buffer_dirty(bh);
05459ca81ac30 (Al Viro            2009-06-07 15:29:45 -0400 268) 	if (wait) {
05459ca81ac30 (Al Viro            2009-06-07 15:29:45 -0400 269)                 sync_dirty_buffer(bh);
05459ca81ac30 (Al Viro            2009-06-07 15:29:45 -0400 270)                 if (buffer_req(bh) && !buffer_uptodate(bh)) {
05459ca81ac30 (Al Viro            2009-06-07 15:29:45 -0400 271)                         printk ("IO error syncing sysv inode [%s:%08x]\n",
05459ca81ac30 (Al Viro            2009-06-07 15:29:45 -0400 272)                                 sb->s_id, ino);
05459ca81ac30 (Al Viro            2009-06-07 15:29:45 -0400 273)                         err = -EIO;
05459ca81ac30 (Al Viro            2009-06-07 15:29:45 -0400 274)                 }
05459ca81ac30 (Al Viro            2009-06-07 15:29:45 -0400 275)         }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 276) 	brelse(bh);
c4b7d1ba7d263 (YueHaibing         2018-11-10 04:13:24 +0000 277) 	return err;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 278) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 279) 
a9185b41a4f84 (Christoph Hellwig  2010-03-05 09:21:37 +0100 280) int sysv_write_inode(struct inode *inode, struct writeback_control *wbc)
a9185b41a4f84 (Christoph Hellwig  2010-03-05 09:21:37 +0100 281) {
a9185b41a4f84 (Christoph Hellwig  2010-03-05 09:21:37 +0100 282) 	return __sysv_write_inode(inode, wbc->sync_mode == WB_SYNC_ALL);
a9185b41a4f84 (Christoph Hellwig  2010-03-05 09:21:37 +0100 283) }
a9185b41a4f84 (Christoph Hellwig  2010-03-05 09:21:37 +0100 284) 
05459ca81ac30 (Al Viro            2009-06-07 15:29:45 -0400 285) int sysv_sync_inode(struct inode *inode)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 286) {
a9185b41a4f84 (Christoph Hellwig  2010-03-05 09:21:37 +0100 287) 	return __sysv_write_inode(inode, 1);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 288) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 289) 
d299eadc09874 (Al Viro            2010-06-05 19:16:20 -0400 290) static void sysv_evict_inode(struct inode *inode)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 291) {
91b0abe36a7b2 (Johannes Weiner    2014-04-03 14:47:49 -0700 292) 	truncate_inode_pages_final(&inode->i_data);
d299eadc09874 (Al Viro            2010-06-05 19:16:20 -0400 293) 	if (!inode->i_nlink) {
d299eadc09874 (Al Viro            2010-06-05 19:16:20 -0400 294) 		inode->i_size = 0;
d299eadc09874 (Al Viro            2010-06-05 19:16:20 -0400 295) 		sysv_truncate(inode);
d299eadc09874 (Al Viro            2010-06-05 19:16:20 -0400 296) 	}
d299eadc09874 (Al Viro            2010-06-05 19:16:20 -0400 297) 	invalidate_inode_buffers(inode);
dbd5768f87ff6 (Jan Kara           2012-05-03 14:48:02 +0200 298) 	clear_inode(inode);
d299eadc09874 (Al Viro            2010-06-05 19:16:20 -0400 299) 	if (!inode->i_nlink)
d299eadc09874 (Al Viro            2010-06-05 19:16:20 -0400 300) 		sysv_free_inode(inode);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 301) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 302) 
e18b890bb0881 (Christoph Lameter  2006-12-06 20:33:20 -0800 303) static struct kmem_cache *sysv_inode_cachep;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 304) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 305) static struct inode *sysv_alloc_inode(struct super_block *sb)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 306) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 307) 	struct sysv_inode_info *si;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 308) 
e94b1766097d5 (Christoph Lameter  2006-12-06 20:33:17 -0800 309) 	si = kmem_cache_alloc(sysv_inode_cachep, GFP_KERNEL);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 310) 	if (!si)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 311) 		return NULL;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 312) 	return &si->vfs_inode;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 313) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 314) 
6becf8edf1a74 (Al Viro            2019-04-15 22:26:51 -0400 315) static void sysv_free_in_core_inode(struct inode *inode)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 316) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 317) 	kmem_cache_free(sysv_inode_cachep, SYSV_I(inode));
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 318) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 319) 
51cc50685a427 (Alexey Dobriyan    2008-07-25 19:45:34 -0700 320) static void init_once(void *p)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 321) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 322) 	struct sysv_inode_info *si = (struct sysv_inode_info *)p;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 323) 
a35afb830f8d7 (Christoph Lameter  2007-05-16 22:10:57 -0700 324) 	inode_init_once(&si->vfs_inode);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 325) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 326) 
ee9b6d61a2a43 (Josef 'Jeff' Sipek 2007-02-12 00:55:41 -0800 327) const struct super_operations sysv_sops = {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 328) 	.alloc_inode	= sysv_alloc_inode,
6becf8edf1a74 (Al Viro            2019-04-15 22:26:51 -0400 329) 	.free_inode	= sysv_free_in_core_inode,
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 330) 	.write_inode	= sysv_write_inode,
d299eadc09874 (Al Viro            2010-06-05 19:16:20 -0400 331) 	.evict_inode	= sysv_evict_inode,
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 332) 	.put_super	= sysv_put_super,
ad43ffdeea0a7 (Christoph Hellwig  2009-06-08 10:07:45 +0200 333) 	.sync_fs	= sysv_sync_fs,
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 334) 	.remount_fs	= sysv_remount,
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 335) 	.statfs		= sysv_statfs,
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 336) };
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 337) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 338) int __init sysv_init_icache(void)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 339) {
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 340) 	sysv_inode_cachep = kmem_cache_create("sysv_inode_cache",
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 341) 			sizeof(struct sysv_inode_info), 0,
5d097056c9a01 (Vladimir Davydov   2016-01-14 15:18:21 -0800 342) 			SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_ACCOUNT,
20c2df83d25c6 (Paul Mundt         2007-07-20 10:11:58 +0900 343) 			init_once);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 344) 	if (!sysv_inode_cachep)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 345) 		return -ENOMEM;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 346) 	return 0;
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 347) }
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 348) 
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 349) void sysv_destroy_icache(void)
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 350) {
8c0a85377048b (Kirill A. Shutemov 2012-09-26 11:33:07 +1000 351) 	/*
8c0a85377048b (Kirill A. Shutemov 2012-09-26 11:33:07 +1000 352) 	 * Make sure all delayed rcu free inodes are flushed before we
8c0a85377048b (Kirill A. Shutemov 2012-09-26 11:33:07 +1000 353) 	 * destroy cache.
8c0a85377048b (Kirill A. Shutemov 2012-09-26 11:33:07 +1000 354) 	 */
8c0a85377048b (Kirill A. Shutemov 2012-09-26 11:33:07 +1000 355) 	rcu_barrier();
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 356) 	kmem_cache_destroy(sysv_inode_cachep);
^1da177e4c3f4 (Linus Torvalds     2005-04-16 15:20:36 -0700 357) }