xref: /openbmc/linux/fs/erofs/inode.c (revision d3c4bdcc)
147e4937aSGao Xiang // SPDX-License-Identifier: GPL-2.0-only
247e4937aSGao Xiang /*
347e4937aSGao Xiang  * Copyright (C) 2017-2018 HUAWEI, Inc.
4592e7cd0SAlexander A. Klimov  *             https://www.huawei.com/
5c5aa903aSGao Xiang  * Copyright (C) 2021, Alibaba Cloud
647e4937aSGao Xiang  */
747e4937aSGao Xiang #include "xattr.h"
847e4937aSGao Xiang 
947e4937aSGao Xiang #include <trace/events/erofs.h>
1047e4937aSGao Xiang 
11c521e3adSGao Xiang static void *erofs_read_inode(struct erofs_buf *buf,
12c521e3adSGao Xiang 			      struct inode *inode, unsigned int *ofs)
1347e4937aSGao Xiang {
140dcd3c94SGao Xiang 	struct super_block *sb = inode->i_sb;
150dcd3c94SGao Xiang 	struct erofs_sb_info *sbi = EROFS_SB(sb);
16a5876e24SGao Xiang 	struct erofs_inode *vi = EROFS_I(inode);
17b780d3fcSGao Xiang 	const erofs_off_t inode_loc = erofs_iloc(inode);
188a765682SGao Xiang 
190dcd3c94SGao Xiang 	erofs_blk_t blkaddr, nblks = 0;
20c521e3adSGao Xiang 	void *kaddr;
210dcd3c94SGao Xiang 	struct erofs_inode_compact *dic;
220dcd3c94SGao Xiang 	struct erofs_inode_extended *die, *copied = NULL;
230dcd3c94SGao Xiang 	unsigned int ifmt;
240dcd3c94SGao Xiang 	int err;
250dcd3c94SGao Xiang 
263acea5fcSJingbo Xu 	blkaddr = erofs_blknr(sb, inode_loc);
273acea5fcSJingbo Xu 	*ofs = erofs_blkoff(sb, inode_loc);
280dcd3c94SGao Xiang 
290dcd3c94SGao Xiang 	erofs_dbg("%s, reading inode nid %llu at %u of blkaddr %u",
300dcd3c94SGao Xiang 		  __func__, vi->nid, *ofs, blkaddr);
310dcd3c94SGao Xiang 
32c521e3adSGao Xiang 	kaddr = erofs_read_metabuf(buf, sb, blkaddr, EROFS_KMAP);
33c521e3adSGao Xiang 	if (IS_ERR(kaddr)) {
340dcd3c94SGao Xiang 		erofs_err(sb, "failed to get inode (nid: %llu) page, err %ld",
35c521e3adSGao Xiang 			  vi->nid, PTR_ERR(kaddr));
36c521e3adSGao Xiang 		return kaddr;
370dcd3c94SGao Xiang 	}
380dcd3c94SGao Xiang 
39c521e3adSGao Xiang 	dic = kaddr + *ofs;
400dcd3c94SGao Xiang 	ifmt = le16_to_cpu(dic->i_format);
4147e4937aSGao Xiang 
4224a806d8SGao Xiang 	if (ifmt & ~EROFS_I_ALL) {
4324a806d8SGao Xiang 		erofs_err(inode->i_sb, "unsupported i_format %u of nid %llu",
4424a806d8SGao Xiang 			  ifmt, vi->nid);
4524a806d8SGao Xiang 		err = -EOPNOTSUPP;
4624a806d8SGao Xiang 		goto err_out;
4724a806d8SGao Xiang 	}
4824a806d8SGao Xiang 
498a765682SGao Xiang 	vi->datalayout = erofs_inode_datalayout(ifmt);
508a765682SGao Xiang 	if (vi->datalayout >= EROFS_INODE_DATALAYOUT_MAX) {
514f761fa2SGao Xiang 		erofs_err(inode->i_sb, "unsupported datalayout %u of nid %llu",
528a765682SGao Xiang 			  vi->datalayout, vi->nid);
530dcd3c94SGao Xiang 		err = -EOPNOTSUPP;
540dcd3c94SGao Xiang 		goto err_out;
5547e4937aSGao Xiang 	}
5647e4937aSGao Xiang 
578a765682SGao Xiang 	switch (erofs_inode_version(ifmt)) {
588a765682SGao Xiang 	case EROFS_INODE_LAYOUT_EXTENDED:
598a765682SGao Xiang 		vi->inode_isize = sizeof(struct erofs_inode_extended);
60c521e3adSGao Xiang 		/* check if the extended inode acrosses block boundary */
613acea5fcSJingbo Xu 		if (*ofs + vi->inode_isize <= sb->s_blocksize) {
620dcd3c94SGao Xiang 			*ofs += vi->inode_isize;
630dcd3c94SGao Xiang 			die = (struct erofs_inode_extended *)dic;
640dcd3c94SGao Xiang 		} else {
653acea5fcSJingbo Xu 			const unsigned int gotten = sb->s_blocksize - *ofs;
660dcd3c94SGao Xiang 
670dcd3c94SGao Xiang 			copied = kmalloc(vi->inode_isize, GFP_NOFS);
680dcd3c94SGao Xiang 			if (!copied) {
690dcd3c94SGao Xiang 				err = -ENOMEM;
700dcd3c94SGao Xiang 				goto err_out;
710dcd3c94SGao Xiang 			}
720dcd3c94SGao Xiang 			memcpy(copied, dic, gotten);
73c521e3adSGao Xiang 			kaddr = erofs_read_metabuf(buf, sb, blkaddr + 1,
74c521e3adSGao Xiang 						   EROFS_KMAP);
75c521e3adSGao Xiang 			if (IS_ERR(kaddr)) {
76c521e3adSGao Xiang 				erofs_err(sb, "failed to get inode payload block (nid: %llu), err %ld",
77c521e3adSGao Xiang 					  vi->nid, PTR_ERR(kaddr));
780dcd3c94SGao Xiang 				kfree(copied);
79c521e3adSGao Xiang 				return kaddr;
800dcd3c94SGao Xiang 			}
810dcd3c94SGao Xiang 			*ofs = vi->inode_isize - gotten;
82c521e3adSGao Xiang 			memcpy((u8 *)copied + gotten, kaddr, *ofs);
830dcd3c94SGao Xiang 			die = copied;
840dcd3c94SGao Xiang 		}
858a765682SGao Xiang 		vi->xattr_isize = erofs_xattr_ibody_size(die->i_xattr_icount);
8647e4937aSGao Xiang 
878a765682SGao Xiang 		inode->i_mode = le16_to_cpu(die->i_mode);
888a765682SGao Xiang 		switch (inode->i_mode & S_IFMT) {
898a765682SGao Xiang 		case S_IFREG:
908a765682SGao Xiang 		case S_IFDIR:
918a765682SGao Xiang 		case S_IFLNK:
928a765682SGao Xiang 			vi->raw_blkaddr = le32_to_cpu(die->i_u.raw_blkaddr);
938a765682SGao Xiang 			break;
948a765682SGao Xiang 		case S_IFCHR:
958a765682SGao Xiang 		case S_IFBLK:
9647e4937aSGao Xiang 			inode->i_rdev =
978a765682SGao Xiang 				new_decode_dev(le32_to_cpu(die->i_u.rdev));
988a765682SGao Xiang 			break;
998a765682SGao Xiang 		case S_IFIFO:
1008a765682SGao Xiang 		case S_IFSOCK:
10147e4937aSGao Xiang 			inode->i_rdev = 0;
1028a765682SGao Xiang 			break;
1038a765682SGao Xiang 		default:
10447e4937aSGao Xiang 			goto bogusimode;
1058a765682SGao Xiang 		}
1068a765682SGao Xiang 		i_uid_write(inode, le32_to_cpu(die->i_uid));
1078a765682SGao Xiang 		i_gid_write(inode, le32_to_cpu(die->i_gid));
1088a765682SGao Xiang 		set_nlink(inode, le32_to_cpu(die->i_nlink));
10947e4937aSGao Xiang 
110d3938ee2SGao Xiang 		/* extended inode has its own timestamp */
111a1108dcdSDavid Anderson 		inode->i_ctime.tv_sec = le64_to_cpu(die->i_mtime);
112a1108dcdSDavid Anderson 		inode->i_ctime.tv_nsec = le32_to_cpu(die->i_mtime_nsec);
11347e4937aSGao Xiang 
1148a765682SGao Xiang 		inode->i_size = le64_to_cpu(die->i_size);
11547e4937aSGao Xiang 
11647e4937aSGao Xiang 		/* total blocks for compressed files */
1178a765682SGao Xiang 		if (erofs_inode_is_data_compressed(vi->datalayout))
1188a765682SGao Xiang 			nblks = le32_to_cpu(die->i_u.compressed_blocks);
119c5aa903aSGao Xiang 		else if (vi->datalayout == EROFS_INODE_CHUNK_BASED)
120c5aa903aSGao Xiang 			/* fill chunked inode summary info */
121c5aa903aSGao Xiang 			vi->chunkformat = le16_to_cpu(die->i_u.c.format);
1220dcd3c94SGao Xiang 		kfree(copied);
1231266b4a7SGao Xiang 		copied = NULL;
1248a765682SGao Xiang 		break;
1258a765682SGao Xiang 	case EROFS_INODE_LAYOUT_COMPACT:
1268a765682SGao Xiang 		vi->inode_isize = sizeof(struct erofs_inode_compact);
1270dcd3c94SGao Xiang 		*ofs += vi->inode_isize;
1288a765682SGao Xiang 		vi->xattr_isize = erofs_xattr_ibody_size(dic->i_xattr_icount);
12947e4937aSGao Xiang 
1308a765682SGao Xiang 		inode->i_mode = le16_to_cpu(dic->i_mode);
1318a765682SGao Xiang 		switch (inode->i_mode & S_IFMT) {
1328a765682SGao Xiang 		case S_IFREG:
1338a765682SGao Xiang 		case S_IFDIR:
1348a765682SGao Xiang 		case S_IFLNK:
1358a765682SGao Xiang 			vi->raw_blkaddr = le32_to_cpu(dic->i_u.raw_blkaddr);
1368a765682SGao Xiang 			break;
1378a765682SGao Xiang 		case S_IFCHR:
1388a765682SGao Xiang 		case S_IFBLK:
13947e4937aSGao Xiang 			inode->i_rdev =
1408a765682SGao Xiang 				new_decode_dev(le32_to_cpu(dic->i_u.rdev));
1418a765682SGao Xiang 			break;
1428a765682SGao Xiang 		case S_IFIFO:
1438a765682SGao Xiang 		case S_IFSOCK:
14447e4937aSGao Xiang 			inode->i_rdev = 0;
1458a765682SGao Xiang 			break;
1468a765682SGao Xiang 		default:
14747e4937aSGao Xiang 			goto bogusimode;
1488a765682SGao Xiang 		}
1498a765682SGao Xiang 		i_uid_write(inode, le16_to_cpu(dic->i_uid));
1508a765682SGao Xiang 		i_gid_write(inode, le16_to_cpu(dic->i_gid));
1518a765682SGao Xiang 		set_nlink(inode, le16_to_cpu(dic->i_nlink));
15247e4937aSGao Xiang 
153d3938ee2SGao Xiang 		/* use build time for compact inodes */
154d3938ee2SGao Xiang 		inode->i_ctime.tv_sec = sbi->build_time;
155d3938ee2SGao Xiang 		inode->i_ctime.tv_nsec = sbi->build_time_nsec;
15647e4937aSGao Xiang 
1578a765682SGao Xiang 		inode->i_size = le32_to_cpu(dic->i_size);
1588a765682SGao Xiang 		if (erofs_inode_is_data_compressed(vi->datalayout))
1598a765682SGao Xiang 			nblks = le32_to_cpu(dic->i_u.compressed_blocks);
160c5aa903aSGao Xiang 		else if (vi->datalayout == EROFS_INODE_CHUNK_BASED)
161c5aa903aSGao Xiang 			vi->chunkformat = le16_to_cpu(dic->i_u.c.format);
1628a765682SGao Xiang 		break;
1638a765682SGao Xiang 	default:
1644f761fa2SGao Xiang 		erofs_err(inode->i_sb,
1654f761fa2SGao Xiang 			  "unsupported on-disk inode version %u of nid %llu",
1668a765682SGao Xiang 			  erofs_inode_version(ifmt), vi->nid);
1670dcd3c94SGao Xiang 		err = -EOPNOTSUPP;
1680dcd3c94SGao Xiang 		goto err_out;
16947e4937aSGao Xiang 	}
17047e4937aSGao Xiang 
171c5aa903aSGao Xiang 	if (vi->datalayout == EROFS_INODE_CHUNK_BASED) {
172d705117dSGao Xiang 		if (vi->chunkformat & ~EROFS_CHUNK_FORMAT_ALL) {
173c5aa903aSGao Xiang 			erofs_err(inode->i_sb,
174c5aa903aSGao Xiang 				  "unsupported chunk format %x of nid %llu",
175c5aa903aSGao Xiang 				  vi->chunkformat, vi->nid);
176c5aa903aSGao Xiang 			err = -EOPNOTSUPP;
177c5aa903aSGao Xiang 			goto err_out;
178c5aa903aSGao Xiang 		}
1793acea5fcSJingbo Xu 		vi->chunkbits = sb->s_blocksize_bits +
180c5aa903aSGao Xiang 			(vi->chunkformat & EROFS_CHUNK_FORMAT_BLKBITS_MASK);
181c5aa903aSGao Xiang 	}
182d3938ee2SGao Xiang 	inode->i_mtime.tv_sec = inode->i_ctime.tv_sec;
183d3938ee2SGao Xiang 	inode->i_atime.tv_sec = inode->i_ctime.tv_sec;
184d3938ee2SGao Xiang 	inode->i_mtime.tv_nsec = inode->i_ctime.tv_nsec;
185d3938ee2SGao Xiang 	inode->i_atime.tv_nsec = inode->i_ctime.tv_nsec;
186d3938ee2SGao Xiang 
18706252e9cSGao Xiang 	inode->i_flags &= ~S_DAX;
188e6242465SGao Xiang 	if (test_opt(&sbi->opt, DAX_ALWAYS) && S_ISREG(inode->i_mode) &&
18906252e9cSGao Xiang 	    vi->datalayout == EROFS_INODE_FLAT_PLAIN)
19006252e9cSGao Xiang 		inode->i_flags |= S_DAX;
1913acea5fcSJingbo Xu 
19247e4937aSGao Xiang 	if (!nblks)
19347e4937aSGao Xiang 		/* measure inode.i_blocks as generic filesystems */
1943acea5fcSJingbo Xu 		inode->i_blocks = round_up(inode->i_size, sb->s_blocksize) >> 9;
19547e4937aSGao Xiang 	else
1963acea5fcSJingbo Xu 		inode->i_blocks = nblks << (sb->s_blocksize_bits - 9);
197c521e3adSGao Xiang 	return kaddr;
19847e4937aSGao Xiang 
19947e4937aSGao Xiang bogusimode:
2004f761fa2SGao Xiang 	erofs_err(inode->i_sb, "bogus i_mode (%o) @ nid %llu",
2014f761fa2SGao Xiang 		  inode->i_mode, vi->nid);
2020dcd3c94SGao Xiang 	err = -EFSCORRUPTED;
2030dcd3c94SGao Xiang err_out:
20447e4937aSGao Xiang 	DBG_BUGON(1);
2050dcd3c94SGao Xiang 	kfree(copied);
206c521e3adSGao Xiang 	erofs_put_metabuf(buf);
2070dcd3c94SGao Xiang 	return ERR_PTR(err);
20847e4937aSGao Xiang }
20947e4937aSGao Xiang 
210c521e3adSGao Xiang static int erofs_fill_symlink(struct inode *inode, void *kaddr,
21147e4937aSGao Xiang 			      unsigned int m_pofs)
21247e4937aSGao Xiang {
213a5876e24SGao Xiang 	struct erofs_inode *vi = EROFS_I(inode);
2143acea5fcSJingbo Xu 	unsigned int bsz = i_blocksize(inode);
215a2c75c81SGao Xiang 	char *lnk;
21647e4937aSGao Xiang 
217a2c75c81SGao Xiang 	/* if it cannot be handled with fast symlink scheme */
218a2c75c81SGao Xiang 	if (vi->datalayout != EROFS_INODE_FLAT_INLINE ||
2193acea5fcSJingbo Xu 	    inode->i_size >= bsz || inode->i_size < 0) {
220a2c75c81SGao Xiang 		inode->i_op = &erofs_symlink_iops;
22147e4937aSGao Xiang 		return 0;
222a2c75c81SGao Xiang 	}
22347e4937aSGao Xiang 
224e2c71e74SGao Xiang 	lnk = kmalloc(inode->i_size + 1, GFP_KERNEL);
2258d8a09b0SGao Xiang 	if (!lnk)
22647e4937aSGao Xiang 		return -ENOMEM;
22747e4937aSGao Xiang 
2280dcd3c94SGao Xiang 	m_pofs += vi->xattr_isize;
229c521e3adSGao Xiang 	/* inline symlink data shouldn't cross block boundary */
2303acea5fcSJingbo Xu 	if (m_pofs + inode->i_size > bsz) {
23147e4937aSGao Xiang 		kfree(lnk);
2324f761fa2SGao Xiang 		erofs_err(inode->i_sb,
2334f761fa2SGao Xiang 			  "inline data cross block boundary @ nid %llu",
23447e4937aSGao Xiang 			  vi->nid);
23547e4937aSGao Xiang 		DBG_BUGON(1);
23647e4937aSGao Xiang 		return -EFSCORRUPTED;
23747e4937aSGao Xiang 	}
238c521e3adSGao Xiang 	memcpy(lnk, kaddr + m_pofs, inode->i_size);
23947e4937aSGao Xiang 	lnk[inode->i_size] = '\0';
24047e4937aSGao Xiang 
24147e4937aSGao Xiang 	inode->i_link = lnk;
242a2c75c81SGao Xiang 	inode->i_op = &erofs_fast_symlink_iops;
24347e4937aSGao Xiang 	return 0;
24447e4937aSGao Xiang }
24547e4937aSGao Xiang 
246312fe643SGao Xiang static int erofs_fill_inode(struct inode *inode)
24747e4937aSGao Xiang {
248a5876e24SGao Xiang 	struct erofs_inode *vi = EROFS_I(inode);
249c521e3adSGao Xiang 	struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
250c521e3adSGao Xiang 	void *kaddr;
25147e4937aSGao Xiang 	unsigned int ofs;
2520dcd3c94SGao Xiang 	int err = 0;
25347e4937aSGao Xiang 
254312fe643SGao Xiang 	trace_erofs_fill_inode(inode);
25547e4937aSGao Xiang 
2560dcd3c94SGao Xiang 	/* read inode base data from disk */
257c521e3adSGao Xiang 	kaddr = erofs_read_inode(&buf, inode, &ofs);
258c521e3adSGao Xiang 	if (IS_ERR(kaddr))
259c521e3adSGao Xiang 		return PTR_ERR(kaddr);
26084947eb6SGao Xiang 
26147e4937aSGao Xiang 	/* setup the new inode */
262512f9922SPratik Shinde 	switch (inode->i_mode & S_IFMT) {
263512f9922SPratik Shinde 	case S_IFREG:
26447e4937aSGao Xiang 		inode->i_op = &erofs_generic_iops;
265a08e67a0SHuang Jianan 		if (erofs_inode_is_data_compressed(vi->datalayout))
26647e4937aSGao Xiang 			inode->i_fop = &generic_ro_fops;
267a08e67a0SHuang Jianan 		else
268a08e67a0SHuang Jianan 			inode->i_fop = &erofs_file_fops;
269512f9922SPratik Shinde 		break;
270512f9922SPratik Shinde 	case S_IFDIR:
27147e4937aSGao Xiang 		inode->i_op = &erofs_dir_iops;
27247e4937aSGao Xiang 		inode->i_fop = &erofs_dir_fops;
273927e5010SGao Xiang 		inode_nohighmem(inode);
274512f9922SPratik Shinde 		break;
275512f9922SPratik Shinde 	case S_IFLNK:
276c521e3adSGao Xiang 		err = erofs_fill_symlink(inode, kaddr, ofs);
277a2c75c81SGao Xiang 		if (err)
278a2c75c81SGao Xiang 			goto out_unlock;
27947e4937aSGao Xiang 		inode_nohighmem(inode);
280512f9922SPratik Shinde 		break;
281512f9922SPratik Shinde 	case S_IFCHR:
282512f9922SPratik Shinde 	case S_IFBLK:
283512f9922SPratik Shinde 	case S_IFIFO:
284512f9922SPratik Shinde 	case S_IFSOCK:
28547e4937aSGao Xiang 		inode->i_op = &erofs_generic_iops;
28647e4937aSGao Xiang 		init_special_inode(inode, inode->i_mode, inode->i_rdev);
28747e4937aSGao Xiang 		goto out_unlock;
288512f9922SPratik Shinde 	default:
28947e4937aSGao Xiang 		err = -EFSCORRUPTED;
29047e4937aSGao Xiang 		goto out_unlock;
29147e4937aSGao Xiang 	}
29247e4937aSGao Xiang 
2938a765682SGao Xiang 	if (erofs_inode_is_data_compressed(vi->datalayout)) {
294*d3c4bdccSJingbo Xu 		if (!erofs_is_fscache_mode(inode->i_sb) &&
295*d3c4bdccSJingbo Xu 		    inode->i_sb->s_blocksize_bits == PAGE_SHIFT)
29647e4937aSGao Xiang 			err = z_erofs_fill_inode(inode);
2970130e4e8SJeffle Xu 		else
2980130e4e8SJeffle Xu 			err = -EOPNOTSUPP;
29947e4937aSGao Xiang 		goto out_unlock;
30047e4937aSGao Xiang 	}
30147e4937aSGao Xiang 	inode->i_mapping->a_ops = &erofs_raw_access_aops;
302ce529cc2SJingbo Xu 	mapping_set_large_folios(inode->i_mapping);
3031442b02bSJeffle Xu #ifdef CONFIG_EROFS_FS_ONDEMAND
3041442b02bSJeffle Xu 	if (erofs_is_fscache_mode(inode->i_sb))
3051442b02bSJeffle Xu 		inode->i_mapping->a_ops = &erofs_fscache_access_aops;
3061442b02bSJeffle Xu #endif
30747e4937aSGao Xiang 
30847e4937aSGao Xiang out_unlock:
309c521e3adSGao Xiang 	erofs_put_metabuf(&buf);
31047e4937aSGao Xiang 	return err;
31147e4937aSGao Xiang }
31247e4937aSGao Xiang 
31347e4937aSGao Xiang /*
3147c3511a2SGao Xiang  * ino_t is 32-bits on 32-bit arch. We have to squash the 64-bit value down
3157c3511a2SGao Xiang  * so that it will fit.
31647e4937aSGao Xiang  */
3177c3511a2SGao Xiang static ino_t erofs_squash_ino(erofs_nid_t nid)
31847e4937aSGao Xiang {
3197c3511a2SGao Xiang 	ino_t ino = (ino_t)nid;
32047e4937aSGao Xiang 
3217c3511a2SGao Xiang 	if (sizeof(ino_t) < sizeof(erofs_nid_t))
3227c3511a2SGao Xiang 		ino ^= nid >> (sizeof(erofs_nid_t) - sizeof(ino_t)) * 8;
3237c3511a2SGao Xiang 	return ino;
32447e4937aSGao Xiang }
32547e4937aSGao Xiang 
3267c3511a2SGao Xiang static int erofs_iget5_eq(struct inode *inode, void *opaque)
3277c3511a2SGao Xiang {
3287c3511a2SGao Xiang 	return EROFS_I(inode)->nid == *(erofs_nid_t *)opaque;
3297c3511a2SGao Xiang }
3307c3511a2SGao Xiang 
3317c3511a2SGao Xiang static int erofs_iget5_set(struct inode *inode, void *opaque)
33247e4937aSGao Xiang {
33347e4937aSGao Xiang 	const erofs_nid_t nid = *(erofs_nid_t *)opaque;
33447e4937aSGao Xiang 
3357c3511a2SGao Xiang 	inode->i_ino = erofs_squash_ino(nid);
3367c3511a2SGao Xiang 	EROFS_I(inode)->nid = nid;
33747e4937aSGao Xiang 	return 0;
33847e4937aSGao Xiang }
33947e4937aSGao Xiang 
340312fe643SGao Xiang struct inode *erofs_iget(struct super_block *sb, erofs_nid_t nid)
34147e4937aSGao Xiang {
342312fe643SGao Xiang 	struct inode *inode;
34347e4937aSGao Xiang 
3447c3511a2SGao Xiang 	inode = iget5_locked(sb, erofs_squash_ino(nid), erofs_iget5_eq,
3457c3511a2SGao Xiang 			     erofs_iget5_set, &nid);
3468d8a09b0SGao Xiang 	if (!inode)
34747e4937aSGao Xiang 		return ERR_PTR(-ENOMEM);
34847e4937aSGao Xiang 
34947e4937aSGao Xiang 	if (inode->i_state & I_NEW) {
3507c3511a2SGao Xiang 		int err = erofs_fill_inode(inode);
35147e4937aSGao Xiang 
3527c3511a2SGao Xiang 		if (err) {
35347e4937aSGao Xiang 			iget_failed(inode);
3547c3511a2SGao Xiang 			return ERR_PTR(err);
35547e4937aSGao Xiang 		}
3567c3511a2SGao Xiang 		unlock_new_inode(inode);
35747e4937aSGao Xiang 	}
35847e4937aSGao Xiang 	return inode;
35947e4937aSGao Xiang }
36047e4937aSGao Xiang 
361b74d24f7SChristian Brauner int erofs_getattr(struct mnt_idmap *idmap, const struct path *path,
362549c7297SChristian Brauner 		  struct kstat *stat, u32 request_mask,
363549c7297SChristian Brauner 		  unsigned int query_flags)
36447e4937aSGao Xiang {
36547e4937aSGao Xiang 	struct inode *const inode = d_inode(path->dentry);
36647e4937aSGao Xiang 
367a5876e24SGao Xiang 	if (erofs_inode_is_data_compressed(EROFS_I(inode)->datalayout))
36847e4937aSGao Xiang 		stat->attributes |= STATX_ATTR_COMPRESSED;
36947e4937aSGao Xiang 
37047e4937aSGao Xiang 	stat->attributes |= STATX_ATTR_IMMUTABLE;
37147e4937aSGao Xiang 	stat->attributes_mask |= (STATX_ATTR_COMPRESSED |
37247e4937aSGao Xiang 				  STATX_ATTR_IMMUTABLE);
37347e4937aSGao Xiang 
374b74d24f7SChristian Brauner 	generic_fillattr(idmap, inode, stat);
37547e4937aSGao Xiang 	return 0;
37647e4937aSGao Xiang }
37747e4937aSGao Xiang 
37847e4937aSGao Xiang const struct inode_operations erofs_generic_iops = {
37947e4937aSGao Xiang 	.getattr = erofs_getattr,
38047e4937aSGao Xiang 	.listxattr = erofs_listxattr,
381cac2f8b8SChristian Brauner 	.get_inode_acl = erofs_get_acl,
382eadcd6b5SGao Xiang 	.fiemap = erofs_fiemap,
38347e4937aSGao Xiang };
38447e4937aSGao Xiang 
38547e4937aSGao Xiang const struct inode_operations erofs_symlink_iops = {
38647e4937aSGao Xiang 	.get_link = page_get_link,
38747e4937aSGao Xiang 	.getattr = erofs_getattr,
38847e4937aSGao Xiang 	.listxattr = erofs_listxattr,
389cac2f8b8SChristian Brauner 	.get_inode_acl = erofs_get_acl,
39047e4937aSGao Xiang };
39147e4937aSGao Xiang 
39247e4937aSGao Xiang const struct inode_operations erofs_fast_symlink_iops = {
39347e4937aSGao Xiang 	.get_link = simple_get_link,
39447e4937aSGao Xiang 	.getattr = erofs_getattr,
39547e4937aSGao Xiang 	.listxattr = erofs_listxattr,
396cac2f8b8SChristian Brauner 	.get_inode_acl = erofs_get_acl,
39747e4937aSGao Xiang };
398