dfs_cache.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * DFS referral cache routines
  4. *
  5. * Copyright (c) 2018-2019 Paulo Alcantara <palcantara@suse.de>
  6. */
  7. #ifndef _CIFS_DFS_CACHE_H
  8. #define _CIFS_DFS_CACHE_H
  9. #include <linux/nls.h>
  10. #include <linux/list.h>
  11. #include "cifsglob.h"
  12. struct dfs_cache_tgt_list {
  13. int tl_numtgts;
  14. struct list_head tl_list;
  15. };
  16. struct dfs_cache_tgt_iterator {
  17. char *it_name;
  18. int it_path_consumed;
  19. struct list_head it_list;
  20. };
  21. extern int dfs_cache_init(void);
  22. extern void dfs_cache_destroy(void);
  23. extern const struct proc_ops dfscache_proc_ops;
  24. extern int dfs_cache_find(const unsigned int xid, struct cifs_ses *ses,
  25. const struct nls_table *nls_codepage, int remap,
  26. const char *path, struct dfs_info3_param *ref,
  27. struct dfs_cache_tgt_list *tgt_list);
  28. extern int dfs_cache_noreq_find(const char *path, struct dfs_info3_param *ref,
  29. struct dfs_cache_tgt_list *tgt_list);
  30. extern int dfs_cache_update_tgthint(const unsigned int xid,
  31. struct cifs_ses *ses,
  32. const struct nls_table *nls_codepage,
  33. int remap, const char *path,
  34. const struct dfs_cache_tgt_iterator *it);
  35. extern int
  36. dfs_cache_noreq_update_tgthint(const char *path,
  37. const struct dfs_cache_tgt_iterator *it);
  38. extern int dfs_cache_get_tgt_referral(const char *path,
  39. const struct dfs_cache_tgt_iterator *it,
  40. struct dfs_info3_param *ref);
  41. extern int dfs_cache_add_vol(char *mntdata, struct smb_vol *vol,
  42. const char *fullpath);
  43. extern int dfs_cache_update_vol(const char *fullpath,
  44. struct TCP_Server_Info *server);
  45. extern void dfs_cache_del_vol(const char *fullpath);
  46. extern int dfs_cache_get_tgt_share(char *path, const struct dfs_cache_tgt_iterator *it,
  47. char **share, char **prefix);
  48. static inline struct dfs_cache_tgt_iterator *
  49. dfs_cache_get_next_tgt(struct dfs_cache_tgt_list *tl,
  50. struct dfs_cache_tgt_iterator *it)
  51. {
  52. if (!tl || list_empty(&tl->tl_list) || !it ||
  53. list_is_last(&it->it_list, &tl->tl_list))
  54. return NULL;
  55. return list_next_entry(it, it_list);
  56. }
  57. static inline struct dfs_cache_tgt_iterator *
  58. dfs_cache_get_tgt_iterator(struct dfs_cache_tgt_list *tl)
  59. {
  60. if (!tl)
  61. return NULL;
  62. return list_first_entry_or_null(&tl->tl_list,
  63. struct dfs_cache_tgt_iterator,
  64. it_list);
  65. }
  66. static inline void dfs_cache_free_tgts(struct dfs_cache_tgt_list *tl)
  67. {
  68. struct dfs_cache_tgt_iterator *it, *nit;
  69. if (!tl || list_empty(&tl->tl_list))
  70. return;
  71. list_for_each_entry_safe(it, nit, &tl->tl_list, it_list) {
  72. list_del(&it->it_list);
  73. kfree(it->it_name);
  74. kfree(it);
  75. }
  76. tl->tl_numtgts = 0;
  77. }
  78. static inline const char *
  79. dfs_cache_get_tgt_name(const struct dfs_cache_tgt_iterator *it)
  80. {
  81. return it ? it->it_name : NULL;
  82. }
  83. static inline int
  84. dfs_cache_get_nr_tgts(const struct dfs_cache_tgt_list *tl)
  85. {
  86. return tl ? tl->tl_numtgts : 0;
  87. }
  88. #endif /* _CIFS_DFS_CACHE_H */