2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* fs/cifs/link.c
|
|
|
|
*
|
2008-01-25 18:12:41 +08:00
|
|
|
* Copyright (C) International Business Machines Corp., 2002,2008
|
2005-04-17 06:20:36 +08:00
|
|
|
* 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 cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#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"
|
2010-07-31 15:14:16 +08:00
|
|
|
|
|
|
|
#define CIFS_MF_SYMLINK_LEN_OFFSET (4+1)
|
|
|
|
#define CIFS_MF_SYMLINK_MD5_OFFSET (CIFS_MF_SYMLINK_LEN_OFFSET+(4+1))
|
|
|
|
#define CIFS_MF_SYMLINK_LINK_OFFSET (CIFS_MF_SYMLINK_MD5_OFFSET+(32+1))
|
|
|
|
#define CIFS_MF_SYMLINK_LINK_MAXLEN (1024)
|
|
|
|
#define CIFS_MF_SYMLINK_FILE_SIZE \
|
|
|
|
(CIFS_MF_SYMLINK_LINK_OFFSET + CIFS_MF_SYMLINK_LINK_MAXLEN)
|
|
|
|
|
|
|
|
#define CIFS_MF_SYMLINK_LEN_FORMAT "XSym\n%04u\n"
|
|
|
|
#define CIFS_MF_SYMLINK_MD5_FORMAT \
|
|
|
|
"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n"
|
|
|
|
#define CIFS_MF_SYMLINK_MD5_ARGS(md5_hash) \
|
|
|
|
md5_hash[0], md5_hash[1], md5_hash[2], md5_hash[3], \
|
|
|
|
md5_hash[4], md5_hash[5], md5_hash[6], md5_hash[7], \
|
|
|
|
md5_hash[8], md5_hash[9], md5_hash[10], md5_hash[11],\
|
|
|
|
md5_hash[12], md5_hash[13], md5_hash[14], md5_hash[15]
|
|
|
|
|
2011-01-26 03:28:43 +08:00
|
|
|
static int
|
|
|
|
symlink_hash(unsigned int link_len, const char *link_str, u8 *md5_hash)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
unsigned int size;
|
|
|
|
struct crypto_shash *md5;
|
|
|
|
struct sdesc *sdescmd5;
|
|
|
|
|
|
|
|
md5 = crypto_alloc_shash("md5", 0, 0);
|
2011-01-27 23:58:04 +08:00
|
|
|
if (IS_ERR(md5)) {
|
2011-01-29 20:03:02 +08:00
|
|
|
rc = PTR_ERR(md5);
|
2012-07-24 01:14:28 +08:00
|
|
|
cERROR(1, "%s: Crypto md5 allocation error %d", __func__, rc);
|
2011-01-29 20:03:02 +08:00
|
|
|
return rc;
|
2011-01-26 03:28:43 +08:00
|
|
|
}
|
|
|
|
size = sizeof(struct shash_desc) + crypto_shash_descsize(md5);
|
|
|
|
sdescmd5 = kmalloc(size, GFP_KERNEL);
|
|
|
|
if (!sdescmd5) {
|
|
|
|
rc = -ENOMEM;
|
2012-07-24 01:14:28 +08:00
|
|
|
cERROR(1, "%s: Memory allocation failure", __func__);
|
2011-01-26 03:28:43 +08:00
|
|
|
goto symlink_hash_err;
|
|
|
|
}
|
|
|
|
sdescmd5->shash.tfm = md5;
|
|
|
|
sdescmd5->shash.flags = 0x0;
|
|
|
|
|
|
|
|
rc = crypto_shash_init(&sdescmd5->shash);
|
|
|
|
if (rc) {
|
2012-07-24 01:14:28 +08:00
|
|
|
cERROR(1, "%s: Could not init md5 shash", __func__);
|
2011-01-26 03:28:43 +08:00
|
|
|
goto symlink_hash_err;
|
|
|
|
}
|
2011-06-21 05:14:03 +08:00
|
|
|
rc = crypto_shash_update(&sdescmd5->shash, link_str, link_len);
|
|
|
|
if (rc) {
|
2012-07-24 01:14:28 +08:00
|
|
|
cERROR(1, "%s: Could not update iwth link_str", __func__);
|
2011-06-21 05:14:03 +08:00
|
|
|
goto symlink_hash_err;
|
|
|
|
}
|
2011-01-26 03:28:43 +08:00
|
|
|
rc = crypto_shash_final(&sdescmd5->shash, md5_hash);
|
2011-06-21 05:14:03 +08:00
|
|
|
if (rc)
|
2012-07-24 01:14:28 +08:00
|
|
|
cERROR(1, "%s: Could not generate md5 hash", __func__);
|
2011-01-26 03:28:43 +08:00
|
|
|
|
|
|
|
symlink_hash_err:
|
|
|
|
crypto_free_shash(md5);
|
|
|
|
kfree(sdescmd5);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2010-07-31 15:14:16 +08:00
|
|
|
static int
|
|
|
|
CIFSParseMFSymlink(const u8 *buf,
|
|
|
|
unsigned int buf_len,
|
|
|
|
unsigned int *_link_len,
|
|
|
|
char **_link_str)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
unsigned int link_len;
|
|
|
|
const char *md5_str1;
|
|
|
|
const char *link_str;
|
|
|
|
u8 md5_hash[16];
|
|
|
|
char md5_str2[34];
|
|
|
|
|
|
|
|
if (buf_len != CIFS_MF_SYMLINK_FILE_SIZE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
md5_str1 = (const char *)&buf[CIFS_MF_SYMLINK_MD5_OFFSET];
|
|
|
|
link_str = (const char *)&buf[CIFS_MF_SYMLINK_LINK_OFFSET];
|
|
|
|
|
|
|
|
rc = sscanf(buf, CIFS_MF_SYMLINK_LEN_FORMAT, &link_len);
|
|
|
|
if (rc != 1)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2011-01-26 03:28:43 +08:00
|
|
|
rc = symlink_hash(link_len, link_str, md5_hash);
|
|
|
|
if (rc) {
|
2012-07-24 01:14:28 +08:00
|
|
|
cFYI(1, "%s: MD5 hash failure: %d", __func__, rc);
|
2011-01-26 03:28:43 +08:00
|
|
|
return rc;
|
|
|
|
}
|
2010-07-31 15:14:16 +08:00
|
|
|
|
|
|
|
snprintf(md5_str2, sizeof(md5_str2),
|
|
|
|
CIFS_MF_SYMLINK_MD5_FORMAT,
|
|
|
|
CIFS_MF_SYMLINK_MD5_ARGS(md5_hash));
|
|
|
|
|
|
|
|
if (strncmp(md5_str1, md5_str2, 17) != 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (_link_str) {
|
|
|
|
*_link_str = kstrndup(link_str, link_len, GFP_KERNEL);
|
|
|
|
if (!*_link_str)
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
*_link_len = link_len;
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-08-06 03:13:44 +08:00
|
|
|
static int
|
2010-08-03 17:24:22 +08:00
|
|
|
CIFSFormatMFSymlink(u8 *buf, unsigned int buf_len, const char *link_str)
|
|
|
|
{
|
2011-01-26 03:28:43 +08:00
|
|
|
int rc;
|
2010-08-03 17:24:22 +08:00
|
|
|
unsigned int link_len;
|
|
|
|
unsigned int ofs;
|
|
|
|
u8 md5_hash[16];
|
|
|
|
|
|
|
|
if (buf_len != CIFS_MF_SYMLINK_FILE_SIZE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
link_len = strlen(link_str);
|
|
|
|
|
|
|
|
if (link_len > CIFS_MF_SYMLINK_LINK_MAXLEN)
|
|
|
|
return -ENAMETOOLONG;
|
|
|
|
|
2011-01-26 03:28:43 +08:00
|
|
|
rc = symlink_hash(link_len, link_str, md5_hash);
|
|
|
|
if (rc) {
|
2012-07-24 01:14:28 +08:00
|
|
|
cFYI(1, "%s: MD5 hash failure: %d", __func__, rc);
|
2011-01-26 03:28:43 +08:00
|
|
|
return rc;
|
|
|
|
}
|
2010-08-03 17:24:22 +08:00
|
|
|
|
|
|
|
snprintf(buf, buf_len,
|
|
|
|
CIFS_MF_SYMLINK_LEN_FORMAT CIFS_MF_SYMLINK_MD5_FORMAT,
|
|
|
|
link_len,
|
|
|
|
CIFS_MF_SYMLINK_MD5_ARGS(md5_hash));
|
|
|
|
|
|
|
|
ofs = CIFS_MF_SYMLINK_LINK_OFFSET;
|
|
|
|
memcpy(buf + ofs, link_str, link_len);
|
|
|
|
|
|
|
|
ofs += link_len;
|
|
|
|
if (ofs < CIFS_MF_SYMLINK_FILE_SIZE) {
|
|
|
|
buf[ofs] = '\n';
|
|
|
|
ofs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (ofs < CIFS_MF_SYMLINK_FILE_SIZE) {
|
|
|
|
buf[ofs] = ' ';
|
|
|
|
ofs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-08-06 03:15:22 +08:00
|
|
|
static int
|
2012-06-20 15:21:16 +08:00
|
|
|
CIFSCreateMFSymLink(const unsigned int xid, struct cifs_tcon *tcon,
|
2010-08-06 03:15:22 +08:00
|
|
|
const char *fromName, const char *toName,
|
2011-09-26 22:56:44 +08:00
|
|
|
struct cifs_sb_info *cifs_sb)
|
2010-08-06 03:15:22 +08:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
int oplock = 0;
|
2011-09-26 22:56:44 +08:00
|
|
|
int remap;
|
|
|
|
int create_options = CREATE_NOT_DIR;
|
2010-08-06 03:15:22 +08:00
|
|
|
__u16 netfid = 0;
|
|
|
|
u8 *buf;
|
|
|
|
unsigned int bytes_written = 0;
|
2011-05-26 14:01:59 +08:00
|
|
|
struct cifs_io_parms io_parms;
|
2011-09-26 22:56:44 +08:00
|
|
|
struct nls_table *nls_codepage;
|
|
|
|
|
|
|
|
nls_codepage = cifs_sb->local_nls;
|
|
|
|
remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR;
|
2010-08-06 03:15:22 +08:00
|
|
|
|
|
|
|
buf = kmalloc(CIFS_MF_SYMLINK_FILE_SIZE, GFP_KERNEL);
|
|
|
|
if (!buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
rc = CIFSFormatMFSymlink(buf, CIFS_MF_SYMLINK_FILE_SIZE, toName);
|
|
|
|
if (rc != 0) {
|
|
|
|
kfree(buf);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2011-09-26 22:56:44 +08:00
|
|
|
if (backup_cred(cifs_sb))
|
|
|
|
create_options |= CREATE_OPEN_BACKUP_INTENT;
|
|
|
|
|
2010-08-06 03:15:22 +08:00
|
|
|
rc = CIFSSMBOpen(xid, tcon, fromName, FILE_CREATE, GENERIC_WRITE,
|
2011-09-26 22:56:44 +08:00
|
|
|
create_options, &netfid, &oplock, NULL,
|
2010-08-06 03:15:22 +08:00
|
|
|
nls_codepage, remap);
|
|
|
|
if (rc != 0) {
|
|
|
|
kfree(buf);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2011-05-26 14:01:59 +08:00
|
|
|
io_parms.netfid = netfid;
|
|
|
|
io_parms.pid = current->tgid;
|
|
|
|
io_parms.tcon = tcon;
|
|
|
|
io_parms.offset = 0;
|
|
|
|
io_parms.length = CIFS_MF_SYMLINK_FILE_SIZE;
|
|
|
|
|
|
|
|
rc = CIFSSMBWrite(xid, &io_parms, &bytes_written, buf, NULL, 0);
|
2010-08-06 03:15:22 +08:00
|
|
|
CIFSSMBClose(xid, tcon, netfid);
|
|
|
|
kfree(buf);
|
|
|
|
if (rc != 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
if (bytes_written != CIFS_MF_SYMLINK_FILE_SIZE)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-06-20 15:21:16 +08:00
|
|
|
CIFSQueryMFSymLink(const unsigned int xid, struct cifs_tcon *tcon,
|
2010-08-06 03:13:44 +08:00
|
|
|
const unsigned char *searchName, char **symlinkinfo,
|
|
|
|
const struct nls_table *nls_codepage, int remap)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
int oplock = 0;
|
|
|
|
__u16 netfid = 0;
|
|
|
|
u8 *buf;
|
|
|
|
char *pbuf;
|
|
|
|
unsigned int bytes_read = 0;
|
|
|
|
int buf_type = CIFS_NO_BUFFER;
|
|
|
|
unsigned int link_len = 0;
|
2011-05-26 14:02:00 +08:00
|
|
|
struct cifs_io_parms io_parms;
|
2010-08-06 03:13:44 +08:00
|
|
|
FILE_ALL_INFO file_info;
|
|
|
|
|
|
|
|
rc = CIFSSMBOpen(xid, tcon, searchName, FILE_OPEN, GENERIC_READ,
|
|
|
|
CREATE_NOT_DIR, &netfid, &oplock, &file_info,
|
|
|
|
nls_codepage, remap);
|
|
|
|
if (rc != 0)
|
|
|
|
return rc;
|
|
|
|
|
2011-03-13 13:08:25 +08:00
|
|
|
if (file_info.EndOfFile != cpu_to_le64(CIFS_MF_SYMLINK_FILE_SIZE)) {
|
2010-08-06 03:13:44 +08:00
|
|
|
CIFSSMBClose(xid, tcon, netfid);
|
|
|
|
/* it's not a symlink */
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf = kmalloc(CIFS_MF_SYMLINK_FILE_SIZE, GFP_KERNEL);
|
|
|
|
if (!buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
pbuf = buf;
|
2011-05-26 14:02:00 +08:00
|
|
|
io_parms.netfid = netfid;
|
|
|
|
io_parms.pid = current->tgid;
|
|
|
|
io_parms.tcon = tcon;
|
|
|
|
io_parms.offset = 0;
|
|
|
|
io_parms.length = CIFS_MF_SYMLINK_FILE_SIZE;
|
2010-08-06 03:13:44 +08:00
|
|
|
|
2011-05-26 14:02:00 +08:00
|
|
|
rc = CIFSSMBRead(xid, &io_parms, &bytes_read, &pbuf, &buf_type);
|
2010-08-06 03:13:44 +08:00
|
|
|
CIFSSMBClose(xid, tcon, netfid);
|
|
|
|
if (rc != 0) {
|
|
|
|
kfree(buf);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = CIFSParseMFSymlink(buf, bytes_read, &link_len, symlinkinfo);
|
|
|
|
kfree(buf);
|
|
|
|
if (rc != 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-07-31 15:15:10 +08:00
|
|
|
bool
|
|
|
|
CIFSCouldBeMFSymlink(const struct cifs_fattr *fattr)
|
|
|
|
{
|
|
|
|
if (!(fattr->cf_mode & S_IFREG))
|
|
|
|
/* it's not a symlink */
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (fattr->cf_eof != CIFS_MF_SYMLINK_FILE_SIZE)
|
|
|
|
/* it's not a symlink */
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
CIFSCheckMFSymlink(struct cifs_fattr *fattr,
|
|
|
|
const unsigned char *path,
|
2012-06-20 15:21:16 +08:00
|
|
|
struct cifs_sb_info *cifs_sb, unsigned int xid)
|
2010-07-31 15:15:10 +08:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
int oplock = 0;
|
|
|
|
__u16 netfid = 0;
|
2010-09-30 07:51:11 +08:00
|
|
|
struct tcon_link *tlink;
|
2011-05-27 12:34:02 +08:00
|
|
|
struct cifs_tcon *pTcon;
|
2011-05-26 14:02:00 +08:00
|
|
|
struct cifs_io_parms io_parms;
|
2010-07-31 15:15:10 +08:00
|
|
|
u8 *buf;
|
|
|
|
char *pbuf;
|
|
|
|
unsigned int bytes_read = 0;
|
|
|
|
int buf_type = CIFS_NO_BUFFER;
|
|
|
|
unsigned int link_len = 0;
|
|
|
|
FILE_ALL_INFO file_info;
|
|
|
|
|
|
|
|
if (!CIFSCouldBeMFSymlink(fattr))
|
|
|
|
/* it's not a symlink */
|
|
|
|
return 0;
|
|
|
|
|
2010-09-30 07:51:11 +08:00
|
|
|
tlink = cifs_sb_tlink(cifs_sb);
|
|
|
|
if (IS_ERR(tlink))
|
|
|
|
return PTR_ERR(tlink);
|
|
|
|
pTcon = tlink_tcon(tlink);
|
|
|
|
|
2010-07-31 15:15:10 +08:00
|
|
|
rc = CIFSSMBOpen(xid, pTcon, path, FILE_OPEN, GENERIC_READ,
|
|
|
|
CREATE_NOT_DIR, &netfid, &oplock, &file_info,
|
|
|
|
cifs_sb->local_nls,
|
|
|
|
cifs_sb->mnt_cifs_flags &
|
|
|
|
CIFS_MOUNT_MAP_SPECIAL_CHR);
|
|
|
|
if (rc != 0)
|
2010-09-30 07:51:11 +08:00
|
|
|
goto out;
|
2010-07-31 15:15:10 +08:00
|
|
|
|
2011-03-13 13:08:25 +08:00
|
|
|
if (file_info.EndOfFile != cpu_to_le64(CIFS_MF_SYMLINK_FILE_SIZE)) {
|
2010-07-31 15:15:10 +08:00
|
|
|
CIFSSMBClose(xid, pTcon, netfid);
|
|
|
|
/* it's not a symlink */
|
2010-09-30 07:51:11 +08:00
|
|
|
goto out;
|
2010-07-31 15:15:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
buf = kmalloc(CIFS_MF_SYMLINK_FILE_SIZE, GFP_KERNEL);
|
2010-09-30 07:51:11 +08:00
|
|
|
if (!buf) {
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2010-07-31 15:15:10 +08:00
|
|
|
pbuf = buf;
|
2011-05-26 14:02:00 +08:00
|
|
|
io_parms.netfid = netfid;
|
|
|
|
io_parms.pid = current->tgid;
|
|
|
|
io_parms.tcon = pTcon;
|
|
|
|
io_parms.offset = 0;
|
|
|
|
io_parms.length = CIFS_MF_SYMLINK_FILE_SIZE;
|
2010-07-31 15:15:10 +08:00
|
|
|
|
2011-05-26 14:02:00 +08:00
|
|
|
rc = CIFSSMBRead(xid, &io_parms, &bytes_read, &pbuf, &buf_type);
|
2010-07-31 15:15:10 +08:00
|
|
|
CIFSSMBClose(xid, pTcon, netfid);
|
|
|
|
if (rc != 0) {
|
|
|
|
kfree(buf);
|
2010-09-30 07:51:11 +08:00
|
|
|
goto out;
|
2010-07-31 15:15:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rc = CIFSParseMFSymlink(buf, bytes_read, &link_len, NULL);
|
|
|
|
kfree(buf);
|
2010-09-30 07:51:11 +08:00
|
|
|
if (rc == -EINVAL) {
|
2010-07-31 15:15:10 +08:00
|
|
|
/* it's not a symlink */
|
2010-09-30 07:51:11 +08:00
|
|
|
rc = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-07-31 15:15:10 +08:00
|
|
|
if (rc != 0)
|
2010-09-30 07:51:11 +08:00
|
|
|
goto out;
|
2010-07-31 15:15:10 +08:00
|
|
|
|
|
|
|
/* it is a symlink */
|
|
|
|
fattr->cf_eof = link_len;
|
|
|
|
fattr->cf_mode &= ~S_IFMT;
|
|
|
|
fattr->cf_mode |= S_IFLNK | S_IRWXU | S_IRWXG | S_IRWXO;
|
|
|
|
fattr->cf_dtype = DT_LNK;
|
2010-09-30 07:51:11 +08:00
|
|
|
out:
|
|
|
|
cifs_put_tlink(tlink);
|
|
|
|
return rc;
|
2010-07-31 15:15:10 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
int
|
|
|
|
cifs_hardlink(struct dentry *old_file, struct inode *inode,
|
|
|
|
struct dentry *direntry)
|
|
|
|
{
|
|
|
|
int rc = -EACCES;
|
2012-06-20 15:21:16 +08:00
|
|
|
unsigned int xid;
|
2012-09-19 07:20:31 +08:00
|
|
|
char *from_name = NULL;
|
|
|
|
char *to_name = NULL;
|
2010-09-30 07:51:11 +08:00
|
|
|
struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
|
|
|
|
struct tcon_link *tlink;
|
2012-09-19 07:20:31 +08:00
|
|
|
struct cifs_tcon *tcon;
|
|
|
|
struct TCP_Server_Info *server;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct cifsInodeInfo *cifsInode;
|
|
|
|
|
2010-09-30 07:51:11 +08:00
|
|
|
tlink = cifs_sb_tlink(cifs_sb);
|
|
|
|
if (IS_ERR(tlink))
|
|
|
|
return PTR_ERR(tlink);
|
2012-09-19 07:20:31 +08:00
|
|
|
tcon = tlink_tcon(tlink);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-06-20 15:21:16 +08:00
|
|
|
xid = get_xid();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-09-19 07:20:31 +08:00
|
|
|
from_name = build_path_from_dentry(old_file);
|
|
|
|
to_name = build_path_from_dentry(direntry);
|
|
|
|
if ((from_name == NULL) || (to_name == NULL)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
rc = -ENOMEM;
|
|
|
|
goto cifs_hl_exit;
|
|
|
|
}
|
|
|
|
|
2012-09-19 07:20:31 +08:00
|
|
|
if (tcon->unix_ext)
|
|
|
|
rc = CIFSUnixCreateHardLink(xid, tcon, from_name, to_name,
|
2010-09-30 07:51:11 +08:00
|
|
|
cifs_sb->local_nls,
|
|
|
|
cifs_sb->mnt_cifs_flags &
|
2005-04-29 13:41:06 +08:00
|
|
|
CIFS_MOUNT_MAP_SPECIAL_CHR);
|
2005-04-17 06:20:36 +08:00
|
|
|
else {
|
2012-09-19 07:20:31 +08:00
|
|
|
server = tcon->ses->server;
|
|
|
|
if (!server->ops->create_hardlink)
|
|
|
|
return -ENOSYS;
|
|
|
|
rc = server->ops->create_hardlink(xid, tcon, from_name, to_name,
|
|
|
|
cifs_sb);
|
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 */
|
|
|
|
|
2012-09-19 07:20:31 +08:00
|
|
|
/*
|
|
|
|
* 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) {
|
2012-08-03 21:43:01 +08:00
|
|
|
spin_lock(&old_file->d_inode->i_lock);
|
2011-10-28 20:13:28 +08:00
|
|
|
inc_nlink(old_file->d_inode);
|
2012-08-03 21:43:01 +08:00
|
|
|
spin_unlock(&old_file->d_inode->i_lock);
|
2012-09-19 07:20:31 +08:00
|
|
|
/*
|
|
|
|
* BB should we make this contingent on superblock flag
|
|
|
|
* NOATIME?
|
|
|
|
*/
|
|
|
|
/* old_file->d_inode->i_ctime = CURRENT_TIME; */
|
|
|
|
/*
|
|
|
|
* 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?
|
|
|
|
*/
|
2006-11-17 04:54:20 +08:00
|
|
|
}
|
2012-09-19 07:20:31 +08:00
|
|
|
/*
|
|
|
|
* if not oplocked will force revalidate to get info on source
|
|
|
|
* file from srv
|
|
|
|
*/
|
2006-11-17 04:54:20 +08:00
|
|
|
cifsInode->time = 0;
|
|
|
|
|
2012-09-19 07:20:31 +08:00
|
|
|
/*
|
|
|
|
* Will update parent dir timestamps from srv within a second.
|
|
|
|
* Would it really be worth it to set the parent dir (cifs
|
|
|
|
* inode) time field to zero to force revalidate on parent
|
|
|
|
* directory faster ie
|
|
|
|
*
|
|
|
|
* CIFS_I(inode)->time = 0;
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cifs_hl_exit:
|
2012-09-19 07:20:31 +08:00
|
|
|
kfree(from_name);
|
|
|
|
kfree(to_name);
|
2012-06-20 15:21:16 +08:00
|
|
|
free_xid(xid);
|
2010-09-30 07:51:11 +08:00
|
|
|
cifs_put_tlink(tlink);
|
2005-04-17 06:20:36 +08:00
|
|
|
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;
|
2009-05-19 21:57:03 +08:00
|
|
|
int rc = -ENOMEM;
|
2012-06-20 15:21:16 +08:00
|
|
|
unsigned int xid;
|
2005-04-17 06:20:36 +08:00
|
|
|
char *full_path = NULL;
|
2009-05-19 21:57:03 +08:00
|
|
|
char *target_path = NULL;
|
|
|
|
struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
|
2010-09-30 07:51:11 +08:00
|
|
|
struct tcon_link *tlink = NULL;
|
2011-05-27 12:34:02 +08:00
|
|
|
struct cifs_tcon *tcon;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-06-20 15:21:16 +08:00
|
|
|
xid = get_xid();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-09-30 07:51:11 +08:00
|
|
|
tlink = cifs_sb_tlink(cifs_sb);
|
|
|
|
if (IS_ERR(tlink)) {
|
|
|
|
rc = PTR_ERR(tlink);
|
|
|
|
tlink = NULL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
tcon = tlink_tcon(tlink);
|
|
|
|
|
2009-05-19 21:57:03 +08:00
|
|
|
/*
|
|
|
|
* For now, we just handle symlinks with unix extensions enabled.
|
|
|
|
* Eventually we should handle NTFS reparse points, and MacOS
|
|
|
|
* symlink support. For instance...
|
|
|
|
*
|
|
|
|
* rc = CIFSSMBQueryReparseLinkInfo(...)
|
|
|
|
*
|
|
|
|
* For now, just return -EACCES when the server doesn't support posix
|
|
|
|
* extensions. Note that we still allow querying symlinks when posix
|
|
|
|
* extensions are manually disabled. We could disable these as well
|
|
|
|
* but there doesn't seem to be any harm in allowing the client to
|
|
|
|
* read them.
|
|
|
|
*/
|
2012-07-13 17:58:14 +08:00
|
|
|
if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS) &&
|
|
|
|
!cap_unix(tcon->ses)) {
|
2009-05-19 21:57:03 +08:00
|
|
|
rc = -EACCES;
|
|
|
|
goto out;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-05-19 21:57:03 +08:00
|
|
|
full_path = build_path_from_dentry(direntry);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!full_path)
|
2009-04-30 19:17:56 +08:00
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-04-21 11:50:45 +08:00
|
|
|
cFYI(1, "Full path: %s inode = 0x%p", full_path, inode);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-08-06 03:19:56 +08:00
|
|
|
rc = -EACCES;
|
|
|
|
/*
|
|
|
|
* First try Minshall+French Symlinks, if configured
|
|
|
|
* and fallback to UNIX Extensions Symlinks.
|
|
|
|
*/
|
|
|
|
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS)
|
|
|
|
rc = CIFSQueryMFSymLink(xid, tcon, full_path, &target_path,
|
|
|
|
cifs_sb->local_nls,
|
|
|
|
cifs_sb->mnt_cifs_flags &
|
|
|
|
CIFS_MOUNT_MAP_SPECIAL_CHR);
|
|
|
|
|
2012-07-13 17:58:14 +08:00
|
|
|
if ((rc != 0) && cap_unix(tcon->ses))
|
2010-08-06 03:19:56 +08:00
|
|
|
rc = CIFSSMBUnixQuerySymLink(xid, tcon, full_path, &target_path,
|
|
|
|
cifs_sb->local_nls);
|
|
|
|
|
2009-05-19 21:57:03 +08:00
|
|
|
kfree(full_path);
|
|
|
|
out:
|
2009-04-30 19:17:56 +08:00
|
|
|
if (rc != 0) {
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree(target_path);
|
|
|
|
target_path = ERR_PTR(rc);
|
|
|
|
}
|
|
|
|
|
2012-06-20 15:21:16 +08:00
|
|
|
free_xid(xid);
|
2010-09-30 07:51:11 +08:00
|
|
|
if (tlink)
|
|
|
|
cifs_put_tlink(tlink);
|
2005-04-17 06:20:36 +08:00
|
|
|
nd_set_link(nd, target_path);
|
2009-04-30 19:17:56 +08:00
|
|
|
return NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
cifs_symlink(struct inode *inode, struct dentry *direntry, const char *symname)
|
|
|
|
{
|
|
|
|
int rc = -EOPNOTSUPP;
|
2012-06-20 15:21:16 +08:00
|
|
|
unsigned int xid;
|
2010-09-30 07:51:11 +08:00
|
|
|
struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
|
|
|
|
struct tcon_link *tlink;
|
2011-05-27 12:34:02 +08:00
|
|
|
struct cifs_tcon *pTcon;
|
2005-04-17 06:20:36 +08:00
|
|
|
char *full_path = NULL;
|
|
|
|
struct inode *newinode = NULL;
|
|
|
|
|
2012-06-20 15:21:16 +08:00
|
|
|
xid = get_xid();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-09-30 07:51:11 +08:00
|
|
|
tlink = cifs_sb_tlink(cifs_sb);
|
|
|
|
if (IS_ERR(tlink)) {
|
|
|
|
rc = PTR_ERR(tlink);
|
|
|
|
goto symlink_exit;
|
|
|
|
}
|
|
|
|
pTcon = tlink_tcon(tlink);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-08-31 02:32:14 +08:00
|
|
|
full_path = build_path_from_dentry(direntry);
|
2007-07-10 09:16:18 +08:00
|
|
|
if (full_path == NULL) {
|
2009-06-25 20:42:34 +08:00
|
|
|
rc = -ENOMEM;
|
2010-09-30 07:51:11 +08:00
|
|
|
goto symlink_exit;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-04-21 11:50:45 +08:00
|
|
|
cFYI(1, "Full path: %s", full_path);
|
|
|
|
cFYI(1, "symname is %s", symname);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* BB what if DFS and this volume is on different share? BB */
|
2010-08-06 03:19:56 +08:00
|
|
|
if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS)
|
|
|
|
rc = CIFSCreateMFSymLink(xid, pTcon, full_path, symname,
|
2011-09-26 22:56:44 +08:00
|
|
|
cifs_sb);
|
2010-08-06 03:19:56 +08:00
|
|
|
else if (pTcon->unix_ext)
|
2005-04-17 06:20:36 +08:00
|
|
|
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) {
|
2007-07-19 07:21:09 +08:00
|
|
|
if (pTcon->unix_ext)
|
2005-04-17 06:20:36 +08:00
|
|
|
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,
|
2008-03-15 06:37:16 +08:00
|
|
|
inode->i_sb, xid, NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (rc != 0) {
|
2010-04-21 11:50:45 +08:00
|
|
|
cFYI(1, "Create symlink ok, getinodeinfo fail rc = %d",
|
|
|
|
rc);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
d_instantiate(direntry, newinode);
|
|
|
|
}
|
|
|
|
}
|
2010-09-30 07:51:11 +08:00
|
|
|
symlink_exit:
|
2005-11-07 17:01:34 +08:00
|
|
|
kfree(full_path);
|
2010-09-30 07:51:11 +08:00
|
|
|
cifs_put_tlink(tlink);
|
2012-06-20 15:21:16 +08:00
|
|
|
free_xid(xid);
|
2005-04-17 06:20:36 +08:00
|
|
|
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);
|
|
|
|
}
|