/core/sdk-objc/ProjectTemplates/Objective-C Command Line File System/main.m

http://macfuse.googlecode.com/ · Objective C · 65 lines · 45 code · 7 blank · 13 comment · 9 complexity · 495ff485ba45dd7bb0ecb79647412a21 MD5 · raw file

  1. //
  2. // main.m
  3. // ÇPROJECTNAME?
  4. //
  5. // Created by ÇFULLUSERNAME? on ÇDATE?.
  6. // Copyright ÇYEAR? ÇORGANIZATIONNAME?. All rights reserved.
  7. //
  8. // Compile on the command line as follows:
  9. // gcc -o "ÇPROJECTNAME?" ÇPROJECTNAMEASIDENTIFIER?_Filesystem.m main.m
  10. // -framework MacFUSE -framework Foundation
  11. //
  12. #import <sys/stat.h>
  13. #import <Foundation/Foundation.h>
  14. #import <MacFUSE/GMUserFileSystem.h>
  15. #import "ÇPROJECTNAMEASIDENTIFIER?_Filesystem.h"
  16. int main(int argc, char* argv[], char* envp[], char** exec_path) {
  17. NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
  18. NSUserDefaults *args = [NSUserDefaults standardUserDefaults];
  19. NSString* mountPath = [args stringForKey:@"mountPath"];
  20. NSString* iconPath = [args stringForKey:@"volicon"];
  21. if (!mountPath || [mountPath isEqualToString:@""]) {
  22. printf("\nUsage: %s -mountPath <path> [-volicon <path>]\n", argv[0]);
  23. printf(" -mountPath: Mount point to use.\n");
  24. printf("Ex: %s -mountPath /Volumes/ÇPROJECTNAME?\n\n", argv[0]);
  25. return 0;
  26. }
  27. if (!iconPath) {
  28. // We check for a volume icon embedded as our resource fork.
  29. char program_path[PATH_MAX] = { 0 };
  30. if (realpath(*exec_path, program_path)) {
  31. iconPath = [NSString stringWithFormat:@"%s/..namedfork/rsrc", program_path];
  32. struct stat stat_buf;
  33. memset(&stat_buf, 0, sizeof(stat_buf));
  34. if (stat([iconPath UTF8String], &stat_buf) != 0 || stat_buf.st_size <= 0) {
  35. iconPath = nil; // We found an exec path, but the resource fork is empty.
  36. }
  37. }
  38. }
  39. ÇPROJECTNAMEASIDENTIFIER?_Filesystem* fs =
  40. [[ÇPROJECTNAMEASIDENTIFIER?_Filesystem alloc] init];
  41. GMUserFileSystem* userFS = [[GMUserFileSystem alloc] initWithDelegate:fs
  42. isThreadSafe:NO];
  43. NSMutableArray* options = [NSMutableArray array];
  44. if (iconPath != nil) {
  45. NSString* volArg = [NSString stringWithFormat:@"volicon=%@", iconPath];
  46. [options addObject:volArg];
  47. }
  48. [options addObject:@"volname=ÇPROJECTNAME?"];
  49. // [options addObject:@"rdonly"]; <-- Uncomment to mount read-only.
  50. [userFS mountAtPath:mountPath
  51. withOptions:options
  52. shouldForeground:YES
  53. detachNewThread:NO];
  54. [userFS release];
  55. [fs release];
  56. [pool release];
  57. return 0;
  58. }