sysfs.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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, 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. #endif /* _BTRFS_SYSFS_H_ */