sysfs.h 3.6 KB

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