libjf API reference guide

Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

jf_journal_file.h

Go to the documentation of this file.
00001 /* 00002 * Copyright 2005 Tiian 00003 * {In real life Tiian is Christian Ferrari} 00004 * This file is part of "libjf" package. 00005 * 00006 * "libjf" is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 2.1 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * "libjf" is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with ; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 */ 00020 #ifndef JF_JOURNAL_FILE_H 00021 #define JF_JOURNAL_FILE_H 00022 00023 00024 00025 #include <jf/jf_config.h> 00026 00027 00028 00029 #ifdef HAVE_STDIO_H 00030 # include <stdio.h> 00031 #endif /* HAVE_STDIO_H */ 00032 #ifdef HAVE_LIMITS_H 00033 # include <limits.h> 00034 #endif /* HAVE_LIMITS_H */ 00035 00036 #include <jf/jf_defines.h> 00037 #include <jf/jf_errors.h> 00038 #include <jf/jf_cache_file.h> 00039 #include <jf/jf_trace.h> 00040 00041 00042 00043 /* save old JF_TRACE_MODULE and set a new value */ 00044 #ifdef JF_TRACE_MODULE 00045 # define JF_TRACE_MODULE_SAVE JF_TRACE_MODULE 00046 # undef JF_TRACE_MODULE 00047 #else 00048 # undef JF_TRACE_MODULE_SAVE 00049 #endif /* JF_TRACE_MODULE */ 00050 #define JF_TRACE_MODULE JF_TRACE_MOD_LIB_JOURNAL_FILE 00051 00052 00053 00060 #define JF_JOURNAL_FILE_CACHE_SIZE_ENV_VAR "JF_JOURNALED_FILE_CACHE_SIZE" 00061 00062 00063 00067 #define JF_FILE_OM_READ 0x80000000 00068 00071 #define JF_FILE_OM_WRITE 0x40000000 00072 00075 #define JF_FILE_OM_APPEND 0x20000000 00076 00079 #define JF_FILE_OM_RESTART 0x10000000 00080 00083 #define JF_FILE_OM_TRUNCATE 0x08000000 00084 00087 #define JF_FILE_OM_MSDOS 0x04000000 00088 00091 #define JF_FILE_OM_MASK (JF_FILE_OM_READ | JF_FILE_OM_WRITE | JF_FILE_OM_APPEND | JF_FILE_OM_RESTART | JF_FILE_OM_TRUNCATE | JF_FILE_OM_MSDOS) 00092 00093 00094 00098 #define JF_JOURNAL_FILE_ST_RESET 0x0 00099 00102 #define JF_JOURNAL_FILE_ST_OPEN 0x1 00103 00107 #define JF_JOURNAL_FILE_ST_SYNC 0x2 00108 00112 #define JF_JOURNAL_FILE_MAX_PATH_SIZE (PATH_MAX + 1) 00113 00114 00115 00116 #ifdef __cplusplus 00117 extern "C" { 00118 #endif /* __cplusplus */ 00119 00120 00121 00126 struct jf_journal_file_opts_s { 00131 jf_offset_t cache_size_limit; 00132 }; 00133 00134 00135 00140 static void inline jf_set_default_journal_file_opts( 00141 struct jf_journal_file_opts_s *options) { 00142 options->cache_size_limit = 00143 (getenv(JF_JOURNAL_FILE_CACHE_SIZE_ENV_VAR) != NULL) ? 00144 strtoll(getenv(JF_JOURNAL_FILE_CACHE_SIZE_ENV_VAR), 00145 NULL, 0) : JF_CACHE_FILE_DEFAULT_LIMIT; 00146 if (options->cache_size_limit < JF_CACHE_FILE_DEFAULT_LIMIT) 00147 options->cache_size_limit = 00148 JF_CACHE_FILE_DEFAULT_LIMIT; 00149 } 00150 00151 00152 00157 typedef struct { 00161 char *file_path; 00165 jf_offset_t last_pos; 00169 jf_offset_t last_size; 00173 uint32_t status; 00177 FILE *stream; 00182 jf_offset_t last_uc_pos; 00187 jf_offset_t last_uc_size; 00192 uint32_t open_mode; 00197 jf_cache_file_t cache_file; 00204 int all_in_cache; 00205 } jf_journal_file_t; 00206 00207 00208 00214 static inline FILE *jf_journal_file_get_stream( 00215 const jf_journal_file_t *jf) { return jf->stream; } 00216 00217 00218 00225 static inline int jf_journal_file_set_stream( 00226 jf_journal_file_t *jf, FILE *stream) { 00227 jf->stream = stream; 00228 return JF_RC_OK; 00229 } 00230 00231 00232 00238 static inline const char *jf_journal_file_get_path( 00239 const jf_journal_file_t *jf) { return jf->file_path; } 00240 00241 00242 00249 int jf_journal_file_set_path(jf_journal_file_t *jf, 00250 const char *new_path); 00251 00252 00253 00259 static inline jf_offset_t jf_journal_file_get_last_pos( 00260 const jf_journal_file_t *jf) { return jf->last_pos; } 00261 00262 00263 00270 static inline int jf_journal_file_set_last_pos( 00271 jf_journal_file_t *jf, jf_offset_t new_pos) { 00272 jf->last_pos = new_pos; 00273 return JF_RC_OK; 00274 } 00275 00276 00277 00283 static inline jf_offset_t jf_journal_file_get_last_size( 00284 const jf_journal_file_t *jf) { return jf->last_size; } 00285 00286 00287 00294 static inline int jf_journal_file_set_last_size( 00295 jf_journal_file_t *jf, jf_offset_t new_size) { 00296 jf->last_size = new_size; 00297 return JF_RC_OK; 00298 } 00299 00300 00301 00307 static inline uint32_t jf_journal_file_get_status( 00308 const jf_journal_file_t *jf) { return jf->status; } 00309 00310 00311 00318 static inline int jf_journal_file_set_status( 00319 jf_journal_file_t *jf, uint32_t status) { 00320 jf->status = status; 00321 return JF_RC_OK; 00322 } 00323 00324 00325 00331 static inline jf_offset_t jf_journal_file_get_last_uc_size( 00332 const jf_journal_file_t *jf) { return jf->last_uc_size; } 00333 00334 00335 00343 static inline int jf_journal_file_set_last_uc_size( 00344 jf_journal_file_t *jf, jf_offset_t new_size) { 00345 jf->last_uc_size = new_size; 00346 return JF_RC_OK; 00347 } 00348 00349 00350 00358 static inline uint32_t jf_journal_file_get_open_mode( 00359 const jf_journal_file_t *jf) { 00360 JF_TRACE(("jf_journal_file_get_open_mode: 0x%x\n", 00361 jf->open_mode)); 00362 return jf->open_mode; 00363 } 00364 00365 00366 00375 static inline int jf_journal_file_set_open_mode( 00376 jf_journal_file_t *jf, uint32_t new_open_mode) { 00377 JF_TRACE(("jf_journal_file_set_open_mode: 0x%x\n" , 00378 new_open_mode)); 00379 jf->open_mode = new_open_mode; 00380 return JF_RC_OK; 00381 } 00382 00383 00384 00390 static inline jf_offset_t jf_journal_file_get_last_uc_pos( 00391 const jf_journal_file_t *jf) { return jf->last_uc_pos; } 00392 00393 00394 00401 static inline int jf_journal_file_set_last_uc_pos( 00402 jf_journal_file_t *jf, jf_offset_t new_pos) { 00403 jf->last_uc_pos = new_pos; 00404 return JF_RC_OK; 00405 } 00406 00407 00408 00415 static inline jf_cache_file_t *jf_journal_file_get_cache_file( 00416 jf_journal_file_t *jf) { return &(jf->cache_file); } 00417 00418 00419 00429 int jf_journal_file_set_cache_file(jf_journal_file_t *jf, 00430 const jf_cache_file_t *cf); 00431 00432 00433 00440 static inline int jf_journal_file_get_all_in_cache( 00441 const jf_journal_file_t *jf) { 00442 return jf->all_in_cache; 00443 } 00444 00445 00446 00454 static inline int jf_journal_file_set_all_in_cache( 00455 jf_journal_file_t *jf, int new_value) { 00456 jf->all_in_cache = new_value; 00457 return JF_RC_OK; 00458 } 00459 00460 00461 00468 int jf_journal_file_set_options( 00469 jf_journal_file_t *jf, 00470 const struct jf_journal_file_opts_s *options); 00471 00472 00473 00480 void jf_journal_file_reset(jf_journal_file_t *jf); 00481 00482 00483 00488 void jf_journal_file_create(jf_journal_file_t *jf); 00489 00490 00491 00497 void jf_journal_file_destroy(jf_journal_file_t *jf); 00498 00499 00500 00512 int jf_journal_file_init(jf_journal_file_t *jf, 00513 const char *path, FILE *stream, 00514 uint32_t open_mode, 00515 const struct jf_journal_file_opts_s *options); 00516 00517 00518 00519 #ifdef __cplusplus 00520 } 00521 #endif /* __cplusplus */ 00522 00523 00524 00525 /* restore old value of JF_TRACE_MODULE */ 00526 #ifdef JF_TRACE_MODULE_SAVE 00527 # undef JF_TRACE_MODULE 00528 # define JF_TRACE_MODULE JF_TRACE_MODULE_SAVE 00529 # undef JF_TRACE_MODULE_SAVE 00530 #endif /* JF_TRACE_MODULE_SAVE */ 00531 00532 00533 00534 #endif /* JF_JOURNAL_FILE_H */

Copyright 2005 © Tiian