1 /* $Id: socksys.c,v 1.7 1998/03/29 10:11:04 davem Exp $
2 * socksys.c: /dev/inet/ stuff for Solaris emulation.
4 * Copyright (C) 1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
5 * Copyright (C) 1997, 1998 Patrik Rak (prak3264@ss1000.ms.mff.cuni.cz)
6 * Copyright (C) 1995, 1996 Mike Jagdis (jaggy@purplet.demon.co.uk)
9 #include <linux/types.h>
10 #include <linux/kernel.h>
11 #include <linux/sched.h>
12 #include <linux/smp.h>
13 #include <linux/smp_lock.h>
14 #include <linux/ioctl.h>
16 #include <linux/file.h>
17 #include <linux/init.h>
18 #include <linux/poll.h>
19 #include <linux/file.h>
20 #include <linux/malloc.h>
22 #include <asm/uaccess.h>
23 #include <asm/termios.h>
28 extern asmlinkage
int sys_ioctl(unsigned int fd
, unsigned int cmd
,
31 static int af_inet_protocols
[] = {
32 IPPROTO_ICMP
, IPPROTO_ICMP
, IPPROTO_IGMP
, IPPROTO_IPIP
, IPPROTO_TCP
,
33 IPPROTO_EGP
, IPPROTO_PUP
, IPPROTO_UDP
, IPPROTO_IDP
, IPPROTO_RAW
,
37 #ifndef DEBUG_SOLARIS_KMALLOC
39 #define mykmalloc kmalloc
44 extern void * mykmalloc(size_t s
, int gfp
);
45 extern void mykfree(void *);
49 static unsigned int (*sock_poll
)(struct file
*, poll_table
*);
51 static struct file_operations socksys_file_ops
= {
64 static int socksys_open(struct inode
* inode
, struct file
* filp
)
66 int family
, type
, protocol
, fd
;
67 struct dentry
*dentry
;
68 int (*sys_socket
)(int,int,int) =
69 (int (*)(int,int,int))SUNOS(97);
70 struct sol_socket_struct
* sock
;
72 family
= ((MINOR(inode
->i_rdev
) >> 4) & 0xf);
79 protocol
= af_inet_protocols
[MINOR(inode
->i_rdev
) & 0xf];
81 case IPPROTO_TCP
: type
= SOCK_STREAM
; break;
82 case IPPROTO_UDP
: type
= SOCK_DGRAM
; break;
83 default: type
= SOCK_RAW
; break;
92 fd
= sys_socket(family
, type
, protocol
);
96 * N.B. The following operations are not legal!
98 * d_delete(filp->f_dentry), then d_instantiate with sock inode
100 dentry
= filp
->f_dentry
;
101 filp
->f_dentry
= dget(fcheck(fd
)->f_dentry
);
102 filp
->f_dentry
->d_inode
->i_rdev
= inode
->i_rdev
;
103 filp
->f_dentry
->d_inode
->i_flock
= inode
->i_flock
;
104 filp
->f_dentry
->d_inode
->u
.socket_i
.file
= filp
;
105 filp
->f_op
= &socksys_file_ops
;
106 sock
= (struct sol_socket_struct
*)
107 mykmalloc(sizeof(struct sol_socket_struct
), GFP_KERNEL
);
108 if (!sock
) return -ENOMEM
;
109 SOLDD(("sock=%016lx(%016lx)\n", sock
, filp
));
110 sock
->magic
= SOLARIS_SOCKET_MAGIC
;
112 sock
->state
= TS_UNBND
;
114 sock
->pfirst
= sock
->plast
= NULL
;
115 filp
->private_data
= sock
;
116 SOLDD(("filp->private_data %016lx\n", filp
->private_data
));
123 static int socksys_release(struct inode
* inode
, struct file
* filp
)
125 struct sol_socket_struct
* sock
;
128 /* XXX: check this */
129 sock
= (struct sol_socket_struct
*)filp
->private_data
;
130 SOLDD(("sock release %016lx(%016lx)\n", sock
, filp
));
133 struct T_primsg
*next
= it
->next
;
135 SOLDD(("socksys_release %016lx->%016lx\n", it
, next
));
139 filp
->private_data
= NULL
;
140 SOLDD(("socksys_release %016lx\n", sock
));
141 mykfree((char*)sock
);
145 static unsigned int socksys_poll(struct file
* filp
, poll_table
* wait
)
148 unsigned int mask
= 0;
150 ino
=filp
->f_dentry
->d_inode
;
151 if (ino
&& ino
->i_sock
) {
152 struct sol_socket_struct
*sock
;
153 sock
= (struct sol_socket_struct
*)filp
->private_data
;
154 if (sock
&& sock
->pfirst
) {
155 mask
|= POLLIN
| POLLRDNORM
;
156 if (sock
->pfirst
->pri
== MSG_HIPRI
)
161 mask
|= (*sock_poll
)(filp
, wait
);
165 static struct file_operations socksys_fops
= {
173 socksys_open
, /* open */
175 socksys_release
,/* release */
183 int (*sys_socket
)(int,int,int) =
184 (int (*)(int,int,int))SUNOS(97);
185 int (*sys_close
)(unsigned int) =
186 (int (*)(unsigned int))SYS(close
);
188 ret
= register_chrdev (30, "socksys", &socksys_fops
);
190 printk ("Couldn't register socksys character device\n");
193 ret
= sys_socket(AF_INET
, SOCK_STREAM
, IPPROTO_TCP
);
195 printk ("Couldn't create socket\n");
199 /* N.B. Is this valid? Suppose the f_ops are in a module ... */
200 socksys_file_ops
= *file
->f_op
;
202 sock_poll
= socksys_file_ops
.poll
;
203 socksys_file_ops
.poll
= socksys_poll
;
204 socksys_file_ops
.release
= socksys_release
;
209 cleanup_socksys(void)
211 if (unregister_chrdev (30, "socksys"))
212 printk ("Couldn't unregister socksys character device\n");