fs/erofs/xattr.c

Source file repositories/reference/linux-study-clean/fs/erofs/xattr.c

File Facts

System
Linux kernel
Corpus path
fs/erofs/xattr.c
Extension
.c
Size
17665 bytes
Lines
650
Domain
Core OS
Bucket
VFS And Filesystem Core
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

struct erofs_xattr_iter {
	struct super_block *sb;
	struct erofs_buf buf;
	erofs_off_t pos;
	void *kaddr;

	char *buffer;
	int buffer_size, buffer_ofs;

	/* getxattr */
	int index, infix_len;
	struct qstr name;

	/* listxattr */
	struct dentry *dentry;
};

static const char *erofs_xattr_prefix(unsigned int idx, struct dentry *dentry);

static int erofs_init_inode_xattrs(struct inode *inode)
{
	struct erofs_buf buf = __EROFS_BUF_INITIALIZER;
	struct erofs_inode *vi = EROFS_I(inode);
	struct super_block *sb = inode->i_sb;
	const struct erofs_xattr_ibody_header *ih;
	__le32 *xattr_id;
	erofs_off_t pos;
	unsigned int i;
	int ret = 0;

	if (!vi->xattr_isize)
		return -ENODATA;

	/* the most case is that xattrs of this inode are initialized. */
	if (test_bit(EROFS_I_EA_INITED_BIT, &vi->flags)) {
		/*
		 * paired with smp_mb() at the end of the function to ensure
		 * fields will only be observed after the bit is set.
		 */
		smp_mb();
		return 0;
	}
	if (wait_on_bit_lock(&vi->flags, EROFS_I_BL_XATTR_BIT, TASK_KILLABLE))
		return -ERESTARTSYS;

	/* someone has initialized xattrs for us? */
	if (test_bit(EROFS_I_EA_INITED_BIT, &vi->flags))
		goto out_unlock;

	/*
	 * bypass all xattr operations if ->xattr_isize is not greater than
	 * sizeof(struct erofs_xattr_ibody_header), in detail:
	 * 1) it is not enough to contain erofs_xattr_ibody_header then
	 *    ->xattr_isize should be 0 (it means no xattr);
	 * 2) it is just to contain erofs_xattr_ibody_header, which is on-disk
	 *    undefined right now (maybe use later with some new sb feature).
	 */
	if (vi->xattr_isize == sizeof(struct erofs_xattr_ibody_header)) {
		erofs_err(sb, "xattr_isize %d of nid %llu is not supported yet",
			  vi->xattr_isize, vi->nid);
		ret = -EOPNOTSUPP;
		goto out_unlock;
	} else if (vi->xattr_isize < sizeof(struct erofs_xattr_ibody_header)) {
		erofs_err(sb, "bogus xattr ibody @ nid %llu", vi->nid);
		DBG_BUGON(1);
		ret = -EFSCORRUPTED;
		goto out_unlock;
	}

	pos = erofs_iloc(inode) + vi->inode_isize;
	ih = erofs_read_metabuf(&buf, sb, pos, erofs_inode_in_metabox(inode));
	if (IS_ERR(ih)) {
		ret = PTR_ERR(ih);
		goto out_unlock;
	}
	vi->xattr_name_filter = le32_to_cpu(ih->h_name_filter);
	vi->xattr_shared_count = ih->h_shared_count;
	if ((u32)vi->xattr_shared_count * sizeof(__le32) >
	    vi->xattr_isize - sizeof(struct erofs_xattr_ibody_header)) {
		erofs_err(sb, "invalid h_shared_count %u @ nid %llu",
			  vi->xattr_shared_count, vi->nid);
		ret = -EFSCORRUPTED;
		goto out_unlock;
	}
	vi->xattr_shared_xattrs = kmalloc_objs(uint, vi->xattr_shared_count);
	if (!vi->xattr_shared_xattrs) {
		ret = -ENOMEM;
		goto out_unlock;
	}

Annotation

Implementation Notes