fuse_dfs.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #include "fuse_dfs.h"
  19. #include "fuse_options.h"
  20. #include "fuse_impls.h"
  21. #include "fuse_init.h"
  22. #include "fuse_connect.h"
  23. #include <string.h>
  24. #include <stdlib.h>
  25. int is_protected(const char *path) {
  26. dfs_context *dfs = (dfs_context*)fuse_get_context()->private_data;
  27. assert(dfs != NULL);
  28. assert(dfs->protectedpaths);
  29. int i ;
  30. for (i = 0; dfs->protectedpaths[i]; i++) {
  31. if (strcmp(path, dfs->protectedpaths[i]) == 0) {
  32. return 1;
  33. }
  34. }
  35. return 0;
  36. }
  37. static struct fuse_operations dfs_oper = {
  38. .getattr = dfs_getattr,
  39. .access = dfs_access,
  40. .readdir = dfs_readdir,
  41. .destroy = dfs_destroy,
  42. .init = dfs_init,
  43. .open = dfs_open,
  44. .read = dfs_read,
  45. .symlink = dfs_symlink,
  46. .statfs = dfs_statfs,
  47. .mkdir = dfs_mkdir,
  48. .rmdir = dfs_rmdir,
  49. .rename = dfs_rename,
  50. .unlink = dfs_unlink,
  51. .release = dfs_release,
  52. .create = dfs_create,
  53. .write = dfs_write,
  54. .flush = dfs_flush,
  55. .mknod = dfs_mknod,
  56. .utimens = dfs_utimens,
  57. .chmod = dfs_chmod,
  58. .chown = dfs_chown,
  59. .truncate = dfs_truncate,
  60. };
  61. int main(int argc, char *argv[])
  62. {
  63. umask(0);
  64. extern const char *program;
  65. program = argv[0];
  66. struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
  67. memset(&options, 0, sizeof(struct options));
  68. options.rdbuffer_size = 10*1024*1024;
  69. options.attribute_timeout = 60;
  70. options.entry_timeout = 60;
  71. if (-1 == fuse_opt_parse(&args, &options, dfs_opts, dfs_options)) {
  72. return -1;
  73. }
  74. if (!options.private) {
  75. fuse_opt_add_arg(&args, "-oallow_other");
  76. }
  77. if (!options.no_permissions) {
  78. fuse_opt_add_arg(&args, "-odefault_permissions");
  79. }
  80. {
  81. char buf[1024];
  82. snprintf(buf, sizeof buf, "-oattr_timeout=%d",options.attribute_timeout);
  83. fuse_opt_add_arg(&args, buf);
  84. snprintf(buf, sizeof buf, "-oentry_timeout=%d",options.entry_timeout);
  85. fuse_opt_add_arg(&args, buf);
  86. }
  87. if (options.nn_uri == NULL) {
  88. print_usage(argv[0]);
  89. exit(0);
  90. }
  91. // Check connection as root
  92. if (options.initchecks == 1) {
  93. hdfsFS tempFS = hdfsConnectAsUser(options.nn_uri, options.nn_port, "root");
  94. if (NULL == tempFS) {
  95. const char *cp = getenv("CLASSPATH");
  96. const char *ld = getenv("LD_LIBRARY_PATH");
  97. ERROR("FATAL: misconfiguration - cannot connect to HDFS");
  98. ERROR("LD_LIBRARY_PATH=%s",ld == NULL ? "NULL" : ld);
  99. ERROR("CLASSPATH=%s",cp == NULL ? "NULL" : cp);
  100. exit(1);
  101. }
  102. if (doDisconnect(tempFS)) {
  103. ERROR("FATAL: unable to disconnect from test filesystem.");
  104. exit(1);
  105. }
  106. }
  107. int ret = fuse_main(args.argc, args.argv, &dfs_oper, NULL);
  108. fuse_opt_free_args(&args);
  109. return ret;
  110. }