… | |
… | |
153 | #endif |
153 | #endif |
154 | #ifndef minor |
154 | #ifndef minor |
155 | # define minor(dev) ((dev) & 0xff) |
155 | # define minor(dev) ((dev) & 0xff) |
156 | #endif |
156 | #endif |
157 | |
157 | |
158 | #ifndef PAGESIZE |
158 | #if PAGESIZE <= 0 |
159 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
159 | # define PAGESIZE sysconf (_SC_PAGESIZE) |
160 | #endif |
160 | #endif |
161 | |
161 | |
162 | /*****************************************************************************/ |
162 | /*****************************************************************************/ |
163 | |
163 | |
… | |
… | |
165 | fiemap (eio_req *req) |
165 | fiemap (eio_req *req) |
166 | { |
166 | { |
167 | req->result = -1; |
167 | req->result = -1; |
168 | |
168 | |
169 | #if HAVE_FIEMAP |
169 | #if HAVE_FIEMAP |
|
|
170 | /* assume some c99 */ |
|
|
171 | struct fiemap *fiemap = 0; |
|
|
172 | size_t end_offset; |
170 | int count = req->int3; |
173 | int count = req->int3; |
171 | |
174 | |
172 | /* heuristic: first try with 72 extents if we don't know how many, */ |
175 | req->flags |= EIO_FLAG_PTR1_FREE; |
173 | /* as most files have (hopefully) fewer than this many extents */ |
176 | |
174 | /* in fact, most should have <= 2, so the 72 below is probably overkill */ |
177 | /* heuristic: start with 512 bytes (8 extents), and if that isn't enough, */ |
|
|
178 | /* increase in 3.5kb steps */ |
175 | if (count < 0) |
179 | if (count < 0) |
176 | count = 72; /* for what it's worth, 72 extents fit nicely into 4kb */ |
180 | count = 8; |
|
|
181 | |
|
|
182 | fiemap = malloc (sizeof (*fiemap) + sizeof (struct fiemap_extent) * count); |
|
|
183 | errno = ENOMEM; |
|
|
184 | if (!fiemap) |
|
|
185 | return; |
|
|
186 | |
|
|
187 | req->ptr1 = fiemap; |
|
|
188 | |
|
|
189 | fiemap->fm_start = req->offs; |
|
|
190 | fiemap->fm_length = req->size; |
|
|
191 | fiemap->fm_flags = req->int2; |
|
|
192 | fiemap->fm_extent_count = count; |
|
|
193 | |
|
|
194 | if (ioctl (req->int1, FS_IOC_FIEMAP, fiemap) < 0) |
|
|
195 | return; |
|
|
196 | |
|
|
197 | if (req->int3 >= 0 /* not autosizing */ |
|
|
198 | || !fiemap->fm_mapped_extents /* no more extents */ |
|
|
199 | || fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_flags & FIEMAP_EXTENT_LAST /* hit eof */) |
|
|
200 | goto done; |
|
|
201 | |
|
|
202 | /* else we have to loop - |
|
|
203 | * it would be tempting (atcually I tried that first) to just query the |
|
|
204 | * number of extents needed, but linux often feels like not returning all |
|
|
205 | * extents, without telling us it left any out. this complicates |
|
|
206 | * this quite a bit. |
|
|
207 | */ |
|
|
208 | |
|
|
209 | end_offset = fiemap->fm_length + (fiemap->fm_length == FIEMAP_MAX_OFFSET ? 0 : fiemap->fm_start); |
177 | |
210 | |
178 | for (;;) |
211 | for (;;) |
179 | { |
212 | { |
|
|
213 | /* we go in 54 extent steps - 3kb, in the hope that this fits nicely on the eio stack (normally 16+ kb) */ |
|
|
214 | char scratch[3072]; |
|
|
215 | struct fiemap *incmap = (struct fiemap *)scratch; |
|
|
216 | |
|
|
217 | incmap->fm_start = fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_logical |
|
|
218 | + fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_length; |
|
|
219 | incmap->fm_length = fiemap->fm_length - (incmap->fm_start - fiemap->fm_start); |
|
|
220 | incmap->fm_flags = fiemap->fm_flags; |
|
|
221 | incmap->fm_extent_count = (sizeof (scratch) - sizeof (struct fiemap)) / sizeof (struct fiemap_extent); |
|
|
222 | |
|
|
223 | if (ioctl (req->int1, FS_IOC_FIEMAP, incmap) < 0) |
|
|
224 | return; |
|
|
225 | |
|
|
226 | count = fiemap->fm_mapped_extents + incmap->fm_mapped_extents; |
180 | struct fiemap *fiemap = malloc (sizeof (*fiemap) + sizeof (struct fiemap_extent) * count); |
227 | fiemap = realloc (fiemap, sizeof (*fiemap) + sizeof (struct fiemap_extent) * count); |
181 | errno = ENOMEM; |
228 | errno = ENOMEM; |
182 | if (!fiemap) |
229 | if (!fiemap) |
183 | return; |
230 | return; |
184 | |
231 | |
185 | req->ptr1 = fiemap; |
232 | req->ptr1 = fiemap; |
186 | req->flags |= EIO_FLAG_PTR1_FREE; |
|
|
187 | |
233 | |
188 | fiemap->fm_start = req->offs; |
234 | for (count = 0; count < incmap->fm_mapped_extents; ++count) |
189 | fiemap->fm_length = req->size; |
235 | { |
190 | fiemap->fm_flags = req->int2; |
236 | struct fiemap_extent *e = incmap->fm_extents + count; |
191 | fiemap->fm_extent_count = count; |
|
|
192 | |
237 | |
193 | if (ioctl (req->int1, FS_IOC_FIEMAP, fiemap)) |
238 | if (e->fe_logical + e->fe_length >= end_offset) |
194 | return; |
239 | goto done; |
195 | |
240 | |
196 | if (req->int3 >= 0) |
241 | fiemap->fm_extents [fiemap->fm_mapped_extents++] = *e; |
197 | break; /* when not autosizing we are done */ |
|
|
198 | |
242 | |
199 | if (!fiemap->fm_mapped_extents) |
243 | if (e->fe_flags & FIEMAP_EXTENT_LAST) |
200 | break; /* if file has no segments, we are done */ |
244 | goto done; |
201 | |
245 | |
202 | if (fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_flags & FIEMAP_EXTENT_LAST) |
246 | } |
203 | break; /* autosizing successful, we are done */ |
|
|
204 | |
|
|
205 | fiemap->fm_flags = req->int2; |
|
|
206 | fiemap->fm_extent_count = 0; |
|
|
207 | |
|
|
208 | if (ioctl (req->int1, FS_IOC_FIEMAP, fiemap)) |
|
|
209 | return; |
|
|
210 | |
|
|
211 | count = fiemap->fm_mapped_extents; |
|
|
212 | |
|
|
213 | free (fiemap); |
|
|
214 | } |
247 | } |
215 | |
248 | |
|
|
249 | done: |
216 | req->result = 0; |
250 | req->result = 0; |
217 | |
251 | |
218 | #else |
252 | #else |
219 | errno = ENOSYS; |
253 | errno = ENOSYS; |
220 | #endif |
254 | #endif |
… | |
… | |
473 | #ifndef _WIN32 |
507 | #ifndef _WIN32 |
474 | if (req->result >= 0) |
508 | if (req->result >= 0) |
475 | { |
509 | { |
476 | EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); |
510 | EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); |
477 | HV *hv = newHV (); |
511 | HV *hv = newHV (); |
|
|
512 | /* POSIX requires fsid to be unsigned long, but AIX in its infinite wisdom |
|
|
513 | * chooses to make it a struct. |
|
|
514 | */ |
|
|
515 | unsigned long fsid = 0; |
|
|
516 | memcpy (&fsid, &f->f_fsid, sizeof (unsigned long) < sizeof (f->f_fsid) ? sizeof (unsigned long) : sizeof (f->f_fsid)); |
478 | |
517 | |
479 | rv = sv_2mortal (newRV_noinc ((SV *)hv)); |
518 | rv = sv_2mortal (newRV_noinc ((SV *)hv)); |
480 | |
519 | |
481 | hv_store (hv, "bsize" , sizeof ("bsize" ) - 1, newSVval64 (f->f_bsize ), 0); |
520 | hv_store (hv, "bsize" , sizeof ("bsize" ) - 1, newSVval64 (f->f_bsize ), 0); |
482 | hv_store (hv, "frsize" , sizeof ("frsize" ) - 1, newSVval64 (f->f_frsize ), 0); |
521 | hv_store (hv, "frsize" , sizeof ("frsize" ) - 1, newSVval64 (f->f_frsize ), 0); |
… | |
… | |
484 | hv_store (hv, "bfree" , sizeof ("bfree" ) - 1, newSVval64 (f->f_bfree ), 0); |
523 | hv_store (hv, "bfree" , sizeof ("bfree" ) - 1, newSVval64 (f->f_bfree ), 0); |
485 | hv_store (hv, "bavail" , sizeof ("bavail" ) - 1, newSVval64 (f->f_bavail ), 0); |
524 | hv_store (hv, "bavail" , sizeof ("bavail" ) - 1, newSVval64 (f->f_bavail ), 0); |
486 | hv_store (hv, "files" , sizeof ("files" ) - 1, newSVval64 (f->f_files ), 0); |
525 | hv_store (hv, "files" , sizeof ("files" ) - 1, newSVval64 (f->f_files ), 0); |
487 | hv_store (hv, "ffree" , sizeof ("ffree" ) - 1, newSVval64 (f->f_ffree ), 0); |
526 | hv_store (hv, "ffree" , sizeof ("ffree" ) - 1, newSVval64 (f->f_ffree ), 0); |
488 | hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); |
527 | hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); |
489 | hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0); |
528 | hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (fsid ), 0); |
490 | hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); |
529 | hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); |
491 | hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); |
530 | hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); |
492 | } |
531 | } |
493 | #endif |
532 | #endif |
494 | |
533 | |
… | |
… | |
1097 | aio_fsync = EIO_FSYNC |
1136 | aio_fsync = EIO_FSYNC |
1098 | aio_fdatasync = EIO_FDATASYNC |
1137 | aio_fdatasync = EIO_FDATASYNC |
1099 | aio_syncfs = EIO_SYNCFS |
1138 | aio_syncfs = EIO_SYNCFS |
1100 | PPCODE: |
1139 | PPCODE: |
1101 | { |
1140 | { |
1102 | int fd = s_fileno_croak (fh, 0); |
1141 | int fd = s_fileno_croak (fh, 0); |
1103 | dREQ; |
1142 | dREQ; |
1104 | |
1143 | |
1105 | req->type = ix; |
1144 | req->type = ix; |
1106 | req->sv1 = newSVsv (fh); |
1145 | req->sv1 = newSVsv (fh); |
1107 | req->int1 = fd; |
1146 | req->int1 = fd; |
… | |
… | |
1111 | |
1150 | |
1112 | void |
1151 | void |
1113 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
1152 | aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) |
1114 | PPCODE: |
1153 | PPCODE: |
1115 | { |
1154 | { |
1116 | int fd = s_fileno_croak (fh, 0); |
1155 | int fd = s_fileno_croak (fh, 0); |
1117 | dREQ; |
1156 | dREQ; |
1118 | |
1157 | |
1119 | req->type = EIO_SYNC_FILE_RANGE; |
1158 | req->type = EIO_SYNC_FILE_RANGE; |
1120 | req->sv1 = newSVsv (fh); |
1159 | req->sv1 = newSVsv (fh); |
1121 | req->int1 = fd; |
1160 | req->int1 = fd; |
… | |
… | |
1125 | |
1164 | |
1126 | REQ_SEND; |
1165 | REQ_SEND; |
1127 | } |
1166 | } |
1128 | |
1167 | |
1129 | void |
1168 | void |
1130 | aio_fallocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef) |
1169 | aio_allocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef) |
1131 | PPCODE: |
1170 | PPCODE: |
1132 | { |
1171 | { |
1133 | int fd = s_fileno_croak (fh, 0); |
1172 | int fd = s_fileno_croak (fh, 0); |
1134 | dREQ; |
1173 | dREQ; |
1135 | |
1174 | |
1136 | req->type = EIO_FALLOCATE; |
1175 | req->type = EIO_FALLOCATE; |
1137 | req->sv1 = newSVsv (fh); |
1176 | req->sv1 = newSVsv (fh); |
1138 | req->int1 = fd; |
1177 | req->int1 = fd; |
… | |
… | |
1146 | void |
1185 | void |
1147 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
1186 | aio_close (SV *fh, SV *callback=&PL_sv_undef) |
1148 | PPCODE: |
1187 | PPCODE: |
1149 | { |
1188 | { |
1150 | static int close_fd = -1; /* dummy fd to close fds via dup2 */ |
1189 | static int close_fd = -1; /* dummy fd to close fds via dup2 */ |
1151 | int fd = s_fileno_croak (fh, 0); |
1190 | int fd = s_fileno_croak (fh, 0); |
1152 | dREQ; |
1191 | dREQ; |
1153 | |
1192 | |
1154 | if (expect_false (close_fd < 0)) |
1193 | if (expect_false (close_fd < 0)) |
1155 | { |
1194 | { |
1156 | int pipefd [2]; |
1195 | int pipefd [2]; |
… | |
… | |
1266 | |
1305 | |
1267 | void |
1306 | void |
1268 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
1307 | aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) |
1269 | PPCODE: |
1308 | PPCODE: |
1270 | { |
1309 | { |
1271 | int ifd = s_fileno_croak (in_fh , 0); |
1310 | int ifd = s_fileno_croak (in_fh , 0); |
1272 | int ofd = s_fileno_croak (out_fh, 1); |
1311 | int ofd = s_fileno_croak (out_fh, 1); |
1273 | dREQ; |
1312 | dREQ; |
1274 | |
1313 | |
1275 | req->type = EIO_SENDFILE; |
1314 | req->type = EIO_SENDFILE; |
1276 | req->sv1 = newSVsv (out_fh); |
1315 | req->sv1 = newSVsv (out_fh); |
1277 | req->int1 = ofd; |
1316 | req->int1 = ofd; |
… | |
… | |
1285 | |
1324 | |
1286 | void |
1325 | void |
1287 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
1326 | aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) |
1288 | PPCODE: |
1327 | PPCODE: |
1289 | { |
1328 | { |
1290 | int fd = s_fileno_croak (fh, 0); |
1329 | int fd = s_fileno_croak (fh, 0); |
1291 | dREQ; |
1330 | dREQ; |
1292 | |
1331 | |
1293 | req->type = EIO_READAHEAD; |
1332 | req->type = EIO_READAHEAD; |
1294 | req->sv1 = newSVsv (fh); |
1333 | req->sv1 = newSVsv (fh); |
1295 | req->int1 = fd; |
1334 | req->int1 = fd; |
… | |
… | |
1765 | int |
1804 | int |
1766 | munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef) |
1805 | munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef) |
1767 | CODE: |
1806 | CODE: |
1768 | { |
1807 | { |
1769 | STRLEN svlen; |
1808 | STRLEN svlen; |
1770 | void *addr = SvPVbyte (scalar, svlen); |
1809 | void *addr = SvPVbyte (scalar, svlen); |
1771 | size_t len = SvUV (length); |
1810 | size_t len = SvUV (length); |
1772 | |
1811 | |
1773 | if (offset < 0) |
1812 | if (offset < 0) |
1774 | offset += svlen; |
1813 | offset += svlen; |
1775 | |
1814 | |