sysfs.h 3.9 KB

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