sysfs.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. struct sysfs_dirent {
  2. atomic_t s_count;
  3. struct sysfs_dirent * s_parent;
  4. struct list_head s_sibling;
  5. struct list_head s_children;
  6. void * s_element;
  7. int s_type;
  8. umode_t s_mode;
  9. ino_t s_ino;
  10. struct dentry * s_dentry;
  11. struct iattr * s_iattr;
  12. atomic_t s_event;
  13. };
  14. extern struct vfsmount * sysfs_mount;
  15. extern struct kmem_cache *sysfs_dir_cachep;
  16. extern void sysfs_delete_inode(struct inode *inode);
  17. extern struct inode * sysfs_new_inode(mode_t mode, struct sysfs_dirent *);
  18. extern int sysfs_create(struct dentry *, int mode, int (*init)(struct inode *));
  19. extern void release_sysfs_dirent(struct sysfs_dirent * sd);
  20. extern int sysfs_dirent_exist(struct sysfs_dirent *, const unsigned char *);
  21. extern struct sysfs_dirent *sysfs_new_dirent(void *element, umode_t mode,
  22. int type);
  23. extern void sysfs_attach_dirent(struct sysfs_dirent *sd,
  24. struct sysfs_dirent *parent_sd,
  25. struct dentry *dentry);
  26. extern int sysfs_add_file(struct dentry *, const struct attribute *, int);
  27. extern int sysfs_hash_and_remove(struct dentry * dir, const char * name);
  28. extern struct sysfs_dirent *sysfs_find(struct sysfs_dirent *dir, const char * name);
  29. extern int sysfs_create_subdir(struct kobject *, const char *, struct dentry **);
  30. extern void sysfs_remove_subdir(struct dentry *);
  31. extern const unsigned char * sysfs_get_name(struct sysfs_dirent *sd);
  32. extern void sysfs_drop_dentry(struct sysfs_dirent *sd, struct dentry *parent);
  33. extern int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
  34. extern spinlock_t sysfs_lock;
  35. extern struct rw_semaphore sysfs_rename_sem;
  36. extern struct super_block * sysfs_sb;
  37. extern const struct file_operations sysfs_dir_operations;
  38. extern const struct file_operations sysfs_file_operations;
  39. extern const struct file_operations bin_fops;
  40. extern const struct inode_operations sysfs_dir_inode_operations;
  41. extern const struct inode_operations sysfs_symlink_inode_operations;
  42. struct sysfs_symlink {
  43. char * link_name;
  44. struct kobject * target_kobj;
  45. };
  46. struct sysfs_buffer {
  47. struct list_head associates;
  48. size_t count;
  49. loff_t pos;
  50. char * page;
  51. struct sysfs_ops * ops;
  52. struct semaphore sem;
  53. int orphaned;
  54. int needs_read_fill;
  55. int event;
  56. };
  57. struct sysfs_buffer_collection {
  58. struct list_head associates;
  59. };
  60. static inline struct kobject * to_kobj(struct dentry * dentry)
  61. {
  62. struct sysfs_dirent * sd = dentry->d_fsdata;
  63. return ((struct kobject *) sd->s_element);
  64. }
  65. static inline struct attribute * to_attr(struct dentry * dentry)
  66. {
  67. struct sysfs_dirent * sd = dentry->d_fsdata;
  68. return ((struct attribute *) sd->s_element);
  69. }
  70. static inline struct bin_attribute * to_bin_attr(struct dentry * dentry)
  71. {
  72. struct sysfs_dirent * sd = dentry->d_fsdata;
  73. return ((struct bin_attribute *) sd->s_element);
  74. }
  75. static inline struct kobject *sysfs_get_kobject(struct dentry *dentry)
  76. {
  77. struct kobject * kobj = NULL;
  78. spin_lock(&dcache_lock);
  79. if (!d_unhashed(dentry)) {
  80. struct sysfs_dirent * sd = dentry->d_fsdata;
  81. if (sd->s_type & SYSFS_KOBJ_LINK) {
  82. struct sysfs_symlink * sl = sd->s_element;
  83. kobj = kobject_get(sl->target_kobj);
  84. } else
  85. kobj = kobject_get(sd->s_element);
  86. }
  87. spin_unlock(&dcache_lock);
  88. return kobj;
  89. }
  90. static inline struct sysfs_dirent * sysfs_get(struct sysfs_dirent * sd)
  91. {
  92. if (sd) {
  93. WARN_ON(!atomic_read(&sd->s_count));
  94. atomic_inc(&sd->s_count);
  95. }
  96. return sd;
  97. }
  98. static inline void sysfs_put(struct sysfs_dirent * sd)
  99. {
  100. if (sd && atomic_dec_and_test(&sd->s_count))
  101. release_sysfs_dirent(sd);
  102. }
  103. static inline int sysfs_is_shadowed_inode(struct inode *inode)
  104. {
  105. return S_ISDIR(inode->i_mode) && inode->i_op->follow_link;
  106. }