sysfs.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. struct sysfs_elem_dir {
  2. struct kobject * kobj;
  3. };
  4. struct sysfs_elem_symlink {
  5. struct sysfs_dirent * target_sd;
  6. };
  7. struct sysfs_elem_attr {
  8. struct attribute * attr;
  9. };
  10. struct sysfs_elem_bin_attr {
  11. struct bin_attribute * bin_attr;
  12. };
  13. /*
  14. * As long as s_count reference is held, the sysfs_dirent itself is
  15. * accessible. Dereferencing s_elem or any other outer entity
  16. * requires s_active reference.
  17. */
  18. struct sysfs_dirent {
  19. atomic_t s_count;
  20. atomic_t s_active;
  21. struct sysfs_dirent * s_parent;
  22. struct sysfs_dirent * s_sibling;
  23. struct sysfs_dirent * s_children;
  24. const char * s_name;
  25. union {
  26. struct sysfs_elem_dir dir;
  27. struct sysfs_elem_symlink symlink;
  28. struct sysfs_elem_attr attr;
  29. struct sysfs_elem_bin_attr bin_attr;
  30. } s_elem;
  31. unsigned int s_flags;
  32. umode_t s_mode;
  33. ino_t s_ino;
  34. struct iattr * s_iattr;
  35. atomic_t s_event;
  36. };
  37. #define SD_DEACTIVATED_BIAS INT_MIN
  38. struct sysfs_addrm_cxt {
  39. struct sysfs_dirent *parent_sd;
  40. struct inode *parent_inode;
  41. struct sysfs_dirent *removed;
  42. int cnt;
  43. };
  44. extern struct sysfs_dirent sysfs_root;
  45. extern struct kmem_cache *sysfs_dir_cachep;
  46. extern struct dentry *sysfs_get_dentry(struct sysfs_dirent *sd);
  47. extern struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd);
  48. extern void sysfs_put_active(struct sysfs_dirent *sd);
  49. extern struct sysfs_dirent *sysfs_get_active_two(struct sysfs_dirent *sd);
  50. extern void sysfs_put_active_two(struct sysfs_dirent *sd);
  51. extern void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt,
  52. struct sysfs_dirent *parent_sd);
  53. extern int sysfs_add_one(struct sysfs_addrm_cxt *acxt,
  54. struct sysfs_dirent *sd);
  55. extern void sysfs_remove_one(struct sysfs_addrm_cxt *acxt,
  56. struct sysfs_dirent *sd);
  57. extern void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt);
  58. extern struct inode * sysfs_get_inode(struct sysfs_dirent *sd);
  59. extern void release_sysfs_dirent(struct sysfs_dirent * sd);
  60. extern struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
  61. const unsigned char *name);
  62. extern struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
  63. const unsigned char *name);
  64. extern struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode,
  65. int type);
  66. extern int sysfs_add_file(struct sysfs_dirent *dir_sd,
  67. const struct attribute *attr, int type);
  68. extern int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name);
  69. extern struct sysfs_dirent *sysfs_find(struct sysfs_dirent *dir, const char * name);
  70. extern int sysfs_create_subdir(struct kobject *kobj, const char *name,
  71. struct sysfs_dirent **p_sd);
  72. extern void sysfs_remove_subdir(struct sysfs_dirent *sd);
  73. extern int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
  74. extern spinlock_t sysfs_assoc_lock;
  75. extern struct mutex sysfs_mutex;
  76. extern struct mutex sysfs_rename_mutex;
  77. extern struct super_block * sysfs_sb;
  78. extern const struct file_operations sysfs_dir_operations;
  79. extern const struct file_operations sysfs_file_operations;
  80. extern const struct file_operations bin_fops;
  81. extern const struct inode_operations sysfs_dir_inode_operations;
  82. extern const struct inode_operations sysfs_symlink_inode_operations;
  83. static inline unsigned int sysfs_type(struct sysfs_dirent *sd)
  84. {
  85. return sd->s_flags & SYSFS_TYPE_MASK;
  86. }
  87. static inline struct sysfs_dirent * sysfs_get(struct sysfs_dirent * sd)
  88. {
  89. if (sd) {
  90. WARN_ON(!atomic_read(&sd->s_count));
  91. atomic_inc(&sd->s_count);
  92. }
  93. return sd;
  94. }
  95. static inline void sysfs_put(struct sysfs_dirent * sd)
  96. {
  97. if (sd && atomic_dec_and_test(&sd->s_count))
  98. release_sysfs_dirent(sd);
  99. }