aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaegeuk Kim <jaegeuk@google.com>2024-03-07 09:22:11 -0800
committerJaegeuk Kim <jaegeuk@google.com>2024-03-07 09:22:11 -0800
commit5547d4cec155ba547f3cc93d1fdfd244f795a99d (patch)
treedda1dfcaec3dcd7b6558445e28904a0b90482edd
parent59e88966f3bf423faabdd8c80e5f1a287b650744 (diff)
parentefcff4bc169fbcb7276769ab0ad5444b1df33a70 (diff)
downloadf2fs-tools-5547d4cec155ba547f3cc93d1fdfd244f795a99d.tar.gz
Upgrade f2fs-tools to efcff4bc169fbcb7276769ab0ad5444b1df33a70
This project was upgraded with external_updater. 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 Test: TreeHugger Change-Id: Iceef0be15bf6455b7d664ad99f30555da2b544b8
-rw-r--r--METADATA6
-rw-r--r--fsck/f2fs.h3
-rw-r--r--fsck/fsck.c18
-rw-r--r--fsck/mount.c1
-rw-r--r--include/f2fs_fs.h2
-rw-r--r--lib/libf2fs.c12
-rw-r--r--man/mkfs.f2fs.86
-rw-r--r--mkfs/f2fs_format.c8
-rw-r--r--mkfs/f2fs_format_main.c5
-rw-r--r--tools/f2fs_io/f2fs_io.c173
-rw-r--r--tools/f2fs_io/f2fs_io.h4
11 files changed, 173 insertions, 65 deletions
diff --git a/METADATA b/METADATA
index cab387c..053806a 100644
--- a/METADATA
+++ b/METADATA
@@ -8,13 +8,13 @@ third_party {
license_type: RESTRICTED
last_upgrade_date {
year: 2024
- month: 2
- day: 15
+ month: 3
+ day: 7
}
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: "e22c88626852048034e8d99ebb5b1a8e673a8086"
+ version: "efcff4bc169fbcb7276769ab0ad5444b1df33a70"
}
}
diff --git a/fsck/f2fs.h b/fsck/f2fs.h
index e31be22..187e73c 100644
--- a/fsck/f2fs.h
+++ b/fsck/f2fs.h
@@ -257,9 +257,6 @@ struct f2fs_sb_info {
struct f2fs_checkpoint *ckpt;
int cur_cp;
- struct list_head orphan_inode_list;
- unsigned int n_orphans;
-
/* basic file system units */
unsigned int log_sectors_per_block; /* log2 sectors per block */
unsigned int log_blocksize; /* log2 block size */
diff --git a/fsck/fsck.c b/fsck/fsck.c
index 3461a52..a42b597 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -1071,13 +1071,13 @@ check_next:
qf_szchk_type[cur_qtype] = QF_SZCHK_INLINE;
block_t blkaddr = le32_to_cpu(node_blk->i.i_addr[ofs]);
- if (blkaddr != 0) {
+ if (blkaddr != NULL_ADDR) {
ASSERT_MSG("[0x%x] wrong inline reserve blkaddr:%u",
nid, blkaddr);
if (c.fix_on) {
FIX_MSG("inline_data has wrong 0'th block = %x",
blkaddr);
- node_blk->i.i_addr[ofs] = 0;
+ node_blk->i.i_addr[ofs] = NULL_ADDR;
node_blk->i.i_blocks = cpu_to_le64(*blk_cnt);
need_fix = 1;
}
@@ -1121,7 +1121,7 @@ check_next:
if (c.fix_on) {
FIX_MSG("inline_dentry has wrong 0'th block = %x",
blkaddr);
- node_blk->i.i_addr[ofs] = 0;
+ node_blk->i.i_addr[ofs] = NULL_ADDR;
node_blk->i.i_blocks = cpu_to_le64(*blk_cnt);
need_fix = 1;
}
@@ -1161,8 +1161,8 @@ check_next:
node_blk->i.i_addr[ofs + idx] =
NULL_ADDR;
need_fix = 1;
- FIX_MSG("[0x%x] i_addr[%d] = 0", nid,
- ofs + idx);
+ FIX_MSG("[0x%x] i_addr[%d] = NULL_ADDR",
+ nid, ofs + idx);
}
continue;
}
@@ -1190,9 +1190,9 @@ check_next:
if (cur_qtype != -1 && blkaddr != NEW_ADDR)
qf_last_blkofs[cur_qtype] = child.pgofs;
} else if (c.fix_on) {
- node_blk->i.i_addr[ofs + idx] = 0;
+ node_blk->i.i_addr[ofs + idx] = NULL_ADDR;
need_fix = 1;
- FIX_MSG("[0x%x] i_addr[%d] = 0", nid, ofs + idx);
+ FIX_MSG("[0x%x] i_addr[%d] = NULL_ADDR", nid, ofs + idx);
}
}
@@ -1253,8 +1253,8 @@ check:
}
if (i_blocks != *blk_cnt) {
- ASSERT_MSG("ino: 0x%x has i_blocks: %08"PRIx64", "
- "but has %u blocks",
+ ASSERT_MSG("ino: 0x%x has i_blocks: 0x%08"PRIx64", "
+ "but has 0x%x blocks",
nid, i_blocks, *blk_cnt);
if (c.fix_on) {
node_blk->i.i_blocks = cpu_to_le64(*blk_cnt);
diff --git a/fsck/mount.c b/fsck/mount.c
index 50afd01..b983920 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -679,6 +679,7 @@ static char *stop_reason_str[] = {
[STOP_CP_REASON_CORRUPTED_SUMMARY] = "corrupted_summary",
[STOP_CP_REASON_UPDATE_INODE] = "update_inode",
[STOP_CP_REASON_FLUSH_FAIL] = "flush_fail",
+ [STOP_CP_REASON_NO_SEGMENT] = "no_segment",
};
void print_sb_stop_reason(struct f2fs_super_block *sb)
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 5e9dfad..9056e02 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -718,6 +718,7 @@ enum stop_cp_reason {
STOP_CP_REASON_CORRUPTED_SUMMARY,
STOP_CP_REASON_UPDATE_INODE,
STOP_CP_REASON_FLUSH_FAIL,
+ STOP_CP_REASON_NO_SEGMENT,
STOP_CP_REASON_MAX,
};
@@ -1475,7 +1476,6 @@ struct f2fs_configuration {
char *vol_uuid;
uint16_t s_encoding;
uint16_t s_encoding_flags;
- int heap;
int32_t kd;
int32_t dump_fd;
struct device_info devices[MAX_DEVICES];
diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index d51e485..1cfbf31 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -854,9 +854,15 @@ int f2fs_dev_is_umounted(char *path)
loop_fd = open(mnt->mnt_fsname, O_RDONLY);
if (loop_fd < 0) {
+ /* non-root users have no permission */
+ if (errno == EPERM || errno == EACCES) {
+ MSG(0, "Info: open %s failed errno:%d - be careful to overwrite a mounted loopback file.\n",
+ mnt->mnt_fsname, errno);
+ return 0;
+ }
MSG(0, "Info: open %s failed errno:%d\n",
- mnt->mnt_fsname, errno);
- return -1;
+ mnt->mnt_fsname, errno);
+ return -errno;
}
err = ioctl(loop_fd, LOOP_GET_STATUS64, &loopinfo);
@@ -864,7 +870,7 @@ int f2fs_dev_is_umounted(char *path)
if (err < 0) {
MSG(0, "\tError: ioctl LOOP_GET_STATUS64 failed errno:%d!\n",
errno);
- return -1;
+ return -errno;
}
if (st_buf.st_dev == loopinfo.lo_device &&
diff --git a/man/mkfs.f2fs.8 b/man/mkfs.f2fs.8
index 6670003..0dc367b 100644
--- a/man/mkfs.f2fs.8
+++ b/man/mkfs.f2fs.8
@@ -8,10 +8,6 @@ mkfs.f2fs \- create an F2FS file system
.SH SYNOPSIS
.B mkfs.f2fs
[
-.B \-a
-.I heap-based-allocation
-]
-[
.B \-c
.I device-list
]
@@ -110,7 +106,7 @@ The exit code returned by
is 0 on success and 1 on failure.
.SH OPTIONS
.TP
-.BI \-a " heap-based-allocation"
+.BI \-a " heap-based-allocation" (deprecated)
Specify 1 or 0 to enable/disable heap based block allocation policy.
If the value is equal to 1, each of active log areas are initially
assigned separately according to the whole volume size.
diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index 63d675e..8f632f8 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -548,14 +548,6 @@ static int f2fs_prepare_super_block(void)
c.cur_seg[CURSEG_HOT_DATA] = 0;
c.cur_seg[CURSEG_COLD_DATA] = 0;
c.cur_seg[CURSEG_WARM_DATA] = 0;
- } else if (c.heap) {
- c.cur_seg[CURSEG_HOT_NODE] =
- last_section(last_zone(total_zones));
- c.cur_seg[CURSEG_WARM_NODE] = prev_zone(CURSEG_HOT_NODE);
- c.cur_seg[CURSEG_COLD_NODE] = prev_zone(CURSEG_WARM_NODE);
- c.cur_seg[CURSEG_HOT_DATA] = prev_zone(CURSEG_COLD_NODE);
- c.cur_seg[CURSEG_COLD_DATA] = 0;
- 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) {
diff --git a/mkfs/f2fs_format_main.c b/mkfs/f2fs_format_main.c
index f3316f7..c98e73c 100644
--- a/mkfs/f2fs_format_main.c
+++ b/mkfs/f2fs_format_main.c
@@ -49,7 +49,6 @@ static void mkfs_usage()
{
MSG(0, "\nUsage: mkfs.f2fs [options] device [sectors]\n");
MSG(0, "[options]:\n");
- MSG(0, " -a heap-based allocation [default:0]\n");
MSG(0, " -b filesystem block size [default:4096]\n");
MSG(0, " -c device1[,device2,...] up to 7 additional devices, except meta device\n");
MSG(0, " -d debug level [default:0]\n");
@@ -84,8 +83,6 @@ static void f2fs_show_info()
MSG(0, "\n F2FS-tools: mkfs.f2fs Ver: %s (%s)\n\n",
F2FS_TOOLS_VERSION,
F2FS_TOOLS_DATE);
- if (c.heap == 0)
- MSG(0, "Info: Disable heap-based policy\n");
MSG(0, "Info: Debug level = %d\n", c.dbg_lv);
if (c.extension_list[0])
@@ -191,7 +188,7 @@ static void f2fs_parse_options(int argc, char *argv[])
c.dbg_lv = -1;
break;
case 'a':
- c.heap = atoi(optarg);
+ MSG(0, "Info: heap allocation is deprecated\n");
break;
case 'b':
c.blksize = atoi(optarg);
diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index e7d286a..7059cbf 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -597,26 +597,8 @@ static void do_erase(int argc, char **argv, const struct cmd_desc *cmd)
exit(0);
}
-#define write_desc "write data into file"
-#define write_help \
-"f2fs_io write [chunk_size in 4kb] [offset in chunk_size] [count] [pattern] [IO] [file_path] {delay}\n\n" \
-"Write given patten data in file_path\n" \
-"pattern can be\n" \
-" zero : zeros\n" \
-" inc_num : incrementing numbers\n" \
-" rand : random numbers\n" \
-"IO can be\n" \
-" buffered : buffered IO\n" \
-" dio : O_DIRECT\n" \
-" dsync : O_DIRECT | O_DSYNC\n" \
-" osync : O_SYNC\n" \
-" atomic_commit : atomic write & commit\n" \
-" atomic_abort : atomic write & abort\n" \
-" atomic_rcommit: atomic replace & commit\n" \
-" atomic_rabort : atomic replace & abort\n" \
-"{delay} is in ms unit and optional only for atomic operations\n"
-
-static void do_write(int argc, char **argv, const struct cmd_desc *cmd)
+static void do_write_with_advice(int argc, char **argv,
+ const struct cmd_desc *cmd, bool with_advice)
{
u64 buf_size = 0, inc_num = 0, written = 0;
u64 offset;
@@ -630,12 +612,6 @@ static void do_write(int argc, char **argv, const struct cmd_desc *cmd)
srand(time(0));
- if (argc < 7 || argc > 8) {
- fputs("Excess arguments\n\n", stderr);
- fputs(cmd->cmd_help, stderr);
- exit(1);
- }
-
bs = atoi(argv[1]);
if (bs > 1024)
die("Too big chunk size - limit: 4MB");
@@ -672,7 +648,28 @@ static void do_write(int argc, char **argv, const struct cmd_desc *cmd)
die("Wrong IO type");
}
- fd = xopen(argv[6], O_CREAT | O_WRONLY | flags, 0755);
+ if (!with_advice) {
+ fd = xopen(argv[6], O_CREAT | O_WRONLY | flags, 0755);
+ } else {
+ unsigned char advice;
+ int ret;
+
+ if (!strcmp(argv[6], "hot"))
+ advice = FADVISE_HOT_BIT;
+ else if (!strcmp(argv[6], "cold"))
+ advice = FADVISE_COLD_BIT;
+ else
+ die("Wrong Advise type");
+
+ fd = xopen(argv[7], O_CREAT | O_WRONLY | flags, 0755);
+
+ ret = fsetxattr(fd, F2FS_SYSTEM_ADVISE_NAME,
+ (char *)&advice, 1, XATTR_CREATE);
+ if (ret) {
+ fputs("fsetxattr advice failed\n", stderr);
+ exit(1);
+ }
+ }
if (atomic_commit || atomic_abort) {
int ret;
@@ -739,6 +736,67 @@ static void do_write(int argc, char **argv, const struct cmd_desc *cmd)
exit(0);
}
+#define write_desc "write data into file"
+#define write_help \
+"f2fs_io write [chunk_size in 4kb] [offset in chunk_size] [count] [pattern] [IO] [file_path] {delay}\n\n" \
+"Write given patten data in file_path\n" \
+"pattern can be\n" \
+" zero : zeros\n" \
+" inc_num : incrementing numbers\n" \
+" rand : random numbers\n" \
+"IO can be\n" \
+" buffered : buffered IO\n" \
+" dio : O_DIRECT\n" \
+" dsync : O_DIRECT | O_DSYNC\n" \
+" osync : O_SYNC\n" \
+" atomic_commit : atomic write & commit\n" \
+" atomic_abort : atomic write & abort\n" \
+" atomic_rcommit: atomic replace & commit\n" \
+" atomic_rabort : atomic replace & abort\n" \
+"{delay} is in ms unit and optional only for atomic operations\n"
+
+static void do_write(int argc, char **argv, const struct cmd_desc *cmd)
+{
+ if (argc < 7 || argc > 8) {
+ fputs("Excess arguments\n\n", stderr);
+ fputs(cmd->cmd_help, stderr);
+ exit(1);
+ }
+ do_write_with_advice(argc, argv, cmd, false);
+}
+
+#define write_advice_desc "write data into file with a hint"
+#define write_advice_help \
+"f2fs_io write_advice [chunk_size in 4kb] [offset in chunk_size] [count] [pattern] [IO] [advise] [file_path] {delay}\n\n" \
+"Write given patten data in file_path\n" \
+"pattern can be\n" \
+" zero : zeros\n" \
+" inc_num : incrementing numbers\n" \
+" rand : random numbers\n" \
+"IO can be\n" \
+" buffered : buffered IO\n" \
+" dio : O_DIRECT\n" \
+" dsync : O_DIRECT | O_DSYNC\n" \
+" osync : O_SYNC\n" \
+" atomic_commit : atomic write & commit\n" \
+" atomic_abort : atomic write & abort\n" \
+" atomic_rcommit: atomic replace & commit\n" \
+" atomic_rabort : atomic replace & abort\n" \
+"advise can be\n" \
+" cold : indicate a cold file\n" \
+" hot : indicate a hot file\n" \
+"{delay} is in ms unit and optional only for atomic operations\n"
+
+static void do_write_advice(int argc, char **argv, const struct cmd_desc *cmd)
+{
+ if (argc < 8 || argc > 9) {
+ fputs("Excess arguments\n\n", stderr);
+ fputs(cmd->cmd_help, stderr);
+ exit(1);
+ }
+ do_write_with_advice(argc, argv, cmd, true);
+}
+
#define read_desc "read data from file"
#define read_help \
"f2fs_io read [chunk_size in 4kb] [offset in chunk_size] [count] [IO] [print_nbytes] [file_path]\n\n" \
@@ -1592,6 +1650,8 @@ static void do_listxattr(int argc, char **argv, const struct cmd_desc *cmd)
static void do_setxattr(int argc, char **argv, const struct cmd_desc *cmd)
{
int ret;
+ char *value;
+ unsigned char tmp;
if (argc != 4) {
fputs("Excess arguments\n\n", stderr);
@@ -1599,11 +1659,18 @@ static void do_setxattr(int argc, char **argv, const struct cmd_desc *cmd)
exit(1);
}
- ret = setxattr(argv[3], argv[1], argv[2], strlen(argv[2]), XATTR_CREATE);
+ if (!strcmp(argv[1], F2FS_SYSTEM_ADVISE_NAME)) {
+ tmp = strtoul(argv[2], NULL, 0);
+ value = (char *)&tmp;
+ } else {
+ value = argv[2];
+ }
+
+ ret = setxattr(argv[3], argv[1], value, strlen(argv[2]), XATTR_CREATE);
printf("setxattr %s CREATE: name: %s, value: %s: ret=%d\n",
argv[3], argv[1], argv[2], ret);
if (ret < 0 && errno == EEXIST) {
- ret = setxattr(argv[3], argv[1], argv[2], strlen(argv[2]), XATTR_REPLACE);
+ ret = setxattr(argv[3], argv[1], value, strlen(argv[2]), XATTR_REPLACE);
printf("setxattr %s REPLACE: name: %s, value: %s: ret=%d\n",
argv[3], argv[1], argv[2], ret);
}
@@ -1630,6 +1697,52 @@ static void do_removexattr(int argc, char **argv, const struct cmd_desc *cmd)
exit(0);
}
+#define lseek_desc "do lseek for a file"
+#define lseek_help \
+"f2fs_io lseek [whence] [offset] [file_path]\n\n" \
+"Do lseek file data in file_path and return the adjusted file offset\n" \
+"whence can be\n" \
+" set : SEEK_SET, The file offset is set to offset bytes\n" \
+" cur : SEEK_CUR, The file offset is set to its current location plus offset bytes\n" \
+" end : SEEK_END, The file offset is set to the size of the file plus offset bytes\n" \
+" data : SEEK_DATA, set the file offset to the next data location from offset\n" \
+" hole : SEEK_HOLE, set the file offset to the next hole from offset\n"
+
+static void do_lseek(int argc, char **argv, const struct cmd_desc *cmd)
+{
+ int fd, whence;
+ off_t offset, ret;
+
+ if (argc != 4) {
+ fputs("Excess arguments\n\n", stderr);
+ fputs(cmd->cmd_help, stderr);
+ exit(1);
+ }
+
+ offset = atoi(argv[2]);
+
+ if (!strcmp(argv[1], "set"))
+ whence = SEEK_SET;
+ else if (!strcmp(argv[1], "cur"))
+ whence = SEEK_CUR;
+ else if (!strcmp(argv[1], "end"))
+ whence = SEEK_END;
+ else if (!strcmp(argv[1], "data"))
+ whence = SEEK_DATA;
+ else if (!strcmp(argv[1], "hole"))
+ whence = SEEK_HOLE;
+ else
+ die("Wrong whence type");
+
+ fd = xopen(argv[3], O_RDONLY, 0);
+
+ ret = lseek(fd, offset, whence);
+ if (ret < 0)
+ die_errno("lseek failed");
+ printf("returned offset=%ld\n", ret);
+ exit(0);
+}
+
#define CMD_HIDDEN 0x0001
#define CMD(name) { #name, do_##name, name##_desc, name##_help, 0 }
#define _CMD(name) { #name, do_##name, NULL, NULL, CMD_HIDDEN }
@@ -1648,6 +1761,7 @@ const struct cmd_desc cmd_list[] = {
CMD(fallocate),
CMD(erase),
CMD(write),
+ CMD(write_advice),
CMD(read),
CMD(randread),
CMD(fiemap),
@@ -1671,6 +1785,7 @@ const struct cmd_desc cmd_list[] = {
CMD(listxattr),
CMD(setxattr),
CMD(removexattr),
+ CMD(lseek),
{ NULL, NULL, NULL, NULL, 0 }
};
diff --git a/tools/f2fs_io/f2fs_io.h b/tools/f2fs_io/f2fs_io.h
index b4aa9cf..d2641cb 100644
--- a/tools/f2fs_io/f2fs_io.h
+++ b/tools/f2fs_io/f2fs_io.h
@@ -167,6 +167,10 @@ struct fscrypt_get_policy_ex_arg {
#define F2FS_IOC_FSGETXATTR FS_IOC_FSGETXATTR
#define F2FS_IOC_FSSETXATTR FS_IOC_FSSETXATTR
+#define F2FS_SYSTEM_ADVISE_NAME "system.advise"
+#define FADVISE_COLD_BIT 0x01
+#define FADVISE_HOT_BIT 0x20
+
#ifndef FS_IMMUTABLE_FL
#define FS_IMMUTABLE_FL 0x00000010 /* Immutable file */
#endif