--- IO-AIO/AIO.xs 2012/04/06 11:39:25 1.210 +++ IO-AIO/AIO.xs 2012/04/07 00:50:33 1.211 @@ -166,25 +166,16 @@ req->result = -1; #if HAVE_FIEMAP - for (;;) - { - int count = req->int3; - - if (count < 0) - { - struct fiemap fiemap; - - fiemap.fm_start = req->offs; - fiemap.fm_length = req->size; - fiemap.fm_flags = req->int2; - fiemap.fm_extent_count = 0; + int count = req->int3; - if (ioctl (req->int1, FS_IOC_FIEMAP, &fiemap)) - return; - - count = fiemap.fm_mapped_extents; - } + /* heuristic: first try with 64 extents if we don't know how many, */ + /* as most files have (hopefully) fewer than this many extents */ + /* in fact, most should have <= 2, so maybe the 72 below is probably overkill */ + if (count < 0) + count = 72; /* for what it's worth, 72 extents fit nicely into 4kb */ + for (;;) + { struct fiemap *fiemap = malloc (sizeof (*fiemap) + sizeof (struct fiemap_extent) * count); errno = ENOMEM; if (!fiemap) @@ -207,6 +198,14 @@ if (fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_flags & FIEMAP_EXTENT_LAST) break; /* autosizing successful, we are done */ + fiemap->fm_flags = req->int2; + fiemap->fm_extent_count = 0; + + if (ioctl (req->int1, FS_IOC_FIEMAP, fiemap)) + return; + + count = fiemap->fm_mapped_extents; + free (fiemap); } @@ -547,6 +546,7 @@ case EIO_CUSTOM: if (req->feed == fiemap) { +#if HAVE_FIEMAP if (!req->result) { struct fiemap *fiemap = (struct fiemap *)req->ptr1; @@ -577,6 +577,7 @@ PUSHs (sv_result); } } +#endif } else PUSHs (sv_result); @@ -1166,7 +1167,6 @@ aio_seek (SV *fh, SV *offset, int whence, SV *callback=&PL_sv_undef) PPCODE: { - STRLEN svlen; int fd = s_fileno_croak (fh, 0); dREQ; @@ -1528,11 +1528,13 @@ req->int1 = fd; req->feed = fiemap; +#if HAVE_FIEMAP /* keep our fingers crossed that the next two types are 64 bit */ req->offs = start; req->size = SvOK (length) ? SvVAL64 (length) : ~0ULL; req->int2 = flags; req->int3 = SvOK (count) ? SvIV (count) : -1; +#endif REQ_SEND; }