^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/affs/amigaffs.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * (c) 1996 Hans-Joachim Widmaier - Rewritten
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * (C) 1993 Ray Burr - Amiga FFS filesystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Please send bug reports to: hjw@zvw.de
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/math64.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/iversion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "affs.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Functions for accessing Amiga-FFS structures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) /* Insert a header block bh into the directory dir
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * caller must hold AFFS_DIR->i_hash_lock!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) affs_insert_hash(struct inode *dir, struct buffer_head *bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct super_block *sb = dir->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct buffer_head *dir_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) u32 ino, hash_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) ino = bh->b_blocknr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) offset = affs_hash_name(sb, AFFS_TAIL(sb, bh)->name + 1, AFFS_TAIL(sb, bh)->name[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) pr_debug("%s(dir=%lu, ino=%d)\n", __func__, dir->i_ino, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) dir_bh = affs_bread(sb, dir->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) if (!dir_bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) hash_ino = be32_to_cpu(AFFS_HEAD(dir_bh)->table[offset]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) while (hash_ino) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) affs_brelse(dir_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) dir_bh = affs_bread(sb, hash_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (!dir_bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) hash_ino = be32_to_cpu(AFFS_TAIL(sb, dir_bh)->hash_chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) AFFS_TAIL(sb, bh)->parent = cpu_to_be32(dir->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) AFFS_TAIL(sb, bh)->hash_chain = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) affs_fix_checksum(sb, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) if (dir->i_ino == dir_bh->b_blocknr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) AFFS_HEAD(dir_bh)->table[offset] = cpu_to_be32(ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) AFFS_TAIL(sb, dir_bh)->hash_chain = cpu_to_be32(ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) affs_adjust_checksum(dir_bh, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) mark_buffer_dirty_inode(dir_bh, dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) affs_brelse(dir_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) dir->i_mtime = dir->i_ctime = current_time(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) inode_inc_iversion(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) mark_inode_dirty(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /* Remove a header block from its directory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * caller must hold AFFS_DIR->i_hash_lock!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) affs_remove_hash(struct inode *dir, struct buffer_head *rem_bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct super_block *sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) u32 rem_ino, hash_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) __be32 ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) int offset, retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) sb = dir->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) rem_ino = rem_bh->b_blocknr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) offset = affs_hash_name(sb, AFFS_TAIL(sb, rem_bh)->name+1, AFFS_TAIL(sb, rem_bh)->name[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) pr_debug("%s(dir=%lu, ino=%d, hashval=%d)\n", __func__, dir->i_ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) rem_ino, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) bh = affs_bread(sb, dir->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) retval = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) hash_ino = be32_to_cpu(AFFS_HEAD(bh)->table[offset]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) while (hash_ino) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (hash_ino == rem_ino) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) ino = AFFS_TAIL(sb, rem_bh)->hash_chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) if (dir->i_ino == bh->b_blocknr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) AFFS_HEAD(bh)->table[offset] = ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) AFFS_TAIL(sb, bh)->hash_chain = ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) affs_adjust_checksum(bh, be32_to_cpu(ino) - hash_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) mark_buffer_dirty_inode(bh, dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) AFFS_TAIL(sb, rem_bh)->parent = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) affs_brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) bh = affs_bread(sb, hash_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) hash_ino = be32_to_cpu(AFFS_TAIL(sb, bh)->hash_chain);
^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) affs_brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) dir->i_mtime = dir->i_ctime = current_time(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) inode_inc_iversion(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) mark_inode_dirty(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) affs_fix_dcache(struct inode *inode, u32 entry_ino)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct dentry *dentry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (entry_ino == (u32)(long)dentry->d_fsdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) dentry->d_fsdata = (void *)inode->i_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) /* Remove header from link chain */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) affs_remove_link(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) struct inode *dir, *inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct super_block *sb = inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct buffer_head *bh, *link_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) u32 link_ino, ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) pr_debug("%s(key=%ld)\n", __func__, inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) retval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) bh = affs_bread(sb, inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) link_ino = (u32)(long)dentry->d_fsdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) if (inode->i_ino == link_ino) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /* we can't remove the head of the link, as its blocknr is still used as ino,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * so we remove the block of the first link instead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) link_ino = be32_to_cpu(AFFS_TAIL(sb, bh)->link_chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) link_bh = affs_bread(sb, link_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (!link_bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) dir = affs_iget(sb, be32_to_cpu(AFFS_TAIL(sb, link_bh)->parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (IS_ERR(dir)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) retval = PTR_ERR(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) affs_lock_dir(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * if there's a dentry for that block, make it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * refer to inode itself.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) affs_fix_dcache(inode, link_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) retval = affs_remove_hash(dir, link_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) affs_unlock_dir(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) mark_buffer_dirty_inode(link_bh, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) memcpy(AFFS_TAIL(sb, bh)->name, AFFS_TAIL(sb, link_bh)->name, 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) retval = affs_insert_hash(dir, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) affs_unlock_dir(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) mark_buffer_dirty_inode(bh, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) affs_unlock_dir(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) iput(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) link_bh = affs_bread(sb, link_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (!link_bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) while ((ino = be32_to_cpu(AFFS_TAIL(sb, bh)->link_chain)) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if (ino == link_ino) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) __be32 ino2 = AFFS_TAIL(sb, link_bh)->link_chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) AFFS_TAIL(sb, bh)->link_chain = ino2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) affs_adjust_checksum(bh, be32_to_cpu(ino2) - link_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) mark_buffer_dirty_inode(bh, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /* Fix the link count, if bh is a normal header block without links */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) switch (be32_to_cpu(AFFS_TAIL(sb, bh)->stype)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) case ST_LINKDIR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) case ST_LINKFILE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) if (!AFFS_TAIL(sb, bh)->link_chain)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) set_nlink(inode, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) affs_free_block(sb, link_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) affs_brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) bh = affs_bread(sb, ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) retval = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) affs_brelse(link_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) affs_brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) affs_empty_dir(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) struct super_block *sb = inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) int retval, size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) retval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) bh = affs_bread(sb, inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) retval = -ENOTEMPTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) for (size = AFFS_SB(sb)->s_hashsize - 1; size >= 0; size--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (AFFS_HEAD(bh)->table[size])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) goto not_empty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) not_empty:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) affs_brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) /* Remove a filesystem object. If the object to be removed has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) * links to it, one of the links must be changed to inherit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * the file or directory. As above, any inode will do.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) * The buffer will not be freed. If the header is a link, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) * block will be marked as free.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) * This function returns a negative error number in case of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * an error, else 0 if the inode is to be deleted or 1 if not.
^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) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) affs_remove_header(struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) struct super_block *sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) struct inode *inode, *dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) struct buffer_head *bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) dir = d_inode(dentry->d_parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) sb = dir->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) retval = -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) inode = d_inode(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) pr_debug("%s(key=%ld)\n", __func__, inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) retval = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) bh = affs_bread(sb, (u32)(long)dentry->d_fsdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) if (!bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) affs_lock_link(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) affs_lock_dir(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) switch (be32_to_cpu(AFFS_TAIL(sb, bh)->stype)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) case ST_USERDIR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) /* if we ever want to support links to dirs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) * i_hash_lock of the inode must only be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) * taken after some checks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) affs_lock_dir(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) retval = affs_empty_dir(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) affs_unlock_dir(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) goto done_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) retval = affs_remove_hash(dir, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) goto done_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) mark_buffer_dirty_inode(bh, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) affs_unlock_dir(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) if (inode->i_nlink > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) retval = affs_remove_link(dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) clear_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) affs_unlock_link(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) affs_brelse(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) done_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) affs_unlock_dir(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) affs_unlock_link(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) /* Checksum a block, do various consistency checks and optionally return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) the blocks type number. DATA points to the block. If their pointers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) are non-null, *PTYPE and *STYPE are set to the primary and secondary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) block types respectively, *HASHSIZE is set to the size of the hashtable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) (which lets us calculate the block size).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) Returns non-zero if the block is not consistent. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) u32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) affs_checksum_block(struct super_block *sb, struct buffer_head *bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) __be32 *ptr = (__be32 *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) u32 sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) int bsize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) sum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) for (bsize = sb->s_blocksize / sizeof(__be32); bsize > 0; bsize--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) sum += be32_to_cpu(*ptr++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) return sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) * Calculate the checksum of a disk block and store it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) * at the indicated position.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) affs_fix_checksum(struct super_block *sb, struct buffer_head *bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) int cnt = sb->s_blocksize / sizeof(__be32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) __be32 *ptr = (__be32 *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) u32 checksum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) __be32 *checksumptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) checksumptr = ptr + 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) *checksumptr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) for (checksum = 0; cnt > 0; ptr++, cnt--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) checksum += be32_to_cpu(*ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) *checksumptr = cpu_to_be32(-checksum);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) affs_secs_to_datestamp(time64_t secs, struct affs_date *ds)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) u32 days;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) u32 minute;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) s32 rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) secs -= sys_tz.tz_minuteswest * 60 + AFFS_EPOCH_DELTA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) if (secs < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) secs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) days = div_s64_rem(secs, 86400, &rem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) minute = rem / 60;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) rem -= minute * 60;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) ds->days = cpu_to_be32(days);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) ds->mins = cpu_to_be32(minute);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) ds->ticks = cpu_to_be32(rem * 50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) umode_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) affs_prot_to_mode(u32 prot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) umode_t mode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) if (!(prot & FIBF_NOWRITE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) mode |= 0200;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) if (!(prot & FIBF_NOREAD))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) mode |= 0400;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) if (!(prot & FIBF_NOEXECUTE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) mode |= 0100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) if (prot & FIBF_GRP_WRITE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) mode |= 0020;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) if (prot & FIBF_GRP_READ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) mode |= 0040;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (prot & FIBF_GRP_EXECUTE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) mode |= 0010;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) if (prot & FIBF_OTR_WRITE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) mode |= 0002;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) if (prot & FIBF_OTR_READ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) mode |= 0004;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (prot & FIBF_OTR_EXECUTE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) mode |= 0001;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) return mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) affs_mode_to_prot(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) u32 prot = AFFS_I(inode)->i_protect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) umode_t mode = inode->i_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) * First, clear all RWED bits for owner, group, other.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) * Then, recalculate them afresh.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) * We'll always clear the delete-inhibit bit for the owner, as that is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) * the classic single-user mode AmigaOS protection bit and we need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) * stay compatible with all scenarios.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) * Since multi-user AmigaOS is an extension, we'll only set the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) * delete-allow bit if any of the other bits in the same user class
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) * (group/other) are used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) prot &= ~(FIBF_NOEXECUTE | FIBF_NOREAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) | FIBF_NOWRITE | FIBF_NODELETE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) | FIBF_GRP_EXECUTE | FIBF_GRP_READ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) | FIBF_GRP_WRITE | FIBF_GRP_DELETE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) | FIBF_OTR_EXECUTE | FIBF_OTR_READ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) | FIBF_OTR_WRITE | FIBF_OTR_DELETE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) /* Classic single-user AmigaOS flags. These are inverted. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) if (!(mode & 0100))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) prot |= FIBF_NOEXECUTE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) if (!(mode & 0400))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) prot |= FIBF_NOREAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) if (!(mode & 0200))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) prot |= FIBF_NOWRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) /* Multi-user extended flags. Not inverted. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) if (mode & 0010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) prot |= FIBF_GRP_EXECUTE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) if (mode & 0040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) prot |= FIBF_GRP_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) if (mode & 0020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) prot |= FIBF_GRP_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) if (mode & 0070)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) prot |= FIBF_GRP_DELETE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) if (mode & 0001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) prot |= FIBF_OTR_EXECUTE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) if (mode & 0004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) prot |= FIBF_OTR_READ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) if (mode & 0002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) prot |= FIBF_OTR_WRITE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) if (mode & 0007)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) prot |= FIBF_OTR_DELETE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) AFFS_I(inode)->i_protect = prot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) affs_error(struct super_block *sb, const char *function, const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) struct va_format vaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) vaf.fmt = fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) vaf.va = &args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) pr_crit("error (device %s): %s(): %pV\n", sb->s_id, function, &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) if (!sb_rdonly(sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) pr_warn("Remounting filesystem read-only\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) sb->s_flags |= SB_RDONLY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) affs_warning(struct super_block *sb, const char *function, const char *fmt, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) struct va_format vaf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) va_list args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) va_start(args, fmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) vaf.fmt = fmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) vaf.va = &args;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) pr_warn("(device %s): %s(): %pV\n", sb->s_id, function, &vaf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) va_end(args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) affs_nofilenametruncate(const struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) return affs_test_opt(AFFS_SB(dentry->d_sb)->s_flags, SF_NO_TRUNCATE);
^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) /* Check if the name is valid for a affs object. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) affs_check_name(const unsigned char *name, int len, bool notruncate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) if (len > AFFSNAMEMAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) if (notruncate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) return -ENAMETOOLONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) len = AFFSNAMEMAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) for (i = 0; i < len; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) if (name[i] < ' ' || name[i] == ':'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) || (name[i] > 0x7e && name[i] < 0xa0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) /* This function copies name to bstr, with at most 30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) * characters length. The bstr will be prepended by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) * a length byte.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) * NOTE: The name will must be already checked by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) * affs_check_name()!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) affs_copy_name(unsigned char *bstr, struct dentry *dentry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) u32 len = min(dentry->d_name.len, AFFSNAMEMAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) *bstr++ = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) memcpy(bstr, dentry->d_name.name, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) }