|
|
Command Line Utility for HFS+ Compressed Files
Since I submitted this hint I've been working on a solution for the lack of information about HFS+ compression files, by developing this command line utility:
afsctool (source is included) Here's the usage information for it:
The -c flag applies in place HFS+ compression to a file or recursively to a folder, with the option to specify the compression level (default is 9), change the default maximum size (in bytes) of files to process (default is 20971520, which is 20 MiB), and specify the minimum savings for a file to be HFS+ compressed. If the -k flag is given then compressed files will be checked after compression against the uncompressed files, and if any corruption has occurred then the file will be reverted back to its uncompressed form. The -l flag lists HFS+ compressed files in a folder or if the -c flag is given, it lists the files that fail to compress. The -d flag decompresses HFS+ compressed files (similar to afscexpand, but sometimes more reliable). The -a flag flattens a HFS+ compressed file to the data fork of the destination file, decompressing the original compressed file afterwards if the -d flag is given. The -x flag does the reverse of -a, unflattening a file with HFS+ compressed data in the data fork to the destination file, then decompressed the destination file is the -d flag is given. The -v flag increases verbosity.Here's some example output: A warning about using this utility; do NOT try to compress the System folder. Any files that were not compressed in the System folder were left uncompressed for a reason! If you do try to compress your System folder further, then you will very likely end up having to reinstall Mac OS X.
Command Line Utility for HFS+ Compressed Files
This looks really useful! I'd like to incorporate this into my Backup Bouncer test suite:
http://n8gray.org/code/backup-bouncer Do you approve? Do you have this tool hosted somewhere so I can check for updates? Thanks, -n8
Command Line Utility for HFS+ Compressed Files
Sure, as long as Backup Bouncer remains open source I have no problem with you reusing the code in afsctool. Currently I'm keeping this link updated with the latest version:
http://files.me.com/brkirch/ijt4f7
Command Line Utility for HFS+ Compressed Files
Your tool is great; the source contains a lot of magic numbers buried directly. I guess it took a lot of times for you to reverse-engineer the format!
Command Line Utility for HFS+ Compressed Files
The first thing that I tried to do was figure out the system call used for compression;
ditto uses the private framework Bom to compress files. However, looking into it further I found that the Bom framework makes a call to another private framework: AppleFSCompression. Unfortunately the syntax for the functions in AppleFSCompression is far from obvious, especially since it is a private framework which means that there are no included headers for it (and it also means that it will probably remain closed source). It didn't in the end matter however, because I found that zlib is used for the actual compression and that library is well documented. So I decided to simply figure out how the HFS+ compressed files are constructed and added that to my program.Here's how the HFS+ compression is applied: 1. Check the file to ensure it does not have a resource fork or com.apple.decmpfs extended attribute. 2. Construct the headers, calculate the number of 64 KiB blocks needed based on the source file size. 3. Compress the 64 KiB blocks using zlib (Apple uses compression level 5, but other compression levels also work); if there is only one block then append it to the com.apple.decmpfs extended attribute if the compressed data is 3786 bytes or less in size, otherwise the compressed data is put into the resource fork of the file. If the resource fork is used to store the compressed data, then no block is allowed to be larger after compression (if a block is larger after compression then compression for the entire file will fail). After the compressed blocks are created then their locations and sizes are written to the resource fork data header. 4. Add the com.apple.decmpfs extended attribute to the file, then the resource fork if one is needed. 5. Truncate the data fork length to zero and use chflags to set the HFS+ compression flag. This produces compressed files that are identical to the ones produced by ditto, provided compression level 5 was used for the zlib functions.
Command Line Utility for HFS+ Compressed Files
The download link is broken->goes to MacOSXHints.
Download afsctool here: http://files.me.com/brkirch/ijt4f7
Command Line Utility for HFS+ Compressed Files
Thanks for posting a fixed link, when I previewed the post it looked like the redirect it added should work, but apparently not. There is also one other mistake in my post; the default compression level is 5 (the same as the compression level
ditto uses).
Command Line Utility for HFS+ Compressed Files
Just a quick q - everything I try to compress via afsctool seems to give me an 'Unable to compress file,' which isn't particularly informative…Â Any clue as to what could be causing everything to fail out? And it's not the obvious - I am on 10.6, HFS+…
Command Line Utility for HFS+ Compressed Files
The latest version of afsctool will only fail to compress a file if one of the following is true:
Website for afsctool
I have made a website for my software: |
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysNo new commentsLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.20 seconds |
|