fuse_impls_statfs.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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_connect.h"
  21. int dfs_statfs(const char *path, struct statvfs *st)
  22. {
  23. TRACE1("statfs",path)
  24. // retrieve dfs specific data
  25. dfs_context *dfs = (dfs_context*)fuse_get_context()->private_data;
  26. // check params and the context var
  27. assert(path);
  28. assert(st);
  29. assert(dfs);
  30. // init the stat structure
  31. memset(st,0,sizeof(struct statvfs));
  32. hdfsFS userFS;
  33. // if not connected, try to connect and fail out if we can't.
  34. if ((userFS = doConnectAsUser(dfs->nn_hostname,dfs->nn_port))== NULL) {
  35. ERROR("Could not connect");
  36. return -EIO;
  37. }
  38. const tOffset cap = hdfsGetCapacity(userFS);
  39. const tOffset used = hdfsGetUsed(userFS);
  40. const tOffset bsize = hdfsGetDefaultBlockSize(userFS);
  41. // fill in the statvfs structure
  42. /* FOR REFERENCE:
  43. struct statvfs {
  44. unsigned long f_bsize; // file system block size
  45. unsigned long f_frsize; // fragment size
  46. fsblkcnt_t f_blocks; // size of fs in f_frsize units
  47. fsblkcnt_t f_bfree; // # free blocks
  48. fsblkcnt_t f_bavail; // # free blocks for non-root
  49. fsfilcnt_t f_files; // # inodes
  50. fsfilcnt_t f_ffree; // # free inodes
  51. fsfilcnt_t f_favail; // # free inodes for non-root
  52. unsigned long f_fsid; // file system id
  53. unsigned long f_flag; / mount flags
  54. unsigned long f_namemax; // maximum filename length
  55. };
  56. */
  57. st->f_bsize = bsize;
  58. st->f_frsize = bsize;
  59. st->f_blocks = cap/bsize;
  60. st->f_bfree = (cap-used)/bsize;
  61. st->f_bavail = (cap-used)/bsize;
  62. st->f_files = 1000;
  63. st->f_ffree = 500;
  64. st->f_favail = 500;
  65. st->f_fsid = 1023;
  66. st->f_flag = ST_RDONLY | ST_NOSUID;
  67. st->f_namemax = 1023;
  68. return 0;
  69. }