123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- /**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #include "fuse_dfs.h"
- #include "fuse_init.h"
- #include "fuse_options.h"
- #include "fuse_context_handle.h"
- #include "fuse_connect.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- // Hacked up function to basically do:
- // protectedpaths = split(options.protected,':');
- void init_protectedpaths(dfs_context *dfs) {
- char *tmp = options.protected;
- // handle degenerate case up front.
- if (tmp == NULL || 0 == *tmp) {
- dfs->protectedpaths = (char**)malloc(sizeof(char*));
- dfs->protectedpaths[0] = NULL;
- return;
- }
- assert(tmp);
- if (options.debug) {
- print_options();
- }
- int i = 0;
- while (tmp && (NULL != (tmp = index(tmp,':')))) {
- tmp++; // pass the ,
- i++;
- }
- i++; // for the last entry
- i++; // for the final NULL
- dfs->protectedpaths = (char**)malloc(sizeof(char*)*i);
- assert(dfs->protectedpaths);
- tmp = options.protected;
- int j = 0;
- while (NULL != tmp && j < i) {
- int length;
- char *eos = index(tmp,':');
- if (NULL != eos) {
- length = eos - tmp; // length of this value
- } else {
- length = strlen(tmp);
- }
- dfs->protectedpaths[j] = (char*)malloc(sizeof(char)*length+1);
- assert(dfs->protectedpaths[j]);
- strncpy(dfs->protectedpaths[j], tmp, length);
- dfs->protectedpaths[j][length] = '\0';
- if (eos) {
- tmp = eos + 1;
- } else {
- tmp = NULL;
- }
- j++;
- }
- dfs->protectedpaths[j] = NULL;
- }
- static void dfsPrintOptions(FILE *fp, const struct options *o)
- {
- fprintf(fp, "[ protected=%s, nn_uri=%s, nn_port=%d, "
- "debug=%d, read_only=%d, initchecks=%d, "
- "no_permissions=%d, usetrash=%d, entry_timeout=%d, "
- "attribute_timeout=%d, rdbuffer_size=%Zd, direct_io=%d ]",
- (o->protected ? o->protected : "(NULL)"), o->nn_uri, o->nn_port,
- o->debug, o->read_only, o->initchecks,
- o->no_permissions, o->usetrash, o->entry_timeout,
- o->attribute_timeout, o->rdbuffer_size, o->direct_io);
- }
- void *dfs_init(void)
- {
- //
- // Create a private struct of data we will pass to fuse here and which
- // will then be accessible on every call.
- //
- dfs_context *dfs = (dfs_context*)malloc(sizeof(dfs_context));
- if (NULL == dfs) {
- ERROR("FATAL: could not malloc dfs_context");
- exit(1);
- }
- // initialize the context
- dfs->debug = options.debug;
- dfs->read_only = options.read_only;
- dfs->usetrash = options.usetrash;
- dfs->protectedpaths = NULL;
- dfs->rdbuffer_size = options.rdbuffer_size;
- dfs->direct_io = options.direct_io;
- fprintf(stderr, "Mounting with options ");
- dfsPrintOptions(stderr, &options);
- fprintf(stderr, "\n");
- init_protectedpaths(dfs);
- assert(dfs->protectedpaths != NULL);
- if (dfs->rdbuffer_size <= 0) {
- DEBUG("dfs->rdbuffersize <= 0 = %ld", dfs->rdbuffer_size);
- dfs->rdbuffer_size = 32768;
- }
- return (void*)dfs;
- }
- void dfs_destroy(void *ptr)
- {
- TRACE("destroy")
- }
|