4 * Copyright (C) International Business Machines Corp., 2002,2003
5 * Author(s): Steve French (sfrench@us.ibm.com)
7 * This library is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published
9 * by the Free Software Foundation; either version 2.1 of the License, or
10 * (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
15 * the GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <linux/stat.h>
26 #include "cifsproto.h"
27 #include "cifs_debug.h"
28 #include "cifs_fs_sb.h"
31 cifs_hardlink(struct dentry *old_file, struct inode *inode,
32 struct dentry *direntry)
36 char *fromName = NULL;
38 struct cifs_sb_info *cifs_sb_target;
39 struct cifsTconInfo *pTcon;
40 struct cifsInodeInfo *cifsInode;
44 cifs_sb_target = CIFS_SB(inode->i_sb);
45 pTcon = cifs_sb_target->tcon;
47 /* 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) */
49 fromName = build_path_from_dentry(old_file);
50 toName = build_path_from_dentry(direntry);
51 if (cifs_sb_target->tcon->ses->capabilities & CAP_UNIX)
52 rc = CIFSUnixCreateHardLink(xid, pTcon, fromName, toName,
53 cifs_sb_target->local_nls);
55 rc = CIFSCreateHardLink(xid, pTcon, fromName, toName,
56 cifs_sb_target->local_nls);
63 /* renew_parental_timestamps(old_file);
65 mark_inode_dirty(inode);
66 d_instantiate(direntry, inode); */
67 /* BB add call to either mark inode dirty or refresh its data and timestamp to current time */
69 d_drop(direntry); /* force new lookup from server */
70 cifsInode = CIFS_I(old_file->d_inode);
71 cifsInode->time = 0; /* will force revalidate to go get info when needed */
82 cifs_follow_link(struct dentry *direntry, struct nameidata *nd)
84 struct inode *inode = direntry->d_inode;
87 char *full_path = NULL;
89 struct cifs_sb_info *cifs_sb;
90 struct cifsTconInfo *pTcon;
93 full_path = build_path_from_dentry(direntry);
94 cFYI(1, ("Full path: %s inode = 0x%p", full_path, inode));
95 cifs_sb = CIFS_SB(inode->i_sb);
96 pTcon = cifs_sb->tcon;
97 target_path = kmalloc(PATH_MAX, GFP_KERNEL);
98 if(target_path == NULL) {
104 /* can not call the following line due to EFAULT in vfs_readlink which is presumably expecting a user space buffer */
105 /* length = cifs_readlink(direntry,target_path, sizeof(target_path) - 1); */
107 /* BB add read reparse point symlink code and Unix extensions symlink code here BB */
108 if (pTcon->ses->capabilities & CAP_UNIX)
109 rc = CIFSSMBUnixQuerySymLink(xid, pTcon, full_path,
114 /* rc = CIFSSMBQueryReparseLinkInfo */
115 /* BB Add code to Query ReparsePoint info */
117 /* BB Anything else to do to handle recursive links? */
118 /* BB Should we be using page symlink ops here? */
122 /* BB Add special case check for Samba DFS symlinks */
124 target_path[PATH_MAX-1] = 0;
125 rc = vfs_follow_link(nd, target_path);
138 cifs_symlink(struct inode *inode, struct dentry *direntry, const char *symname)
140 int rc = -EOPNOTSUPP;
142 struct cifs_sb_info *cifs_sb;
143 struct cifsTconInfo *pTcon;
144 char *full_path = NULL;
145 struct inode *newinode = NULL;
149 cifs_sb = CIFS_SB(inode->i_sb);
150 pTcon = cifs_sb->tcon;
152 full_path = build_path_from_dentry(direntry);
153 cFYI(1, ("Full path: %s ", full_path));
154 cFYI(1, ("symname is %s", symname));
156 /* BB what if DFS and this volume is on different share? BB */
157 if (cifs_sb->tcon->ses->capabilities & CAP_UNIX)
158 rc = CIFSUnixCreateSymLink(xid, pTcon, full_path, symname,
161 rc = CIFSCreateReparseSymLink(xid, pTcon, fromName, toName,cifs_sb_target->local_nls); */
164 if (pTcon->ses->capabilities & CAP_UNIX)
165 rc = cifs_get_inode_info_unix(&newinode, full_path,
168 rc = cifs_get_inode_info(&newinode, full_path, NULL,
173 ("Create symlink worked but get_inode_info failed with rc = %d ",
176 direntry->d_op = &cifs_dentry_ops;
177 d_instantiate(direntry, newinode);
188 cifs_readlink(struct dentry *direntry, char *pBuffer, int buflen)
190 struct inode *inode = direntry->d_inode;
194 struct cifs_sb_info *cifs_sb;
195 struct cifsTconInfo *pTcon;
196 char *full_path = NULL;
197 char *tmp_path = NULL;
199 unsigned char * referrals = NULL;
200 int num_referrals = 0;
205 cifs_sb = CIFS_SB(inode->i_sb);
206 pTcon = cifs_sb->tcon;
207 full_path = build_path_from_dentry(direntry);
209 ("Full path: %s inode = 0x%p pBuffer = 0x%p buflen = %d",
210 full_path, inode, pBuffer, buflen));
211 if(buflen > PATH_MAX)
215 tmpbuffer = kmalloc(len,GFP_KERNEL);
216 if(tmpbuffer == NULL) {
223 /* BB add read reparse point symlink code and Unix extensions symlink code here BB */
224 if (cifs_sb->tcon->ses->capabilities & CAP_UNIX)
225 rc = CIFSSMBUnixQuerySymLink(xid, pTcon, full_path,
230 rc = CIFSSMBOpen(xid, pTcon, full_path, FILE_OPEN, GENERIC_READ,
231 OPEN_REPARSE_POINT,&fid, &oplock, NULL, cifs_sb->local_nls);
233 rc = CIFSSMBQueryReparseLinkInfo(xid, pTcon, full_path,
238 if(CIFSSMBClose(xid, pTcon, fid)) {
239 cFYI(1,("Error closing junction point (open for ioctl)"));
242 /* Query if DFS Junction */
244 kmalloc(MAX_TREE_SIZE + MAX_PATHCONF + 1,
247 strncpy(tmp_path, pTcon->treeName, MAX_TREE_SIZE);
248 strncat(tmp_path, full_path, MAX_PATHCONF);
249 rc = get_dfs_path(xid, pTcon->ses, tmp_path,
250 cifs_sb->local_nls, &num_referrals, &referrals);
251 cFYI(1,("Get DFS for %s rc = %d ",tmp_path, rc));
252 if((num_referrals == 0) && (rc == 0))
255 cFYI(1,("num referral: %d",num_referrals));
257 cFYI(1,("referral string: %s ",referrals));
258 strncpy(tmpbuffer, referrals, len-1);
268 /* BB add code like else decode referrals then memcpy to
269 tmpbuffer and free referrals string array BB */
273 /* BB Anything else to do to handle recursive links? */
274 /* BB Should we be using page ops here? */
276 /* BB null terminate returned string in pBuffer? BB */
278 rc = vfs_readlink(direntry, pBuffer, len, tmpbuffer);
280 ("vfs_readlink called from cifs_readlink returned %d",