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 #ifndef __CLSYNC_CLSYNC_H 21 #define __CLSYNC_CLSYNC_H 22 23 #include <stdio.h> 24 #include <stdint.h> 25 #include <sys/types.h> 26 27 #define CLSYNC_API_VERSION 2 28 29 enum eventobjtype { 30 EOT_UNKNOWN = 0, // Unknown 31 EOT_DOESNTEXIST = 1, // Doesn't exists (not created yet or already deleted) 32 EOT_FILE = 2, // File 33 EOT_DIR = 3, // Directory 34 35 // The value cannot be higher than "65535". It's due to recognize_event() function of mon_*.c 36 }; 37 typedef enum eventobjtype eventobjtype_t; 38 39 struct api_eventinfo { 40 uint32_t evmask; // event mask, see /usr/include/linux/inotify.h 41 uint32_t flags; // flags, see "enum eventinfo_flags" 42 size_t path_len; // strlen(path) 43 const char *path; // path 44 eventobjtype_t objtype_old; // type of object by path "path" before the event 45 eventobjtype_t objtype_new; // type of object by path "path" after the event 46 }; 47 typedef struct api_eventinfo api_eventinfo_t; 48 49 struct ctx; 50 struct indexes; 51 typedef int(*api_funct_init) (struct ctx *, struct indexes *); 52 typedef int(*api_funct_sync) (int n, api_eventinfo_t *); 53 typedef int(*api_funct_rsync) (const char *inclist, const char *exclist); 54 typedef int(*api_funct_deinit)(); 55 56 enum eventinfo_flags { 57 EVIF_NONE = 0x00000000, // No modifier 58 EVIF_RECURSIVELY = 0x00000001, // Need to be synced recursively 59 EVIF_CONTENTRECURSIVELY = 0x00000002, // Affects recursively only on content of this dir 60 }; 61 typedef enum eventinfo_flags eventinfo_flags_t; 62 63 /** 64 * @brief Writes the list to list-file for "--include-from" option of rsync using array of api_eventinfo_t 65 * 66 * @param[in] indexes_p Pointer to "indexes" 67 * @param[in] listfile File identifier to write to 68 * @param[in] n Number of records in apievinfo 69 * @param[in] apievinfo Pointer to api_eventinfo_t records 70 * 71 * @retval zero Successful 72 * @retval non-zero If got error while deleting the message. The error-code is placed into returned value. 73 * 74 */ 75 extern int apievinfo2rsynclist(struct indexes *indexes_p, FILE *listfile, int n, api_eventinfo_t *apievinfo); // Not tested, yet 76 77 /** 78 * @brief Returns currect API version 79 * 80 * @retval api_version Version of clsync's API 81 * 82 */ 83 extern int clsyncapi_getapiversion(); 84 85 /** 86 * @brief clsync's wrapper for function "fork()". Should be used instead of "fork()" directly, to notify clsync about child's pid. 87 * 88 * @param[in] ctx_p Pointer to "ctx" 89 * 90 * @retval -1 If error (see "man 2 fork", added error code "ECANCELED" if too many children) 91 * @retval 0 If child 92 * @retval pid Pid of child of parent. (see "man 2 fork") 93 * 94 */ 95 extern pid_t clsyncapi_fork(struct ctx *ctx_p); 96 97 #endif 98 99