Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * kernfs.h - pseudo filesystem decoupled from vfs locking
  3.  *
  4.  * This file is released under the GPLv2.
  5.  */
  6.  
  7. #ifndef __LINUX_KERNFS_H
  8. #define __LINUX_KERNFS_H
  9.  
  10. #include <linux/kernel.h>
  11. #include <linux/err.h>
  12. #include <linux/list.h>
  13. #include <linux/mutex.h>
  14. #include <linux/idr.h>
  15. #include <linux/lockdep.h>
  16. #include <linux/rbtree.h>
  17. #include <linux/atomic.h>
  18. #include <linux/wait.h>
  19.  
  20. struct file;
  21. struct dentry;
  22. struct iattr;
  23. struct seq_file;
  24. struct vm_area_struct;
  25. struct super_block;
  26. struct file_system_type;
  27.  
  28. struct kernfs_open_node;
  29. struct kernfs_iattrs;
  30.  
  31. enum kernfs_node_type {
  32.         KERNFS_DIR              = 0x0001,
  33.         KERNFS_FILE             = 0x0002,
  34.         KERNFS_LINK             = 0x0004,
  35. };
  36.  
  37. #define KERNFS_TYPE_MASK        0x000f
  38. #define KERNFS_FLAG_MASK        ~KERNFS_TYPE_MASK
  39.  
  40. enum kernfs_node_flag {
  41.         KERNFS_ACTIVATED        = 0x0010,
  42.         KERNFS_NS               = 0x0020,
  43.         KERNFS_HAS_SEQ_SHOW     = 0x0040,
  44.         KERNFS_HAS_MMAP         = 0x0080,
  45.         KERNFS_LOCKDEP          = 0x0100,
  46.         KERNFS_SUICIDAL         = 0x0400,
  47.         KERNFS_SUICIDED         = 0x0800,
  48.         KERNFS_EMPTY_DIR        = 0x1000,
  49. };
  50.  
  51. /* @flags for kernfs_create_root() */
  52. enum kernfs_root_flag {
  53.         /*
  54.          * kernfs_nodes are created in the deactivated state and invisible.
  55.          * They require explicit kernfs_activate() to become visible.  This
  56.          * can be used to make related nodes become visible atomically
  57.          * after all nodes are created successfully.
  58.          */
  59.         KERNFS_ROOT_CREATE_DEACTIVATED          = 0x0001,
  60.  
  61.         /*
  62.          * For regular flies, if the opener has CAP_DAC_OVERRIDE, open(2)
  63.          * succeeds regardless of the RW permissions.  sysfs had an extra
  64.          * layer of enforcement where open(2) fails with -EACCES regardless
  65.          * of CAP_DAC_OVERRIDE if the permission doesn't have the
  66.          * respective read or write access at all (none of S_IRUGO or
  67.          * S_IWUGO) or the respective operation isn't implemented.  The
  68.          * following flag enables that behavior.
  69.          */
  70.         KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK       = 0x0002,
  71. };
  72.  
  73. /* type-specific structures for kernfs_node union members */
  74. struct kernfs_elem_dir {
  75.         unsigned long           subdirs;
  76.         /* children rbtree starts here and goes through kn->rb */
  77.         struct rb_root          children;
  78.  
  79.         /*
  80.          * The kernfs hierarchy this directory belongs to.  This fits
  81.          * better directly in kernfs_node but is here to save space.
  82.          */
  83.         struct kernfs_root      *root;
  84. };
  85.  
  86. struct kernfs_elem_symlink {
  87.         struct kernfs_node      *target_kn;
  88. };
  89.  
  90. struct kernfs_elem_attr {
  91.         const struct kernfs_ops *ops;
  92.         struct kernfs_open_node *open;
  93.         loff_t                  size;
  94.         struct kernfs_node      *notify_next;   /* for kernfs_notify() */
  95. };
  96.  
  97. /*
  98.  * kernfs_node - the building block of kernfs hierarchy.  Each and every
  99.  * kernfs node is represented by single kernfs_node.  Most fields are
  100.  * private to kernfs and shouldn't be accessed directly by kernfs users.
  101.  *
  102.  * As long as s_count reference is held, the kernfs_node itself is
  103.  * accessible.  Dereferencing elem or any other outer entity requires
  104.  * active reference.
  105.  */
  106. struct kernfs_node {
  107.         atomic_t                count;
  108.         atomic_t                active;
  109. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  110.         struct lockdep_map      dep_map;
  111. #endif
  112.         /*
  113.          * Use kernfs_get_parent() and kernfs_name/path() instead of
  114.          * accessing the following two fields directly.  If the node is
  115.          * never moved to a different parent, it is safe to access the
  116.          * parent directly.
  117.          */
  118.         struct kernfs_node      *parent;
  119.         const char              *name;
  120.  
  121.         struct rb_node          rb;
  122.  
  123.         const void              *ns;    /* namespace tag */
  124.         unsigned int            hash;   /* ns + name hash */
  125.         union {
  126.                 struct kernfs_elem_dir          dir;
  127.                 struct kernfs_elem_symlink      symlink;
  128.                 struct kernfs_elem_attr         attr;
  129.         };
  130.  
  131.         void                    *priv;
  132.  
  133.         unsigned short          flags;
  134.         umode_t                 mode;
  135.         unsigned int            ino;
  136.         struct kernfs_iattrs    *iattr;
  137. };
  138.  
  139.  
  140. #endif  /* __LINUX_KERNFS_H */
  141.