Ejemplo n.º 1
0
int main(int argc, char **argv)
{
	int ret;
	if(sigaction(SIGINT, &sigact, NULL) < 0 ||
		sigaction(SIGTERM, &sigact, NULL) < 0) {
		perror("Error installing signal handler");
		return 1;
	}

	if(initialise_options(&opt, argc, argv) < 0)
		return 1;

	ret = get_loop(&opt);

	destroy_options(&opt);
	return ret;

}
Ejemplo n.º 2
0
int main(int argc, char** argv)
{
#if __x86_64__ || __ppc64__
  const unsigned long MAX_SEGMENT_SIZE = (unsigned  long)5 * (unsigned long)(1 << 30);
#else
  const unsigned long MAX_SEGMENT_SIZE = (unsigned  long)2 * (unsigned long)(1 << 30);
#endif

  if (debug)
    fprintf(stderr, "Starting hubicfuse on homedir %s!\n", get_home_dir());

  signal(SIGINT, interrupt_handler);

  int return_code;
  FILE* settings;
  struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
  char default_settings[MAX_PATH_SIZE];

  // Default value for extra_options.settings_filename
  snprintf(default_settings, MAX_PATH_SIZE, "%s/.hubicfuse", get_home_dir());
  strncpy(extra_options.settings_filename, default_settings, MAX_PATH_SIZE);

  // Reading FUSE options
  fuse_opt_parse(&args, &options, NULL, parse_option);

  // Reading hubiC settings
  if ((settings = fopen(extra_options.settings_filename, "r")))
  {
    char line[OPTION_SIZE];
    while (fgets(line, sizeof(line), settings))
      parse_option(NULL, line, -1, &args);
    fclose(settings);
  }

  cache_timeout = atoi(options.cache_timeout);
  segment_size = atoll(options.segment_size);
  segment_above = atoll(options.segment_above);

  // check consistency

  if (segment_above > MAX_SEGMENT_SIZE)
  {
    printf ("A segment cannot be larger than 5Gb\n");
    return 1;
  }
  if (segment_size > segment_above)
  {
    printf ("segment_size must be smaller than segment_above\n");
    return 1;
  }

  // this is ok since main is on the stack during the entire execution
  override_storage_url = options.storage_url;
  public_container = options.container;
  temp_dir = options.temp_dir;

  if (!*options.client_id || !*options.client_secret || !*options.refresh_token)
  {
    fprintf(stderr,
            "Unable to determine client_id, client_secret or refresh_token.\n\n");
    fprintf(stderr, "These can be set either as mount options or in "
            "a file named %s\n\n", default_settings);
    fprintf(stderr, "  client_id=[App's id]\n");
    fprintf(stderr, "  client_secret=[App's secret]\n");
    fprintf(stderr, "  refresh_token=[Get it running hubic_token]\n");
    fprintf(stderr, "The following settings are optional:\n\n");
    fprintf(stderr,
            "  cache_timeout=[Seconds for directory caching, default 600]\n");
    fprintf(stderr, "  verify_ssl=[false to disable SSL cert verification]\n");
    fprintf(stderr,
            "  segment_size=[Size to use when creating DLOs, default 1073741824]\n");
    fprintf(stderr,
            "  segment_above=[File size at which to use segments, default 2147483648]\n");
    fprintf(stderr,
            "  storage_url=[Storage URL for other tenant to view container]\n");
    fprintf(stderr,
            "  container=[Public container to view of tenant specified by storage_url]\n");
    fprintf(stderr, "  temp_dir=[Directory to store temp files]\n");
    fprintf(stderr,
            "  get_extended_metadata=[true to enable download of utime, chmod, chown file attributes (but slower)]\n");
    fprintf(stderr,
            "  curl_verbose=[true to debug info on curl requests (lots of output)]\n");
    fprintf(stderr,
            "  curl_progress_state=[true to enable progress callback enabled. Mostly used for debugging]\n");
    fprintf(stderr,
            "  cache_statfs_timeout=[number of seconds to cache requests to statfs (cloud statistics), 0 for no cache]\n");
    fprintf(stderr,
            "  debug_level=[0 to 2, 0 for minimal verbose debugging. No debug if -d or -f option is not provided.]\n");
    fprintf(stderr, "  enable_chmod=[true to enable chmod support on fuse]\n");
    fprintf(stderr, "  enable_chown=[true to enable chown support on fuse]\n");
    return 1;
  }
  cloudfs_init();
  initialise_options();
  if (debug)
  {
    fprintf(stderr, "settings_filename = %s\n", extra_options.settings_filename);
    fprintf(stderr, "debug_level = %d\n", option_debug_level);
    fprintf(stderr, "get_extended_metadata = %d\n", option_get_extended_metadata);
    fprintf(stderr, "curl_progress_state = %d\n", option_curl_progress_state);
    fprintf(stderr, "enable_chmod = %d\n", option_enable_chmod);
    fprintf(stderr, "enable_chown = %d\n", option_enable_chown);
  }
  cloudfs_set_credentials(options.client_id, options.client_secret,
                          options.refresh_token);

  if (!cloudfs_connect())
  {
    fprintf(stderr, "Failed to authenticate.\n");
    return 1;
  }
  //todo: check why in some cases the define below is not available (when running the binary on symbolic linked folders)
#ifndef HAVE_OPENSSL
#warning Compiling without libssl, will run single-threaded.
  fuse_opt_add_arg(&args, "-s");
#endif

  struct fuse_operations cfs_oper =
  {
    .readdir = cfs_readdir,
    .mkdir = cfs_mkdir,
    .read = cfs_read,
    .create = cfs_create,
    .open = cfs_open,
    .fgetattr = cfs_fgetattr,
    .getattr = cfs_getattr,
    .flush = cfs_flush,
    .release = cfs_release,
    .rmdir = cfs_rmdir,
    .ftruncate = cfs_ftruncate,
    .truncate = cfs_truncate,
    .write = cfs_write,
    .unlink = cfs_unlink,
    .fsync = cfs_fsync,
    .statfs = cfs_statfs,
    .chmod = cfs_chmod,
    .chown = cfs_chown,
    .rename = cfs_rename,
    .symlink = cfs_symlink,
    .readlink = cfs_readlink,
    .init = cfs_init,
    .utimens = cfs_utimens,
#ifdef HAVE_SETXATTR
    .setxattr = cfs_setxattr,
    .getxattr = cfs_getxattr,
    .listxattr = cfs_listxattr,
    .removexattr = cfs_removexattr,
#endif
  };

  pthread_mutexattr_init(&mutex_attr);
  pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
  pthread_mutex_init(&dcachemut, &mutex_attr);
  return_code = fuse_main(args.argc, args.argv, &cfs_oper, &options);

  if (return_code > 0 && !strcmp(extra_options.help, "true"))
  {
    fprintf(stderr, "\nhubiC options:\n");
    fprintf(stderr, "    -o settings_filename=FILE  use FILE as hubiC settings\n");
    fprintf(stderr, "                               instead of %s\n", default_settings);
  }

  return return_code;
}