You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright (C) 2013 Marin Hannache <ipxe@mareo.fr>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  17. * 02110-1301, USA.
  18. */
  19. #include <stdint.h>
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <assert.h>
  24. #include <errno.h>
  25. #include <libgen.h>
  26. #include <byteswap.h>
  27. #include <ipxe/time.h>
  28. #include <ipxe/iobuf.h>
  29. #include <ipxe/open.h>
  30. #include <ipxe/features.h>
  31. #include <ipxe/oncrpc.h>
  32. #include <ipxe/oncrpc_iob.h>
  33. #include <ipxe/nfs.h>
  34. #include <ipxe/mount.h>
  35. /** @file
  36. *
  37. * NFS MOUNT protocol
  38. *
  39. */
  40. /** MNT procedure number */
  41. #define MOUNT_MNT 1
  42. /** UMNT procedure number */
  43. #define MOUNT_UMNT 3
  44. /**
  45. * Send a MNT request
  46. *
  47. * @v intf Interface to send the request on
  48. * @v session ONC RPC session
  49. * @v mountpoinrt The path of the directory to mount.
  50. * @ret rc Return status code
  51. */
  52. int mount_mnt ( struct interface *intf, struct oncrpc_session *session,
  53. const char *mountpoint ) {
  54. struct oncrpc_field fields[] = {
  55. ONCRPC_FIELD ( str, mountpoint ),
  56. ONCRPC_FIELD_END,
  57. };
  58. return oncrpc_call ( intf, session, MOUNT_MNT, fields );
  59. }
  60. /**
  61. * Send a UMNT request
  62. *
  63. * @v intf Interface to send the request on
  64. * @v session ONC RPC session
  65. * @v mountpoinrt The path of the directory to unmount.
  66. * @ret rc Return status code
  67. */
  68. int mount_umnt ( struct interface *intf, struct oncrpc_session *session,
  69. const char *mountpoint ) {
  70. struct oncrpc_field fields[] = {
  71. ONCRPC_FIELD ( str, mountpoint ),
  72. ONCRPC_FIELD_END,
  73. };
  74. return oncrpc_call ( intf, session, MOUNT_UMNT, fields );
  75. }
  76. /**
  77. * Parse an MNT reply
  78. *
  79. * @v mnt_reply A structure where the data will be saved
  80. * @v reply The ONC RPC reply to get data from
  81. * @ret rc Return status code
  82. */
  83. int mount_get_mnt_reply ( struct mount_mnt_reply *mnt_reply,
  84. struct oncrpc_reply *reply ) {
  85. if ( ! mnt_reply || ! reply )
  86. return -EINVAL;
  87. mnt_reply->status = oncrpc_iob_get_int ( reply->data );
  88. switch ( mnt_reply->status )
  89. {
  90. case MNT3_OK:
  91. break;
  92. case MNT3ERR_NOENT:
  93. return -ENOENT;
  94. case MNT3ERR_IO:
  95. return -EIO;
  96. case MNT3ERR_ACCES:
  97. return -EACCES;
  98. case MNT3ERR_NOTDIR:
  99. return -ENOTDIR;
  100. case MNT3ERR_NAMETOOLONG:
  101. return -ENAMETOOLONG;
  102. default:
  103. return -EPROTO;
  104. }
  105. nfs_iob_get_fh ( reply->data, &mnt_reply->fh );
  106. return 0;
  107. }