sysfs.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 void sysfs_link_sibling(struct sysfs_dirent *sd);
  50. extern void sysfs_unlink_sibling(struct sysfs_dirent *sd);
  51. extern struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd);
  52. extern void sysfs_put_active(struct sysfs_dirent *sd);
  53. extern struct sysfs_dirent *sysfs_get_active_two(struct sysfs_dirent *sd);
  54. extern void sysfs_put_active_two(struct sysfs_dirent *sd);
  55. extern void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt,
  56. struct sysfs_dirent *parent_sd);
  57. extern void sysfs_add_one(struct sysfs_addrm_cxt *acxt,
  58. struct sysfs_dirent *sd);
  59. extern void sysfs_remove_one(struct sysfs_addrm_cxt *acxt,
  60. struct sysfs_dirent *sd);
  61. extern int sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt);
  62. extern void sysfs_delete_inode(struct inode *inode);
  63. extern void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode);
  64. extern struct inode * sysfs_get_inode(struct sysfs_dirent *sd);
  65. extern void sysfs_instantiate(struct dentry *dentry, struct inode *inode);
  66. extern void release_sysfs_dirent(struct sysfs_dirent * sd);
  67. extern struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
  68. const unsigned char *name);
  69. extern struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
  70. const unsigned char *name);
  71. extern struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode,
  72. int type);
  73. extern int sysfs_add_file(struct sysfs_dirent *dir_sd,
  74. const struct attribute *attr, int type);
  75. extern int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name);
  76. extern struct sysfs_dirent *sysfs_find(struct sysfs_dirent *dir, const char * name);
  77. extern int sysfs_create_subdir(struct kobject *kobj, const char *name,
  78. struct sysfs_dirent **p_sd);
  79. extern void sysfs_remove_subdir(struct sysfs_dirent *sd);
  80. extern int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
  81. extern spinlock_t sysfs_assoc_lock;
  82. extern struct mutex sysfs_mutex;
  83. extern struct super_block * sysfs_sb;
  84. extern const struct file_operations sysfs_dir_operations;
  85. extern const struct file_operations sysfs_file_operations;
  86. extern const struct file_operations bin_fops;
  87. extern const struct inode_operations sysfs_dir_inode_operations;
  88. extern const struct inode_operations sysfs_symlink_inode_operations;
  89. static inline unsigned int sysfs_type(struct sysfs_dirent *sd)
  90. {
  91. return sd->s_flags & SYSFS_TYPE_MASK;
  92. }
  93. static inline struct sysfs_dirent * sysfs_get(struct sysfs_dirent * sd)
  94. {
  95. if (sd) {
  96. WARN_ON(!atomic_read(&sd->s_count));
  97. atomic_inc(&sd->s_count);
  98. }
  99. return sd;
  100. }
  101. static inline void sysfs_put(struct sysfs_dirent * sd)
  102. {
  103. if (sd && atomic_dec_and_test(&sd->s_count))
  104. release_sysfs_dirent(sd);
  105. }
  106. static inline int sysfs_is_shadowed_inode(struct inode *inode)
  107. {
  108. return S_ISDIR(inode->i_mode) && inode->i_op->follow_link;
  109. }