PageRenderTime 52ms CodeModel.GetById 17ms app.highlight 32ms RepoModel.GetById 1ms app.codeStats 0ms

/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
  1//
  2//  ÇPROJECTNAMEASIDENTIFIER?_Filesystem.m
  3//  ÇPROJECTNAME?
  4//
  5//  Created by ÇFULLUSERNAME? on ÇDATE?.
  6//  Copyright ÇYEAR? ÇORGANIZATIONNAME?. All rights reserved.
  7//
  8#import <sys/xattr.h>
  9#import <sys/stat.h>
 10#importPROJECTNAMEASIDENTIFIER?_Filesystem.h"
 11#import <MacFUSE/MacFUSE.h>
 12
 13// Category on NSError to  simplify creating an NSError based on posix errno.
 14@interface NSError (POSIX)
 15+ (NSError *)errorWithPOSIXCode:(int)code;
 16@end
 17@implementation NSError (POSIX)
 18+ (NSError *)errorWithPOSIXCode:(int) code {
 19  return [NSError errorWithDomain:NSPOSIXErrorDomain code:code userInfo:nil];
 20}
 21@end
 22
 23// NOTE: It is fine to remove the below sections that are marked as 'Optional'.
 24// To create a working write-able file system, you must implement all non-optional
 25// methods fully and have them return errors correctly.
 26
 27// The core set of file system operations. This class will serve as the delegate
 28// for GMUserFileSystemFilesystem. For more details, see the section on 
 29// GMUserFileSystemOperations found in the documentation at:
 30// http://macfuse.googlecode.com/svn/trunk/core/sdk-objc/Documentation/index.html
 31@implementation ÇPROJECTNAMEASIDENTIFIER?_Filesystem
 32
 33#pragma mark Directory Contents
 34
 35- (NSArray *)contentsOfDirectoryAtPath:(NSString *)path error:(NSError **)error {
 36  *error = [NSError errorWithPOSIXCode:ENOENT];
 37  return nil;
 38}
 39
 40#pragma mark Getting and Setting Attributes
 41
 42- (NSDictionary *)attributesOfItemAtPath:(NSString *)path
 43                                userData:(id)userData
 44                                   error:(NSError **)error {
 45  *error = [NSError errorWithPOSIXCode:ENOENT];
 46  return nil;
 47}
 48
 49- (NSDictionary *)attributesOfFileSystemForPath:(NSString *)path
 50                                          error:(NSError **)error {
 51  return [NSDictionary dictionary];  // Default file system attributes.
 52}
 53
 54- (BOOL)setAttributes:(NSDictionary *)attributes 
 55         ofItemAtPath:(NSString *)path
 56             userData:(id)userData
 57                error:(NSError **)error {
 58  return YES; 
 59}
 60
 61#pragma mark File Contents
 62
 63- (BOOL)openFileAtPath:(NSString *)path 
 64                  mode:(int)mode
 65              userData:(id *)userData
 66                 error:(NSError **)error {
 67  *error = [NSError errorWithPOSIXCode:ENOENT];
 68  return NO;
 69}
 70
 71- (void)releaseFileAtPath:(NSString *)path userData:(id)userData {
 72}
 73
 74- (int)readFileAtPath:(NSString *)path 
 75             userData:(id)userData
 76               buffer:(char *)buffer 
 77                 size:(size_t)size 
 78               offset:(off_t)offset
 79                error:(NSError **)error {
 80  return 0;  // We've reached end of file.
 81}
 82
 83- (int)writeFileAtPath:(NSString *)path 
 84              userData:(id)userData
 85                buffer:(const char *)buffer
 86                  size:(size_t)size 
 87                offset:(off_t)offset
 88                error:(NSError **)error {
 89  return size;
 90}
 91
 92// (Optional)
 93- (BOOL)exchangeDataOfItemAtPath:(NSString *)path1
 94                  withItemAtPath:(NSString *)path2
 95                           error:(NSError **)error {
 96  return YES;
 97}
 98
 99#pragma mark Creating an Item
100
101- (BOOL)createDirectoryAtPath:(NSString *)path 
102                   attributes:(NSDictionary *)attributes
103                        error:(NSError **)error {
104  return YES;
105}
106
107- (BOOL)createFileAtPath:(NSString *)path 
108              attributes:(NSDictionary *)attributes
109                userData:(id *)userData
110                   error:(NSError **)error {
111  return YES;
112}
113
114#pragma mark Moving an Item
115
116- (BOOL)moveItemAtPath:(NSString *)source 
117               toPath:(NSString *)destination
118                error:(NSError **)error {
119  return YES;
120}
121
122#pragma mark Removing an Item
123
124// Optional
125- (BOOL)removeDirectoryAtPath:(NSString *)path error:(NSError **)error {
126  return YES;
127}
128
129- (BOOL)removeItemAtPath:(NSString *)path error:(NSError **)error {
130  return YES;
131}
132
133#pragma mark Linking an Item (Optional)
134
135- (BOOL)linkItemAtPath:(NSString *)path
136                toPath:(NSString *)otherPath
137                 error:(NSError **)error {
138  return NO; 
139}
140
141#pragma mark Symbolic Links (Optional)
142
143- (BOOL)createSymbolicLinkAtPath:(NSString *)path 
144             withDestinationPath:(NSString *)otherPath
145                           error:(NSError **)error {
146  return NO;
147}
148
149- (NSString *)destinationOfSymbolicLinkAtPath:(NSString *)path
150                                        error:(NSError **)error {
151  *error = [NSError errorWithPOSIXCode:ENOENT];
152  return NO;
153}
154
155#pragma mark Extended Attributes (Optional)
156
157- (NSArray *)extendedAttributesOfItemAtPath:(NSString *)path error:(NSError **)error {
158  return [NSArray array];  // No extended attributes.
159}
160
161- (NSData *)valueOfExtendedAttribute:(NSString *)name 
162                        ofItemAtPath:(NSString *)path
163                            position:(off_t)position
164                               error:(NSError **)error {
165  *error = [NSError errorWithPOSIXCode:ENOATTR];
166  return nil;
167}
168
169- (BOOL)setExtendedAttribute:(NSString *)name
170                ofItemAtPath:(NSString *)path
171                       value:(NSData *)value
172                    position:(off_t)position
173                     options:(int)options
174                       error:(NSError **)error {
175  return YES;
176}
177
178- (BOOL)removeExtendedAttribute:(NSString *)name
179                   ofItemAtPath:(NSString *)path
180                          error:(NSError **)error {
181  return YES;
182}
183
184#pragma mark FinderInfo and ResourceFork (Optional)
185
186- (NSDictionary *)finderAttributesAtPath:(NSString *)path 
187                                   error:(NSError **)error {
188  return [NSDictionary dictionary];
189}
190
191- (NSDictionary *)resourceAttributesAtPath:(NSString *)path
192                                     error:(NSError **)error {
193  return [NSDictionary dictionary];
194}
195
196@end