sysfs.h 3.6 KB

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