1/*
2 * Copyright 2004-2008, Fran��ois Revol, <revol@free.fr>.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _GOOGLEFS_H
6#define _GOOGLEFS_H
7
8/* wrappers */
9#ifdef __HAIKU__
10
11#include <fs_interface.h>
12#include <kernel/lock.h>
13#include <fs_info.h>
14#include <NodeMonitor.h>
15#define lock mutex
16#define new_lock mutex_init
17#define free_lock mutex_destroy
18#define LOCK mutex_lock
19#define UNLOCK mutex_unlock
20typedef dev_t nspace_id;
21
22#else
23
24#include "fsproto.h"
25#include "lock.h"
26#define publish_vnode new_vnode
27
28#endif
29
30#include "lists2.h"
31
32#include <Errors.h>
33#include <sys/stat.h>
34#include <SupportDefs.h>
35
36/* should be more than enough */
37//#define GOOGLEFS_NAME_LEN B_OS_NAME_LENGTH
38//#define GOOGLEFS_NAME_LEN 64 /* GR_MAX_NAME */
39/* some google results are a bit more than 64 */
40#define GOOGLEFS_NAME_LEN 70 /* GR_MAX_NAME */
41
42#define GOOGLEFS_NAME "googlefs"
43#define GOOGLEFS_PRETTY_NAME "Google Bookmark File System"
44
45#define MAX_VNIDS 5000
46
47
48struct attr_entry {
49	const char *name;
50	uint32 type;
51	size_t size;
52	void *value;
53};
54
55#undef ASSERT
56#define ASSERT(op) if (!(op)) panic("ASSERT: %s in %s:%s", #op, __FILE__, __FUNCTION__)
57
58struct mount_fs_params
59{
60	/* no param */
61};
62
63struct fs_file_cookie;
64
65struct fs_node
66{
67	struct fs_node *nlnext; /* node list */
68	struct fs_node *qnext; /* query list */
69	struct fs_node *next; /* next in folder */
70	struct fs_node *parent, *children;
71	struct fs_file_cookie *opened; /* opened on this node */
72
73	char name[GOOGLEFS_NAME_LEN];
74	ino_t vnid;
75	lock l;
76
77	int is_perm:1;	/* don't delete on last close */
78	int deleted:1;
79	int qcompleted:1;
80	int hidden:1;	/* don't list in readdir */
81	struct stat st; /* including S_IFDIR in st_mode */
82	struct google_request *request; /* set on root folder for a query */
83	struct google_result *result; /* for query results */
84	struct attr_entry *attrs_indirect;
85	struct attr_entry attrs[10];
86	void *data;
87	size_t data_size;
88};
89
90struct vnidpool;
91
92struct fs_nspace
93{
94	nspace_id nsid;
95	ino_t rootid;
96	struct vnidpool *vnids;
97	struct fs_node *root; /* fast access for stat time change */
98	struct fs_node *nodes;
99	struct fs_node *queries;
100	vint32 nodecount; /* just for statvfs() */
101
102	lock l;
103};
104
105struct fs_file_cookie
106{
107	struct fs_file_cookie *next; /* must stay here */
108	struct fs_node *node;
109	int dir_current; /* current entry for readdir() */
110	int omode;
111	int type; /* S_IF* of the *cookie* */
112	struct attr_entry *attr;
113};
114/* just for type */
115#define     S_IFQUERY                     00000070000
116
117typedef struct attr_entry attr_entry;
118typedef struct fs_nspace fs_nspace;
119typedef struct fs_node fs_node;
120typedef struct fs_file_cookie fs_file_cookie;
121/* not much different */
122#define fs_dir_cookie fs_file_cookie
123#define fs_attr_dir_cookie fs_file_cookie
124#define fs_query_cookie fs_file_cookie
125
126ino_t new_vnid(fs_nspace *ns);
127
128int googlefs_event(fs_nspace *ns, fs_node *node, int flags);
129
130/* used by the requester to publish entries in queries
131 * result = NULL to notify end of list
132 */
133extern int googlefs_push_result_to_query(struct google_request *request, struct google_result *result);
134
135#endif
136