/core/sdk-objc/ProjectTemplates/Objective-C File System (Read-Write)/TemplateFS_Filesystem.m
http://macfuse.googlecode.com/ · Objective C · 196 lines · 142 code · 37 blank · 17 comment · 0 complexity · b386877a237d5c9e762e11211b916917 MD5 · raw file
- //
- // ÇPROJECTNAMEASIDENTIFIER?_Filesystem.m
- // ÇPROJECTNAME?
- //
- // Created by ÇFULLUSERNAME? on ÇDATE?.
- // Copyright ÇYEAR? ÇORGANIZATIONNAME?. All rights reserved.
- //
- #import <sys/xattr.h>
- #import <sys/stat.h>
- #import "ÇPROJECTNAMEASIDENTIFIER?_Filesystem.h"
- #import <MacFUSE/MacFUSE.h>
- // Category on NSError to simplify creating an NSError based on posix errno.
- @interface NSError (POSIX)
- + (NSError *)errorWithPOSIXCode:(int)code;
- @end
- @implementation NSError (POSIX)
- + (NSError *)errorWithPOSIXCode:(int) code {
- return [NSError errorWithDomain:NSPOSIXErrorDomain code:code userInfo:nil];
- }
- @end
- // NOTE: It is fine to remove the below sections that are marked as 'Optional'.
- // To create a working write-able file system, you must implement all non-optional
- // methods fully and have them return errors correctly.
- // The core set of file system operations. This class will serve as the delegate
- // for GMUserFileSystemFilesystem. For more details, see the section on
- // GMUserFileSystemOperations found in the documentation at:
- // http://macfuse.googlecode.com/svn/trunk/core/sdk-objc/Documentation/index.html
- @implementation ÇPROJECTNAMEASIDENTIFIER?_Filesystem
- #pragma mark Directory Contents
- - (NSArray *)contentsOfDirectoryAtPath:(NSString *)path error:(NSError **)error {
- *error = [NSError errorWithPOSIXCode:ENOENT];
- return nil;
- }
- #pragma mark Getting and Setting Attributes
- - (NSDictionary *)attributesOfItemAtPath:(NSString *)path
- userData:(id)userData
- error:(NSError **)error {
- *error = [NSError errorWithPOSIXCode:ENOENT];
- return nil;
- }
- - (NSDictionary *)attributesOfFileSystemForPath:(NSString *)path
- error:(NSError **)error {
- return [NSDictionary dictionary]; // Default file system attributes.
- }
- - (BOOL)setAttributes:(NSDictionary *)attributes
- ofItemAtPath:(NSString *)path
- userData:(id)userData
- error:(NSError **)error {
- return YES;
- }
- #pragma mark File Contents
- - (BOOL)openFileAtPath:(NSString *)path
- mode:(int)mode
- userData:(id *)userData
- error:(NSError **)error {
- *error = [NSError errorWithPOSIXCode:ENOENT];
- return NO;
- }
- - (void)releaseFileAtPath:(NSString *)path userData:(id)userData {
- }
- - (int)readFileAtPath:(NSString *)path
- userData:(id)userData
- buffer:(char *)buffer
- size:(size_t)size
- offset:(off_t)offset
- error:(NSError **)error {
- return 0; // We've reached end of file.
- }
- - (int)writeFileAtPath:(NSString *)path
- userData:(id)userData
- buffer:(const char *)buffer
- size:(size_t)size
- offset:(off_t)offset
- error:(NSError **)error {
- return size;
- }
- // (Optional)
- - (BOOL)exchangeDataOfItemAtPath:(NSString *)path1
- withItemAtPath:(NSString *)path2
- error:(NSError **)error {
- return YES;
- }
- #pragma mark Creating an Item
- - (BOOL)createDirectoryAtPath:(NSString *)path
- attributes:(NSDictionary *)attributes
- error:(NSError **)error {
- return YES;
- }
- - (BOOL)createFileAtPath:(NSString *)path
- attributes:(NSDictionary *)attributes
- userData:(id *)userData
- error:(NSError **)error {
- return YES;
- }
- #pragma mark Moving an Item
- - (BOOL)moveItemAtPath:(NSString *)source
- toPath:(NSString *)destination
- error:(NSError **)error {
- return YES;
- }
- #pragma mark Removing an Item
- // Optional
- - (BOOL)removeDirectoryAtPath:(NSString *)path error:(NSError **)error {
- return YES;
- }
- - (BOOL)removeItemAtPath:(NSString *)path error:(NSError **)error {
- return YES;
- }
- #pragma mark Linking an Item (Optional)
- - (BOOL)linkItemAtPath:(NSString *)path
- toPath:(NSString *)otherPath
- error:(NSError **)error {
- return NO;
- }
- #pragma mark Symbolic Links (Optional)
- - (BOOL)createSymbolicLinkAtPath:(NSString *)path
- withDestinationPath:(NSString *)otherPath
- error:(NSError **)error {
- return NO;
- }
- - (NSString *)destinationOfSymbolicLinkAtPath:(NSString *)path
- error:(NSError **)error {
- *error = [NSError errorWithPOSIXCode:ENOENT];
- return NO;
- }
- #pragma mark Extended Attributes (Optional)
- - (NSArray *)extendedAttributesOfItemAtPath:(NSString *)path error:(NSError **)error {
- return [NSArray array]; // No extended attributes.
- }
- - (NSData *)valueOfExtendedAttribute:(NSString *)name
- ofItemAtPath:(NSString *)path
- position:(off_t)position
- error:(NSError **)error {
- *error = [NSError errorWithPOSIXCode:ENOATTR];
- return nil;
- }
- - (BOOL)setExtendedAttribute:(NSString *)name
- ofItemAtPath:(NSString *)path
- value:(NSData *)value
- position:(off_t)position
- options:(int)options
- error:(NSError **)error {
- return YES;
- }
- - (BOOL)removeExtendedAttribute:(NSString *)name
- ofItemAtPath:(NSString *)path
- error:(NSError **)error {
- return YES;
- }
- #pragma mark FinderInfo and ResourceFork (Optional)
- - (NSDictionary *)finderAttributesAtPath:(NSString *)path
- error:(NSError **)error {
- return [NSDictionary dictionary];
- }
- - (NSDictionary *)resourceAttributesAtPath:(NSString *)path
- error:(NSError **)error {
- return [NSDictionary dictionary];
- }
- @end