sysfs.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. struct sysfs_dirent {
  14. atomic_t s_count;
  15. struct sysfs_dirent * s_parent;
  16. struct list_head s_sibling;
  17. struct list_head s_children;
  18. const char * s_name;
  19. union {
  20. struct sysfs_elem_dir dir;
  21. struct sysfs_elem_symlink symlink;
  22. struct sysfs_elem_attr attr;
  23. struct sysfs_elem_bin_attr bin_attr;
  24. } s_elem;
  25. int s_type;
  26. umode_t s_mode;
  27. ino_t s_ino;
  28. struct dentry * s_dentry;
  29. struct iattr * s_iattr;
  30. atomic_t s_event;
  31. };
  32. extern struct vfsmount * sysfs_mount;
  33. extern struct kmem_cache *sysfs_dir_cachep;
  34. extern void sysfs_delete_inode(struct inode *inode);
  35. extern struct inode * sysfs_new_inode(mode_t mode, struct sysfs_dirent *);
  36. extern int sysfs_create(struct dentry *, int mode, int (*init)(struct inode *));
  37. extern void release_sysfs_dirent(struct sysfs_dirent * sd);
  38. extern int sysfs_dirent_exist(struct sysfs_dirent *, const unsigned char *);
  39. extern struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode,
  40. int type);
  41. extern void sysfs_attach_dirent(struct sysfs_dirent *sd,
  42. struct sysfs_dirent *parent_sd,
  43. struct dentry *dentry);
  44. extern int sysfs_add_file(struct dentry *, const struct attribute *, int);
  45. extern int sysfs_hash_and_remove(struct dentry * dir, const char * name);
  46. extern struct sysfs_dirent *sysfs_find(struct sysfs_dirent *dir, const char * name);
  47. extern int sysfs_create_subdir(struct kobject *, const char *, struct dentry **);
  48. extern void sysfs_remove_subdir(struct dentry *);
  49. extern void sysfs_drop_dentry(struct sysfs_dirent *sd, struct dentry *parent);
  50. extern int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
  51. extern spinlock_t sysfs_lock;
  52. extern spinlock_t kobj_sysfs_assoc_lock;
  53. extern struct rw_semaphore sysfs_rename_sem;
  54. extern struct super_block * sysfs_sb;
  55. extern const struct file_operations sysfs_dir_operations;
  56. extern const struct file_operations sysfs_file_operations;
  57. extern const struct file_operations bin_fops;
  58. extern const struct inode_operations sysfs_dir_inode_operations;
  59. extern const struct inode_operations sysfs_symlink_inode_operations;
  60. struct sysfs_buffer {
  61. struct list_head associates;
  62. size_t count;
  63. loff_t pos;
  64. char * page;
  65. struct sysfs_ops * ops;
  66. struct semaphore sem;
  67. int orphaned;
  68. int needs_read_fill;
  69. int event;
  70. };
  71. struct sysfs_buffer_collection {
  72. struct list_head associates;
  73. };
  74. static inline struct kobject * to_kobj(struct dentry * dentry)
  75. {
  76. struct sysfs_dirent * sd = dentry->d_fsdata;
  77. return sd->s_elem.dir.kobj;
  78. }
  79. static inline struct kobject *sysfs_get_kobject(struct dentry *dentry)
  80. {
  81. struct kobject * kobj = NULL;
  82. spin_lock(&dcache_lock);
  83. if (!d_unhashed(dentry)) {
  84. struct sysfs_dirent * sd = dentry->d_fsdata;
  85. if (sd->s_type & SYSFS_KOBJ_LINK)
  86. sd = sd->s_elem.symlink.target_sd;
  87. kobj = kobject_get(sd->s_elem.dir.kobj);
  88. }
  89. spin_unlock(&dcache_lock);
  90. return kobj;
  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. }