… | |
… | |
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 |
27 | # include <linux/types.h> |
31 | # include <linux/types.h> |
28 | # include <linux/fiemap.h> |
32 | # include <linux/fiemap.h> |
29 | # define HAVE_FIEMAP 1 |
33 | # define HAVE_FIEMAP 1 |
… | |
… | |
153 | #endif |
157 | #endif |
154 | #ifndef minor |
158 | #ifndef minor |
155 | # define minor(dev) ((dev) & 0xff) |
159 | # define minor(dev) ((dev) & 0xff) |
156 | #endif |
160 | #endif |
157 | |
161 | |
158 | #ifndef PAGESIZE |
162 | #if PAGESIZE <= 0 |
159 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
163 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
160 | #endif |
164 | #endif |
161 | |
165 | |
162 | /*****************************************************************************/ |
166 | /*****************************************************************************/ |
163 | |
167 | |
… | |
… | |
189 | fiemap->fm_start = req->offs; |
193 | fiemap->fm_start = req->offs; |
190 | fiemap->fm_length = req->size; |
194 | fiemap->fm_length = req->size; |
191 | fiemap->fm_flags = req->int2; |
195 | fiemap->fm_flags = req->int2; |
192 | fiemap->fm_extent_count = count; |
196 | fiemap->fm_extent_count = count; |
193 | |
197 | |
194 | if (ioctl (req->int1, FS_IOC_FIEMAP, fiemap)) |
198 | if (ioctl (req->int1, FS_IOC_FIEMAP, fiemap) < 0) |
195 | return; |
199 | return; |
196 | |
200 | |
197 | if (req->int3 >= 0 /* not autosizing */ |
201 | if (req->int3 >= 0 /* not autosizing */ |
198 | || !fiemap->fm_mapped_extents /* no more extents */ |
202 | || !fiemap->fm_mapped_extents /* no more extents */ |
199 | || fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_flags & FIEMAP_EXTENT_LAST /* hit eof */) |
203 | || fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_flags & FIEMAP_EXTENT_LAST /* hit eof */) |
200 | goto done; |
204 | goto done; |
201 | |
205 | |
202 | /* else we have to loop - |
206 | /* else we have to loop - |
203 | * it would be tempting (atcually I tried that first) to just query the |
207 | * it would be tempting (actually I tried that first) to just query the |
204 | * number of extents needed, but linux often feels like not returning all |
208 | * number of extents needed, but linux often feels like not returning all |
205 | * extents, without telling us it left any out. this complicates |
209 | * extents, without telling us it left any out. this complicates |
206 | * this quite a bit. |
210 | * this quite a bit. |
207 | */ |
211 | */ |
208 | |
212 | |
… | |
… | |
218 | + fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_length; |
222 | + fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_length; |
219 | incmap->fm_length = fiemap->fm_length - (incmap->fm_start - fiemap->fm_start); |
223 | incmap->fm_length = fiemap->fm_length - (incmap->fm_start - fiemap->fm_start); |
220 | incmap->fm_flags = fiemap->fm_flags; |
224 | incmap->fm_flags = fiemap->fm_flags; |
221 | incmap->fm_extent_count = (sizeof (scratch) - sizeof (struct fiemap)) / sizeof (struct fiemap_extent); |
225 | incmap->fm_extent_count = (sizeof (scratch) - sizeof (struct fiemap)) / sizeof (struct fiemap_extent); |
222 | |
226 | |
223 | if (ioctl (req->int1, FS_IOC_FIEMAP, incmap)) |
227 | if (ioctl (req->int1, FS_IOC_FIEMAP, incmap) < 0) |
224 | return; |
228 | return; |
|
|
229 | |
|
|
230 | if (!incmap->fm_mapped_extents) |
|
|
231 | goto done; |
225 | |
232 | |
226 | count = fiemap->fm_mapped_extents + incmap->fm_mapped_extents; |
233 | count = fiemap->fm_mapped_extents + incmap->fm_mapped_extents; |
227 | fiemap = realloc (fiemap, sizeof (*fiemap) + sizeof (struct fiemap_extent) * count); |
234 | fiemap = realloc (fiemap, sizeof (*fiemap) + sizeof (struct fiemap_extent) * count); |
228 | errno = ENOMEM; |
235 | errno = ENOMEM; |
229 | if (!fiemap) |
236 | if (!fiemap) |
… | |
… | |
301 | } |
308 | } |
302 | |
309 | |
303 | static SV * |
310 | static SV * |
304 | newSVaio_wd (aio_wd wd) |
311 | newSVaio_wd (aio_wd wd) |
305 | { |
312 | { |
306 | return sv_bless (newRV_noinc (newSViv ((IV)wd)), aio_wd_stash); |
313 | return sv_bless (newRV_noinc (newSViv ((intptr_t)wd)), aio_wd_stash); |
307 | } |
314 | } |
308 | |
315 | |
309 | static aio_req |
316 | static aio_req |
310 | SvAIO_REQ (SV *sv) |
317 | SvAIO_REQ (SV *sv) |
311 | { |
318 | { |
… | |
… | |
507 | #ifndef _WIN32 |
514 | #ifndef _WIN32 |
508 | if (req->result >= 0) |
515 | if (req->result >= 0) |
509 | { |
516 | { |
510 | EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); |
517 | EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); |
511 | 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)); |
512 | |
524 | |
513 | rv = sv_2mortal (newRV_noinc ((SV *)hv)); |
525 | rv = sv_2mortal (newRV_noinc ((SV *)hv)); |
514 | |
526 | |
515 | 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); |
516 | 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); |
… | |
… | |
518 | 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); |
519 | 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); |
520 | 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); |
521 | 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); |
522 | 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); |
523 | hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0); |
535 | hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (fsid ), 0); |
524 | 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); |
525 | 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); |
526 | } |
538 | } |
527 | #endif |
539 | #endif |
528 | |
540 | |
… | |
… | |
1131 | aio_fsync = EIO_FSYNC |
1143 | aio_fsync = EIO_FSYNC |
1132 | aio_fdatasync = EIO_FDATASYNC |
1144 | aio_fdatasync = EIO_FDATASYNC |
1133 | aio_syncfs = EIO_SYNCFS |
1145 | aio_syncfs = EIO_SYNCFS |
1134 | PPCODE: |
1146 | PPCODE: |
1135 | { |
1147 | { |
1136 | int fd = s_fileno_croak (fh, 0); |
1148 | int fd = s_fileno_croak (fh, 0); |
1137 | dREQ; |
1149 | dREQ; |
1138 | |
1150 | |
1139 | req->type = ix; |
1151 | req->type = ix; |
1140 | req->sv1 = newSVsv (fh); |
1152 | req->sv1 = newSVsv (fh); |
1141 | req->int1 = fd; |
1153 | req->int1 = fd; |
… | |
… | |
1145 | |
1157 | |
1146 | void |
1158 | void |
1147 | 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) |
1148 | PPCODE: |
1160 | PPCODE: |
1149 | { |
1161 | { |
1150 | int fd = s_fileno_croak (fh, 0); |
1162 | int fd = s_fileno_croak (fh, 0); |
1151 | dREQ; |
1163 | dREQ; |
1152 | |
1164 | |
1153 | req->type = EIO_SYNC_FILE_RANGE; |
1165 | req->type = EIO_SYNC_FILE_RANGE; |
1154 | req->sv1 = newSVsv (fh); |
1166 | req->sv1 = newSVsv (fh); |
1155 | req->int1 = fd; |
1167 | req->int1 = fd; |
… | |
… | |
1159 | |
1171 | |
1160 | REQ_SEND; |
1172 | REQ_SEND; |
1161 | } |
1173 | } |
1162 | |
1174 | |
1163 | void |
1175 | void |
1164 | 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) |
1165 | PPCODE: |
1177 | PPCODE: |
1166 | { |
1178 | { |
1167 | int fd = s_fileno_croak (fh, 0); |
1179 | int fd = s_fileno_croak (fh, 0); |
1168 | dREQ; |
1180 | dREQ; |
1169 | |
1181 | |
1170 | req->type = EIO_FALLOCATE; |
1182 | req->type = EIO_FALLOCATE; |
1171 | req->sv1 = newSVsv (fh); |
1183 | req->sv1 = newSVsv (fh); |
1172 | req->int1 = fd; |
1184 | req->int1 = fd; |
… | |
… | |
1180 | void |
1192 | void |
1181 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
1193 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
1182 | PPCODE: |
1194 | PPCODE: |
1183 | { |
1195 | { |
1184 | 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 */ |
1185 | int fd = s_fileno_croak (fh, 0); |
1197 | int fd = s_fileno_croak (fh, 0); |
1186 | dREQ; |
1198 | dREQ; |
1187 | |
1199 | |
1188 | if (expect_false (close_fd < 0)) |
1200 | if (expect_false (close_fd < 0)) |
1189 | { |
1201 | { |
1190 | int pipefd [2]; |
1202 | int pipefd [2]; |
… | |
… | |
1252 | len = svlen - dataoffset; |
1264 | len = svlen - dataoffset; |
1253 | } |
1265 | } |
1254 | else |
1266 | else |
1255 | { |
1267 | { |
1256 | /* read: check type and grow scalar as necessary */ |
1268 | /* read: check type and grow scalar as necessary */ |
1257 | SvUPGRADE (data, SVt_PV); |
|
|
1258 | if (SvLEN (data) >= SvCUR (data)) |
1269 | if (!SvPOK (data) || SvLEN (data) >= SvCUR (data)) |
1259 | svptr = SvGROW (data, len + dataoffset + 1); |
1270 | svptr = sv_grow (data, len + dataoffset + 1); |
1260 | else if (SvCUR (data) < len + dataoffset) |
1271 | else if (SvCUR (data) < len + dataoffset) |
1261 | croak ("length + dataoffset outside of scalar, and cannot grow"); |
1272 | croak ("length + dataoffset outside of scalar, and cannot grow"); |
1262 | } |
1273 | } |
1263 | |
1274 | |
1264 | { |
1275 | { |
… | |
… | |
1300 | |
1311 | |
1301 | void |
1312 | void |
1302 | 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) |
1303 | PPCODE: |
1314 | PPCODE: |
1304 | { |
1315 | { |
1305 | int ifd = s_fileno_croak (in_fh , 0); |
1316 | int ifd = s_fileno_croak (in_fh , 0); |
1306 | int ofd = s_fileno_croak (out_fh, 1); |
1317 | int ofd = s_fileno_croak (out_fh, 1); |
1307 | dREQ; |
1318 | dREQ; |
1308 | |
1319 | |
1309 | req->type = EIO_SENDFILE; |
1320 | req->type = EIO_SENDFILE; |
1310 | req->sv1 = newSVsv (out_fh); |
1321 | req->sv1 = newSVsv (out_fh); |
1311 | req->int1 = ofd; |
1322 | req->int1 = ofd; |
… | |
… | |
1319 | |
1330 | |
1320 | void |
1331 | void |
1321 | 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) |
1322 | PPCODE: |
1333 | PPCODE: |
1323 | { |
1334 | { |
1324 | int fd = s_fileno_croak (fh, 0); |
1335 | int fd = s_fileno_croak (fh, 0); |
1325 | dREQ; |
1336 | dREQ; |
1326 | |
1337 | |
1327 | req->type = EIO_READAHEAD; |
1338 | req->type = EIO_READAHEAD; |
1328 | req->sv1 = newSVsv (fh); |
1339 | req->sv1 = newSVsv (fh); |
1329 | req->int1 = fd; |
1340 | req->int1 = fd; |
… | |
… | |
1608 | { |
1619 | { |
1609 | dREQ; |
1620 | dREQ; |
1610 | |
1621 | |
1611 | req->type = EIO_GROUP; |
1622 | req->type = EIO_GROUP; |
1612 | |
1623 | |
|
|
1624 | PUTBACK; |
1613 | req_submit (req); |
1625 | req_submit (req); |
|
|
1626 | SPAGAIN; |
|
|
1627 | |
1614 | XPUSHs (req_sv (req, aio_grp_stash)); |
1628 | XPUSHs (req_sv (req, aio_grp_stash)); |
1615 | } |
1629 | } |
1616 | |
1630 | |
1617 | void |
1631 | void |
1618 | aio_nop (SV *callback=&PL_sv_undef) |
1632 | aio_nop (SV *callback=&PL_sv_undef) |
… | |
… | |
1727 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1741 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1728 | OUTPUT: |
1742 | OUTPUT: |
1729 | RETVAL |
1743 | RETVAL |
1730 | |
1744 | |
1731 | void |
1745 | void |
1732 | mmap (SV *scalar, size_t length, int prot, int flags, SV *fh = &PL_sv_undef, off_t offset = 0) |
1746 | mmap (SV *scalar, STRLEN length, int prot, int flags, SV *fh = &PL_sv_undef, off_t offset = 0) |
1733 | PPCODE: |
1747 | PPCODE: |
1734 | sv_unmagic (scalar, MMAP_MAGIC); |
1748 | sv_unmagic (scalar, MMAP_MAGIC); |
1735 | { |
1749 | { |
1736 | 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; |
1737 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
1751 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
… | |
… | |
1764 | munmap (SV *scalar) |
1778 | munmap (SV *scalar) |
1765 | CODE: |
1779 | CODE: |
1766 | sv_unmagic (scalar, MMAP_MAGIC); |
1780 | sv_unmagic (scalar, MMAP_MAGIC); |
1767 | |
1781 | |
1768 | int |
1782 | int |
1769 | 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) |
1770 | ALIAS: |
1784 | ALIAS: |
1771 | mprotect = 1 |
1785 | mprotect = 1 |
1772 | CODE: |
1786 | CODE: |
1773 | { |
1787 | { |
1774 | STRLEN svlen; |
1788 | STRLEN svlen; |
1775 | void *addr = SvPVbyte (scalar, svlen); |
1789 | void *addr = SvPVbyte (scalar, svlen); |
1776 | size_t len = SvUV (length); |
1790 | STRLEN len = SvUV (length); |
1777 | |
1791 | |
1778 | if (offset < 0) |
1792 | if (offset < 0) |
1779 | offset += svlen; |
1793 | offset += svlen; |
1780 | |
1794 | |
1781 | if (offset < 0 || offset > svlen) |
1795 | if (offset < 0 || offset > svlen) |
… | |
… | |
1795 | } |
1809 | } |
1796 | OUTPUT: |
1810 | OUTPUT: |
1797 | RETVAL |
1811 | RETVAL |
1798 | |
1812 | |
1799 | int |
1813 | int |
1800 | munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef) |
1814 | munlock (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef) |
1801 | CODE: |
1815 | CODE: |
1802 | { |
1816 | { |
1803 | STRLEN svlen; |
1817 | STRLEN svlen; |
1804 | void *addr = SvPVbyte (scalar, svlen); |
1818 | void *addr = SvPVbyte (scalar, svlen); |
1805 | size_t len = SvUV (length); |
1819 | size_t len = SvUV (length); |
1806 | |
1820 | |
1807 | if (offset < 0) |
1821 | if (offset < 0) |
1808 | offset += svlen; |
1822 | offset += svlen; |
1809 | |
1823 | |
… | |
… | |
1860 | RETVAL = tee (rfh, wfh, length, flags); |
1874 | RETVAL = tee (rfh, wfh, length, flags); |
1861 | #else |
1875 | #else |
1862 | RETVAL = EIO_ENOSYS (); |
1876 | RETVAL = EIO_ENOSYS (); |
1863 | #endif |
1877 | #endif |
1864 | OUTPUT: |
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; |
|
|
1892 | RETVAL = -1; |
|
|
1893 | #endif |
|
|
1894 | OUTPUT: |
1865 | RETVAL |
1895 | RETVAL |
1866 | |
1896 | |
1867 | void _on_next_submit (SV *cb) |
1897 | void _on_next_submit (SV *cb) |
1868 | CODE: |
1898 | CODE: |
1869 | SvREFCNT_dec (on_next_submit); |
1899 | SvREFCNT_dec (on_next_submit); |