Exemplo n.º 1
0
void initialise_options()
{
  //todo: handle param init consistently, quite heavy implementation
  cloudfs_verify_ssl(!strcasecmp(options.verify_ssl, "true"));
  cloudfs_option_get_extended_metadata(!strcasecmp(
                                         extra_options.get_extended_metadata, "true"));
  cloudfs_option_curl_verbose(!strcasecmp(extra_options.curl_verbose, "true"));
  //lean way to init params, to be used as reference
  if (*extra_options.debug_level)
    option_debug_level = atoi(extra_options.debug_level);
  if (*extra_options.cache_statfs_timeout)
    option_cache_statfs_timeout = atoi(extra_options.cache_statfs_timeout);
  if (*extra_options.curl_progress_state)
    option_curl_progress_state = !strcasecmp(extra_options.curl_progress_state,
                                 "true");
  if (*extra_options.enable_chmod)
    option_enable_chmod = !strcasecmp(extra_options.enable_chmod, "true");
  if (*extra_options.enable_chown)
    option_enable_chown = !strcasecmp(extra_options.enable_chown, "true");
}
Exemplo n.º 2
0
int main(int argc, char **argv)
{
    char settings_filename[MAX_PATH_SIZE] = "";
    FILE *settings;
    struct fuse_args args = FUSE_ARGS_INIT(argc, argv);

    snprintf(settings_filename, sizeof(settings_filename), "%s/.hubicfuse", get_home_dir());
    if ((settings = fopen(settings_filename, "r")))
    {
        char line[OPTION_SIZE];
        while (fgets(line, sizeof(line), settings))
            parse_option(NULL, line, -1, &args);
        fclose(settings);
    }

    fuse_opt_parse(&args, &options, NULL, parse_option);

    cache_timeout = atoi(options.cache_timeout);
    segment_size = atoll(options.segment_size);
    segment_above = atoll(options.segment_above);
    // 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", settings_filename);
        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, defult 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");

        return 1;
    }

    cloudfs_init();

    cloudfs_verify_ssl(!strcasecmp(options.verify_ssl, "true"));

    cloudfs_set_credentials(options.client_id, options.client_secret, options.refresh_token);

    if (!cloudfs_connect())
    {
        fprintf(stderr, "Failed to authenticate.\n");
        return 1;
    }

#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,
    };

    pthread_mutex_init(&dmut, NULL);
    return fuse_main(args.argc, args.argv, &cfs_oper, &options);
}