sysfs.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef _BTRFS_SYSFS_H_
  2. #define _BTRFS_SYSFS_H_
  3. /*
  4. * Data exported through sysfs
  5. */
  6. extern u64 btrfs_debugfs_test;
  7. enum btrfs_feature_set {
  8. FEAT_COMPAT,
  9. FEAT_COMPAT_RO,
  10. FEAT_INCOMPAT,
  11. FEAT_MAX
  12. };
  13. #define __INIT_KOBJ_ATTR(_name, _mode, _show, _store) \
  14. { \
  15. .attr = { .name = __stringify(_name), .mode = _mode }, \
  16. .show = _show, \
  17. .store = _store, \
  18. }
  19. #define BTRFS_ATTR_RW(_name, _show, _store) \
  20. static struct kobj_attribute btrfs_attr_##_name = \
  21. __INIT_KOBJ_ATTR(_name, 0644, _show, _store)
  22. #define BTRFS_ATTR(_name, _show) \
  23. static struct kobj_attribute btrfs_attr_##_name = \
  24. __INIT_KOBJ_ATTR(_name, 0444, _show, NULL)
  25. #define BTRFS_ATTR_PTR(_name) (&btrfs_attr_##_name.attr)
  26. #define BTRFS_RAID_ATTR(_name, _show) \
  27. static struct kobj_attribute btrfs_raid_attr_##_name = \
  28. __INIT_KOBJ_ATTR(_name, 0444, _show, NULL)
  29. #define BTRFS_RAID_ATTR_PTR(_name) (&btrfs_raid_attr_##_name.attr)
  30. struct btrfs_feature_attr {
  31. struct kobj_attribute kobj_attr;
  32. enum btrfs_feature_set feature_set;
  33. u64 feature_bit;
  34. };
  35. #define BTRFS_FEAT_ATTR(_name, _feature_set, _prefix, _feature_bit) \
  36. static struct btrfs_feature_attr btrfs_attr_##_name = { \
  37. .kobj_attr = __INIT_KOBJ_ATTR(_name, S_IRUGO, \
  38. btrfs_feature_attr_show, \
  39. btrfs_feature_attr_store), \
  40. .feature_set = _feature_set, \
  41. .feature_bit = _prefix ##_## _feature_bit, \
  42. }
  43. #define BTRFS_FEAT_ATTR_PTR(_name) (&btrfs_attr_##_name.kobj_attr.attr)
  44. #define BTRFS_FEAT_ATTR_COMPAT(name, feature) \
  45. BTRFS_FEAT_ATTR(name, FEAT_COMPAT, BTRFS_FEATURE_COMPAT, feature)
  46. #define BTRFS_FEAT_ATTR_COMPAT_RO(name, feature) \
  47. BTRFS_FEAT_ATTR(name, FEAT_COMPAT_RO, BTRFS_FEATURE_COMPAT_RO, feature)
  48. #define BTRFS_FEAT_ATTR_INCOMPAT(name, feature) \
  49. BTRFS_FEAT_ATTR(name, FEAT_INCOMPAT, BTRFS_FEATURE_INCOMPAT, feature)
  50. /* convert from attribute */
  51. static inline struct btrfs_feature_attr *
  52. to_btrfs_feature_attr(struct kobj_attribute *a)
  53. {
  54. return container_of(a, struct btrfs_feature_attr, kobj_attr);
  55. }
  56. static inline struct kobj_attribute *attr_to_btrfs_attr(struct attribute *attr)
  57. {
  58. return container_of(attr, struct kobj_attribute, attr);
  59. }
  60. static inline struct btrfs_feature_attr *
  61. attr_to_btrfs_feature_attr(struct attribute *attr)
  62. {
  63. return to_btrfs_feature_attr(attr_to_btrfs_attr(attr));
  64. }
  65. char *btrfs_printable_features(enum btrfs_feature_set set, u64 flags);
  66. extern const char * const btrfs_feature_set_names[3];
  67. extern struct kobj_type space_info_ktype;
  68. extern struct kobj_type btrfs_raid_ktype;
  69. int btrfs_sysfs_add_device_link(struct btrfs_fs_devices *fs_devices,
  70. struct btrfs_device *one_device);
  71. int btrfs_sysfs_rm_device_link(struct btrfs_fs_devices *fs_devices,
  72. struct btrfs_device *one_device);
  73. int btrfs_sysfs_add_fsid(struct btrfs_fs_devices *fs_devs,
  74. struct kobject *parent);
  75. int btrfs_sysfs_add_device(struct btrfs_fs_devices *fs_devs);
  76. void btrfs_sysfs_remove_fsid(struct btrfs_fs_devices *fs_devs);
  77. void btrfs_sysfs_feature_update(struct btrfs_fs_info *fs_info,
  78. u64 bit, enum btrfs_feature_set set);
  79. #endif /* _BTRFS_SYSFS_H_ */