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