Date: Wed, 12 Nov 2014 00:10:27 +0000 (UTC) From: Marcel Moolenaar <marcel@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r274410 - head/usr.bin/mkimg Message-ID: <201411120010.sAC0ARwD099300@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: marcel Date: Wed Nov 12 00:10:27 2014 New Revision: 274410 URL: https://svnweb.freebsd.org/changeset/base/274410 Log: SEEK_DATA has interesting behaviour for sparse files on ZFS. A sparse file with 128K of random data and truncated to 800K can have SEEK_DATA return -1 when given an offset of 128K. On UFS, the SEEK_DATA returns 800K (the size of the file). SEEK_HOLE on ZFS seems to behave the same as UFS. To handle this, map -1 to the size of the file (`end') when lseek returns this for either SEEK_HOLE or SEEK_DATA. When sparse files are not supported by the file system both `hole' and `data' will now be equal to `end' and we will treat the entire file as data. This way, the -1 return for SEEK_DATA on ZFS will end up doing the right thing. Reported by: gjb@ MFC after: 3 days Modified: head/usr.bin/mkimg/image.c Modified: head/usr.bin/mkimg/image.c ============================================================================== --- head/usr.bin/mkimg/image.c Tue Nov 11 23:55:37 2014 (r274409) +++ head/usr.bin/mkimg/image.c Wed Nov 12 00:10:27 2014 (r274410) @@ -405,16 +405,18 @@ image_copyin_mapped(lba_t blk, int fd, u error = 0; while (!error && cur < end) { hole = lseek(fd, cur, SEEK_HOLE); + if (hole == -1) + hole = end; data = lseek(fd, cur, SEEK_DATA); + if (data == -1) + data = end; /* * Treat the entire file as data if sparse files * are not supported by the underlying file system. */ - if (hole == -1 && data == -1) { + if (hole == end && data == end) data = cur; - hole = end; - } if (cur == hole && data > hole) { hole = pos;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201411120010.sAC0ARwD099300>