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>
30 #include <linux/slab.h>
32 #include <linux/stat.h>
33 #include "ncplib_kernel.h"
36 /* these magic numbers must appear in the symlink file -- this makes it a bit
37 more resilient against the magic attributes being set on random files. */
39 #define NCP_SYMLINK_MAGIC0 cpu_to_le32(0x6c6d7973) /* "symlnk->" */
40 #define NCP_SYMLINK_MAGIC1 cpu_to_le32(0x3e2d6b6e)
42 /* ----- read a symbolic link ------------------------------------------ */
44 static int ncp_symlink_readpage(struct file
*file
, struct page
*page
)
46 struct inode
*inode
= page
->mapping
->host
;
47 int error
, length
, len
;
49 char *buf
= kmap(page
);
52 rawlink
= kmalloc(NCP_MAX_SYMLINK_SIZE
, GFP_KERNEL
);
56 if (ncp_make_open(inode
,O_RDONLY
))
59 error
=ncp_read_kernel(NCP_SERVER(inode
),NCP_FINFO(inode
)->file_handle
,
60 0,NCP_MAX_SYMLINK_SIZE
,rawlink
,&length
);
62 ncp_inode_close(inode
);
63 /* Close file handle if no other users... */
64 ncp_make_closed(inode
);
68 if (NCP_FINFO(inode
)->flags
& NCPI_KLUDGE_SYMLINK
) {
69 if (length
<NCP_MIN_SYMLINK_SIZE
||
70 ((__le32
*)rawlink
)[0]!=NCP_SYMLINK_MAGIC0
||
71 ((__le32
*)rawlink
)[1]!=NCP_SYMLINK_MAGIC1
)
79 len
= NCP_MAX_SYMLINK_SIZE
;
80 error
= ncp_vol2io(NCP_SERVER(inode
), buf
, &len
, link
, length
, 0);
84 SetPageUptodate(page
);
100 * symlinks can't do much...
102 const struct address_space_operations ncp_symlink_aops
= {
103 .readpage
= ncp_symlink_readpage
,
106 /* ----- create a new symbolic link -------------------------------------- */
108 int ncp_symlink(struct inode
*dir
, struct dentry
*dentry
, const char *symname
) {
111 int length
, err
, i
, outlen
;
117 DPRINTK("ncp_symlink(dir=%p,dentry=%p,symname=%s)\n",dir
,dentry
,symname
);
119 if (ncp_is_nfs_extras(NCP_SERVER(dir
), NCP_FINFO(dir
)->volNumber
))
122 #ifdef CONFIG_NCPFS_EXTRAS
123 if (NCP_SERVER(dir
)->m
.flags
& NCP_MOUNT_SYMLINKS
)
127 /* EPERM is returned by VFS if symlink procedure does not exist */
130 rawlink
= kmalloc(NCP_MAX_SYMLINK_SIZE
, GFP_KERNEL
);
136 attr
= aSHARED
| aHIDDEN
;
137 ((__le32
*)rawlink
)[0]=NCP_SYMLINK_MAGIC0
;
138 ((__le32
*)rawlink
)[1]=NCP_SYMLINK_MAGIC1
;
141 mode
= S_IFLNK
| S_IRWXUGO
;
146 length
= strlen(symname
);
147 /* map to/from server charset, do not touch upper/lower case as
148 symlink can point out of ncp filesystem */
149 outlen
= NCP_MAX_SYMLINK_SIZE
- hdr
;
150 err
= ncp_io2vol(NCP_SERVER(dir
), rawlink
+ hdr
, &outlen
, symname
, length
, 0);
157 if (ncp_create_new(dir
,dentry
,mode
,0,attr
)) {
161 inode
=dentry
->d_inode
;
163 if (ncp_make_open(inode
, O_WRONLY
))
166 if (ncp_write_kernel(NCP_SERVER(inode
), NCP_FINFO(inode
)->file_handle
,
167 0, outlen
, rawlink
, &i
) || i
!=outlen
) {
171 ncp_inode_close(inode
);
172 ncp_make_closed(inode
);
176 ncp_inode_close(inode
);
177 ncp_make_closed(inode
);
183 /* ----- EOF ----- */