Add an option to only dump/fsck an inode by path
PATCH 1/1 Add an option to only dump/fsck an inode by path
This is useful when playing around with EROFS images locally. For example, it allows us to inspect block mappings of a filepath.
--- dump/main.c | 15 ++++++++++++++- fsck/main.c | 16 +++++++++++++++- mkfs/main.c | 7 +++++++ 3 files changed, 36 insertions(+), 2 deletions(-)
dump/main.c +14 -1
@@ -8,6 +8,7 @@#include <stdlib.h> #include <getopt.h> #include <time.h> +#include "erofs/internal.h" #include "erofs/print.h" #include "erofs/inode.h" #include "erofs/io.h"
@@ -23,6 +24,7 @@ struct erofsdump_cfg {bool show_superblock;bool show_statistics;erofs_nid_t nid; +const char *inode_path; };static struct erofsdump_cfg dumpcfg;
@@ -71,6 +73,7 @@ static struct option long_options[] = { {"help", no_argument, NULL, 1}, {"nid", required_argument, NULL, 2}, {"device", required_argument, NULL, 3}, + {"path", required_argument, NULL, 4}, {0, 0, 0, 0}, };
@@ -103,6 +106,7 @@ static void usage(void)" -s show information about superblock\n" " --device=X specify an extra device to be used together\n" " --nid=# show the target inode info of nid #\n" +" --path=str show the target inode info of path\n" " --help display this help and exit.\n" , stderr); }
@@ -148,6 +152,10 @@ static int erofsdump_parse_options_cfg(int argc, char **argv)return err; ++sbi.extra_devices;break ; +case 4 : + dumpcfg.inode_path = optarg; + dumpcfg.show_inode = true; +break ;default :return -EINVAL ; }
@@ -449,7 +457,12 @@ static void erofsdump_show_fileinfo(bool show_extent) .m_la = 0, }; - err =erofs_read_inode_from_disk (&inode); +if (dumpcfg.inode_path) { + err =erofs_ilookup (dumpcfg.inode_path, &inode); + }else { + err =erofs_read_inode_from_disk (&inode); + } +if (err) {erofs_err ("read inode failed @ nid %llu" , inode.nid |0ULL );return ;
fsck/main.c +15 -1
@@ -6,6 +6,7 @@#include <stdlib.h> #include <getopt.h> #include <time.h> +#include "erofs/internal.h" #include "erofs/print.h" #include "erofs/io.h" #include "erofs/decompress.h"
@@ -18,6 +19,7 @@ struct erofsfsck_cfg {bool check_decomp;u64 physical_blocks;u64 logical_blocks; +const char *inode_path; };static struct erofsfsck_cfg fsckcfg;
@@ -25,6 +27,7 @@ static struct option long_options[] = { {"help", no_argument, 0, 1}, {"extract", no_argument, 0, 2}, {"device", required_argument, 0, 3}, + {"path", required_argument, 0, 4}, {0, 0, 0, 0}, };
@@ -37,6 +40,7 @@ static void usage(void)" -p print total compression ratio of all files\n" " --device=X specify an extra device to be used together\n" " --extract check if all files are well encoded\n" +" --path check if a specific file well encoded\n" " --help display this help and exit.\n" , stderr); }
@@ -79,6 +83,10 @@ static int erofsfsck_parse_options_cfg(int argc, char **argv)return ret; ++sbi.extra_devices;break ; +case 4 : + fsckcfg.inode_path = optarg; + fsckcfg.check_decomp = true; +break ;default :return -EINVAL ; }
@@ -582,7 +590,13 @@ int main(int argc, char **argv) goto exit_dev_close; } -erofs_check_inode (sbi.root_nid, sbi.root_nid); +if (fsckcfg.inode_path) { +struct erofs_inode inode; +erofs_ilookup (fsckcfg.inode_path, &inode); +erofs_verify_inode_data (&inode); + }else { +erofs_check_inode (sbi.root_nid, sbi.root_nid); + }if (fsckcfg.corrupted) {erofs_err ("Found some filesystem corruption" );
mkfs/main.c +7 -0
@@ -24,6 +24,13 @@#include "erofs/compress_hints.h" #include "erofs/blobchunk.h" +#ifdef WITH_ANDROID +#include <selinux/android.h> +#include <private/android_filesystem_config.h> +#include <private/canned_fs_config.h> +#include <private/fs_config.h> +#endif +#ifdef HAVE_LIBUUID #include <uuid.h> #endif
Signature · 1 line
2.34.0.rc2.393.gf8c9666880-goog
Hi,
On Wed, Dec 01, 2021 at 01:48:02PM -0800, Kelvin Zhang wrote:
...
I will check this main patchset later..
Working on another stuff now.
Quoted 5 lines
mkfs/main.c +0
-0
mkfs/main.c line 32
Quoted 9 lines
mkfs/main.c +6
-0@@ -24,6 +24,13 @@#include "erofs/compress_hints.h" #include "erofs/blobchunk.h" +#ifdef WITH_ANDROID +#include <selinux/android.h> +#include <private/android_filesystem_config.h> +#include <private/canned_fs_config.h> +#include <private/fs_config.h> +#endif
I planned to add
#include "../lib/liberofs_private.h" instead in the previous patch.
Please help check if any other regression out of Android build...
Thanks,
Gao Xiang
PATCH v2 1/1 erofs-utils: add an option to dump an inode by path
In reply to Kelvin Zhang via Linux-erofsFrom: Kelvin Zhang <[email protected]>
This is useful when playing around with EROFS images locally. For example, it allows us to inspect block mappings of a filepath.
---
Hi Kelvin,
I plan to apply the following path, since it's somewhat weird to just fsck a specific path. Also I completed the manpage and fix some minor issues.
Thanks,
Gao Xiang
dump/main.c | 14 +++++++++++++- man/dump.erofs.1 | 3 +++ 2 files changed, 16 insertions(+), 1 deletion(-)
dump/main.c +13 -1
@@ -23,6 +23,7 @@ struct erofsdump_cfg {bool show_superblock;bool show_statistics;erofs_nid_t nid; +const char *inode_path; };static struct erofsdump_cfg dumpcfg;
@@ -71,6 +72,7 @@ static struct option long_options[] = { {"help", no_argument, NULL, 1}, {"nid", required_argument, NULL, 2}, {"device", required_argument, NULL, 3}, + {"path", required_argument, NULL, 4}, {0, 0, 0, 0}, };
@@ -103,6 +105,7 @@ static void usage(void)" -s show information about superblock\n" " --device=X specify an extra device to be used together\n" " --nid=# show the target inode info of nid #\n" +" --path=X show the target inode info of path X\n" " --help display this help and exit.\n" , stderr); }
@@ -148,6 +151,11 @@ static int erofsdump_parse_options_cfg(int argc, char **argv)return err; ++sbi.extra_devices;break ; +case 4 : + dumpcfg.inode_path = optarg; + dumpcfg.show_inode = true; + ++dumpcfg.totalshow; +break ;default :return -EINVAL ; }
@@ -450,7 +458,11 @@ static void erofsdump_show_fileinfo(bool show_extent) .m_la = 0, }; - err =erofs_read_inode_from_disk (&inode); +if (dumpcfg.inode_path) + err =erofs_ilookup (dumpcfg.inode_path, &inode); +else + err =erofs_read_inode_from_disk (&inode); +if (err) {erofs_err ("read inode failed @ nid %llu" , inode.nid |0ULL );return ;
man/dump.erofs.1 +3 -0
@@ -22,6 +22,9 @@ You may give multiple `--device' options in the correct order. .BI "\-\-nid=" NID Specify an inode NID in order to print its file information. .TP +.BI "\-\-path=" path +Specify an inode path in order to print its file information. +.TP .BI \-e Show the file extent information. The option depends on option --nid to specify NID. .TP
Signature · 1 line
2.24.4
PATCH v3 1/1 erofs-utils: add an option to dump an inode by path
From: Kelvin Zhang <[email protected]>
This is useful when playing around with EROFS images locally. For example, it allows us to inspect block mappings of a filepath.
---
changes since v2:
- use different failure message for path.
dump/main.c | 25 +++++++++++++++++++++---- man/dump.erofs.1 | 3 +++ 2 files changed, 24 insertions(+), 4 deletions(-)
dump/main.c +21 -4
@@ -23,6 +23,7 @@ struct erofsdump_cfg {bool show_superblock;bool show_statistics;erofs_nid_t nid; +const char *inode_path; };static struct erofsdump_cfg dumpcfg;
@@ -71,6 +72,7 @@ static struct option long_options[] = { {"help", no_argument, NULL, 1}, {"nid", required_argument, NULL, 2}, {"device", required_argument, NULL, 3}, + {"path", required_argument, NULL, 4}, {0, 0, 0, 0}, };
@@ -103,6 +105,7 @@ static void usage(void)" -s show information about superblock\n" " --device=X specify an extra device to be used together\n" " --nid=# show the target inode info of nid #\n" +" --path=X show the target inode info of path X\n" " --help display this help and exit.\n" , stderr); }
@@ -148,6 +151,11 @@ static int erofsdump_parse_options_cfg(int argc, char **argv)return err; ++sbi.extra_devices;break ; +case 4 : + dumpcfg.inode_path = optarg; + dumpcfg.show_inode = true; + ++dumpcfg.totalshow; +break ;default :return -EINVAL ; }
@@ -450,10 +458,19 @@ static void erofsdump_show_fileinfo(bool show_extent) .m_la = 0, }; - err =erofs_read_inode_from_disk (&inode); -if (err) { -erofs_err ("read inode failed @ nid %llu" , inode.nid |0ULL ); -return ; +if (dumpcfg.inode_path) { + err =erofs_ilookup (dumpcfg.inode_path, &inode); +if (err) { +erofs_err ("read inode failed @ %s" , dumpcfg.inode_path); +return ; + } + }else { + err =erofs_read_inode_from_disk (&inode); +if (err) { +erofs_err ("read inode failed @ nid %llu" , + inode.nid |0ULL ); +return ; + } } err =erofs_get_occupied_size (&inode, &size);
man/dump.erofs.1 +3 -0
@@ -22,6 +22,9 @@ You may give multiple `--device' options in the correct order. .BI "\-\-nid=" NID Specify an inode NID in order to print its file information. .TP +.BI "\-\-path=" path +Specify an inode path in order to print its file information. +.TP .BI \-e Show the file extent information. The option depends on option --nid to specify NID. .TP
Signature · 1 line
2.24.4