@@ -104,6 +104,12 @@ class DirRec : public ApfsDir::DirRec {
104
104
};
105
105
106
106
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
+ }
107
113
APFSPath (const std::string &full_path) {
108
114
// cases:
109
115
// (empty) -> /
@@ -228,7 +234,42 @@ ApfsVolumeSP lookupVolume(const std::string &volName, ApfsContainer *container)
228
234
return vol;
229
235
}
230
236
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
+ // }
232
273
return nullptr ;
233
274
}
234
275
@@ -266,13 +307,16 @@ std::vector<APFSNodeSP> listContainerAsNodes(ApfsContainer *container) {
266
307
}
267
308
268
309
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 ;
270
314
auto subpaths = std::make_shared<std::vector<DirRecSP>>();
271
315
return subpaths;
272
316
}
273
317
274
318
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) {
276
320
auto dirrecs = listPath (container, volume, path);
277
321
if (!dirrecs)
278
322
return nullptr ;
@@ -291,34 +335,8 @@ std::shared_ptr<std::vector<APFSNodeSP>> list(const APFSPath &path, ApfsContaine
291
335
if (!vol)
292
336
return nullptr ;
293
337
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);
322
340
}
323
341
324
342
class APFSCtx {
@@ -338,7 +356,7 @@ class APFSCtx {
338
356
auto part_num = 0 ;
339
357
if (part_num_str) {
340
358
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 ;
342
360
}
343
361
assert (part_num >= 0 );
344
362
@@ -348,9 +366,7 @@ class APFSCtx {
348
366
349
367
GptPartitionMap gpt;
350
368
assert (gpt.LoadAndVerify (m_dev));
351
- fmt::print (" gpt.size: {:d}\n " , gpt.size ());
352
369
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);
354
370
return open_common ();
355
371
}
356
372
bool open (struct blk_desc *fs_dev_desc, struct disk_partition *fs_partition) {
@@ -485,7 +501,7 @@ void uboot_apfs_doit(void) {
485
501
// g_debug = 0xff;
486
502
487
503
#ifdef JEV_BAREMETAL
488
- assert (apfs_ctx.open (" virtio:0: 1" ));
504
+ assert (apfs_ctx.open (" virtio:1" ));
489
505
#else
490
506
assert (apfs_ctx.open (" host:0" ));
491
507
#endif
@@ -495,9 +511,9 @@ void uboot_apfs_doit(void) {
495
511
fmt::print (" node: {:s}\n " , n->name ());
496
512
}
497
513
498
- #if 0
514
+ #if 1
499
515
#ifdef JEV_BAREMETAL
500
- auto dev = Device::OpenDevice("virtio:0 ");
516
+ auto dev = Device::OpenDevice (" virtio:1 " );
501
517
#else
502
518
auto dev = Device::OpenDevice (" host:0" );
503
519
#endif
@@ -550,7 +566,7 @@ void uboot_apfs_doit(void) {
550
566
// assert(apfsDir.LookupName(res, ROOT_DIR_INO_NUM, "D8961206-5EAC-4D35-94A3-5412F17E6B3B"));
551
567
// printf("lookup of root dir D8961206-5EAC-4D35-94A3-5412F17E6B3B worked\n");
552
568
553
- std::vector<DirRec> list_res;
569
+ std::vector<ApfsDir:: DirRec> list_res;
554
570
const bool list_root_res = apfsDir.ListDirectory (list_res, ROOT_DIR_PARENT);
555
571
printf (" list_root_res: %d len: %d\n " , list_root_res, (int )list_res.size ());
556
572
for (const auto &dir : list_res) {
0 commit comments