sysfs.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 dentry * s_dentry;
  35. struct iattr * s_iattr;
  36. atomic_t s_event;
  37. };
  38. #define SD_DEACTIVATED_BIAS INT_MIN
  39. struct sysfs_addrm_cxt {
  40. struct sysfs_dirent *parent_sd;
  41. struct inode *parent_inode;
  42. struct sysfs_dirent *removed;
  43. int cnt;
  44. };
  45. extern struct vfsmount * sysfs_mount;
  46. extern struct sysfs_dirent sysfs_root;
  47. extern struct kmem_cache *sysfs_dir_cachep;
  48. extern struct dentry *sysfs_get_dentry(struct sysfs_dirent *sd);
  49. extern struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd);
  50. extern void sysfs_put_active(struct sysfs_dirent *sd);
  51. extern struct sysfs_dirent *sysfs_get_active_two(struct sysfs_dirent *sd);
  52. extern void sysfs_put_active_two(struct sysfs_dirent *sd);
  53. extern void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt,
  54. struct sysfs_dirent *parent_sd);
  55. extern int sysfs_add_one(struct sysfs_addrm_cxt *acxt,
  56. struct sysfs_dirent *sd);
  57. extern void sysfs_remove_one(struct sysfs_addrm_cxt *acxt,
  58. struct sysfs_dirent *sd);
  59. extern int sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt);
  60. extern struct inode * sysfs_get_inode(struct sysfs_dirent *sd);
  61. extern void sysfs_instantiate(struct dentry *dentry, struct inode *inode);
  62. extern void release_sysfs_dirent(struct sysfs_dirent * sd);
  63. extern struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
  64. const unsigned char *name);
  65. extern struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
  66. const unsigned char *name);
  67. extern struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode,
  68. int type);
  69. extern int sysfs_add_file(struct sysfs_dirent *dir_sd,
  70. const struct attribute *attr, int type);
  71. extern int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name);
  72. extern struct sysfs_dirent *sysfs_find(struct sysfs_dirent *dir, const char * name);
  73. extern int sysfs_create_subdir(struct kobject *kobj, const char *name,
  74. struct sysfs_dirent **p_sd);
  75. extern void sysfs_remove_subdir(struct sysfs_dirent *sd);
  76. extern int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
  77. extern spinlock_t sysfs_assoc_lock;
  78. extern struct mutex sysfs_mutex;
  79. extern struct super_block * sysfs_sb;
  80. extern const struct file_operations sysfs_dir_operations;
  81. extern const struct file_operations sysfs_file_operations;
  82. extern const struct file_operations bin_fops;
  83. extern const struct inode_operations sysfs_dir_inode_operations;
  84. extern const struct inode_operations sysfs_symlink_inode_operations;
  85. static inline unsigned int sysfs_type(struct sysfs_dirent *sd)
  86. {
  87. return sd->s_flags & SYSFS_TYPE_MASK;
  88. }
  89. static inline struct sysfs_dirent * sysfs_get(struct sysfs_dirent * sd)
  90. {
  91. if (sd) {
  92. WARN_ON(!atomic_read(&sd->s_count));
  93. atomic_inc(&sd->s_count);
  94. }
  95. return sd;
  96. }
  97. static inline void sysfs_put(struct sysfs_dirent * sd)
  98. {
  99. if (sd && atomic_dec_and_test(&sd->s_count))
  100. release_sysfs_dirent(sd);
  101. }