SHARE
TWEET

Disable HFS Journaling

a guest Jun 28th, 2010 3,120 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/types.h>
  5. #include <sys/mman.h>
  6. #include <fcntl.h>
  7.  
  8.  
  9.  
  10. int main(int argc, char *argv[])
  11. {
  12.         int fd = open(argv[1], O_RDWR);
  13.         if(fd < 0) {
  14.                 perror("open");
  15.                 return -1;
  16.         }
  17.        
  18.         unsigned char *buffer = (unsigned char *)mmap(NULL, 2048, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
  19.         if(buffer == (unsigned char*)0xffffffff) {
  20.                 perror("mmap");
  21.                 return -1;
  22.         }
  23.        
  24.         if((buffer[1024] != 'H') && (buffer[1025] != '+')) {
  25.                 fprintf(stderr, "%s: HFS+ signature not found -- aborting.\n", argv[0]);
  26.                 return -1;
  27.         }
  28.        
  29.         unsigned long attributes = *(unsigned long *)(&buffer[1028]);
  30.         attributes = bswap_32(attributes);
  31.         printf("attributes = 0x%8.8x\n", attributes);
  32.        
  33.         if(!(attributes & 0x00002000)) {
  34.                 printf("kHFSVolumeJournaledBit not currently set in the volume attributes field.\n");
  35.         }
  36.        
  37.         attributes &= 0xffffdfff;
  38.         attributes = bswap_32(attributes);
  39.         *(unsigned long *)(&buffer[1028]) = attributes;
  40.        
  41.         buffer[1032] = '1';
  42.         buffer[1033] = '0';
  43.         buffer[1034] = '.';
  44.         buffer[1035] = '0';
  45.        
  46.         buffer[1036] = 0;
  47.         buffer[1037] = 0;
  48.         buffer[1038] = 0;
  49.         buffer[1039] = 0;
  50.        
  51.         printf("journal has been disabled.\n");
  52.         return 0;
  53. }
RAW Paste Data
Want to get better at C?
Learn to code C in 2017
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top