fuse_impls_mkdir.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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_impls.h"
  20. #include "fuse_trash.h"
  21. #include "fuse_connect.h"
  22. int dfs_mkdir(const char *path, mode_t mode)
  23. {
  24. TRACE1("mkdir", path)
  25. dfs_context *dfs = (dfs_context*)fuse_get_context()->private_data;
  26. assert(path);
  27. assert(dfs);
  28. assert('/' == *path);
  29. if (is_protected(path)) {
  30. ERROR("HDFS trying to create directory %s", path);
  31. return -EACCES;
  32. }
  33. if (dfs->read_only) {
  34. ERROR("HDFS is configured read-only, cannot create directory %s", path);
  35. return -EACCES;
  36. }
  37. hdfsFS userFS = doConnectAsUser(dfs->nn_uri, dfs->nn_port);
  38. if (userFS == NULL) {
  39. ERROR("Could not connect");
  40. return -EIO;
  41. }
  42. // In theory the create and chmod should be atomic.
  43. int ret = 0;
  44. if (hdfsCreateDirectory(userFS, path)) {
  45. ERROR("HDFS could not create directory %s", path);
  46. ret = (errno > 0) ? -errno : -EIO;
  47. goto cleanup;
  48. }
  49. if (hdfsChmod(userFS, path, (short)mode)) {
  50. ERROR("Could not chmod %s to %d", path, (int)mode);
  51. ret = (errno > 0) ? -errno : -EIO;
  52. }
  53. cleanup:
  54. if (doDisconnect(userFS)) {
  55. ret = -EIO;
  56. }
  57. return ret;
  58. }