smb_stat.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //---------------------------------------------------------------------------
  2. // __________________ _________ _____ _____ .__ ._.
  3. // \______ \______ \ / _____/ / \ / _ \ |__| ____ | |
  4. // | | _/| | \ \_____ \ / \ / \ / /_\ \| _/ __ \ | |
  5. // | | \| ` \/ / Y \ / | | \ ___/ \|
  6. // |______ /_______ /_______ \____|__ / /\ \____|__ |__|\___ | __
  7. // \/ \/ \/ \/ )/ \/ \/ \/
  8. //
  9. // This file is part of libdsm. Copyright © 2014 VideoLabs SAS
  10. //
  11. // Author: Julien 'Lta' BALLET <contact@lta.io>
  12. //
  13. // This program is free software. It comes without any warranty, to the extent
  14. // permitted by applicable law. You can redistribute it and/or modify it under
  15. // the terms of the Do What The Fuck You Want To Public License, Version 2, as
  16. // published by Sam Hocevar. See the COPYING file for more details.
  17. //----------------------------------------------------------------------------
  18. /**
  19. * @file smb_stat.h
  20. * @brief File status / listing
  21. */
  22. #ifndef __BDSM_SMB_STAT_H_
  23. #define __BDSM_SMB_STAT_H_
  24. #include "bdsm/smb_defs.h"
  25. #include "bdsm/smb_session.h"
  26. /// smb_stat_get() OP: Get file size
  27. #define SMB_STAT_SIZE 0
  28. /// smb_stat_get() OP: Get file allocation size (Size on disk)
  29. #define SMB_STAT_ALLOC_SIZE 1
  30. /// smb_stat_get() OP: 0 -> not a directory, != 0 -> directory
  31. #define SMB_STAT_ISDIR 2
  32. /// smb_stat_get() OP: Get file creation time
  33. #define SMB_STAT_CTIME 3
  34. /// smb_stat_get() OP: Get file last access time
  35. #define SMB_STAT_ATIME 4
  36. /// smb_stat_get() OP: Get file last write time
  37. #define SMB_STAT_WTIME 5
  38. /// smb_stat_get() OP: Get file last moditification time
  39. #define SMB_STAT_MTIME 6
  40. /**
  41. * @brief Returns infos about files matching a pattern
  42. * @details This functions uses the FIND_FIRST2 SMB operations to list files
  43. * matching a certain pattern. It's basically used to list folder contents
  44. *
  45. * @param s The session object
  46. * @param tid The share inside of which we want to find files obtained by
  47. * smb_tree_connect()
  48. * @param pattern The pattern to match files. '\\*' will list all the files at
  49. * the root of the share. '\\afolder\\*' will list all the files inside of the
  50. * 'afolder' directory.
  51. * @return An opaque list of smb_stat or NULL in case of error
  52. */
  53. smb_stat_list smb_find(smb_session *s, smb_tid tid, const char *pattern);
  54. /**
  55. * @brief Get the status of a file from it's path inside of a share
  56. *
  57. * @param s The session object
  58. * @param tid The tree id of a share obtained by smb_tree_connect()
  59. * @param path The full path of the file relative to the root of the share
  60. * (e.g. '\\folder\\file.ext')
  61. *
  62. * @return An opaque smb_stat or NULL in case of error. You need to
  63. * destory this object with smb_stat_destroy after usage.
  64. */
  65. smb_stat smb_fstat(smb_session *s, smb_tid tid, const char *path);
  66. /**
  67. * @brief Get the status of an open file from it's file descriptor
  68. * @details The file status will be those at the time of open
  69. *
  70. * @param s The session object
  71. * @param fd The smb_fd from which you want infos/status
  72. *
  73. * @return An opaque smb_stat or NULL in case of error. You don't own
  74. * this object memory, and then don't have to destory it
  75. */
  76. smb_stat smb_stat_fd(smb_session *s, smb_fd fd);
  77. /**
  78. * @brief Clear a smb_stat object, reclaiming its memory
  79. *
  80. * @param stat A smb_stat object returned by smb_fstat.
  81. */
  82. void smb_stat_destroy(smb_stat stat);
  83. /**
  84. * @brief Get the number of item in a smb_stat_list file info
  85. *
  86. * @param list The list you want the length of
  87. * @return The length of the list. It returns 0 if the list is invalid
  88. */
  89. size_t smb_stat_list_count(smb_stat_list list);
  90. /**
  91. * @brief Get the element at the given position.
  92. *
  93. * @param list A stat list
  94. * @param index The position of the element you want.
  95. *
  96. * @return An opaque smb_stat or NULL in case of error
  97. */
  98. smb_stat smb_stat_list_at(smb_stat_list list, size_t index);
  99. /**
  100. * @brief Destroy and release a list of file stat returned by smb_find
  101. *
  102. * @param list The stat_list to free
  103. */
  104. void smb_stat_list_destroy(smb_stat_list list);
  105. /**
  106. * @brief Get the name of the file from its status
  107. *
  108. * @param info A file status
  109. * @return A null-terminated string in you current locale encoding or NULL.
  110. */
  111. const char *smb_stat_name(smb_stat info);
  112. /**
  113. * @brief Get a file attribute
  114. * @details This function is a getter that allow you to retrieve various
  115. * informations about a file on a smb_stat object. You can get its size,
  116. * various timestamps, etc.
  117. *
  118. * @param info The smb_stat object to get info from.
  119. * @param what This parameter tells the functions which information to get, can
  120. * be one of #SMB_STAT_SIZE, #SMB_STAT_ALLOC_SIZE, #SMB_STAT_ISDIR,
  121. * #SMB_STAT_CTIME, #SMB_STAT_ATIME, #SMB_STAT_MTIME, #SMB_STAT_WTIME.
  122. *
  123. * @return The meaning of the returned value depends on the 'what' parameter.
  124. * See each item documentation.
  125. */
  126. uint64_t smb_stat_get(smb_stat info, int what);
  127. #endif