分析erofs-utils canned fs_config查找失败问题
H的erofs已经支持Android,QC/droid 10下生成镜像有如下错误:
failed to find [app] in canned fs_config
code在system/core/libcutils/canned_fs_config.cpp:
void canned_fs_config(const char* path, int dir, const char* target_out_path,
unsigned* uid, unsigned* gid, unsigned* mode, uint64_t* capabilities) {
Path key, *p;
key.path = path;
if (path[0] == '/') key.path++; // canned paths lack the leading '/'
p = (Path*) bsearch(&key, canned_data, canned_used, sizeof(Path), path_compare);
if (p == NULL) {
fprintf(stderr, "failed to find [%s] in canned fs_config\n", path); //tj: here
exit(1);
}
对canned_data
和canned_used
做bsearch()
无结果。先有个load_canned_fs_config()
:
#ifdef WITH_ANDROID
if (cfg.fs_config_file &&
load_canned_fs_config(cfg.fs_config_file) < 0) { //tj: here
erofs_err("failed to load fs config %s", cfg.fs_config_file);
return 1;
}
#endif
cfg.fs_config_file
是工具传入:
#ifdef WITH_ANDROID
"\nwith following android-specific options:\n"
" --mount-point=X X=prefix of target fs path (default: /)\n"
" --product-out=X X=product_out directory\n"
" --fs-config-file=X X=fs_config file\n" //tj: here
#endif
case 12:
cfg.fs_config_file = optarg;
break;
#endif
load_canned_fs_config()
在system/core/libcutils/canned_fs_config.cpp.
看下传入fs_config文件,product分区:
0 0 755 selabel=u:object_r:rootfs:s0 capabilities=0x0
product/app 0 0 755 selabel=u:object_r:system_file:s0 capabilities=0x0
product/app/CalculatorGoogle 0 0 755 selabel=u:object_r:system_file:s0 capabilities=0x0
多了个product目录,txt should来源:
ifdef BUILDING_PRODUCT_IMAGE
$(hide) $(call fs_config,$(zip_root)/PRODUCT,product/) > $(zip_root)/META/product_filesystem_config.txt
endif
# Run fs_config while creating the target files package
# $1: root directory
# $2: add prefix
define fs_config
(cd $(1); find . -type d | sed 's,$$,/,'; find . \! -type d) | cut -c 3- | sort | sed 's,^,$(2),' | $(HOST_OUT_EXECUTABLES)/fs_config -C -D $(TARGET_OUT) -S $(SELINUX_FC) -R "$(2)"
endef
so,应该是build时增加了product这个prefix。
看下erofs的处理:
int erofs_droid_inode_fsconfig(struct erofs_inode *inode,
struct stat64 *st,
const char *path)
{
/* filesystem_config does not preserve file type bits */
mode_t stat_file_type_mask = st->st_mode & S_IFMT;
unsigned int uid = 0, gid = 0, mode = 0;
char *fspath;
inode->capabilities = 0;
if (cfg.fs_config_file)
canned_fs_config(erofs_fspath(path), //tj: here
S_ISDIR(st->st_mode),
cfg.target_out_path,
&uid, &gid, &mode, &inode->capabilities);
else if (cfg.mount_point) {
if (asprintf(&fspath, "%s/%s", cfg.mount_point,
erofs_fspath(path)) <= 0)
return -ENOMEM;
fs_config(fspath, S_ISDIR(st->st_mode),
cfg.target_out_path,
&uid, &gid, &mode, &inode->capabilities);
free(fspath);
}
st->st_uid = uid;
st->st_gid = gid;
st->st_mode = mode | stat_file_type_mask;
erofs_dbg("/%s -> mode = 0x%x, uid = 0x%x, gid = 0x%x, "
"capabilities = 0x%" PRIx64 "\n",
erofs_fspath(path),
mode, uid, gid, inode->capabilities);
return 0;
}
check erofs_fspath()
:
const char *erofs_fspath(const char *fullpath)
{
const char *s = fullpath + fullpath_prefix;
while (*s == '/')
s++;
return s;
}
fullpath_prefix
:
static unsigned int fullpath_prefix; /* root directory prefix length */
void erofs_set_fs_root(const char *rootdir)
{
fullpath_prefix = strlen(rootdir);
}
erofs_set_fs_root(cfg.c_src_path);
so, erofs_fspath()
就是子目录了, 而product_filesystem_config.txt
是有前缀的(就是挂载点), 那加上前缀就可以了。
具体讨论看这里:https://lore.kernel.org/linux-erofs/20201222020430.12512-1-zbestahu@gmail.com/
本站采用CC BY-NC-SA 4.0进行许可 | 转载请注明原文链接 - 分析erofs-utils canned fs_config查找失败问题
int erofs_droid_inode_fsconfig(struct erofs_inode *inode,
struct stat64 *st,
const char *path)这个函数是哪里的代码?没搜到,我最近正在学习使用erofs镜像制作工具代码,希望能多多多交流
https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs-utils.git/tree/lib/inode.c
Hi tj,
合入参考patch(https://lore.kernel.org/linux-erofs/20201222020430.12512-1-zbestahu@gmail.com/)编译pass后执行时出现如下Segmentation fault (core dumped)错误需要怎么定位错误原因?麻烦大佬指导下,谢谢!
~/disk1/code/v2s/android/out$ ./host/linux-x86/bin/mkfs.erofs -zlz4hc ./erofs/product_erofs.img ./target/product/sp3115/product/
mkfs.erofs 1.4
c_version: [ 1.4]
c_dbg_lvl: [ 2]
c_dry_run: [ 0]
Segmentation fault (core dumped)
用高版本的lz4了,readme有写。