aboutsummaryrefslogtreecommitdiffstats
path: root/mkfs
diff options
context:
space:
mode:
authorChangman Lee <cm224.lee@samsung.com>2014-11-04 18:10:54 +0900
committerJP Abgrall <jpa@google.com>2015-03-23 10:10:26 -0700
commit650ad1e30cfa51d4e6db639e3da422385b7f7872 (patch)
tree4bed296da7d15d258f5ecfa826dbd9bd93f74d64 /mkfs
parent0f736527eb38eae3778b8be81921a9c458ad647f (diff)
downloadandroid_external_f2fs-tools-650ad1e30cfa51d4e6db639e3da422385b7f7872.tar.gz
android_external_f2fs-tools-650ad1e30cfa51d4e6db639e3da422385b7f7872.tar.bz2
android_external_f2fs-tools-650ad1e30cfa51d4e6db639e3da422385b7f7872.zip
mkfs.f2fs: reclaim free space in case of regular file
If we use regular file instead block device, let's reclaim its free space. Signed-off-by: Changman Lee <cm224.lee@samsung.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Diffstat (limited to 'mkfs')
-rw-r--r--mkfs/f2fs_format_utils.c18
1 files changed, 16 insertions, 2 deletions
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 {