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