sysfs.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. struct rw_semaphore s_active;
  21. struct sysfs_dirent * s_parent;
  22. struct list_head s_sibling;
  23. struct list_head 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. int s_type;
  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. /*
  39. * A sysfs file which deletes another file when written to need to
  40. * write lock the s_active of the victim while its s_active is read
  41. * locked for the write operation. Tell lockdep that this is okay.
  42. */
  43. enum sysfs_s_active_class
  44. {
  45. SYSFS_S_ACTIVE_NORMAL, /* file r/w access, etc - default */
  46. SYSFS_S_ACTIVE_DEACTIVATE, /* file deactivation */
  47. };
  48. extern struct vfsmount * sysfs_mount;
  49. extern struct kmem_cache *sysfs_dir_cachep;
  50. extern struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd);
  51. extern void sysfs_put_active(struct sysfs_dirent *sd);
  52. extern struct sysfs_dirent *sysfs_get_active_two(struct sysfs_dirent *sd);
  53. extern void sysfs_put_active_two(struct sysfs_dirent *sd);
  54. extern void sysfs_deactivate(struct sysfs_dirent *sd);
  55. extern void sysfs_delete_inode(struct inode *inode);
  56. extern void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode);
  57. extern struct inode * sysfs_get_inode(struct sysfs_dirent *sd);
  58. extern void sysfs_instantiate(struct dentry *dentry, struct inode *inode);
  59. extern void release_sysfs_dirent(struct sysfs_dirent * sd);
  60. extern int sysfs_dirent_exist(struct sysfs_dirent *, const unsigned char *);
  61. extern struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode,
  62. int type);
  63. extern void sysfs_attach_dirent(struct sysfs_dirent *sd,
  64. struct sysfs_dirent *parent_sd,
  65. struct dentry *dentry);
  66. extern int sysfs_add_file(struct dentry *, const struct attribute *, int);
  67. extern int sysfs_hash_and_remove(struct dentry * dir, const char * name);
  68. extern struct sysfs_dirent *sysfs_find(struct sysfs_dirent *dir, const char * name);
  69. extern int sysfs_create_subdir(struct kobject *, const char *, struct dentry **);
  70. extern void sysfs_remove_subdir(struct dentry *);
  71. extern void sysfs_drop_dentry(struct sysfs_dirent *sd);
  72. extern int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
  73. extern spinlock_t sysfs_lock;
  74. extern spinlock_t kobj_sysfs_assoc_lock;
  75. extern struct rw_semaphore sysfs_rename_sem;
  76. extern struct super_block * sysfs_sb;
  77. extern const struct file_operations sysfs_dir_operations;
  78. extern const struct file_operations sysfs_file_operations;
  79. extern const struct file_operations bin_fops;
  80. extern const struct inode_operations sysfs_dir_inode_operations;
  81. extern const struct inode_operations sysfs_symlink_inode_operations;
  82. static inline struct sysfs_dirent * sysfs_get(struct sysfs_dirent * sd)
  83. {
  84. if (sd) {
  85. WARN_ON(!atomic_read(&sd->s_count));
  86. atomic_inc(&sd->s_count);
  87. }
  88. return sd;
  89. }
  90. static inline void sysfs_put(struct sysfs_dirent * sd)
  91. {
  92. if (sd && atomic_dec_and_test(&sd->s_count))
  93. release_sysfs_dirent(sd);
  94. }
  95. static inline int sysfs_is_shadowed_inode(struct inode *inode)
  96. {
  97. return S_ISDIR(inode->i_mode) && inode->i_op->follow_link;
  98. }