Gao Xiang | 29b24f6 | 2019-07-31 23:57:31 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 2 | /* |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 3 | * Copyright (C) 2017-2018 HUAWEI, Inc. |
| 4 | * http://www.huawei.com/ |
| 5 | * Created by Gao Xiang <gaoxiang25@huawei.com> |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 6 | */ |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 7 | #include "xattr.h" |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 8 | |
Chao Yu | 13f06f4 | 2018-07-26 20:21:55 +0800 | [diff] [blame] | 9 | #include <trace/events/erofs.h> |
| 10 | |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 11 | /* no locking */ |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame] | 12 | static int erofs_read_inode(struct inode *inode, void *data) |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 13 | { |
Gao Xiang | a5876e2 | 2019-09-04 10:08:56 +0800 | [diff] [blame] | 14 | struct erofs_inode *vi = EROFS_I(inode); |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 15 | struct erofs_inode_compact *dic = data; |
| 16 | struct erofs_inode_extended *die; |
| 17 | |
| 18 | const unsigned int ifmt = le16_to_cpu(dic->i_format); |
| 19 | struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb); |
Gao Xiang | fe6d987 | 2019-05-28 11:19:43 +0800 | [diff] [blame] | 20 | erofs_blk_t nblks = 0; |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 21 | |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 22 | vi->datalayout = erofs_inode_datalayout(ifmt); |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 23 | |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 24 | if (vi->datalayout >= EROFS_INODE_DATALAYOUT_MAX) { |
Gao Xiang | 4f761fa | 2019-09-04 10:09:09 +0800 | [diff] [blame] | 25 | erofs_err(inode->i_sb, "unsupported datalayout %u of nid %llu", |
| 26 | vi->datalayout, vi->nid); |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 27 | DBG_BUGON(1); |
Gao Xiang | 382329a | 2019-08-14 18:37:04 +0800 | [diff] [blame] | 28 | return -EOPNOTSUPP; |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 29 | } |
| 30 | |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 31 | switch (erofs_inode_version(ifmt)) { |
| 32 | case EROFS_INODE_LAYOUT_EXTENDED: |
| 33 | die = data; |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 34 | |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 35 | vi->inode_isize = sizeof(struct erofs_inode_extended); |
| 36 | vi->xattr_isize = erofs_xattr_ibody_size(die->i_xattr_icount); |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 37 | |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 38 | inode->i_mode = le16_to_cpu(die->i_mode); |
| 39 | switch (inode->i_mode & S_IFMT) { |
| 40 | case S_IFREG: |
| 41 | case S_IFDIR: |
| 42 | case S_IFLNK: |
| 43 | vi->raw_blkaddr = le32_to_cpu(die->i_u.raw_blkaddr); |
| 44 | break; |
| 45 | case S_IFCHR: |
| 46 | case S_IFBLK: |
Chao Yu | d5beb31b | 2018-07-26 20:21:53 +0800 | [diff] [blame] | 47 | inode->i_rdev = |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 48 | new_decode_dev(le32_to_cpu(die->i_u.rdev)); |
| 49 | break; |
| 50 | case S_IFIFO: |
| 51 | case S_IFSOCK: |
Chao Yu | d5beb31b | 2018-07-26 20:21:53 +0800 | [diff] [blame] | 52 | inode->i_rdev = 0; |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 53 | break; |
| 54 | default: |
Gao Xiang | a6b9b1d | 2019-08-14 18:37:03 +0800 | [diff] [blame] | 55 | goto bogusimode; |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 56 | } |
| 57 | i_uid_write(inode, le32_to_cpu(die->i_uid)); |
| 58 | i_gid_write(inode, le32_to_cpu(die->i_gid)); |
| 59 | set_nlink(inode, le32_to_cpu(die->i_nlink)); |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 60 | |
| 61 | /* ns timestamp */ |
| 62 | inode->i_mtime.tv_sec = inode->i_ctime.tv_sec = |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 63 | le64_to_cpu(die->i_ctime); |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 64 | inode->i_mtime.tv_nsec = inode->i_ctime.tv_nsec = |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 65 | le32_to_cpu(die->i_ctime_nsec); |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 66 | |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 67 | inode->i_size = le64_to_cpu(die->i_size); |
Gao Xiang | fe6d987 | 2019-05-28 11:19:43 +0800 | [diff] [blame] | 68 | |
| 69 | /* total blocks for compressed files */ |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 70 | if (erofs_inode_is_data_compressed(vi->datalayout)) |
| 71 | nblks = le32_to_cpu(die->i_u.compressed_blocks); |
| 72 | break; |
| 73 | case EROFS_INODE_LAYOUT_COMPACT: |
| 74 | vi->inode_isize = sizeof(struct erofs_inode_compact); |
| 75 | vi->xattr_isize = erofs_xattr_ibody_size(dic->i_xattr_icount); |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 76 | |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 77 | inode->i_mode = le16_to_cpu(dic->i_mode); |
| 78 | switch (inode->i_mode & S_IFMT) { |
| 79 | case S_IFREG: |
| 80 | case S_IFDIR: |
| 81 | case S_IFLNK: |
| 82 | vi->raw_blkaddr = le32_to_cpu(dic->i_u.raw_blkaddr); |
| 83 | break; |
| 84 | case S_IFCHR: |
| 85 | case S_IFBLK: |
Chao Yu | d5beb31b | 2018-07-26 20:21:53 +0800 | [diff] [blame] | 86 | inode->i_rdev = |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 87 | new_decode_dev(le32_to_cpu(dic->i_u.rdev)); |
| 88 | break; |
| 89 | case S_IFIFO: |
| 90 | case S_IFSOCK: |
Chao Yu | d5beb31b | 2018-07-26 20:21:53 +0800 | [diff] [blame] | 91 | inode->i_rdev = 0; |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 92 | break; |
| 93 | default: |
Gao Xiang | a6b9b1d | 2019-08-14 18:37:03 +0800 | [diff] [blame] | 94 | goto bogusimode; |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 95 | } |
| 96 | i_uid_write(inode, le16_to_cpu(dic->i_uid)); |
| 97 | i_gid_write(inode, le16_to_cpu(dic->i_gid)); |
| 98 | set_nlink(inode, le16_to_cpu(dic->i_nlink)); |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 99 | |
| 100 | /* use build time to derive all file time */ |
| 101 | inode->i_mtime.tv_sec = inode->i_ctime.tv_sec = |
| 102 | sbi->build_time; |
| 103 | inode->i_mtime.tv_nsec = inode->i_ctime.tv_nsec = |
| 104 | sbi->build_time_nsec; |
| 105 | |
Gao Xiang | 8a76568 | 2019-09-04 10:08:54 +0800 | [diff] [blame] | 106 | inode->i_size = le32_to_cpu(dic->i_size); |
| 107 | if (erofs_inode_is_data_compressed(vi->datalayout)) |
| 108 | nblks = le32_to_cpu(dic->i_u.compressed_blocks); |
| 109 | break; |
| 110 | default: |
Gao Xiang | 4f761fa | 2019-09-04 10:09:09 +0800 | [diff] [blame] | 111 | erofs_err(inode->i_sb, |
| 112 | "unsupported on-disk inode version %u of nid %llu", |
| 113 | erofs_inode_version(ifmt), vi->nid); |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 114 | DBG_BUGON(1); |
Gao Xiang | 382329a | 2019-08-14 18:37:04 +0800 | [diff] [blame] | 115 | return -EOPNOTSUPP; |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 116 | } |
| 117 | |
Gao Xiang | fe6d987 | 2019-05-28 11:19:43 +0800 | [diff] [blame] | 118 | if (!nblks) |
| 119 | /* measure inode.i_blocks as generic filesystems */ |
| 120 | inode->i_blocks = roundup(inode->i_size, EROFS_BLKSIZ) >> 9; |
| 121 | else |
| 122 | inode->i_blocks = nblks << LOG_SECTORS_PER_BLOCK; |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 123 | return 0; |
Gao Xiang | a6b9b1d | 2019-08-14 18:37:03 +0800 | [diff] [blame] | 124 | |
| 125 | bogusimode: |
Gao Xiang | 4f761fa | 2019-09-04 10:09:09 +0800 | [diff] [blame] | 126 | erofs_err(inode->i_sb, "bogus i_mode (%o) @ nid %llu", |
| 127 | inode->i_mode, vi->nid); |
Gao Xiang | a6b9b1d | 2019-08-14 18:37:03 +0800 | [diff] [blame] | 128 | DBG_BUGON(1); |
| 129 | return -EFSCORRUPTED; |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 130 | } |
| 131 | |
Gao Xiang | a2c75c81 | 2019-09-04 10:08:59 +0800 | [diff] [blame] | 132 | static int erofs_fill_symlink(struct inode *inode, void *data, |
| 133 | unsigned int m_pofs) |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 134 | { |
Gao Xiang | a5876e2 | 2019-09-04 10:08:56 +0800 | [diff] [blame] | 135 | struct erofs_inode *vi = EROFS_I(inode); |
Gao Xiang | a2c75c81 | 2019-09-04 10:08:59 +0800 | [diff] [blame] | 136 | char *lnk; |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 137 | |
Gao Xiang | a2c75c81 | 2019-09-04 10:08:59 +0800 | [diff] [blame] | 138 | /* if it cannot be handled with fast symlink scheme */ |
| 139 | if (vi->datalayout != EROFS_INODE_FLAT_INLINE || |
| 140 | inode->i_size >= PAGE_SIZE) { |
| 141 | inode->i_op = &erofs_symlink_iops; |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 142 | return 0; |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 143 | } |
Gao Xiang | a2c75c81 | 2019-09-04 10:08:59 +0800 | [diff] [blame] | 144 | |
Gao Xiang | e2c71e7 | 2019-09-04 10:09:06 +0800 | [diff] [blame] | 145 | lnk = kmalloc(inode->i_size + 1, GFP_KERNEL); |
Gao Xiang | a2c75c81 | 2019-09-04 10:08:59 +0800 | [diff] [blame] | 146 | if (!lnk) |
| 147 | return -ENOMEM; |
| 148 | |
| 149 | m_pofs += vi->inode_isize + vi->xattr_isize; |
| 150 | /* inline symlink data shouldn't cross page boundary as well */ |
| 151 | if (m_pofs + inode->i_size > PAGE_SIZE) { |
| 152 | kfree(lnk); |
Gao Xiang | 4f761fa | 2019-09-04 10:09:09 +0800 | [diff] [blame] | 153 | erofs_err(inode->i_sb, |
| 154 | "inline data cross block boundary @ nid %llu", |
| 155 | vi->nid); |
Gao Xiang | a2c75c81 | 2019-09-04 10:08:59 +0800 | [diff] [blame] | 156 | DBG_BUGON(1); |
| 157 | return -EFSCORRUPTED; |
| 158 | } |
| 159 | |
| 160 | memcpy(lnk, data + m_pofs, inode->i_size); |
| 161 | lnk[inode->i_size] = '\0'; |
| 162 | |
| 163 | inode->i_link = lnk; |
| 164 | inode->i_op = &erofs_fast_symlink_iops; |
Yue Hu | 5545745 | 2019-06-27 17:46:15 +0800 | [diff] [blame] | 165 | return 0; |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 166 | } |
| 167 | |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame] | 168 | static int erofs_fill_inode(struct inode *inode, int isdir) |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 169 | { |
Gao Xiang | 4f761fa | 2019-09-04 10:09:09 +0800 | [diff] [blame] | 170 | struct super_block *sb = inode->i_sb; |
Gao Xiang | a5876e2 | 2019-09-04 10:08:56 +0800 | [diff] [blame] | 171 | struct erofs_inode *vi = EROFS_I(inode); |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 172 | struct page *page; |
| 173 | void *data; |
| 174 | int err; |
| 175 | erofs_blk_t blkaddr; |
Thomas Weißschuh | 7dd68b1 | 2018-09-10 21:41:14 +0200 | [diff] [blame] | 176 | unsigned int ofs; |
Pratik Shinde | a725535 | 2019-08-14 02:08:40 +0530 | [diff] [blame] | 177 | erofs_off_t inode_loc; |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 178 | |
Chao Yu | 13f06f4 | 2018-07-26 20:21:55 +0800 | [diff] [blame] | 179 | trace_erofs_fill_inode(inode, isdir); |
Gao Xiang | 4f761fa | 2019-09-04 10:09:09 +0800 | [diff] [blame] | 180 | inode_loc = iloc(EROFS_SB(sb), vi->nid); |
Pratik Shinde | a725535 | 2019-08-14 02:08:40 +0530 | [diff] [blame] | 181 | blkaddr = erofs_blknr(inode_loc); |
| 182 | ofs = erofs_blkoff(inode_loc); |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 183 | |
Gao Xiang | 4f761fa | 2019-09-04 10:09:09 +0800 | [diff] [blame] | 184 | erofs_dbg("%s, reading inode nid %llu at %u of blkaddr %u", |
| 185 | __func__, vi->nid, ofs, blkaddr); |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 186 | |
Gao Xiang | 4f761fa | 2019-09-04 10:09:09 +0800 | [diff] [blame] | 187 | page = erofs_get_meta_page(sb, blkaddr); |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 188 | |
| 189 | if (IS_ERR(page)) { |
Gao Xiang | 4f761fa | 2019-09-04 10:09:09 +0800 | [diff] [blame] | 190 | erofs_err(sb, "failed to get inode (nid: %llu) page, err %ld", |
| 191 | vi->nid, PTR_ERR(page)); |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 192 | return PTR_ERR(page); |
| 193 | } |
| 194 | |
Gao Xiang | 8b987bc | 2018-12-05 21:23:13 +0800 | [diff] [blame] | 195 | DBG_BUGON(!PageUptodate(page)); |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 196 | data = page_address(page); |
| 197 | |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame] | 198 | err = erofs_read_inode(inode, data + ofs); |
Gao Xiang | 84947eb6 | 2019-09-04 10:09:08 +0800 | [diff] [blame] | 199 | if (err) |
| 200 | goto out_unlock; |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 201 | |
Gao Xiang | 84947eb6 | 2019-09-04 10:09:08 +0800 | [diff] [blame] | 202 | /* setup the new inode */ |
| 203 | switch (inode->i_mode & S_IFMT) { |
| 204 | case S_IFREG: |
| 205 | inode->i_op = &erofs_generic_iops; |
| 206 | inode->i_fop = &generic_ro_fops; |
| 207 | break; |
| 208 | case S_IFDIR: |
| 209 | inode->i_op = &erofs_dir_iops; |
| 210 | inode->i_fop = &erofs_dir_fops; |
| 211 | break; |
| 212 | case S_IFLNK: |
| 213 | err = erofs_fill_symlink(inode, data, ofs); |
| 214 | if (err) |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 215 | goto out_unlock; |
Gao Xiang | 84947eb6 | 2019-09-04 10:09:08 +0800 | [diff] [blame] | 216 | inode_nohighmem(inode); |
| 217 | break; |
| 218 | case S_IFCHR: |
| 219 | case S_IFBLK: |
| 220 | case S_IFIFO: |
| 221 | case S_IFSOCK: |
| 222 | inode->i_op = &erofs_generic_iops; |
| 223 | init_special_inode(inode, inode->i_mode, inode->i_rdev); |
| 224 | goto out_unlock; |
| 225 | default: |
| 226 | err = -EFSCORRUPTED; |
| 227 | goto out_unlock; |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 228 | } |
| 229 | |
Gao Xiang | 84947eb6 | 2019-09-04 10:09:08 +0800 | [diff] [blame] | 230 | if (erofs_inode_is_data_compressed(vi->datalayout)) { |
| 231 | err = z_erofs_fill_inode(inode); |
| 232 | goto out_unlock; |
| 233 | } |
| 234 | inode->i_mapping->a_ops = &erofs_raw_access_aops; |
| 235 | |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 236 | out_unlock: |
| 237 | unlock_page(page); |
| 238 | put_page(page); |
| 239 | return err; |
| 240 | } |
| 241 | |
Gao Xiang | 2abd781 | 2018-10-09 22:07:13 +0800 | [diff] [blame] | 242 | /* |
| 243 | * erofs nid is 64bits, but i_ino is 'unsigned long', therefore |
| 244 | * we should do more for 32-bit platform to find the right inode. |
| 245 | */ |
Gao Xiang | 2abd781 | 2018-10-09 22:07:13 +0800 | [diff] [blame] | 246 | static int erofs_ilookup_test_actor(struct inode *inode, void *opaque) |
| 247 | { |
| 248 | const erofs_nid_t nid = *(erofs_nid_t *)opaque; |
| 249 | |
Gao Xiang | a5876e2 | 2019-09-04 10:08:56 +0800 | [diff] [blame] | 250 | return EROFS_I(inode)->nid == nid; |
Gao Xiang | 2abd781 | 2018-10-09 22:07:13 +0800 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | static int erofs_iget_set_actor(struct inode *inode, void *opaque) |
| 254 | { |
| 255 | const erofs_nid_t nid = *(erofs_nid_t *)opaque; |
| 256 | |
| 257 | inode->i_ino = erofs_inode_hash(nid); |
| 258 | return 0; |
| 259 | } |
Gao Xiang | 2abd781 | 2018-10-09 22:07:13 +0800 | [diff] [blame] | 260 | |
| 261 | static inline struct inode *erofs_iget_locked(struct super_block *sb, |
| 262 | erofs_nid_t nid) |
| 263 | { |
| 264 | const unsigned long hashval = erofs_inode_hash(nid); |
| 265 | |
Gao Xiang | 2abd781 | 2018-10-09 22:07:13 +0800 | [diff] [blame] | 266 | return iget5_locked(sb, hashval, erofs_ilookup_test_actor, |
| 267 | erofs_iget_set_actor, &nid); |
Gao Xiang | 2abd781 | 2018-10-09 22:07:13 +0800 | [diff] [blame] | 268 | } |
| 269 | |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 270 | struct inode *erofs_iget(struct super_block *sb, |
Julian Merida | 447a362 | 2019-03-18 20:58:41 -0300 | [diff] [blame] | 271 | erofs_nid_t nid, |
| 272 | bool isdir) |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 273 | { |
Gao Xiang | 2abd781 | 2018-10-09 22:07:13 +0800 | [diff] [blame] | 274 | struct inode *inode = erofs_iget_locked(sb, nid); |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 275 | |
Gao Xiang | 8d8a09b | 2019-08-30 00:38:27 +0800 | [diff] [blame] | 276 | if (!inode) |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 277 | return ERR_PTR(-ENOMEM); |
| 278 | |
| 279 | if (inode->i_state & I_NEW) { |
| 280 | int err; |
Gao Xiang | a5876e2 | 2019-09-04 10:08:56 +0800 | [diff] [blame] | 281 | struct erofs_inode *vi = EROFS_I(inode); |
Julio Bianco | 8af3647 | 2019-03-09 14:08:53 -0300 | [diff] [blame] | 282 | |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 283 | vi->nid = nid; |
| 284 | |
Gao Xiang | 99634bf | 2019-09-04 10:09:05 +0800 | [diff] [blame] | 285 | err = erofs_fill_inode(inode, isdir); |
Gao Xiang | 8d8a09b | 2019-08-30 00:38:27 +0800 | [diff] [blame] | 286 | if (!err) |
Gao Xiang | 431339b | 2018-07-26 20:21:48 +0800 | [diff] [blame] | 287 | unlock_new_inode(inode); |
| 288 | else { |
| 289 | iget_failed(inode); |
| 290 | inode = ERR_PTR(err); |
| 291 | } |
| 292 | } |
| 293 | return inode; |
| 294 | } |
| 295 | |
Gao Xiang | 89f27ed | 2019-05-28 11:19:42 +0800 | [diff] [blame] | 296 | int erofs_getattr(const struct path *path, struct kstat *stat, |
| 297 | u32 request_mask, unsigned int query_flags) |
| 298 | { |
| 299 | struct inode *const inode = d_inode(path->dentry); |
Gao Xiang | 89f27ed | 2019-05-28 11:19:42 +0800 | [diff] [blame] | 300 | |
Gao Xiang | a5876e2 | 2019-09-04 10:08:56 +0800 | [diff] [blame] | 301 | if (erofs_inode_is_data_compressed(EROFS_I(inode)->datalayout)) |
Gao Xiang | 89f27ed | 2019-05-28 11:19:42 +0800 | [diff] [blame] | 302 | stat->attributes |= STATX_ATTR_COMPRESSED; |
| 303 | |
| 304 | stat->attributes |= STATX_ATTR_IMMUTABLE; |
| 305 | stat->attributes_mask |= (STATX_ATTR_COMPRESSED | |
| 306 | STATX_ATTR_IMMUTABLE); |
| 307 | |
| 308 | generic_fillattr(inode, stat); |
| 309 | return 0; |
| 310 | } |
| 311 | |
Gao Xiang | 6093982 | 2019-01-14 19:40:24 +0800 | [diff] [blame] | 312 | const struct inode_operations erofs_generic_iops = { |
Gao Xiang | 89f27ed | 2019-05-28 11:19:42 +0800 | [diff] [blame] | 313 | .getattr = erofs_getattr, |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 314 | #ifdef CONFIG_EROFS_FS_XATTR |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 315 | .listxattr = erofs_listxattr, |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 316 | #endif |
Gao Xiang | 516c115c | 2019-01-29 16:35:20 +0800 | [diff] [blame] | 317 | .get_acl = erofs_get_acl, |
Gao Xiang | 6093982 | 2019-01-14 19:40:24 +0800 | [diff] [blame] | 318 | }; |
| 319 | |
| 320 | const struct inode_operations erofs_symlink_iops = { |
| 321 | .get_link = page_get_link, |
Gao Xiang | 89f27ed | 2019-05-28 11:19:42 +0800 | [diff] [blame] | 322 | .getattr = erofs_getattr, |
Gao Xiang | 6093982 | 2019-01-14 19:40:24 +0800 | [diff] [blame] | 323 | #ifdef CONFIG_EROFS_FS_XATTR |
| 324 | .listxattr = erofs_listxattr, |
| 325 | #endif |
Gao Xiang | 516c115c | 2019-01-29 16:35:20 +0800 | [diff] [blame] | 326 | .get_acl = erofs_get_acl, |
Gao Xiang | 6093982 | 2019-01-14 19:40:24 +0800 | [diff] [blame] | 327 | }; |
| 328 | |
| 329 | const struct inode_operations erofs_fast_symlink_iops = { |
| 330 | .get_link = simple_get_link, |
Gao Xiang | 89f27ed | 2019-05-28 11:19:42 +0800 | [diff] [blame] | 331 | .getattr = erofs_getattr, |
Gao Xiang | 6093982 | 2019-01-14 19:40:24 +0800 | [diff] [blame] | 332 | #ifdef CONFIG_EROFS_FS_XATTR |
| 333 | .listxattr = erofs_listxattr, |
| 334 | #endif |
Gao Xiang | 516c115c | 2019-01-29 16:35:20 +0800 | [diff] [blame] | 335 | .get_acl = erofs_get_acl, |
Gao Xiang | 6093982 | 2019-01-14 19:40:24 +0800 | [diff] [blame] | 336 | }; |
Gao Xiang | b17500a | 2018-07-26 20:21:52 +0800 | [diff] [blame] | 337 | |