2022-10-05 05:41:27 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2022 Paulo Alcantara <palcantara@suse.de>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _CIFS_DFS_H
|
|
|
|
#define _CIFS_DFS_H
|
|
|
|
|
|
|
|
#include "cifsglob.h"
|
|
|
|
#include "fs_context.h"
|
2022-11-18 00:23:49 +08:00
|
|
|
#include "cifs_unicode.h"
|
2022-10-05 05:41:27 +08:00
|
|
|
|
2023-03-15 07:32:54 +08:00
|
|
|
struct dfs_root_ses {
|
|
|
|
struct list_head list;
|
|
|
|
struct cifs_ses *ses;
|
|
|
|
};
|
|
|
|
|
2022-10-05 05:41:27 +08:00
|
|
|
int dfs_parse_target_referral(const char *full_path, const struct dfs_info3_param *ref,
|
|
|
|
struct smb3_fs_context *ctx);
|
2022-11-18 00:23:49 +08:00
|
|
|
int dfs_mount_share(struct cifs_mount_ctx *mnt_ctx, bool *isdfs);
|
2022-10-05 05:41:27 +08:00
|
|
|
|
2022-11-18 00:23:49 +08:00
|
|
|
static inline char *dfs_get_path(struct cifs_sb_info *cifs_sb, const char *path)
|
|
|
|
{
|
|
|
|
return dfs_cache_canonical_path(path, cifs_sb->local_nls, cifs_remap(cifs_sb));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int dfs_get_referral(struct cifs_mount_ctx *mnt_ctx, const char *path,
|
|
|
|
struct dfs_info3_param *ref, struct dfs_cache_tgt_list *tl)
|
|
|
|
{
|
2023-03-15 07:32:53 +08:00
|
|
|
struct smb3_fs_context *ctx = mnt_ctx->fs_ctx;
|
2022-11-18 00:23:49 +08:00
|
|
|
struct cifs_sb_info *cifs_sb = mnt_ctx->cifs_sb;
|
|
|
|
|
2023-03-15 07:32:53 +08:00
|
|
|
return dfs_cache_find(mnt_ctx->xid, ctx->dfs_root_ses, cifs_sb->local_nls,
|
2022-11-18 00:23:49 +08:00
|
|
|
cifs_remap(cifs_sb), path, ref, tl);
|
|
|
|
}
|
2022-10-05 05:41:27 +08:00
|
|
|
|
2023-04-17 02:38:28 +08:00
|
|
|
/* Return DFS full path out of a dentry set for automount */
|
2022-12-19 01:37:32 +08:00
|
|
|
static inline char *dfs_get_automount_devname(struct dentry *dentry, void *page)
|
|
|
|
{
|
|
|
|
struct cifs_sb_info *cifs_sb = CIFS_SB(dentry->d_sb);
|
|
|
|
struct cifs_tcon *tcon = cifs_sb_master_tcon(cifs_sb);
|
2023-04-17 02:38:28 +08:00
|
|
|
size_t len;
|
|
|
|
char *s;
|
2022-12-19 01:37:32 +08:00
|
|
|
|
2023-06-27 03:04:17 +08:00
|
|
|
spin_lock(&tcon->tc_lock);
|
|
|
|
if (unlikely(!tcon->origin_fullpath)) {
|
|
|
|
spin_unlock(&tcon->tc_lock);
|
2022-12-19 01:37:32 +08:00
|
|
|
return ERR_PTR(-EREMOTE);
|
2023-04-27 00:43:53 +08:00
|
|
|
}
|
2023-06-27 03:04:17 +08:00
|
|
|
spin_unlock(&tcon->tc_lock);
|
2022-12-19 01:37:32 +08:00
|
|
|
|
2023-04-17 02:38:28 +08:00
|
|
|
s = dentry_path_raw(dentry, page, PATH_MAX);
|
|
|
|
if (IS_ERR(s))
|
|
|
|
return s;
|
|
|
|
/* for root, we want "" */
|
|
|
|
if (!s[1])
|
|
|
|
s++;
|
|
|
|
|
2023-06-27 03:04:17 +08:00
|
|
|
spin_lock(&tcon->tc_lock);
|
|
|
|
len = strlen(tcon->origin_fullpath);
|
2023-04-27 00:43:53 +08:00
|
|
|
if (s < (char *)page + len) {
|
2023-06-27 03:04:17 +08:00
|
|
|
spin_unlock(&tcon->tc_lock);
|
2023-04-17 02:38:28 +08:00
|
|
|
return ERR_PTR(-ENAMETOOLONG);
|
2023-04-27 00:43:53 +08:00
|
|
|
}
|
2023-04-17 02:38:28 +08:00
|
|
|
|
|
|
|
s -= len;
|
2023-06-27 03:04:17 +08:00
|
|
|
memcpy(s, tcon->origin_fullpath, len);
|
|
|
|
spin_unlock(&tcon->tc_lock);
|
2023-04-17 02:38:28 +08:00
|
|
|
convert_delimiter(s, '/');
|
2023-04-27 00:43:53 +08:00
|
|
|
|
2023-04-17 02:38:28 +08:00
|
|
|
return s;
|
2022-12-19 01:37:32 +08:00
|
|
|
}
|
|
|
|
|
2023-03-15 07:32:54 +08:00
|
|
|
static inline void dfs_put_root_smb_sessions(struct list_head *head)
|
|
|
|
{
|
|
|
|
struct dfs_root_ses *root, *tmp;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(root, tmp, head, list) {
|
|
|
|
list_del_init(&root->list);
|
|
|
|
cifs_put_smb_ses(root->ses);
|
|
|
|
kfree(root);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-05 05:41:27 +08:00
|
|
|
#endif /* _CIFS_DFS_H */
|