From 4468706ca32a93838d78dddcae2cf6fd006d4e8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 4 Aug 2008 16:10:25 +0000 Subject: [PATCH] * Now uses _kern_write_stat() directly in order to resize the swap file without filling it with zeros (ie. make use of B_STAT_SIZE_INSECURE). * Added TODO that closing the file descriptor in swap_init_post_modules() (that should probably renamed to swap_init_post_boot_device()) is not really a good idea. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26797 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/vm/VMAnonymousCache.cpp | 24 ++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/system/kernel/vm/VMAnonymousCache.cpp b/src/system/kernel/vm/VMAnonymousCache.cpp index 8a92a6f95b..1912c7da66 100644 --- a/src/system/kernel/vm/VMAnonymousCache.cpp +++ b/src/system/kernel/vm/VMAnonymousCache.cpp @@ -16,17 +16,21 @@ #include #include -#include -#include #include +#include + +#include +#include +#include +#include #include +#include +#include +#include #include #include #include #include -#include -#include -#include #if ENABLE_SWAP_SUPPORT @@ -765,13 +769,19 @@ swap_init_post_modules() dprintf("Can't open/create /var/swap: %s\n", strerror(errno)); return; } - close(fd); - if (truncate("/var/swap", size) < 0) { + struct stat stat; + stat.st_size = size; + if (_kern_write_stat(fd, NULL, false, &stat, sizeof(struct stat), + B_STAT_SIZE | B_STAT_SIZE_INSECURE) != B_OK) { dprintf("Failed to resize /var/swap to %lld bytes: %s\n", size, strerror(errno)); } + close(fd); + // TODO: if we don't keep the file open, O_NOCACHE is going to be + // removed - we must not do this while we're using the swap file + swap_file_add("/var/swap"); }