1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _BTRFS_SYSFS_H_
3 #define _BTRFS_SYSFS_H_
6 * Data exported through sysfs
8 extern u64 btrfs_debugfs_test
;
10 enum btrfs_feature_set
{
17 #define __INIT_KOBJ_ATTR(_name, _mode, _show, _store) \
19 .attr = { .name = __stringify(_name), .mode = _mode }, \
24 #define BTRFS_ATTR_RW(_name, _show, _store) \
25 static struct kobj_attribute btrfs_attr_##_name = \
26 __INIT_KOBJ_ATTR(_name, 0644, _show, _store)
28 #define BTRFS_ATTR(_name, _show) \
29 static struct kobj_attribute btrfs_attr_##_name = \
30 __INIT_KOBJ_ATTR(_name, 0444, _show, NULL)
32 #define BTRFS_ATTR_PTR(_name) (&btrfs_attr_##_name.attr)
34 #define BTRFS_RAID_ATTR(_name, _show) \
35 static struct kobj_attribute btrfs_raid_attr_##_name = \
36 __INIT_KOBJ_ATTR(_name, 0444, _show, NULL)
38 #define BTRFS_RAID_ATTR_PTR(_name) (&btrfs_raid_attr_##_name.attr)
41 struct btrfs_feature_attr
{
42 struct kobj_attribute kobj_attr
;
43 enum btrfs_feature_set feature_set
;
47 #define BTRFS_FEAT_ATTR(_name, _feature_set, _prefix, _feature_bit) \
48 static struct btrfs_feature_attr btrfs_attr_##_name = { \
49 .kobj_attr = __INIT_KOBJ_ATTR(_name, S_IRUGO, \
50 btrfs_feature_attr_show, \
51 btrfs_feature_attr_store), \
52 .feature_set = _feature_set, \
53 .feature_bit = _prefix ##_## _feature_bit, \
55 #define BTRFS_FEAT_ATTR_PTR(_name) (&btrfs_attr_##_name.kobj_attr.attr)
57 #define BTRFS_FEAT_ATTR_COMPAT(name, feature) \
58 BTRFS_FEAT_ATTR(name, FEAT_COMPAT, BTRFS_FEATURE_COMPAT, feature)
59 #define BTRFS_FEAT_ATTR_COMPAT_RO(name, feature) \
60 BTRFS_FEAT_ATTR(name, FEAT_COMPAT_RO, BTRFS_FEATURE_COMPAT_RO, feature)
61 #define BTRFS_FEAT_ATTR_INCOMPAT(name, feature) \
62 BTRFS_FEAT_ATTR(name, FEAT_INCOMPAT, BTRFS_FEATURE_INCOMPAT, feature)
64 /* convert from attribute */
65 static inline struct btrfs_feature_attr
*
66 to_btrfs_feature_attr(struct kobj_attribute
*a
)
68 return container_of(a
, struct btrfs_feature_attr
, kobj_attr
);
71 static inline struct kobj_attribute
*attr_to_btrfs_attr(struct attribute
*attr
)
73 return container_of(attr
, struct kobj_attribute
, attr
);
76 static inline struct btrfs_feature_attr
*
77 attr_to_btrfs_feature_attr(struct attribute
*attr
)
79 return to_btrfs_feature_attr(attr_to_btrfs_attr(attr
));
82 char *btrfs_printable_features(enum btrfs_feature_set set
, u64 flags
);
83 extern const char * const btrfs_feature_set_names
[3];
84 extern struct kobj_type space_info_ktype
;
85 extern struct kobj_type btrfs_raid_ktype
;
86 int btrfs_sysfs_add_device_link(struct btrfs_fs_devices
*fs_devices
,
87 struct btrfs_device
*one_device
);
88 int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices
*fs_devices
,
89 struct btrfs_device
*one_device
);
90 int btrfs_sysfs_add_fsid(struct btrfs_fs_devices
*fs_devs
,
91 struct kobject
*parent
);
92 int btrfs_sysfs_add_device(struct btrfs_fs_devices
*fs_devs
);
93 void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices
*fs_devs
);
94 void btrfs_sysfs_feature_update(struct btrfs_fs_info
*fs_info
,
95 u64 bit
, enum btrfs_feature_set set
);
97 #endif /* _BTRFS_SYSFS_H_ */