Exemple #1
0
void usage(char *progname, struct ltfs_fuse_data *priv)
{
	int ret;
	const char *default_driver = config_file_get_default_plugin("driver", priv->config);
	const char *default_device = NULL;

	if (! priv->advanced_help) {
		if (! priv->tape_backend_name)
			priv->tape_backend_name = default_driver;

		ret = plugin_load(&priv->driver_plugin, "driver", priv->tape_backend_name, priv->config);
		if (ret == 0)
			default_device = ltfs_default_device_name(priv->driver_plugin.ops);

		ltfsresult("14400I", progname);                   /* usage: %s mountpoint [options] */
		fprintf(stderr, "\n");
		ltfsresult("14401I");                             /* LTFS options: */
		if (default_device)
			ltfsresult("14402I", default_device);         /* -o devname=<dev> */
		else
			ltfsresult("14403I");                         /* -o devname=<dev> */
		ltfsresult("14404I", LTFS_DEFAULT_WORK_DIR);      /* -o work_directory=<dir> */
		ltfsresult("14405I");                             /* -o trace */
		ltfsresult("14425I");                             /* -o eject */
#ifdef HP_mingw_BUILD
		ltfsresult("14480I", LONG_MAX / 60);              /* -o sync_type=type */
#else
		ltfsresult("14427I", LONG_MAX / 60);              /* -o sync_type=type */
#endif /* HP_mingw_BUILD */
		ltfsresult("14443I");                             /* -o force_mount_no_eod */
		/*ltfsresult("14436I");*/                         /* -o device_list */
		ltfsresult("14437I");                             /* -o rollback_mount */
		ltfsresult("14448I");                             /* -o release_device */
		ltfsresult("14461I");                             /* -o symlink_type=type */
		ltfsresult("14406I");                             /* -a */
		ltfsresult("14407I");                             /* -V, --version */
		ltfsresult("14408I");                             /* -h, --help */
		fprintf(stderr, "\n");
		ltfsresult("14409I");                             /* FUSE options: */
		ltfsresult("14410I");                             /* -o umask=M */
		ltfsresult("14411I");                             /* -o uid=N */
		ltfsresult("14412I");                             /* -o gid=N */
		fprintf(stderr, "\n");
		fprintf(stderr, "\n");

		if (ret == 0)
			plugin_unload(&priv->driver_plugin);
	} else {
		fprintf(stderr, "\n");
		single_drive_advanced_usage(default_driver, priv);
		fprintf(stderr, "\n");
		plugin_usage(progname, "driver", priv->config);
		/* We will not be printing any messages related to 'kmi'. */
		/*plugin_usage("kmi", priv->config);*/
	}
}
Exemple #2
0
void show_usage(char *appname, struct config_file *config, bool full)
{
	struct libltfs_plugin backend;
	const char *default_backend;
	char *devname = NULL;

	default_backend = config_file_get_default_plugin("driver", config);
	if (default_backend && plugin_load(&backend, "driver", default_backend, config) == 0) {
		devname = strdup(ltfs_default_device_name(backend.ops));
		plugin_unload(&backend);
	}

	if (! devname)
		devname = strdup("<devname>");

	fprintf(stderr, "\n");
	ltfsresult("15400I", appname);  /* Usage: %s <options> */
	fprintf(stderr, "\n");
	ltfsresult("15401I");           /* Available options are: */
	ltfsresult("15402I");           /* -d, --device=<name> */
	ltfsresult("15420I");           /* -f, --force */
	ltfsresult("15403I");           /* -s, --tape-serial=<id> */
	ltfsresult("15404I");           /* -n, --volume-name */
	ltfsresult("15405I");           /* -r, --rules=<rule[,rule]> */
	ltfsresult("15406I");           /*     --no-override */
	ltfsresult("15418I");           /* -w, --wipe */
	ltfsresult("15407I");           /* -q, --quiet */
	ltfsresult("15408I");           /* -t, --trace */
	ltfsresult("15422I");           /* --syslogtrace */
	ltfsresult("15423I");			/* -V, --version */
	ltfsresult("15409I");           /* -h, --help */
	ltfsresult("15412I");           /* -p, --advanced-help */
	ltfsresult("15496I");			/* -g, --interactive */
	if (full) {
		ltfsresult("15413I", LTFS_CONFIG_FILE);       /* -i, --config=<file> */
		ltfsresult("15414I", default_backend);        /* -e, --backend */
		/* We have disabled all messages related to the 'kmi' backend. */
		/*ltfsresult("15421I", config_file_get_default_plugin("kmi", config));*/ /*     --kmi-backend */
		ltfsresult("15415I", LTFS_DEFAULT_BLOCKSIZE); /* -b, --blocksize */
		ltfsresult("15416I");                         /* -c, --no-compression */
		ltfsresult("15419I");                         /* -k, --keep-capacity */
		ltfsresult("15417I");                         /* -x, --fulltrace */
		ltfsresult("15424I");                         /* --long-wipe */
		fprintf(stderr, "\n");
		plugin_usage(appname, "driver", config);
		/*plugin_usage("kmi", config);*/
	}
	fprintf(stderr, "\n");
	ltfsresult("15410I"); /* Usage example: */
	ltfsresult("15411I", appname, devname, "size=100K"); /* %s --device=%s --rules="%s" */
	ltfsresult("15411I", appname, devname, "size=1M/name=*.jpg");
	ltfsresult("15411I", appname, devname, "size=1M/name=*.jpg:*.png");
	fprintf(stderr, "\n");

	free(devname);
}
Exemple #3
0
void show_usage(char *appname, struct config_file *config, bool full)
{
	struct libltfs_plugin backend;
	const char *default_backend;
	char *devname = NULL;

	default_backend = config_file_get_default_plugin("driver", config);
	if (default_backend && plugin_load(&backend, "driver", default_backend, config) == 0) {
		devname = strdup(ltfs_default_device_name(backend.ops));
		plugin_unload(&backend);
	}

	if (! devname)
		devname = strdup("<devname>");

	ltfsresult("16400I", appname); /* Usage: %s [options] filesys */
	fprintf(stderr, "\n");
	ltfsresult("16401I"); /* filesys   Device file for the tape drive */
	fprintf(stderr, "\n");
	ltfsresult("16402I"); /* Available options are: */
	ltfsresult("16403I"); /* -g, --generation */
	ltfsresult("16404I"); /* -r, --rollback */
	ltfsresult("16405I"); /* -n, --no-rollback */
	ltfsresult("16406I", LTFS_LOSTANDFOUND_DIR); /* -f, --full-recovery */
	ltfsresult("16421I"); /* -z --deep-recovery */
	ltfsresult("16407I"); /* -l, --list-rollback-points */
	ltfsresult("16422I"); /* -m, --full-index-info */
	ltfsresult("16420I"); /* -v, --traverse */
	ltfsresult("16408I"); /* -j, --erase-history */
	ltfsresult("16409I"); /* -k, --keep-history */
	ltfsresult("16410I"); /* -q, --quiet */
	ltfsresult("16411I"); /* -t, --trace */
	ltfsresult("16425I"); /* --syslogtrace */
	ltfsresult("16426I"); /* -V --version */
	ltfsresult("16412I"); /* -h, --help */
	ltfsresult("16413I"); /* -p, --advanced-help */
	if (full) {
		ltfsresult("16414I", LTFS_CONFIG_FILE); /* -i, --config=<file> */
		ltfsresult("16415I");                   /* -e, --backend=<name> */
		/* We have disabled all messages related to 'kmi' */
		/*ltfsresult("16423I");*/                   /*     --kmi-backend=<name> */
		ltfsresult("16416I");                   /* -x, --fulltrace */
		ltfsresult("16424I");                   /*     --capture-index */
		ltfsresult("16427I");                   /*     --salvage-rollback-points */
		fprintf(stderr, "\n");
		plugin_usage(appname, "driver", config);
		/*plugin_usage("kmi", config);*/
	}
	fprintf(stderr, "\n");
	ltfsresult("16432I"); /* Usage example: */
	ltfsresult("16433I", appname, devname);
	ltfsresult("16434I", appname, "--generation", "--rollback", devname);
	ltfsresult("16434I", appname, "--deep-recovery", "--full-recovery", devname);
	fprintf(stderr, "\n");
}
Exemple #4
0
int
main (int argc, char *argv[])
{
  int c;
  int option_index;
  int help = 0, version = 0;

  tls_init ();

  for (;;) {
    c = getopt_long (argc, argv, short_options, long_options, &option_index);
    if (c == -1)
      break;

    switch (c) {
    case 0:                     /* options which are long only */
      if (strcmp (long_options[option_index].name, "dump-config") == 0) {
        dump_config ();
        exit (EXIT_SUCCESS);
      }
      else if (strcmp (long_options[option_index].name, "run") == 0) {
        run = optarg;
        foreground = 1;
      }
      else {
        fprintf (stderr, "%s: unknown long option: %s (%d)\n",
                 program_name, long_options[option_index].name, option_index);
        exit (EXIT_FAILURE);
      }
      break;

    case 'f':
      foreground = 1;
      break;

    case 'g':
      group = optarg;
      break;

    case 'i':
      ipaddr = optarg;
      break;

    case 'n':
      newstyle = 1;
      break;

    case 'o':
      /* XXX When we add support for exportnames, we will need to
       * ensure that the user does not use -o + --export.
       */
      newstyle = 0;
      break;

    case 'P':
      pidfile = nbdkit_absolute_path (optarg);
      if (pidfile == NULL)
        exit (EXIT_FAILURE);
      break;

    case 'p':
      port = optarg;
      break;

    case 'r':
      readonly = 1;
      break;

    case 's':
      listen_stdin = 1;
      break;

    case 'U':
      if (strcmp (optarg, "-") == 0)
        unixsocket = make_random_fifo ();
      else
        unixsocket = nbdkit_absolute_path (optarg);
      if (unixsocket == NULL)
        exit (EXIT_FAILURE);
      break;

    case 'u':
      user = optarg;
      break;

    case 'v':
      verbose = 1;
      break;

    case 'V':
      version = 1;
      break;

    case HELP_OPTION:
      help = 1;
      break;

    default:
      usage ();
      exit (EXIT_FAILURE);
    }
  }

  /* No extra parameters. */
  if (optind >= argc) {
    if (help) {
      usage ();
      exit (EXIT_SUCCESS);
    }
    if (version) {
      display_version ();
      exit (EXIT_SUCCESS);
    }

    /* Otherwise this is an error. */
    fprintf (stderr,
             "%s: no plugins given on the command line.\nRead nbdkit(1) for documentation.\n",
             program_name);
    exit (EXIT_FAILURE);
  }

  /* Remaining command line arguments define the plugins and plugin
   * configuration.  If --help or --version was specified, we still
   * partially parse these in order that we can display the per-plugin
   * help/version information.  In future (when the new protocol and
   * export names are permitted) we will allow multiple plugins to be
   * given, but at the moment only one plugin is allowed.
   */
  while (optind < argc) {
    const char *filename = argv[optind];
    char *p;

    open_plugin_so (filename);

    /* Find key=value configuration parameters for this plugin. */
    ++optind;
    while (optind < argc && (p = strchr (argv[optind], '=')) != NULL) {
      if (help || version)
        continue;

      *p = '\0';
      plugin_config (argv[optind], p+1);

      ++optind;
    }

    if (help) {
      usage ();
      printf ("\n%s:\n\n", filename);
      plugin_usage ();
      exit (EXIT_SUCCESS);
    }

    if (version) {
      display_version ();
      plugin_version ();
      exit (EXIT_SUCCESS);
    }

    plugin_config_complete ();

    /* If we supported export names, then we'd continue in the loop
     * here, but at the moment only one plugin may be used per server
     * so exit if there are any more.
     */
    ++optind;
    if (optind < argc) {
      fprintf (stderr, "%s: this server only supports a single plugin\n",
               program_name);
      exit (EXIT_FAILURE);
    }
  }

  start_serving ();

  plugin_cleanup ();

  free (unixsocket);
  free (pidfile);

  if (random_fifo) {
    unlink (random_fifo);
    free (random_fifo);
  }

  if (random_fifo_dir) {
    rmdir (random_fifo_dir);
    free (random_fifo_dir);
  }

  exit (EXIT_SUCCESS);
}