How to create (or verify) an SFV in Mac OS X

An SFV file is just a simple text file with each line containing a filename and a corresponding CRC-32 checksum. On Windows you can easily generate this file with a number of GUI apps (eg. Total Commander), but on the Mac you're left in the cold. There's one app named MacSFV, but to be honest, I could not find the DMG for the latest 2.0.1 version (dated back in 2003) on the net. Shock

However, the cksum command in Darwin's command line is capable of generating various CRCs. Play a little with it and you'll find that the -o 3 option switches to an algorithm that produces the same CRC as required in SFV files. Unfortunately cksum can print its checksum only in decimal format (which developer did think of this anyway? Shock), so you've to convert it to hex to be of use.

Here's a simple example to generate an SFV for all the RAR archive pieces in the current directory:
cksum -o 3 *.r* | perl -wane 'printf "%s %08X\n", $F[2], $F[0]' > checksums.sfv

To verify some files against the checksums of an SFV, you can simply create a new SFV from the files and use diff -u <original.sfv> <new.sfv> to compare them. Be careful that the original SFV file might have been created in a Windows environment and line terminators are probably CR+LF character duos, while the SFV created by you in Mac has only LF as line-terminator. Diff will not ignore line-terminator differences by default, but you can force it to by specifying the --strip-trailing-cr option.

Update (2010.08.22): I forgot that printf exists as a separate command too (and is a built-in function in some shells) so no need to invoke Perl with all it's heavy stuff. So here's another one-liner that does not use Perl and is functionally equivalent to the above commandline ...
cksum -o 3 *.r* | while read CK SIZE FILE; do printf "%s %08X\n" "$FILE" "$CK"; done > checksums.sfv

Btw. the linux/GNU cksum follows the IEEE 1003.2 (aka. POSIX.2) standard for CRC32 calculation, which is different from what an SFV should contain. However linux users have two utilities to calculate/verify SFV files: cksfv and cfv.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

mirror of the MacSFV 2.0.1 DMG

You can find a mirror of the MacSFV 2.0.1 DMG here.

It's rather easier to use than cksum and diff Smile

http://garrettreid.com/2008/macsfv-201-mirror/

Thanks for the cksum tip!

Re: mirror of the MacSFV 2.0.1 DMG

Thanks for the link! Unfortunately that blog post (and the mirror) was not yet available, when I needed MacSFV.
I see a small problem with this app that will surface sometime in the future: it's no longer maintained, thus sooner or later it'll break (hopefully not yet on Snow Leopard Smile ).

thanks

thanks

Syndicate content