readdir was rewritten in Ruby just before the end of the hackfest
[hurd/trovefs.git] / trovefs.h
1 /*
2  * Copyright (C) 1997 Free Software Foundation, Inc.
3  * Copyright (C) 2013  Steven McDonald <steven@steven-mcdonald.id.au>
4  *
5  * ftpfs translator written by Miles Bader <miles@gnu.ai.mit.edu>
6  * Modified for trovefs by Steven McDonald <steven@steven-mcdonald.id.au>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2, or (at your option)
11  * any later version.
12  *
13  * This software is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
21  */
22
23 #ifndef __TROVEFS_H__
24 #define __TROVEFS_H__
25
26 #include <pthread.h>
27 #include <libs3.h>
28 #include <sys/stat.h>
29 #include <hurd/ihash.h>
30
31 #define TROVEFS_VERSION "0.0"
32
33 #define TROVEFS_DEFAULT_HOSTNAME "beta.anchortrove.com"
34 #define TROVEFS_USER_AGENT "trovefs " TROVEFS_VERSION " (GNU)"
35 #define TROVEFS_REMOTE_PATH_MALLOC_SIZE 128
36 #define TROVEFS_MAX_LIST_KEYS 10000
37
38 struct trovefs_dir_entry
39 {
40         char *name;
41         size_t hv;
42
43         struct node *node;
44
45         struct stat stat;
46         time_t stat_timestamp;
47
48         struct trovefs_dir *dir;
49
50         struct trovefs_dir_entry *next, **self_p;
51
52         struct trovefs_dir_entry *ordered_next, **ordered_self_p;
53
54         time_t name_timestamp;
55
56         hurd_ihash_locp_t inode_locp;
57
58         int noent : 1;
59         int valid : 1;
60 };
61
62 struct trovefs_dir
63 {
64         size_t num_entries;
65
66         size_t num_live_entries;
67
68         struct trovefs_dir_entry **htable;
69         size_t htable_len;
70
71         struct trovefs_dir_entry *ordered;
72
73         struct node *node;
74
75         struct trovefs *fs;
76
77         const char *rmt_path;
78
79         time_t stat_timestamp;
80         time_t name_timestamp;
81
82         time_t bulk_stat_base_stamp;
83         unsigned bulk_stat_count_first_half;
84         unsigned bulk_stat_count_second_half;
85 };
86
87 struct netnode
88 {
89         struct trovefs *fs;
90
91         struct trovefs_dir_entry *dir_entry;
92
93         const char *rmt_path;
94
95         struct ccache *contents;
96
97         struct trovefs_dir *dir;
98
99         struct node *ncache_next, *ncache_prev;
100 };
101
102 struct trovefs
103 {
104         /* Filesystem root. */
105         struct node *root;
106
107         /* Context for S3 requests. */
108         S3BucketContext *s3_ctx;
109
110         ino_t next_inode;
111         int fsid;
112
113         struct hurd_ihash inode_mappings;
114         pthread_spinlock_t inode_mappings_lock;
115 };
116
117 error_t
118 trovefs_create (char *hostname, char *bucket, char *access_key_id, char *secret_access_key, int fsid, struct trovefs **fs);
119
120 error_t
121 trovefs_dir_create (struct trovefs *fs, struct node *node, const char *rmt_path, struct trovefs_dir **dir);
122
123 error_t
124 trovefs_dir_null_lookup (struct trovefs_dir *dir, struct node **node);
125
126 error_t
127 trovefs_create_node (struct trovefs_dir_entry *e, const char *rmt_path, struct node **node);
128
129 error_t
130 trovefs_refresh_node (struct node *node);
131
132 error_t
133 refresh_dir (struct trovefs_dir *dir, int update_stats, struct trovefs_dir_entry *preserve_entry);
134
135 void
136 free_entry (struct trovefs_dir_entry *e);
137
138 error_t
139 trovefs_s3_get_names (struct trovefs_dir *dir);
140
141 struct trovefs_dir_entry *
142 lookup (struct trovefs_dir *dir, const char *name, int add);
143
144 #endif // __TROVEFS_H__