sysfs.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. extern struct vfsmount * sysfs_mount;
  2. extern struct kmem_cache *sysfs_dir_cachep;
  3. extern struct inode * sysfs_new_inode(mode_t mode, struct sysfs_dirent *);
  4. extern int sysfs_create(struct dentry *, int mode, int (*init)(struct inode *));
  5. extern int sysfs_dirent_exist(struct sysfs_dirent *, const unsigned char *);
  6. extern int sysfs_make_dirent(struct sysfs_dirent *, struct dentry *, void *,
  7. umode_t, int);
  8. extern int sysfs_add_file(struct dentry *, const struct attribute *, int);
  9. extern int sysfs_hash_and_remove(struct dentry * dir, const char * name);
  10. extern struct sysfs_dirent *sysfs_find(struct sysfs_dirent *dir, const char * name);
  11. extern int sysfs_create_subdir(struct kobject *, const char *, struct dentry **);
  12. extern void sysfs_remove_subdir(struct dentry *);
  13. extern const unsigned char * sysfs_get_name(struct sysfs_dirent *sd);
  14. extern void sysfs_drop_dentry(struct sysfs_dirent *sd, struct dentry *parent);
  15. extern int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
  16. extern struct rw_semaphore sysfs_rename_sem;
  17. extern struct super_block * sysfs_sb;
  18. extern const struct file_operations sysfs_dir_operations;
  19. extern const struct file_operations sysfs_file_operations;
  20. extern const struct file_operations bin_fops;
  21. extern struct inode_operations sysfs_dir_inode_operations;
  22. extern struct inode_operations sysfs_symlink_inode_operations;
  23. struct sysfs_symlink {
  24. char * link_name;
  25. struct kobject * target_kobj;
  26. };
  27. struct sysfs_buffer {
  28. struct list_head associates;
  29. size_t count;
  30. loff_t pos;
  31. char * page;
  32. struct sysfs_ops * ops;
  33. struct semaphore sem;
  34. int orphaned;
  35. int needs_read_fill;
  36. int event;
  37. };
  38. struct sysfs_buffer_collection {
  39. struct list_head associates;
  40. };
  41. static inline struct kobject * to_kobj(struct dentry * dentry)
  42. {
  43. struct sysfs_dirent * sd = dentry->d_fsdata;
  44. return ((struct kobject *) sd->s_element);
  45. }
  46. static inline struct attribute * to_attr(struct dentry * dentry)
  47. {
  48. struct sysfs_dirent * sd = dentry->d_fsdata;
  49. return ((struct attribute *) sd->s_element);
  50. }
  51. static inline struct bin_attribute * to_bin_attr(struct dentry * dentry)
  52. {
  53. struct sysfs_dirent * sd = dentry->d_fsdata;
  54. return ((struct bin_attribute *) sd->s_element);
  55. }
  56. static inline struct kobject *sysfs_get_kobject(struct dentry *dentry)
  57. {
  58. struct kobject * kobj = NULL;
  59. spin_lock(&dcache_lock);
  60. if (!d_unhashed(dentry)) {
  61. struct sysfs_dirent * sd = dentry->d_fsdata;
  62. if (sd->s_type & SYSFS_KOBJ_LINK) {
  63. struct sysfs_symlink * sl = sd->s_element;
  64. kobj = kobject_get(sl->target_kobj);
  65. } else
  66. kobj = kobject_get(sd->s_element);
  67. }
  68. spin_unlock(&dcache_lock);
  69. return kobj;
  70. }
  71. static inline void release_sysfs_dirent(struct sysfs_dirent * sd)
  72. {
  73. if (sd->s_type & SYSFS_KOBJ_LINK) {
  74. struct sysfs_symlink * sl = sd->s_element;
  75. kfree(sl->link_name);
  76. kobject_put(sl->target_kobj);
  77. kfree(sl);
  78. }
  79. kfree(sd->s_iattr);
  80. kmem_cache_free(sysfs_dir_cachep, sd);
  81. }
  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 (atomic_dec_and_test(&sd->s_count))
  93. release_sysfs_dirent(sd);
  94. }