clsync
common.h
Go to the documentation of this file.
1 /*
2  clsync - file tree sync utility based on inotify
3 
4  Copyright (C) 2013 Dmitry Yu Okunev <dyokunev@ut.mephi.ru> 0x8E30679C
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 
21 #ifndef __CLSYNC_COMMON_H
22 #define __CLSYNC_COMMON_H
23 
24 #ifndef __linux__
25 # ifdef HAVE_CAPABILITIES
26 # undef HAVE_CAPABILITIES
27 # warning Capabilities support can be built only on Linux
28 # endif
29 #endif
30 
31 #define _GNU_SOURCE
32 //#define _XOPEN_SOURCE 700
33 #define _LARGEFILE64_SOURCE
34 
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <stdint.h>
38 #include <string.h>
39 #include <strings.h>
40 #include <unistd.h>
41 #include <getopt.h>
42 #include <limits.h>
43 #include <stdarg.h>
44 #include <sys/types.h>
45 #include <sys/stat.h>
46 #include <fcntl.h>
47 #include <sys/mman.h>
48 #include <errno.h>
49 #include <ctype.h>
50 #include <signal.h>
51 #ifdef KQUEUE_SUPPORT
52 # include <sys/event.h>
53 #endif
54 #ifdef INOTIFY_SUPPORT
55 # include <sys/inotify.h>
56 #endif
57 #ifdef FANOTIFY_SUPPORT
58 # include <sys/fanotify.h>
59 #endif
60 #include <sys/wait.h>
61 #include <fts.h>
62 #include <sys/time.h>
63 #include <dirent.h>
64 #include <sys/utsname.h>
65 #include <sys/socket.h>
66 #include <arpa/inet.h>
67 #include <netinet/in.h>
68 #include <libgen.h>
69 #include <pthread.h>
70 
71 #define CLSYNC_ITSELF
72 
73 #include "configuration.h"
74 #ifdef HAVE_CONFIG_H
75 # include "config.h"
76 #endif
77 
78 #include "clsync.h"
79 #include "port-hacks.h"
80 #include "posix-hacks.h"
81 #include "ctx.h"
82 #include "program.h"
83 
84 #include <sys/param.h>
85 
86 #ifndef IN_CREATE_SELF
87 # define IN_CREATE_SELF IN_CREATE
88 #endif
89 
90 #include "macros.h"
91 
98 // PS_REHASH,
100 };
102 
103 
113 };
115 
117  PM_OFF = 0,
120 };
122 
124  SM_OFF = 0,
127 };
129 
130 /*
131 struct excludeinfo {
132  unsigned int seqid_min;
133  unsigned int seqid_max;
134  eventobjtype_t objtype_old;
135  eventobjtype_t objtype_new;
136  uint32_t flags;
137 };
138 typedef struct eventinfo eventinfo_t;
139 */
140 struct eventinfo {
141  uint32_t evmask;
142  unsigned int seqid_min;
143  unsigned int seqid_max;
146  int wd;
147  size_t fsize;
148  uint32_t flags;
149 };
150 typedef struct eventinfo eventinfo_t;
151 
157 };
158 
159 
160 struct dosync_arg {
161  int evcount;
162  char excf_path[PATH_MAX + 1];
163  char outf_path[PATH_MAX + 1];
164  FILE *outf;
166  struct indexes *indexes_p;
167  void *data;
168  unsigned int linescount;
171  char buf[BUFSIZ + 1];
172 
173 // for be read by sync_parameter_get():
174  const char *include_list[MAXARGUMENTS + 2];
176  const char *list_type_str;
177  const char *evmask_str;
178 };
179 
180 struct doubleentry {
181  size_t size0;
182  size_t size1;
183  size_t alloc0;
184  size_t alloc1;
185  void *dat0;
186  void *dat1;
187 };
188 
191  int total;
192  size_t size;
194 };
195 
196 struct myentry {
197  size_t size;
198  size_t alloc;
199  void *dat;
200 };
201 
204  int total;
205  size_t size;
206  struct myentry *entry;
207 };
208 
209 enum initsync {
213 };
214 typedef enum initsync initsync_t;
215 
218 // indexes_t *indexes_p;
219  pthread_t pthread_parent;
221  sigset_t *sigset_p;
222 };
224 
225 #endif
226 
SM_PROCESS
@ SM_PROCESS
Definition: common.h:126
ctx.h
pushdoubleentry_arg
Definition: common.h:189
SM_OFF
@ SM_OFF
Definition: common.h:124
dosync_arg::linescount
unsigned int linescount
Definition: common.h:168
INITSYNC_FULL
@ INITSYNC_FULL
Definition: common.h:211
eventinfo::objtype_old
eventobjtype_t objtype_old
Definition: common.h:144
sighandler_arg::ctx_p
ctx_t * ctx_p
Definition: common.h:217
pushentry_arg
Definition: common.h:202
INITSYNC_UNKNOWN
@ INITSYNC_UNKNOWN
Definition: common.h:210
ctx
Definition: ctx.h:315
doubleentry::alloc0
size_t alloc0
Definition: common.h:183
eventinfo::seqid_min
unsigned int seqid_min
Definition: common.h:142
doubleentry::dat1
void * dat1
Definition: common.h:186
MAXARGUMENTS
#define MAXARGUMENTS
Definition: configuration.h:13
program.h
api_eventinfo
Definition: clsync.h:39
sighandler_arg::exitcode_p
int * exitcode_p
Definition: common.h:220
pushdoubleentry_arg::total
int total
Definition: common.h:191
eventobjtype_t
enum eventobjtype eventobjtype_t
Definition: clsync.h:37
notifyengine_t
enum notifyengine_enum notifyengine_t
Definition: common.h:114
PTHREAD_MUTEX_SELECT
@ PTHREAD_MUTEX_SELECT
Definition: common.h:154
myentry::size
size_t size
Definition: common.h:197
indexes
Definition: indexes.h:34
doubleentry::size1
size_t size1
Definition: common.h:182
doubleentry
Definition: common.h:180
pushentry_arg::entry
struct myentry * entry
Definition: common.h:206
PS_CONTROL
@ PS_CONTROL
Definition: common.h:96
NE_KQUEUE
@ NE_KQUEUE
Definition: common.h:108
pushentry_arg::total
int total
Definition: common.h:204
macros.h
posix-hacks.h
pushentry_arg::size
size_t size
Definition: common.h:205
sighandler_arg::pthread_parent
pthread_t pthread_parent
Definition: common.h:219
PTHREAD_MUTEX_MAX
@ PTHREAD_MUTEX_MAX
Definition: common.h:156
notifyengine_enum
notifyengine_enum
Definition: common.h:104
INITSYNC_SUBDIR
@ INITSYNC_SUBDIR
Definition: common.h:212
NE_BSM_PREFETCH
@ NE_BSM_PREFETCH
Definition: common.h:110
pushdoubleentry_arg::allocated
int allocated
Definition: common.h:190
NE_DTRACEPIPE
@ NE_DTRACEPIPE
Definition: common.h:111
pushentry_arg::allocated
int allocated
Definition: common.h:203
initsync
initsync
Definition: common.h:209
dosync_arg::excf_path
char excf_path[PATH_MAX+1]
Definition: common.h:162
dosync_arg::api_ei
api_eventinfo_t * api_ei
Definition: common.h:169
dosync_arg::outf
FILE * outf
Definition: common.h:164
paramsource_enum
paramsource_enum
Definition: common.h:92
PS_CONFIG
@ PS_CONFIG
Definition: common.h:95
initsync_t
enum initsync initsync_t
Definition: common.h:214
eventinfo::seqid_max
unsigned int seqid_max
Definition: common.h:143
myentry::dat
void * dat
Definition: common.h:199
dosync_arg::outf_path
char outf_path[PATH_MAX+1]
Definition: common.h:163
splittingmode_enum
splittingmode_enum
Definition: common.h:123
PTHREAD_MUTEX_THREADSINFO
@ PTHREAD_MUTEX_THREADSINFO
Definition: common.h:155
threadingmode_t
enum threadingmode threadingmode_t
Definition: common.h:121
doubleentry::dat0
void * dat0
Definition: common.h:185
NE_INOTIFY
@ NE_INOTIFY
Definition: common.h:107
sighandler_arg::sigset_p
sigset_t * sigset_p
Definition: common.h:221
dosync_arg
Definition: common.h:160
PTHREAD_MUTEX_STATE
@ PTHREAD_MUTEX_STATE
Definition: common.h:153
PS_DEFAULTS
@ PS_DEFAULTS
Definition: common.h:97
NE_BSM
@ NE_BSM
Definition: common.h:109
dosync_arg::api_ei_count
int api_ei_count
Definition: common.h:170
clsync.h
sighandler_arg
Definition: common.h:216
NE_FANOTIFY
@ NE_FANOTIFY
Definition: common.h:106
doubleentry::alloc1
size_t alloc1
Definition: common.h:184
dosync_arg::evcount
int evcount
Definition: common.h:161
dosync_arg::include_list_count
size_t include_list_count
Definition: common.h:175
PM_OFF
@ PM_OFF
Definition: common.h:117
BUFSIZ
#define BUFSIZ
Definition: configuration.h:6
NE_UNDEFINED
@ NE_UNDEFINED
Definition: common.h:105
eventinfo
Definition: common.h:140
dosync_arg::list_type_str
const char * list_type_str
Definition: common.h:176
doubleentry::size0
size_t size0
Definition: common.h:181
PM_SAFE
@ PM_SAFE
Definition: common.h:118
pthread_mutex_id
pthread_mutex_id
Definition: common.h:152
pushdoubleentry_arg::size
size_t size
Definition: common.h:192
configuration.h
dosync_arg::data
void * data
Definition: common.h:167
PS_CORRECTION
@ PS_CORRECTION
Definition: common.h:99
paramsource_t
enum paramsource_enum paramsource_t
Definition: common.h:101
eventinfo::wd
int wd
Definition: common.h:146
eventinfo::objtype_new
eventobjtype_t objtype_new
Definition: common.h:145
config.h
eventinfo::fsize
size_t fsize
Definition: common.h:147
port-hacks.h
SM_THREAD
@ SM_THREAD
Definition: common.h:125
dosync_arg::include_list
const char * include_list[(1<< 8)+2]
Definition: common.h:174
threadingmode
threadingmode
Definition: common.h:116
dosync_arg::buf
char buf[(1<< 16)+1]
Definition: common.h:171
NE_GIO
@ NE_GIO
Definition: common.h:112
pushdoubleentry_arg::entry
struct doubleentry * entry
Definition: common.h:193
myentry
Definition: common.h:196
eventinfo::evmask
uint32_t evmask
Definition: common.h:141
PS_ARGUMENT
@ PS_ARGUMENT
Definition: common.h:94
PM_FULL
@ PM_FULL
Definition: common.h:119
dosync_arg::evmask_str
const char * evmask_str
Definition: common.h:177
dosync_arg::ctx_p
ctx_t * ctx_p
Definition: common.h:165
myentry::alloc
size_t alloc
Definition: common.h:198
PS_UNKNOWN
@ PS_UNKNOWN
Definition: common.h:93
eventinfo::flags
uint32_t flags
Definition: common.h:148
splittingmode_t
enum splittingmode_enum splittingmode_t
Definition: common.h:128