… | |
… | |
19 | |
19 | |
20 | #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
20 | #if _POSIX_MEMLOCK || _POSIX_MEMLOCK_RANGE || _POSIX_MAPPED_FILES |
21 | # include <sys/mman.h> |
21 | # include <sys/mman.h> |
22 | #endif |
22 | #endif |
23 | |
23 | |
24 | #if __linux__ |
24 | /* the incompetent fool that created musl keeps __linux__, refuses |
|
|
25 | * to implement any linux standard apis, and also has no way to test |
|
|
26 | * for his broken iplementation. on't complain if this fails for you. |
|
|
27 | */ |
|
|
28 | #if __linux__ && (defined __GLIBC__ || defined __UCLIBC__) |
25 | # include <linux/fs.h> |
29 | # include <linux/fs.h> |
26 | # ifdef FS_IOC_FIEMAP |
30 | # ifdef FS_IOC_FIEMAP |
|
|
31 | # include <linux/types.h> |
27 | # include <linux/fiemap.h> |
32 | # include <linux/fiemap.h> |
28 | # define HAVE_FIEMAP 1 |
33 | # define HAVE_FIEMAP 1 |
29 | # endif |
34 | # endif |
30 | #endif |
35 | #endif |
31 | |
36 | |
… | |
… | |
152 | #endif |
157 | #endif |
153 | #ifndef minor |
158 | #ifndef minor |
154 | # define minor(dev) ((dev) & 0xff) |
159 | # define minor(dev) ((dev) & 0xff) |
155 | #endif |
160 | #endif |
156 | |
161 | |
157 | #ifndef PAGESIZE |
162 | #if PAGESIZE <= 0 |
158 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
163 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
159 | #endif |
164 | #endif |
160 | |
165 | |
161 | /*****************************************************************************/ |
166 | /*****************************************************************************/ |
162 | |
167 | |
… | |
… | |
164 | fiemap (eio_req *req) |
169 | fiemap (eio_req *req) |
165 | { |
170 | { |
166 | req->result = -1; |
171 | req->result = -1; |
167 | |
172 | |
168 | #if HAVE_FIEMAP |
173 | #if HAVE_FIEMAP |
|
|
174 | /* assume some c99 */ |
|
|
175 | struct fiemap *fiemap = 0; |
|
|
176 | size_t end_offset; |
|
|
177 | int count = req->int3; |
|
|
178 | |
|
|
179 | req->flags |= EIO_FLAG_PTR1_FREE; |
|
|
180 | |
|
|
181 | /* heuristic: start with 512 bytes (8 extents), and if that isn't enough, */ |
|
|
182 | /* increase in 3.5kb steps */ |
|
|
183 | if (count < 0) |
|
|
184 | count = 8; |
|
|
185 | |
|
|
186 | fiemap = malloc (sizeof (*fiemap) + sizeof (struct fiemap_extent) * count); |
|
|
187 | errno = ENOMEM; |
|
|
188 | if (!fiemap) |
|
|
189 | return; |
|
|
190 | |
|
|
191 | req->ptr1 = fiemap; |
|
|
192 | |
|
|
193 | fiemap->fm_start = req->offs; |
|
|
194 | fiemap->fm_length = req->size; |
|
|
195 | fiemap->fm_flags = req->int2; |
|
|
196 | fiemap->fm_extent_count = count; |
|
|
197 | |
|
|
198 | if (ioctl (req->int1, FS_IOC_FIEMAP, fiemap) < 0) |
|
|
199 | return; |
|
|
200 | |
|
|
201 | if (req->int3 >= 0 /* not autosizing */ |
|
|
202 | || !fiemap->fm_mapped_extents /* no more extents */ |
|
|
203 | || fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_flags & FIEMAP_EXTENT_LAST /* hit eof */) |
|
|
204 | goto done; |
|
|
205 | |
|
|
206 | /* else we have to loop - |
|
|
207 | * it would be tempting (actually I tried that first) to just query the |
|
|
208 | * number of extents needed, but linux often feels like not returning all |
|
|
209 | * extents, without telling us it left any out. this complicates |
|
|
210 | * this quite a bit. |
|
|
211 | */ |
|
|
212 | |
|
|
213 | end_offset = fiemap->fm_length + (fiemap->fm_length == FIEMAP_MAX_OFFSET ? 0 : fiemap->fm_start); |
|
|
214 | |
169 | for (;;) |
215 | for (;;) |
170 | { |
216 | { |
171 | int count = req->int3; |
217 | /* we go in 54 extent steps - 3kb, in the hope that this fits nicely on the eio stack (normally 16+ kb) */ |
|
|
218 | char scratch[3072]; |
|
|
219 | struct fiemap *incmap = (struct fiemap *)scratch; |
172 | |
220 | |
173 | if (count < 0) |
221 | incmap->fm_start = fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_logical |
174 | { |
222 | + fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_length; |
175 | struct fiemap fiemap; |
223 | incmap->fm_length = fiemap->fm_length - (incmap->fm_start - fiemap->fm_start); |
|
|
224 | incmap->fm_flags = fiemap->fm_flags; |
|
|
225 | incmap->fm_extent_count = (sizeof (scratch) - sizeof (struct fiemap)) / sizeof (struct fiemap_extent); |
176 | |
226 | |
177 | fiemap.fm_start = req->offs; |
|
|
178 | fiemap.fm_length = req->size; |
|
|
179 | fiemap.fm_flags = req->int2; |
|
|
180 | fiemap.fm_extent_count = 0; |
|
|
181 | |
|
|
182 | if (ioctl (req->int1, FS_IOC_FIEMAP, &fiemap)) |
227 | if (ioctl (req->int1, FS_IOC_FIEMAP, incmap) < 0) |
183 | return; |
228 | return; |
184 | |
229 | |
185 | count = fiemap.fm_mapped_extents; |
230 | if (!incmap->fm_mapped_extents) |
186 | } |
231 | goto done; |
187 | |
232 | |
|
|
233 | count = fiemap->fm_mapped_extents + incmap->fm_mapped_extents; |
188 | struct fiemap *fiemap = malloc (sizeof (*fiemap) + sizeof (struct fiemap_extent) * count); |
234 | fiemap = realloc (fiemap, sizeof (*fiemap) + sizeof (struct fiemap_extent) * count); |
189 | errno = ENOMEM; |
235 | errno = ENOMEM; |
190 | if (!fiemap) |
236 | if (!fiemap) |
191 | return; |
237 | return; |
192 | |
238 | |
193 | req->ptr1 = fiemap; |
239 | req->ptr1 = fiemap; |
194 | req->flags |= EIO_FLAG_PTR1_FREE; |
|
|
195 | |
240 | |
196 | fiemap->fm_start = req->offs; |
241 | for (count = 0; count < incmap->fm_mapped_extents; ++count) |
197 | fiemap->fm_length = req->size; |
242 | { |
198 | fiemap->fm_flags = req->int2; |
243 | struct fiemap_extent *e = incmap->fm_extents + count; |
199 | fiemap->fm_extent_count = count; |
|
|
200 | |
244 | |
201 | if (ioctl (req->int1, FS_IOC_FIEMAP, fiemap)) |
245 | if (e->fe_logical + e->fe_length >= end_offset) |
202 | return; |
246 | goto done; |
203 | |
247 | |
204 | if (req->int3 >= 0) |
248 | fiemap->fm_extents [fiemap->fm_mapped_extents++] = *e; |
205 | break; /* when not autosizing we are done */ |
|
|
206 | |
249 | |
207 | if (fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_flags & FIEMAP_EXTENT_LAST) |
250 | if (e->fe_flags & FIEMAP_EXTENT_LAST) |
208 | break; /* autosizing successful, we are done */ |
251 | goto done; |
209 | |
252 | |
210 | free (fiemap); |
253 | } |
211 | } |
254 | } |
212 | |
255 | |
|
|
256 | done: |
213 | req->result = 0; |
257 | req->result = 0; |
214 | |
258 | |
215 | #else |
259 | #else |
216 | errno = ENOSYS; |
260 | errno = ENOSYS; |
217 | #endif |
261 | #endif |
… | |
… | |
264 | } |
308 | } |
265 | |
309 | |
266 | static SV * |
310 | static SV * |
267 | newSVaio_wd (aio_wd wd) |
311 | newSVaio_wd (aio_wd wd) |
268 | { |
312 | { |
269 | return sv_bless (newRV_noinc (newSViv ((IV)wd)), aio_wd_stash); |
313 | return sv_bless (newRV_noinc (newSViv ((intptr_t)wd)), aio_wd_stash); |
270 | } |
314 | } |
271 | |
315 | |
272 | static aio_req |
316 | static aio_req |
273 | SvAIO_REQ (SV *sv) |
317 | SvAIO_REQ (SV *sv) |
274 | { |
318 | { |
… | |
… | |
470 | #ifndef _WIN32 |
514 | #ifndef _WIN32 |
471 | if (req->result >= 0) |
515 | if (req->result >= 0) |
472 | { |
516 | { |
473 | EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); |
517 | EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); |
474 | HV *hv = newHV (); |
518 | HV *hv = newHV (); |
|
|
519 | /* POSIX requires fsid to be unsigned long, but AIX in its infinite wisdom |
|
|
520 | * chooses to make it a struct. |
|
|
521 | */ |
|
|
522 | unsigned long fsid = 0; |
|
|
523 | memcpy (&fsid, &f->f_fsid, sizeof (unsigned long) < sizeof (f->f_fsid) ? sizeof (unsigned long) : sizeof (f->f_fsid)); |
475 | |
524 | |
476 | rv = sv_2mortal (newRV_noinc ((SV *)hv)); |
525 | rv = sv_2mortal (newRV_noinc ((SV *)hv)); |
477 | |
526 | |
478 | hv_store (hv, "bsize" , sizeof ("bsize" ) - 1, newSVval64 (f->f_bsize ), 0); |
527 | hv_store (hv, "bsize" , sizeof ("bsize" ) - 1, newSVval64 (f->f_bsize ), 0); |
479 | hv_store (hv, "frsize" , sizeof ("frsize" ) - 1, newSVval64 (f->f_frsize ), 0); |
528 | hv_store (hv, "frsize" , sizeof ("frsize" ) - 1, newSVval64 (f->f_frsize ), 0); |
… | |
… | |
481 | hv_store (hv, "bfree" , sizeof ("bfree" ) - 1, newSVval64 (f->f_bfree ), 0); |
530 | hv_store (hv, "bfree" , sizeof ("bfree" ) - 1, newSVval64 (f->f_bfree ), 0); |
482 | hv_store (hv, "bavail" , sizeof ("bavail" ) - 1, newSVval64 (f->f_bavail ), 0); |
531 | hv_store (hv, "bavail" , sizeof ("bavail" ) - 1, newSVval64 (f->f_bavail ), 0); |
483 | hv_store (hv, "files" , sizeof ("files" ) - 1, newSVval64 (f->f_files ), 0); |
532 | hv_store (hv, "files" , sizeof ("files" ) - 1, newSVval64 (f->f_files ), 0); |
484 | hv_store (hv, "ffree" , sizeof ("ffree" ) - 1, newSVval64 (f->f_ffree ), 0); |
533 | hv_store (hv, "ffree" , sizeof ("ffree" ) - 1, newSVval64 (f->f_ffree ), 0); |
485 | hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); |
534 | hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); |
486 | hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0); |
535 | hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (fsid ), 0); |
487 | hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); |
536 | hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); |
488 | hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); |
537 | hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); |
489 | } |
538 | } |
490 | #endif |
539 | #endif |
491 | |
540 | |
… | |
… | |
545 | break; |
594 | break; |
546 | |
595 | |
547 | case EIO_CUSTOM: |
596 | case EIO_CUSTOM: |
548 | if (req->feed == fiemap) |
597 | if (req->feed == fiemap) |
549 | { |
598 | { |
|
|
599 | #if HAVE_FIEMAP |
550 | if (!req->result) |
600 | if (!req->result) |
551 | { |
601 | { |
552 | struct fiemap *fiemap = (struct fiemap *)req->ptr1; |
602 | struct fiemap *fiemap = (struct fiemap *)req->ptr1; |
553 | |
603 | |
554 | if (fiemap->fm_extent_count) |
604 | if (fiemap->fm_extent_count) |
… | |
… | |
575 | { |
625 | { |
576 | SvIV_set (sv_result, fiemap->fm_mapped_extents); |
626 | SvIV_set (sv_result, fiemap->fm_mapped_extents); |
577 | PUSHs (sv_result); |
627 | PUSHs (sv_result); |
578 | } |
628 | } |
579 | } |
629 | } |
|
|
630 | #endif |
580 | } |
631 | } |
581 | else |
632 | else |
582 | PUSHs (sv_result); |
633 | PUSHs (sv_result); |
583 | break; |
634 | break; |
584 | |
635 | |
… | |
… | |
696 | } |
747 | } |
697 | |
748 | |
698 | /*****************************************************************************/ |
749 | /*****************************************************************************/ |
699 | |
750 | |
700 | #if !_POSIX_MAPPED_FILES |
751 | #if !_POSIX_MAPPED_FILES |
701 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
752 | # define mmap(addr,length,prot,flags,fd,offs) EIO_ENOSYS () |
702 | # define munmap(addr,length) (errno = ENOSYS, -1) |
753 | # define munmap(addr,length) EIO_ENOSYS () |
703 | #endif |
754 | #endif |
704 | |
755 | |
705 | #if !_POSIX_MEMORY_PROTECTION |
756 | #if !_POSIX_MEMORY_PROTECTION |
706 | # define mprotect(addr,len,prot) (errno = ENOSYS, -1) |
757 | # define mprotect(addr,len,prot) EIO_ENOSYS () |
707 | # define PROT_NONE 0 |
758 | # define PROT_NONE 0 |
708 | # define PROT_WRITE 0 |
759 | # define PROT_WRITE 0 |
709 | # define MAP_PRIVATE 0 |
760 | # define MAP_PRIVATE 0 |
710 | # define MAP_SHARED 0 |
761 | # define MAP_SHARED 0 |
711 | # define MAP_FIXED 0 |
762 | # define MAP_FIXED 0 |
… | |
… | |
954 | const_iv (FIEMAP_EXTENT_DATA_TAIL) |
1005 | const_iv (FIEMAP_EXTENT_DATA_TAIL) |
955 | const_iv (FIEMAP_EXTENT_UNWRITTEN) |
1006 | const_iv (FIEMAP_EXTENT_UNWRITTEN) |
956 | const_iv (FIEMAP_EXTENT_MERGED) |
1007 | const_iv (FIEMAP_EXTENT_MERGED) |
957 | const_iv (FIEMAP_EXTENT_SHARED) |
1008 | const_iv (FIEMAP_EXTENT_SHARED) |
958 | |
1009 | |
|
|
1010 | const_iv (SPLICE_F_MOVE) |
|
|
1011 | const_iv (SPLICE_F_NONBLOCK) |
|
|
1012 | const_iv (SPLICE_F_MORE) |
|
|
1013 | const_iv (SPLICE_F_GIFT) |
|
|
1014 | |
|
|
1015 | const_iv (SEEK_DATA) |
|
|
1016 | const_iv (SEEK_HOLE) |
|
|
1017 | |
|
|
1018 | /* libeio constants */ |
959 | const_eio (SEEK_SET) |
1019 | const_eio (SEEK_SET) |
960 | const_eio (SEEK_CUR) |
1020 | const_eio (SEEK_CUR) |
961 | const_eio (SEEK_END) |
1021 | const_eio (SEEK_END) |
962 | |
1022 | |
963 | const_eio (MCL_FUTURE) |
1023 | const_eio (MCL_FUTURE) |
… | |
… | |
972 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
1032 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
973 | const_eio (SYNC_FILE_RANGE_WRITE) |
1033 | const_eio (SYNC_FILE_RANGE_WRITE) |
974 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
1034 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
975 | |
1035 | |
976 | const_eio (FALLOC_FL_KEEP_SIZE) |
1036 | const_eio (FALLOC_FL_KEEP_SIZE) |
|
|
1037 | const_eio (FALLOC_FL_PUNCH_HOLE) |
977 | |
1038 | |
978 | const_eio (READDIR_DENTS) |
1039 | const_eio (READDIR_DENTS) |
979 | const_eio (READDIR_DIRS_FIRST) |
1040 | const_eio (READDIR_DIRS_FIRST) |
980 | const_eio (READDIR_STAT_ORDER) |
1041 | const_eio (READDIR_STAT_ORDER) |
981 | const_eio (READDIR_FOUND_UNKNOWN) |
1042 | const_eio (READDIR_FOUND_UNKNOWN) |
… | |
… | |
1082 | aio_fsync = EIO_FSYNC |
1143 | aio_fsync = EIO_FSYNC |
1083 | aio_fdatasync = EIO_FDATASYNC |
1144 | aio_fdatasync = EIO_FDATASYNC |
1084 | aio_syncfs = EIO_SYNCFS |
1145 | aio_syncfs = EIO_SYNCFS |
1085 | PPCODE: |
1146 | PPCODE: |
1086 | { |
1147 | { |
1087 | int fd = s_fileno_croak (fh, 0); |
1148 | int fd = s_fileno_croak (fh, 0); |
1088 | dREQ; |
1149 | dREQ; |
1089 | |
1150 | |
1090 | req->type = ix; |
1151 | req->type = ix; |
1091 | req->sv1 = newSVsv (fh); |
1152 | req->sv1 = newSVsv (fh); |
1092 | req->int1 = fd; |
1153 | req->int1 = fd; |
… | |
… | |
1096 | |
1157 | |
1097 | void |
1158 | void |
1098 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
1159 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
1099 | PPCODE: |
1160 | PPCODE: |
1100 | { |
1161 | { |
1101 | int fd = s_fileno_croak (fh, 0); |
1162 | int fd = s_fileno_croak (fh, 0); |
1102 | dREQ; |
1163 | dREQ; |
1103 | |
1164 | |
1104 | req->type = EIO_SYNC_FILE_RANGE; |
1165 | req->type = EIO_SYNC_FILE_RANGE; |
1105 | req->sv1 = newSVsv (fh); |
1166 | req->sv1 = newSVsv (fh); |
1106 | req->int1 = fd; |
1167 | req->int1 = fd; |
… | |
… | |
1110 | |
1171 | |
1111 | REQ_SEND; |
1172 | REQ_SEND; |
1112 | } |
1173 | } |
1113 | |
1174 | |
1114 | void |
1175 | void |
1115 | aio_fallocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef) |
1176 | aio_allocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef) |
1116 | PPCODE: |
1177 | PPCODE: |
1117 | { |
1178 | { |
1118 | int fd = s_fileno_croak (fh, 0); |
1179 | int fd = s_fileno_croak (fh, 0); |
1119 | dREQ; |
1180 | dREQ; |
1120 | |
1181 | |
1121 | req->type = EIO_FALLOCATE; |
1182 | req->type = EIO_FALLOCATE; |
1122 | req->sv1 = newSVsv (fh); |
1183 | req->sv1 = newSVsv (fh); |
1123 | req->int1 = fd; |
1184 | req->int1 = fd; |
… | |
… | |
1131 | void |
1192 | void |
1132 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
1193 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
1133 | PPCODE: |
1194 | PPCODE: |
1134 | { |
1195 | { |
1135 | static int close_fd = -1; /* dummy fd to close fds via dup2 */ |
1196 | static int close_fd = -1; /* dummy fd to close fds via dup2 */ |
1136 | int fd = s_fileno_croak (fh, 0); |
1197 | int fd = s_fileno_croak (fh, 0); |
1137 | dREQ; |
1198 | dREQ; |
1138 | |
1199 | |
1139 | if (expect_false (close_fd < 0)) |
1200 | if (expect_false (close_fd < 0)) |
1140 | { |
1201 | { |
1141 | int pipefd [2]; |
1202 | int pipefd [2]; |
… | |
… | |
1164 | |
1225 | |
1165 | void |
1226 | void |
1166 | aio_seek (SV *fh, SV *offset, int whence, SV *callback=&PL_sv_undef) |
1227 | aio_seek (SV *fh, SV *offset, int whence, SV *callback=&PL_sv_undef) |
1167 | PPCODE: |
1228 | PPCODE: |
1168 | { |
1229 | { |
1169 | STRLEN svlen; |
|
|
1170 | int fd = s_fileno_croak (fh, 0); |
1230 | int fd = s_fileno_croak (fh, 0); |
1171 | dREQ; |
1231 | dREQ; |
1172 | |
1232 | |
1173 | req->type = EIO_SEEK; |
1233 | req->type = EIO_SEEK; |
1174 | req->sv1 = newSVsv (fh); |
1234 | req->sv1 = newSVsv (fh); |
… | |
… | |
1204 | len = svlen - dataoffset; |
1264 | len = svlen - dataoffset; |
1205 | } |
1265 | } |
1206 | else |
1266 | else |
1207 | { |
1267 | { |
1208 | /* read: check type and grow scalar as necessary */ |
1268 | /* read: check type and grow scalar as necessary */ |
1209 | SvUPGRADE (data, SVt_PV); |
1269 | if (!SvPOK (data) || SvLEN (data) >= SvCUR (data)) |
1210 | svptr = SvGROW (data, len + dataoffset + 1); |
1270 | svptr = sv_grow (data, len + dataoffset + 1); |
|
|
1271 | else if (SvCUR (data) < len + dataoffset) |
|
|
1272 | croak ("length + dataoffset outside of scalar, and cannot grow"); |
1211 | } |
1273 | } |
1212 | |
1274 | |
1213 | { |
1275 | { |
1214 | dREQ; |
1276 | dREQ; |
1215 | |
1277 | |
… | |
… | |
1249 | |
1311 | |
1250 | void |
1312 | void |
1251 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
1313 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
1252 | PPCODE: |
1314 | PPCODE: |
1253 | { |
1315 | { |
1254 | int ifd = s_fileno_croak (in_fh , 0); |
1316 | int ifd = s_fileno_croak (in_fh , 0); |
1255 | int ofd = s_fileno_croak (out_fh, 1); |
1317 | int ofd = s_fileno_croak (out_fh, 1); |
1256 | dREQ; |
1318 | dREQ; |
1257 | |
1319 | |
1258 | req->type = EIO_SENDFILE; |
1320 | req->type = EIO_SENDFILE; |
1259 | req->sv1 = newSVsv (out_fh); |
1321 | req->sv1 = newSVsv (out_fh); |
1260 | req->int1 = ofd; |
1322 | req->int1 = ofd; |
… | |
… | |
1268 | |
1330 | |
1269 | void |
1331 | void |
1270 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
1332 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
1271 | PPCODE: |
1333 | PPCODE: |
1272 | { |
1334 | { |
1273 | int fd = s_fileno_croak (fh, 0); |
1335 | int fd = s_fileno_croak (fh, 0); |
1274 | dREQ; |
1336 | dREQ; |
1275 | |
1337 | |
1276 | req->type = EIO_READAHEAD; |
1338 | req->type = EIO_READAHEAD; |
1277 | req->sv1 = newSVsv (fh); |
1339 | req->sv1 = newSVsv (fh); |
1278 | req->int1 = fd; |
1340 | req->int1 = fd; |
… | |
… | |
1518 | |
1580 | |
1519 | void |
1581 | void |
1520 | aio_fiemap (SV *fh, off_t start, SV *length, U32 flags, SV *count, SV *callback=&PL_sv_undef) |
1582 | aio_fiemap (SV *fh, off_t start, SV *length, U32 flags, SV *count, SV *callback=&PL_sv_undef) |
1521 | PPCODE: |
1583 | PPCODE: |
1522 | { |
1584 | { |
1523 | int fd = s_fileno_croak (fh, 0); |
1585 | int fd = s_fileno_croak (fh, 0); |
1524 | dREQ; |
1586 | dREQ; |
1525 | |
1587 | |
1526 | req->type = EIO_CUSTOM; |
1588 | req->type = EIO_CUSTOM; |
1527 | req->sv1 = newSVsv (fh); |
1589 | req->sv1 = newSVsv (fh); |
1528 | req->int1 = fd; |
1590 | req->int1 = fd; |
1529 | |
1591 | |
1530 | req->feed = fiemap; |
1592 | req->feed = fiemap; |
|
|
1593 | #if HAVE_FIEMAP |
1531 | /* keep our fingers crossed that the next two types are 64 bit */ |
1594 | /* keep our fingers crossed that the next two types are 64 bit */ |
1532 | req->offs = start; |
1595 | req->offs = start; |
1533 | req->size = SvOK (length) ? SvVAL64 (length) : ~0ULL; |
1596 | req->size = SvOK (length) ? SvVAL64 (length) : ~0ULL; |
1534 | req->int2 = flags; |
1597 | req->int2 = flags; |
1535 | req->int3 = SvOK (count) ? SvIV (count) : -1; |
1598 | req->int3 = SvOK (count) ? SvIV (count) : -1; |
|
|
1599 | #endif |
1536 | |
1600 | |
1537 | REQ_SEND; |
1601 | REQ_SEND; |
1538 | } |
1602 | } |
1539 | |
1603 | |
1540 | void |
1604 | void |
… | |
… | |
1555 | { |
1619 | { |
1556 | dREQ; |
1620 | dREQ; |
1557 | |
1621 | |
1558 | req->type = EIO_GROUP; |
1622 | req->type = EIO_GROUP; |
1559 | |
1623 | |
|
|
1624 | PUTBACK; |
1560 | req_submit (req); |
1625 | req_submit (req); |
|
|
1626 | SPAGAIN; |
|
|
1627 | |
1561 | XPUSHs (req_sv (req, aio_grp_stash)); |
1628 | XPUSHs (req_sv (req, aio_grp_stash)); |
1562 | } |
1629 | } |
1563 | |
1630 | |
1564 | void |
1631 | void |
1565 | aio_nop (SV *callback=&PL_sv_undef) |
1632 | aio_nop (SV *callback=&PL_sv_undef) |
… | |
… | |
1674 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1741 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1675 | OUTPUT: |
1742 | OUTPUT: |
1676 | RETVAL |
1743 | RETVAL |
1677 | |
1744 | |
1678 | void |
1745 | void |
1679 | mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) |
1746 | mmap (SV *scalar, STRLEN length, int prot, int flags, SV *fh = &PL_sv_undef, off_t offset = 0) |
1680 | PPCODE: |
1747 | PPCODE: |
1681 | sv_unmagic (scalar, MMAP_MAGIC); |
1748 | sv_unmagic (scalar, MMAP_MAGIC); |
1682 | { |
1749 | { |
1683 | int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; |
1750 | int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; |
1684 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
1751 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
… | |
… | |
1711 | munmap (SV *scalar) |
1778 | munmap (SV *scalar) |
1712 | CODE: |
1779 | CODE: |
1713 | sv_unmagic (scalar, MMAP_MAGIC); |
1780 | sv_unmagic (scalar, MMAP_MAGIC); |
1714 | |
1781 | |
1715 | int |
1782 | int |
1716 | madvise (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) |
1783 | madvise (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef, IV advice_or_prot) |
1717 | ALIAS: |
1784 | ALIAS: |
1718 | mprotect = 1 |
1785 | mprotect = 1 |
1719 | CODE: |
1786 | CODE: |
1720 | { |
1787 | { |
1721 | STRLEN svlen; |
1788 | STRLEN svlen; |
1722 | void *addr = SvPVbyte (scalar, svlen); |
1789 | void *addr = SvPVbyte (scalar, svlen); |
1723 | size_t len = SvUV (length); |
1790 | STRLEN len = SvUV (length); |
1724 | |
1791 | |
1725 | if (offset < 0) |
1792 | if (offset < 0) |
1726 | offset += svlen; |
1793 | offset += svlen; |
1727 | |
1794 | |
1728 | if (offset < 0 || offset > svlen) |
1795 | if (offset < 0 || offset > svlen) |
… | |
… | |
1742 | } |
1809 | } |
1743 | OUTPUT: |
1810 | OUTPUT: |
1744 | RETVAL |
1811 | RETVAL |
1745 | |
1812 | |
1746 | int |
1813 | int |
1747 | munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef) |
1814 | munlock (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef) |
1748 | CODE: |
1815 | CODE: |
1749 | { |
1816 | { |
1750 | STRLEN svlen; |
1817 | STRLEN svlen; |
1751 | void *addr = SvPVbyte (scalar, svlen); |
1818 | void *addr = SvPVbyte (scalar, svlen); |
1752 | size_t len = SvUV (length); |
1819 | size_t len = SvUV (length); |
1753 | |
1820 | |
1754 | if (offset < 0) |
1821 | if (offset < 0) |
1755 | offset += svlen; |
1822 | offset += svlen; |
1756 | |
1823 | |
… | |
… | |
1763 | addr = (void *)(((intptr_t)addr) + offset); |
1830 | addr = (void *)(((intptr_t)addr) + offset); |
1764 | eio_page_align (&addr, &len); |
1831 | eio_page_align (&addr, &len); |
1765 | #if _POSIX_MEMLOCK_RANGE |
1832 | #if _POSIX_MEMLOCK_RANGE |
1766 | RETVAL = munlock (addr, len); |
1833 | RETVAL = munlock (addr, len); |
1767 | #else |
1834 | #else |
1768 | RETVAL = ((errno = ENOSYS), -1); |
1835 | RETVAL = EIO_ENOSYS (); |
1769 | #endif |
1836 | #endif |
1770 | } |
1837 | } |
1771 | OUTPUT: |
1838 | OUTPUT: |
1772 | RETVAL |
1839 | RETVAL |
1773 | |
1840 | |
… | |
… | |
1775 | munlockall () |
1842 | munlockall () |
1776 | CODE: |
1843 | CODE: |
1777 | #if _POSIX_MEMLOCK |
1844 | #if _POSIX_MEMLOCK |
1778 | munlockall (); |
1845 | munlockall (); |
1779 | #else |
1846 | #else |
|
|
1847 | RETVAL = EIO_ENOSYS (); |
|
|
1848 | #endif |
|
|
1849 | OUTPUT: |
|
|
1850 | RETVAL |
|
|
1851 | |
|
|
1852 | int |
|
|
1853 | splice (aio_rfd rfh, SV *off_in, aio_wfd wfh, SV *off_out, size_t length, unsigned int flags) |
|
|
1854 | CODE: |
|
|
1855 | { |
|
|
1856 | #if HAVE_LINUX_SPLICE |
|
|
1857 | loff_t off_in_, off_out_; |
|
|
1858 | RETVAL = splice ( |
|
|
1859 | rfh, SvOK (off_in ) ? (off_in_ = SvVAL64 (off_in )), &off_in_ : 0, |
|
|
1860 | wfh, SvOK (off_out) ? (off_out_ = SvVAL64 (off_out)), &off_out_ : 0, |
|
|
1861 | length, flags |
|
|
1862 | ); |
|
|
1863 | #else |
|
|
1864 | RETVAL = EIO_ENOSYS (); |
|
|
1865 | #endif |
|
|
1866 | } |
|
|
1867 | OUTPUT: |
|
|
1868 | RETVAL |
|
|
1869 | |
|
|
1870 | int |
|
|
1871 | tee (aio_rfd rfh, aio_wfd wfh, size_t length, unsigned int flags) |
|
|
1872 | CODE: |
|
|
1873 | #if HAVE_LINUX_SPLICE |
|
|
1874 | RETVAL = tee (rfh, wfh, length, flags); |
|
|
1875 | #else |
|
|
1876 | RETVAL = EIO_ENOSYS (); |
|
|
1877 | #endif |
|
|
1878 | OUTPUT: |
|
|
1879 | RETVAL |
|
|
1880 | |
|
|
1881 | int |
|
|
1882 | pipesize (aio_rfd rfh, int new_size = -1) |
|
|
1883 | PROTOTYPE: $;$ |
|
|
1884 | CODE: |
|
|
1885 | #if defined(F_SETPIPE_SZ) && defined(F_GETPIPE_SZ) |
|
|
1886 | if (new_size >= 0) |
|
|
1887 | RETVAL = fcntl (rfh, F_SETPIPE_SZ, new_size); |
|
|
1888 | else |
|
|
1889 | RETVAL = fcntl (rfh, F_GETPIPE_SZ); |
|
|
1890 | #else |
|
|
1891 | errno = ENOSYS; |
1780 | RETVAL = -1; |
1892 | RETVAL = -1; |
1781 | errno = ENOSYS; |
|
|
1782 | #endif |
1893 | #endif |
1783 | OUTPUT: |
1894 | OUTPUT: |
1784 | RETVAL |
1895 | RETVAL |
1785 | |
1896 | |
1786 | void _on_next_submit (SV *cb) |
1897 | void _on_next_submit (SV *cb) |