link.c 6.0 KB

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