Annotation of libaitio/src/aio.c, revision 1.1.2.2
1.1.2.1 misho 1: #include "global.h"
2:
3:
4: /*
1.1.2.2 ! misho 5: * io_rread() Raw VFS read function
1.1.2.1 misho 6: * @fd = File handle
7: * @buf = Read buffer
8: * @nbytes = Read buffer size
9: * @offset = Read from position, if -1 read nbytes from current position
10: * @update = Update file handle position !0
11: * return: -1 error or !=-1 readed bytes
12: */
13: inline int
14: io_rread(int fd, void * __restrict buf, size_t nbytes, off_t offset, int update)
15: {
16: int ret;
17: #ifdef AIO_OPS
18: struct aiocb acb;
19: #endif
20:
21: if (!buf) {
22: io_SetErr(EINVAL, "Error:: invalid arguments ...\n");
23: return -1;
24: }
25: if (!nbytes)
26: return 0;
27: if (offset == -1) {
28: offset = lseek(fd, 0, SEEK_CUR);
29: if (offset == -1) {
30: LOGERR;
31: return -1;
32: }
33: }
34:
35: #ifdef AIO_OPS
1.1.2.2 ! misho 36: /* This made for generate EOF for file */
! 37: if (update && offset >= lseek(fd, 0, SEEK_END))
! 38: return 0;
! 39:
1.1.2.1 misho 40: memset(buf, 0, nbytes);
41: memset(&acb, 0, sizeof acb);
42: acb.aio_fildes = fd;
43: acb.aio_nbytes = nbytes;
44: acb.aio_buf = buf;
45: acb.aio_offset = offset;
46:
47: if (aio_read(&acb) == -1) {
48: LOGERR;
49: return -1;
50: }
51:
52: while (aio_error(&acb) == EINPROGRESS);
53: ret = aio_return(&acb);
54: if (ret == -1) {
55: LOGERR;
56: return -1;
57: } else
58: ret = acb.aio_nbytes;
59: #else
60: ret = pread(fd, buf, nbytes, offset);
61: if (ret == -1) {
62: LOGERR;
63: return -1;
64: }
65: #endif
66:
67: if (update)
68: lseek(fd, offset + ret, SEEK_SET);
69:
70: return ret;
71: }
72:
73: /*
1.1.2.2 ! misho 74: * io_rwrite() Raw VFS write function
1.1.2.1 misho 75: * @fd = File handle
76: * @buf = Write buffer
77: * @nbytes = Write bytes from buffer
78: * @offset = Write at position, if -1 write nbytes from current position
79: * @update = Update file handle position !0
80: * return: -1 error or !=-1 writed bytes
81: */
82: inline int
83: io_rwrite(int fd, void * __restrict buf, size_t nbytes, off_t offset, int update)
84: {
85: int ret;
86: #ifdef AIO_OPS
87: struct aiocb acb;
88: #endif
89:
90: if (!buf) {
91: io_SetErr(EINVAL, "Error:: invalid arguments ...\n");
92: return -1;
93: }
94: if (!nbytes)
95: return 0;
96: if (offset == -1) {
97: offset = lseek(fd, 0, SEEK_CUR);
98: if (offset == -1) {
99: LOGERR;
100: return -1;
101: }
102: }
103:
104: #ifdef AIO_OPS
105: memset(&acb, 0, sizeof acb);
106: acb.aio_fildes = fd;
107: acb.aio_nbytes = nbytes;
108: acb.aio_buf = buf;
109: acb.aio_offset = offset;
110:
111: if (aio_write(&acb) == -1) {
112: LOGERR;
113: return -1;
114: }
115:
116: while (aio_error(&acb) == EINPROGRESS);
117: ret = aio_return(&acb);
118: if (ret == -1) {
119: LOGERR;
120: return -1;
121: } else
122: ret = acb.aio_nbytes;
123: #else
124: ret = pwrite(fd, buf, nbytes, offset);
125: if (ret == -1) {
126: LOGERR;
127: return -1;
128: }
129: #endif
130:
131: if (update)
132: lseek(fd, offset + ret, SEEK_SET);
133:
134:
135: return ret;
136: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>