link.c 14.7 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3
/*
 *   fs/cifs/link.c
 *
S
Steve French 已提交
4
 *   Copyright (C) International Business Machines  Corp., 2002,2008
L
Linus Torvalds 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *   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>
23
#include <linux/slab.h>
L
Linus Torvalds 已提交
24 25 26 27 28 29 30
#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"
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

#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]

48 49 50 51 52 53 54 55 56
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);
57
	if (IS_ERR(md5)) {
58
		rc = PTR_ERR(md5);
59
		cERROR(1, "%s: Crypto md5 allocation error %d\n", __func__, rc);
60
		return rc;
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
	}
	size = sizeof(struct shash_desc) + crypto_shash_descsize(md5);
	sdescmd5 = kmalloc(size, GFP_KERNEL);
	if (!sdescmd5) {
		rc = -ENOMEM;
		cERROR(1, "%s: Memory allocation failure\n", __func__);
		goto symlink_hash_err;
	}
	sdescmd5->shash.tfm = md5;
	sdescmd5->shash.flags = 0x0;

	rc = crypto_shash_init(&sdescmd5->shash);
	if (rc) {
		cERROR(1, "%s: Could not init md5 shash\n", __func__);
		goto symlink_hash_err;
	}
77 78 79 80 81
	rc = crypto_shash_update(&sdescmd5->shash, link_str, link_len);
	if (rc) {
		cERROR(1, "%s: Could not update iwth link_str\n", __func__);
		goto symlink_hash_err;
	}
82
	rc = crypto_shash_final(&sdescmd5->shash, md5_hash);
83 84
	if (rc)
		cERROR(1, "%s: Could not generate md5 hash\n", __func__);
85 86 87 88 89 90 91 92

symlink_hash_err:
	crypto_free_shash(md5);
	kfree(sdescmd5);

	return rc;
}

93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
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;

116 117 118 119 120
	rc = symlink_hash(link_len, link_str, md5_hash);
	if (rc) {
		cFYI(1, "%s: MD5 hash failure: %d\n", __func__, rc);
		return rc;
	}
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137

	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;
}
L
Linus Torvalds 已提交
138

139
static int
140 141
CIFSFormatMFSymlink(u8 *buf, unsigned int buf_len, const char *link_str)
{
142
	int rc;
143 144 145 146 147 148 149 150 151 152 153 154
	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;

155 156 157 158 159
	rc = symlink_hash(link_len, link_str, md5_hash);
	if (rc) {
		cFYI(1, "%s: MD5 hash failure: %d\n", __func__, rc);
		return rc;
	}
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182

	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;
}

183
static int
184
CIFSCreateMFSymLink(const int xid, struct cifs_tcon *tcon,
185
		    const char *fromName, const char *toName,
186
		    struct cifs_sb_info *cifs_sb)
187 188 189
{
	int rc;
	int oplock = 0;
190 191
	int remap;
	int create_options = CREATE_NOT_DIR;
192 193 194
	__u16 netfid = 0;
	u8 *buf;
	unsigned int bytes_written = 0;
195
	struct cifs_io_parms io_parms;
196 197 198 199
	struct nls_table *nls_codepage;

	nls_codepage = cifs_sb->local_nls;
	remap = cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MAP_SPECIAL_CHR;
200 201 202 203 204 205 206 207 208 209 210

	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;
	}

211 212 213
	if (backup_cred(cifs_sb))
		create_options |= CREATE_OPEN_BACKUP_INTENT;

214
	rc = CIFSSMBOpen(xid, tcon, fromName, FILE_CREATE, GENERIC_WRITE,
215
			 create_options, &netfid, &oplock, NULL,
216 217 218 219 220 221
			 nls_codepage, remap);
	if (rc != 0) {
		kfree(buf);
		return rc;
	}

222 223 224 225 226 227 228
	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);
229 230 231 232 233 234 235 236 237 238 239 240
	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
241
CIFSQueryMFSymLink(const int xid, struct cifs_tcon *tcon,
242 243 244 245 246 247 248 249 250 251 252
		   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;
253
	struct cifs_io_parms io_parms;
254 255 256 257 258 259 260 261
	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;

S
Steve French 已提交
262
	if (file_info.EndOfFile != cpu_to_le64(CIFS_MF_SYMLINK_FILE_SIZE)) {
263 264 265 266 267 268 269 270 271
		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;
272 273 274 275 276
	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;
277

278
	rc = CIFSSMBRead(xid, &io_parms, &bytes_read, &pbuf, &buf_type);
279 280 281 282 283 284 285 286 287 288 289 290 291 292
	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;
}

293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314
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,
		   struct cifs_sb_info *cifs_sb, int xid)
{
	int rc;
	int oplock = 0;
	__u16 netfid = 0;
315
	struct tcon_link *tlink;
316
	struct cifs_tcon *pTcon;
317
	struct cifs_io_parms io_parms;
318 319 320 321 322 323 324 325 326 327 328
	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;

329 330 331 332 333
	tlink = cifs_sb_tlink(cifs_sb);
	if (IS_ERR(tlink))
		return PTR_ERR(tlink);
	pTcon = tlink_tcon(tlink);

334 335 336 337 338 339
	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)
340
		goto out;
341

S
Steve French 已提交
342
	if (file_info.EndOfFile != cpu_to_le64(CIFS_MF_SYMLINK_FILE_SIZE)) {
343 344
		CIFSSMBClose(xid, pTcon, netfid);
		/* it's not a symlink */
