Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags   |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  *  linux/fs/hfs/inode.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) 1995-1997  Paul H. Hargrove
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * (C) 2003 Ardis Technologies <roman@ardistech.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * This file may be distributed under the terms of the GNU General Public License.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * This file contains inode-related functions which do not depend on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * which scheme is being used to represent forks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * Based on the minix file system code, (C) 1991, 1992 by Linus Torvalds
^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/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/mpage.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/cred.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/uio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/xattr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include "hfs_fs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include "btree.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static const struct file_operations hfs_file_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static const struct inode_operations hfs_file_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) /*================ Variable-like macros ================*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define HFS_VALID_MODE_BITS  (S_IFREG | S_IFDIR | S_IRWXUGO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) static int hfs_writepage(struct page *page, struct writeback_control *wbc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	return block_write_full_page(page, hfs_get_block, wbc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static int hfs_readpage(struct file *file, struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	return block_read_full_page(page, hfs_get_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) static void hfs_write_failed(struct address_space *mapping, loff_t to)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	struct inode *inode = mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	if (to > inode->i_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		truncate_pagecache(inode, inode->i_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		hfs_file_truncate(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static int hfs_write_begin(struct file *file, struct address_space *mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 			loff_t pos, unsigned len, unsigned flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 			struct page **pagep, void **fsdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	*pagep = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	ret = cont_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 				hfs_get_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 				&HFS_I(mapping->host)->phys_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	if (unlikely(ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		hfs_write_failed(mapping, pos + len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) static sector_t hfs_bmap(struct address_space *mapping, sector_t block)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	return generic_block_bmap(mapping, block, hfs_get_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static int hfs_releasepage(struct page *page, gfp_t mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	struct inode *inode = page->mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	struct super_block *sb = inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct hfs_btree *tree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	struct hfs_bnode *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	u32 nidx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	int i, res = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	switch (inode->i_ino) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	case HFS_EXT_CNID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		tree = HFS_SB(sb)->ext_tree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	case HFS_CAT_CNID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		tree = HFS_SB(sb)->cat_tree;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	if (!tree)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (tree->node_size >= PAGE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		nidx = page->index >> (tree->node_size_shift - PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		spin_lock(&tree->hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		node = hfs_bnode_findhash(tree, nidx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		if (!node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 			;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		else if (atomic_read(&node->refcnt))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		if (res && node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			hfs_bnode_unhash(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 			hfs_bnode_free(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		spin_unlock(&tree->hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		nidx = page->index << (PAGE_SHIFT - tree->node_size_shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		i = 1 << (PAGE_SHIFT - tree->node_size_shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		spin_lock(&tree->hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 			node = hfs_bnode_findhash(tree, nidx++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			if (!node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 			if (atomic_read(&node->refcnt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 				res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			hfs_bnode_unhash(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			hfs_bnode_free(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		} while (--i && nidx < tree->node_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		spin_unlock(&tree->hash_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	return res ? try_to_free_buffers(page) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) static ssize_t hfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	struct file *file = iocb->ki_filp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	struct address_space *mapping = file->f_mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	struct inode *inode = mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	size_t count = iov_iter_count(iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	ssize_t ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	ret = blockdev_direct_IO(iocb, inode, iter, hfs_get_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	 * In case of error extending write may have instantiated a few
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	 * blocks outside i_size. Trim these off again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	if (unlikely(iov_iter_rw(iter) == WRITE && ret < 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 		loff_t isize = i_size_read(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		loff_t end = iocb->ki_pos + count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		if (end > isize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			hfs_write_failed(mapping, end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) static int hfs_writepages(struct address_space *mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			  struct writeback_control *wbc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	return mpage_writepages(mapping, wbc, hfs_get_block);
^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) const struct address_space_operations hfs_btree_aops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	.readpage	= hfs_readpage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	.writepage	= hfs_writepage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	.write_begin	= hfs_write_begin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	.write_end	= generic_write_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	.bmap		= hfs_bmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	.releasepage	= hfs_releasepage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) const struct address_space_operations hfs_aops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	.readpage	= hfs_readpage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	.writepage	= hfs_writepage,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	.write_begin	= hfs_write_begin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	.write_end	= generic_write_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	.bmap		= hfs_bmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	.direct_IO	= hfs_direct_IO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	.writepages	= hfs_writepages,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  * hfs_new_inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) struct inode *hfs_new_inode(struct inode *dir, const struct qstr *name, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	struct super_block *sb = dir->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	struct inode *inode = new_inode(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	mutex_init(&HFS_I(inode)->extents_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	INIT_LIST_HEAD(&HFS_I(inode)->open_dir_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	spin_lock_init(&HFS_I(inode)->open_dir_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	hfs_cat_build_key(sb, (btree_key *)&HFS_I(inode)->cat_key, dir->i_ino, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	inode->i_ino = HFS_SB(sb)->next_id++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	inode->i_mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	inode->i_uid = current_fsuid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	inode->i_gid = current_fsgid();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	set_nlink(inode, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	HFS_I(inode)->flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	HFS_I(inode)->rsrc_inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	HFS_I(inode)->fs_blocks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	if (S_ISDIR(mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		inode->i_size = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		HFS_SB(sb)->folder_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		if (dir->i_ino == HFS_ROOT_CNID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			HFS_SB(sb)->root_dirs++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		inode->i_op = &hfs_dir_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		inode->i_fop = &hfs_dir_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		inode->i_mode |= S_IRWXUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		inode->i_mode &= ~HFS_SB(inode->i_sb)->s_dir_umask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	} else if (S_ISREG(mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		HFS_I(inode)->clump_blocks = HFS_SB(sb)->clumpablks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		HFS_SB(sb)->file_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		if (dir->i_ino == HFS_ROOT_CNID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 			HFS_SB(sb)->root_files++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		inode->i_op = &hfs_file_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		inode->i_fop = &hfs_file_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		inode->i_mapping->a_ops = &hfs_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		inode->i_mode |= S_IRUGO|S_IXUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		if (mode & S_IWUSR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 			inode->i_mode |= S_IWUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 		inode->i_mode &= ~HFS_SB(inode->i_sb)->s_file_umask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		HFS_I(inode)->phys_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		HFS_I(inode)->alloc_blocks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		HFS_I(inode)->first_blocks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		HFS_I(inode)->cached_start = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		HFS_I(inode)->cached_blocks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		memset(HFS_I(inode)->first_extents, 0, sizeof(hfs_extent_rec));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		memset(HFS_I(inode)->cached_extents, 0, sizeof(hfs_extent_rec));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	insert_inode_hash(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	set_bit(HFS_FLG_MDB_DIRTY, &HFS_SB(sb)->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	hfs_mark_mdb_dirty(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) void hfs_delete_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	struct super_block *sb = inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	hfs_dbg(INODE, "delete_inode: %lu\n", inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	if (S_ISDIR(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		HFS_SB(sb)->folder_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 		if (HFS_I(inode)->cat_key.ParID == cpu_to_be32(HFS_ROOT_CNID))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 			HFS_SB(sb)->root_dirs--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		set_bit(HFS_FLG_MDB_DIRTY, &HFS_SB(sb)->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		hfs_mark_mdb_dirty(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	HFS_SB(sb)->file_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	if (HFS_I(inode)->cat_key.ParID == cpu_to_be32(HFS_ROOT_CNID))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		HFS_SB(sb)->root_files--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	if (S_ISREG(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		if (!inode->i_nlink) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 			inode->i_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 			hfs_file_truncate(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	set_bit(HFS_FLG_MDB_DIRTY, &HFS_SB(sb)->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	hfs_mark_mdb_dirty(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) void hfs_inode_read_fork(struct inode *inode, struct hfs_extent *ext,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			 __be32 __log_size, __be32 phys_size, u32 clump_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	struct super_block *sb = inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	u32 log_size = be32_to_cpu(__log_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	u16 count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	memcpy(HFS_I(inode)->first_extents, ext, sizeof(hfs_extent_rec));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	for (count = 0, i = 0; i < 3; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		count += be16_to_cpu(ext[i].count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	HFS_I(inode)->first_blocks = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	inode->i_size = HFS_I(inode)->phys_size = log_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	HFS_I(inode)->fs_blocks = (log_size + sb->s_blocksize - 1) >> sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 	inode_set_bytes(inode, HFS_I(inode)->fs_blocks << sb->s_blocksize_bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	HFS_I(inode)->alloc_blocks = be32_to_cpu(phys_size) /
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 				     HFS_SB(sb)->alloc_blksz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	HFS_I(inode)->clump_blocks = clump_size / HFS_SB(sb)->alloc_blksz;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	if (!HFS_I(inode)->clump_blocks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		HFS_I(inode)->clump_blocks = HFS_SB(sb)->clumpablks;
^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) struct hfs_iget_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	struct hfs_cat_key *key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	hfs_cat_rec *rec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) static int hfs_test_inode(struct inode *inode, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	struct hfs_iget_data *idata = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	hfs_cat_rec *rec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	rec = idata->rec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	switch (rec->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	case HFS_CDR_DIR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		return inode->i_ino == be32_to_cpu(rec->dir.DirID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	case HFS_CDR_FIL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		return inode->i_ino == be32_to_cpu(rec->file.FlNum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)  * hfs_read_inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static int hfs_read_inode(struct inode *inode, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	struct hfs_iget_data *idata = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	struct hfs_sb_info *hsb = HFS_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	hfs_cat_rec *rec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	HFS_I(inode)->flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	HFS_I(inode)->rsrc_inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	mutex_init(&HFS_I(inode)->extents_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	INIT_LIST_HEAD(&HFS_I(inode)->open_dir_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	spin_lock_init(&HFS_I(inode)->open_dir_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	/* Initialize the inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	inode->i_uid = hsb->s_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	inode->i_gid = hsb->s_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	set_nlink(inode, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	if (idata->key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		HFS_I(inode)->cat_key = *idata->key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		HFS_I(inode)->flags |= HFS_FLG_RSRC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	HFS_I(inode)->tz_secondswest = sys_tz.tz_minuteswest * 60;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	rec = idata->rec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	switch (rec->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 	case HFS_CDR_FIL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		if (!HFS_IS_RSRC(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 			hfs_inode_read_fork(inode, rec->file.ExtRec, rec->file.LgLen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 					    rec->file.PyLen, be16_to_cpu(rec->file.ClpSize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 			hfs_inode_read_fork(inode, rec->file.RExtRec, rec->file.RLgLen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 					    rec->file.RPyLen, be16_to_cpu(rec->file.ClpSize));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		inode->i_ino = be32_to_cpu(rec->file.FlNum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		inode->i_mode = S_IRUGO | S_IXUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 		if (!(rec->file.Flags & HFS_FIL_LOCK))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 			inode->i_mode |= S_IWUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		inode->i_mode &= ~hsb->s_file_umask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		inode->i_mode |= S_IFREG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		inode->i_ctime = inode->i_atime = inode->i_mtime =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 				hfs_m_to_utime(rec->file.MdDat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		inode->i_op = &hfs_file_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		inode->i_fop = &hfs_file_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		inode->i_mapping->a_ops = &hfs_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	case HFS_CDR_DIR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		inode->i_ino = be32_to_cpu(rec->dir.DirID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 		inode->i_size = be16_to_cpu(rec->dir.Val) + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 		HFS_I(inode)->fs_blocks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 		inode->i_mode = S_IFDIR | (S_IRWXUGO & ~hsb->s_dir_umask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 		inode->i_ctime = inode->i_atime = inode->i_mtime =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 				hfs_m_to_utime(rec->dir.MdDat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		inode->i_op = &hfs_dir_inode_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 		inode->i_fop = &hfs_dir_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		make_bad_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)  * __hfs_iget()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)  * Given the MDB for a HFS filesystem, a 'key' and an 'entry' in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)  * the catalog B-tree and the 'type' of the desired file return the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)  * inode for that file/directory or NULL.  Note that 'type' indicates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)  * whether we want the actual file or directory, or the corresponding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)  * metadata (AppleDouble header file or CAP metadata file).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) struct inode *hfs_iget(struct super_block *sb, struct hfs_cat_key *key, hfs_cat_rec *rec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	struct hfs_iget_data data = { key, rec };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	u32 cnid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	switch (rec->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	case HFS_CDR_DIR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		cnid = be32_to_cpu(rec->dir.DirID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	case HFS_CDR_FIL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 		cnid = be32_to_cpu(rec->file.FlNum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 	inode = iget5_locked(sb, cnid, hfs_test_inode, hfs_read_inode, &data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 	if (inode && (inode->i_state & I_NEW))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		unlock_new_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 	return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) void hfs_inode_write_fork(struct inode *inode, struct hfs_extent *ext,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 			  __be32 *log_size, __be32 *phys_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	memcpy(ext, HFS_I(inode)->first_extents, sizeof(hfs_extent_rec));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	if (log_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		*log_size = cpu_to_be32(inode->i_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 	if (phys_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		*phys_size = cpu_to_be32(HFS_I(inode)->alloc_blocks *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 					 HFS_SB(inode->i_sb)->alloc_blksz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) int hfs_write_inode(struct inode *inode, struct writeback_control *wbc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	struct inode *main_inode = inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	struct hfs_find_data fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	hfs_cat_rec rec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	hfs_dbg(INODE, "hfs_write_inode: %lu\n", inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	res = hfs_ext_write_extent(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 		return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	if (inode->i_ino < HFS_FIRSTUSER_CNID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		switch (inode->i_ino) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 		case HFS_ROOT_CNID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		case HFS_EXT_CNID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 			hfs_btree_write(HFS_SB(inode->i_sb)->ext_tree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 		case HFS_CAT_CNID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 			hfs_btree_write(HFS_SB(inode->i_sb)->cat_tree);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 			return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 			BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) 			return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	if (HFS_IS_RSRC(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 		main_inode = HFS_I(inode)->rsrc_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 	if (!main_inode->i_nlink)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 	if (hfs_find_init(HFS_SB(main_inode->i_sb)->cat_tree, &fd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		/* panic? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 	fd.search_key->cat = HFS_I(main_inode)->cat_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	if (hfs_brec_find(&fd))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 		/* panic? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 	if (S_ISDIR(main_inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 		if (fd.entrylength < sizeof(struct hfs_cat_dir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 			/* panic? */;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 		hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 			   sizeof(struct hfs_cat_dir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 		if (rec.type != HFS_CDR_DIR ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		    be32_to_cpu(rec.dir.DirID) != inode->i_ino) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		rec.dir.MdDat = hfs_u_to_mtime(inode->i_mtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 		rec.dir.Val = cpu_to_be16(inode->i_size - 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 		hfs_bnode_write(fd.bnode, &rec, fd.entryoffset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 			    sizeof(struct hfs_cat_dir));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 	} else if (HFS_IS_RSRC(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 		hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 			       sizeof(struct hfs_cat_file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		hfs_inode_write_fork(inode, rec.file.RExtRec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 				     &rec.file.RLgLen, &rec.file.RPyLen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		hfs_bnode_write(fd.bnode, &rec, fd.entryoffset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 				sizeof(struct hfs_cat_file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 		if (fd.entrylength < sizeof(struct hfs_cat_file))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 			/* panic? */;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 		hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 			   sizeof(struct hfs_cat_file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 		if (rec.type != HFS_CDR_FIL ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 		    be32_to_cpu(rec.file.FlNum) != inode->i_ino) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 		if (inode->i_mode & S_IWUSR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 			rec.file.Flags &= ~HFS_FIL_LOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 			rec.file.Flags |= HFS_FIL_LOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 		hfs_inode_write_fork(inode, rec.file.ExtRec, &rec.file.LgLen, &rec.file.PyLen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 		rec.file.MdDat = hfs_u_to_mtime(inode->i_mtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 		hfs_bnode_write(fd.bnode, &rec, fd.entryoffset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 			    sizeof(struct hfs_cat_file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 	hfs_find_exit(&fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) static struct dentry *hfs_file_lookup(struct inode *dir, struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 				      unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	struct inode *inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	hfs_cat_rec rec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	struct hfs_find_data fd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 	if (HFS_IS_RSRC(dir) || strcmp(dentry->d_name.name, "rsrc"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	inode = HFS_I(dir)->rsrc_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 	if (inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	inode = new_inode(dir->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	res = hfs_find_init(HFS_SB(dir->i_sb)->cat_tree, &fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 	if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 		iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 		return ERR_PTR(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) 	fd.search_key->cat = HFS_I(dir)->cat_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	res = hfs_brec_read(&fd, &rec, sizeof(rec));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) 	if (!res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 		struct hfs_iget_data idata = { NULL, &rec };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 		hfs_read_inode(inode, &idata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 	hfs_find_exit(&fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) 	if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 		iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 		return ERR_PTR(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	HFS_I(inode)->rsrc_inode = dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	HFS_I(dir)->rsrc_inode = inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	igrab(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	inode_fake_hash(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	dont_mount(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) 	return d_splice_alias(inode, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) void hfs_evict_inode(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	truncate_inode_pages_final(&inode->i_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	clear_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	if (HFS_IS_RSRC(inode) && HFS_I(inode)->rsrc_inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 		HFS_I(HFS_I(inode)->rsrc_inode)->rsrc_inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 		iput(HFS_I(inode)->rsrc_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) static int hfs_file_open(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	if (HFS_IS_RSRC(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 		inode = HFS_I(inode)->rsrc_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	atomic_inc(&HFS_I(inode)->opencnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) static int hfs_file_release(struct inode *inode, struct file *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	//struct super_block *sb = inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	if (HFS_IS_RSRC(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 		inode = HFS_I(inode)->rsrc_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	if (atomic_dec_and_test(&HFS_I(inode)->opencnt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 		inode_lock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 		hfs_file_truncate(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 		//if (inode->i_flags & S_DEAD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 		//	hfs_delete_cat(inode->i_ino, HFSPLUS_SB(sb).hidden_dir, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 		//	hfs_delete_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 		//}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 		inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)  * hfs_notify_change()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)  * Based very closely on fs/msdos/inode.c by Werner Almesberger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)  * This is the notify_change() field in the super_operations structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)  * for HFS file systems.  The purpose is to take that changes made to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)  * an inode and apply then in a filesystem-dependent manner.  In this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596)  * case the process has a few of tasks to do:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597)  *  1) prevent changes to the i_uid and i_gid fields.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)  *  2) map file permissions to the closest allowable permissions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599)  *  3) Since multiple Linux files can share the same on-disk inode under
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)  *     HFS (for instance the data and resource forks of a file) a change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)  *     to permissions must be applied to all other in-core inodes which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)  *     correspond to the same HFS file.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) int hfs_inode_setattr(struct dentry *dentry, struct iattr * attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 	struct inode *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	struct hfs_sb_info *hsb = HFS_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 	error = setattr_prepare(dentry, attr); /* basic permission checks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) 	/* no uig/gid changes and limit which mode bits can be set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) 	if (((attr->ia_valid & ATTR_UID) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) 	     (!uid_eq(attr->ia_uid, hsb->s_uid))) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	    ((attr->ia_valid & ATTR_GID) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 	     (!gid_eq(attr->ia_gid, hsb->s_gid))) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) 	    ((attr->ia_valid & ATTR_MODE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	     ((S_ISDIR(inode->i_mode) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) 	       (attr->ia_mode != inode->i_mode)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	      (attr->ia_mode & ~HFS_VALID_MODE_BITS)))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 		return hsb->s_quiet ? 0 : error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 	if (attr->ia_valid & ATTR_MODE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) 		/* Only the 'w' bits can ever change and only all together. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) 		if (attr->ia_mode & S_IWUSR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 			attr->ia_mode = inode->i_mode | S_IWUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 			attr->ia_mode = inode->i_mode & ~S_IWUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 		attr->ia_mode &= S_ISDIR(inode->i_mode) ? ~hsb->s_dir_umask: ~hsb->s_file_umask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	if ((attr->ia_valid & ATTR_SIZE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 	    attr->ia_size != i_size_read(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 		inode_dio_wait(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 		error = inode_newsize_ok(inode, attr->ia_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 			return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 		truncate_setsize(inode, attr->ia_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) 		hfs_file_truncate(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 		inode->i_atime = inode->i_mtime = inode->i_ctime =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 						  current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	setattr_copy(inode, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) 	mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) 	return 0;
^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) static int hfs_file_fsync(struct file *filp, loff_t start, loff_t end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 			  int datasync)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 	struct inode *inode = filp->f_mapping->host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 	struct super_block * sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	int ret, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 	ret = file_write_and_wait_range(filp, start, end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	inode_lock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 	/* sync the inode to buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) 	ret = write_inode_now(inode, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	/* sync the superblock to buffers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) 	sb = inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 	flush_delayed_work(&HFS_SB(sb)->mdb_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) 	/* .. finally sync the buffers to disk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) 	err = sync_blockdev(sb->s_bdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) 		ret = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) 	inode_unlock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) static const struct file_operations hfs_file_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) 	.llseek		= generic_file_llseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) 	.read_iter	= generic_file_read_iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) 	.write_iter	= generic_file_write_iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) 	.mmap		= generic_file_mmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) 	.splice_read	= generic_file_splice_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) 	.fsync		= hfs_file_fsync,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) 	.open		= hfs_file_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) 	.release	= hfs_file_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) static const struct inode_operations hfs_file_inode_operations = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) 	.lookup		= hfs_file_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) 	.setattr	= hfs_inode_setattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) 	.listxattr	= generic_listxattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) };