libjio.h | libjio.h | |||
---|---|---|---|---|
skipping to change at line 21 | skipping to change at line 21 | |||
#include <stdio.h> | #include <stdio.h> | |||
#include <sys/types.h> | #include <sys/types.h> | |||
#include <sys/uio.h> | #include <sys/uio.h> | |||
#include <pthread.h> | #include <pthread.h> | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
extern "C" { | extern "C" { | |||
#endif | #endif | |||
/* logical structures */ | /* logical structures */ | |||
/* the main file structure */ | ||||
struct jfs { | struct jfs { | |||
int fd; /* main file descriptor */ | int fd; /* main file descriptor */ | |||
char *name; /* and its name */ | char *name; /* and its name */ | |||
int jfd; /* journal's lock file descriptor */ | int jfd; /* journal's lock file descriptor */ | |||
int flags; /* journal mode options used in jopen() */ | int flags; /* journal flags */ | |||
pthread_mutex_t lock; /* a soft lock used in some operations */ | pthread_mutex_t lock; /* a soft lock used in some operations */ | |||
}; | }; | |||
/* a single operation */ | ||||
struct joper { | ||||
int locked; /* is the region is locked? */ | ||||
off_t offset; /* operation's offset */ | ||||
size_t len; /* data length */ | ||||
void *buf; /* data */ | ||||
size_t plen; /* previous data length */ | ||||
void *pdata; /* previous data */ | ||||
struct joper *prev; | ||||
struct joper *next; | ||||
}; | ||||
/* a transaction */ | ||||
struct jtrans { | struct jtrans { | |||
struct jfs *fs; /* journal file structure to operate on */ | struct jfs *fs; /* journal file structure to operate on */ | |||
char *name; /* name of the transaction file */ | char *name; /* name of the transaction file */ | |||
int id; /* transaction id */ | int id; /* transaction id */ | |||
int flags; /* misc flags */ | int flags; /* misc flags */ | |||
const void *buf; /* buffer */ | unsigned int numops; /* quantity of operations in the list */ | |||
size_t len; /* buffer lenght */ | pthread_mutex_t lock; /* used to modify the operation list */ | |||
off_t offset; /* file offset to operate on */ | struct joper *op; /* list of operations */ | |||
void *udata; /* user-supplied data */ | ||||
size_t ulen; /* udata lenght */ | ||||
void *pdata; /* previous data, for rollback */ | ||||
size_t plen; /* pdata lenght */ | ||||
}; | }; | |||
struct jfsck_result { | struct jfsck_result { | |||
int total; /* total transactions files we looked at */ | int total; /* total transactions files we looked at */ | |||
int invalid; /* invalid files in the journal directory */ | int invalid; /* invalid files in the journal directory */ | |||
int in_progress; /* transactions in progress */ | int in_progress; /* transactions in progress */ | |||
int broken_head; /* transactions broken (header missing) */ | int broken; /* transactions broken */ | |||
int broken_body; /* transactions broken (body missing) */ | ||||
int load_error; /* errors loading the transaction */ | ||||
int apply_error; /* errors applying the transaction */ | int apply_error; /* errors applying the transaction */ | |||
int rollbacked; /* transactions that were rollbacked */ | int rollbacked; /* transactions that were rollbacked */ | |||
}; | }; | |||
/* on-disk structure */ | /* on-disk structures */ | |||
struct disk_trans { | ||||
/* header (fixed lenght, defined below) */ | /* header (fixed length, defined below) */ | |||
struct disk_header { | ||||
uint32_t id; /* id */ | uint32_t id; /* id */ | |||
uint32_t flags; /* flags about this transaction */ | uint32_t flags; /* flags about this transaction */ | |||
uint32_t len; /* data lenght */ | uint32_t numops; /* number of operations */ | |||
uint32_t plen; /* previous data lenght */ | }; | |||
uint32_t ulen; /* user-supplied information lenght */ | ||||
uint64_t offset; /* offset relative to the BOF */ | ||||
/* payload (variable lenght) */ | /* operation */ | |||
char *udata; /* user-supplied data */ | struct disk_operation { | |||
uint32_t len; /* data length */ | ||||
uint32_t plen; /* previous data length */ | ||||
uint64_t offset; /* offset relative to the BOF */ | ||||
char *prevdata; /* previous data for rollback */ | char *prevdata; /* previous data for rollback */ | |||
}; | }; | |||
/* core operations */ | /* core functions */ | |||
int jopen(struct jfs *fs, const char *name, int flags, int mode, int jflags ); | int jopen(struct jfs *fs, const char *name, int flags, int mode, int jflags ); | |||
void jtrans_init(struct jfs *fs, struct jtrans *ts); | void jtrans_init(struct jfs *fs, struct jtrans *ts); | |||
int jtrans_add(struct jtrans *ts, const void *buf, size_t count, off_t offs et); | ||||
int jtrans_commit(struct jtrans *ts); | int jtrans_commit(struct jtrans *ts); | |||
int jtrans_rollback(struct jtrans *ts); | int jtrans_rollback(struct jtrans *ts); | |||
void jtrans_free(struct jtrans *ts); | void jtrans_free(struct jtrans *ts); | |||
int jclose(struct jfs *fs); | int jclose(struct jfs *fs); | |||
/* journal checker */ | /* journal checker */ | |||
int jfsck(const char *name, struct jfsck_result *res); | int jfsck(const char *name, struct jfsck_result *res); | |||
int jfsck_cleanup(const char *name); | int jfsck_cleanup(const char *name); | |||
/* UNIX API wrappers */ | /* UNIX API wrappers */ | |||
ssize_t jread(struct jfs *fs, void *buf, size_t count); | ssize_t jread(struct jfs *fs, void *buf, size_t count); | |||
ssize_t jpread(struct jfs *fs, void *buf, size_t count, off_t offset); | ssize_t jpread(struct jfs *fs, void *buf, size_t count, off_t offset); | |||
ssize_t jreadv(struct jfs *fs, struct iovec *vector, int count); | ssize_t jreadv(struct jfs *fs, struct iovec *vector, int count); | |||
ssize_t jwrite(struct jfs *fs, const void *buf, size_t count); | ssize_t jwrite(struct jfs *fs, const void *buf, size_t count); | |||
ssize_t jpwrite(struct jfs *fs, const void *buf, size_t count, off_t offset ); | ssize_t jpwrite(struct jfs *fs, const void *buf, size_t count, off_t offset ); | |||
ssize_t jwritev(struct jfs *fs, const struct iovec *vector, int count); | ssize_t jwritev(struct jfs *fs, const struct iovec *vector, int count); | |||
int jtruncate(struct jfs *fs, off_t lenght); | int jtruncate(struct jfs *fs, off_t length); | |||
/* ANSI C stdio wrappers */ | /* ANSI C stdio wrappers */ | |||
struct jfs *jfopen(const char *path, const char *mode); | struct jfs *jfopen(const char *path, const char *mode); | |||
int jfclose(struct jfs *stream); | int jfclose(struct jfs *stream); | |||
struct jfs *jfreopen(const char *path, const char *mode, struct jfs *stream ); | struct jfs *jfreopen(const char *path, const char *mode, struct jfs *stream ); | |||
size_t jfread(void *ptr, size_t size, size_t nmemb, struct jfs *stream); | size_t jfread(void *ptr, size_t size, size_t nmemb, struct jfs *stream); | |||
size_t jfwrite(const void *ptr, size_t size, size_t nmemb, struct jfs *stre am); | size_t jfwrite(const void *ptr, size_t size, size_t nmemb, struct jfs *stre am); | |||
int jfileno(struct jfs *stream); | int jfileno(struct jfs *stream); | |||
int jfeof(struct jfs *stream); | int jfeof(struct jfs *stream); | |||
void jclearerr(struct jfs *stream); | void jclearerr(struct jfs *stream); | |||
skipping to change at line 113 | skipping to change at line 124 | |||
void frewind(struct jfs *stream); | void frewind(struct jfs *stream); | |||
FILE *jfsopen(struct jfs *stream, const char *mode); | FILE *jfsopen(struct jfs *stream, const char *mode); | |||
/* jfs constants */ | /* jfs constants */ | |||
#define J_NOLOCK 1 /* don't lock the file before operating on i t */ | #define J_NOLOCK 1 /* don't lock the file before operating on i t */ | |||
/* jtrans constants */ | /* jtrans constants */ | |||
#define J_COMMITED 1 /* mark a transaction as commited */ | #define J_COMMITED 1 /* mark a transaction as commited */ | |||
#define J_ROLLBACKED 2 /* mark a transaction as rollbacked */ | #define J_ROLLBACKED 2 /* mark a transaction as rollbacked */ | |||
/* disk_trans constants */ | /* disk constants */ | |||
#define J_DISKTFIXSIZE 28 /* lenght of disk_trans' header */ | #define J_DISKHEADSIZE 12 /* length of disk_header */ | |||
#define J_DISKOPHEADSIZE 16 /* length of disk_operation header */ | ||||
/* jfsck constants (return values) */ | /* jfsck constants (return values) */ | |||
#define J_ESUCCESS 0 /* success - shouldn't be used */ | #define J_ESUCCESS 0 /* success - shouldn't be used */ | |||
#define J_ENOENT 1 /* no such file */ | #define J_ENOENT 1 /* no such file */ | |||
#define J_ENOJOURNAL 2 /* no journal associated */ | #define J_ENOJOURNAL 2 /* no journal associated */ | |||
#define J_ENOMEM 3 /* no enough free memory */ | #define J_ENOMEM 3 /* no enough free memory */ | |||
#ifdef __cplusplus | #ifdef __cplusplus | |||
} /* from extern "C" avobe */ | } /* from extern "C" avobe */ | |||
#endif | #endif | |||
End of changes. 13 change blocks. | ||||
24 lines changed or deleted | 36 lines changed or added | |||