[PATCH 1/2] erofs: add sysfs interface

Joe Perches joe at perches.com
Tue Nov 9 14:14:13 AEDT 2021


On Tue, 2021-11-09 at 10:54 +0800, Huang Jianan wrote:
> Add sysfs interface to configure erofs related parameters in the
> future.
[]
> diff --git a/fs/erofs/sysfs.c b/fs/erofs/sysfs.c
[]
> +static ssize_t erofs_attr_show(struct kobject *kobj,
> +				struct attribute *attr, char *buf)
> +{
> +	struct erofs_sb_info *sbi = container_of(kobj, struct erofs_sb_info,
> +						s_kobj);
> +	struct erofs_attr *a = container_of(attr, struct erofs_attr, attr);
> +	unsigned char *ptr = __struct_ptr(sbi, a->struct_type, a->offset);
> +
> +	switch (a->attr_id) {
> +	case attr_feature:
> +		return snprintf(buf, PAGE_SIZE, "supported\n");
> +	case attr_pointer_ui:
> +		if (!ptr)
> +			return 0;
> +		return snprintf(buf, PAGE_SIZE, "%u\n",
> +				*((unsigned int *) ptr));

Prefer sysfs_emit over snprintf

	case attr_feature:
		return sysfs_emit(buf, "supported\n");
	case attr_pointer_ui:
		...
		return sysfs_emit(buf, "%u\n", *(unsigned int *)ptr);

etc...




More information about the Linux-erofs mailing list