Linux Audio

Check our new training course

Yocto / OpenEmbedded training

Mar 24-27, 2025, special US time zones
Register
Loading...
v4.6
  1/*
  2 *  linux/fs/hpfs/inode.c
  3 *
  4 *  Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 1998-1999
  5 *
  6 *  inode VFS functions
  7 */
  8
  9#include <linux/slab.h>
 10#include <linux/user_namespace.h>
 11#include "hpfs_fn.h"
 12
 13void hpfs_init_inode(struct inode *i)
 14{
 15	struct super_block *sb = i->i_sb;
 16	struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
 17
 18	i->i_uid = hpfs_sb(sb)->sb_uid;
 19	i->i_gid = hpfs_sb(sb)->sb_gid;
 20	i->i_mode = hpfs_sb(sb)->sb_mode;
 21	i->i_size = -1;
 22	i->i_blocks = -1;
 23	
 24	hpfs_inode->i_dno = 0;
 25	hpfs_inode->i_n_secs = 0;
 26	hpfs_inode->i_file_sec = 0;
 27	hpfs_inode->i_disk_sec = 0;
 28	hpfs_inode->i_dpos = 0;
 29	hpfs_inode->i_dsubdno = 0;
 30	hpfs_inode->i_ea_mode = 0;
 31	hpfs_inode->i_ea_uid = 0;
 32	hpfs_inode->i_ea_gid = 0;
 33	hpfs_inode->i_ea_size = 0;
 34
 35	hpfs_inode->i_rddir_off = NULL;
 36	hpfs_inode->i_dirty = 0;
 37
 38	i->i_ctime.tv_sec = i->i_ctime.tv_nsec = 0;
 39	i->i_mtime.tv_sec = i->i_mtime.tv_nsec = 0;
 40	i->i_atime.tv_sec = i->i_atime.tv_nsec = 0;
 41}
 42
 43void hpfs_read_inode(struct inode *i)
 44{
 45	struct buffer_head *bh;
 46	struct fnode *fnode;
 47	struct super_block *sb = i->i_sb;
 48	struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
 49	void *ea;
 50	int ea_size;
 51
 52	if (!(fnode = hpfs_map_fnode(sb, i->i_ino, &bh))) {
 53		/*i->i_mode |= S_IFREG;
 54		i->i_mode &= ~0111;
 55		i->i_op = &hpfs_file_iops;
 56		i->i_fop = &hpfs_file_ops;
 57		clear_nlink(i);*/
 58		make_bad_inode(i);
 59		return;
 60	}
 61	if (hpfs_sb(i->i_sb)->sb_eas) {
 62		if ((ea = hpfs_get_ea(i->i_sb, fnode, "UID", &ea_size))) {
 63			if (ea_size == 2) {
 64				i_uid_write(i, le16_to_cpu(*(__le16*)ea));
 65				hpfs_inode->i_ea_uid = 1;
 66			}
 67			kfree(ea);
 68		}
 69		if ((ea = hpfs_get_ea(i->i_sb, fnode, "GID", &ea_size))) {
 70			if (ea_size == 2) {
 71				i_gid_write(i, le16_to_cpu(*(__le16*)ea));
 72				hpfs_inode->i_ea_gid = 1;
 73			}
 74			kfree(ea);
 75		}
 76		if ((ea = hpfs_get_ea(i->i_sb, fnode, "SYMLINK", &ea_size))) {
 77			kfree(ea);
 78			i->i_mode = S_IFLNK | 0777;
 79			i->i_op = &page_symlink_inode_operations;
 80			inode_nohighmem(i);
 81			i->i_data.a_ops = &hpfs_symlink_aops;
 82			set_nlink(i, 1);
 83			i->i_size = ea_size;
 84			i->i_blocks = 1;
 85			brelse(bh);
 86			return;
 87		}
 88		if ((ea = hpfs_get_ea(i->i_sb, fnode, "MODE", &ea_size))) {
 89			int rdev = 0;
 90			umode_t mode = hpfs_sb(sb)->sb_mode;
 91			if (ea_size == 2) {
 92				mode = le16_to_cpu(*(__le16*)ea);
 93				hpfs_inode->i_ea_mode = 1;
 94			}
 95			kfree(ea);
 96			i->i_mode = mode;
 97			if (S_ISBLK(mode) || S_ISCHR(mode)) {
 98				if ((ea = hpfs_get_ea(i->i_sb, fnode, "DEV", &ea_size))) {
 99					if (ea_size == 4)
100						rdev = le32_to_cpu(*(__le32*)ea);
101					kfree(ea);
102				}
103			}
104			if (S_ISBLK(mode) || S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) {
105				brelse(bh);
106				set_nlink(i, 1);
107				i->i_size = 0;
108				i->i_blocks = 1;
109				init_special_inode(i, mode,
110					new_decode_dev(rdev));
111				return;
112			}
113		}
114	}
115	if (fnode_is_dir(fnode)) {
116		int n_dnodes, n_subdirs;
117		i->i_mode |= S_IFDIR;
118		i->i_op = &hpfs_dir_iops;
119		i->i_fop = &hpfs_dir_ops;
120		hpfs_inode->i_parent_dir = le32_to_cpu(fnode->up);
121		hpfs_inode->i_dno = le32_to_cpu(fnode->u.external[0].disk_secno);
122		if (hpfs_sb(sb)->sb_chk >= 2) {
123			struct buffer_head *bh0;
124			if (hpfs_map_fnode(sb, hpfs_inode->i_parent_dir, &bh0)) brelse(bh0);
125		}
126		n_dnodes = 0; n_subdirs = 0;
127		hpfs_count_dnodes(i->i_sb, hpfs_inode->i_dno, &n_dnodes, &n_subdirs, NULL);
128		i->i_blocks = 4 * n_dnodes;
129		i->i_size = 2048 * n_dnodes;
130		set_nlink(i, 2 + n_subdirs);
131	} else {
132		i->i_mode |= S_IFREG;
133		if (!hpfs_inode->i_ea_mode) i->i_mode &= ~0111;
134		i->i_op = &hpfs_file_iops;
135		i->i_fop = &hpfs_file_ops;
136		set_nlink(i, 1);
137		i->i_size = le32_to_cpu(fnode->file_size);
138		i->i_blocks = ((i->i_size + 511) >> 9) + 1;
139		i->i_data.a_ops = &hpfs_aops;
140		hpfs_i(i)->mmu_private = i->i_size;
141	}
142	brelse(bh);
143}
144
145static void hpfs_write_inode_ea(struct inode *i, struct fnode *fnode)
146{
147	struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
148	/*if (le32_to_cpu(fnode->acl_size_l) || le16_to_cpu(fnode->acl_size_s)) {
149		   Some unknown structures like ACL may be in fnode,
150		   we'd better not overwrite them
151		hpfs_error(i->i_sb, "fnode %08x has some unknown HPFS386 structures", i->i_ino);
152	} else*/ if (hpfs_sb(i->i_sb)->sb_eas >= 2) {
153		__le32 ea;
154		if (!uid_eq(i->i_uid, hpfs_sb(i->i_sb)->sb_uid) || hpfs_inode->i_ea_uid) {
155			ea = cpu_to_le32(i_uid_read(i));
156			hpfs_set_ea(i, fnode, "UID", (char*)&ea, 2);
157			hpfs_inode->i_ea_uid = 1;
158		}
159		if (!gid_eq(i->i_gid, hpfs_sb(i->i_sb)->sb_gid) || hpfs_inode->i_ea_gid) {
160			ea = cpu_to_le32(i_gid_read(i));
161			hpfs_set_ea(i, fnode, "GID", (char *)&ea, 2);
162			hpfs_inode->i_ea_gid = 1;
163		}
164		if (!S_ISLNK(i->i_mode))
165			if ((i->i_mode != ((hpfs_sb(i->i_sb)->sb_mode & ~(S_ISDIR(i->i_mode) ? 0 : 0111))
166			  | (S_ISDIR(i->i_mode) ? S_IFDIR : S_IFREG))
167			  && i->i_mode != ((hpfs_sb(i->i_sb)->sb_mode & ~(S_ISDIR(i->i_mode) ? 0222 : 0333))
168			  | (S_ISDIR(i->i_mode) ? S_IFDIR : S_IFREG))) || hpfs_inode->i_ea_mode) {
169				ea = cpu_to_le32(i->i_mode);
170				/* sick, but legal */
171				hpfs_set_ea(i, fnode, "MODE", (char *)&ea, 2);
172				hpfs_inode->i_ea_mode = 1;
173			}
174		if (S_ISBLK(i->i_mode) || S_ISCHR(i->i_mode)) {
175			ea = cpu_to_le32(new_encode_dev(i->i_rdev));
176			hpfs_set_ea(i, fnode, "DEV", (char *)&ea, 4);
177		}
178	}
179}
180
181void hpfs_write_inode(struct inode *i)
182{
183	struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
184	struct inode *parent;
185	if (i->i_ino == hpfs_sb(i->i_sb)->sb_root) return;
186	if (hpfs_inode->i_rddir_off && !atomic_read(&i->i_count)) {
187		if (*hpfs_inode->i_rddir_off)
188			pr_err("write_inode: some position still there\n");
189		kfree(hpfs_inode->i_rddir_off);
190		hpfs_inode->i_rddir_off = NULL;
191	}
192	if (!i->i_nlink) {
193		return;
194	}
195	parent = iget_locked(i->i_sb, hpfs_inode->i_parent_dir);
196	if (parent) {
197		hpfs_inode->i_dirty = 0;
198		if (parent->i_state & I_NEW) {
199			hpfs_init_inode(parent);
200			hpfs_read_inode(parent);
201			unlock_new_inode(parent);
202		}
203		hpfs_write_inode_nolock(i);
204		iput(parent);
205	}
206}
207
208void hpfs_write_inode_nolock(struct inode *i)
209{
210	struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
211	struct buffer_head *bh;
212	struct fnode *fnode;
213	struct quad_buffer_head qbh;
214	struct hpfs_dirent *de;
215	if (i->i_ino == hpfs_sb(i->i_sb)->sb_root) return;
216	if (!(fnode = hpfs_map_fnode(i->i_sb, i->i_ino, &bh))) return;
217	if (i->i_ino != hpfs_sb(i->i_sb)->sb_root && i->i_nlink) {
218		if (!(de = map_fnode_dirent(i->i_sb, i->i_ino, fnode, &qbh))) {
219			brelse(bh);
220			return;
221		}
222	} else de = NULL;
223	if (S_ISREG(i->i_mode)) {
224		fnode->file_size = cpu_to_le32(i->i_size);
225		if (de) de->file_size = cpu_to_le32(i->i_size);
226	} else if (S_ISDIR(i->i_mode)) {
227		fnode->file_size = cpu_to_le32(0);
228		if (de) de->file_size = cpu_to_le32(0);
229	}
230	hpfs_write_inode_ea(i, fnode);
231	if (de) {
232		de->write_date = cpu_to_le32(gmt_to_local(i->i_sb, i->i_mtime.tv_sec));
233		de->read_date = cpu_to_le32(gmt_to_local(i->i_sb, i->i_atime.tv_sec));
234		de->creation_date = cpu_to_le32(gmt_to_local(i->i_sb, i->i_ctime.tv_sec));
235		de->read_only = !(i->i_mode & 0222);
236		de->ea_size = cpu_to_le32(hpfs_inode->i_ea_size);
237		hpfs_mark_4buffers_dirty(&qbh);
238		hpfs_brelse4(&qbh);
239	}
240	if (S_ISDIR(i->i_mode)) {
241		if ((de = map_dirent(i, hpfs_inode->i_dno, "\001\001", 2, NULL, &qbh))) {
242			de->write_date = cpu_to_le32(gmt_to_local(i->i_sb, i->i_mtime.tv_sec));
243			de->read_date = cpu_to_le32(gmt_to_local(i->i_sb, i->i_atime.tv_sec));
244			de->creation_date = cpu_to_le32(gmt_to_local(i->i_sb, i->i_ctime.tv_sec));
245			de->read_only = !(i->i_mode & 0222);
246			de->ea_size = cpu_to_le32(/*hpfs_inode->i_ea_size*/0);
247			de->file_size = cpu_to_le32(0);
248			hpfs_mark_4buffers_dirty(&qbh);
249			hpfs_brelse4(&qbh);
250		} else
251			hpfs_error(i->i_sb,
252				"directory %08lx doesn't have '.' entry",
253				(unsigned long)i->i_ino);
254	}
255	mark_buffer_dirty(bh);
256	brelse(bh);
257}
258
259int hpfs_setattr(struct dentry *dentry, struct iattr *attr)
260{
261	struct inode *inode = d_inode(dentry);
262	int error = -EINVAL;
263
264	hpfs_lock(inode->i_sb);
265	if (inode->i_ino == hpfs_sb(inode->i_sb)->sb_root)
266		goto out_unlock;
267	if ((attr->ia_valid & ATTR_UID) &&
268	    from_kuid(&init_user_ns, attr->ia_uid) >= 0x10000)
269		goto out_unlock;
270	if ((attr->ia_valid & ATTR_GID) &&
271	    from_kgid(&init_user_ns, attr->ia_gid) >= 0x10000)
272		goto out_unlock;
273	if ((attr->ia_valid & ATTR_SIZE) && attr->ia_size > inode->i_size)
274		goto out_unlock;
275
276	error = inode_change_ok(inode, attr);
277	if (error)
278		goto out_unlock;
279
280	if ((attr->ia_valid & ATTR_SIZE) &&
281	    attr->ia_size != i_size_read(inode)) {
282		error = inode_newsize_ok(inode, attr->ia_size);
283		if (error)
284			goto out_unlock;
285
286		truncate_setsize(inode, attr->ia_size);
287		hpfs_truncate(inode);
288	}
289
290	setattr_copy(inode, attr);
291
292	hpfs_write_inode(inode);
293
294 out_unlock:
295	hpfs_unlock(inode->i_sb);
296	return error;
297}
298
299void hpfs_write_if_changed(struct inode *inode)
300{
301	struct hpfs_inode_info *hpfs_inode = hpfs_i(inode);
302
303	if (hpfs_inode->i_dirty)
304		hpfs_write_inode(inode);
305}
306
307void hpfs_evict_inode(struct inode *inode)
308{
309	truncate_inode_pages_final(&inode->i_data);
310	clear_inode(inode);
311	if (!inode->i_nlink) {
312		hpfs_lock(inode->i_sb);
313		hpfs_remove_fnode(inode->i_sb, inode->i_ino);
314		hpfs_unlock(inode->i_sb);
315	}
316}
v3.15
  1/*
  2 *  linux/fs/hpfs/inode.c
  3 *
  4 *  Mikulas Patocka (mikulas@artax.karlin.mff.cuni.cz), 1998-1999
  5 *
  6 *  inode VFS functions
  7 */
  8
  9#include <linux/slab.h>
 10#include <linux/user_namespace.h>
 11#include "hpfs_fn.h"
 12
 13void hpfs_init_inode(struct inode *i)
 14{
 15	struct super_block *sb = i->i_sb;
 16	struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
 17
 18	i->i_uid = hpfs_sb(sb)->sb_uid;
 19	i->i_gid = hpfs_sb(sb)->sb_gid;
 20	i->i_mode = hpfs_sb(sb)->sb_mode;
 21	i->i_size = -1;
 22	i->i_blocks = -1;
 23	
 24	hpfs_inode->i_dno = 0;
 25	hpfs_inode->i_n_secs = 0;
 26	hpfs_inode->i_file_sec = 0;
 27	hpfs_inode->i_disk_sec = 0;
 28	hpfs_inode->i_dpos = 0;
 29	hpfs_inode->i_dsubdno = 0;
 30	hpfs_inode->i_ea_mode = 0;
 31	hpfs_inode->i_ea_uid = 0;
 32	hpfs_inode->i_ea_gid = 0;
 33	hpfs_inode->i_ea_size = 0;
 34
 35	hpfs_inode->i_rddir_off = NULL;
 36	hpfs_inode->i_dirty = 0;
 37
 38	i->i_ctime.tv_sec = i->i_ctime.tv_nsec = 0;
 39	i->i_mtime.tv_sec = i->i_mtime.tv_nsec = 0;
 40	i->i_atime.tv_sec = i->i_atime.tv_nsec = 0;
 41}
 42
 43void hpfs_read_inode(struct inode *i)
 44{
 45	struct buffer_head *bh;
 46	struct fnode *fnode;
 47	struct super_block *sb = i->i_sb;
 48	struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
 49	void *ea;
 50	int ea_size;
 51
 52	if (!(fnode = hpfs_map_fnode(sb, i->i_ino, &bh))) {
 53		/*i->i_mode |= S_IFREG;
 54		i->i_mode &= ~0111;
 55		i->i_op = &hpfs_file_iops;
 56		i->i_fop = &hpfs_file_ops;
 57		clear_nlink(i);*/
 58		make_bad_inode(i);
 59		return;
 60	}
 61	if (hpfs_sb(i->i_sb)->sb_eas) {
 62		if ((ea = hpfs_get_ea(i->i_sb, fnode, "UID", &ea_size))) {
 63			if (ea_size == 2) {
 64				i_uid_write(i, le16_to_cpu(*(__le16*)ea));
 65				hpfs_inode->i_ea_uid = 1;
 66			}
 67			kfree(ea);
 68		}
 69		if ((ea = hpfs_get_ea(i->i_sb, fnode, "GID", &ea_size))) {
 70			if (ea_size == 2) {
 71				i_gid_write(i, le16_to_cpu(*(__le16*)ea));
 72				hpfs_inode->i_ea_gid = 1;
 73			}
 74			kfree(ea);
 75		}
 76		if ((ea = hpfs_get_ea(i->i_sb, fnode, "SYMLINK", &ea_size))) {
 77			kfree(ea);
 78			i->i_mode = S_IFLNK | 0777;
 79			i->i_op = &page_symlink_inode_operations;
 
 80			i->i_data.a_ops = &hpfs_symlink_aops;
 81			set_nlink(i, 1);
 82			i->i_size = ea_size;
 83			i->i_blocks = 1;
 84			brelse(bh);
 85			return;
 86		}
 87		if ((ea = hpfs_get_ea(i->i_sb, fnode, "MODE", &ea_size))) {
 88			int rdev = 0;
 89			umode_t mode = hpfs_sb(sb)->sb_mode;
 90			if (ea_size == 2) {
 91				mode = le16_to_cpu(*(__le16*)ea);
 92				hpfs_inode->i_ea_mode = 1;
 93			}
 94			kfree(ea);
 95			i->i_mode = mode;
 96			if (S_ISBLK(mode) || S_ISCHR(mode)) {
 97				if ((ea = hpfs_get_ea(i->i_sb, fnode, "DEV", &ea_size))) {
 98					if (ea_size == 4)
 99						rdev = le32_to_cpu(*(__le32*)ea);
100					kfree(ea);
101				}
102			}
103			if (S_ISBLK(mode) || S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) {
104				brelse(bh);
105				set_nlink(i, 1);
106				i->i_size = 0;
107				i->i_blocks = 1;
108				init_special_inode(i, mode,
109					new_decode_dev(rdev));
110				return;
111			}
112		}
113	}
114	if (fnode_is_dir(fnode)) {
115		int n_dnodes, n_subdirs;
116		i->i_mode |= S_IFDIR;
117		i->i_op = &hpfs_dir_iops;
118		i->i_fop = &hpfs_dir_ops;
119		hpfs_inode->i_parent_dir = le32_to_cpu(fnode->up);
120		hpfs_inode->i_dno = le32_to_cpu(fnode->u.external[0].disk_secno);
121		if (hpfs_sb(sb)->sb_chk >= 2) {
122			struct buffer_head *bh0;
123			if (hpfs_map_fnode(sb, hpfs_inode->i_parent_dir, &bh0)) brelse(bh0);
124		}
125		n_dnodes = 0; n_subdirs = 0;
126		hpfs_count_dnodes(i->i_sb, hpfs_inode->i_dno, &n_dnodes, &n_subdirs, NULL);
127		i->i_blocks = 4 * n_dnodes;
128		i->i_size = 2048 * n_dnodes;
129		set_nlink(i, 2 + n_subdirs);
130	} else {
131		i->i_mode |= S_IFREG;
132		if (!hpfs_inode->i_ea_mode) i->i_mode &= ~0111;
133		i->i_op = &hpfs_file_iops;
134		i->i_fop = &hpfs_file_ops;
135		set_nlink(i, 1);
136		i->i_size = le32_to_cpu(fnode->file_size);
137		i->i_blocks = ((i->i_size + 511) >> 9) + 1;
138		i->i_data.a_ops = &hpfs_aops;
139		hpfs_i(i)->mmu_private = i->i_size;
140	}
141	brelse(bh);
142}
143
144static void hpfs_write_inode_ea(struct inode *i, struct fnode *fnode)
145{
146	struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
147	/*if (le32_to_cpu(fnode->acl_size_l) || le16_to_cpu(fnode->acl_size_s)) {
148		   Some unknown structures like ACL may be in fnode,
149		   we'd better not overwrite them
150		hpfs_error(i->i_sb, "fnode %08x has some unknown HPFS386 structures", i->i_ino);
151	} else*/ if (hpfs_sb(i->i_sb)->sb_eas >= 2) {
152		__le32 ea;
153		if (!uid_eq(i->i_uid, hpfs_sb(i->i_sb)->sb_uid) || hpfs_inode->i_ea_uid) {
154			ea = cpu_to_le32(i_uid_read(i));
155			hpfs_set_ea(i, fnode, "UID", (char*)&ea, 2);
156			hpfs_inode->i_ea_uid = 1;
157		}
158		if (!gid_eq(i->i_gid, hpfs_sb(i->i_sb)->sb_gid) || hpfs_inode->i_ea_gid) {
159			ea = cpu_to_le32(i_gid_read(i));
160			hpfs_set_ea(i, fnode, "GID", (char *)&ea, 2);
161			hpfs_inode->i_ea_gid = 1;
162		}
163		if (!S_ISLNK(i->i_mode))
164			if ((i->i_mode != ((hpfs_sb(i->i_sb)->sb_mode & ~(S_ISDIR(i->i_mode) ? 0 : 0111))
165			  | (S_ISDIR(i->i_mode) ? S_IFDIR : S_IFREG))
166			  && i->i_mode != ((hpfs_sb(i->i_sb)->sb_mode & ~(S_ISDIR(i->i_mode) ? 0222 : 0333))
167			  | (S_ISDIR(i->i_mode) ? S_IFDIR : S_IFREG))) || hpfs_inode->i_ea_mode) {
168				ea = cpu_to_le32(i->i_mode);
169				/* sick, but legal */
170				hpfs_set_ea(i, fnode, "MODE", (char *)&ea, 2);
171				hpfs_inode->i_ea_mode = 1;
172			}
173		if (S_ISBLK(i->i_mode) || S_ISCHR(i->i_mode)) {
174			ea = cpu_to_le32(new_encode_dev(i->i_rdev));
175			hpfs_set_ea(i, fnode, "DEV", (char *)&ea, 4);
176		}
177	}
178}
179
180void hpfs_write_inode(struct inode *i)
181{
182	struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
183	struct inode *parent;
184	if (i->i_ino == hpfs_sb(i->i_sb)->sb_root) return;
185	if (hpfs_inode->i_rddir_off && !atomic_read(&i->i_count)) {
186		if (*hpfs_inode->i_rddir_off) printk("HPFS: write_inode: some position still there\n");
 
187		kfree(hpfs_inode->i_rddir_off);
188		hpfs_inode->i_rddir_off = NULL;
189	}
190	if (!i->i_nlink) {
191		return;
192	}
193	parent = iget_locked(i->i_sb, hpfs_inode->i_parent_dir);
194	if (parent) {
195		hpfs_inode->i_dirty = 0;
196		if (parent->i_state & I_NEW) {
197			hpfs_init_inode(parent);
198			hpfs_read_inode(parent);
199			unlock_new_inode(parent);
200		}
201		hpfs_write_inode_nolock(i);
202		iput(parent);
203	}
204}
205
206void hpfs_write_inode_nolock(struct inode *i)
207{
208	struct hpfs_inode_info *hpfs_inode = hpfs_i(i);
209	struct buffer_head *bh;
210	struct fnode *fnode;
211	struct quad_buffer_head qbh;
212	struct hpfs_dirent *de;
213	if (i->i_ino == hpfs_sb(i->i_sb)->sb_root) return;
214	if (!(fnode = hpfs_map_fnode(i->i_sb, i->i_ino, &bh))) return;
215	if (i->i_ino != hpfs_sb(i->i_sb)->sb_root && i->i_nlink) {
216		if (!(de = map_fnode_dirent(i->i_sb, i->i_ino, fnode, &qbh))) {
217			brelse(bh);
218			return;
219		}
220	} else de = NULL;
221	if (S_ISREG(i->i_mode)) {
222		fnode->file_size = cpu_to_le32(i->i_size);
223		if (de) de->file_size = cpu_to_le32(i->i_size);
224	} else if (S_ISDIR(i->i_mode)) {
225		fnode->file_size = cpu_to_le32(0);
226		if (de) de->file_size = cpu_to_le32(0);
227	}
228	hpfs_write_inode_ea(i, fnode);
229	if (de) {
230		de->write_date = cpu_to_le32(gmt_to_local(i->i_sb, i->i_mtime.tv_sec));
231		de->read_date = cpu_to_le32(gmt_to_local(i->i_sb, i->i_atime.tv_sec));
232		de->creation_date = cpu_to_le32(gmt_to_local(i->i_sb, i->i_ctime.tv_sec));
233		de->read_only = !(i->i_mode & 0222);
234		de->ea_size = cpu_to_le32(hpfs_inode->i_ea_size);
235		hpfs_mark_4buffers_dirty(&qbh);
236		hpfs_brelse4(&qbh);
237	}
238	if (S_ISDIR(i->i_mode)) {
239		if ((de = map_dirent(i, hpfs_inode->i_dno, "\001\001", 2, NULL, &qbh))) {
240			de->write_date = cpu_to_le32(gmt_to_local(i->i_sb, i->i_mtime.tv_sec));
241			de->read_date = cpu_to_le32(gmt_to_local(i->i_sb, i->i_atime.tv_sec));
242			de->creation_date = cpu_to_le32(gmt_to_local(i->i_sb, i->i_ctime.tv_sec));
243			de->read_only = !(i->i_mode & 0222);
244			de->ea_size = cpu_to_le32(/*hpfs_inode->i_ea_size*/0);
245			de->file_size = cpu_to_le32(0);
246			hpfs_mark_4buffers_dirty(&qbh);
247			hpfs_brelse4(&qbh);
248		} else
249			hpfs_error(i->i_sb,
250				"directory %08lx doesn't have '.' entry",
251				(unsigned long)i->i_ino);
252	}
253	mark_buffer_dirty(bh);
254	brelse(bh);
255}
256
257int hpfs_setattr(struct dentry *dentry, struct iattr *attr)
258{
259	struct inode *inode = dentry->d_inode;
260	int error = -EINVAL;
261
262	hpfs_lock(inode->i_sb);
263	if (inode->i_ino == hpfs_sb(inode->i_sb)->sb_root)
264		goto out_unlock;
265	if ((attr->ia_valid & ATTR_UID) &&
266	    from_kuid(&init_user_ns, attr->ia_uid) >= 0x10000)
267		goto out_unlock;
268	if ((attr->ia_valid & ATTR_GID) &&
269	    from_kgid(&init_user_ns, attr->ia_gid) >= 0x10000)
270		goto out_unlock;
271	if ((attr->ia_valid & ATTR_SIZE) && attr->ia_size > inode->i_size)
272		goto out_unlock;
273
274	error = inode_change_ok(inode, attr);
275	if (error)
276		goto out_unlock;
277
278	if ((attr->ia_valid & ATTR_SIZE) &&
279	    attr->ia_size != i_size_read(inode)) {
280		error = inode_newsize_ok(inode, attr->ia_size);
281		if (error)
282			goto out_unlock;
283
284		truncate_setsize(inode, attr->ia_size);
285		hpfs_truncate(inode);
286	}
287
288	setattr_copy(inode, attr);
289
290	hpfs_write_inode(inode);
291
292 out_unlock:
293	hpfs_unlock(inode->i_sb);
294	return error;
295}
296
297void hpfs_write_if_changed(struct inode *inode)
298{
299	struct hpfs_inode_info *hpfs_inode = hpfs_i(inode);
300
301	if (hpfs_inode->i_dirty)
302		hpfs_write_inode(inode);
303}
304
305void hpfs_evict_inode(struct inode *inode)
306{
307	truncate_inode_pages_final(&inode->i_data);
308	clear_inode(inode);
309	if (!inode->i_nlink) {
310		hpfs_lock(inode->i_sb);
311		hpfs_remove_fnode(inode->i_sb, inode->i_ino);
312		hpfs_unlock(inode->i_sb);
313	}
314}