Table of Contents

Shortcircuit

The development notes are to be used for reference while developing Shortcircuit.

Concept and Idea

Create a simple small toolbar icon utility that’s simply a shortcut to the “Connect to Server…” option in macOS so that it's simple to automatically mount our network shares on macOS.

It's also very important, since it's a common feature on Windows and many organizations would love this, add the ability to automatically mount certain drives when the system boots.

Resources

Some resources gathered while researching what would be needed for the macOS application:

Mounting network shares programatically

Whenever you search online for ways to mount a network share programatically on macOS you'll inevitably find the NetFSMountURLSync and NetFSMountURLAsync functions that apparently are available if you include the NetFS.framework to your project. Apple really wants to hide this framework from the world, since its documentation isn't available anywhere online, and even when using the full offline docsets on Xcode 5.1 I only get changelogs and not the proper documentation.

From what I was able to gather the NetFS.framework was introduced in OS X 10.6, and according to the chapter “NetFS Changes” in the “OS X 10.8 API Diffs” collection, the NetFSMountURLSync and NetFSMountURLAsync functions were only introduced in OS X 10.8.

This presents a problem, since our application is supposed to work all the way down to the OS X 10.4 release on PowerPC (to at least target the Powerbook G4s), these APIs won't be available to us, so we can use them in builds for newer operating systems, but we need to ensure that we have an alternative for older platforms. It's important to have both approaches since using the newer APIs will most likely give us a bit more compatibility with ultra modern versions of the OS.

mount(2)

POSIX will always come to our rescue! We can use the low-level mount(2) function (and its umount(2) counterpart) to perform the same operation. In fact this will allow us an even greater level of flexibility since we can let the user specify custom mount options. According to this post the data argument is simply a string with the mount options as used in the -o parameter when using the command line interface to mount.

Given the flexibility afforded with this approach, we should reconsider the idea of using this only for older systems. I'm sure many users will find it useful to have access to these advanced options. We may even be able to create a nice UI for setting some of the more common options.

Help

I've been stuck trying to implement this for way too long. Apparently instead of implementing mount(2) in a sane way we are supposed to pass complex structures and the mount point should be part of that structure, not a parameter in the function call. I've asked about this on StackOverflow and on Apple's Developer Forums. Let's hope someone is able to help me out.

In the mean time I've been able to find these two questions about using mount(2) and its syntax, although they are both trying to mount an HFS file system:

I've also located an interesting structure in under /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/nfs/nfs.h:

/*
 * Old-style arguments to mount NFS
 */
#define NFS_ARGSVERSION 6               /* change when nfs_args changes */
struct nfs_args {
        int             version;        /* args structure version number */
        struct sockaddr *addr;          /* file server address */
        uint8_t         addrlen;        /* length of address */
        int             sotype;         /* Socket type */
        int             proto;          /* and Protocol */
        u_char          *fh;            /* File handle to be mounted */
        int             fhsize;         /* Size, in bytes, of fh */
        int             flags;          /* flags */
        int             wsize;          /* write size in bytes */
        int             rsize;          /* read size in bytes */
        int             readdirsize;    /* readdir size in bytes */
        int             timeo;          /* initial timeout in .1 secs */
        int             retrans;        /* times to retry send */
        int             maxgrouplist;   /* Max. size of group list */
        int             readahead;      /* # of blocks to readahead */
        int             leaseterm;      /* obsolete: Term (sec) of lease */
        int             deadthresh;     /* obsolete: Retrans threshold */
        char            *hostname;      /* server's name */
        /* NFS_ARGSVERSION 3 ends here */
        int             acregmin;       /* reg file min attr cache timeout */
        int             acregmax;       /* reg file max attr cache timeout */
        int             acdirmin;       /* dir min attr cache timeout */
        int             acdirmax;       /* dir max attr cache timeout */
        /* NFS_ARGSVERSION 4 ends here */
        uint32_t        auth;           /* security mechanism flavor */
        /* NFS_ARGSVERSION 5 ends here */
        uint32_t        deadtimeout;    /* secs until unresponsive mount considered dead */
};

Although I haven't been able to use this in a way that works.

Windows version

It would be interesting to also offer a Windows version to help everyone that wants to simply map a network share to a drive letter without messing with Windows' super complicated and buggy wizards. It will also make mounting NFS shares a breeze for the first time.

Simply create the same UI in a .NET application, since NFS is only supported on Windows 8+, that hides itself on the system tray and allows the same functionality as its macOS counterpart. If we are interested in pain we can always write the application using the Win32 API and target all the way down to Windows 95 and only support NFS mounts on supporting OSes.

Resources

Some research on what would be needed to pull this off on Windows: