2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1997, 1998
5 * Sleepycat Software. All rights reserved.
11 static const char sccsid
[] = "@(#)os_rw.c 10.11 (Sleepycat) 10/12/98";
14 #ifndef NO_SYSTEM_INCLUDES
15 #include <sys/types.h>
28 * PUBLIC: int __os_io __P((DB_IO *, int, ssize_t *));
31 __os_io(db_iop
, op
, niop
)
41 if (__db_jump
.j_read
!= NULL
)
43 *niop
= pread(db_iop
->fd_io
, db_iop
->buf
,
44 db_iop
->bytes
, (off_t
)db_iop
->pgno
* db_iop
->pagesize
);
47 if (__db_jump
.j_write
!= NULL
)
49 *niop
= pwrite(db_iop
->fd_io
, db_iop
->buf
,
50 db_iop
->bytes
, (off_t
)db_iop
->pgno
* db_iop
->pagesize
);
53 if (*niop
== db_iop
->bytes
)
57 if (db_iop
->mutexp
!= NULL
)
58 (void)__db_mutex_lock(db_iop
->mutexp
, db_iop
->fd_lock
);
60 if ((ret
= __os_seek(db_iop
->fd_io
,
61 db_iop
->pagesize
, db_iop
->pgno
, 0, 0, SEEK_SET
)) != 0)
66 __os_read(db_iop
->fd_io
, db_iop
->buf
, db_iop
->bytes
, niop
);
70 __os_write(db_iop
->fd_io
, db_iop
->buf
, db_iop
->bytes
, niop
);
74 err
: if (db_iop
->mutexp
!= NULL
)
75 (void)__db_mutex_unlock(db_iop
->mutexp
, db_iop
->fd_lock
);
83 * Read from a file handle.
85 * PUBLIC: int __os_read __P((int, void *, size_t, ssize_t *));
88 __os_read(fd
, addr
, len
, nrp
)
99 offset
= 0; offset
< len
; taddr
+= nr
, offset
+= nr
) {
100 if ((nr
= __db_jump
.j_read
!= NULL
?
101 __db_jump
.j_read(fd
, taddr
, len
- offset
) :
102 read(fd
, taddr
, len
- offset
)) < 0)
107 *nrp
= taddr
- (u_int8_t
*)addr
;
113 * Write to a file handle.
115 * PUBLIC: int __os_write __P((int, void *, size_t, ssize_t *));
118 __os_write(fd
, addr
, len
, nwp
)
129 offset
= 0; offset
< len
; taddr
+= nw
, offset
+= nw
)
130 if ((nw
= __db_jump
.j_write
!= NULL
?
131 __db_jump
.j_write(fd
, taddr
, len
- offset
) :
132 write(fd
, taddr
, len
- offset
)) < 0)