sysfs.h 3.6 KB

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