… | |
… | |
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 |
… | |
… | |
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 | |
… | |
… | |
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) < 0) |
227 | if (ioctl (req->int1, FS_IOC_FIEMAP, incmap) < 0) |
224 | return; |
228 | return; |
225 | |
229 | |
|
|
230 | if (!incmap->fm_mapped_extents) |
|
|
231 | goto done; |
|
|
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) |
230 | return; |
237 | return; |
… | |
… | |
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 | { |
… | |
… | |
1257 | len = svlen - dataoffset; |
1264 | len = svlen - dataoffset; |
1258 | } |
1265 | } |
1259 | else |
1266 | else |
1260 | { |
1267 | { |
1261 | /* read: check type and grow scalar as necessary */ |
1268 | /* read: check type and grow scalar as necessary */ |
1262 | SvUPGRADE (data, SVt_PV); |
|
|
1263 | if (SvLEN (data) >= SvCUR (data)) |
1269 | if (!SvPOK (data) || SvLEN (data) >= SvCUR (data)) |
1264 | svptr = SvGROW (data, len + dataoffset + 1); |
1270 | svptr = sv_grow (data, len + dataoffset + 1); |
1265 | else if (SvCUR (data) < len + dataoffset) |
1271 | else if (SvCUR (data) < len + dataoffset) |
1266 | croak ("length + dataoffset outside of scalar, and cannot grow"); |
1272 | croak ("length + dataoffset outside of scalar, and cannot grow"); |
1267 | } |
1273 | } |
1268 | |
1274 | |
1269 | { |
1275 | { |
… | |
… | |
1613 | { |
1619 | { |
1614 | dREQ; |
1620 | dREQ; |
1615 | |
1621 | |
1616 | req->type = EIO_GROUP; |
1622 | req->type = EIO_GROUP; |
1617 | |
1623 | |
|
|
1624 | PUTBACK; |
1618 | req_submit (req); |
1625 | req_submit (req); |
|
|
1626 | SPAGAIN; |
|
|
1627 | |
1619 | XPUSHs (req_sv (req, aio_grp_stash)); |
1628 | XPUSHs (req_sv (req, aio_grp_stash)); |
1620 | } |
1629 | } |
1621 | |
1630 | |
1622 | void |
1631 | void |
1623 | aio_nop (SV *callback=&PL_sv_undef) |
1632 | aio_nop (SV *callback=&PL_sv_undef) |
… | |
… | |
1732 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1741 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1733 | OUTPUT: |
1742 | OUTPUT: |
1734 | RETVAL |
1743 | RETVAL |
1735 | |
1744 | |
1736 | void |
1745 | void |
1737 | 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) |
1738 | PPCODE: |
1747 | PPCODE: |
1739 | sv_unmagic (scalar, MMAP_MAGIC); |
1748 | sv_unmagic (scalar, MMAP_MAGIC); |
1740 | { |
1749 | { |
1741 | 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; |
1742 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
1751 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
… | |
… | |
1769 | munmap (SV *scalar) |
1778 | munmap (SV *scalar) |
1770 | CODE: |
1779 | CODE: |
1771 | sv_unmagic (scalar, MMAP_MAGIC); |
1780 | sv_unmagic (scalar, MMAP_MAGIC); |
1772 | |
1781 | |
1773 | int |
1782 | int |
1774 | 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) |
1775 | ALIAS: |
1784 | ALIAS: |
1776 | mprotect = 1 |
1785 | mprotect = 1 |
1777 | CODE: |
1786 | CODE: |
1778 | { |
1787 | { |
1779 | STRLEN svlen; |
1788 | STRLEN svlen; |
1780 | void *addr = SvPVbyte (scalar, svlen); |
1789 | void *addr = SvPVbyte (scalar, svlen); |
1781 | size_t len = SvUV (length); |
1790 | STRLEN len = SvUV (length); |
1782 | |
1791 | |
1783 | if (offset < 0) |
1792 | if (offset < 0) |
1784 | offset += svlen; |
1793 | offset += svlen; |
1785 | |
1794 | |
1786 | if (offset < 0 || offset > svlen) |
1795 | if (offset < 0 || offset > svlen) |
… | |
… | |
1800 | } |
1809 | } |
1801 | OUTPUT: |
1810 | OUTPUT: |
1802 | RETVAL |
1811 | RETVAL |
1803 | |
1812 | |
1804 | int |
1813 | int |
1805 | munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef) |
1814 | munlock (SV *scalar, STRLEN offset = 0, SV *length = &PL_sv_undef) |
1806 | CODE: |
1815 | CODE: |
1807 | { |
1816 | { |
1808 | STRLEN svlen; |
1817 | STRLEN svlen; |
1809 | void *addr = SvPVbyte (scalar, svlen); |
1818 | void *addr = SvPVbyte (scalar, svlen); |
1810 | size_t len = SvUV (length); |
1819 | size_t len = SvUV (length); |
… | |
… | |
1865 | RETVAL = tee (rfh, wfh, length, flags); |
1874 | RETVAL = tee (rfh, wfh, length, flags); |
1866 | #else |
1875 | #else |
1867 | RETVAL = EIO_ENOSYS (); |
1876 | RETVAL = EIO_ENOSYS (); |
1868 | #endif |
1877 | #endif |
1869 | 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: |
1870 | RETVAL |
1895 | RETVAL |
1871 | |
1896 | |
1872 | void _on_next_submit (SV *cb) |
1897 | void _on_next_submit (SV *cb) |
1873 | CODE: |
1898 | CODE: |
1874 | SvREFCNT_dec (on_next_submit); |
1899 | SvREFCNT_dec (on_next_submit); |