Add fallback when mmap fails on regular files. Some filesystems,

like smbnetfs, do not support mmap.

Reported by:	Harti Brandt
MFC after:	1 month
This commit is contained in:
Diomidis Spinellis 2008-10-27 15:21:15 +00:00
parent 1272ddb213
commit cce2092c73
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=184342

View File

@ -137,15 +137,14 @@ copy_file(const FTSENT *entp, int dne)
* Mmap and write if less than 8M (the limit is so we don't totally
* trash memory on big files. This is really a minor hack, but it
* wins some CPU back.
* Some filesystems, such as smbnetfs, don't support mmap,
* so this is a best-effort attempt.
*/
#ifdef VM_AND_BUFFER_CACHE_SYNCHRONIZED
if (S_ISREG(fs->st_mode) && fs->st_size > 0 &&
fs->st_size <= 8 * 1048576) {
if ((p = mmap(NULL, (size_t)fs->st_size, PROT_READ,
MAP_SHARED, from_fd, (off_t)0)) == MAP_FAILED) {
warn("%s", entp->fts_path);
rval = 1;
} else {
fs->st_size <= 8 * 1024 * 1024 &&
(p = mmap(NULL, (size_t)fs->st_size, PROT_READ,
MAP_SHARED, from_fd, (off_t)0)) != MAP_FAILED) {
wtotal = 0;
for (bufp = p, wresid = fs->st_size; ;
bufp += wcount, wresid -= (size_t)wcount) {
@ -172,7 +171,6 @@ copy_file(const FTSENT *entp, int dne)
warn("%s", entp->fts_path);
rval = 1;
}
}
} else
#endif
{