Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 1 | #ifndef _BTRFS_SYSFS_H_ |
| 2 | #define _BTRFS_SYSFS_H_ |
| 3 | |
| 4 | enum btrfs_feature_set { |
| 5 | FEAT_COMPAT, |
| 6 | FEAT_COMPAT_RO, |
| 7 | FEAT_INCOMPAT, |
| 8 | FEAT_MAX |
| 9 | }; |
| 10 | |
| 11 | #define __INIT_KOBJ_ATTR(_name, _mode, _show, _store) \ |
| 12 | { \ |
| 13 | .attr = { .name = __stringify(_name), .mode = _mode }, \ |
| 14 | .show = _show, \ |
| 15 | .store = _store, \ |
| 16 | } |
| 17 | |
Jeff Mahoney | 5ac1d20 | 2013-11-01 13:06:58 -0400 | [diff] [blame^] | 18 | #define BTRFS_ATTR_RW(_name, _mode, _show, _store) \ |
| 19 | static struct kobj_attribute btrfs_attr_##_name = \ |
| 20 | __INIT_KOBJ_ATTR(_name, _mode, _show, _store) |
| 21 | #define BTRFS_ATTR(_name, _mode, _show) \ |
| 22 | BTRFS_ATTR_RW(_name, _mode, _show, NULL) |
| 23 | #define BTRFS_ATTR_PTR(_name) (&btrfs_attr_##_name.attr) |
| 24 | |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 25 | struct btrfs_feature_attr { |
| 26 | struct kobj_attribute kobj_attr; |
| 27 | enum btrfs_feature_set feature_set; |
| 28 | u64 feature_bit; |
| 29 | }; |
| 30 | |
| 31 | #define BTRFS_FEAT_ATTR(_name, _feature_set, _prefix, _feature_bit) \ |
| 32 | static struct btrfs_feature_attr btrfs_attr_##_name = { \ |
| 33 | .kobj_attr = __INIT_KOBJ_ATTR(_name, S_IRUGO, \ |
| 34 | btrfs_feature_attr_show, NULL), \ |
| 35 | .feature_set = _feature_set, \ |
| 36 | .feature_bit = _prefix ##_## _feature_bit, \ |
| 37 | } |
| 38 | #define BTRFS_FEAT_ATTR_PTR(_name) (&btrfs_attr_##_name.kobj_attr.attr) |
| 39 | |
| 40 | #define BTRFS_FEAT_ATTR_COMPAT(name, feature) \ |
| 41 | BTRFS_FEAT_ATTR(name, FEAT_COMPAT, BTRFS_FEATURE_COMPAT, feature) |
| 42 | #define BTRFS_FEAT_ATTR_COMPAT_RO(name, feature) \ |
| 43 | BTRFS_FEAT_ATTR(name, FEAT_COMPAT_RO, BTRFS_FEATURE_COMPAT, feature) |
| 44 | #define BTRFS_FEAT_ATTR_INCOMPAT(name, feature) \ |
| 45 | BTRFS_FEAT_ATTR(name, FEAT_INCOMPAT, BTRFS_FEATURE_INCOMPAT, feature) |
| 46 | |
| 47 | /* convert from attribute */ |
| 48 | #define to_btrfs_feature_attr(a) \ |
| 49 | container_of(a, struct btrfs_feature_attr, kobj_attr) |
Jeff Mahoney | 5ac1d20 | 2013-11-01 13:06:58 -0400 | [diff] [blame^] | 50 | #define attr_to_btrfs_attr(a) container_of(a, struct kobj_attribute, attr) |
| 51 | #define attr_to_btrfs_feature_attr(a) \ |
| 52 | to_btrfs_feature_attr(attr_to_btrfs_attr(a)) |
Jeff Mahoney | 079b72b | 2013-11-01 13:06:57 -0400 | [diff] [blame] | 53 | #endif /* _BTRFS_SYSFS_H_ */ |