Blame view

clsync.h 3.3 KB
redmine authored
1
/*
redmine authored
2
    clsync - file tree sync utility based on inotify
redmine authored
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

    Copyright (C) 2013  Dmitry Yu Okunev <dyokunev@ut.mephi.ru> 0x8E30679C

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

redmine authored
20 21 22
#ifndef __CLSYNC_CLSYNC_H
#define __CLSYNC_CLSYNC_H

redmine authored
23
#include <stdio.h>
redmine authored
24 25 26
#include <stdint.h>
#include <sys/types.h>

redmine authored
27
#define CLSYNC_API_VERSION 2
redmine authored
28

redmine authored
29 30 31 32 33
enum eventobjtype {
	EOT_UNKNOWN	= 0,		// Unknown
	EOT_DOESNTEXIST	= 1,		// Doesn't exists (not created yet or already deleted)
	EOT_FILE	= 2,		// File
	EOT_DIR		= 3,		// Directory
redmine authored
34 35

	// The value cannot be higher than "65535". It's due to recognize_event() function of mon_*.c
redmine authored
36 37 38
};
typedef enum eventobjtype eventobjtype_t;

redmine authored
39
struct api_eventinfo {
redmine authored
40 41 42 43 44 45
	uint32_t	 evmask;	// event mask, see /usr/include/linux/inotify.h
	uint32_t	 flags;		// flags, see "enum eventinfo_flags"
	size_t		 path_len;	// strlen(path)
	const char	*path;		// path
	eventobjtype_t   objtype_old;	// type of object by path "path" before the event
	eventobjtype_t   objtype_new;	// type of object by path "path" after  the event
redmine authored
46 47 48
};
typedef struct api_eventinfo api_eventinfo_t;

redmine authored
49
struct ctx;
redmine authored
50
struct indexes;
redmine authored
51
typedef int(*api_funct_init)  (struct ctx *, struct indexes *);
redmine authored
52
typedef int(*api_funct_sync)  (int n, api_eventinfo_t *);
redmine authored
53
typedef int(*api_funct_rsync) (const char *inclist, const char *exclist);
redmine authored
54 55 56
typedef int(*api_funct_deinit)();

enum eventinfo_flags {
redmine authored
57 58
	EVIF_NONE		= 0x00000000,	// No modifier
	EVIF_RECURSIVELY	= 0x00000001,	// Need to be synced recursively
redmine authored
59
	EVIF_CONTENTRECURSIVELY	= 0x00000002,	// Affects recursively only on content of this dir
redmine authored
60
};
redmine authored
61
typedef enum eventinfo_flags eventinfo_flags_t;
redmine authored
62

redmine authored
63
/**
redmine authored
64
 * @brief 			Writes the list to list-file for "--include-from" option of rsync using array of api_eventinfo_t
redmine authored
65
 * 
redmine authored
66 67
 * @param[in]	indexes_p	Pointer to "indexes"
 * @param[in]	listfile	File identifier to write to
redmine authored
68 69 70 71 72 73 74
 * @param[in]	n		Number of records in apievinfo
 * @param[in]	apievinfo	Pointer to api_eventinfo_t records
 * 
 * @retval	zero		Successful
 * @retval	non-zero	If got error while deleting the message. The error-code is placed into returned value.
 * 
 */
redmine authored
75
extern int apievinfo2rsynclist(struct indexes *indexes_p, FILE *listfile, int n, api_eventinfo_t *apievinfo); // Not tested, yet
redmine authored
76

redmine authored
77 78 79 80 81 82 83 84
/**
 * @brief 			Returns currect API version
 * 
 * @retval	api_version	Version of clsync's API
 * 
 */
extern int clsyncapi_getapiversion();

redmine authored
85 86 87
/**
 * @brief 			clsync's wrapper for function "fork()". Should be used instead of "fork()" directly, to notify clsync about child's pid.
 *
redmine authored
88
 * @param[in]	ctx_p	Pointer to "ctx"
redmine authored
89
 * 
redmine authored
90
 * @retval	-1		If error (see "man 2 fork", added error code "ECANCELED" if too many children)
redmine authored
91 92 93 94
 * @retval	0		If child
 * @retval	pid		Pid of child of parent. (see "man 2 fork")
 * 
 */
redmine authored
95
extern pid_t clsyncapi_fork(struct ctx *ctx_p);
redmine authored
96

redmine authored
97 98
#endif