Skip to content

Instantly share code, notes, and snippets.

@profburke
Created May 2, 2020 14:02
Show Gist options
  • Save profburke/b6eb8ece9da9fe1c266ebd2c88aec665 to your computer and use it in GitHub Desktop.
Save profburke/b6eb8ece9da9fe1c266ebd2c88aec665 to your computer and use it in GitHub Desktop.
ToyFS
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
}
}
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
}
}
@GarrettAlbright
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment