smb_stat.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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_stat.h
  32. * @brief File status / listing
  33. */
  34. #ifndef __BDSM_SMB_STAT_H_
  35. #define __BDSM_SMB_STAT_H_
  36. #include "bdsm/smb_defs.h"
  37. #include "bdsm/smb_session.h"
  38. /// smb_stat_get() OP: Get file size
  39. #define SMB_STAT_SIZE 0
  40. /// smb_stat_get() OP: Get file allocation size (Size on disk)
  41. #define SMB_STAT_ALLOC_SIZE 1
  42. /// smb_stat_get() OP: 0 -> not a directory, != 0 -> directory
  43. #define SMB_STAT_ISDIR 2
  44. /// smb_stat_get() OP: Get file creation time
  45. #define SMB_STAT_CTIME 3
  46. /// smb_stat_get() OP: Get file last access time
  47. #define SMB_STAT_ATIME 4
  48. /// smb_stat_get() OP: Get file last write time
  49. #define SMB_STAT_WTIME 5
  50. /// smb_stat_get() OP: Get file last moditification time
  51. #define SMB_STAT_MTIME 6
  52. /**
  53. * @brief Returns infos about files matching a pattern
  54. * @details This functions uses the FIND_FIRST2 SMB operations to list files
  55. * matching a certain pattern. It's basically used to list folder contents
  56. *
  57. * @param s The session object
  58. * @param tid The share inside of which we want to find files obtained by
  59. * smb_tree_connect()
  60. * @param pattern The pattern to match files. '\\*' will list all the files at
  61. * the root of the share. '\\afolder\\*' will list all the files inside of the
  62. * 'afolder' directory.
  63. * @return An opaque list of smb_stat or NULL in case of error
  64. */
  65. smb_stat_list smb_find(smb_session *s, smb_tid tid, const char *pattern);
  66. /**
  67. * @brief Get the status of a file from it's path inside of a share
  68. *
  69. * @param s The session object
  70. * @param tid The tree id of a share obtained by smb_tree_connect()
  71. * @param path The full path of the file relative to the root of the share
  72. * (e.g. '\\folder\\file.ext')
  73. *
  74. * @return An opaque smb_stat or NULL in case of error. You need to
  75. * destory this object with smb_stat_destroy after usage.
  76. */
  77. smb_stat smb_fstat(smb_session *s, smb_tid tid, const char *path);
  78. /**
  79. * @brief Get the status of an open file from it's file descriptor
  80. * @details The file status will be those at the time of open
  81. *
  82. * @param s The session object
  83. * @param fd The smb_fd from which you want infos/status
  84. *
  85. * @return An opaque smb_stat or NULL in case of error. You don't own
  86. * this object memory, and then don't have to destory it
  87. */
  88. smb_stat smb_stat_fd(smb_session *s, smb_fd fd);
  89. /**
  90. * @brief Clear a smb_stat object, reclaiming its memory
  91. *
  92. * @param stat A smb_stat object returned by smb_fstat.
  93. */
  94. void smb_stat_destroy(smb_stat stat);
  95. /**
  96. * @brief Get the number of item in a smb_stat_list file info
  97. *
  98. * @param list The list you want the length of
  99. * @return The length of the list. It returns 0 if the list is invalid
  100. */
  101. size_t smb_stat_list_count(smb_stat_list list);
  102. smb_stat smb_stat_list_next(smb_stat_list stat);
  103. /**
  104. * @brief Get the element at the given position.
  105. *
  106. * @param list A stat list
  107. * @param index The position of the element you want.
  108. *
  109. * @return An opaque smb_stat or NULL in case of error
  110. */
  111. smb_stat smb_stat_list_at(smb_stat_list list, size_t index);
  112. /**
  113. * @brief Destroy and release a list of file stat returned by smb_find
  114. *
  115. * @param list The stat_list to free
  116. */
  117. void smb_stat_list_destroy(smb_stat_list list);
  118. /**
  119. * @brief Get the name of the file from its status
  120. *
  121. * @param info A file status
  122. * @return A null-terminated string in you current locale encoding or NULL.
  123. */
  124. const char *smb_stat_name(smb_stat info);
  125. /**
  126. * @brief Get a file attribute
  127. * @details This function is a getter that allow you to retrieve various
  128. * informations about a file on a smb_stat object. You can get its size,
  129. * various timestamps, etc.
  130. *
  131. * @param info The smb_stat object to get info from.
  132. * @param what This parameter tells the functions which information to get, can
  133. * be one of #SMB_STAT_SIZE, #SMB_STAT_ALLOC_SIZE, #SMB_STAT_ISDIR,
  134. * #SMB_STAT_CTIME, #SMB_STAT_ATIME, #SMB_STAT_MTIME, #SMB_STAT_WTIME.
  135. *
  136. * @return The meaning of the returned value depends on the 'what' parameter.
  137. * See each item documentation.
  138. */
  139. uint64_t smb_stat_get(smb_stat info, int what);
  140. #endif