2 Tagsistant (tagfs) -- tagsistant.h
3 Copyright (C) 2006-2007 Tx0 <tx0@strumentiresistenti.org>
5 Tagsistant (tagfs) mount binary written using FUSE userspace library.
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)
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
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 Foundation,
20 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 /* for developing purposes only */
24 #define VERBOSE_DEBUG 0
25 /* #define DEBUG_STRDUP */
27 #define TAGSISTANT_PLUGIN_PREFIX "libtagsistant_"
33 /* used to import mempcpy */
39 /* For pread()/pwrite() */
43 #define _XOPEN_SOURCE 500
46 #ifndef FUSE_USE_VERSION
47 #define FUSE_USE_VERSION 26
51 #define _POSIX_PTHREAD_SEMANTICS
57 #include "../../debug.h"
66 #include <sys/types.h>
67 #include <sys/socket.h>
69 #if FUSE_USE_VERSION == 25
70 # if HAVE_SYS_STATVFS_H
71 # include <sys/statvfs.h>
74 # if HAVE_SYS_STATFS_H
75 # include <sys/statfs.h>
79 #include <netinet/in.h>
82 #include <dlfcn.h> /* for dlopen() and friends */
84 #include <glib/gstrfuncs.h>
87 #include <sys/xattr.h>
90 #ifndef _FILE_OFFSET_BITS
91 #define _FILE_OFFSET_BITS 64
97 #include <compat/fuse_opt.h>
102 #define MAX_TAG_LENGTH 255
104 #define dyn_strcat(original, newstring) original = _dyn_strcat(original, newstring)
105 extern gchar
*_dyn_strcat(gchar
*original
, const gchar
*newstring
);
108 * defines an AND token in a query path
110 typedef struct ptree_and_node
{
111 /** the name of this token */
114 /** list of all related tags **/
115 struct ptree_and_node
*related
;
117 /** next AND token */
118 struct ptree_and_node
*next
;
122 * define an OR section in a query path
124 typedef struct ptree_or_node
{
125 /** the next OR section */
126 struct ptree_or_node
*next
;
128 /** the list of AND tokens */
129 struct ptree_and_node
*and_set
;
133 * used in linked list of returned results
135 typedef struct file_handle
{
136 /** filename pointed by this structure */
139 /** next element in results */
140 struct file_handle
*next
;
143 /* codes used in plugin chain processing */
145 #define TP_ERROR 0 /**< an error occurred while processing with this plugin */
146 #define TP_OK 1 /**< ok, but further tagging can be done by other plugins */
147 #define TP_STOP 2 /**< this plugin is authoritative for mimetype, stop chaining */
148 #define TP_NULL 3 /**< no tagging has been done, but that's not an error */
151 * holds a pointer to a processing funtion
152 * exported by a plugin
154 typedef struct tagsistant_plugin
{
155 /** MIME type managed by this plugins */
158 /** file name of this plugin */
161 /** handle to plugin returned by dlopen() */
165 * hook to processing function
167 * \param filename the file to be processed
168 * \return 0 on failure (the plugin wasn't unable to process the file), 1 on
169 * partial success (the plugin did processed the file, but later processing
170 * by other plugins is allowed) or 2 on successful processing (no further
171 * processing required).
173 int (*processor
)(const char *filename
);
176 * hook to g_free allocated resources
180 /** next plugin in linked list */
181 struct tagsistant_plugin
*next
;
182 } tagsistant_plugin_t
;
185 * defines command line options for tagsistant mount tool
188 int debug
; /**< enable debug */
189 int foreground
; /**< run in foreground */
190 int singlethread
; /**< single thread? */
191 int readonly
; /**< mount filesystem readonly */
192 int verbose
; /**< do verbose logging on syslog (stderr is always verbose) */
193 int quiet
; /**< don't log anything */
195 char *progname
; /**< tagsistant */
196 char *mountpoint
; /**< no clue? */
197 char *repository
; /**< it's where files and tags are archived, no? */
198 char *archive
; /**< a directory holding all the files */
199 char *tags
; /**< a SQLite database on file */
201 sqlite3
*dbh
; /**< database handle to operate on SQLite thingy, but no longer used? */
204 extern struct tagsistant tagsistant
;
207 extern int log_enabled
;
209 extern char *get_tag_name(const char *path
);
210 extern char *get_tag_path(const char *tag
);
211 extern char *get_file_path(const char *tag
);
212 extern char *get_tmp_file_path(const char *tag
);
214 extern int is_tagged(char *filename
, char *tagname
);
215 extern int tag_file(const char *filename
, char *tagname
);
216 extern int untag_file(char *filename
, char *tagname
);
218 extern ptree_or_node_t
*build_querytree(const char *path
);
219 extern file_handle_t
*build_filetree(ptree_or_node_t
*query
, const char *path
);
221 extern void destroy_querytree(ptree_or_node_t
*pt
);
222 extern void destroy_filetree(file_handle_t
*fh
);
224 extern FILE *debugfd
;
227 # ifndef DEBUG_TO_LOGFILE
228 # define DEBUG_TO_LOGFILE
232 # define strdup(string) real_strdup(string, __FILE__, __LINE__)
234 char *real_strdup(const char *orig
, char *file
, int line
);
237 #define freenull(symbol) {\
238 if (symbol != NULL) {\
239 if (debugfd != NULL) {\
240 fprintf(debugfd, "0x%.8x: g_free()\n", (unsigned int) symbol);\
245 dbg(LOG_ERR, "FREE ERROR: symbol %s is NULL!", __STRING(symbol));\
249 // vim:ts=4:nocindent:nowrap