fuse_impls_mkdir.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. struct hdfsConn *conn = NULL;
  25. hdfsFS fs;
  26. dfs_context *dfs = (dfs_context*)fuse_get_context()->private_data;
  27. int ret;
  28. TRACE1("mkdir", path)
  29. assert(path);
  30. assert(dfs);
  31. assert('/' == *path);
  32. if (is_protected(path)) {
  33. ERROR("HDFS trying to create directory %s", path);
  34. return -EACCES;
  35. }
  36. ret = fuseConnectAsThreadUid(&conn);
  37. if (ret) {
  38. fprintf(stderr, "fuseConnectAsThreadUid: failed to open a libhdfs "
  39. "connection! error %d.\n", ret);
  40. ret = -EIO;
  41. goto cleanup;
  42. }
  43. fs = hdfsConnGetFs(conn);
  44. // In theory the create and chmod should be atomic.
  45. if (hdfsCreateDirectory(fs, path)) {
  46. ERROR("HDFS could not create directory %s", path);
  47. ret = (errno > 0) ? -errno : -EIO;
  48. goto cleanup;
  49. }
  50. if (hdfsChmod(fs, path, (short)mode)) {
  51. ERROR("Could not chmod %s to %d", path, (int)mode);
  52. ret = (errno > 0) ? -errno : -EIO;
  53. }
  54. ret = 0;
  55. cleanup:
  56. if (conn) {
  57. hdfsConnRelease(conn);
  58. }
  59. return ret;
  60. }