… | |
… | |
164 | fiemap (eio_req *req) |
164 | fiemap (eio_req *req) |
165 | { |
165 | { |
166 | req->result = -1; |
166 | req->result = -1; |
167 | |
167 | |
168 | #if HAVE_FIEMAP |
168 | #if HAVE_FIEMAP |
|
|
169 | int count = req->int3; |
|
|
170 | |
|
|
171 | /* heuristic: first try with 64 extents if we don't know how many, */ |
|
|
172 | /* 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 | if (count < 0) |
|
|
175 | count = 72; /* for what it's worth, 72 extents fit nicely into 4kb */ |
|
|
176 | |
169 | for (;;) |
177 | for (;;) |
170 | { |
178 | { |
171 | int count = req->int3; |
|
|
172 | |
|
|
173 | if (count < 0) |
|
|
174 | { |
|
|
175 | struct fiemap fiemap; |
|
|
176 | |
|
|
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)) |
|
|
183 | return; |
|
|
184 | |
|
|
185 | count = fiemap.fm_mapped_extents; |
|
|
186 | } |
|
|
187 | |
|
|
188 | struct fiemap *fiemap = malloc (sizeof (*fiemap) + sizeof (struct fiemap_extent) * count); |
179 | struct fiemap *fiemap = malloc (sizeof (*fiemap) + sizeof (struct fiemap_extent) * count); |
189 | errno = ENOMEM; |
180 | errno = ENOMEM; |
190 | if (!fiemap) |
181 | if (!fiemap) |
191 | return; |
182 | return; |
192 | |
183 | |
… | |
… | |
204 | if (req->int3 >= 0) |
195 | if (req->int3 >= 0) |
205 | break; /* when not autosizing we are done */ |
196 | break; /* when not autosizing we are done */ |
206 | |
197 | |
207 | if (fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_flags & FIEMAP_EXTENT_LAST) |
198 | if (fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_flags & FIEMAP_EXTENT_LAST) |
208 | break; /* autosizing successful, we are done */ |
199 | break; /* autosizing successful, we are done */ |
|
|
200 | |
|
|
201 | fiemap->fm_flags = req->int2; |
|
|
202 | fiemap->fm_extent_count = 0; |
|
|
203 | |
|
|
204 | if (ioctl (req->int1, FS_IOC_FIEMAP, fiemap)) |
|
|
205 | return; |
|
|
206 | |
|
|
207 | count = fiemap->fm_mapped_extents; |
209 | |
208 | |
210 | free (fiemap); |
209 | free (fiemap); |
211 | } |
210 | } |
212 | |
211 | |
213 | req->result = 0; |
212 | req->result = 0; |
… | |
… | |
545 | break; |
544 | break; |
546 | |
545 | |
547 | case EIO_CUSTOM: |
546 | case EIO_CUSTOM: |
548 | if (req->feed == fiemap) |
547 | if (req->feed == fiemap) |
549 | { |
548 | { |
|
|
549 | #if HAVE_FIEMAP |
550 | if (!req->result) |
550 | if (!req->result) |
551 | { |
551 | { |
552 | struct fiemap *fiemap = (struct fiemap *)req->ptr1; |
552 | struct fiemap *fiemap = (struct fiemap *)req->ptr1; |
553 | |
553 | |
554 | if (fiemap->fm_extent_count) |
554 | if (fiemap->fm_extent_count) |
… | |
… | |
575 | { |
575 | { |
576 | SvIV_set (sv_result, fiemap->fm_mapped_extents); |
576 | SvIV_set (sv_result, fiemap->fm_mapped_extents); |
577 | PUSHs (sv_result); |
577 | PUSHs (sv_result); |
578 | } |
578 | } |
579 | } |
579 | } |
|
|
580 | #endif |
580 | } |
581 | } |
581 | else |
582 | else |
582 | PUSHs (sv_result); |
583 | PUSHs (sv_result); |
583 | break; |
584 | break; |
584 | |
585 | |
… | |
… | |
1164 | |
1165 | |
1165 | void |
1166 | void |
1166 | aio_seek (SV *fh, SV *offset, int whence, SV *callback=&PL_sv_undef) |
1167 | aio_seek (SV *fh, SV *offset, int whence, SV *callback=&PL_sv_undef) |
1167 | PPCODE: |
1168 | PPCODE: |
1168 | { |
1169 | { |
1169 | STRLEN svlen; |
|
|
1170 | int fd = s_fileno_croak (fh, 0); |
1170 | int fd = s_fileno_croak (fh, 0); |
1171 | dREQ; |
1171 | dREQ; |
1172 | |
1172 | |
1173 | req->type = EIO_SEEK; |
1173 | req->type = EIO_SEEK; |
1174 | req->sv1 = newSVsv (fh); |
1174 | req->sv1 = newSVsv (fh); |
… | |
… | |
1526 | req->type = EIO_CUSTOM; |
1526 | req->type = EIO_CUSTOM; |
1527 | req->sv1 = newSVsv (fh); |
1527 | req->sv1 = newSVsv (fh); |
1528 | req->int1 = fd; |
1528 | req->int1 = fd; |
1529 | |
1529 | |
1530 | req->feed = fiemap; |
1530 | req->feed = fiemap; |
|
|
1531 | #if HAVE_FIEMAP |
1531 | /* keep our fingers crossed that the next two types are 64 bit */ |
1532 | /* keep our fingers crossed that the next two types are 64 bit */ |
1532 | req->offs = start; |
1533 | req->offs = start; |
1533 | req->size = SvOK (length) ? SvVAL64 (length) : ~0ULL; |
1534 | req->size = SvOK (length) ? SvVAL64 (length) : ~0ULL; |
1534 | req->int2 = flags; |
1535 | req->int2 = flags; |
1535 | req->int3 = SvOK (count) ? SvIV (count) : -1; |
1536 | req->int3 = SvOK (count) ? SvIV (count) : -1; |
|
|
1537 | #endif |
1536 | |
1538 | |
1537 | REQ_SEND; |
1539 | REQ_SEND; |
1538 | } |
1540 | } |
1539 | |
1541 | |
1540 | void |
1542 | void |