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 <linux/uaccess.h>
26 #include <linux/errno.h>
28 #include <linux/time.h>
29 #include <linux/slab.h>
31 #include <linux/stat.h>
34 /* these magic numbers must appear in the symlink file -- this makes it a bit
35 more resilient against the magic attributes being set on random files. */
37 #define NCP_SYMLINK_MAGIC0 cpu_to_le32(0x6c6d7973) /* "symlnk->" */
38 #define NCP_SYMLINK_MAGIC1 cpu_to_le32(0x3e2d6b6e)
40 /* ----- read a symbolic link ------------------------------------------ */
42 static int ncp_symlink_readpage(struct file
*file
, struct page
*page
)
44 struct inode
*inode
= page
->mapping
->host
;
45 int error
, length
, len
;
47 char *buf
= kmap(page
);
50 rawlink
= kmalloc(NCP_MAX_SYMLINK_SIZE
, GFP_KERNEL
);
54 if (ncp_make_open(inode
,O_RDONLY
))
57 error
=ncp_read_kernel(NCP_SERVER(inode
),NCP_FINFO(inode
)->file_handle
,
58 0,NCP_MAX_SYMLINK_SIZE
,rawlink
,&length
);
60 ncp_inode_close(inode
);
61 /* Close file handle if no other users... */
62 ncp_make_closed(inode
);
66 if (NCP_FINFO(inode
)->flags
& NCPI_KLUDGE_SYMLINK
) {
67 if (length
<NCP_MIN_SYMLINK_SIZE
||
68 ((__le32
*)rawlink
)[0]!=NCP_SYMLINK_MAGIC0
||
69 ((__le32
*)rawlink
)[1]!=NCP_SYMLINK_MAGIC1
)
77 len
= NCP_MAX_SYMLINK_SIZE
;
78 error
= ncp_vol2io(NCP_SERVER(inode
), buf
, &len
, link
, length
, 0);
82 SetPageUptodate(page
);
98 * symlinks can't do much...
100 const struct address_space_operations ncp_symlink_aops
= {
101 .readpage
= ncp_symlink_readpage
,
104 /* ----- create a new symbolic link -------------------------------------- */
106 int ncp_symlink(struct inode
*dir
, struct dentry
*dentry
, const char *symname
) {
109 int length
, err
, i
, outlen
;
115 ncp_dbg(1, "dir=%p, dentry=%p, symname=%s\n", dir
, dentry
, symname
);
117 if (ncp_is_nfs_extras(NCP_SERVER(dir
), NCP_FINFO(dir
)->volNumber
))
120 #ifdef CONFIG_NCPFS_EXTRAS
121 if (NCP_SERVER(dir
)->m
.flags
& NCP_MOUNT_SYMLINKS
)
125 /* EPERM is returned by VFS if symlink procedure does not exist */
128 rawlink
= kmalloc(NCP_MAX_SYMLINK_SIZE
, GFP_KERNEL
);
134 attr
= aSHARED
| aHIDDEN
;
135 ((__le32
*)rawlink
)[0]=NCP_SYMLINK_MAGIC0
;
136 ((__le32
*)rawlink
)[1]=NCP_SYMLINK_MAGIC1
;
139 mode
= S_IFLNK
| S_IRWXUGO
;
144 length
= strlen(symname
);
145 /* map to/from server charset, do not touch upper/lower case as
146 symlink can point out of ncp filesystem */
147 outlen
= NCP_MAX_SYMLINK_SIZE
- hdr
;
148 err
= ncp_io2vol(NCP_SERVER(dir
), rawlink
+ hdr
, &outlen
, symname
, length
, 0);
155 if (ncp_create_new(dir
,dentry
,mode
,0,attr
)) {
159 inode
=d_inode(dentry
);
161 if (ncp_make_open(inode
, O_WRONLY
))
164 if (ncp_write_kernel(NCP_SERVER(inode
), NCP_FINFO(inode
)->file_handle
,
165 0, outlen
, rawlink
, &i
) || i
!=outlen
) {
169 ncp_inode_close(inode
);
170 ncp_make_closed(inode
);
174 ncp_inode_close(inode
);
175 ncp_make_closed(inode
);
181 /* ----- EOF ----- */