sysfs.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. extern struct vfsmount * sysfs_mount;
  40. extern struct kmem_cache *sysfs_dir_cachep;
  41. extern struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd);
  42. extern void sysfs_put_active(struct sysfs_dirent *sd);
  43. extern struct sysfs_dirent *sysfs_get_active_two(struct sysfs_dirent *sd);
  44. extern void sysfs_put_active_two(struct sysfs_dirent *sd);
  45. extern void sysfs_deactivate(struct sysfs_dirent *sd);
  46. extern void sysfs_delete_inode(struct inode *inode);
  47. extern void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode);
  48. extern struct inode * sysfs_get_inode(struct sysfs_dirent *sd);
  49. extern void sysfs_instantiate(struct dentry *dentry, struct inode *inode);
  50. extern void release_sysfs_dirent(struct sysfs_dirent * sd);
  51. extern struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
  52. const unsigned char *name);
  53. extern struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
  54. const unsigned char *name);
  55. extern struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode,
  56. int type);
  57. extern void sysfs_attach_dirent(struct sysfs_dirent *sd,
  58. struct sysfs_dirent *parent_sd,
  59. struct dentry *dentry);
  60. extern int sysfs_add_file(struct dentry *, const struct attribute *, int);
  61. extern int sysfs_hash_and_remove(struct dentry * dir, const char * name);
  62. extern struct sysfs_dirent *sysfs_find(struct sysfs_dirent *dir, const char * name);
  63. extern int sysfs_create_subdir(struct kobject *, const char *, struct dentry **);
  64. extern void sysfs_remove_subdir(struct dentry *);
  65. extern void sysfs_drop_dentry(struct sysfs_dirent *sd);
  66. extern int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
  67. extern spinlock_t sysfs_lock;
  68. extern spinlock_t kobj_sysfs_assoc_lock;
  69. extern struct rw_semaphore sysfs_rename_sem;
  70. extern struct super_block * sysfs_sb;
  71. extern const struct file_operations sysfs_dir_operations;
  72. extern const struct file_operations sysfs_file_operations;
  73. extern const struct file_operations bin_fops;
  74. extern const struct inode_operations sysfs_dir_inode_operations;
  75. extern const struct inode_operations sysfs_symlink_inode_operations;
  76. static inline unsigned int sysfs_type(struct sysfs_dirent *sd)
  77. {
  78. return sd->s_flags & SYSFS_TYPE_MASK;
  79. }
  80. static inline struct sysfs_dirent * sysfs_get(struct sysfs_dirent * sd)
  81. {
  82. if (sd) {
  83. WARN_ON(!atomic_read(&sd->s_count));
  84. atomic_inc(&sd->s_count);
  85. }
  86. return sd;
  87. }
  88. static inline void sysfs_put(struct sysfs_dirent * sd)
  89. {
  90. if (sd && atomic_dec_and_test(&sd->s_count))
  91. release_sysfs_dirent(sd);
  92. }
  93. static inline int sysfs_is_shadowed_inode(struct inode *inode)
  94. {
  95. return S_ISDIR(inode->i_mode) && inode->i_op->follow_link;
  96. }