Initial start on a user-level NFS server.
[bluesky.git] / inode.h
1 #ifndef _BLUESKY_INODE_H
2 #define _BLUESKY_INODE_H
3
4 #include <stdint.h>
5 #include <glib.h>
6
7 /* File types.  The numeric values are chosen to match with those used in
8  * NFSv3. */
9 enum BlueSkyFileType {
10     BLUESKY_INVALID = 0,
11     BLUESKY_REGULAR = 1,
12     BLUESKY_DIRECTORY = 2,
13     BLUESKY_BLOCK = 3,
14     BLUESKY_CHARACTER = 4,
15     BLUESKY_SYMLINK = 5,
16     BLUESKY_SOCKET = 6,
17     BLUESKY_FIFO = 7,
18 };
19
20 /* Filesystem state.  Each filesystem which is exported is represented by a
21  * single bluesky_fs structure in memory. */
22 typedef struct {
23     GMutex *lock;
24
25     gchar *name;                /* Descriptive name for the filesystem */
26     GHashTable *inodes;         /* Cached inodes */
27     uint64_t next_inum;         /* Next available inode for allocation */
28 } BlueSkyFS;
29
30 /* Timestamp, measured in microseconds since the Unix epoch. */
31 typedef int64_t bluesky_time;
32
33 /* In-memory representation of an inode within a Blue Sky server.  This
34  * corresponds roughly with information that is committed to persistent
35  * storage. */
36 typedef struct {
37     gint refcnt;                /* May be accessed atomically without lock */
38     GMutex *lock;
39
40     int type;
41     uint32_t mode;
42     uint32_t uid, gid;
43     uint32_t nlink;
44
45     /* Rather than track an inode number and generation number, we will simply
46      * never re-use a fileid after a file is deleted.  64 bits should be enough
47      * that we don't exhaust the identifier space. */
48     uint64_t inum;
49
50     uint64_t change_count;      /* Incremented each with each change made */
51     int64_t atime;              /* Microseconds since the Unix epoch */
52     int64_t ctime;
53     int64_t mtime;
54     int64_t ntime;              /* "new time": time object was created */
55
56     /* File-specific fields */
57     uint64_t size;
58
59     /* Directory-specific fields */
60     GSequence *dirents;
61 } BlueSkyInode;
62
63 /* A directory entry.  The name is UTF-8 and is a freshly-allocated string.
64  * The name is hashed to a 64-bit value, and the directory entries are sorted
65  * by hash value (the hash value can then be used as a cookie for resuming a
66  * READDIR call). */
67 typedef struct {
68     gchar *name;
69     uint64_t hash;
70     uint64_t inum;
71 } BlueSkyDirent ;
72
73 uint64_t bluesky_directory_hash(gchar *name);
74
75 #endif