smb_stat.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. #include <assert.h>
  31. #include "smb_stat.h"
  32. #include "smb_fd.h"
  33. smb_stat smb_stat_fd(smb_session *s, smb_fd fd)
  34. {
  35. assert(s != NULL && fd);
  36. return smb_session_file_get(s, fd);
  37. }
  38. void smb_stat_destroy(smb_stat stat)
  39. {
  40. smb_stat_list_destroy((smb_stat_list) stat);
  41. }
  42. size_t smb_stat_list_count(smb_stat_list list)
  43. {
  44. size_t count = 0;
  45. while (list != NULL)
  46. {
  47. list = list->next;
  48. ++count;
  49. }
  50. return count;
  51. }
  52. // XXX: Duplicate some code of smb_session_share_clear
  53. void smb_stat_list_destroy(smb_stat_list list)
  54. {
  55. smb_stat_list tmp;
  56. while(list != NULL)
  57. {
  58. tmp = list->next;
  59. free(list->name);
  60. free(list);
  61. list = tmp;
  62. }
  63. }
  64. smb_stat smb_stat_list_next(smb_stat_list list)
  65. {
  66. return list->next;
  67. }
  68. smb_stat smb_stat_list_at(smb_stat_list list, size_t index)
  69. {
  70. size_t pos = 0;
  71. while (list != NULL && pos < index)
  72. {
  73. list = list->next;
  74. pos++;
  75. }
  76. return list;
  77. }
  78. const char *smb_stat_name(smb_stat info)
  79. {
  80. if (info == NULL)
  81. return NULL;
  82. else
  83. return info->name;
  84. }
  85. uint64_t smb_stat_get(smb_stat info, int what)
  86. {
  87. if (info == NULL)
  88. return 0;
  89. switch (what)
  90. {
  91. case SMB_STAT_SIZE:
  92. return info->size;
  93. case SMB_STAT_ALLOC_SIZE:
  94. return info->alloc_size;
  95. case SMB_STAT_CTIME:
  96. return info->created;
  97. case SMB_STAT_ATIME:
  98. return info->accessed;
  99. case SMB_STAT_WTIME:
  100. return info->written;
  101. case SMB_STAT_MTIME:
  102. return info->changed;
  103. case SMB_STAT_ISDIR:
  104. return info->is_dir;
  105. default:
  106. return 0;
  107. }
  108. }