^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) International Business Machines Corp., 2000-2004
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/quotaops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include "jfs_incore.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include "jfs_inode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "jfs_filsys.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "jfs_imap.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "jfs_dinode.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "jfs_debug.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) void jfs_set_inode_flags(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) unsigned int flags = JFS_IP(inode)->mode2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) unsigned int new_fl = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) if (flags & JFS_IMMUTABLE_FL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) new_fl |= S_IMMUTABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) if (flags & JFS_APPEND_FL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) new_fl |= S_APPEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) if (flags & JFS_NOATIME_FL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) new_fl |= S_NOATIME;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) if (flags & JFS_DIRSYNC_FL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) new_fl |= S_DIRSYNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) if (flags & JFS_SYNC_FL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) new_fl |= S_SYNC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) inode_set_flags(inode, new_fl, S_IMMUTABLE | S_APPEND | S_NOATIME |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) S_DIRSYNC | S_SYNC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * NAME: ialloc()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * FUNCTION: Allocate a new inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct inode *ialloc(struct inode *parent, umode_t mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct super_block *sb = parent->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct jfs_inode_info *jfs_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) inode = new_inode(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) if (!inode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) jfs_warn("ialloc: new_inode returned NULL!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) jfs_inode = JFS_IP(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) rc = diAlloc(parent, S_ISDIR(mode), inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) jfs_warn("ialloc: diAlloc returned %d!", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) goto fail_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) if (insert_inode_locked(inode) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) rc = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) goto fail_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) inode_init_owner(inode, parent, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * New inodes need to save sane values on disk when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * uid & gid mount options are used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) jfs_inode->saved_uid = inode->i_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) jfs_inode->saved_gid = inode->i_gid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * Allocate inode to quota.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) rc = dquot_initialize(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) goto fail_drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) rc = dquot_alloc_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) goto fail_drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /* inherit flags from parent */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) jfs_inode->mode2 = JFS_IP(parent)->mode2 & JFS_FL_INHERIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if (S_ISDIR(mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) jfs_inode->mode2 |= IDIRECTORY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) jfs_inode->mode2 &= ~JFS_DIRSYNC_FL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) jfs_inode->mode2 |= INLINEEA | ISPARSE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (S_ISLNK(mode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) jfs_inode->mode2 &= ~(JFS_IMMUTABLE_FL|JFS_APPEND_FL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) jfs_inode->mode2 |= inode->i_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) inode->i_blocks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) inode->i_mtime = inode->i_atime = inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) jfs_inode->otime = inode->i_ctime.tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) inode->i_generation = JFS_SBI(sb)->gengen++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) jfs_inode->cflag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /* Zero remaining fields */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) memset(&jfs_inode->acl, 0, sizeof(dxd_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) memset(&jfs_inode->ea, 0, sizeof(dxd_t));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) jfs_inode->next_index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) jfs_inode->acltype = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) jfs_inode->btorder = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) jfs_inode->btindex = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) jfs_inode->bxflag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) jfs_inode->blid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) jfs_inode->atlhead = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) jfs_inode->atltail = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) jfs_inode->xtlid = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) jfs_set_inode_flags(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) jfs_info("ialloc returns inode = 0x%p", inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) fail_drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) dquot_drop(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) inode->i_flags |= S_NOQUOTA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) clear_nlink(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) discard_new_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) return ERR_PTR(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) fail_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) iput(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return ERR_PTR(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }