dfs.h 2.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/* 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"
11
#include "cifs_unicode.h"
12

13 14 15 16 17
struct dfs_root_ses {
	struct list_head list;
	struct cifs_ses *ses;
};

18 19
int dfs_parse_target_referral(const char *full_path, const struct dfs_info3_param *ref,
			      struct smb3_fs_context *ctx);
20
int dfs_mount_share(struct cifs_mount_ctx *mnt_ctx, bool *isdfs);
21

22 23 24 25 26 27 28 29
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)
{
30
	struct smb3_fs_context *ctx = mnt_ctx->fs_ctx;
31 32
	struct cifs_sb_info *cifs_sb = mnt_ctx->cifs_sb;

33
	return dfs_cache_find(mnt_ctx->xid, ctx->dfs_root_ses, cifs_sb->local_nls,
34 35
			      cifs_remap(cifs_sb), path, ref, tl);
}
36

37
/* Return DFS full path out of a dentry set for automount */
38 39 40 41 42
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);
	struct TCP_Server_Info *server = tcon->ses->server;
43 44
	size_t len;
	char *s;
45

46 47 48
	spin_lock(&server->srv_lock);
	if (unlikely(!server->origin_fullpath)) {
		spin_unlock(&server->srv_lock);
49
		return ERR_PTR(-EREMOTE);
50 51
	}
	spin_unlock(&server->srv_lock);
52

53 54 55 56 57 58 59
	s = dentry_path_raw(dentry, page, PATH_MAX);
	if (IS_ERR(s))
		return s;
	/* for root, we want "" */
	if (!s[1])
		s++;

60
	spin_lock(&server->srv_lock);
61
	len = strlen(server->origin_fullpath);
62 63
	if (s < (char *)page + len) {
		spin_unlock(&server->srv_lock);
64
		return ERR_PTR(-ENAMETOOLONG);
65
	}
66 67 68

	s -= len;
	memcpy(s, server->origin_fullpath, len);
69
	spin_unlock(&server->srv_lock);
70
	convert_delimiter(s, '/');
71

72
	return s;
73 74
}

75 76 77 78 79 80 81 82 83 84 85
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);
	}
}

86
#endif /* _CIFS_DFS_H */