Skip to content

Commit fd27496

Browse files
committedJan 25, 2022
wip
1 parent ba10a8e commit fd27496

File tree

2 files changed

+56
-39
lines changed

2 files changed

+56
-39
lines changed
 

‎Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ build/jevmachopp/libjevmachopp.a: $(LIBJEVMACHOPP_OBJS)
226226

227227
build/jevmachopp/libjevmachopp.o: build/jevmachopp/libjevmachopp.a build/jevmachopp/fmt/libfmt.a build/jevmachopp/uleb128/libuleb128.a build/jevmachopp/apfs/libapfs.a build/jevmachopp/apfs/miniz/libminiz.a build/jevmachopp/apfs/lzfse/liblzfse.a build/jevmachopp/apfs/bzip2/libbz2.a $(ROOT_DIR)/jevmachopp-u-boot-apfs-exported-syms.txt
228228
@mkdir -p "$(dir $@)"
229-
$(JEV_CXX) -o $@ -g -Wl,-r -nostdlib build/jevmachopp/apfs/miniz/libminiz.a build/jevmachopp/apfs/lzfse/liblzfse.a build/jevmachopp/apfs/bzip2/libbz2.a build/jevmachopp/apfs/libapfs.a build/jevmachopp/uleb128/libuleb128.a build/jevmachopp/fmt/libfmt.a -Wl,--whole-archive build/jevmachopp/libjevmachopp.a -Wl,--no-whole-archive -Wl,--start-group $(JEV_LIBCXX_PATH) $(JEV_LIBCXXABI_PATH) $(JEV_LIBUNWIND_PATH) $(JEV_LIBC_PATH) $(JEV_LIBGCC_PATH) -Wl,--end-group -Wl,--lto-load-pass-plugin=$(JEVEMBCUSTOMS_LIB) -Wl,-mllvm-plugin,-embcust-libgcc=$(JEV_LIBGCC_PATH) -Wl,-mllvm-plugin,-embcust-exported-syms=$(ROOT_DIR)/jevmachopp-u-boot-apfs-exported-syms.txt -Xlinker --lto-newpm-passes='write-bitcode<mod.bc>,embcust<pre&ep_wrapper=__libc_start_embcust>,write-bitcode<mod-p1.bc>,default<O0>,write-bitcode<mod-opt.bc>,embcust<post&rename_ctors_array>,write-bitcode<mod-linked.bc>'
229+
$(JEV_CXX) -o $@ -g -Wl,-r -nostdlib build/jevmachopp/apfs/miniz/libminiz.a build/jevmachopp/apfs/lzfse/liblzfse.a build/jevmachopp/apfs/bzip2/libbz2.a build/jevmachopp/apfs/libapfs.a build/jevmachopp/uleb128/libuleb128.a build/jevmachopp/fmt/libfmt.a -Wl,--whole-archive build/jevmachopp/libjevmachopp.a -Wl,--no-whole-archive -Wl,--start-group $(JEV_LIBCXX_PATH) $(JEV_LIBCXXABI_PATH) $(JEV_LIBUNWIND_PATH) $(JEV_LIBC_PATH) $(JEV_LIBGCC_PATH) -Wl,--end-group -Wl,--lto-load-pass-plugin=$(JEVEMBCUSTOMS_LIB) -Wl,-mllvm-plugin,-embcust-libgcc=$(JEV_LIBGCC_PATH) -Wl,-mllvm-plugin,-embcust-exported-syms=$(ROOT_DIR)/jevmachopp-u-boot-apfs-exported-syms.txt -Xlinker --lto-newpm-passes='embcust<pre&ep_wrapper=__libc_start_embcust>,default<O0>,embcust<post&rename_ctors_array>'
230+
# --lto-newpm-passes='write-bitcode<mod.bc>,embcust<pre&ep_wrapper=__libc_start_embcust>,write-bitcode<mod-p1.bc>,default<O0>,write-bitcode<mod-opt.bc>,embcust<post&rename_ctors_array>,write-bitcode<mod-linked.bc>'
230231
# --lto-newpm-passes='embcust,default<Os>,embcust<rename_ctors_array>'
231232

