ec90757065baae963840ac27b1ad0588a9332d3f
[bluesky.git] / inode.c
1 /* Blue Sky: File Systems in the Cloud
2  *
3  * Copyright (C) 2009  The Regents of the University of California
4  * Written by Michael Vrable <mvrable@cs.ucsd.edu>
5  *
6  * TODO: Licensing
7  */
8
9 #include <stdint.h>
10 #include <glib.h>
11
12 #include "bluesky.h"
13
14 /* Core filesystem.  Different proxies, such as the NFSv3 one, interface to
15  * this, but the core actually tracks the data which is stored.  So far we just
16  * implement an in-memory filesystem, but eventually this will be state which
17  * is persisted to the cloud. */
18
19 /* Return the current time, in microseconds since the epoch. */
20 int64_t bluesky_get_current_time()
21 {
22     GTimeVal t;
23     g_get_current_time(&t);
24     return t.tv_sec * 1000000 + t.tv_usec;
25 }
26
27 /* Allocate a fresh inode number which has not been used before within a
28  * filesystem. */
29 uint64_t bluesky_fs_alloc_inode(BlueSkyFS *fs)
30 {
31     uint64_t inum;
32
33     g_mutex_lock(fs->lock);
34     inum = fs->next_inum;
35     fs->next_inum++;
36     g_mutex_unlock(fs->lock);
37
38     return inum;
39 }
40
41 BlueSkyInode *bluesky_new_inode(uint64_t inum)
42 {
43     BlueSkyInode *i = g_new0(BlueSkyInode, 1);
44
45     i->lock = g_mutex_new();
46     i->inum = inum;
47
48     return i;
49 }