diff options
author | Changman Lee <cm224.lee@samsung.com> | 2015-03-24 02:57:43 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-03-24 02:57:43 +0000 |
commit | f2654fd7ae6d230a30105a375e2b8852fb1c87c2 (patch) | |
tree | 4bed296da7d15d258f5ecfa826dbd9bd93f74d64 | |
parent | f992212c2e36e1da9cdffafe9776db9bf77ef438 (diff) | |
parent | 650ad1e30cfa51d4e6db639e3da422385b7f7872 (diff) | |
download | f2fs-tools-f2654fd7ae6d230a30105a375e2b8852fb1c87c2.tar.gz |
am 650ad1e3: mkfs.f2fs: reclaim free space in case of regular file
* commit '650ad1e30cfa51d4e6db639e3da422385b7f7872':
mkfs.f2fs: reclaim free space in case of regular file
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | mkfs/f2fs_format_utils.c | 18 |
2 files changed, 17 insertions, 3 deletions
diff --git a/configure.ac b/configure.ac index 0111e72..d66cb73 100644 --- a/configure.ac +++ b/configure.ac @@ -57,7 +57,7 @@ PKG_CHECK_MODULES([libuuid], [uuid]) # Checks for header files. AC_CHECK_HEADERS([linux/fs.h fcntl.h mntent.h stdlib.h string.h \ - sys/ioctl.h sys/mount.h unistd.h]) + sys/ioctl.h sys/mount.h unistd.h linux/falloc.h]) # Checks for typedefs, structures, and compiler characteristics. AC_C_INLINE diff --git a/mkfs/f2fs_format_utils.c b/mkfs/f2fs_format_utils.c index 9892a8f..88b9953 100644 --- a/mkfs/f2fs_format_utils.c +++ b/mkfs/f2fs_format_utils.c @@ -6,18 +6,26 @@ * * Dual licensed under the GPL or LGPL version 2 licenses. */ +#define _LARGEFILE_SOURCE #define _LARGEFILE64_SOURCE +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif #include <stdio.h> #include <unistd.h> #include <sys/ioctl.h> #include <sys/stat.h> +#include <fcntl.h> #include "f2fs_fs.h" #ifdef HAVE_LINUX_FS_H #include <linux/fs.h> #endif +#ifdef HAVE_LINUX_FALLOC_H +#include <linux/falloc.h> +#endif int f2fs_trim_device() { @@ -37,9 +45,15 @@ int f2fs_trim_device() #if defined(WITH_BLKDISCARD) && defined(BLKDISCARD) MSG(0, "Info: Discarding device\n"); - if (S_ISREG(stat_buf.st_mode)) + if (S_ISREG(stat_buf.st_mode)) { +#ifdef FALLOC_FL_PUNCH_HOLE + if (fallocate(config.fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, + range[0], range[1]) < 0) { + MSG(0, "Info: fallocate(PUNCH_HOLE|KEEP_SIZE) is failed\n"); + } +#endif return 0; - else if (S_ISBLK(stat_buf.st_mode)) { + } else if (S_ISBLK(stat_buf.st_mode)) { if (ioctl(config.fd, BLKDISCARD, &range) < 0) { MSG(0, "Info: This device doesn't support TRIM\n"); } else { |