sysfs.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * fs/sysfs/sysfs.h - sysfs internal header file
  3. *
  4. * Copyright (c) 2001-3 Patrick Mochel
  5. * Copyright (c) 2007 SUSE Linux Products GmbH
  6. * Copyright (c) 2007 Tejun Heo <teheo@suse.de>
  7. *
  8. * This file is released under the GPLv2.
  9. */
  10. struct sysfs_open_dirent;
  11. /* type-specific structures for sysfs_dirent->s_* union members */
  12. struct sysfs_elem_dir {
  13. struct kobject *kobj;
  14. /* children list starts here and goes through sd->s_sibling */
  15. struct sysfs_dirent *children;
  16. };
  17. struct sysfs_elem_symlink {
  18. struct sysfs_dirent *target_sd;
  19. };
  20. struct sysfs_elem_attr {
  21. struct attribute *attr;
  22. struct sysfs_open_dirent *open;
  23. };
  24. struct sysfs_elem_bin_attr {
  25. struct bin_attribute *bin_attr;
  26. };
  27. /*
  28. * sysfs_dirent - the building block of sysfs hierarchy. Each and
  29. * every sysfs node is represented by single sysfs_dirent.
  30. *
  31. * As long as s_count reference is held, the sysfs_dirent itself is
  32. * accessible. Dereferencing s_elem or any other outer entity
  33. * requires s_active reference.
  34. */
  35. struct sysfs_dirent {
  36. atomic_t s_count;
  37. atomic_t s_active;
  38. struct sysfs_dirent *s_parent;
  39. struct sysfs_dirent *s_sibling;
  40. const char *s_name;
  41. union {
  42. struct sysfs_elem_dir s_dir;
  43. struct sysfs_elem_symlink s_symlink;
  44. struct sysfs_elem_attr s_attr;
  45. struct sysfs_elem_bin_attr s_bin_attr;
  46. };
  47. unsigned int s_flags;
  48. ino_t s_ino;
  49. umode_t s_mode;
  50. struct iattr *s_iattr;
  51. };
  52. #define SD_DEACTIVATED_BIAS INT_MIN
  53. #define SYSFS_TYPE_MASK 0x00ff
  54. #define SYSFS_DIR 0x0001
  55. #define SYSFS_KOBJ_ATTR 0x0002
  56. #define SYSFS_KOBJ_BIN_ATTR 0x0004
  57. #define SYSFS_KOBJ_LINK 0x0008
  58. #define SYSFS_COPY_NAME (SYSFS_DIR | SYSFS_KOBJ_LINK)
  59. #define SYSFS_FLAG_MASK ~SYSFS_TYPE_MASK
  60. #define SYSFS_FLAG_REMOVED 0x0200
  61. static inline unsigned int sysfs_type(struct sysfs_dirent *sd)
  62. {
  63. return sd->s_flags & SYSFS_TYPE_MASK;
  64. }
  65. /*
  66. * Context structure to be used while adding/removing nodes.
  67. */
  68. struct sysfs_addrm_cxt {
  69. struct sysfs_dirent *parent_sd;
  70. struct inode *parent_inode;
  71. struct sysfs_dirent *removed;
  72. int cnt;
  73. };
  74. /*
  75. * mount.c
  76. */
  77. extern struct sysfs_dirent sysfs_root;
  78. extern struct super_block *sysfs_sb;
  79. extern struct kmem_cache *sysfs_dir_cachep;
  80. /*
  81. * dir.c
  82. */
  83. extern struct mutex sysfs_mutex;
  84. extern struct mutex sysfs_rename_mutex;
  85. extern spinlock_t sysfs_assoc_lock;
  86. extern const struct file_operations sysfs_dir_operations;
  87. extern const struct inode_operations sysfs_dir_inode_operations;
  88. struct dentry *sysfs_get_dentry(struct sysfs_dirent *sd);
  89. struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd);
  90. void sysfs_put_active(struct sysfs_dirent *sd);
  91. struct sysfs_dirent *sysfs_get_active_two(struct sysfs_dirent *sd);
  92. void sysfs_put_active_two(struct sysfs_dirent *sd);
  93. void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt,
  94. struct sysfs_dirent *parent_sd);
  95. int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd);
  96. void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd);
  97. void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt);
  98. struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
  99. const unsigned char *name);
  100. struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd,
  101. const unsigned char *name);
  102. struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type);
  103. void release_sysfs_dirent(struct sysfs_dirent *sd);
  104. int sysfs_create_subdir(struct kobject *kobj, const char *name,
  105. struct sysfs_dirent **p_sd);
  106. void sysfs_remove_subdir(struct sysfs_dirent *sd);
  107. static inline struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd)
  108. {
  109. if (sd) {
  110. WARN_ON(!atomic_read(&sd->s_count));
  111. atomic_inc(&sd->s_count);
  112. }
  113. return sd;
  114. }
  115. static inline void sysfs_put(struct sysfs_dirent *sd)
  116. {
  117. if (sd && atomic_dec_and_test(&sd->s_count))
  118. release_sysfs_dirent(sd);
  119. }
  120. /*
  121. * inode.c
  122. */
  123. struct inode *sysfs_get_inode(struct sysfs_dirent *sd);
  124. int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
  125. int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name);
  126. int sysfs_inode_init(void);
  127. /*
  128. * file.c
  129. */
  130. extern const struct file_operations sysfs_file_operations;
  131. int sysfs_add_file(struct sysfs_dirent *dir_sd,
  132. const struct attribute *attr, int type);
  133. /*
  134. * bin.c
  135. */
  136. extern const struct file_operations bin_fops;
  137. /*
  138. * symlink.c
  139. */
  140. extern const struct inode_operations sysfs_symlink_inode_operations;