29 #define USE_LOCKFILE_EX
32 ivbopen (
const char *pcfilename,
const int iflags,
const mode_t tmode)
41 if (stat (pcfilename, &sstat)) {
42 if (!iflags & O_CREAT) {
48 &&
svbfile[iloop].tdevice == sstat.st_dev
50 && !strcmp(
svbfile[iloop].cfilename, pcfilename)) {
59 for (iloop = 0; iloop < VB_MAX_FILES * 3; iloop++) {
60 if (
svbfile[iloop].irefcount == 0) {
62 if (
svbfile[iloop].ihandle == -1) {
65 if ((iflags & O_CREAT) && stat (pcfilename, &sstat)) {
72 free (
svbfile[iloop].cfilename);
74 svbfile[iloop].whandle = (HANDLE)_get_osfhandle (
svbfile[iloop].ihandle);
75 if (
svbfile[iloop].whandle == INVALID_HANDLE_VALUE) {
79 svbfile[iloop].cfilename = strdup (pcfilename);
95 if (!
svbfile[ihandle].irefcount) {
100 if (!
svbfile[ihandle].irefcount) {
101 return close (
svbfile[ihandle].ihandle);
107 tvblseek (
const int ihandle, off_t toffset,
const int iwhence)
113 return lseek (
svbfile[ihandle].ihandle, toffset, iwhence);
117 tvbread (
const int ihandle,
void *pvbuffer,
const size_t tcount)
123 return read (
svbfile[ihandle].ihandle, pvbuffer, tcount);
127 tvbwrite (
const int ihandle,
const void *pvbuffer,
const size_t tcount)
133 return write (
svbfile[ihandle].ihandle, pvbuffer, tcount);
137 ivbblockread (
const int ihandle,
const int iisindex,
const off_t tblocknumber,
char *cbuffer)
144 psvbptr = psvbfile[ihandle];
145 toffset = (off_t) ((tblocknumber - 1) * psvbptr->
inodesize);
151 if (
tvblseek (thandle, toffset, SEEK_SET) != toffset) {
156 if (!iisindex && tresult == 0) {
158 memset (cbuffer, 0, (
size_t)psvbptr->
inodesize);
160 if (tresult != (ssize_t)psvbptr->
inodesize) {
167 ivbblockwrite (
const int ihandle,
const int iisindex,
const off_t tblocknumber,
const char *cbuffer)
174 psvbptr = psvbfile[ihandle];
175 toffset = (off_t) ((tblocknumber - 1) * psvbptr->
inodesize);
185 if (
tvblseek (thandle, toffset, SEEK_SET) != toffset) {
190 if (tresult != (ssize_t)psvbptr->
inodesize) {
197 ivblock (
const int ihandle,
const off_t toffset,
const off_t tlength,
const int imode)
200 #ifdef USE_LOCKFILE_EX
202 OVERLAPPED toverlapped;
207 if (!
svbfile[ihandle].irefcount) {
218 tflags = LOCKFILE_FAIL_IMMEDIATELY;
226 tflags = LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY;
230 tflags = LOCKFILE_EXCLUSIVE_LOCK;
238 memset (&toverlapped, 0,
sizeof(OVERLAPPED));
239 toverlapped.Offset = (DWORD)(toffset & 0xffffffff);
240 toverlapped.OffsetHigh = (DWORD)(toffset >> 32);
243 if (LockFileEx (
svbfile[ihandle].whandle, tflags, 0, (
int)(tlength & 0xffffffff),
244 (
int)(tlength >> 32), &toverlapped)) {
248 if (UnlockFileEx (
svbfile[ihandle].whandle, 0, (
int)(tlength & 0xffffffff),
249 (
int)(tlength >> 32), &toverlapped)) {
252 winerrno = GetLastError ();
253 if (winerrno == ERROR_NOT_LOCKED) {
263 int itype, iresult = -1;
267 if (!
svbfile[ihandle].irefcount) {
296 soffset = lseek (
svbfile[ihandle].ihandle, 0, SEEK_CUR);
301 tempoffset = lseek (
svbfile[ihandle].ihandle, toffset, SEEK_SET);
302 if (tempoffset == -1) {
307 iresult = _locking (
svbfile[ihandle].ihandle, itype, (
long)tlength);
313 lseek (
svbfile[ihandle].ihandle, soffset, SEEK_SET);
317 int icommand, itype, iresult;
320 if (!
svbfile[ihandle].irefcount) {
354 sflock.l_type = itype;
355 sflock.l_whence = SEEK_SET;
356 sflock.l_start = toffset;
357 sflock.l_len = tlength;
360 iresult = fcntl (
svbfile[ihandle].ihandle, icommand, &sflock);
361 }
while (iresult && errno == EINTR);
int ivblock(const int ihandle, const off_t toffset, const off_t tlength, const int imode)
int ivbopen(const char *pcfilename, const int iflags, const mode_t tmode)
ssize_t tvbwrite(const int ihandle, const void *pvbuffer, const size_t tcount)
int ivbclose(const int ihandle)
int ivbblockwrite(const int ihandle, const int iisindex, const off_t tblocknumber, const char *cbuffer)
int ivbblockread(const int ihandle, const int iisindex, const off_t tblocknumber, char *cbuffer)
off_t tvblseek(const int ihandle, off_t toffset, const int iwhence)
struct VBFILE svbfile[128 *3]
ssize_t tvbread(const int ihandle, void *pvbuffer, const size_t tcount)
struct DICTINFO * psvbfile[128+1]