Plan 9 from Bell Labs’s /usr/web/sources/contrib/de0u/root/sys/src/cmd/divergefs/main.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.



#include <u.h>
#include <libc.h>
#include <String.h>
#include "common.h"
#include "debug.h"
#include "holemanager.h"
#include "fs.h"

enum { DEBUG_MAIN = true };

static void usage(void)
{
  debug_print("usage", 
    "\tdivergefs -f rulefile [-h holefile] [-d debuglevel] mountpoint\n"
    "\t\tdivergefs -p defaultpath mountpoint");
  exits("usage");
}

/**
 * parses use the command line arguments to initialize the given setting object
 */
static Setting *parse_options(int argc, char **argv)
{
  char *rulefile = nil;
  char *holefile = nil;
  char *defaultpath = nil;

  ARGBEGIN
  {
    case 'd':
      /* sets fs' own debugging level */
      debug_set_level(atoi(EARGF(usage())));
      break;
    case 'D':
      fs_native_9p_debug_enable();
      break;
    case 'h':
      holefile = EARGF(usage());
      break;
    case 'f':
      rulefile = EARGF(usage());
      break;
    case 'p':
      defaultpath = EARGF(usage());
      break;
    default:
      usage();
  }
  ARGEND

  if(argc < 1)
  {
    usage();
  }

  if(rulefile == nil && holefile == nil && defaultpath == nil)
  {
    defaultpath = "/tmp";
  }

  NOISE(DEBUG_MAIN, "parse_options rulefile: %s holefile: %s defaultpath: %s",
    rulefile, holefile, defaultpath);
  return (defaultpath == nil) ?
    setting_new(rulefile, argv[0], holefile) :
    setting_default_path_new(defaultpath, rulefile, argv[0], holefile);
}

void main(int argc, char **argv)
{
  Setting *setting;

  debug_init();
  setting = parse_options(argc, argv);

  if(setting != nil)
  {
    NOISE(DEBUG_MAIN, "main starting fs ...");
    fs_start(setting);
  }
  else
  {
    ERROR(DEBUG_MAIN, "main failed to parse rule file");
  }

  NOISE(DEBUG_MAIN, "main exits");
  exits(nil);
}


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.