link.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. * fs/cifs/link.c
  3. *
  4. * Copyright (C) International Business Machines Corp., 2002,2008
  5. * Author(s): Steve French (sfrench@us.ibm.com)
  6. *
  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.
  11. *
  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.
  16. *
  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
  20. */
  21. #include <linux/fs.h>
  22. #include <linux/stat.h>
  23. #include <linux/namei.h>
  24. #include "cifsfs.h"
  25. #include "cifspdu.h"
  26. #include "cifsglob.h"
  27. #include "cifsproto.h"
  28. #include "cifs_debug.h"
  29. #include "cifs_fs_sb.h"
  30. int
  31. cifs_hardlink(struct dentry *old_file, struct inode *inode,
  32. struct dentry *direntry)
  33. {
  34. int rc = -EACCES;
  35. int xid;
  36. char *fromName = NULL;
  37. char *toName = NULL;
  38. struct cifs_sb_info *cifs_sb_target;
  39. struct cifsTconInfo *pTcon;
  40. struct cifsInodeInfo *cifsInode;
  41. xid = GetXid();
  42. cifs_sb_target = CIFS_SB(inode->i_sb);
  43. pTcon = cifs_sb_target->tcon;
  44. /* No need to check for cross device links since server will do that
  45. BB note DFS case in future though (when we may have to check) */
  46. fromName = build_path_from_dentry(old_file);
  47. toName = build_path_from_dentry(direntry);
  48. if ((fromName == NULL) || (toName == NULL)) {
  49. rc = -ENOMEM;
  50. goto cifs_hl_exit;
  51. }
  52. /* if (cifs_sb_target->tcon->ses->capabilities & CAP_UNIX)*/
  53. if (pTcon->unix_ext)
  54. rc = CIFSUnixCreateHardLink(xid, pTcon, fromName, toName,
  55. cifs_sb_target->local_nls,
  56. cifs_sb_target->mnt_cifs_flags &
  57. CIFS_MOUNT_MAP_SPECIAL_CHR);
  58. else {
  59. rc = CIFSCreateHardLink(xid, pTcon, fromName, toName,
  60. cifs_sb_target->local_nls,
  61. cifs_sb_target->mnt_cifs_flags &
  62. CIFS_MOUNT_MAP_SPECIAL_CHR);
  63. if ((rc == -EIO) || (rc == -EINVAL))
  64. rc = -EOPNOTSUPP;
  65. }
  66. d_drop(direntry); /* force new lookup from server of target */
  67. /* if source file is cached (oplocked) revalidate will not go to server
  68. until the file is closed or oplock broken so update nlinks locally */
  69. if (old_file->d_inode) {
  70. cifsInode = CIFS_I(old_file->d_inode);
  71. if (rc == 0) {
  72. old_file->d_inode->i_nlink++;
  73. /* BB should we make this contingent on superblock flag NOATIME? */
  74. /* old_file->d_inode->i_ctime = CURRENT_TIME;*/
  75. /* parent dir timestamps will update from srv
  76. within a second, would it really be worth it
  77. to set the parent dir cifs inode time to zero
  78. to force revalidate (faster) for it too? */
  79. }
  80. /* if not oplocked will force revalidate to get info
  81. on source file from srv */
  82. cifsInode->time = 0;
  83. /* Will update parent dir timestamps from srv within a second.
  84. Would it really be worth it to set the parent dir (cifs
  85. inode) time field to zero to force revalidate on parent
  86. directory faster ie
  87. CIFS_I(inode)->time = 0; */
  88. }
  89. cifs_hl_exit:
  90. kfree(fromName);
  91. kfree(toName);
  92. FreeXid(xid);
  93. return rc;
  94. }
  95. void *
  96. cifs_follow_link(struct dentry *direntry, struct nameidata *nd)
  97. {
  98. struct inode *inode = direntry->d_inode;
  99. int rc = -ENOMEM;
  100. int xid;
  101. char *full_path = NULL;
  102. char *target_path = NULL;
  103. struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
  104. struct cifsTconInfo *tcon = cifs_sb->tcon;
  105. xid = GetXid();
  106. /*
  107. * For now, we just handle symlinks with unix extensions enabled.
  108. * Eventually we should handle NTFS reparse points, and MacOS
  109. * symlink support. For instance...
  110. *
  111. * rc = CIFSSMBQueryReparseLinkInfo(...)
  112. *
  113. * For now, just return -EACCES when the server doesn't support posix
  114. * extensions. Note that we still allow querying symlinks when posix
  115. * extensions are manually disabled. We could disable these as well
  116. * but there doesn't seem to be any harm in allowing the client to
  117. * read them.
  118. */
  119. if (!(tcon->ses->capabilities & CAP_UNIX)) {
  120. rc = -EACCES;
  121. goto out;
  122. }
  123. full_path = build_path_from_dentry(direntry);
  124. if (!full_path)
  125. goto out;
  126. cFYI(1, ("Full path: %s inode = 0x%p", full_path, inode));
  127. rc = CIFSSMBUnixQuerySymLink(xid, tcon, full_path, &target_path,
  128. cifs_sb->local_nls);
  129. kfree(full_path);
  130. out:
  131. if (rc != 0) {
  132. kfree(target_path);
  133. target_path = ERR_PTR(rc);
  134. }
  135. FreeXid(xid);
  136. nd_set_link(nd, target_path);
  137. return NULL;
  138. }
  139. int
  140. cifs_symlink(struct inode *inode, struct dentry *direntry, const char *symname)
  141. {
  142. int rc = -EOPNOTSUPP;
  143. int xid;
  144. struct cifs_sb_info *cifs_sb;
  145. struct cifsTconInfo *pTcon;
  146. char *full_path = NULL;
  147. struct inode *newinode = NULL;
  148. xid = GetXid();
  149. cifs_sb = CIFS_SB(inode->i_sb);
  150. pTcon = cifs_sb->tcon;
  151. full_path = build_path_from_dentry(direntry);
  152. if (full_path == NULL) {
  153. rc = -ENOMEM;
  154. FreeXid(xid);
  155. return rc;
  156. }
  157. cFYI(1, ("Full path: %s", full_path));
  158. cFYI(1, ("symname is %s", symname));
  159. /* BB what if DFS and this volume is on different share? BB */
  160. if (pTcon->unix_ext)
  161. rc = CIFSUnixCreateSymLink(xid, pTcon, full_path, symname,
  162. cifs_sb->local_nls);
  163. /* else
  164. rc = CIFSCreateReparseSymLink(xid, pTcon, fromName, toName,
  165. cifs_sb_target->local_nls); */
  166. if (rc == 0) {
  167. if (pTcon->unix_ext)
  168. rc = cifs_get_inode_info_unix(&newinode, full_path,
  169. inode->i_sb, xid);
  170. else
  171. rc = cifs_get_inode_info(&newinode, full_path, NULL,
  172. inode->i_sb, xid, NULL);
  173. if (rc != 0) {
  174. cFYI(1, ("Create symlink ok, getinodeinfo fail rc = %d",
  175. rc));
  176. } else {
  177. if (pTcon->nocase)
  178. direntry->d_op = &cifs_ci_dentry_ops;
  179. else
  180. direntry->d_op = &cifs_dentry_ops;
  181. d_instantiate(direntry, newinode);
  182. }
  183. }
  184. kfree(full_path);
  185. FreeXid(xid);
  186. return rc;
  187. }
  188. void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
  189. {
  190. char *p = nd_get_link(nd);
  191. if (!IS_ERR(p))
  192. kfree(p);
  193. }