smb_file.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*****************************************************************************
  2. * __________________ _________ _____ _____ .__ ._.
  3. * \______ \______ \ / _____/ / \ / _ \ |__| ____ | |
  4. * | | _/| | \ \_____ \ / \ / \ / /_\ \| _/ __ \ | |
  5. * | | \| ` \/ / Y \ / | | \ ___/ \|
  6. * |______ /_______ /_______ \____|__ / /\ \____|__ |__|\___ | __
  7. * \/ \/ \/ \/ )/ \/ \/ \/
  8. *
  9. * This file is part of liBDSM. Copyright © 2014-2015 VideoLabs SAS
  10. *
  11. * Author: Julien 'Lta' BALLET <contact@lta.io>
  12. *
  13. * liBDSM is released under LGPLv2.1 (or later) and is also available
  14. * under a commercial license.
  15. *****************************************************************************
  16. * This program is free software; you can redistribute it and/or modify it
  17. * under the terms of the GNU Lesser General Public License as published by
  18. * the Free Software Foundation; either version 2.1 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU Lesser General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU Lesser General Public License
  27. * along with this program; if not, write to the Free Software Foundation,
  28. * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  29. *****************************************************************************/
  30. /**
  31. * @file smb_file.h
  32. * @brief File operations
  33. */
  34. #ifndef __BDSM_SMB_FILE_H_
  35. #define __BDSM_SMB_FILE_H_
  36. #include "bdsm/smb_session.h"
  37. /**
  38. * @brief Open a file on a share.
  39. * @details Use this function to obtain an smb_fd, necesary for file operations
  40. *
  41. * @param s The session object
  42. * @param tid The tid of the share the file is in, obtained via smb_tree_connect()
  43. * @param path The path of the file to open
  44. * @param mod The access modes requested (example: #SMB_MOD_RO)
  45. * @param fd The pointer to the smb file description that can be used for
  46. * further file operations
  47. * @return 0 on success or a DSM error code in case of error
  48. *
  49. * @see smb_tree_connect
  50. */
  51. int smb_fopen(smb_session *s, smb_tid tid, const char *path,
  52. uint32_t mod, smb_fd *fd);
  53. /**
  54. * @brief Close an open file
  55. * @details The smb_fd is invalidated and MUST not be use it anymore. You can
  56. * give it the 0 value.
  57. *
  58. * @param s The session object
  59. * @param fd The SMB file descriptor
  60. */
  61. void smb_fclose(smb_session *s, smb_fd fd);
  62. /**
  63. * @brief Read from an open file
  64. * @details The semantics is basically the same that the unix read() one.
  65. * At most 'buf_size' bytes are read from the current seek offset and copied into
  66. * the memory pointed by 'buf' from the open file represented by the smb file
  67. * descriptor 'fd'.
  68. *
  69. * @param[in] s The session object
  70. * @param[in] fd [description]
  71. * @param[out] buf can be NULL in order to skip buf_size bytes
  72. * @param[in] buf_size [description]
  73. * @return The number of bytes read or -1 in case of error.
  74. */
  75. ssize_t smb_fread(smb_session *s, smb_fd fd, void *buf, size_t buf_size);
  76. /**
  77. * @brief Write to an open file
  78. * @details At most 'buf_size' bytes from memory pointed by 'buf' are written
  79. * to the current seek offset of the open file represented by the smb file
  80. * descriptor 'fd'.
  81. *
  82. * @param[in] s The session object
  83. * @param[in] fd [description]
  84. * @param[out] buf [description]
  85. * @param[in] buf_size [description]
  86. * @return The number of bytes written or -1 in case of error.
  87. */
  88. ssize_t smb_fwrite(smb_session *s, smb_fd fd, void *buf, size_t buf_size);
  89. /**
  90. * @brief Sets/Moves/Get the read/write pointer for a given file
  91. * @details The behavior of this function is the same as the Unix fseek()
  92. * function, except the SEEK_END argument isn't supported.
  93. *
  94. * This functions adjust the read/write pointer depending on the value of
  95. * offset and whence.
  96. *
  97. * - If whence == #SMB_SEEK_SET, the read pointer is set at 'offset'
  98. * - If whence == #SMB_SEEK_CUR, the read pointer is adjusted by 'offset'
  99. *
  100. * @param s The session object
  101. * @param fd The file descriptors for which the read pointer is to be adjusted
  102. * @param offset Set/Adjust quantity
  103. * @param whence Which action to perform. Supported operations are
  104. * #SMB_SEEK_SET and #SMB_SEEK_CUR
  105. * @return The current read pointer position or -1 on error
  106. */
  107. ssize_t smb_fseek(smb_session *s, smb_fd fd, off_t offset, int whence);
  108. /**
  109. * @brief remove a file on a share.
  110. * @details Use this function to delete a file
  111. *
  112. * @param s The session object
  113. * @param tid The tid of the share the file is in, obtained via smb_tree_connect()
  114. * @param path The path of the file to delete
  115. * @return 0 if delete OK or "NT" error code
  116. */
  117. int smb_file_rm(smb_session *s, smb_tid tid, const char *path);
  118. /**
  119. * @brief move/rename a file/directory on a share.
  120. * @details Use this function to move and/or rename a file/directory
  121. *
  122. * @param s The session object
  123. * @param tid The tid of the share the file is in, obtained via smb_tree_connect()
  124. * @param old_path The current path of the file/directory to move/rename
  125. * @param new_path The new path of the file/directory
  126. * @return 0 if move OK or -1 in case of error
  127. */
  128. int smb_file_mv(smb_session *s, smb_tid tid, const char *old_path, const char *new_path);
  129. #endif