afpfs-ng-OSX – connect to Classic MacOS via AFP2

About Qemu-system-ppc, a PPC Mac emulator for Windows, macOS and Linux that can run Mac OS 9.0 up to Mac OS X 10.5

Moderators: Cat_7, Ronald P. Regensburg

User avatar
mabam
Master Emulator
Posts: 497
Joined: Wed Apr 10, 2013 9:32 am

afpfs-ng-OSX – connect to Classic MacOS via AFP2

Post by mabam »

[This is the continuation of http://emaculation.com/forum/viewtopic. ... 076#p58076]

MARCH 2021 ANNOUNCEMENT:
Our user dgsga has accomplished what I would never have been able to achieve: He made netatalk compile and run on macOS!

Everyone who came here looking for a solution to network his Classic Mac or emulator (running up to Mac OS 9.2) with modern macOS, I’d like to encourage using his solution. While afpfs-ng is in fact immature and incomplete, netatalk has been developed and refined over many years making it a solid software.

Get started at:
viewtopic.php?f=34&t=11123

mabam


The first "distribution" of afpfs-ng-OSX for Snow Leopard and up is ready as .pkg installer.
"Packages" made it easy to create.

Some quick information on it:

• First install Fuse for macOS from https://osxfuse.github.io/ (don't install it via Homebrew, it probably won't work for afpfs-ng-OSX).
• Then get afpfs-ng-OSX —>here<— (the 10.6 .pgk was only tested on OS X 10.6, the 10.8 .pkg was tested on OS X 10.8 and macOS 10.12). Ctrl-click on it and choose 'open'.
• Open Terminal and start Fuse for macOS and the afpfs daemon:

Code: Select all

/Library/Filesystems/osxfuse.fs/Contents/Resources/load_osxfuse; afpfsd
• Connect to a Macintosh or emulator running Classic MacOS (should work for 7.6 through 9.2.2) by entering:

Code: Select all

mkdir ~/mount1; mount_afp2 afp://192.168.1.95/share1 ~/mount1
where "192.168.1.95" is the IP of the machine running Classic MacOS (you could also use its name), "share1" the name of the shared folder and "mount1" (twice) the folder serving as mount point in your user folder ("~/").


AFP2 doesn't support password encryption, which is not implemented in afpfs-ng-OSX anyway.
Therefore, for connecting to AFP3 servers use the built-in functionality of macOS/OS X.

afpfs-ng-OSX does connect through AFP, but it does not actually report that to macOS/OS X. Therefore resource forks and metadata are not supported. I'm working on a workaround for critical files, but it will take some time until I get that finished.

Also, I'm working on a GUI based on AppleScript that starts Fuse for macOS, shows all AFP2 servers on the network and provides mounting by clicking on their shared volumes. It should also give the mounts sensible names like "AFP2_ServerName_VolumeName" (i.s.o. "OSXFUSE Volume 0 (afpfsd)").
I think I have most of the underlying "do shell script" commands for afpfs-ng-OSX ready.


As mentioned, afpfs-ng-OSX is tested on Snow Leopard (which actually still seems to work for AFP2 without it), Mountaion Lion, and Sierra.

Any help in testing on other macOS/OS X versions will be very much appreciated!
Last edited by mabam on Wed Nov 08, 2017 11:18 pm, edited 1 time in total.
User avatar
mabam
Master Emulator
Posts: 497
Joined: Wed Apr 10, 2013 9:32 am

Re: afpfs-ng-OSX – connect to Classic MacOS via AFP2

Post by mabam »

I have written an AppleScript that requests AFP server information from all IP's on the network. From the responses it displays AFP2.x servers (only if not capable of AFP3.x) to select from a list:
Image
Upon choosing a server and clicking "Continue …" its shared volumes are requested which are again displayed as list to select from (unfortunately, AppleScript does not allow to combine both lists into one dialog):
Image
Upon clicking "Mount" the script creates the "mount_afp2 …" command prepended by "/usr/local/bin" as required by AppleScript. Now I think the problem is that mount_afp2 passes stuff to another binary without its location. That binary cannot be called directly. I tried having AppleScript run a LaunchAgent that executes a bash script. But that wouldn't work without the location prefix either and therefore resulted in the same problem.
I do not want to have the AppleScript execute a bash script directly as that would make a Terminal window pop up.

Does anyone know a solution for this issue?

(Support for password protected shares will follow at a later stage.)
User avatar
adespoton
Forum All-Star
Posts: 4226
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com
Contact:

Re: afpfs-ng-OSX – connect to Classic MacOS via AFP2

Post by adespoton »

The best solution is probably to bundle mount_afp2 inside the AppleScript application in the resources folder, along with all the other components you need.

You could use lsof to trace the file chain to see what the dependencies are....
User avatar
mabam
Master Emulator
Posts: 497
Joined: Wed Apr 10, 2013 9:32 am

Re: afpfs-ng-OSX – connect to Classic MacOS via AFP2

Post by mabam »

I'm using a sub-folder of /etc where I put stuff as I also need a place for the mount points and link to them with sensible names.

For days I was looking for a solution to the problem with calling mount_afp2. It wasn't until you responded that I found Platypus which compiles a (bash) script into an app. Its documentation mentions the possibility to use bash with the -l flag making it "act as if it had been invoked as a login shell". Maybe this also would have worked with the LaunchAgent, but using Platypus is easier and the created app can run invisibly or set to display errors if needed.

Nonetheless, thanks for your tip!
User avatar
adespoton
Forum All-Star
Posts: 4226
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com
Contact:

Re: afpfs-ng-OSX – connect to Classic MacOS via AFP2

Post by adespoton »

You're welcome :) I tend to use Platypus to create all my apps that have scripts of some sort, because it's just so easy to debug and deploy, with just a few plist and script file changes required after building.
User avatar
mabam
Master Emulator
Posts: 497
Joined: Wed Apr 10, 2013 9:32 am

Re: afpfs-ng-OSX – connect to Classic MacOS via AFP2

Post by mabam »

After inserting some lines needed if there are errors and amending a few other things, it looks like the script is ready. Except there is one thing I can't find a solution for since a while now: In the end of the script it is supposed to launch the "mount app" I have created with Platypus.

Code: Select all

tell application "/etc/afpfs-ng-OSX/afpfs-ng-OSX.mountcmd.app" to launch
But after every restart of the host machine the mount app won't launch at first attempt. Only at the second and after.

Is there a solution for this?

(If I have an AppleScript only containing the line to launch the mount app, it does launch at first attempt after a restart.)
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: afpfs-ng-OSX – connect to Classic MacOS via AFP2

Post by emendelson »

mabam wrote:After inserting some lines needed if there are errors and amending a few other things, it looks like the script is ready. Except there is one thing I can't find a solution for since a while now: In the end of the script it is supposed to launch the "mount app" I have created with Platypus.

Code: Select all

tell application "/etc/afpfs-ng-OSX/afpfs-ng-OSX.mountcmd.app" to launch
But after every restart of the host machine the mount app won't launch at first attempt. Only at the second and after.

Is there a solution for this?
I've had similar problems. I hope this message isn't time-wasting, but here are some possible alternatives that I remember using:

Code: Select all

do shell script "open /etc/afpfs-ng-OSX/afpfs-ng-OSX.mountcmd.app"

Code: Select all

tell application "Finder" to open file "/etc/afpfs-ng-OSX/afpfs-ng-OSX.mountcmd.app" 
I'm just guessing at the syntax in both examples, but these are two ideas.
User avatar
mabam
Master Emulator
Posts: 497
Joined: Wed Apr 10, 2013 9:32 am

Re: afpfs-ng-OSX – connect to Classic MacOS via AFP2

Post by mabam »

Thanks for your suggestions. The first one I had tried already. The second one I did just now but it didn't help either.
mabam wrote:(If I have an AppleScript only containing the line to launch the mount app, it does launch at first attempt after a restart.)
The above means that the app might launch if I put it at the beginning of the script. That will make it the second try when the required launch at the end of the script is attempted.
I probably know a way to amend the app so it doesn't have any effect when first launched at the beginning.
emendelson
Forum All-Star
Posts: 1706
Joined: Tue Oct 14, 2008 12:12 am

Re: afpfs-ng-OSX – connect to Classic MacOS via AFP2

Post by emendelson »

One last idea (probably as useless as the others):

Code: Select all

tell application "System Events" to open [etc.]
Apologies if this is just more time-wasting! I'm always annoyed at wasting time over pointless suggestions, but all these have worked in the past in other circumstances.
User avatar
mabam
Master Emulator
Posts: 497
Joined: Wed Apr 10, 2013 9:32 am

Re: afpfs-ng-OSX – connect to Classic MacOS via AFP2

Post by mabam »

I had tried that already but it doesn't work either. But that doesn't mean that you are wasting my time. Thank you for taking the time!

I have copied the script over from Mountain Lion to my Sierra VM to test. Same issue there except that the script get stopped after a while.

The script line is wrapped in an if block. Maybe that is related. I'm done for today, but that is something I'll have to look into.
User avatar
mabam
Master Emulator
Posts: 497
Joined: Wed Apr 10, 2013 9:32 am

Re: afpfs-ng-OSX – connect to Classic MacOS via AFP2

Post by mabam »

As last action in the AppleScript (which will run as app once finished) it launches an app that has a bash script compiled into it. I have extended that bash script by a line that will kill the AppleScript app if still running (which, as discussed, is the case at first run after reboot).

This is not a beautiful solution to my problem, but a working one.
Any better suggestions are welcome!
User avatar
celebi23
Granny Smith
Posts: 101
Joined: Wed Jun 18, 2008 5:53 am

Re: afpfs-ng-OSX – connect to Classic MacOS via AFP2

Post by celebi23 »

This solution looks awesome. Is it still being worked on?
User avatar
mabam
Master Emulator
Posts: 497
Joined: Wed Apr 10, 2013 9:32 am

Re: afpfs-ng-OSX – connect to Classic MacOS via AFP2

Post by mabam »

I have no time right now and probably won't have the coming weeks. But I'll get back to it eventually.
User avatar
mabam
Master Emulator
Posts: 497
Joined: Wed Apr 10, 2013 9:32 am

Re: afpfs-ng-OSX – connect to Classic MacOS via AFP2

Post by mabam »

A first version of the GUI is ready. I'm working on an updated package installer.

The GUI is controlled through the AppleScript menu in the menu bar (couldn't figure how to make it a stand-alone menu – the related online tutorials are above me). I'd like to have the package installer activate the AppleScript menu. Manually that is done by ticking the box "Show Script menu in menu bar" in the Script Editor settings. I suppose this setting is saved in some .plist file, but I couldn't find it.

Is there a way to set that option through an AppleScript or shell script?
(Well, if someone can tell me the location of the .plist file I know there is a way using a shell script.)


EDIT:
Found it: ~/Library/Preferences/com.apple.systemuiserver.plist
But it is not in plain text and can only be edited manually using XCode. So I won't be able to automate that.
User avatar
adespoton
Forum All-Star
Posts: 4226
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com
Contact:

Re: afpfs-ng-OSX – connect to Classic MacOS via AFP2

Post by adespoton »

mabam wrote: Found it: ~/Library/Preferences/com.apple.systemuiserver.plist
But it is not in plain text and can only be edited manually using XCode. So I won't be able to automate that.
There's a command line tool to convert binary plists to XML for editing and then convert them back after:

Code: Select all

plutil -convert <xml1|binary1> <file.plist>
User avatar
mabam
Master Emulator
Posts: 497
Joined: Wed Apr 10, 2013 9:32 am

Re: afpfs-ng-OSX – connect to Classic MacOS via AFP2

Post by mabam »

Wow, that works, thank you!

The only thing is that if I do "killall SystemUIServer" the AppleScript menu doesn't always appear though it is contained in /Users/markus/Library/Preferences/com.apple.systemuiserver.plist . Is there any way to solve that?
User avatar
adespoton
Forum All-Star
Posts: 4226
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com
Contact:

Re: afpfs-ng-OSX – connect to Classic MacOS via AFP2

Post by adespoton »

Yes, there's another service you need to reset as well -- but for the life of me I can't remember what it is.
User avatar
mabam
Master Emulator
Posts: 497
Joined: Wed Apr 10, 2013 9:32 am

Re: afpfs-ng-OSX – connect to Classic MacOS via AFP2

Post by mabam »

I've found a solution: After killing SystemUIServer I

Code: Select all

open "/System/Library/CoreServices/Menu Extras/Script Menu.menu"
That makes it run for the present session. And for the next one it gets started automatically as it is registered in SystemUIServer's .plist file.
User avatar
adespoton
Forum All-Star
Posts: 4226
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com
Contact:

Re: afpfs-ng-OSX – connect to Classic MacOS via AFP2

Post by adespoton »

If you're doing that, you could also launch your own custom menu. There's a few frameworks out there that'll do the heavy lifting for you, and let you load in the menu items you want.
User avatar
mabam
Master Emulator
Posts: 497
Joined: Wed Apr 10, 2013 9:32 am

Re: afpfs-ng-OSX – connect to Classic MacOS via AFP2

Post by mabam »

adespoton wrote:If you're doing that, you could also launch your own custom menu.
Not sure it would really be a custom menu as it gets loaded into the AppleScript menu.

EDIT: You're right, it would be a separate menu. Error in reasoning on my side ...
adespoton wrote:There's a few frameworks out there that'll do the heavy lifting for you, and let you load in the menu items you want.
If you could point me to any such framework I would be thankful as I haven't found one yet. Maybe something for a future version.
Last edited by mabam on Wed Jan 24, 2018 4:12 pm, edited 1 time in total.
User avatar
mabam
Master Emulator
Posts: 497
Joined: Wed Apr 10, 2013 9:32 am

Re: afpfs-ng-OSX – connect to Classic MacOS via AFP2

Post by mabam »

A first version of the GUI is ready.
Find a full installer at https://github.com/mabam/afpfs-ng-OSX/releases.

• The GUI doesn't support password protected shares yet. For the time being you will have to use the command line for that.
(Through the GUI it actually connects to such shares without asking for a password. But neither does the volume show any content nor can you copy anything onto it.)
• When connected to multiple AFP2.x volumes, it is not possible to unmount a single one. afpfs-ng-OSX is only able to unmount ALL those volumes at once (even if you use the command line).
• Resource forks and meta data are NOT preserved (neither here it helps to use the command line). For a future version I'm planning a conversion mechanism for critical files. Without it macOS/OS X splits such data into "." preceded files when writing on volumes mounted through afpfs-ng-OSX. I might have an automated AppleScript remove them in future.

Please report any problems with the GUI. Not sure whether I can solve them, but I will if I can.

EDIT:
All the GUI related (uncompiled) scripts and files can be found here: https://github.com/mabam/afpfs-ng-OSX-GUI.
User avatar
adespoton
Forum All-Star
Posts: 4226
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com
Contact:

Re: afpfs-ng-OSX – connect to Classic MacOS via AFP2

Post by adespoton »

A request for when you get password protected shares into the GUI version... any chance you could use the keychain for management?

Code: Select all

security unlock-keychain ~/Library/Keychains/login.keychain
<enter password>
security find-internet-password -s smtp.gmail.com -a foo@gmail.com
<dumps keychain attributes, not including password>
security find-internet-password -s smtp.gmail.com -a foo@gmail.com -g
<dumps keychain attributes, including password>
Should be doable to use the security tool to store/retrieve AFP2 password info.
User avatar
mabam
Master Emulator
Posts: 497
Joined: Wed Apr 10, 2013 9:32 am

Re: afpfs-ng-OSX – connect to Classic MacOS via AFP2

Post by mabam »

adespoton wrote:... any chance you could use the keychain for management?
From the shell commands you posted, I don't know. I will have to dive into that once I start working on supporting password protected shares. But it would definitely make sense!
User avatar
mabam
Master Emulator
Posts: 497
Joined: Wed Apr 10, 2013 9:32 am

Re: afpfs-ng-OSX – connect to Classic MacOS via AFP2

Post by mabam »

In order to preserve the resource fork, I'm working on a conversion mechanism using 'macbinary encode'. But if the original file contains for example an umlaut, StuffIt Expander in Classic MacOS fails on decoding it. Except for manually renaming the source file on the host, I don't have an idea for a workaround yet.

Any suggestions on how I could make this work?
User avatar
adespoton
Forum All-Star
Posts: 4226
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com
Contact:

Re: afpfs-ng-OSX – connect to Classic MacOS via AFP2

Post by adespoton »

I've been coming up against the same MacRoman encoding issue on a project I'm working on.

Because classic Macs don't understand UTF, but only MacRoman, 7-bit ASCII and Shift-JIS, some sort of translation will be needed prior to encoding. The source code for The Unarchiver might be useful here, as they've somehow dealt with the same issue.

The quick hack, of course, is to just throw out any characters past the 7-bit boundary and encode as ASCII. That's not very nice for any international users though.
Post Reply