OSDN Git Service

Merge branch 'uaccess.csum' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
[tomoyo/tomoyo-test1.git] / fs / cifs / dfs_cache.h
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
8 #ifndef _CIFS_DFS_CACHE_H
9 #define _CIFS_DFS_CACHE_H
10
11 #include <linux/nls.h>
12 #include <linux/list.h>
13 #include "cifsglob.h"
14
15 struct dfs_cache_tgt_list {
16         int tl_numtgts;
17         struct list_head tl_list;
18 };
19
20 struct dfs_cache_tgt_iterator {
21         char *it_name;
22         struct list_head it_list;
23 };
24
25 extern int dfs_cache_init(void);
26 extern void dfs_cache_destroy(void);
27 extern const struct proc_ops dfscache_proc_ops;
28
29 extern int dfs_cache_find(const unsigned int xid, struct cifs_ses *ses,
30                           const struct nls_table *nls_codepage, int remap,
31                           const char *path, struct dfs_info3_param *ref,
32                           struct dfs_cache_tgt_list *tgt_list);
33 extern int dfs_cache_noreq_find(const char *path, struct dfs_info3_param *ref,
34                                 struct dfs_cache_tgt_list *tgt_list);
35 extern int dfs_cache_update_tgthint(const unsigned int xid,
36                                     struct cifs_ses *ses,
37                                     const struct nls_table *nls_codepage,
38                                     int remap, const char *path,
39                                     const struct dfs_cache_tgt_iterator *it);
40 extern int
41 dfs_cache_noreq_update_tgthint(const char *path,
42                                const struct dfs_cache_tgt_iterator *it);
43 extern int dfs_cache_get_tgt_referral(const char *path,
44                                       const struct dfs_cache_tgt_iterator *it,
45                                       struct dfs_info3_param *ref);
46 extern int dfs_cache_add_vol(char *mntdata, struct smb_vol *vol,
47                         const char *fullpath);
48 extern int dfs_cache_update_vol(const char *fullpath,
49                                 struct TCP_Server_Info *server);
50 extern void dfs_cache_del_vol(const char *fullpath);
51
52 extern int dfs_cache_get_tgt_share(const struct dfs_cache_tgt_iterator *it,
53                                    const char **share, size_t *share_len,
54                                    const char **prefix, size_t *prefix_len);
55
56 static inline struct dfs_cache_tgt_iterator *
57 dfs_cache_get_next_tgt(struct dfs_cache_tgt_list *tl,
58                        struct dfs_cache_tgt_iterator *it)
59 {
60         if (!tl || list_empty(&tl->tl_list) || !it ||
61             list_is_last(&it->it_list, &tl->tl_list))
62                 return NULL;
63         return list_next_entry(it, it_list);
64 }
65
66 static inline struct dfs_cache_tgt_iterator *
67 dfs_cache_get_tgt_iterator(struct dfs_cache_tgt_list *tl)
68 {
69         if (!tl)
70                 return NULL;
71         return list_first_entry_or_null(&tl->tl_list,
72                                         struct dfs_cache_tgt_iterator,
73                                         it_list);
74 }
75
76 static inline void dfs_cache_free_tgts(struct dfs_cache_tgt_list *tl)
77 {
78         struct dfs_cache_tgt_iterator *it, *nit;
79
80         if (!tl || list_empty(&tl->tl_list))
81                 return;
82         list_for_each_entry_safe(it, nit, &tl->tl_list, it_list) {
83                 list_del(&it->it_list);
84                 kfree(it->it_name);
85                 kfree(it);
86         }
87         tl->tl_numtgts = 0;
88 }
89
90 static inline const char *
91 dfs_cache_get_tgt_name(const struct dfs_cache_tgt_iterator *it)
92 {
93         return it ? it->it_name : NULL;
94 }
95
96 static inline int
97 dfs_cache_get_nr_tgts(const struct dfs_cache_tgt_list *tl)
98 {
99         return tl ? tl->tl_numtgts : 0;
100 }
101
102 #endif /* _CIFS_DFS_CACHE_H */