2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* fs/cifs/link.c
|
|
|
|
*
|
|
|
|
* Copyright (C) International Business Machines Corp., 2002,2003
|
|
|
|
* Author(s): Steve French (sfrench@us.ibm.com)
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published
|
|
|
|
* by the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
|
|
|
|
* the GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/stat.h>
|
|
|
|
#include <linux/namei.h>
|
|
|
|
#include "cifsfs.h"
|
|
|
|
#include "cifspdu.h"
|
|
|
|
#include "cifsglob.h"
|
|
|
|
#include "cifsproto.h"
|
|
|
|
#include "cifs_debug.h"
|
|
|
|
#include "cifs_fs_sb.h"
|
|
|
|
|
|
|
|
int
|
|
|
|
cifs_hardlink(struct dentry *old_file, struct inode *inode,
|
|
|
|
struct dentry *direntry)
|
|
|
|
{
|
|
|
|
int rc = -EACCES;
|
|
|
|
int xid;
|
|
|
|
char *fromName = NULL;
|
|
|
|
char *toName = NULL;
|
|
|
|
struct cifs_sb_info *cifs_sb_target;
|
|
|
|
struct cifsTconInfo *pTcon;
|
|
|
|
struct cifsInodeInfo *cifsInode;
|
|
|
|
|
|
|
|
xid = GetXid();
|
|
|
|
|
|
|
|
cifs_sb_target = CIFS_SB(inode->i_sb);
|
|
|
|
pTcon = cifs_sb_target->tcon;
|
|
|
|
|
|
|
|
/* No need to check for cross device links since server will do that
|
|
|
|
BB note DFS case in future though (when we may have to check) */
|
|
|
|
|
2005-08-31 02:32:14 +08:00
|
|
|
fromName = build_path_from_dentry(old_file);
|
|
|
|
toName = build_path_from_dentry(direntry);
|
2007-07-10 09:16:18 +08:00
|
|
|
if ((fromName == NULL) || (toName == NULL)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
rc = -ENOMEM;
|
|
|
|
goto cifs_hl_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cifs_sb_target->tcon->ses->capabilities & CAP_UNIX)
|
|
|
|
rc = CIFSUnixCreateHardLink(xid, pTcon, fromName, toName,
|
2007-07-10 09:16:18 +08:00
|
|
|
cifs_sb_target->local_nls,
|
2005-04-29 13:41:06 +08:00
|
|
|
cifs_sb_target->mnt_cifs_flags &
|
|
|
|
CIFS_MOUNT_MAP_SPECIAL_CHR);
|
2005-04-17 06:20:36 +08:00
|
|
|
else {
|
|
|
|
rc = CIFSCreateHardLink(xid, pTcon, fromName, toName,
|
2007-07-10 09:16:18 +08:00
|
|
|
cifs_sb_target->local_nls,
|
2005-04-29 13:41:06 +08:00
|
|
|
cifs_sb_target->mnt_cifs_flags &
|
|
|
|
CIFS_MOUNT_MAP_SPECIAL_CHR);
|
2007-07-10 09:16:18 +08:00
|
|
|
if ((rc == -EIO) || (rc == -EINVAL))
|
|
|
|
rc = -EOPNOTSUPP;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-11-17 04:54:20 +08:00
|
|
|
d_drop(direntry); /* force new lookup from server of target */
|
|
|
|
|
|
|
|
/* if source file is cached (oplocked) revalidate will not go to server
|
|
|
|
until the file is closed or oplock broken so update nlinks locally */
|
2007-07-10 09:16:18 +08:00
|
|
|
if (old_file->d_inode) {
|
2006-11-17 04:54:20 +08:00
|
|
|
cifsInode = CIFS_I(old_file->d_inode);
|
2007-07-10 09:16:18 +08:00
|
|
|
if (rc == 0) {
|
2006-11-17 04:54:20 +08:00
|
|
|
old_file->d_inode->i_nlink++;
|
2007-02-17 12:30:54 +08:00
|
|
|
/* BB should we make this contingent on superblock flag NOATIME? */
|
|
|
|
/* old_file->d_inode->i_ctime = CURRENT_TIME;*/
|
2006-11-17 04:54:20 +08:00
|
|
|
/* parent dir timestamps will update from srv
|
|
|
|
within a second, would it really be worth it
|
|
|
|
to set the parent dir cifs inode time to zero
|
|
|
|
to force revalidate (faster) for it too? */
|
|
|
|
}
|
2007-07-10 09:16:18 +08:00
|
|
|
/* if not oplocked will force revalidate to get info
|
2006-11-17 04:54:20 +08:00
|
|
|
on source file from srv */
|
|
|
|
cifsInode->time = 0;
|
|
|
|
|
2007-07-10 09:16:18 +08:00
|
|
|
/* Will update parent dir timestamps from srv within a second.
|
2006-11-17 04:54:20 +08:00
|
|
|
Would it really be worth it to set the parent dir (cifs
|
|
|
|
inode) time field to zero to force revalidate on parent
|
2007-07-10 09:16:18 +08:00
|
|
|
directory faster ie
|
2006-11-17 04:54:20 +08:00
|
|
|
CIFS_I(inode)->time = 0; */
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cifs_hl_exit:
|
2005-11-07 17:01:34 +08:00
|
|
|
kfree(fromName);
|
|
|
|
kfree(toName);
|
2005-04-17 06:20:36 +08:00
|
|
|
FreeXid(xid);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2005-08-20 09:02:56 +08:00
|
|
|
void *
|
2005-04-17 06:20:36 +08:00
|
|
|
cifs_follow_link(struct dentry *direntry, struct nameidata *nd)
|
|
|
|
{
|
|
|
|
struct inode *inode = direntry->d_inode;
|
|
|
|
int rc = -EACCES;
|
|
|
|
int xid;
|
|
|
|
char *full_path = NULL;
|
2007-07-10 09:16:18 +08:00
|
|
|
char *target_path = ERR_PTR(-ENOMEM);
|
2005-04-17 06:20:36 +08:00
|
|
|
struct cifs_sb_info *cifs_sb;
|
|
|
|
struct cifsTconInfo *pTcon;
|
|
|
|
|
|
|
|
xid = GetXid();
|
|
|
|
|
2005-08-31 02:32:14 +08:00
|
|
|
full_path = build_path_from_dentry(direntry);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!full_path)
|
|
|
|
goto out_no_free;
|
|
|
|
|
|
|
|
cFYI(1, ("Full path: %s inode = 0x%p", full_path, inode));
|
2005-08-31 02:32:14 +08:00
|
|
|
cifs_sb = CIFS_SB(inode->i_sb);
|
|
|
|
pTcon = cifs_sb->tcon;
|
2005-04-17 06:20:36 +08:00
|
|
|
target_path = kmalloc(PATH_MAX, GFP_KERNEL);
|
|
|
|
if (!target_path) {
|
|
|
|
target_path = ERR_PTR(-ENOMEM);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2007-07-10 09:16:18 +08:00
|
|
|
/* BB add read reparse point symlink code and Unix extensions
|
|
|
|
symlink code here BB */
|
2005-04-17 06:20:36 +08:00
|
|
|
if (pTcon->ses->capabilities & CAP_UNIX)
|
|
|
|
rc = CIFSSMBUnixQuerySymLink(xid, pTcon, full_path,
|
|
|
|
target_path,
|
|
|
|
PATH_MAX-1,
|
|
|
|
cifs_sb->local_nls);
|
|
|
|
else {
|
|
|
|
/* rc = CIFSSMBQueryReparseLinkInfo */
|
|
|
|
/* BB Add code to Query ReparsePoint info */
|
|
|
|
/* BB Add MAC style xsymlink check here if enabled */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc == 0) {
|
|
|
|
|
|
|
|
/* BB Add special case check for Samba DFS symlinks */
|
|
|
|
|
|
|
|
target_path[PATH_MAX-1] = 0;
|
|
|
|
} else {
|
|
|
|
kfree(target_path);
|
|
|
|
target_path = ERR_PTR(rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
kfree(full_path);
|
|
|
|
out_no_free:
|
|
|
|
FreeXid(xid);
|
|
|
|
nd_set_link(nd, target_path);
|
2005-08-20 09:02:56 +08:00
|
|
|
return NULL; /* No cookie */
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cifs_symlink(struct inode *inode, struct dentry *direntry, const char *symname)
|
|
|
|
{
|
|
|
|
int rc = -EOPNOTSUPP;
|
|
|
|
int xid;
|
|
|
|
struct cifs_sb_info *cifs_sb;
|
|
|
|
struct cifsTconInfo *pTcon;
|
|
|
|
char *full_path = NULL;
|
|
|
|
struct inode *newinode = NULL;
|
|
|
|
|
|
|
|
xid = GetXid();
|
|
|
|
|
|
|
|
cifs_sb = CIFS_SB(inode->i_sb);
|
|
|
|
pTcon = cifs_sb->tcon;
|
|
|
|
|
2005-08-31 02:32:14 +08:00
|
|
|
full_path = build_path_from_dentry(direntry);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-07-10 09:16:18 +08:00
|
|
|
if (full_path == NULL) {
|
2005-04-17 06:20:36 +08:00
|
|
|
FreeXid(xid);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2006-06-01 02:05:34 +08:00
|
|
|
cFYI(1, ("Full path: %s", full_path));
|
2005-04-17 06:20:36 +08:00
|
|
|
cFYI(1, ("symname is %s", symname));
|
|
|
|
|
|
|
|
/* BB what if DFS and this volume is on different share? BB */
|
|
|
|
if (cifs_sb->tcon->ses->capabilities & CAP_UNIX)
|
|
|
|
rc = CIFSUnixCreateSymLink(xid, pTcon, full_path, symname,
|
|
|
|
cifs_sb->local_nls);
|
|
|
|
/* else
|
2007-07-10 09:16:18 +08:00
|
|
|
rc = CIFSCreateReparseSymLink(xid, pTcon, fromName, toName,
|
|
|
|
cifs_sb_target->local_nls); */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (rc == 0) {
|
|
|
|
if (pTcon->ses->capabilities & CAP_UNIX)
|
|
|
|
rc = cifs_get_inode_info_unix(&newinode, full_path,
|
2007-07-10 09:16:18 +08:00
|
|
|
inode->i_sb, xid);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
|
|
|
rc = cifs_get_inode_info(&newinode, full_path, NULL,
|
2007-07-10 09:16:18 +08:00
|
|
|
inode->i_sb, xid);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (rc != 0) {
|
2006-06-01 02:05:34 +08:00
|
|
|
cFYI(1, ("Create symlink ok, getinodeinfo fail rc = %d",
|
2005-04-17 06:20:36 +08:00
|
|
|
rc));
|
|
|
|
} else {
|
2005-08-23 11:09:43 +08:00
|
|
|
if (pTcon->nocase)
|
|
|
|
direntry->d_op = &cifs_ci_dentry_ops;
|
|
|
|
else
|
|
|
|
direntry->d_op = &cifs_dentry_ops;
|
2005-04-17 06:20:36 +08:00
|
|
|
d_instantiate(direntry, newinode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-07 17:01:34 +08:00
|
|
|
kfree(full_path);
|
2005-04-17 06:20:36 +08:00
|
|
|
FreeXid(xid);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cifs_readlink(struct dentry *direntry, char __user *pBuffer, int buflen)
|
|
|
|
{
|
|
|
|
struct inode *inode = direntry->d_inode;
|
|
|
|
int rc = -EACCES;
|
|
|
|
int xid;
|
|
|
|
int oplock = FALSE;
|
|
|
|
struct cifs_sb_info *cifs_sb;
|
|
|
|
struct cifsTconInfo *pTcon;
|
|
|
|
char *full_path = NULL;
|
2007-07-10 09:16:18 +08:00
|
|
|
char *tmp_path = NULL;
|
|
|
|
char *tmpbuffer;
|
|
|
|
unsigned char *referrals = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
int num_referrals = 0;
|
|
|
|
int len;
|
|
|
|
__u16 fid;
|
|
|
|
|
|
|
|
xid = GetXid();
|
|
|
|
cifs_sb = CIFS_SB(inode->i_sb);
|
|
|
|
pTcon = cifs_sb->tcon;
|
|
|
|
|
2007-07-10 09:16:18 +08:00
|
|
|
/* BB would it be safe against deadlock to grab this sem
|
2005-04-17 06:20:36 +08:00
|
|
|
even though rename itself grabs the sem and calls lookup? */
|
2006-03-23 19:00:33 +08:00
|
|
|
/* mutex_lock(&inode->i_sb->s_vfs_rename_mutex);*/
|
2005-08-31 02:32:14 +08:00
|
|
|
full_path = build_path_from_dentry(direntry);
|
2006-03-23 19:00:33 +08:00
|
|
|
/* mutex_unlock(&inode->i_sb->s_vfs_rename_mutex);*/
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-07-10 09:16:18 +08:00
|
|
|
if (full_path == NULL) {
|
2005-04-17 06:20:36 +08:00
|
|
|
FreeXid(xid);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
cFYI(1,
|
|
|
|
("Full path: %s inode = 0x%p pBuffer = 0x%p buflen = %d",
|
|
|
|
full_path, inode, pBuffer, buflen));
|
2007-07-10 09:16:18 +08:00
|
|
|
if (buflen > PATH_MAX)
|
2005-04-17 06:20:36 +08:00
|
|
|
len = PATH_MAX;
|
|
|
|
else
|
|
|
|
len = buflen;
|
2007-07-10 09:16:18 +08:00
|
|
|
tmpbuffer = kmalloc(len, GFP_KERNEL);
|
|
|
|
if (tmpbuffer == NULL) {
|
2005-11-07 17:01:34 +08:00
|
|
|
kfree(full_path);
|
2005-04-17 06:20:36 +08:00
|
|
|
FreeXid(xid);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2007-07-10 09:16:18 +08:00
|
|
|
/* BB add read reparse point symlink code and
|
|
|
|
Unix extensions symlink code here BB */
|
2005-04-17 06:20:36 +08:00
|
|
|
if (cifs_sb->tcon->ses->capabilities & CAP_UNIX)
|
|
|
|
rc = CIFSSMBUnixQuerySymLink(xid, pTcon, full_path,
|
|
|
|
tmpbuffer,
|
|
|
|
len - 1,
|
|
|
|
cifs_sb->local_nls);
|
2006-09-28 11:35:57 +08:00
|
|
|
else if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UNX_EMUL) {
|
2007-07-10 09:16:18 +08:00
|
|
|
cERROR(1, ("SFU style symlinks not implemented yet"));
|
2006-09-28 11:35:57 +08:00
|
|
|
/* add open and read as in fs/cifs/inode.c */
|
|
|
|
} else {
|
2005-04-17 06:20:36 +08:00
|
|
|
rc = CIFSSMBOpen(xid, pTcon, full_path, FILE_OPEN, GENERIC_READ,
|
2007-07-10 09:16:18 +08:00
|
|
|
OPEN_REPARSE_POINT, &fid, &oplock, NULL,
|
|
|
|
cifs_sb->local_nls,
|
|
|
|
cifs_sb->mnt_cifs_flags &
|
2005-04-29 13:41:06 +08:00
|
|
|
CIFS_MOUNT_MAP_SPECIAL_CHR);
|
2007-07-10 09:16:18 +08:00
|
|
|
if (!rc) {
|
2005-04-17 06:20:36 +08:00
|
|
|
rc = CIFSSMBQueryReparseLinkInfo(xid, pTcon, full_path,
|
|
|
|
tmpbuffer,
|
2007-07-10 09:16:18 +08:00
|
|
|
len - 1,
|
2005-04-17 06:20:36 +08:00
|
|
|
fid,
|
|
|
|
cifs_sb->local_nls);
|
2007-07-10 09:16:18 +08:00
|
|
|
if (CIFSSMBClose(xid, pTcon, fid)) {
|
2007-07-18 01:34:02 +08:00
|
|
|
cFYI(1, ("Error closing junction point "
|
|
|
|
"(open for ioctl)"));
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-07-10 09:16:18 +08:00
|
|
|
if (rc == -EIO) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Query if DFS Junction */
|
|
|
|
tmp_path =
|
|
|
|
kmalloc(MAX_TREE_SIZE + MAX_PATHCONF + 1,
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (tmp_path) {
|
2007-07-10 09:16:18 +08:00
|
|
|
strncpy(tmp_path, pTcon->treeName,
|
|
|
|
MAX_TREE_SIZE);
|
|
|
|
strncat(tmp_path, full_path,
|
|
|
|
MAX_PATHCONF);
|
|
|
|
rc = get_dfs_path(xid, pTcon->ses,
|
|
|
|
tmp_path,
|
2005-04-29 13:41:06 +08:00
|
|
|
cifs_sb->local_nls,
|
|
|
|
&num_referrals, &referrals,
|
|
|
|
cifs_sb->mnt_cifs_flags &
|
|
|
|
CIFS_MOUNT_MAP_SPECIAL_CHR);
|
2007-07-10 09:16:18 +08:00
|
|
|
cFYI(1, ("Get DFS for %s rc = %d ",
|
|
|
|
tmp_path, rc));
|
|
|
|
if ((num_referrals == 0) && (rc == 0))
|
2005-04-17 06:20:36 +08:00
|
|
|
rc = -EACCES;
|
|
|
|
else {
|
2007-07-10 09:16:18 +08:00
|
|
|
cFYI(1, ("num referral: %d",
|
|
|
|
num_referrals));
|
|
|
|
if (referrals) {
|
|
|
|
cFYI(1,("referral string: %s", referrals));
|
2007-07-13 08:33:32 +08:00
|
|
|
strncpy(tmpbuffer,
|
|
|
|
referrals,
|
|
|
|
len-1);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
2005-11-07 17:01:34 +08:00
|
|
|
kfree(referrals);
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree(tmp_path);
|
|
|
|
}
|
2007-07-10 09:16:18 +08:00
|
|
|
/* BB add code like else decode referrals
|
|
|
|
then memcpy to tmpbuffer and free referrals
|
|
|
|
string array BB */
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* BB Anything else to do to handle recursive links? */
|
|
|
|
/* BB Should we be using page ops here? */
|
|
|
|
|
|
|
|
/* BB null terminate returned string in pBuffer? BB */
|
|
|
|
if (rc == 0) {
|
|
|
|
rc = vfs_readlink(direntry, pBuffer, len, tmpbuffer);
|
|
|
|
cFYI(1,
|
|
|
|
("vfs_readlink called from cifs_readlink returned %d",
|
|
|
|
rc));
|
|
|
|
}
|
|
|
|
|
2005-11-07 17:01:34 +08:00
|
|
|
kfree(tmpbuffer);
|
|
|
|
kfree(full_path);
|
2005-04-17 06:20:36 +08:00
|
|
|
FreeXid(xid);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2005-08-20 09:02:56 +08:00
|
|
|
void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
char *p = nd_get_link(nd);
|
|
|
|
if (!IS_ERR(p))
|
|
|
|
kfree(p);
|
|
|
|
}
|