1 #ifndef _BCACHE_SYSFS_H_
2 #define _BCACHE_SYSFS_H_
7 struct kobj_type type ## _ktype = { \
8 .release = type ## _release, \
9 .sysfs_ops = &((const struct sysfs_ops) { \
10 .show = type ## _show, \
11 .store = type ## _store \
13 .default_attrs = type ## _files \
17 static ssize_t fn ## _show(struct kobject *kobj, struct attribute *attr,\
21 static ssize_t fn ## _store(struct kobject *kobj, struct attribute *attr,\
22 const char *buf, size_t size) \
24 #define __sysfs_attribute(_name, _mode) \
25 static struct attribute sysfs_##_name = \
26 { .name = #_name, .mode = _mode }
28 #define write_attribute(n) __sysfs_attribute(n, S_IWUSR)
29 #define read_attribute(n) __sysfs_attribute(n, S_IRUGO)
30 #define rw_attribute(n) __sysfs_attribute(n, S_IRUGO|S_IWUSR)
32 #define sysfs_printf(file, fmt, ...) \
34 if (attr == &sysfs_ ## file) \
35 return snprintf(buf, PAGE_SIZE, fmt "\n", __VA_ARGS__); \
38 #define sysfs_print(file, var) \
40 if (attr == &sysfs_ ## file) \
41 return snprint(buf, PAGE_SIZE, var); \
44 #define sysfs_hprint(file, val) \
46 if (attr == &sysfs_ ## file) { \
47 ssize_t ret = bch_hprint(buf, val); \
53 #define var_printf(_var, fmt) sysfs_printf(_var, fmt, var(_var))
54 #define var_print(_var) sysfs_print(_var, var(_var))
55 #define var_hprint(_var) sysfs_hprint(_var, var(_var))
57 #define sysfs_strtoul(file, var) \
59 if (attr == &sysfs_ ## file) \
60 return strtoul_safe(buf, var) ?: (ssize_t) size; \
63 #define sysfs_strtoul_clamp(file, var, min, max) \
65 if (attr == &sysfs_ ## file) \
66 return strtoul_safe_clamp(buf, var, min, max) \
70 #define strtoul_or_return(cp) \
73 int _r = kstrtoul(cp, 10, &_v); \
79 #define strtoul_restrict_or_return(cp, min, max) \
81 unsigned long __v = 0; \
82 int _r = strtoul_safe_restrict(cp, __v, min, max); \
88 #define strtoi_h_or_return(cp) \
91 int _r = strtoi_h(cp, &_v); \
97 #define sysfs_hatoi(file, var) \
99 if (attr == &sysfs_ ## file) \
100 return strtoi_h(buf, &var) ?: (ssize_t) size; \
103 #endif /* _BCACHE_SYSFS_H_ */