root/jlog_io.h

Revision 9b8a62c4050371b1896f1b7751c6a4f675dd4e28, 3.7 kB (checked in by Theo Schlossnagle <jesus@omniti.com>, 7 years ago)

Offer these files under a new BSD-style license. Yay

  • Property mode set to 100644
Line 
1 /*
2  * Copyright (c) 2005-2007, OmniTI Computer Consulting, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met:
8  *
9  *    * Redistributions of source code must retain the above copyright
10  *      notice, this list of conditions and the following disclaimer.
11  *    * Redistributions in binary form must reproduce the above
12  *      copyright notice, this list of conditions and the following
13  *      disclaimer in the documentation and/or other materials provided
14  *      with the distribution.
15  *    * Neither the name OmniTI Computer Consulting, Inc. nor the names
16  *      of its contributors may be used to endorse or promote products
17  *      derived from this software without specific prior written
18  *      permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef _JLOG_IO_H_
34 #define _JLOG_IO_H_
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 typedef struct _jlog_file jlog_file;
41
42 /**
43  * opens a jlog_file
44  *
45  * since a jlog_file is a shared handle potentially used by many threads,
46  * the underlying open mode is always O_RDWR; only the O_CREAT and O_EXCL
47  * flags are honored
48  * @return pointer to jlog_file on success, NULL on failure
49  * @internal
50  */
51 jlog_file *jlog_file_open(const char *path, int flags, int mode);
52
53 /**
54  * closes a jlog_file
55  * @return 1 on success, 0 on failure
56  * @internal
57  */
58 int jlog_file_close(jlog_file *f);
59
60 /**
61  * exclusively locks a jlog_file against other processes and threads
62  * @return 1 on success, 0 on failure
63  * @internal
64  */
65 int jlog_file_lock(jlog_file *f);
66
67 /**
68  * unlocks a jlog_file
69  * @return 1 on success, 0 on failure
70  * @internal
71  */
72 int jlog_file_unlock(jlog_file *f);
73
74 /**
75  * preads from a jlog_file, retries EINTR
76  * @return 1 if the read was fully satisfied, 0 otherwise
77  * @internal
78  */
79 int jlog_file_pread(jlog_file *f, void *buf, size_t nbyte, off_t offset);
80
81 /**
82  * pwrites to a jlog_file, retries EINTR
83  * @return 1 if the write was fully satisfied, 0 otherwise
84  * @internal
85  */
86 int jlog_file_pwrite(jlog_file *f, const void *buf, size_t nbyte, off_t offset);
87
88 /**
89  * calls fdatasync (if avalable) or fsync on the underlying filehandle
90  * @return 1 on success, 0 on failure
91  * @internal
92  */
93 int jlog_file_sync(jlog_file *f);
94
95 /**
96  * maps the entirety of a jlog_file into memory for reading
97  * @param[out] map is set to the base of the mapped region
98  * @param[out] len is set to the length of the mapped region
99  * @return 1 on success, 0 on failure
100  * @internal
101  */
102 int jlog_file_map_read(jlog_file *f, void **base, size_t *len);
103
104 /**
105  * gives the size of a jlog_file
106  * @return size of file on success, -1 on failure
107  * @internal
108  */
109 off_t jlog_file_size(jlog_file *f);
110
111 /**
112  * truncates a jlog_file, retries EINTR
113  * @return 1 on success, 0 on failure
114  * @internal
115  */
116 int jlog_file_truncate(jlog_file *f, off_t len);
117
118 #ifdef __cplusplus
119 }  /* Close scope of 'extern "C"' declaration which encloses file. */
120 #endif
121
122 #endif /* _JLOG_IO_H_ */
123 /* vim:se ts=2 sw=2 et: */
Note: See TracBrowser for help on using the browser.