ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/IO-AIO/AIO.xs
(Generate patch)

Comparing IO-AIO/AIO.xs (file contents):
Revision 1.220 by root, Mon Jul 30 16:44:12 2012 UTC vs.
Revision 1.227 by root, Sat Sep 7 23:18:23 2013 UTC

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
189 fiemap->fm_start = req->offs; 189 fiemap->fm_start = req->offs;
190 fiemap->fm_length = req->size; 190 fiemap->fm_length = req->size;
191 fiemap->fm_flags = req->int2; 191 fiemap->fm_flags = req->int2;
192 fiemap->fm_extent_count = count; 192 fiemap->fm_extent_count = count;
193 193
194 if (ioctl (req->int1, FS_IOC_FIEMAP, fiemap)) 194 if (ioctl (req->int1, FS_IOC_FIEMAP, fiemap) < 0)
195 return; 195 return;
196 196
197 if (req->int3 >= 0 /* not autosizing */ 197 if (req->int3 >= 0 /* not autosizing */
198 || !fiemap->fm_mapped_extents /* no more extents */ 198 || !fiemap->fm_mapped_extents /* no more extents */
199 || fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_flags & FIEMAP_EXTENT_LAST /* hit eof */) 199 || fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_flags & FIEMAP_EXTENT_LAST /* hit eof */)
200 goto done; 200 goto done;
201 201
202 /* else we have to loop - 202 /* else we have to loop -
203 * it would be tempting (atcually I tried that first) to just query the 203 * 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 204 * number of extents needed, but linux often feels like not returning all
205 * extents, without telling us it left any out. this complicates 205 * extents, without telling us it left any out. this complicates
206 * this quite a bit. 206 * this quite a bit.
207 */ 207 */
208 208
218 + fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_length; 218 + fiemap->fm_extents [fiemap->fm_mapped_extents - 1].fe_length;
219 incmap->fm_length = fiemap->fm_length - (incmap->fm_start - fiemap->fm_start); 219 incmap->fm_length = fiemap->fm_length - (incmap->fm_start - fiemap->fm_start);
220 incmap->fm_flags = fiemap->fm_flags; 220 incmap->fm_flags = fiemap->fm_flags;
221 incmap->fm_extent_count = (sizeof (scratch) - sizeof (struct fiemap)) / sizeof (struct fiemap_extent); 221 incmap->fm_extent_count = (sizeof (scratch) - sizeof (struct fiemap)) / sizeof (struct fiemap_extent);
222 222
223 if (ioctl (req->int1, FS_IOC_FIEMAP, incmap)) 223 if (ioctl (req->int1, FS_IOC_FIEMAP, incmap) < 0)
224 return; 224 return;
225
226 if (!incmap->fm_mapped_extents)
227 goto done;
225 228
226 count = fiemap->fm_mapped_extents + incmap->fm_mapped_extents; 229 count = fiemap->fm_mapped_extents + incmap->fm_mapped_extents;
227 fiemap = realloc (fiemap, sizeof (*fiemap) + sizeof (struct fiemap_extent) * count); 230 fiemap = realloc (fiemap, sizeof (*fiemap) + sizeof (struct fiemap_extent) * count);
228 errno = ENOMEM; 231 errno = ENOMEM;
229 if (!fiemap) 232 if (!fiemap)
507#ifndef _WIN32 510#ifndef _WIN32
508 if (req->result >= 0) 511 if (req->result >= 0)
509 { 512 {
510 EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req); 513 EIO_STRUCT_STATVFS *f = EIO_STATVFS_BUF (req);
511 HV *hv = newHV (); 514 HV *hv = newHV ();
515 /* POSIX requires fsid to be unsigned long, but AIX in its infinite wisdom
516 * chooses to make it a struct.
517 */
518 unsigned long fsid = 0;
519 memcpy (&fsid, &f->f_fsid, sizeof (unsigned long) < sizeof (f->f_fsid) ? sizeof (unsigned long) : sizeof (f->f_fsid));
512 520
513 rv = sv_2mortal (newRV_noinc ((SV *)hv)); 521 rv = sv_2mortal (newRV_noinc ((SV *)hv));
514 522
515 hv_store (hv, "bsize" , sizeof ("bsize" ) - 1, newSVval64 (f->f_bsize ), 0); 523 hv_store (hv, "bsize" , sizeof ("bsize" ) - 1, newSVval64 (f->f_bsize ), 0);
516 hv_store (hv, "frsize" , sizeof ("frsize" ) - 1, newSVval64 (f->f_frsize ), 0); 524 hv_store (hv, "frsize" , sizeof ("frsize" ) - 1, newSVval64 (f->f_frsize ), 0);
518 hv_store (hv, "bfree" , sizeof ("bfree" ) - 1, newSVval64 (f->f_bfree ), 0); 526 hv_store (hv, "bfree" , sizeof ("bfree" ) - 1, newSVval64 (f->f_bfree ), 0);
519 hv_store (hv, "bavail" , sizeof ("bavail" ) - 1, newSVval64 (f->f_bavail ), 0); 527 hv_store (hv, "bavail" , sizeof ("bavail" ) - 1, newSVval64 (f->f_bavail ), 0);
520 hv_store (hv, "files" , sizeof ("files" ) - 1, newSVval64 (f->f_files ), 0); 528 hv_store (hv, "files" , sizeof ("files" ) - 1, newSVval64 (f->f_files ), 0);
521 hv_store (hv, "ffree" , sizeof ("ffree" ) - 1, newSVval64 (f->f_ffree ), 0); 529 hv_store (hv, "ffree" , sizeof ("ffree" ) - 1, newSVval64 (f->f_ffree ), 0);
522 hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0); 530 hv_store (hv, "favail" , sizeof ("favail" ) - 1, newSVval64 (f->f_favail ), 0);
523 hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (f->f_fsid ), 0); 531 hv_store (hv, "fsid" , sizeof ("fsid" ) - 1, newSVval64 (fsid ), 0);
524 hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0); 532 hv_store (hv, "flag" , sizeof ("flag" ) - 1, newSVval64 (f->f_flag ), 0);
525 hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0); 533 hv_store (hv, "namemax", sizeof ("namemax") - 1, newSVval64 (f->f_namemax), 0);
526 } 534 }
527#endif 535#endif
528 536
1131 aio_fsync = EIO_FSYNC 1139 aio_fsync = EIO_FSYNC
1132 aio_fdatasync = EIO_FDATASYNC 1140 aio_fdatasync = EIO_FDATASYNC
1133 aio_syncfs = EIO_SYNCFS 1141 aio_syncfs = EIO_SYNCFS
1134 PPCODE: 1142 PPCODE:
1135{ 1143{
1136 int fd = s_fileno_croak (fh, 0); 1144 int fd = s_fileno_croak (fh, 0);
1137 dREQ; 1145 dREQ;
1138 1146
1139 req->type = ix; 1147 req->type = ix;
1140 req->sv1 = newSVsv (fh); 1148 req->sv1 = newSVsv (fh);
1141 req->int1 = fd; 1149 req->int1 = fd;
1145 1153
1146void 1154void
1147aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef) 1155aio_sync_file_range (SV *fh, off_t offset, size_t nbytes, UV flags, SV *callback=&PL_sv_undef)
1148 PPCODE: 1156 PPCODE:
1149{ 1157{
1150 int fd = s_fileno_croak (fh, 0); 1158 int fd = s_fileno_croak (fh, 0);
1151 dREQ; 1159 dREQ;
1152 1160
1153 req->type = EIO_SYNC_FILE_RANGE; 1161 req->type = EIO_SYNC_FILE_RANGE;
1154 req->sv1 = newSVsv (fh); 1162 req->sv1 = newSVsv (fh);
1155 req->int1 = fd; 1163 req->int1 = fd;
1159 1167
1160 REQ_SEND; 1168 REQ_SEND;
1161} 1169}
1162 1170
1163void 1171void
1164aio_fallocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef) 1172aio_allocate (SV *fh, int mode, off_t offset, size_t len, SV *callback=&PL_sv_undef)
1165 PPCODE: 1173 PPCODE:
1166{ 1174{
1167 int fd = s_fileno_croak (fh, 0); 1175 int fd = s_fileno_croak (fh, 0);
1168 dREQ; 1176 dREQ;
1169 1177
1170 req->type = EIO_FALLOCATE; 1178 req->type = EIO_FALLOCATE;
1171 req->sv1 = newSVsv (fh); 1179 req->sv1 = newSVsv (fh);
1172 req->int1 = fd; 1180 req->int1 = fd;
1180void 1188void
1181aio_close (SV *fh, SV *callback=&PL_sv_undef) 1189aio_close (SV *fh, SV *callback=&PL_sv_undef)
1182 PPCODE: 1190 PPCODE:
1183{ 1191{
1184 static int close_fd = -1; /* dummy fd to close fds via dup2 */ 1192 static int close_fd = -1; /* dummy fd to close fds via dup2 */
1185 int fd = s_fileno_croak (fh, 0); 1193 int fd = s_fileno_croak (fh, 0);
1186 dREQ; 1194 dREQ;
1187 1195
1188 if (expect_false (close_fd < 0)) 1196 if (expect_false (close_fd < 0))
1189 { 1197 {
1190 int pipefd [2]; 1198 int pipefd [2];
1300 1308
1301void 1309void
1302aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef) 1310aio_sendfile (SV *out_fh, SV *in_fh, off_t in_offset, size_t length, SV *callback=&PL_sv_undef)
1303 PPCODE: 1311 PPCODE:
1304{ 1312{
1305 int ifd = s_fileno_croak (in_fh , 0); 1313 int ifd = s_fileno_croak (in_fh , 0);
1306 int ofd = s_fileno_croak (out_fh, 1); 1314 int ofd = s_fileno_croak (out_fh, 1);
1307 dREQ; 1315 dREQ;
1308 1316
1309 req->type = EIO_SENDFILE; 1317 req->type = EIO_SENDFILE;
1310 req->sv1 = newSVsv (out_fh); 1318 req->sv1 = newSVsv (out_fh);
1311 req->int1 = ofd; 1319 req->int1 = ofd;
1319 1327
1320void 1328void
1321aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef) 1329aio_readahead (SV *fh, off_t offset, size_t length, SV *callback=&PL_sv_undef)
1322 PPCODE: 1330 PPCODE:
1323{ 1331{
1324 int fd = s_fileno_croak (fh, 0); 1332 int fd = s_fileno_croak (fh, 0);
1325 dREQ; 1333 dREQ;
1326 1334
1327 req->type = EIO_READAHEAD; 1335 req->type = EIO_READAHEAD;
1328 req->sv1 = newSVsv (fh); 1336 req->sv1 = newSVsv (fh);
1329 req->int1 = fd; 1337 req->int1 = fd;
1799int 1807int
1800munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef) 1808munlock (SV *scalar, off_t offset = 0, SV *length = &PL_sv_undef)
1801 CODE: 1809 CODE:
1802{ 1810{
1803 STRLEN svlen; 1811 STRLEN svlen;
1804 void *addr = SvPVbyte (scalar, svlen); 1812 void *addr = SvPVbyte (scalar, svlen);
1805 size_t len = SvUV (length); 1813 size_t len = SvUV (length);
1806 1814
1807 if (offset < 0) 1815 if (offset < 0)
1808 offset += svlen; 1816 offset += svlen;
1809 1817
1860 RETVAL = tee (rfh, wfh, length, flags); 1868 RETVAL = tee (rfh, wfh, length, flags);
1861#else 1869#else
1862 RETVAL = EIO_ENOSYS (); 1870 RETVAL = EIO_ENOSYS ();
1863#endif 1871#endif
1864 OUTPUT: 1872 OUTPUT:
1873 RETVAL
1874
1875int
1876pipesize (aio_rfd rfh, int new_size = -1)
1877 PROTOTYPE: $;$
1878 CODE:
1879#if defined(F_SETPIPE_SZ) && defined(F_GETPIPE_SZ)
1880 if (new_size >= 0)
1881 RETVAL = fcntl (rfh, F_SETPIPE_SZ, new_size);
1882 else
1883 RETVAL = fcntl (rfh, F_GETPIPE_SZ);
1884#else
1885 errno = ENOSYS;
1886 RETVAL = -1;
1887#endif
1888 OUTPUT:
1865 RETVAL 1889 RETVAL
1866 1890
1867void _on_next_submit (SV *cb) 1891void _on_next_submit (SV *cb)
1868 CODE: 1892 CODE:
1869 SvREFCNT_dec (on_next_submit); 1893 SvREFCNT_dec (on_next_submit);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines