sysfs.h 3.5 KB

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