Sunday, October 14, 2007

NTFS-3G Mount/Re-Mount Script for OS X

  • Optional Command-Line Parameters:
    • Partition to mount or re-mount (must be specified as the first parameter)
    • Use the force option at mount (can be specified as either first or 2nd parameter)
    • If no parameters are entered, script enters "interactive mode," and prompts user with a menu of confirmed NTFS partitions
  • Handle volumes that are currently using the (read-only) kernel NTFS driver
    • Prompt to unmount, custom exit level if user-aborted
    • Capture name that is assigned in Finder
    • Remount as read/write using the same Finder name
  • Handle volumes that are not currently mounted
    • Mount and assign a default Finder name: NTFS-disk#s#
  • Input Sanitizing
    • Volumes can be entered as "/dev/disk#s#" or (preferably) as "disk#s#"
    • Script throws custom exit level if volume does not exist
    • Script throws custom exit level if mount command fails due to non-NTFS volume
    • Script throws custom exit level if it encounters NTFS-3G errors during mount
  • (Possible Future Enhancements)
    • Add a -? or --help option to the script for ├╝ber-completeness
    • Silent output -- rely only on the exit codes (Why? -- I can always redirect to /dev/null if I want to call it from within another script)
    • Something I haven't thought of yet...
  • bzip2 compressed version of the script (now includes updates through 1.4).
[Oct. 15] Version 1.1:
  • Implemented volume-unique mount points, so more than one disk can be mounted
  • Implemented menu (via array variable) for volume selection -- type a number instead of having to type disk#s#
[Oct. 16] Version 1.2:
  • Implemented actual type detection using File System field from "diskutil info disk#s#"
  • Previous method used reasonable speculation based on type field from "diskutil list"
  • Learned that array index values can be non-contiguous, and are not changed when array elements are unset. (This led to a later post.)
[Oct. 19] Version 1.3:
  • Added current mount point information to menu (yep, another array)
  • Added header bar to menu
  • Added Quit option to menu
[Oct. 27] Version 1.4:
  • Implemented the file system type detection for volumes that are input from the command line.
  • Previously, this was only implemented for volumes on the menu in "interactive mode."
  • Added an exit level for "Not an NTFS Volume."