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