Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (C) 2017-2018 HUAWEI, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *             https://www.huawei.com/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Created by Gao Xiang <gaoxiang25@huawei.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include "xattr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <trace/events/erofs.h>
^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)  * if inode is successfully read, return its inode page (or sometimes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * the inode payload page if it's an extended inode) in order to fill
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * inline data if possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) static struct page *erofs_read_inode(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 				     unsigned int *ofs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	struct super_block *sb = inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	struct erofs_sb_info *sbi = EROFS_SB(sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	struct erofs_inode *vi = EROFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	const erofs_off_t inode_loc = iloc(sbi, vi->nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	erofs_blk_t blkaddr, nblks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct erofs_inode_compact *dic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	struct erofs_inode_extended *die, *copied = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	unsigned int ifmt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	blkaddr = erofs_blknr(inode_loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	*ofs = erofs_blkoff(inode_loc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	erofs_dbg("%s, reading inode nid %llu at %u of blkaddr %u",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		  __func__, vi->nid, *ofs, blkaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	page = erofs_get_meta_page(sb, blkaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	if (IS_ERR(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		erofs_err(sb, "failed to get inode (nid: %llu) page, err %ld",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 			  vi->nid, PTR_ERR(page));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		return page;
^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) 	dic = page_address(page) + *ofs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	ifmt = le16_to_cpu(dic->i_format);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	if (ifmt & ~EROFS_I_ALL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		erofs_err(inode->i_sb, "unsupported i_format %u of nid %llu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			  ifmt, vi->nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		err = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		goto err_out;
^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) 	vi->datalayout = erofs_inode_datalayout(ifmt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	if (vi->datalayout >= EROFS_INODE_DATALAYOUT_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		erofs_err(inode->i_sb, "unsupported datalayout %u of nid %llu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 			  vi->datalayout, vi->nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		err = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		goto err_out;
^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) 	switch (erofs_inode_version(ifmt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	case EROFS_INODE_LAYOUT_EXTENDED:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		vi->inode_isize = sizeof(struct erofs_inode_extended);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		/* check if the inode acrosses page boundary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		if (*ofs + vi->inode_isize <= PAGE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 			*ofs += vi->inode_isize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 			die = (struct erofs_inode_extended *)dic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 			const unsigned int gotten = PAGE_SIZE - *ofs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			copied = kmalloc(vi->inode_isize, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			if (!copied) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 				err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 				goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			memcpy(copied, dic, gotten);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 			unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 			page = erofs_get_meta_page(sb, blkaddr + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			if (IS_ERR(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 				erofs_err(sb, "failed to get inode payload page (nid: %llu), err %ld",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 					  vi->nid, PTR_ERR(page));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 				kfree(copied);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 				return page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			*ofs = vi->inode_isize - gotten;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			memcpy((u8 *)copied + gotten, page_address(page), *ofs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			die = copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		vi->xattr_isize = erofs_xattr_ibody_size(die->i_xattr_icount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		inode->i_mode = le16_to_cpu(die->i_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		switch (inode->i_mode & S_IFMT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		case S_IFREG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		case S_IFDIR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		case S_IFLNK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			vi->raw_blkaddr = le32_to_cpu(die->i_u.raw_blkaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		case S_IFCHR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		case S_IFBLK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 			inode->i_rdev =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 				new_decode_dev(le32_to_cpu(die->i_u.rdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		case S_IFIFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		case S_IFSOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			inode->i_rdev = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			goto bogusimode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		i_uid_write(inode, le32_to_cpu(die->i_uid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		i_gid_write(inode, le32_to_cpu(die->i_gid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		set_nlink(inode, le32_to_cpu(die->i_nlink));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		/* extended inode has its own timestamp */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		inode->i_ctime.tv_sec = le64_to_cpu(die->i_ctime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		inode->i_ctime.tv_nsec = le32_to_cpu(die->i_ctime_nsec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		inode->i_size = le64_to_cpu(die->i_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		/* total blocks for compressed files */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		if (erofs_inode_is_data_compressed(vi->datalayout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			nblks = le32_to_cpu(die->i_u.compressed_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		kfree(copied);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	case EROFS_INODE_LAYOUT_COMPACT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		vi->inode_isize = sizeof(struct erofs_inode_compact);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		*ofs += vi->inode_isize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		vi->xattr_isize = erofs_xattr_ibody_size(dic->i_xattr_icount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		inode->i_mode = le16_to_cpu(dic->i_mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		switch (inode->i_mode & S_IFMT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		case S_IFREG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		case S_IFDIR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		case S_IFLNK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			vi->raw_blkaddr = le32_to_cpu(dic->i_u.raw_blkaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		case S_IFCHR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		case S_IFBLK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			inode->i_rdev =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 				new_decode_dev(le32_to_cpu(dic->i_u.rdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		case S_IFIFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		case S_IFSOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			inode->i_rdev = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 			goto bogusimode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		i_uid_write(inode, le16_to_cpu(dic->i_uid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		i_gid_write(inode, le16_to_cpu(dic->i_gid));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		set_nlink(inode, le16_to_cpu(dic->i_nlink));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		/* use build time for compact inodes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		inode->i_ctime.tv_sec = sbi->build_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		inode->i_ctime.tv_nsec = sbi->build_time_nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		inode->i_size = le32_to_cpu(dic->i_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		if (erofs_inode_is_data_compressed(vi->datalayout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			nblks = le32_to_cpu(dic->i_u.compressed_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		erofs_err(inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 			  "unsupported on-disk inode version %u of nid %llu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			  erofs_inode_version(ifmt), vi->nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		err = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	inode->i_mtime.tv_sec = inode->i_ctime.tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	inode->i_atime.tv_sec = inode->i_ctime.tv_sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	inode->i_mtime.tv_nsec = inode->i_ctime.tv_nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	inode->i_atime.tv_nsec = inode->i_ctime.tv_nsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	inode->i_flags &= ~S_DAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	if (test_opt(&sbi->ctx, DAX_ALWAYS) && S_ISREG(inode->i_mode) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	    vi->datalayout == EROFS_INODE_FLAT_PLAIN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		inode->i_flags |= S_DAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	if (!nblks)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		/* measure inode.i_blocks as generic filesystems */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		inode->i_blocks = roundup(inode->i_size, EROFS_BLKSIZ) >> 9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		inode->i_blocks = nblks << LOG_SECTORS_PER_BLOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	return page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) bogusimode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	erofs_err(inode->i_sb, "bogus i_mode (%o) @ nid %llu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		  inode->i_mode, vi->nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	err = -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	DBG_BUGON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	kfree(copied);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	return ERR_PTR(err);
^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) static int erofs_fill_symlink(struct inode *inode, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			      unsigned int m_pofs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	struct erofs_inode *vi = EROFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	char *lnk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	/* if it cannot be handled with fast symlink scheme */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	if (vi->datalayout != EROFS_INODE_FLAT_INLINE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	    inode->i_size >= PAGE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		inode->i_op = &erofs_symlink_iops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	lnk = kmalloc(inode->i_size + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	if (!lnk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	m_pofs += vi->xattr_isize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	/* inline symlink data shouldn't cross page boundary as well */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (m_pofs + inode->i_size > PAGE_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		kfree(lnk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		erofs_err(inode->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			  "inline data cross block boundary @ nid %llu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 			  vi->nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		DBG_BUGON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		return -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	memcpy(lnk, data + m_pofs, inode->i_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	lnk[inode->i_size] = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	inode->i_link = lnk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	inode->i_op = &erofs_fast_symlink_iops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static int erofs_fill_inode(struct inode *inode, int isdir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	struct erofs_inode *vi = EROFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	unsigned int ofs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	trace_erofs_fill_inode(inode, isdir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	/* read inode base data from disk */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	page = erofs_read_inode(inode, &ofs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	if (IS_ERR(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 		return PTR_ERR(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	/* setup the new inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	switch (inode->i_mode & S_IFMT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	case S_IFREG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		inode->i_op = &erofs_generic_iops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		if (erofs_inode_is_data_compressed(vi->datalayout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 			inode->i_fop = &generic_ro_fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 			inode->i_fop = &erofs_file_fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	case S_IFDIR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		inode->i_op = &erofs_dir_iops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		inode->i_fop = &erofs_dir_fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	case S_IFLNK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		err = erofs_fill_symlink(inode, page_address(page), ofs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		inode_nohighmem(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	case S_IFCHR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	case S_IFBLK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	case S_IFIFO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	case S_IFSOCK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		inode->i_op = &erofs_generic_iops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		init_special_inode(inode, inode->i_mode, inode->i_rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		err = -EFSCORRUPTED;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	if (erofs_inode_is_data_compressed(vi->datalayout)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		err = z_erofs_fill_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	inode->i_mapping->a_ops = &erofs_raw_access_aops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)  * erofs nid is 64bits, but i_ino is 'unsigned long', therefore
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)  * we should do more for 32-bit platform to find the right inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) static int erofs_ilookup_test_actor(struct inode *inode, void *opaque)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	const erofs_nid_t nid = *(erofs_nid_t *)opaque;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	return EROFS_I(inode)->nid == nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) static int erofs_iget_set_actor(struct inode *inode, void *opaque)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	const erofs_nid_t nid = *(erofs_nid_t *)opaque;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	inode->i_ino = erofs_inode_hash(nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) static inline struct inode *erofs_iget_locked(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 					      erofs_nid_t nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	const unsigned long hashval = erofs_inode_hash(nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	return iget5_locked(sb, hashval, erofs_ilookup_test_actor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		erofs_iget_set_actor, &nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) struct inode *erofs_iget(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 			 erofs_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 			 bool isdir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	struct inode *inode = erofs_iget_locked(sb, nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	if (!inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	if (inode->i_state & I_NEW) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 		int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 		struct erofs_inode *vi = EROFS_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		vi->nid = nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		err = erofs_fill_inode(inode, isdir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 			unlock_new_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 			iget_failed(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 			inode = ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	return inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) int erofs_getattr(const struct path *path, struct kstat *stat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		  u32 request_mask, unsigned int query_flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	struct inode *const inode = d_inode(path->dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	if (erofs_inode_is_data_compressed(EROFS_I(inode)->datalayout))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 		stat->attributes |= STATX_ATTR_COMPRESSED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	stat->attributes |= STATX_ATTR_IMMUTABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 	stat->attributes_mask |= (STATX_ATTR_COMPRESSED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 				  STATX_ATTR_IMMUTABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	generic_fillattr(inode, stat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) const struct inode_operations erofs_generic_iops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	.getattr = erofs_getattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	.listxattr = erofs_listxattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	.get_acl = erofs_get_acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) const struct inode_operations erofs_symlink_iops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	.get_link = page_get_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	.getattr = erofs_getattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	.listxattr = erofs_listxattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	.get_acl = erofs_get_acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) const struct inode_operations erofs_fast_symlink_iops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	.get_link = simple_get_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	.getattr = erofs_getattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	.listxattr = erofs_listxattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	.get_acl = erofs_get_acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)