Created
May 2, 2020 14:02
-
-
Save profburke/b6eb8ece9da9fe1c266ebd2c88aec665 to your computer and use it in GitHub Desktop.
ToyFS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
@NSApplicationMain | |
class AppDelegate: NSObject, NSApplicationDelegate { | |
private lazy var toyFS: SimulatorFS = { | |
return SimulatorFS() | |
}() | |
private lazy var userFileSystem: GMUserFileSystem = { | |
return GMUserFileSystem(delegate: self.toyFS, isThreadSafe: false) | |
}() | |
func applicationDidFinishLaunching(_ aNotification: Notification) { | |
let options = ["native_xattr", "volname=ToyFS"] | |
userFileSystem.mount(atPath: "/Volumes/loop", withOptions: options) | |
} | |
func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply { | |
userFileSystem.unmount() | |
return .terminateNow | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
final class ToyFS: NSObject { | |
override class func attributesOfItem(atPath path: String!, userData: Any!) throws -> [AnyHashable : Any] { | |
var attributes: [FileAttributeKey: Any] = [:] | |
attributes[.creationDate] = Date() | |
attributes[.modificationDate] = Date() | |
attributes[.groupOwnerAccountID] = getgid() | |
attributes[.ownerAccountID] = getuid() | |
if path == "/" { | |
attributes[.type] = FileAttributeType.typeDirectory | |
} else { | |
attributes[.type] = FileAttributeType.typeRegular | |
} | |
return attributes | |
} | |
override func contentsOfDirectory(atPath path: String!) throws -> [Any] { | |
return ["file54", "file349"] | |
} | |
override func attributesOfFileSystem(forPath path: String!) throws -> [AnyHashable : Any] { | |
var attributes: [FileAttributeKey: Any] = [:] | |
attributes[FileAttributeKey(rawValue: kGMUserFileSystemVolumeSupportsExtendedDatesKey)] = true | |
attributes[FileAttributeKey(rawValue: kGMUserFileSystemVolumeSupportsCaseSensitiveNamesKey)] = false | |
return attributes | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi. I found your post on the OSXFUSE Google Group but I'm not able to reply to it. Did you ever end up making any further progress on this project? I might be trying to write my own Fuse FS in Swift in the near future and I'd love to have some more examples out there and/or access to someone's brain to pick.