Skip to content

Instantly share code, notes, and snippets.

@Luxter77
Last active June 19, 2021 01:27
Show Gist options
  • Save Luxter77/1b35e4c988e05c750ee4e8d6009448d2 to your computer and use it in GitHub Desktop.
Save Luxter77/1b35e4c988e05c750ee4e8d6009448d2 to your computer and use it in GitHub Desktop.
Disable hfs journaling by flipping bits on raw disk (bad idea, but sometimes nesesary when disk is on a poor state and you just want to do the thing)
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <byteswap.h>
int main(int argc, char * argv[]) {
int fd = open(argv[1], O_RDWR);
if (fd < 0) {
perror("open");
return -1;
}
unsigned char * buffer = (unsigned char * ) mmap(NULL, 2048, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (buffer == (unsigned char * ) 0xffffffff) {
perror("mmap");
return -1;
}
if ((buffer[1024] != 'H') && (buffer[1025] != '+')) {
fprintf(stderr, "%s: HFS+ signature not found -- aborting.\n", argv[0]);
return -1;
}
unsigned long attributes = * (unsigned long * )( & buffer[1028]);
attributes = bswap_32(attributes);
printf("attributes = 0x%8.8x\n", attributes);
if (!(attributes & 0x00002000)) {
printf("kHFSVolumeJournaledBit not currently set in the volume attributes field.\n");
}
attributes &= 0xffffdfff;
attributes = bswap_32(attributes);
*(unsigned long * )( & buffer[1028]) = attributes;
buffer[1032] = '1';
buffer[1033] = '0';
buffer[1034] = '.';
buffer[1035] = '0';
buffer[1036] = 0;
buffer[1037] = 0;
buffer[1038] = 0;
buffer[1039] = 0;
printf("journal has been disabled.\n");
return 0;
}
@Luxter77
Copy link
Author

Luxter77 commented Jun 6, 2021

This hack from this pastebin post I found on this old forum tread

@Luxter77
Copy link
Author

Luxter77 commented Jun 6, 2021

Linux headers are required for this one
gcc ./manually-disable-hfs-jounal-flag.c -o manually-disable-hfs-jounal-flag -Wno-format
usage is simple, just execute the binary pointing to the partition you want the journal disabled from
./manually-disable-hfs-jounal-flag /dev/partition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment