aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2024-02-28 21:01:52 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2024-02-28 21:01:52 +0000
commit732db49c86f43ec23875407254c8c1a3a1ea0a6d (patch)
tree307c9ccbc13a4021f87cff4fd99e792a52b22c3f
parente7b2c9234873dfbb0defb86680fb29e6441ece43 (diff)
parent4da5db5d0af02537769b4b74e3174161bbdc5260 (diff)
downloadf2fs-tools-simpleperf-release.tar.gz
Snap for 11510257 from 4da5db5d0af02537769b4b74e3174161bbdc5260 to simpleperf-releasesimpleperf-release
Change-Id: Ic81ab071f16b8b798eb242cb26f33919dbee10c0
-rw-r--r--METADATA10
-rw-r--r--configure.ac2
-rw-r--r--fsck/fsck.c2
-rw-r--r--fsck/main.c4
-rw-r--r--fsck/mount.c38
-rw-r--r--include/android_config.h2
-rw-r--r--include/f2fs_fs.h1
-rw-r--r--lib/libf2fs.c81
-rw-r--r--lib/libf2fs_io.c26
-rw-r--r--mkfs/f2fs_format.c10
-rw-r--r--mkfs/f2fs_format_main.c7
11 files changed, 136 insertions, 47 deletions
diff --git a/METADATA b/METADATA
index f1c8c9d..cab387c 100644
--- a/METADATA
+++ b/METADATA
@@ -1,5 +1,5 @@
# This project was upgraded with external_updater.
-# Usage: tools/external_updater/updater.sh update f2fs-tools
+# Usage: tools/external_updater/updater.sh update external/f2fs-tools
# For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md
name: "f2fs-tools"
@@ -7,14 +7,14 @@ description: "F2FS filesystem tools"
third_party {
license_type: RESTRICTED
last_upgrade_date {
- year: 2023
- month: 12
- day: 14
+ year: 2024
+ month: 2
+ day: 15
}
homepage: "https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git/"
identifier {
type: "Git"
value: "https://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs-tools.git"
- version: "bf5100606d63f6928799846b7322aa6f3f158bcf"
+ version: "e22c88626852048034e8d99ebb5b1a8e673a8086"
}
}
diff --git a/configure.ac b/configure.ac
index 123ddbb..21c6391 100644
--- a/configure.ac
+++ b/configure.ac
@@ -144,6 +144,8 @@ AC_CHECK_HEADERS(m4_flatten([
linux/fs.h
linux/hdreg.h
linux/limits.h
+ linux/loop.h
+ linux/major.h
linux/posix_acl.h
linux/types.h
linux/xattr.h
diff --git a/fsck/fsck.c b/fsck/fsck.c
index e93db82..3461a52 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -1052,7 +1052,7 @@ check_next:
ofs = get_extra_isize(node_blk);
if ((node_blk->i.i_flags & cpu_to_le32(F2FS_CASEFOLD_FL)) &&
- (ftype != F2FS_FT_DIR ||
+ (!S_ISDIR(le16_to_cpu(node_blk->i.i_mode)) ||
!(c.feature & F2FS_FEATURE_CASEFOLD))) {
ASSERT_MSG("[0x%x] unexpected casefold flag", nid);
if (c.fix_on) {
diff --git a/fsck/main.c b/fsck/main.c
index 1affa72..c4d0956 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -1111,8 +1111,8 @@ int main(int argc, char **argv)
f2fs_parse_options(argc, argv);
- if (c.func != DUMP && f2fs_devs_are_umounted() < 0) {
- if (errno == EBUSY) {
+ if (c.func != DUMP && (ret = f2fs_devs_are_umounted()) < 0) {
+ if (ret == -EBUSY) {
ret = -1;
if (c.func == FSCK)
ret = FSCK_OPERATIONAL_ERROR;
diff --git a/fsck/mount.c b/fsck/mount.c
index 30c6228..50afd01 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -995,6 +995,10 @@ int sanity_check_raw_super(struct f2fs_super_block *sb, enum SB_ADDR sb_addr)
return -1;
blocksize = 1 << get_sb(log_blocksize);
+ if (c.sparse_mode && F2FS_BLKSIZE != blocksize) {
+ MSG(0, "Invalid blocksize (%u), does not equal sparse file blocksize (%u)",
+ F2FS_BLKSIZE, blocksize);
+ }
if (blocksize < F2FS_MIN_BLKSIZE || blocksize > F2FS_MAX_BLKSIZE) {
MSG(0, "Invalid blocksize (%u), must be between 4KB and 16KB\n",
blocksize);
@@ -3811,14 +3815,11 @@ static int do_record_fsync_data(struct f2fs_sb_info *sbi,
se = get_seg_entry(sbi, segno);
offset = OFFSET_IN_SEG(sbi, blkaddr);
- if (f2fs_test_bit(offset, (char *)se->cur_valid_map)) {
- ASSERT(0);
- return -1;
- }
- if (f2fs_test_bit(offset, (char *)se->ckpt_valid_map)) {
- ASSERT(0);
- return -1;
- }
+ if (f2fs_test_bit(offset, (char *)se->cur_valid_map))
+ return 1;
+
+ if (f2fs_test_bit(offset, (char *)se->ckpt_valid_map))
+ return 1;
if (!se->ckpt_valid_blocks)
se->ckpt_type = CURSEG_WARM_NODE;
@@ -3912,8 +3913,11 @@ static int traverse_dnodes(struct f2fs_sb_info *sbi,
goto next;
err = do_record_fsync_data(sbi, node_blk, blkaddr);
- if (err)
+ if (err) {
+ if (err > 0)
+ err = 0;
break;
+ }
if (entry->blkaddr == blkaddr)
del_fsync_inode(entry);
@@ -3965,20 +3969,22 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
sbi->active_logs = NR_CURSEG_TYPE;
ret = validate_super_block(sbi, SB0_ADDR);
if (ret) {
- /* Assuming 4K Block Size */
- c.blksize_bits = 12;
- c.blksize = 1 << c.blksize_bits;
- MSG(0, "Looking for secondary superblock assuming 4K Block Size\n");
+ if (!c.sparse_mode) {
+ /* Assuming 4K Block Size */
+ c.blksize_bits = 12;
+ c.blksize = 1 << c.blksize_bits;
+ MSG(0, "Looking for secondary superblock assuming 4K Block Size\n");
+ }
ret = validate_super_block(sbi, SB1_ADDR);
- if (ret) {
+ if (ret && !c.sparse_mode) {
/* Trying 16K Block Size */
c.blksize_bits = 14;
c.blksize = 1 << c.blksize_bits;
MSG(0, "Looking for secondary superblock assuming 16K Block Size\n");
ret = validate_super_block(sbi, SB1_ADDR);
- if (ret)
- return -1;
}
+ if (ret)
+ return -1;
}
sb = F2FS_RAW_SUPER(sbi);
c.cache_config.num_cache_entry = num_cache_entry;
diff --git a/include/android_config.h b/include/android_config.h
index da8abcb..05b686e 100644
--- a/include/android_config.h
+++ b/include/android_config.h
@@ -6,6 +6,8 @@
#define HAVE_FSYNC 1
#define HAVE_LINUX_HDREG_H 1
#define HAVE_LINUX_LIMITS_H 1
+#define HAVE_LINUX_LOOP_H 1
+#define HAVE_LINUX_MAJOR_H 1
#define HAVE_POSIX_ACL_H 1
#define HAVE_LINUX_TYPES_H 1
#define HAVE_LINUX_XATTR_H 1
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 6df2e73..5e9dfad 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -1514,6 +1514,7 @@ struct f2fs_configuration {
unsigned int quota_bits; /* quota bits */
time_t fixed_time;
int roll_forward;
+ bool need_fsync;
/* mkfs parameters */
int fake_seed;
diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index 2451201..d51e485 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -19,6 +19,12 @@
#endif
#include <time.h>
#include <sys/stat.h>
+#ifdef HAVE_LINUX_LOOP_H
+#include <linux/loop.h>
+#ifdef HAVE_LINUX_MAJOR_H
+#include <linux/major.h>
+#endif
+#endif
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
@@ -756,7 +762,7 @@ int f2fs_dev_is_umounted(char *path)
#ifdef _WIN32
return 0;
#else
- struct stat *st_buf;
+ struct stat st_buf;
int is_rootdev = 0;
int ret = 0;
char *rootdev_name = get_rootdev();
@@ -807,32 +813,81 @@ int f2fs_dev_is_umounted(char *path)
* If f2fs is umounted with -l, the process can still use
* the file system. In this case, we should not format.
*/
- st_buf = malloc(sizeof(struct stat));
- ASSERT(st_buf);
+ if (stat(path, &st_buf)) {
+ /* sparse file will be created after this. */
+ if (c.sparse_mode)
+ return 0;
+ MSG(0, "Info: stat failed errno:%d\n", errno);
+ return -1;
+ }
- if (stat(path, st_buf) == 0 && S_ISBLK(st_buf->st_mode)) {
+ if (S_ISBLK(st_buf.st_mode)) {
int fd = open(path, O_RDONLY | O_EXCL);
if (fd >= 0) {
close(fd);
} else if (errno == EBUSY) {
MSG(0, "\tError: In use by the system!\n");
- free(st_buf);
- return -1;
+ return -EBUSY;
+ }
+ } else if (S_ISREG(st_buf.st_mode)) {
+ /* check whether regular is backfile of loop device */
+#if defined(HAVE_LINUX_LOOP_H) && defined(HAVE_LINUX_MAJOR_H)
+ struct mntent *mnt;
+ struct stat st_loop;
+ FILE *f;
+
+ f = setmntent("/proc/mounts", "r");
+
+ while ((mnt = getmntent(f)) != NULL) {
+ struct loop_info64 loopinfo = {0, };
+ int loop_fd, err;
+
+ if (mnt->mnt_fsname[0] != '/')
+ continue;
+ if (stat(mnt->mnt_fsname, &st_loop) != 0)
+ continue;
+ if (!S_ISBLK(st_loop.st_mode))
+ continue;
+ if (major(st_loop.st_rdev) != LOOP_MAJOR)
+ continue;
+
+ loop_fd = open(mnt->mnt_fsname, O_RDONLY);
+ if (loop_fd < 0) {
+ MSG(0, "Info: open %s failed errno:%d\n",
+ mnt->mnt_fsname, errno);
+ return -1;
+ }
+
+ err = ioctl(loop_fd, LOOP_GET_STATUS64, &loopinfo);
+ close(loop_fd);
+ if (err < 0) {
+ MSG(0, "\tError: ioctl LOOP_GET_STATUS64 failed errno:%d!\n",
+ errno);
+ return -1;
+ }
+
+ if (st_buf.st_dev == loopinfo.lo_device &&
+ st_buf.st_ino == loopinfo.lo_inode) {
+ MSG(0, "\tError: In use by loop device!\n");
+ return -EBUSY;
+ }
}
+#endif
}
- free(st_buf);
return ret;
#endif
}
int f2fs_devs_are_umounted(void)
{
- int i;
+ int ret, i;
- for (i = 0; i < c.ndevs; i++)
- if (f2fs_dev_is_umounted((char *)c.devices[i].path))
- return -1;
+ for (i = 0; i < c.ndevs; i++) {
+ ret = f2fs_dev_is_umounted((char *)c.devices[i].path);
+ if (ret)
+ return ret;
+ }
return 0;
}
@@ -974,7 +1029,7 @@ int get_device_info(int i)
dev->fd = fd;
- if (c.sparse_mode) {
+ if (c.sparse_mode && i == 0) {
if (f2fs_init_sparse_file()) {
free(stat_buf);
return -1;
@@ -1221,7 +1276,7 @@ int get_device_info(int i)
c.sectors_per_blk = F2FS_BLKSIZE / c.sector_size;
c.total_sectors += dev->total_sectors;
- if (c.sparse_mode && f2fs_init_sparse_file())
+ if (c.sparse_mode && i==0 && f2fs_init_sparse_file())
return -1;
return 0;
}
diff --git a/lib/libf2fs_io.c b/lib/libf2fs_io.c
index d76da83..b2d6933 100644
--- a/lib/libf2fs_io.c
+++ b/lib/libf2fs_io.c
@@ -580,6 +580,7 @@ int dev_write(void *buf, __u64 offset, size_t len)
return -1;
if (write(fd, buf, len) < 0)
return -1;
+ c.need_fsync = true;
return 0;
}
@@ -616,6 +617,7 @@ int dev_fill(void *buf, __u64 offset, size_t len)
return -1;
if (write(fd, buf, len) < 0)
return -1;
+ c.need_fsync = true;
return 0;
}
@@ -639,6 +641,9 @@ int f2fs_fsync_device(void)
#ifdef HAVE_FSYNC
int i;
+ if (!c.need_fsync)
+ return 0;
+
for (i = 0; i < c.ndevs; i++) {
if (fsync(c.devices[i].fd) < 0) {
MSG(0, "\tError: Could not conduct fsync!!!\n");
@@ -662,14 +667,17 @@ int f2fs_init_sparse_file(void)
if (!f2fs_sparse_file)
return -1;
+ c.blksize = sparse_file_block_size(f2fs_sparse_file);
+ c.blksize_bits = log_base_2(c.blksize);
+ if (c.blksize_bits == -1) {
+ MSG(0, "\tError: Sparse file blocksize not a power of 2.\n");
+ return -1;
+ }
+
c.device_size = sparse_file_len(f2fs_sparse_file, 0, 0);
c.device_size &= (~((uint64_t)(F2FS_BLKSIZE - 1)));
}
- if (sparse_file_block_size(f2fs_sparse_file) != F2FS_BLKSIZE) {
- MSG(0, "\tError: Corrupted sparse file\n");
- return -1;
- }
blocks_count = c.device_size / F2FS_BLKSIZE;
blocks = calloc(blocks_count, sizeof(char *));
if (!blocks) {
@@ -786,10 +794,12 @@ int f2fs_finalize_device(void)
*/
for (i = 0; i < c.ndevs; i++) {
#ifdef HAVE_FSYNC
- ret = fsync(c.devices[i].fd);
- if (ret < 0) {
- MSG(0, "\tError: Could not conduct fsync!!!\n");
- break;
+ if (c.need_fsync) {
+ ret = fsync(c.devices[i].fd);
+ if (ret < 0) {
+ MSG(0, "\tError: Could not conduct fsync!!!\n");
+ break;
+ }
}
#endif
ret = close(c.devices[i].fd);
diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index b46bc15..63d675e 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -558,6 +558,16 @@ static int f2fs_prepare_super_block(void)
c.cur_seg[CURSEG_WARM_DATA] = next_zone(CURSEG_COLD_DATA);
} else if (c.zoned_mode) {
c.cur_seg[CURSEG_HOT_NODE] = 0;
+ if (c.zoned_model == F2FS_ZONED_HM) {
+ uint32_t conv_zones =
+ c.devices[0].total_segments / c.segs_per_zone
+ - total_meta_zones;
+
+ if (total_zones - conv_zones >= avail_zones)
+ c.cur_seg[CURSEG_HOT_NODE] =
+ (c.devices[1].start_blkaddr -
+ get_sb(main_blkaddr)) / c.blks_per_seg;
+ }
c.cur_seg[CURSEG_WARM_NODE] = next_zone(CURSEG_HOT_NODE);
c.cur_seg[CURSEG_COLD_NODE] = next_zone(CURSEG_WARM_NODE);
c.cur_seg[CURSEG_HOT_DATA] = next_zone(CURSEG_COLD_NODE);
diff --git a/mkfs/f2fs_format_main.c b/mkfs/f2fs_format_main.c
index 4de517a..f3316f7 100644
--- a/mkfs/f2fs_format_main.c
+++ b/mkfs/f2fs_format_main.c
@@ -443,6 +443,8 @@ static int f2fs_check_overwrite(void)
int main(int argc, char *argv[])
{
+ int ret;
+
f2fs_init_configuration();
f2fs_parse_options(argc, argv);
@@ -451,8 +453,9 @@ int main(int argc, char *argv[])
c.func = MKFS;
- if (f2fs_devs_are_umounted() < 0) {
- if (errno != EBUSY)
+ ret = f2fs_devs_are_umounted();
+ if (ret) {
+ if (ret != -EBUSY)
MSG(0, "\tError: Not available on mounted device!\n");
goto err_format;
}