mount.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. Copyright (C) by Ronnie Sahlberg <ronniesahlberg@gmail.com> 2010
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include <stdio.h>
  15. #include <errno.h>
  16. #include <rpc/xdr.h>
  17. #include "nfs.h"
  18. #include "libnfs-raw.h"
  19. #include "libnfs-private.h"
  20. #include "rpc/mount.h"
  21. int rpc_mount_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
  22. {
  23. struct rpc_pdu *pdu;
  24. pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_NULL, cb, private_data, (xdrproc_t)xdr_void, 0);
  25. if (pdu == NULL) {
  26. rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for mount/null call");
  27. return -1;
  28. }
  29. if (rpc_queue_pdu(rpc, pdu) != 0) {
  30. rpc_set_error(rpc, "Out of memory. Failed to queue pdu for mount/null call");
  31. rpc_free_pdu(rpc, pdu);
  32. return -2;
  33. }
  34. return 0;
  35. }
  36. int rpc_mount_mnt_async(struct rpc_context *rpc, rpc_cb cb, char *export, void *private_data)
  37. {
  38. struct rpc_pdu *pdu;
  39. pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_MNT, cb, private_data, (xdrproc_t)xdr_mountres3, sizeof(mountres3));
  40. if (pdu == NULL) {
  41. rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for mount/mnt call");
  42. return -1;
  43. }
  44. if (xdr_dirpath(&pdu->xdr, &export) == 0) {
  45. rpc_set_error(rpc, "XDR error. Failed to encode mount/mnt call");
  46. rpc_free_pdu(rpc, pdu);
  47. return -2;
  48. }
  49. if (rpc_queue_pdu(rpc, pdu) != 0) {
  50. rpc_set_error(rpc, "Out of memory. Failed to queue pdu for mount/mnt call");
  51. rpc_free_pdu(rpc, pdu);
  52. return -2;
  53. }
  54. return 0;
  55. }
  56. int rpc_mount_dump_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
  57. {
  58. struct rpc_pdu *pdu;
  59. pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_DUMP, cb, private_data, (xdrproc_t)xdr_mountlist, sizeof(mountlist));
  60. if (pdu == NULL) {
  61. printf("Failed to allocate pdu for mount/dump\n");
  62. return -1;
  63. }
  64. if (rpc_queue_pdu(rpc, pdu) != 0) {
  65. printf("Failed to queue mount/dump pdu\n");
  66. rpc_free_pdu(rpc, pdu);
  67. return -2;
  68. }
  69. return 0;
  70. }
  71. int rpc_mount_umnt_async(struct rpc_context *rpc, rpc_cb cb, char *export, void *private_data)
  72. {
  73. struct rpc_pdu *pdu;
  74. pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_UMNT, cb, private_data, (xdrproc_t)xdr_void, 0);
  75. if (pdu == NULL) {
  76. printf("Failed to allocate pdu for mount/umnt\n");
  77. return -1;
  78. }
  79. if (xdr_dirpath(&pdu->xdr, &export) == 0) {
  80. printf("failed to encode dirpath for mount/umnt\n");
  81. rpc_free_pdu(rpc, pdu);
  82. return -2;
  83. }
  84. if (rpc_queue_pdu(rpc, pdu) != 0) {
  85. printf("Failed to queue mount/umnt pdu\n");
  86. rpc_free_pdu(rpc, pdu);
  87. return -2;
  88. }
  89. return 0;
  90. }
  91. int rpc_mount_umntall_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
  92. {
  93. struct rpc_pdu *pdu;
  94. pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_UMNTALL, cb, private_data, (xdrproc_t)xdr_void, 0);
  95. if (pdu == NULL) {
  96. printf("Failed to allocate pdu for mount/umntall\n");
  97. return -1;
  98. }
  99. if (rpc_queue_pdu(rpc, pdu) != 0) {
  100. printf("Failed to queue mount/umntall pdu\n");
  101. rpc_free_pdu(rpc, pdu);
  102. return -2;
  103. }
  104. return 0;
  105. }
  106. int rpc_mount_export_async(struct rpc_context *rpc, rpc_cb cb, void *private_data)
  107. {
  108. struct rpc_pdu *pdu;
  109. pdu = rpc_allocate_pdu(rpc, MOUNT_PROGRAM, MOUNT_V3, MOUNT3_EXPORT, cb, private_data, (xdrproc_t)xdr_exports, sizeof(exports));
  110. if (pdu == NULL) {
  111. printf("Failed to allocate pdu for mount/export\n");
  112. return -1;
  113. }
  114. if (rpc_queue_pdu(rpc, pdu) != 0) {
  115. printf("Failed to queue mount/export pdu\n");
  116. rpc_free_pdu(rpc, pdu);
  117. return -2;
  118. }
  119. return 0;
  120. }
  121. char *mountstat3_to_str(int st)
  122. {
  123. enum mountstat3 stat = st;
  124. char *str = "unknown mount stat";
  125. switch (stat) {
  126. case MNT3_OK: str="MNT3_OK"; break;
  127. case MNT3ERR_PERM: str="MNT3ERR_PERM"; break;
  128. case MNT3ERR_NOENT: str="MNT3ERR_NOENT"; break;
  129. case MNT3ERR_IO: str="MNT3ERR_IO"; break;
  130. case MNT3ERR_ACCES: str="MNT3ERR_ACCES"; break;
  131. case MNT3ERR_NOTDIR: str="MNT3ERR_NOTDIR"; break;
  132. case MNT3ERR_INVAL: str="MNT3ERR_INVAL"; break;
  133. case MNT3ERR_NAMETOOLONG: str="MNT3ERR_NAMETOOLONG"; break;
  134. case MNT3ERR_NOTSUPP: str="MNT3ERR_NOTSUPP"; break;
  135. case MNT3ERR_SERVERFAULT: str="MNT3ERR_SERVERFAULT"; break;
  136. }
  137. return str;
  138. }
  139. int mountstat3_to_errno(int st)
  140. {
  141. enum mountstat3 stat = st;
  142. switch (stat) {
  143. case MNT3_OK: return 0; break;
  144. case MNT3ERR_PERM: return -EPERM; break;
  145. case MNT3ERR_NOENT: return -EPERM; break;
  146. case MNT3ERR_IO: return -EIO; break;
  147. case MNT3ERR_ACCES: return -EACCES; break;
  148. case MNT3ERR_NOTDIR: return -ENOTDIR; break;
  149. case MNT3ERR_INVAL: return -EINVAL; break;
  150. case MNT3ERR_NAMETOOLONG: return -E2BIG; break;
  151. case MNT3ERR_NOTSUPP: return -EINVAL; break;
  152. case MNT3ERR_SERVERFAULT: return -EIO; break;
  153. }
  154. return -ERANGE;
  155. }