Skip to content

Commit

Permalink
Update Delete fakefs logic
Browse files Browse the repository at this point in the history
  • Loading branch information
asdfugil committed Aug 9, 2024
1 parent cbe4c4e commit c2d6623
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/payload/loader/prelaunchd.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,30 @@ int prelaunchd(uint32_t payload_options, struct paleinfo* pinfo_p) {

if ((pinfo_p->flags & (palerain_option_rootful | palerain_option_force_revert)) == (palerain_option_rootful | palerain_option_force_revert)) {
if (pinfo_p->flags & palerain_option_ssv) {
char dev_rootdev[32];
CFMutableArrayRef fsArray;
int retval = APFSVolumeRoleFind(container_name(), APFS_VOL_ROLE_RECOVERY, &fsArray);
if (retval && retval != 49245) {
_panic("APFSVolumeRoleFind failed: %d: %s\n", retval, mach_error_string(retval));
}

if (!retval) {
CFStringGetCString(CFArrayGetValueAtIndex(fsArray, 0), dev_rootdev, 32, kCFStringEncodingUTF8);
CFRelease(fsArray);
}

if (!retval && access(dev_rootdev, F_OK) == 0) {
printf("will delete %s\n", dev_rootdev);
int16_t role = 0;
// 49154 = container not found, 49254 = volume with role not found
CHECK_ERROR(APFSVolumeRole(dev_rootdev, &role, NULL), 0, "APFSVolumeRole(%s) Failed", dev_rootdev);
printf("found apfs volume role: 0x%04x\n", role);
if (role != APFS_VOL_ROLE_RECOVERY) {
_panic("BUG: SAFETY: deleting non-recovery volume is not allowed\n");
} else {
CHECK_ERROR(errno = APFSVolumeDelete(&dev_rootdev[5]), 1, "failed to delete fakefs");
nvram(kIONVRAMDeletePropertyKey, "p1-fakefs-rootdev");
CFIndex fsCount = CFArrayGetCount(fsArray);
for (CFIndex i = 0; i < fsCount; i++) {
char dev_rootdev[32];
CFStringGetCString(CFArrayGetValueAtIndex(fsArray, i), dev_rootdev, 32, kCFStringEncodingUTF8);
printf("will delete %s\n", dev_rootdev);
int16_t role = 0;
// 49154 = container not found, 49254 = volume with role not found
CHECK_ERROR(APFSVolumeRole(dev_rootdev, &role, NULL), 0, "APFSVolumeRole(%s) Failed", dev_rootdev);
printf("found apfs volume role: 0x%04x\n", role);
if (role != APFS_VOL_ROLE_RECOVERY) {
_panic("BUG: SAFETY: deleting non-recovery volume is not allowed\n");
} else {
CHECK_ERROR(errno = APFSVolumeDelete(&dev_rootdev[5]), 1, "failed to delete fakefs");
}
}
CFRelease(fsArray);
nvram(kIONVRAMDeletePropertyKey, "p1-fakefs-rootdev");
}
}
}
Expand Down

0 comments on commit c2d6623

Please sign in to comment.