kernfs-internal.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * fs/kernfs/kernfs-internal.h - kernfs internal header file
  3. *
  4. * Copyright (c) 2001-3 Patrick Mochel
  5. * Copyright (c) 2007 SUSE Linux Products GmbH
  6. * Copyright (c) 2007, 2013 Tejun Heo <teheo@suse.de>
  7. *
  8. * This file is released under the GPLv2.
  9. */
  10. #ifndef __KERNFS_INTERNAL_H
  11. #define __KERNFS_INTERNAL_H
  12. #include <linux/lockdep.h>
  13. #include <linux/fs.h>
  14. #include <linux/rbtree.h>
  15. #include <linux/kernfs.h>
  16. struct sysfs_open_dirent;
  17. /* type-specific structures for sysfs_dirent->s_* union members */
  18. struct sysfs_elem_dir {
  19. unsigned long subdirs;
  20. /* children rbtree starts here and goes through sd->s_rb */
  21. struct rb_root children;
  22. };
  23. struct sysfs_elem_symlink {
  24. struct sysfs_dirent *target_sd;
  25. };
  26. struct sysfs_elem_attr {
  27. const struct kernfs_ops *ops;
  28. struct sysfs_open_dirent *open;
  29. loff_t size;
  30. };
  31. struct sysfs_inode_attrs {
  32. struct iattr ia_iattr;
  33. void *ia_secdata;
  34. u32 ia_secdata_len;
  35. };
  36. /*
  37. * sysfs_dirent - the building block of sysfs hierarchy. Each and
  38. * every sysfs node is represented by single sysfs_dirent.
  39. *
  40. * As long as s_count reference is held, the sysfs_dirent itself is
  41. * accessible. Dereferencing s_elem or any other outer entity
  42. * requires s_active reference.
  43. */
  44. struct sysfs_dirent {
  45. atomic_t s_count;
  46. atomic_t s_active;
  47. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  48. struct lockdep_map dep_map;
  49. #endif
  50. struct sysfs_dirent *s_parent;
  51. const char *s_name;
  52. struct rb_node s_rb;
  53. union {
  54. struct completion *completion;
  55. struct sysfs_dirent *removed_list;
  56. } u;
  57. const void *s_ns; /* namespace tag */
  58. unsigned int s_hash; /* ns + name hash */
  59. union {
  60. struct sysfs_elem_dir s_dir;
  61. struct sysfs_elem_symlink s_symlink;
  62. struct sysfs_elem_attr s_attr;
  63. };
  64. void *priv;
  65. unsigned short s_flags;
  66. umode_t s_mode;
  67. unsigned int s_ino;
  68. struct sysfs_inode_attrs *s_iattr;
  69. };
  70. #define SD_DEACTIVATED_BIAS INT_MIN
  71. #define SYSFS_TYPE_MASK 0x000f
  72. #define SYSFS_DIR 0x0001
  73. #define SYSFS_KOBJ_ATTR 0x0002
  74. #define SYSFS_KOBJ_LINK 0x0004
  75. #define SYSFS_COPY_NAME (SYSFS_DIR | SYSFS_KOBJ_LINK)
  76. #define SYSFS_ACTIVE_REF SYSFS_KOBJ_ATTR
  77. #define SYSFS_FLAG_MASK ~SYSFS_TYPE_MASK
  78. #define SYSFS_FLAG_REMOVED 0x0010
  79. #define SYSFS_FLAG_NS 0x0020
  80. #define SYSFS_FLAG_HAS_SEQ_SHOW 0x0040
  81. #define SYSFS_FLAG_HAS_MMAP 0x0080
  82. #define SYSFS_FLAG_LOCKDEP 0x0100
  83. static inline unsigned int sysfs_type(struct sysfs_dirent *sd)
  84. {
  85. return sd->s_flags & SYSFS_TYPE_MASK;
  86. }
  87. /*
  88. * Context structure to be used while adding/removing nodes.
  89. */
  90. struct sysfs_addrm_cxt {
  91. struct sysfs_dirent *removed;
  92. };
  93. #include "../sysfs/sysfs.h"
  94. /*
  95. * inode.c
  96. */
  97. struct inode *sysfs_get_inode(struct super_block *sb, struct sysfs_dirent *sd);
  98. void sysfs_evict_inode(struct inode *inode);
  99. int sysfs_permission(struct inode *inode, int mask);
  100. int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
  101. int sysfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
  102. struct kstat *stat);
  103. int sysfs_setxattr(struct dentry *dentry, const char *name, const void *value,
  104. size_t size, int flags);
  105. int sysfs_inode_init(void);
  106. #endif /* __KERNFS_INTERNAL_H */