… | |
… | |
22 | #endif |
22 | #endif |
23 | |
23 | |
24 | #if __linux__ |
24 | #if __linux__ |
25 | # include <linux/fs.h> |
25 | # include <linux/fs.h> |
26 | # ifdef FS_IOC_FIEMAP |
26 | # ifdef FS_IOC_FIEMAP |
|
|
27 | # include <linux/types.h> |
27 | # include <linux/fiemap.h> |
28 | # include <linux/fiemap.h> |
28 | # define HAVE_FIEMAP 1 |
29 | # define HAVE_FIEMAP 1 |
29 | # endif |
30 | # endif |
30 | #endif |
31 | #endif |
31 | |
32 | |
… | |
… | |
166 | req->result = -1; |
167 | req->result = -1; |
167 | |
168 | |
168 | #if HAVE_FIEMAP |
169 | #if HAVE_FIEMAP |
169 | int count = req->int3; |
170 | int count = req->int3; |
170 | |
171 | |
171 | /* heuristic: first try with 64 extents if we don't know how many, */ |
172 | /* heuristic: first try with 72 extents if we don't know how many, */ |
172 | /* as most files have (hopefully) fewer than this many extents */ |
173 | /* as most files have (hopefully) fewer than this many extents */ |
173 | /* in fact, most should have <= 2, so maybe the 72 below is probably overkill */ |
174 | /* in fact, most should have <= 2, so the 72 below is probably overkill */ |
174 | if (count < 0) |
175 | if (count < 0) |
175 | count = 72; /* for what it's worth, 72 extents fit nicely into 4kb */ |
176 | count = 72; /* for what it's worth, 72 extents fit nicely into 4kb */ |
176 | |
177 | |
177 | for (;;) |
178 | for (;;) |
178 | { |
179 | { |
… | |
… | |
193 | return; |
194 | return; |
194 | |
195 | |
195 | if (req->int3 >= 0) |
196 | if (req->int3 >= 0) |
196 | break; /* when not autosizing we are done */ |
197 | break; /* when not autosizing we are done */ |
197 | |
198 | |
198 | if (fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_flags & FIEMAP_EXTENT_LAST) |
199 | if (fiemap->fm_mapped_extents < count) |
199 | break; /* autosizing successful, we are done */ |
200 | /* either autosizing succeeded, |
|
|
201 | * or the file had no extents |
|
|
202 | * or we luckily had enough space */ |
|
|
203 | break; |
200 | |
204 | |
|
|
205 | /* some kernels overwrite fm_length, so just reset everything */ |
|
|
206 | fiemap->fm_start = req->offs; |
|
|
207 | fiemap->fm_length = req->size; |
201 | fiemap->fm_flags = req->int2; |
208 | fiemap->fm_flags = req->int2; |
202 | fiemap->fm_extent_count = 0; |
209 | fiemap->fm_extent_count = 0; |
203 | |
210 | |
204 | if (ioctl (req->int1, FS_IOC_FIEMAP, fiemap)) |
211 | if (ioctl (req->int1, FS_IOC_FIEMAP, fiemap)) |
205 | return; |
212 | return; |
206 | |
213 | |
|
|
214 | /* to work around a kernel bug, we allocate one more */ |
207 | count = fiemap->fm_mapped_extents; |
215 | count = fiemap->fm_mapped_extents + 1; |
208 | |
216 | |
209 | free (fiemap); |
217 | free (fiemap); |
210 | } |
218 | } |
211 | |
219 | |
212 | req->result = 0; |
220 | req->result = 0; |
… | |
… | |
697 | } |
705 | } |
698 | |
706 | |
699 | /*****************************************************************************/ |
707 | /*****************************************************************************/ |
700 | |
708 | |
701 | #if !_POSIX_MAPPED_FILES |
709 | #if !_POSIX_MAPPED_FILES |
702 | # define mmap(addr,length,prot,flags,fd,offs) (errno = ENOSYS, -1) |
710 | # define mmap(addr,length,prot,flags,fd,offs) EIO_ENOSYS () |
703 | # define munmap(addr,length) (errno = ENOSYS, -1) |
711 | # define munmap(addr,length) EIO_ENOSYS () |
704 | #endif |
712 | #endif |
705 | |
713 | |
706 | #if !_POSIX_MEMORY_PROTECTION |
714 | #if !_POSIX_MEMORY_PROTECTION |
707 | # define mprotect(addr,len,prot) (errno = ENOSYS, -1) |
715 | # define mprotect(addr,len,prot) EIO_ENOSYS () |
708 | # define PROT_NONE 0 |
716 | # define PROT_NONE 0 |
709 | # define PROT_WRITE 0 |
717 | # define PROT_WRITE 0 |
710 | # define MAP_PRIVATE 0 |
718 | # define MAP_PRIVATE 0 |
711 | # define MAP_SHARED 0 |
719 | # define MAP_SHARED 0 |
712 | # define MAP_FIXED 0 |
720 | # define MAP_FIXED 0 |
… | |
… | |
955 | const_iv (FIEMAP_EXTENT_DATA_TAIL) |
963 | const_iv (FIEMAP_EXTENT_DATA_TAIL) |
956 | const_iv (FIEMAP_EXTENT_UNWRITTEN) |
964 | const_iv (FIEMAP_EXTENT_UNWRITTEN) |
957 | const_iv (FIEMAP_EXTENT_MERGED) |
965 | const_iv (FIEMAP_EXTENT_MERGED) |
958 | const_iv (FIEMAP_EXTENT_SHARED) |
966 | const_iv (FIEMAP_EXTENT_SHARED) |
959 | |
967 | |
|
|
968 | const_iv (SPLICE_F_MOVE) |
|
|
969 | const_iv (SPLICE_F_NONBLOCK) |
|
|
970 | const_iv (SPLICE_F_MORE) |
|
|
971 | const_iv (SPLICE_F_GIFT) |
|
|
972 | |
|
|
973 | const_iv (SEEK_DATA) |
|
|
974 | const_iv (SEEK_HOLE) |
|
|
975 | |
|
|
976 | /* libeio constants */ |
960 | const_eio (SEEK_SET) |
977 | const_eio (SEEK_SET) |
961 | const_eio (SEEK_CUR) |
978 | const_eio (SEEK_CUR) |
962 | const_eio (SEEK_END) |
979 | const_eio (SEEK_END) |
963 | |
980 | |
964 | const_eio (MCL_FUTURE) |
981 | const_eio (MCL_FUTURE) |
… | |
… | |
973 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
990 | const_eio (SYNC_FILE_RANGE_WAIT_BEFORE) |
974 | const_eio (SYNC_FILE_RANGE_WRITE) |
991 | const_eio (SYNC_FILE_RANGE_WRITE) |
975 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
992 | const_eio (SYNC_FILE_RANGE_WAIT_AFTER) |
976 | |
993 | |
977 | const_eio (FALLOC_FL_KEEP_SIZE) |
994 | const_eio (FALLOC_FL_KEEP_SIZE) |
|
|
995 | const_eio (FALLOC_FL_PUNCH_HOLE) |
978 | |
996 | |
979 | const_eio (READDIR_DENTS) |
997 | const_eio (READDIR_DENTS) |
980 | const_eio (READDIR_DIRS_FIRST) |
998 | const_eio (READDIR_DIRS_FIRST) |
981 | const_eio (READDIR_STAT_ORDER) |
999 | const_eio (READDIR_STAT_ORDER) |
982 | const_eio (READDIR_FOUND_UNKNOWN) |
1000 | const_eio (READDIR_FOUND_UNKNOWN) |
… | |
… | |
1205 | } |
1223 | } |
1206 | else |
1224 | else |
1207 | { |
1225 | { |
1208 | /* read: check type and grow scalar as necessary */ |
1226 | /* read: check type and grow scalar as necessary */ |
1209 | SvUPGRADE (data, SVt_PV); |
1227 | SvUPGRADE (data, SVt_PV); |
|
|
1228 | if (SvLEN (data) >= SvCUR (data)) |
1210 | svptr = SvGROW (data, len + dataoffset + 1); |
1229 | svptr = SvGROW (data, len + dataoffset + 1); |
|
|
1230 | else if (SvCUR (data) < len + dataoffset) |
|
|
1231 | croak ("length + dataoffset outside of scalar, and cannot grow"); |
1211 | } |
1232 | } |
1212 | |
1233 | |
1213 | { |
1234 | { |
1214 | dREQ; |
1235 | dREQ; |
1215 | |
1236 | |
… | |
… | |
1518 | |
1539 | |
1519 | void |
1540 | void |
1520 | aio_fiemap (SV *fh, off_t start, SV *length, U32 flags, SV *count, SV *callback=&PL_sv_undef) |
1541 | aio_fiemap (SV *fh, off_t start, SV *length, U32 flags, SV *count, SV *callback=&PL_sv_undef) |
1521 | PPCODE: |
1542 | PPCODE: |
1522 | { |
1543 | { |
1523 | int fd = s_fileno_croak (fh, 0); |
1544 | int fd = s_fileno_croak (fh, 0); |
1524 | dREQ; |
1545 | dREQ; |
1525 | |
1546 | |
1526 | req->type = EIO_CUSTOM; |
1547 | req->type = EIO_CUSTOM; |
1527 | req->sv1 = newSVsv (fh); |
1548 | req->sv1 = newSVsv (fh); |
1528 | req->int1 = fd; |
1549 | req->int1 = fd; |
… | |
… | |
1676 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1697 | RETVAL = eio_sendfile_sync (ofh, ifh, offset, count); |
1677 | OUTPUT: |
1698 | OUTPUT: |
1678 | RETVAL |
1699 | RETVAL |
1679 | |
1700 | |
1680 | void |
1701 | void |
1681 | mmap (SV *scalar, size_t length, int prot, int flags, SV *fh, off_t offset = 0) |
1702 | mmap (SV *scalar, size_t length, int prot, int flags, SV *fh = &PL_sv_undef, off_t offset = 0) |
1682 | PPCODE: |
1703 | PPCODE: |
1683 | sv_unmagic (scalar, MMAP_MAGIC); |
1704 | sv_unmagic (scalar, MMAP_MAGIC); |
1684 | { |
1705 | { |
1685 | int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; |
1706 | int fd = SvOK (fh) ? s_fileno_croak (fh, flags & PROT_WRITE) : -1; |
1686 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
1707 | void *addr = (void *)mmap (0, length, prot, flags, fd, offset); |
… | |
… | |
1719 | ALIAS: |
1740 | ALIAS: |
1720 | mprotect = 1 |
1741 | mprotect = 1 |
1721 | CODE: |
1742 | CODE: |
1722 | { |
1743 | { |
1723 | STRLEN svlen; |
1744 | STRLEN svlen; |
1724 | void *addr = SvPVbyte (scalar, svlen); |
1745 | void *addr = SvPVbyte (scalar, svlen); |
1725 | size_t len = SvUV (length); |
1746 | size_t len = SvUV (length); |
1726 | |
1747 | |
1727 | if (offset < 0) |
1748 | if (offset < 0) |
1728 | offset += svlen; |
1749 | offset += svlen; |
1729 | |
1750 | |
… | |
… | |
1765 | addr = (void *)(((intptr_t)addr) + offset); |
1786 | addr = (void *)(((intptr_t)addr) + offset); |
1766 | eio_page_align (&addr, &len); |
1787 | eio_page_align (&addr, &len); |
1767 | #if _POSIX_MEMLOCK_RANGE |
1788 | #if _POSIX_MEMLOCK_RANGE |
1768 | RETVAL = munlock (addr, len); |
1789 | RETVAL = munlock (addr, len); |
1769 | #else |
1790 | #else |
1770 | RETVAL = ((errno = ENOSYS), -1); |
1791 | RETVAL = EIO_ENOSYS (); |
1771 | #endif |
1792 | #endif |
1772 | } |
1793 | } |
1773 | OUTPUT: |
1794 | OUTPUT: |
1774 | RETVAL |
1795 | RETVAL |
1775 | |
1796 | |
… | |
… | |
1777 | munlockall () |
1798 | munlockall () |
1778 | CODE: |
1799 | CODE: |
1779 | #if _POSIX_MEMLOCK |
1800 | #if _POSIX_MEMLOCK |
1780 | munlockall (); |
1801 | munlockall (); |
1781 | #else |
1802 | #else |
1782 | RETVAL = -1; |
1803 | RETVAL = EIO_ENOSYS (); |
1783 | errno = ENOSYS; |
|
|
1784 | #endif |
1804 | #endif |
1785 | OUTPUT: |
1805 | OUTPUT: |
|
|
1806 | RETVAL |
|
|
1807 | |
|
|
1808 | int |
|
|
1809 | splice (aio_rfd rfh, SV *off_in, aio_wfd wfh, SV *off_out, size_t length, unsigned int flags) |
|
|
1810 | CODE: |
|
|
1811 | { |
|
|
1812 | #if HAVE_LINUX_SPLICE |
|
|
1813 | loff_t off_in_, off_out_; |
|
|
1814 | RETVAL = splice ( |
|
|
1815 | rfh, SvOK (off_in ) ? (off_in_ = SvVAL64 (off_in )), &off_in_ : 0, |
|
|
1816 | wfh, SvOK (off_out) ? (off_out_ = SvVAL64 (off_out)), &off_out_ : 0, |
|
|
1817 | length, flags |
|
|
1818 | ); |
|
|
1819 | #else |
|
|
1820 | RETVAL = EIO_ENOSYS (); |
|
|
1821 | #endif |
|
|
1822 | } |
|
|
1823 | OUTPUT: |
|
|
1824 | RETVAL |
|
|
1825 | |
|
|
1826 | int |
|
|
1827 | tee (aio_rfd rfh, aio_wfd wfh, size_t length, unsigned int flags) |
|
|
1828 | CODE: |
|
|
1829 | #if HAVE_LINUX_SPLICE |
|
|
1830 | RETVAL = tee (rfh, wfh, length, flags); |
|
|
1831 | #else |
|
|
1832 | RETVAL = EIO_ENOSYS (); |
|
|
1833 | #endif |
|
|
1834 | OUTPUT: |
1786 | RETVAL |
1835 | RETVAL |
1787 | |
1836 | |
1788 | void _on_next_submit (SV *cb) |
1837 | void _on_next_submit (SV *cb) |
1789 | CODE: |
1838 | CODE: |
1790 | SvREFCNT_dec (on_next_submit); |
1839 | SvREFCNT_dec (on_next_submit); |