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) struct erofs_qstr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 	const unsigned char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 	const unsigned char *end;
^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) /* based on the end of qn is accurate and it must have the trailing '\0' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) static inline int erofs_dirnamecmp(const struct erofs_qstr *qn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 				   const struct erofs_qstr *qd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 				   unsigned int *matched)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	unsigned int i = *matched;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	 * on-disk error, let's only BUG_ON in the debugging mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	 * otherwise, it will return 1 to just skip the invalid name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	 * and go on (in consideration of the lookup performance).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	DBG_BUGON(qd->name > qd->end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	/* qd could not have trailing '\0' */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	/* However it is absolutely safe if < qd->end */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	while (qd->name + i < qd->end && qd->name[i] != '\0') {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		if (qn->name[i] != qd->name[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 			*matched = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 			return qn->name[i] > qd->name[i] ? 1 : -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		++i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	*matched = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	/* See comments in __d_alloc on the terminating NUL character */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	return qn->name[i] == '\0' ? 0 : 1;
^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) #define nameoff_from_disk(off, sz)	(le16_to_cpu(off) & ((sz) - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) static struct erofs_dirent *find_target_dirent(struct erofs_qstr *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 					       u8 *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 					       unsigned int dirblksize,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 					       const int ndirents)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	int head, back;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	unsigned int startprfx, endprfx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	struct erofs_dirent *const de = (struct erofs_dirent *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	/* since the 1st dirent has been evaluated previously */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	head = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	back = ndirents - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	startprfx = endprfx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	while (head <= back) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		const int mid = head + (back - head) / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		const int nameoff = nameoff_from_disk(de[mid].nameoff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 						      dirblksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		unsigned int matched = min(startprfx, endprfx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		struct erofs_qstr dname = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 			.name = data + nameoff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 			.end = mid >= ndirents - 1 ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 				data + dirblksize :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 				data + nameoff_from_disk(de[mid + 1].nameoff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 							 dirblksize)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		/* string comparison without already matched prefix */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		int ret = erofs_dirnamecmp(name, &dname, &matched);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			return de + mid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		} else if (ret > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 			head = mid + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 			startprfx = matched;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 			back = mid - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			endprfx = matched;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	return ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) static struct page *find_target_block_classic(struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 					      struct erofs_qstr *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 					      int *_ndirents)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	unsigned int startprfx, endprfx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	int head, back;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct address_space *const mapping = dir->i_mapping;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	struct page *candidate = ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	startprfx = endprfx = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	head = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	back = erofs_inode_datablocks(dir) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	while (head <= back) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		const int mid = head + (back - head) / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		struct page *page = read_mapping_page(mapping, mid, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		if (!IS_ERR(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 			struct erofs_dirent *de = kmap_atomic(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			const int nameoff = nameoff_from_disk(de->nameoff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 							      EROFS_BLKSIZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 			const int ndirents = nameoff / sizeof(*de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 			int diff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 			unsigned int matched;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 			struct erofs_qstr dname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 			if (!ndirents) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 				kunmap_atomic(de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 				put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 				erofs_err(dir->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 					  "corrupted dir block %d @ nid %llu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 					  mid, EROFS_I(dir)->nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 				DBG_BUGON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 				page = ERR_PTR(-EFSCORRUPTED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			matched = min(startprfx, endprfx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			dname.name = (u8 *)de + nameoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			if (ndirents == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 				dname.end = (u8 *)de + EROFS_BLKSIZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 				dname.end = (u8 *)de +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 					nameoff_from_disk(de[1].nameoff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 							  EROFS_BLKSIZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			/* string comparison without already matched prefix */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			diff = erofs_dirnamecmp(name, &dname, &matched);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 			kunmap_atomic(de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 			if (!diff) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 				*_ndirents = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 				goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 			} else if (diff > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 				head = mid + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 				startprfx = matched;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 				if (!IS_ERR(candidate))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 					put_page(candidate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 				candidate = page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 				*_ndirents = ndirents;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 				put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 				back = mid - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 				endprfx = matched;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) out:		/* free if the candidate is valid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 		if (!IS_ERR(candidate))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			put_page(candidate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		return page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	return candidate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) int erofs_namei(struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		struct qstr *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		erofs_nid_t *nid, unsigned int *d_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	int ndirents;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	void *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	struct erofs_dirent *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	struct erofs_qstr qn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	if (!dir->i_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	qn.name = name->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	qn.end = name->name + name->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	ndirents = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	page = find_target_block_classic(dir, &qn, &ndirents);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	if (IS_ERR(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		return PTR_ERR(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	data = kmap_atomic(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	/* the target page has been mapped */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	if (ndirents)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		de = find_target_dirent(&qn, data, EROFS_BLKSIZ, ndirents);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		de = (struct erofs_dirent *)data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	if (!IS_ERR(de)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		*nid = le64_to_cpu(de->nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		*d_type = de->file_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	kunmap_atomic(data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	return PTR_ERR_OR_ZERO(de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /* NOTE: i_mutex is already held by vfs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static struct dentry *erofs_lookup(struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 				   struct dentry *dentry,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 				   unsigned int flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	erofs_nid_t nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	unsigned int d_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	struct inode *inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	DBG_BUGON(!d_really_is_negative(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	/* dentry must be unhashed in lookup, no need to worry about */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	DBG_BUGON(!d_unhashed(dentry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	trace_erofs_lookup(dir, dentry, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	/* file name exceeds fs limit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	if (dentry->d_name.len > EROFS_NAME_LEN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		return ERR_PTR(-ENAMETOOLONG);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	/* false uninitialized warnings on gcc 4.8.x */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	err = erofs_namei(dir, &dentry->d_name, &nid, &d_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if (err == -ENOENT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		/* negative dentry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	} else if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		inode = ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		erofs_dbg("%s, %s (nid %llu) found, d_type %u", __func__,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 			  dentry->d_name.name, nid, d_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		inode = erofs_iget(dir->i_sb, nid, d_type == FT_DIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	return d_splice_alias(inode, dentry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) const struct inode_operations erofs_dir_iops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	.lookup = erofs_lookup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	.getattr = erofs_getattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	.listxattr = erofs_listxattr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	.get_acl = erofs_get_acl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)