345
		goto out;
346 347 348
	}

	buf = kmalloc(CIFS_MF_SYMLINK_FILE_SIZE, GFP_KERNEL);
349 350 351 352
	if (!buf) {
		rc = -ENOMEM;
		goto out;
	}
353
	pbuf = buf;
354 355 356 357 358
	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;
359

360
	rc = CIFSSMBRead(xid, &io_parms, &bytes_read, &pbuf, &buf_type);
361 362 363
	CIFSSMBClose(xid, pTcon, netfid);
	if (rc != 0) {
		kfree(buf);
364
		goto out;
365 366 367 368
	}

	rc = CIFSParseMFSymlink(buf, bytes_read, &link_len, NULL);
	kfree(buf);
369
	if (rc == -EINVAL) {
370
		/* it's not a symlink */
371 372 373 374
		rc = 0;
		goto out;
	}

375
	if (rc != 0)
376
		goto out;
377 378 379 380 381 382

	/* 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;
383 384 385
out:
	cifs_put_tlink(tlink);
	return rc;
386 387
}

L
Linus Torvalds 已提交
388 389 390 391 392 393 394 395
int
cifs_hardlink(struct dentry *old_file, struct inode *inode,
	      struct dentry *direntry)
{
	int rc = -EACCES;
	int xid;
	char *fromName = NULL;
	char *toName = NULL;
396 397
	struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
	struct tcon_link *tlink;
398
	struct cifs_tcon *pTcon;
L
Linus Torvalds 已提交
399 400
	struct cifsInodeInfo *cifsInode;

401 402 403 404
	tlink = cifs_sb_tlink(cifs_sb);
	if (IS_ERR(tlink))
		return PTR_ERR(tlink);
	pTcon = tlink_tcon(tlink);
L
Linus Torvalds 已提交
405

406
	xid = GetXid();
L
Linus Torvalds 已提交
407

408 409
	fromName = build_path_from_dentry(old_file);
	toName = build_path_from_dentry(direntry);
S
Steve French 已提交
410
	if ((fromName == NULL) || (toName == NULL)) {
L
Linus Torvalds 已提交
411 412 413 414
		rc = -ENOMEM;
		goto cifs_hl_exit;
	}

415
	if (pTcon->unix_ext)
L
Linus Torvalds 已提交
416
		rc = CIFSUnixCreateHardLink(xid, pTcon, fromName, toName,
417 418
					    cifs_sb->local_nls,
					    cifs_sb->mnt_cifs_flags &
419
						CIFS_MOUNT_MAP_SPECIAL_CHR);
L
Linus Torvalds 已提交
420 421
	else {
		rc = CIFSCreateHardLink(xid, pTcon, fromName, toName,
422 423
					cifs_sb->local_nls,
					cifs_sb->mnt_cifs_flags &
424
						CIFS_MOUNT_MAP_SPECIAL_CHR);
S
Steve French 已提交
425 426
		if ((rc == -EIO) || (rc == -EINVAL))
			rc = -EOPNOTSUPP;
L
Linus Torvalds 已提交
427 428
	}

429 430 431 432
	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 */
S
Steve French 已提交
433
	if (old_file->d_inode) {
434
		cifsInode = CIFS_I(old_file->d_inode);
S
Steve French 已提交
435
		if (rc == 0) {
436
			old_file->d_inode->i_nlink++;
437 438
/* BB should we make this contingent on superblock flag NOATIME? */
/*			old_file->d_inode->i_ctime = CURRENT_TIME;*/
439 440 441 442 443
			/* 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? */
		}
S
Steve French 已提交
444
		/* if not oplocked will force revalidate to get info
445 446 447
		   on source file from srv */
		cifsInode->time = 0;

S
Steve French 已提交
448
		/* Will update parent dir timestamps from srv within a second.
449 450
		   Would it really be worth it to set the parent dir (cifs
		   inode) time field to zero to force revalidate on parent
S
Steve French 已提交
451
		   directory faster ie
452
			CIFS_I(inode)->time = 0;  */
L
Linus Torvalds 已提交
453 454 455
	}

cifs_hl_exit:
J
Jesper Juhl 已提交
456 457
	kfree(fromName);
	kfree(toName);
L
Linus Torvalds 已提交
458
	FreeXid(xid);
459
	cifs_put_tlink(tlink);
L
Linus Torvalds 已提交
460 461 462
	return rc;
}

