tools/testing/selftests/filesystems/statmount/statmount.h

Source file repositories/reference/linux-study-clean/tools/testing/selftests/filesystems/statmount/statmount.h

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/filesystems/statmount/statmount.h
Extension
.h
Size
2842 bytes
Lines
139
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

if (mnt_ns_id) {
			req.size = MNT_ID_REQ_SIZE_VER1;
			req.mnt_ns_id = mnt_ns_id;
		}
	}

	return syscall(__NR_statmount, &req, buf, bufsize, flags);
}

static inline ssize_t listmount(uint64_t mnt_id, uint64_t mnt_ns_id,
			 uint64_t last_mnt_id, uint64_t list[], size_t num,
			 unsigned int flags)
{
	struct mnt_id_req req = {
		.size = MNT_ID_REQ_SIZE_VER0,
		.mnt_id = mnt_id,
		.param = last_mnt_id,
	};

	if (mnt_ns_id) {
		req.size = MNT_ID_REQ_SIZE_VER1;
		req.mnt_ns_id = mnt_ns_id;
	}

	return syscall(__NR_listmount, &req, list, num, flags);
}

static inline struct statmount *statmount_alloc(uint64_t mnt_id, uint64_t mnt_ns_id,
						 uint64_t mask, unsigned int flags)
{
	struct statmount *buf;
	size_t bufsize = STATMOUNT_BUFSIZE;
	int ret;

	for (;;) {
		buf = malloc(bufsize);
		if (!buf)
			return NULL;

		ret = statmount(mnt_id, mnt_ns_id, 0, mask, buf, bufsize, flags);
		if (ret == 0)
			return buf;

		free(buf);
		if (errno != EOVERFLOW)
			return NULL;

		bufsize <<= 1;
	}
}

static inline struct statmount *statmount_alloc_by_fd(int fd, uint64_t mask)
{
	struct statmount *buf;
	size_t bufsize = STATMOUNT_BUFSIZE;
	int ret;

	for (;;) {
		buf = malloc(bufsize);
		if (!buf)
			return NULL;

		ret = statmount(0, 0, fd, mask, buf, bufsize, STATMOUNT_BY_FD);
		if (ret == 0)
			return buf;

		free(buf);
		if (errno != EOVERFLOW)
			return NULL;

		bufsize <<= 1;
	}
}

#endif /* __STATMOUNT_H */

Annotation

Implementation Notes