sysfs.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. extern struct vfsmount * sysfs_mount;
  2. extern kmem_cache_t *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 void 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. static inline struct kobject * to_kobj(struct dentry * dentry)
  28. {
  29. struct sysfs_dirent * sd = dentry->d_fsdata;
  30. return ((struct kobject *) sd->s_element);
  31. }
  32. static inline struct attribute * to_attr(struct dentry * dentry)
  33. {
  34. struct sysfs_dirent * sd = dentry->d_fsdata;
  35. return ((struct attribute *) sd->s_element);
  36. }
  37. static inline struct bin_attribute * to_bin_attr(struct dentry * dentry)
  38. {
  39. struct sysfs_dirent * sd = dentry->d_fsdata;
  40. return ((struct bin_attribute *) sd->s_element);
  41. }
  42. static inline struct kobject *sysfs_get_kobject(struct dentry *dentry)
  43. {
  44. struct kobject * kobj = NULL;
  45. spin_lock(&dcache_lock);
  46. if (!d_unhashed(dentry)) {
  47. struct sysfs_dirent * sd = dentry->d_fsdata;
  48. if (sd->s_type & SYSFS_KOBJ_LINK) {
  49. struct sysfs_symlink * sl = sd->s_element;
  50. kobj = kobject_get(sl->target_kobj);
  51. } else
  52. kobj = kobject_get(sd->s_element);
  53. }
  54. spin_unlock(&dcache_lock);
  55. return kobj;
  56. }
  57. static inline void release_sysfs_dirent(struct sysfs_dirent * sd)
  58. {
  59. if (sd->s_type & SYSFS_KOBJ_LINK) {
  60. struct sysfs_symlink * sl = sd->s_element;
  61. kfree(sl->link_name);
  62. kobject_put(sl->target_kobj);
  63. kfree(sl);
  64. }
  65. kfree(sd->s_iattr);
  66. kmem_cache_free(sysfs_dir_cachep, sd);
  67. }
  68. static inline struct sysfs_dirent * sysfs_get(struct sysfs_dirent * sd)
  69. {
  70. if (sd) {
  71. WARN_ON(!atomic_read(&sd->s_count));
  72. atomic_inc(&sd->s_count);
  73. }
  74. return sd;
  75. }
  76. static inline void sysfs_put(struct sysfs_dirent * sd)
  77. {
  78. if (atomic_dec_and_test(&sd->s_count))
  79. release_sysfs_dirent(sd);
  80. }