2005-04-17 02:20:36 +04:00
/*
* fs / cifs / link . c
*
2008-01-25 13:12:41 +03:00
* Copyright ( C ) International Business Machines Corp . , 2002 , 2008
2005-04-17 02:20:36 +04: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 11:04:11 +03:00
# include <linux/slab.h>
2005-04-17 02:20:36 +04: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"
2014-09-27 11:19:01 +04:00
# include "cifs_unicode.h"
2014-09-15 13:49:28 +04:00
# include "smb2proto.h"
2010-07-31 11:14:16 +04:00
2013-11-25 21:09:53 +04:00
/*
* M - F Symlink Functions - Begin
*/
2010-07-31 11:14:16 +04: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"
2016-12-01 01:40:32 +03:00
# define CIFS_MF_SYMLINK_MD5_FORMAT "%16phN\n"
# define CIFS_MF_SYMLINK_MD5_ARGS(md5_hash) md5_hash
2010-07-31 11:14:16 +04:00
2011-01-25 22:28:43 +03:00
static int
symlink_hash ( unsigned int link_len , const char * link_str , u8 * md5_hash )
{
int rc ;
2018-02-16 21:19:27 +03:00
struct crypto_shash * md5 = NULL ;
struct sdesc * sdescmd5 = NULL ;
2011-01-25 22:28:43 +03:00
2018-02-16 21:19:27 +03:00
rc = cifs_alloc_hash ( " md5 " , & md5 , & sdescmd5 ) ;
if ( rc )
2011-01-25 22:28:43 +03:00
goto symlink_hash_err ;
rc = crypto_shash_init ( & sdescmd5 - > shash ) ;
if ( rc ) {
2013-05-05 07:12:25 +04:00
cifs_dbg ( VFS , " %s: Could not init md5 shash \n " , __func__ ) ;
2011-01-25 22:28:43 +03:00
goto symlink_hash_err ;
}
2011-06-21 01:14:03 +04:00
rc = crypto_shash_update ( & sdescmd5 - > shash , link_str , link_len ) ;
if ( rc ) {
2013-05-05 07:12:25 +04:00
cifs_dbg ( VFS , " %s: Could not update with link_str \n " , __func__ ) ;
2011-06-21 01:14:03 +04:00
goto symlink_hash_err ;
}
2011-01-25 22:28:43 +03:00
rc = crypto_shash_final ( & sdescmd5 - > shash , md5_hash ) ;
2011-06-21 01:14:03 +04:00
if ( rc )
2013-05-05 07:12:25 +04:00
cifs_dbg ( VFS , " %s: Could not generate md5 hash \n " , __func__ ) ;
2011-01-25 22:28:43 +03:00
symlink_hash_err :
2018-02-16 21:19:27 +03:00
cifs_free_hash ( & md5 , & sdescmd5 ) ;
2011-01-25 22:28:43 +03:00
return rc ;
}
2010-07-31 11:14:16 +04:00
static int
2013-11-25 21:09:50 +04:00
parse_mf_symlink ( const u8 * buf , unsigned int buf_len , unsigned int * _link_len ,
char * * _link_str )
2010-07-31 11:14:16 +04:00
{
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-25 22:28:43 +03:00
rc = symlink_hash ( link_len , link_str , md5_hash ) ;
if ( rc ) {
2013-05-05 07:12:25 +04:00
cifs_dbg ( FYI , " %s: MD5 hash failure: %d \n " , __func__ , rc ) ;
2011-01-25 22:28:43 +03:00
return rc ;
}
2010-07-31 11:14:16 +04:00
2019-02-09 02:51:11 +03:00
scnprintf ( md5_str2 , sizeof ( md5_str2 ) ,
CIFS_MF_SYMLINK_MD5_FORMAT ,
CIFS_MF_SYMLINK_MD5_ARGS ( md5_hash ) ) ;
2010-07-31 11:14:16 +04:00
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 02:20:36 +04:00
2010-08-05 23:13:44 +04:00
static int
2013-11-25 21:09:50 +04:00
format_mf_symlink ( u8 * buf , unsigned int buf_len , const char * link_str )
2010-08-03 13:24:22 +04:00
{
2011-01-25 22:28:43 +03:00
int rc ;
2010-08-03 13:24:22 +04: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-25 22:28:43 +03:00
rc = symlink_hash ( link_len , link_str , md5_hash ) ;
if ( rc ) {
2013-05-05 07:12:25 +04:00
cifs_dbg ( FYI , " %s: MD5 hash failure: %d \n " , __func__ , rc ) ;
2011-01-25 22:28:43 +03:00
return rc ;
}
2010-08-03 13:24:22 +04:00
2019-02-09 02:51:11 +03:00
scnprintf ( buf , buf_len ,
CIFS_MF_SYMLINK_LEN_FORMAT CIFS_MF_SYMLINK_MD5_FORMAT ,
link_len ,
CIFS_MF_SYMLINK_MD5_ARGS ( md5_hash ) ) ;
2010-08-03 13:24:22 +04:00
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 ;
}
2013-11-25 21:09:53 +04:00
bool
couldbe_mf_symlink ( const struct cifs_fattr * fattr )
{
2014-01-31 18:27:16 +04:00
if ( ! S_ISREG ( fattr - > cf_mode ) )
2013-11-25 21:09:53 +04:00
/* 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 ;
}
2010-08-05 23:15:22 +04:00
static int
2013-11-25 21:09:50 +04:00
create_mf_symlink ( const unsigned int xid , struct cifs_tcon * tcon ,
2013-11-25 21:09:52 +04:00
struct cifs_sb_info * cifs_sb , const char * fromName ,
const char * toName )
2010-08-05 23:15:22 +04:00
{
int rc ;
u8 * buf ;
unsigned int bytes_written = 0 ;
buf = kmalloc ( CIFS_MF_SYMLINK_FILE_SIZE , GFP_KERNEL ) ;
if ( ! buf )
return - ENOMEM ;
2013-11-25 21:09:50 +04:00
rc = format_mf_symlink ( buf , CIFS_MF_SYMLINK_FILE_SIZE , toName ) ;
2013-11-25 21:09:52 +04:00
if ( rc )
goto out ;
2011-05-26 10:01:59 +04:00
2014-09-15 08:27:09 +04:00
if ( tcon - > ses - > server - > ops - > create_mf_symlink )
rc = tcon - > ses - > server - > ops - > create_mf_symlink ( xid , tcon ,
cifs_sb , fromName , buf , & bytes_written ) ;
else
rc = - EOPNOTSUPP ;
2013-11-25 21:09:52 +04:00
if ( rc )
goto out ;
2010-08-05 23:15:22 +04:00
if ( bytes_written ! = CIFS_MF_SYMLINK_FILE_SIZE )
2013-11-25 21:09:52 +04:00
rc = - EIO ;
out :
kfree ( buf ) ;
return rc ;
2010-08-05 23:15:22 +04:00
}
static int
2013-11-25 21:09:50 +04:00
query_mf_symlink ( const unsigned int xid , struct cifs_tcon * tcon ,
2013-11-25 21:09:51 +04:00
struct cifs_sb_info * cifs_sb , const unsigned char * path ,
char * * symlinkinfo )
2010-08-05 23:13:44 +04:00
{
int rc ;
2013-11-25 21:09:51 +04:00
u8 * buf = NULL ;
2010-08-05 23:13:44 +04:00
unsigned int link_len = 0 ;
2013-11-25 21:09:51 +04:00
unsigned int bytes_read = 0 ;
2010-08-05 23:13:44 +04:00
buf = kmalloc ( CIFS_MF_SYMLINK_FILE_SIZE , GFP_KERNEL ) ;
if ( ! buf )
return - ENOMEM ;
2013-11-25 21:09:51 +04:00
if ( tcon - > ses - > server - > ops - > query_mf_symlink )
rc = tcon - > ses - > server - > ops - > query_mf_symlink ( xid , tcon ,
cifs_sb , path , buf , & bytes_read ) ;
else
rc = - ENOSYS ;
if ( rc )
goto out ;
if ( bytes_read = = 0 ) { /* not a symlink */
rc = - EINVAL ;
goto out ;
2010-08-05 23:13:44 +04:00
}
2013-11-25 21:09:50 +04:00
rc = parse_mf_symlink ( buf , bytes_read , & link_len , symlinkinfo ) ;
2013-11-25 21:09:51 +04:00
out :
2010-08-05 23:13:44 +04:00
kfree ( buf ) ;
2013-11-25 21:09:51 +04:00
return rc ;
2010-08-05 23:13:44 +04:00
}
2013-11-25 21:09:53 +04:00
int
check_mf_symlink ( unsigned int xid , struct cifs_tcon * tcon ,
struct cifs_sb_info * cifs_sb , struct cifs_fattr * fattr ,
const unsigned char * path )
2010-07-31 11:15:10 +04:00
{
2013-11-25 21:09:53 +04:00
int rc ;
u8 * buf = NULL ;
unsigned int link_len = 0 ;
unsigned int bytes_read = 0 ;
if ( ! couldbe_mf_symlink ( fattr ) )
2010-07-31 11:15:10 +04:00
/* it's not a symlink */
2013-11-25 21:09:53 +04:00
return 0 ;
2010-07-31 11:15:10 +04:00
2013-11-25 21:09:53 +04:00
buf = kmalloc ( CIFS_MF_SYMLINK_FILE_SIZE , GFP_KERNEL ) ;
if ( ! buf )
return - ENOMEM ;
if ( tcon - > ses - > server - > ops - > query_mf_symlink )
rc = tcon - > ses - > server - > ops - > query_mf_symlink ( xid , tcon ,
cifs_sb , path , buf , & bytes_read ) ;
else
rc = - ENOSYS ;
if ( rc )
goto out ;
if ( bytes_read = = 0 ) /* not a symlink */
goto out ;
rc = parse_mf_symlink ( buf , bytes_read , & link_len , NULL ) ;
if ( rc = = - EINVAL ) {
2010-07-31 11:15:10 +04:00
/* it's not a symlink */
2013-11-25 21:09:53 +04:00
rc = 0 ;
goto out ;
}
2010-07-31 11:15:10 +04:00
2013-11-25 21:09:53 +04:00
if ( rc ! = 0 )
goto out ;
/* 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 ;
out :
kfree ( buf ) ;
return rc ;
2010-07-31 11:15:10 +04:00
}
2013-11-25 21:09:53 +04:00
/*
* SMB 1.0 Protocol specific functions
*/
2010-07-31 11:15:10 +04:00
int
2013-11-25 21:09:49 +04:00
cifs_query_mf_symlink ( unsigned int xid , struct cifs_tcon * tcon ,
struct cifs_sb_info * cifs_sb , const unsigned char * path ,
char * pbuf , unsigned int * pbytes_read )
2010-07-31 11:15:10 +04:00
{
int rc ;
int oplock = 0 ;
2014-01-16 15:53:36 +04:00
struct cifs_fid fid ;
struct cifs_open_parms oparms ;
2020-06-04 18:23:55 +03:00
struct cifs_io_parms io_parms = { 0 } ;
2010-07-31 11:15:10 +04:00
int buf_type = CIFS_NO_BUFFER ;
FILE_ALL_INFO file_info ;
2014-01-16 15:53:36 +04:00
oparms . tcon = tcon ;
oparms . cifs_sb = cifs_sb ;
oparms . desired_access = GENERIC_READ ;
2020-02-03 22:46:43 +03:00
oparms . create_options = cifs_create_options ( cifs_sb , CREATE_NOT_DIR ) ;
2014-01-16 15:53:36 +04:00
oparms . disposition = FILE_OPEN ;
oparms . path = path ;
oparms . fid = & fid ;
oparms . reconnect = false ;
rc = CIFS_open ( xid , & oparms , & oplock , & file_info ) ;
2013-11-25 21:09:49 +04:00
if ( rc )
2013-07-12 04:17:40 +04:00
return rc ;
2010-07-31 11:15:10 +04:00
2014-09-16 15:40:25 +04:00
if ( file_info . EndOfFile ! = cpu_to_le64 ( CIFS_MF_SYMLINK_FILE_SIZE ) ) {
rc = - ENOENT ;
2010-07-31 11:15:10 +04:00
/* it's not a symlink */
2013-11-25 21:09:49 +04:00
goto out ;
2014-09-16 15:40:25 +04:00
}
2010-07-31 11:15:10 +04:00
2014-01-16 15:53:36 +04:00
io_parms . netfid = fid . netfid ;
2011-05-26 10:02:00 +04:00
io_parms . pid = current - > tgid ;
2013-11-25 21:09:49 +04:00
io_parms . tcon = tcon ;
2011-05-26 10:02:00 +04:00
io_parms . offset = 0 ;
io_parms . length = CIFS_MF_SYMLINK_FILE_SIZE ;
2010-07-31 11:15:10 +04:00
2013-07-12 04:17:40 +04:00
rc = CIFSSMBRead ( xid , & io_parms , pbytes_read , & pbuf , & buf_type ) ;
2013-11-25 21:09:49 +04:00
out :
2014-01-16 15:53:36 +04:00
CIFSSMBClose ( xid , tcon , fid . netfid ) ;
2013-07-12 04:17:40 +04:00
return rc ;
}
2013-11-25 21:09:52 +04:00
int
cifs_create_mf_symlink ( unsigned int xid , struct cifs_tcon * tcon ,
struct cifs_sb_info * cifs_sb , const unsigned char * path ,
char * pbuf , unsigned int * pbytes_written )
{
int rc ;
int oplock = 0 ;
2014-01-16 15:53:36 +04:00
struct cifs_fid fid ;
struct cifs_open_parms oparms ;
2020-06-04 18:23:55 +03:00
struct cifs_io_parms io_parms = { 0 } ;
2013-11-25 21:09:52 +04:00
2014-01-16 15:53:36 +04:00
oparms . tcon = tcon ;
oparms . cifs_sb = cifs_sb ;
oparms . desired_access = GENERIC_WRITE ;
2020-02-03 22:46:43 +03:00
oparms . create_options = cifs_create_options ( cifs_sb , CREATE_NOT_DIR ) ;
2014-06-10 14:03:26 +04:00
oparms . disposition = FILE_CREATE ;
2014-01-16 15:53:36 +04:00
oparms . path = path ;
oparms . fid = & fid ;
oparms . reconnect = false ;
rc = CIFS_open ( xid , & oparms , & oplock , NULL ) ;
2013-11-25 21:09:52 +04:00
if ( rc )
return rc ;
2014-01-16 15:53:36 +04:00
io_parms . netfid = fid . netfid ;
2013-11-25 21:09:52 +04:00
io_parms . pid = current - > tgid ;
io_parms . tcon = tcon ;
io_parms . offset = 0 ;
io_parms . length = CIFS_MF_SYMLINK_FILE_SIZE ;
2016-09-06 00:53:43 +03:00
rc = CIFSSMBWrite ( xid , & io_parms , pbytes_written , pbuf ) ;
2014-01-16 15:53:36 +04:00
CIFSSMBClose ( xid , tcon , fid . netfid ) ;
2013-11-25 21:09:52 +04:00
return rc ;
}
2014-09-16 16:18:19 +04:00
/*
* SMB 2.1 / SMB3 Protocol specific functions
*/
int
smb3_query_mf_symlink ( unsigned int xid , struct cifs_tcon * tcon ,
struct cifs_sb_info * cifs_sb , const unsigned char * path ,
char * pbuf , unsigned int * pbytes_read )
{
int rc ;
struct cifs_fid fid ;
struct cifs_open_parms oparms ;
2020-06-04 18:23:55 +03:00
struct cifs_io_parms io_parms = { 0 } ;
2014-09-16 16:18:19 +04:00
int buf_type = CIFS_NO_BUFFER ;
__le16 * utf16_path ;
2018-07-28 06:01:49 +03:00
__u8 oplock = SMB2_OPLOCK_LEVEL_NONE ;
2014-09-16 16:18:19 +04:00
struct smb2_file_all_info * pfile_info = NULL ;
oparms . tcon = tcon ;
oparms . cifs_sb = cifs_sb ;
oparms . desired_access = GENERIC_READ ;
2020-02-03 22:46:43 +03:00
oparms . create_options = cifs_create_options ( cifs_sb , CREATE_NOT_DIR ) ;
2014-09-16 16:18:19 +04:00
oparms . disposition = FILE_OPEN ;
oparms . fid = & fid ;
oparms . reconnect = false ;
utf16_path = cifs_convert_path_to_utf16 ( path , cifs_sb ) ;
if ( utf16_path = = NULL )
return - ENOMEM ;
pfile_info = kzalloc ( sizeof ( struct smb2_file_all_info ) + PATH_MAX * 2 ,
GFP_KERNEL ) ;
if ( pfile_info = = NULL ) {
kfree ( utf16_path ) ;
return - ENOMEM ;
}
2018-06-08 06:21:18 +03:00
rc = SMB2_open ( xid , & oparms , utf16_path , & oplock , pfile_info , NULL ,
2020-03-02 19:53:22 +03:00
NULL , NULL ) ;
2014-09-16 16:18:19 +04:00
if ( rc )
goto qmf_out_open_fail ;
if ( pfile_info - > EndOfFile ! = cpu_to_le64 ( CIFS_MF_SYMLINK_FILE_SIZE ) ) {
/* it's not a symlink */
rc = - ENOENT ; /* Is there a better rc to return? */
goto qmf_out ;
}
io_parms . netfid = fid . netfid ;
io_parms . pid = current - > tgid ;
io_parms . tcon = tcon ;
io_parms . offset = 0 ;
io_parms . length = CIFS_MF_SYMLINK_FILE_SIZE ;
io_parms . persistent_fid = fid . persistent_fid ;
io_parms . volatile_fid = fid . volatile_fid ;
rc = SMB2_read ( xid , & io_parms , pbytes_read , & pbuf , & buf_type ) ;
qmf_out :
SMB2_close ( xid , tcon , fid . persistent_fid , fid . volatile_fid ) ;
qmf_out_open_fail :
kfree ( utf16_path ) ;
kfree ( pfile_info ) ;
return rc ;
}
2014-09-15 13:49:28 +04:00
int
smb3_create_mf_symlink ( unsigned int xid , struct cifs_tcon * tcon ,
struct cifs_sb_info * cifs_sb , const unsigned char * path ,
char * pbuf , unsigned int * pbytes_written )
{
int rc ;
struct cifs_fid fid ;
struct cifs_open_parms oparms ;
2020-05-31 20:38:22 +03:00
struct cifs_io_parms io_parms = { 0 } ;
2014-09-15 13:49:28 +04:00
__le16 * utf16_path ;
2018-07-28 06:01:49 +03:00
__u8 oplock = SMB2_OPLOCK_LEVEL_NONE ;
2014-09-15 13:49:28 +04:00
struct kvec iov [ 2 ] ;
cifs_dbg ( FYI , " %s: path: %s \n " , __func__ , path ) ;
utf16_path = cifs_convert_path_to_utf16 ( path , cifs_sb ) ;
if ( ! utf16_path )
return - ENOMEM ;
oparms . tcon = tcon ;
oparms . cifs_sb = cifs_sb ;
oparms . desired_access = GENERIC_WRITE ;
2020-02-03 22:46:43 +03:00
oparms . create_options = cifs_create_options ( cifs_sb , CREATE_NOT_DIR ) ;
2014-09-15 13:49:28 +04:00
oparms . disposition = FILE_CREATE ;
oparms . fid = & fid ;
oparms . reconnect = false ;
2018-06-08 06:21:18 +03:00
rc = SMB2_open ( xid , & oparms , utf16_path , & oplock , NULL , NULL ,
2020-03-02 19:53:22 +03:00
NULL , NULL ) ;
2014-09-15 13:49:28 +04:00
if ( rc ) {
kfree ( utf16_path ) ;
return rc ;
}
io_parms . netfid = fid . netfid ;
io_parms . pid = current - > tgid ;
io_parms . tcon = tcon ;
io_parms . offset = 0 ;
io_parms . length = CIFS_MF_SYMLINK_FILE_SIZE ;
io_parms . persistent_fid = fid . persistent_fid ;
io_parms . volatile_fid = fid . volatile_fid ;
/* iov[0] is reserved for smb header */
iov [ 1 ] . iov_base = pbuf ;
iov [ 1 ] . iov_len = CIFS_MF_SYMLINK_FILE_SIZE ;
rc = SMB2_write ( xid , & io_parms , pbytes_written , iov , 1 ) ;
/* Make sure we wrote all of the symlink data */
if ( ( rc = = 0 ) & & ( * pbytes_written ! = CIFS_MF_SYMLINK_FILE_SIZE ) )
rc = - EIO ;
SMB2_close ( xid , tcon , fid . persistent_fid , fid . volatile_fid ) ;
kfree ( utf16_path ) ;
return rc ;
}
2013-11-25 21:09:53 +04:00
/*
* M - F Symlink Functions - End
*/
2010-07-31 11:15:10 +04:00
2005-04-17 02:20:36 +04:00
int
cifs_hardlink ( struct dentry * old_file , struct inode * inode ,
struct dentry * direntry )
{
int rc = - EACCES ;
2012-06-20 11:21:16 +04:00
unsigned int xid ;
2012-09-19 03:20:31 +04:00
char * from_name = NULL ;
char * to_name = NULL ;
2010-09-30 03:51:11 +04:00
struct cifs_sb_info * cifs_sb = CIFS_SB ( inode - > i_sb ) ;
struct tcon_link * tlink ;
2012-09-19 03:20:31 +04:00
struct cifs_tcon * tcon ;
struct TCP_Server_Info * server ;
2005-04-17 02:20:36 +04:00
struct cifsInodeInfo * cifsInode ;
2010-09-30 03:51:11 +04:00
tlink = cifs_sb_tlink ( cifs_sb ) ;
if ( IS_ERR ( tlink ) )
return PTR_ERR ( tlink ) ;
2012-09-19 03:20:31 +04:00
tcon = tlink_tcon ( tlink ) ;
2005-04-17 02:20:36 +04:00
2012-06-20 11:21:16 +04:00
xid = get_xid ( ) ;
2005-04-17 02:20:36 +04:00
2012-09-19 03:20:31 +04: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 02:20:36 +04:00
rc = - ENOMEM ;
goto cifs_hl_exit ;
}
2012-09-19 03:20:31 +04:00
if ( tcon - > unix_ext )
rc = CIFSUnixCreateHardLink ( xid , tcon , from_name , to_name ,
2010-09-30 03:51:11 +04:00
cifs_sb - > local_nls ,
2014-09-27 11:19:01 +04:00
cifs_remap ( cifs_sb ) ) ;
2005-04-17 02:20:36 +04:00
else {
2012-09-19 03:20:31 +04:00
server = tcon - > ses - > server ;
2014-01-11 04:57:22 +04:00
if ( ! server - > ops - > create_hardlink ) {
rc = - ENOSYS ;
goto cifs_hl_exit ;
}
2012-09-19 03:20:31 +04:00
rc = server - > ops - > create_hardlink ( xid , tcon , from_name , to_name ,
cifs_sb ) ;
2007-07-10 05:16:18 +04:00
if ( ( rc = = - EIO ) | | ( rc = = - EINVAL ) )
rc = - EOPNOTSUPP ;
2005-04-17 02:20:36 +04:00
}
2006-11-16 23:54:20 +03:00
d_drop ( direntry ) ; /* force new lookup from server of target */
2012-09-19 03:20:31 +04: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
*/
2015-03-18 01:25:59 +03:00
if ( d_really_is_positive ( old_file ) ) {
cifsInode = CIFS_I ( d_inode ( old_file ) ) ;
2007-07-10 05:16:18 +04:00
if ( rc = = 0 ) {
2015-03-18 01:25:59 +03:00
spin_lock ( & d_inode ( old_file ) - > i_lock ) ;
inc_nlink ( d_inode ( old_file ) ) ;
spin_unlock ( & d_inode ( old_file ) - > i_lock ) ;
2014-10-18 02:17:12 +04:00
2012-09-19 03:20:31 +04: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 ?
*/
2006-11-16 23:54:20 +03:00
}
2012-09-19 03:20:31 +04:00
/*
* if not oplocked will force revalidate to get info on source
2014-10-18 02:17:12 +04:00
* file from srv . Note Samba server prior to 4.2 has bug -
* not updating src file ctime on hardlinks but Windows servers
* handle it properly
2012-09-19 03:20:31 +04:00
*/
2006-11-16 23:54:20 +03:00
cifsInode - > time = 0 ;
2012-09-19 03:20:31 +04: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 02:20:36 +04:00
}
cifs_hl_exit :
2012-09-19 03:20:31 +04:00
kfree ( from_name ) ;
kfree ( to_name ) ;
2012-06-20 11:21:16 +04:00
free_xid ( xid ) ;
2010-09-30 03:51:11 +04:00
cifs_put_tlink ( tlink ) ;
2005-04-17 02:20:36 +04:00
return rc ;
}
2015-05-02 20:32:22 +03:00
const char *
2015-12-29 23:58:39 +03:00
cifs_get_link ( struct dentry * direntry , struct inode * inode ,
struct delayed_call * done )
2005-04-17 02:20:36 +04:00
{
2009-05-19 17:57:03 +04:00
int rc = - ENOMEM ;
2012-06-20 11:21:16 +04:00
unsigned int xid ;
2005-04-17 02:20:36 +04:00
char * full_path = NULL ;
2009-05-19 17:57:03 +04:00
char * target_path = NULL ;
struct cifs_sb_info * cifs_sb = CIFS_SB ( inode - > i_sb ) ;
2010-09-30 03:51:11 +04:00
struct tcon_link * tlink = NULL ;
2011-05-27 08:34:02 +04:00
struct cifs_tcon * tcon ;
2013-08-14 19:25:21 +04:00
struct TCP_Server_Info * server ;
2005-04-17 02:20:36 +04:00
2015-11-17 18:20:54 +03:00
if ( ! direntry )
return ERR_PTR ( - ECHILD ) ;
2012-06-20 11:21:16 +04:00
xid = get_xid ( ) ;
2005-04-17 02:20:36 +04:00
2010-09-30 03:51:11 +04:00
tlink = cifs_sb_tlink ( cifs_sb ) ;
if ( IS_ERR ( tlink ) ) {
2015-05-02 20:32:22 +03:00
free_xid ( xid ) ;
return ERR_CAST ( tlink ) ;
2010-09-30 03:51:11 +04:00
}
tcon = tlink_tcon ( tlink ) ;
2013-08-14 19:25:21 +04:00
server = tcon - > ses - > server ;
2005-04-17 02:20:36 +04:00
2009-05-19 17:57:03 +04:00
full_path = build_path_from_dentry ( direntry ) ;
2015-05-02 20:32:22 +03:00
if ( ! full_path ) {
free_xid ( xid ) ;
cifs_put_tlink ( tlink ) ;
return ERR_PTR ( - ENOMEM ) ;
}
2005-04-17 02:20:36 +04:00
2013-05-05 07:12:25 +04:00
cifs_dbg ( FYI , " Full path: %s inode = 0x%p \n " , full_path , inode ) ;
2005-04-17 02:20:36 +04:00
2010-08-05 23:19:56 +04: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 )
2013-11-25 21:09:51 +04:00
rc = query_mf_symlink ( xid , tcon , cifs_sb , full_path ,
& target_path ) ;
2010-08-05 23:19:56 +04:00
2019-04-10 01:44:46 +03:00
if ( rc ! = 0 & & server - > ops - > query_symlink ) {
struct cifsInodeInfo * cifsi = CIFS_I ( inode ) ;
bool reparse_point = false ;
if ( cifsi - > cifsAttrs & ATTR_REPARSE )
reparse_point = true ;
rc = server - > ops - > query_symlink ( xid , tcon , cifs_sb , full_path ,
& target_path , reparse_point ) ;
}
2010-08-05 23:19:56 +04:00
2009-05-19 17:57:03 +04:00
kfree ( full_path ) ;
2015-05-02 20:32:22 +03:00
free_xid ( xid ) ;
cifs_put_tlink ( tlink ) ;
2009-04-30 15:17:56 +04:00
if ( rc ! = 0 ) {
2005-04-17 02:20:36 +04:00
kfree ( target_path ) ;
2015-05-02 20:32:22 +03:00
return ERR_PTR ( rc ) ;
2005-04-17 02:20:36 +04:00
}
2015-12-29 23:58:39 +03:00
set_delayed_call ( done , kfree_link , target_path ) ;
return target_path ;
2005-04-17 02:20:36 +04:00
}
int
cifs_symlink ( struct inode * inode , struct dentry * direntry , const char * symname )
{
int rc = - EOPNOTSUPP ;
2012-06-20 11:21:16 +04:00
unsigned int xid ;
2010-09-30 03:51:11 +04:00
struct cifs_sb_info * cifs_sb = CIFS_SB ( inode - > i_sb ) ;
struct tcon_link * tlink ;
2011-05-27 08:34:02 +04:00
struct cifs_tcon * pTcon ;
2005-04-17 02:20:36 +04:00
char * full_path = NULL ;
struct inode * newinode = NULL ;
2012-06-20 11:21:16 +04:00
xid = get_xid ( ) ;
2005-04-17 02:20:36 +04:00
2010-09-30 03:51:11 +04: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 02:20:36 +04:00
2005-08-30 22:32:14 +04:00
full_path = build_path_from_dentry ( direntry ) ;
2007-07-10 05:16:18 +04:00
if ( full_path = = NULL ) {
2009-06-25 16:42:34 +04:00
rc = - ENOMEM ;
2010-09-30 03:51:11 +04:00
goto symlink_exit ;
2005-04-17 02:20:36 +04:00
}
2013-05-05 07:12:25 +04:00
cifs_dbg ( FYI , " Full path: %s \n " , full_path ) ;
cifs_dbg ( FYI , " symname is %s \n " , symname ) ;
2005-04-17 02:20:36 +04:00
/* BB what if DFS and this volume is on different share? BB */
2010-08-05 23:19:56 +04:00
if ( cifs_sb - > mnt_cifs_flags & CIFS_MOUNT_MF_SYMLINKS )
2013-11-25 21:09:52 +04:00
rc = create_mf_symlink ( xid , pTcon , cifs_sb , full_path , symname ) ;
2010-08-05 23:19:56 +04:00
else if ( pTcon - > unix_ext )
2005-04-17 02:20:36 +04:00
rc = CIFSUnixCreateSymLink ( xid , pTcon , full_path , symname ,
2015-02-13 09:35:58 +03:00
cifs_sb - > local_nls ,
cifs_remap ( cifs_sb ) ) ;
2005-04-17 02:20:36 +04:00
/* else
2007-07-10 05:16:18 +04:00
rc = CIFSCreateReparseSymLink ( xid , pTcon , fromName , toName ,
cifs_sb_target - > local_nls ) ; */
2005-04-17 02:20:36 +04:00
if ( rc = = 0 ) {
2020-06-12 06:43:01 +03:00
if ( pTcon - > posix_extensions )
rc = smb311_posix_get_inode_info ( & newinode , full_path , inode - > i_sb , xid ) ;
else if ( pTcon - > unix_ext )
2005-04-17 02:20:36 +04:00
rc = cifs_get_inode_info_unix ( & newinode , full_path ,
2007-07-10 05:16:18 +04:00
inode - > i_sb , xid ) ;
2005-04-17 02:20:36 +04:00
else
rc = cifs_get_inode_info ( & newinode , full_path , NULL ,
2008-03-15 01:37:16 +03:00
inode - > i_sb , xid , NULL ) ;
2005-04-17 02:20:36 +04:00
if ( rc ! = 0 ) {
2013-05-05 07:12:25 +04:00
cifs_dbg ( FYI , " Create symlink ok, getinodeinfo fail rc = %d \n " ,
rc ) ;
2005-04-17 02:20:36 +04:00
} else {
d_instantiate ( direntry , newinode ) ;
}
}
2010-09-30 03:51:11 +04:00
symlink_exit :
2005-11-07 12:01:34 +03:00
kfree ( full_path ) ;
2010-09-30 03:51:11 +04:00
cifs_put_tlink ( tlink ) ;
2012-06-20 11:21:16 +04:00
free_xid ( xid ) ;
2005-04-17 02:20:36 +04:00
return rc ;
}