463
void *
L
Linus Torvalds 已提交
464 465 466
cifs_follow_link(struct dentry *direntry, struct nameidata *nd)
{
	struct inode *inode = direntry->d_inode;
467
	int rc = -ENOMEM;
L
Linus Torvalds 已提交
468 469
	int xid;
	char *full_path = NULL;
470 471
	char *target_path = NULL;
	struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
472
	struct tcon_link *tlink = NULL;
473
	struct cifs_tcon *tcon;
L
Linus Torvalds 已提交
474 475 476

	xid = GetXid();

477 478 479 480 481 482 483 484
	tlink = cifs_sb_tlink(cifs_sb);
	if (IS_ERR(tlink)) {
		rc = PTR_ERR(tlink);
		tlink = NULL;
		goto out;
	}
	tcon = tlink_tcon(tlink);

485 486 487 488 489 490 491 492 493 494 495 496 497
	/*
	 * 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.
	 */
498 499
	if (!(cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS)
	    && !(tcon->ses->capabilities & CAP_UNIX)) {
500 501 502
		rc = -EACCES;
		goto out;
	}
L
Linus Torvalds 已提交
503

504
	full_path = build_path_from_dentry(direntry);
L
Linus Torvalds 已提交
505
	if (!full_path)
506
		goto out;
L
Linus Torvalds 已提交
507

508
	cFYI(1, "Full path: %s inode = 0x%p", full_path, inode);
L
Linus Torvalds 已提交
509

510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
	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);

	if ((rc != 0) && (tcon->ses->capabilities & CAP_UNIX))
		rc = CIFSSMBUnixQuerySymLink(xid, tcon, full_path, &target_path,
					     cifs_sb->local_nls);

525 526
	kfree(full_path);
out:
527
	if (rc != 0) {
L
Linus Torvalds 已提交
528 529 530 531 532
		kfree(target_path);
		target_path = ERR_PTR(rc);
	}

	FreeXid(xid);
533 534
	if (tlink)
		cifs_put_tlink(tlink);
L
Linus Torvalds 已提交
535
	nd_set_link(nd, target_path);
536
	return NULL;
L
Linus Torvalds 已提交
537 538 539 540 541 542 543
}

int
cifs_symlink(struct inode *inode, struct dentry *direntry, const char *symname)
{
	int rc = -EOPNOTSUPP;
	int xid;
544 545
	struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
	struct tcon_link *tlink;
546
	struct cifs_tcon *pTcon;
L
Linus Torvalds 已提交
547 548 549 550 551
	char *full_path = NULL;
	struct inode *newinode = NULL;

	xid = GetXid();

552 553 554 555 556 557
	tlink = cifs_sb_tlink(cifs_sb);
	if (IS_ERR(tlink)) {
		rc = PTR_ERR(tlink);
		goto symlink_exit;
	}
	pTcon = tlink_tcon(tlink);
L
Linus Torvalds 已提交
558

559
	full_path = build_path_from_dentry(direntry);
S
Steve French 已提交
560
	if (full_path == NULL) {
561
		rc = -ENOMEM;
562
		goto symlink_exit;
L
Linus Torvalds 已提交
563 564
	}

565 566
	cFYI(1, "Full path: %s", full_path);
	cFYI(1, "symname is %s", symname);
L
Linus Torvalds 已提交
567 568

	/* BB what if DFS and this volume is on different share? BB */
569 570
	if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS)
		rc = CIFSCreateMFSymLink(xid, pTcon, full_path, symname,
571
					cifs_sb);
572
	else if (pTcon->unix_ext)
L
Linus Torvalds 已提交
573 574 575
		rc = CIFSUnixCreateSymLink(xid, pTcon, full_path, symname,
					   cifs_sb->local_nls);
	/* else
S
Steve French 已提交
576 577
	   rc = CIFSCreateReparseSymLink(xid, pTcon, fromName, toName,
					cifs_sb_target->local_nls); */
L
Linus Torvalds 已提交
578 579

	if (rc == 0) {
580
		if (pTcon->unix_ext)
L
Linus Torvalds 已提交
581
			rc = cifs_get_inode_info_unix(&newinode, full_path,
S
Steve French 已提交
582
						      inode->i_sb, xid);
L
Linus Torvalds 已提交
583 584
		else
			rc = cifs_get_inode_info(&newinode, full_path, NULL,
585
						 inode->i_sb, xid, NULL);
L
Linus Torvalds 已提交
586 587

		if (rc != 0) {
588 589
			cFYI(1, "Create symlink ok, getinodeinfo fail rc = %d",
			      rc);
L
Linus Torvalds 已提交
590 591 592 593
		} else {
			d_instantiate(direntry, newinode);
		}
	}
594
symlink_exit:
J
Jesper Juhl 已提交
595
	kfree(full_path);
596
	cifs_put_tlink(tlink);
L
Linus Torvalds 已提交
597 598 599 600
	FreeXid(xid);
	return rc;
}

601
void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
L
Linus Torvalds 已提交
602 603 604 605 606
{
	char *p = nd_get_link(nd);
	if (!IS_ERR(p))
		kfree(p);
}