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 * from linux/fs/ext2/symlink.c
12 * Copyright (C) 1998-99, Frank A. Vorstenbosch
14 * ncpfs symlink handling code
15 * NLS support (c) 1999 Petr Vandrovec
19 #include <linux/config.h>
21 #ifdef CONFIG_NCPFS_EXTRAS
23 #include <asm/uaccess.h>
24 #include <asm/segment.h>
26 #include <linux/errno.h>
28 #include <linux/ncp_fs.h>
29 #include <linux/sched.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 le32_to_cpu(0x6c6d7973) /* "symlnk->" */
39 #define NCP_SYMLINK_MAGIC1 le32_to_cpu(0x3e2d6b6e)
41 int ncp_create_new(struct inode *dir, struct dentry *dentry,
42 int mode,int attributes);
44 /* ----- read a symbolic link ------------------------------------------ */
46 static int ncp_symlink_readpage(struct file *file, struct page *page)
48 struct inode *inode = page->mapping->host;
49 int error, length, len, cnt;
51 char *buf = kmap(page);
54 for (cnt = 0; (link=(char *)kmalloc(NCP_MAX_SYMLINK_SIZE, GFP_NFS))==NULL; cnt++) {
60 if (ncp_make_open(inode,O_RDONLY))
63 error=ncp_read_kernel(NCP_SERVER(inode),NCP_FINFO(inode)->file_handle,
64 0,NCP_MAX_SYMLINK_SIZE,link,&length);
66 ncp_inode_close(inode);
67 /* Close file handle if no other users... */
68 ncp_make_closed(inode);
72 if (length<NCP_MIN_SYMLINK_SIZE ||
73 ((__u32 *)link)[0]!=NCP_SYMLINK_MAGIC0 ||
74 ((__u32 *)link)[1]!=NCP_SYMLINK_MAGIC1)
77 len = NCP_MAX_SYMLINK_SIZE;
78 error = ncp_vol2io(NCP_SERVER(inode), buf, &len, link+8, length-8, 0);
82 SetPageUptodate(page);
98 * symlinks can't do much...
100 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) {
112 PRINTK("ncp_symlink(dir=%p,dentry=%p,symname=%s)\n",dir,dentry,symname);
115 if (!(NCP_SERVER(dir)->m.flags & NCP_MOUNT_SYMLINKS))
116 return -EPERM; /* EPERM is returned by VFS if symlink procedure does not exist */
118 if ((length=strlen(symname))>NCP_MAX_SYMLINK_SIZE-8)
121 if ((link=(char *)kmalloc(length+9,GFP_NFS))==NULL)
125 if (ncp_create_new(dir,dentry,0,aSHARED|aHIDDEN))
128 inode=dentry->d_inode;
130 if (ncp_make_open(inode, O_WRONLY))
133 ((__u32 *)link)[0]=NCP_SYMLINK_MAGIC0;
134 ((__u32 *)link)[1]=NCP_SYMLINK_MAGIC1;
136 /* map to/from server charset, do not touch upper/lower case as
137 symlink can point out of ncp filesystem */
139 err = ncp_io2vol(NCP_SERVER(inode),link+8,&length,symname,length-1,0);
143 if(ncp_write_kernel(NCP_SERVER(inode), NCP_FINFO(inode)->file_handle,
144 0, length+8, link, &i) || i!=length+8) {
149 ncp_inode_close(inode);
150 ncp_make_closed(inode);
155 ncp_inode_close(inode);
156 ncp_make_closed(inode);
163 /* ----- EOF ----- */