1/*
2 * Copyright 2016, NICTA
3 *
4 * This software may be distributed and modified according to the terms of
5 * the GNU General Public License version 2. Note that NO WARRANTY is provided.
6 * See "LICENSE_GPLv2.txt" for details.
7 *
8 * @TAG(NICTA_GPL)
9 */
10
11#ifndef ABSTRACT_H__
12#define ABSTRACT_H__
13
14#include <adt.h>
15
16struct Ext2State {
17	void* priv;
18	struct semaphore iop_lock;
19	// struct semaphore sop_lock;
20	// struct semaphore aop_lock;
21	struct super_block* sb;
22};
23
24/* include vfs.h */
25typedef void VfsIWriteResult;
26typedef void VfsIWriteArgs;
27
28typedef void VfsISeekResult;
29typedef void VfsISeekArgs;
30
31typedef void VfsIReadlinkResult;
32typedef void VfsIReadlinkArgs;
33
34typedef void VfsIReadResult;
35typedef void VfsIReadArgs;
36
37typedef void VfsIPutLinkResult;
38typedef void VfsIPutLinkArgs;
39
40typedef void VfsIOpenResult;
41typedef void VfsIOpenArgs;
42
43typedef void VfsIMmapResult;
44typedef void VfsIMmapArgs;
45
46typedef void VfsIFsyncResult;
47typedef void VfsIFsyncArgs;
48
49typedef void VfsIFollowLinkResult;
50typedef void VfsIFollowLinkArgs;
51
52typedef void VfsISetAttrResult;
53typedef void VfsISetAttrArgs;
54
55// really all of type `enum untyped_func_enum' but can't forward declare enums (because size unknown)
56struct cogent_inode_operations {
57	int create; // Option ((SysState, FsState, VfsInode, CString!, VfsMode) -> RR (SysState, FsState, VfsInode) VfsInode U32),
58  	int link; // Option ((SysState, FsState, VfsInode, VfsInode, CString!) -> RR (SysState, FsState, VfsInode, VfsInode) () U32),
59	int unlink; // Option ((SysState, FsState, VfsInode, VfsInode, CString!) -> RR (SysState, FsState, VfsInode, VfsInode) () U32),
60	int symlink; // Option ((SysState, FsState, VfsInode, CString!) -> RR (SysState, FsState, VfsInode) VfsInode U32),
61	int mkdir; // Option ((SysState, FsState, VfsInode, CString!, VfsMode) -> RR (SysState, FsState, VfsInode) VfsInode U32),
62	int rmdir; // Option ((SysState, FsState, VfsInode, VfsInode, CString!) -> RR (SysState, FsState, VfsInode, VfsInode) () U32),
63	int rename; // Option ((SysState, FsState, VfsRenameContext) -> RR (SysState, FsState, VfsRenameContext) () U32),
64	int mknod; // Option ((SysState, FsState, VfsInode, CString!, VfsMode, #VfsDevice) -> RR (SysState, FsState, VfsInode) VfsInode U32),
65
66	int readlink; // Option (VfsIReadlinkArgs -> VfsIReadlinkResult),
67	int followlink; // Option (VfsIFollowLinkArgs -> VfsIFollowLinkResult),
68	int putlink; // Option (VfsIPutLinkArgs -> VfsIPutLinkResult)
69};
70
71struct cogent_file_operations {
72	int iterate; // Option ((#{ex: SysState, state: FsState, parent_inode: VfsInode, dirctx: VfsDirContext}) -> RR #{ex: SysState, state: FsState, parent_inode: VfsInode, dirctx: VfsDirContext} () U32),
73
74	// the rest are bools
75	int llseek; // Option (VfsISeekArgs -> VfsISeekResult),
76	int open; // Option (VfsIOpenArgs -> VfsIOpenResult),
77	int mmap; // Option (VfsIMmapArgs -> VfsIMmapResult),
78	int fsync; // Option (VfsIFsyncArgs -> VfsIFsyncResult),
79
80	// these two are special -- they are essentially bools; if we have these set,
81	// then we setup a LOT more Linux VFS function pointers (ie read_iter, etc).
82	// we also setup address_space_operations if one of these are set.
83	//
84	int read; // Option (VfsIReadArgs -> VfsIReadResult),
85	int write; // Option (VfsIWriteArgs -> VfsIWriteResult)
86};
87/* end include vfs.h */
88
89struct VfsInodeAbstract {
90	struct inode inode_lin;
91
92	// these ones, as opposed to the struct inode ones,
93	// NOT const, they are ours to modify. each inode
94	// gets their own set.
95	//
96	// we don't cast directly since the inode ops may
97	// point elsewhere and we don't want to overwrite them.
98	struct inode_operations iops;
99	struct cogent_inode_operations cogent_iops; // this is NOT a cogent type but records its values (otherwise recursive types?)
100
101	struct file_operations fops;
102	struct cogent_file_operations cogent_fops;
103};
104
105typedef struct VfsInodeAbstract VfsInodeAbstract;
106
107typedef struct buffer_head OSBuffer;
108typedef struct Ext2State SysState;
109typedef struct Ext2State Ext2State;
110typedef struct dir_context OSDirContext;
111typedef dev_t VfsDevice;
112
113typedef struct ubi_volume_desc UbiVol;
114
115typedef struct page OSPage;
116
117typedef struct page OSPageBuffer;
118
119typedef struct address_space VfsMemoryMap;
120
121typedef void File;
122
123typedef void VfsStat;
124typedef void VfsIattr;
125
126#define likely(x)       __builtin_expect(!!(x), 1)
127#define unlikely(x)     __builtin_expect(!!(x), 0)
128
129void *cogent_malloc(size_t sz);
130void *cogent_calloc(int n, size_t sz);
131void cogent_free(void *s);
132void cogent_malloc_freeall(void);
133
134#endif  /* ABSTRACT_H__ */
135