/filesystems-objc/LoopbackFS/loop.m

http://macfuse.googlecode.com/ · Objective C · 66 lines · 35 code · 7 blank · 24 comment · 3 complexity · d45f1ec75f07f21af30ba5ba7da10b93 MD5 · raw file

  1. // ================================================================
  2. // Copyright (C) 2007 Google Inc.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. // ================================================================
  16. //
  17. // loop.m
  18. // LoopbackFS
  19. //
  20. // Created by ted on 12/30/07.
  21. //
  22. // This is a cmdline version of LoopbackFS. Compile as follows:
  23. // gcc -o loop LoopbackFS.m loop.m -framework MacFUSE -framework Foundation
  24. //
  25. #import <Foundation/Foundation.h>
  26. #import <MacFUSE/GMUserFileSystem.h>
  27. #import "LoopbackFS.h"
  28. #define DEFAULT_MOUNT_PATH "/Volumes/loop"
  29. int main(int argc, char* argv[]) {
  30. NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
  31. NSUserDefaults *args = [NSUserDefaults standardUserDefaults];
  32. NSString* rootPath = [args stringForKey:@"rootPath"];
  33. NSString* mountPath = [args stringForKey:@"mountPath"];
  34. if (!mountPath || [mountPath isEqualToString:@""]) {
  35. mountPath = [NSString stringWithUTF8String:DEFAULT_MOUNT_PATH];
  36. }
  37. if (!rootPath) {
  38. printf("\nUsage: %s -rootPath <path> [-mountPath <path>]\n", argv[0]);
  39. printf(" -rootPath: Local directory path to mount, ex: /tmp\n");
  40. printf(" -mountPath: Mount point to use. [Default='%s']\n",
  41. DEFAULT_MOUNT_PATH);
  42. printf("Ex: %s -rootPath /tmp -mountPath %s\n\n", argv[0],
  43. DEFAULT_MOUNT_PATH);
  44. return 0;
  45. }
  46. LoopbackFS* loop = [[LoopbackFS alloc] initWithRootPath:rootPath];
  47. GMUserFileSystem* userFS = [[GMUserFileSystem alloc] initWithDelegate:loop
  48. isThreadSafe:YES];
  49. NSMutableArray* options = [NSMutableArray array];
  50. [options addObject:@"debug"];
  51. [userFS mountAtPath:mountPath
  52. withOptions:options
  53. shouldForeground:YES
  54. detachNewThread:NO];
  55. [userFS release];
  56. [loop release];
  57. [pool release];
  58. return 0;
  59. }