232233
build/jevmachopp/uleb128/%.o: $(ROOT_DIR)/3rdparty/uleb128/src/uleb128/%.cc

‎lib/jevmachopp/UBootAPFS.cpp

+54-38
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ class DirRec : public ApfsDir::DirRec {
104104
};
105105

106106
struct APFSPath {
107+
APFSPath(const std::string volume, const std::string &volume_path)
108+
: volume(volume), path(volume_path) {
109+
assert(!volume.empty());
110+
if (path.empty())
111+
path = "/";
112+
}
107113
APFSPath(const std::string &full_path) {
108114
// cases:
109115
// (empty) -> /
@@ -228,7 +234,42 @@ ApfsVolumeSP lookupVolume(const std::string &volName, ApfsContainer *container)
228234
return vol;
229235
}
230236

231-
DirRecSP lookupDirRec(const std::string &path, std::shared_ptr<ApfsVolume> volume) {
237+
std::unique_ptr<DirRec> childDirNamed(ApfsDir *apfsDir, DirRec *parentDir,
238+
std::string_view childDirName) {
239+
assert(parentDir);
240+
auto res = std::make_unique<DirRec>();
241+
if (!apfsDir->LookupName(*res, parentDir->file_id, std::string{childDirName}.c_str())) {
242+
return nullptr;
243+
}
244+
return res;
245+
}
246+
247+
std::unique_ptr<DirRec> lookupDir(ApfsDir *apfsDir, std::string_view dirPath) {
248+
if (!dirPath.size() || dirPath[0] != '/') {
249+
return nullptr;
250+
}
251+
std::unique_ptr<DirRec> res = std::make_unique<DirRec>();
252+
assert(apfsDir->LookupName(*res, ROOT_DIR_PARENT, "root"));
253+
for (const auto childName : stringSplitViewDelimitedBy(dirPath, '/') | views::drop(1)) {
254+
printf("looking up childName: \"%*s\"\n", SV2PF(childName));
255+
res = std::unique_ptr<DirRec>{childDirNamed(apfsDir, res.get(), childName)};
256+
if (!res) {
257+
return nullptr;
258+
}
259+
}
260+
return res;
261+
}
262+
263+
DirRecSP lookupDirRec(const APFSPath &path, std::shared_ptr<ApfsVolume> volume) {
264+
auto dirrec = std::make_shared<DirRec>();
265+
// for (const auto childName : stringSplitViewDelimitedBy(path.path, '/') | views::drop(1)) {
266+
267+
// printf("looking up childName: \"%*s\"\n", SV2PF(childName));
268+
// res = std::unique_ptr<DirRec>{childDirNamed(apfsDir, res.get(), childName)};
269+
// if (!res) {
270+
// return nullptr;
271+
// }
272+
// }
232273
return nullptr;
233274
}
234275

@@ -266,13 +307,16 @@ std::vector<APFSNodeSP> listContainerAsNodes(ApfsContainer *container) {
266307
}
267308

268309
std::shared_ptr<std::vector<DirRecSP>> listPath(ApfsContainer *container, ApfsVolumeSP volume,
269-
const std::string &path) {
310+
const APFSPath &path) {
311+
auto dirrec = lookupDirRec(path, volume);
312+
if (!dirrec)
313+
return nullptr;
270314
auto subpaths = std::make_shared<std::vector<DirRecSP>>();
271315
return subpaths;
272316
}
273317

274318
std::shared_ptr<std::vector<APFSNodeSP>>
275-
listPathAsNodes(ApfsContainer *container, ApfsVolumeSP volume, const std::string &path) {
319+
listPathAsNodes(ApfsContainer *container, ApfsVolumeSP volume, const APFSPath &path) {
276320
auto dirrecs = listPath(container, volume, path);
277321
if (!dirrecs)
278322
return nullptr;
@@ -291,34 +335,8 @@ std::shared_ptr<std::vector<APFSNodeSP>> list(const APFSPath &path, ApfsContaine
291335
if (!vol)
292336
return nullptr;
293337
if (path.path.empty())
294-
return listPathAsNodes(container, vol, "/");
295-
return listPathAsNodes(container, vol, path.path);
296-
}
297-
298-
std::unique_ptr<DirRec> childDirNamed(ApfsDir *apfsDir, DirRec *parentDir,
299-
std::string_view childDirName) {
300-
assert(parentDir);
301-
auto res = std::make_unique<DirRec>();
302-
if (!apfsDir->LookupName(*res, parentDir->file_id, std::string{childDirName}.c_str())) {
303-
return nullptr;
304-
}
305-
return res;
306-
}
307-
308-
std::unique_ptr<DirRec> lookupDir(ApfsDir *apfsDir, std::string_view dirPath) {
309-
if (!dirPath.size() || dirPath[0] != '/') {
310-
return nullptr;
311-
}
312-
std::unique_ptr<DirRec> res = std::make_unique<DirRec>();
313-
assert(apfsDir->LookupName(*res, ROOT_DIR_PARENT, "root"));
314-
for (const auto childName : stringSplitViewDelimitedBy(dirPath, '/') | views::drop(1)) {
315-
printf("looking up childName: \"%*s\"\n", SV2PF(childName));
316-
res = std::unique_ptr<DirRec>{childDirNamed(apfsDir, res.get(), childName)};
317-
if (!res) {
318-
return nullptr;
319-
}
320-
}
321-
return res;
338+
return listPathAsNodes(container, vol, APFSPath{path.volume, "/"});
339+
return listPathAsNodes(container, vol, path);
322340
}
323341

324342
class APFSCtx {
@@ -338,7 +356,7 @@ class APFSCtx {
338356
auto part_num = 0;
339357
if (part_num_str) {
340358
fmt::print("setting part num to {:s} - 1\n", *part_num_str);
341-
const auto part_num = std::stoi(std::string{*part_num_str}, nullptr, 10) - 1;
359+
part_num = std::stoi(std::string{*part_num_str}, nullptr, 10) - 1;
342360
}
343361
assert(part_num >= 0);
344362

@@ -348,9 +366,7 @@ class APFSCtx {
348366

349367
GptPartitionMap gpt;
350368
assert(gpt.LoadAndVerify(m_dev));
351-
fmt::print("gpt.size: {:d}\n", gpt.size());
352369
assert(gpt.GetPartitionOffsetAndSize((uint32_t)part_num, m_blk_off_blks, m_blk_sz_bytes));
353-
fmt::print("blk_off_blks: 0x{:x} blk_sz_bytes: 0x{:x}\n", m_blk_off_blks, m_blk_sz_bytes);
354370
return open_common();
355371
}
356372
bool open(struct blk_desc *fs_dev_desc, struct disk_partition *fs_partition) {
@@ -485,7 +501,7 @@ void uboot_apfs_doit(void) {
485501
// g_debug = 0xff;
486502

487503
#ifdef JEV_BAREMETAL
488-
assert(apfs_ctx.open("virtio:0:1"));
504+
assert(apfs_ctx.open("virtio:1"));
489505
#else
490506
assert(apfs_ctx.open("host:0"));
491507
#endif
@@ -495,9 +511,9 @@ void uboot_apfs_doit(void) {
495511
fmt::print("node: {:s}\n", n->name());
496512
}
497513

498-
#if 0
514+
#if 1
499515
#ifdef JEV_BAREMETAL
500-
auto dev = Device::OpenDevice("virtio:0");
516+
auto dev = Device::OpenDevice("virtio:1");
501517
#else
502518
auto dev = Device::OpenDevice("host:0");
503519
#endif
@@ -550,7 +566,7 @@ void uboot_apfs_doit(void) {
550566
// assert(apfsDir.LookupName(res, ROOT_DIR_INO_NUM, "D8961206-5EAC-4D35-94A3-5412F17E6B3B"));
551567
// printf("lookup of root dir D8961206-5EAC-4D35-94A3-5412F17E6B3B worked\n");
552568

553-
std::vector<DirRec> list_res;
569+
std::vector<ApfsDir::DirRec> list_res;
554570
const bool list_root_res = apfsDir.ListDirectory(list_res, ROOT_DIR_PARENT);
555571
printf("list_root_res: %d len: %d\n", list_root_res, (int)list_res.size());
556572
for (const auto &dir : list_res) {

0 commit comments

Comments
 (0)
Please sign in to comment.