Add AKAROS_TOOLCHAINS (XCC)
[akaros.git] / kern / include / tree_file.h
index 68a14af..dab14e5 100644 (file)
@@ -30,12 +30,12 @@ struct tree_filesystem;
  *   the tree.  They are never increffed, only rcu-read.
  */
 struct walk_cache {
-       spinlock_t                                      lru_lock;
-       struct list_head                        lru;
-       spinlock_t                                      ht_lock;
-       struct hash_helper                      hh;             /* parts are rcu-read */
-       struct hlist_head                       *ht;
-       struct hlist_head                       static_ht[HASH_INIT_SZ];
+       spinlock_t                      lru_lock;
+       struct list_head                lru;
+       spinlock_t                      ht_lock;
+       struct hash_helper              hh;             /* parts are rcu-read */
+       struct hlist_head               *ht;
+       struct hlist_head               static_ht[HASH_INIT_SZ];
 };
 
 /* All ops that operate on a parent have the parent qlocked.
@@ -69,19 +69,21 @@ struct tree_file_ops {
        void (*free)(struct tree_file *tf);
        void (*unlink)(struct tree_file *parent, struct tree_file *child);
        void (*lookup)(struct tree_file *parent, struct tree_file *child);
-       void (*create)(struct tree_file *parent, struct tree_file *child, int perm);
+       void (*create)(struct tree_file *parent, struct tree_file *child,
+                      int perm);
        void (*rename)(struct tree_file *tf, struct tree_file *old_parent,
-                      struct tree_file *new_parent, const char *name, int flags);
+                      struct tree_file *new_parent, const char *name,
+                      int flags);
        bool (*has_children)(struct tree_file *parent);
 };
 
 struct tree_filesystem {
-       struct walk_cache                       wc;
+       struct walk_cache               wc;
        struct tree_file_ops            tf_ops;
-       struct fs_file_ops                      fs_ops;
-       qlock_t                                         rename_mtx;
-       struct tree_file                        *root;
-       void                                            *priv;
+       struct fs_file_ops              fs_ops;
+       qlock_t                         rename_mtx;
+       struct tree_file                *root;
+       void                            *priv;
 };
 
 /* The tree_file is an fs_file (i.e. the first struct field) that exists in a
@@ -157,24 +159,25 @@ struct tree_filesystem {
  * - Qlocking multiple files that aren't parent->child requires the rename_mtx
  */
 struct tree_file {
-       struct fs_file                          file;
-       spinlock_t                                      lifetime;
-       int                                                     flags;
-       struct kref                                     kref;
-       struct rcu_head                         rcu;
-       struct tree_file                        *parent;                /* rcu protected */
-       struct hlist_node                       hash;                   /* rcu protected */
-       struct list_head                        siblings;
-       struct list_head                        children;
-       struct list_head                        lru;
-       bool                                            can_have_children;
+       struct fs_file                  file;
+       spinlock_t                      lifetime;
+       int                             flags;
+       struct kref                     kref;
+       struct rcu_head                 rcu;
+       struct tree_file                *parent;        /* rcu protected */
+       struct hlist_node               hash;           /* rcu protected */
+       struct list_head                siblings;
+       struct list_head                children;
+       struct list_head                lru;
+       bool                            can_have_children;
        struct tree_filesystem          *tfs;
 };
 
-#define TF_F_DISCONNECTED              (1 << 0)
-#define TF_F_NEGATIVE                  (1 << 1)
-#define TF_F_ON_LRU                            (1 << 2)
-#define TF_F_IS_ROOT                   (1 << 3)
+#define TF_F_DISCONNECTED      (1 << 0)
+#define TF_F_NEGATIVE          (1 << 1)
+#define TF_F_ON_LRU            (1 << 2)
+#define TF_F_IS_ROOT           (1 << 3)
+#define TF_F_HAS_BEEN_USED     (1 << 4)
 
 /* Devices can put their tree_files / fs_files whereever they want.  For now,
  * all of them will use aux.  We can make ops for this if we need it. */
@@ -200,7 +203,7 @@ static inline bool tree_file_is_dir(struct tree_file *tf)
 
 static inline bool tree_file_is_file(struct tree_file *tf)
 {
-       return tree_file_to_qid(tf).type & QTFILE ? true : false;
+       return qid_is_file(tree_file_to_qid(tf));
 }
 
 static inline bool tree_file_is_symlink(struct tree_file *tf)
@@ -262,6 +265,11 @@ size_t tree_chan_read(struct chan *c, void *ubuf, size_t n, off64_t offset);
 size_t tree_chan_write(struct chan *c, void *ubuf, size_t n, off64_t offset);
 size_t tree_chan_stat(struct chan *c, uint8_t *m_buf, size_t m_buf_sz);
 size_t tree_chan_wstat(struct chan *c, uint8_t *m_buf, size_t m_buf_sz);
+struct fs_file *tree_chan_mmap(struct chan *c, struct vm_region *vmr, int prot,
+                               int flags);
+unsigned long tree_chan_ctl(struct chan *c, int op, unsigned long a1,
+                            unsigned long a2, unsigned long a3,
+                            unsigned long a4);
 
 struct chan *tree_file_alloc_chan(struct tree_file *tf, struct dev *dev,
                                   char *name);
@@ -272,3 +280,8 @@ void tfs_frontend_for_each(struct tree_filesystem *tfs,
 void tfs_frontend_purge(struct tree_filesystem *tfs,
                         void (*cb)(struct tree_file *tf));
 void __tfs_dump(struct tree_filesystem *tfs);
+void __tfs_dump_tf(struct tree_file *tf);
+
+void tfs_lru_for_each(struct tree_filesystem *tfs, bool cb(struct tree_file *),
+                      size_t max_tfs);
+void tfs_lru_prune_neg(struct tree_filesystem *tfs);