sysfs.h 3.3 KB

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