2 * linux/fs/ncpfs/symlink.c
4 * Code for allowing symbolic links on NCPFS (i.e. NetWare)
5 * Symbolic links are not supported on native NetWare, so we use an
6 * infrequently-used flag (Sh) and store a two-word magic header in
7 * the file to make sure we don't accidentally use a non-link file
10 * When using the NFS namespace, we set the mode to indicate a symlink and
11 * don't bother with the magic numbers.
13 * from linux/fs/ext2/symlink.c
15 * Copyright (C) 1998-99, Frank A. Vorstenbosch
17 * ncpfs symlink handling code
18 * NLS support (c) 1999 Petr Vandrovec
19 * Modified 2000 Ben Harris, University of Cambridge for NFS NS meta-info
24 #include <asm/uaccess.h>
26 #include <linux/errno.h>
28 #include <linux/ncp_fs.h>
29 #include <linux/time.h>
31 #include <linux/stat.h>
32 #include "ncplib_kernel.h"
35 /* these magic numbers must appear in the symlink file -- this makes it a bit
36 more resilient against the magic attributes being set on random files. */
38 #define NCP_SYMLINK_MAGIC0 cpu_to_le32(0x6c6d7973) /* "symlnk->" */
39 #define NCP_SYMLINK_MAGIC1 cpu_to_le32(0x3e2d6b6e)
41 /* ----- read a symbolic link ------------------------------------------ */
43 static int ncp_symlink_readpage(struct file
*file
, struct page
*page
)
45 struct inode
*inode
= page
->mapping
->host
;
46 int error
, length
, len
;
48 char *buf
= kmap(page
);
51 rawlink
=(char *)kmalloc(NCP_MAX_SYMLINK_SIZE
, GFP_KERNEL
);
55 if (ncp_make_open(inode
,O_RDONLY
))
58 error
=ncp_read_kernel(NCP_SERVER(inode
),NCP_FINFO(inode
)->file_handle
,
59 0,NCP_MAX_SYMLINK_SIZE
,rawlink
,&length
);
61 ncp_inode_close(inode
);
62 /* Close file handle if no other users... */
63 ncp_make_closed(inode
);
67 if (NCP_FINFO(inode
)->flags
& NCPI_KLUDGE_SYMLINK
) {
68 if (length
<NCP_MIN_SYMLINK_SIZE
||
69 ((__le32
*)rawlink
)[0]!=NCP_SYMLINK_MAGIC0
||
70 ((__le32
*)rawlink
)[1]!=NCP_SYMLINK_MAGIC1
)
78 len
= NCP_MAX_SYMLINK_SIZE
;
79 error
= ncp_vol2io(NCP_SERVER(inode
), buf
, &len
, link
, length
, 0);
83 SetPageUptodate(page
);
99 * symlinks can't do much...
101 const struct address_space_operations ncp_symlink_aops
= {
102 .readpage
= ncp_symlink_readpage
,
105 /* ----- create a new symbolic link -------------------------------------- */
107 int ncp_symlink(struct inode
*dir
, struct dentry
*dentry
, const char *symname
) {
110 int length
, err
, i
, outlen
;
116 DPRINTK("ncp_symlink(dir=%p,dentry=%p,symname=%s)\n",dir
,dentry
,symname
);
118 if (ncp_is_nfs_extras(NCP_SERVER(dir
), NCP_FINFO(dir
)->volNumber
))
121 #ifdef CONFIG_NCPFS_EXTRAS
122 if (NCP_SERVER(dir
)->m
.flags
& NCP_MOUNT_SYMLINKS
)
126 /* EPERM is returned by VFS if symlink procedure does not exist */
129 rawlink
=(char *)kmalloc(NCP_MAX_SYMLINK_SIZE
, GFP_KERNEL
);
135 attr
= aSHARED
| aHIDDEN
;
136 ((__le32
*)rawlink
)[0]=NCP_SYMLINK_MAGIC0
;
137 ((__le32
*)rawlink
)[1]=NCP_SYMLINK_MAGIC1
;
140 mode
= S_IFLNK
| S_IRWXUGO
;
145 length
= strlen(symname
);
146 /* map to/from server charset, do not touch upper/lower case as
147 symlink can point out of ncp filesystem */
148 outlen
= NCP_MAX_SYMLINK_SIZE
- hdr
;
149 err
= ncp_io2vol(NCP_SERVER(dir
), rawlink
+ hdr
, &outlen
, symname
, length
, 0);
156 if (ncp_create_new(dir
,dentry
,mode
,0,attr
)) {
160 inode
=dentry
->d_inode
;
162 if (ncp_make_open(inode
, O_WRONLY
))
165 if (ncp_write_kernel(NCP_SERVER(inode
), NCP_FINFO(inode
)->file_handle
,
166 0, outlen
, rawlink
, &i
) || i
!=outlen
) {
170 ncp_inode_close(inode
);
171 ncp_make_closed(inode
);
175 ncp_inode_close(inode
);
176 ncp_make_closed(inode
);
182 /* ----- EOF ----- */