[SCSI] drivers/scsi/dpt_i2o.c: fix compile warnings
[linux/fpc-iii.git] / arch / sparc64 / solaris / socksys.c
blobd7c1c76582cc3698d3f2b028103166a3f8c31266
1 /* $Id: socksys.c,v 1.21 2002/02/08 03:57:14 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)
7 */
9 /*
10 * Dave, _please_ give me specifications on this fscking mess so that I
11 * could at least get it into the state when it wouldn't screw the rest of
12 * the kernel over. socksys.c and timod.c _stink_ and we are not talking
13 * H2S here, it's isopropilmercaptan in concentrations way over LD50. -- AV
16 #include <linux/types.h>
17 #include <linux/kernel.h>
18 #include <linux/sched.h>
19 #include <linux/smp.h>
20 #include <linux/smp_lock.h>
21 #include <linux/ioctl.h>
22 #include <linux/fs.h>
23 #include <linux/file.h>
24 #include <linux/init.h>
25 #include <linux/poll.h>
26 #include <linux/slab.h>
27 #include <linux/syscalls.h>
28 #include <linux/in.h>
29 #include <linux/devfs_fs_kernel.h>
31 #include <net/sock.h>
33 #include <asm/uaccess.h>
34 #include <asm/termios.h>
36 #include "conv.h"
37 #include "socksys.h"
39 static int af_inet_protocols[] = {
40 IPPROTO_ICMP, IPPROTO_ICMP, IPPROTO_IGMP, IPPROTO_IPIP, IPPROTO_TCP,
41 IPPROTO_EGP, IPPROTO_PUP, IPPROTO_UDP, IPPROTO_IDP, IPPROTO_RAW,
42 0, 0, 0, 0, 0, 0,
45 #ifndef DEBUG_SOLARIS_KMALLOC
47 #define mykmalloc kmalloc
48 #define mykfree kfree
50 #else
52 extern void * mykmalloc(size_t s, int gfp);
53 extern void mykfree(void *);
55 #endif
57 static unsigned int (*sock_poll)(struct file *, poll_table *);
59 static struct file_operations socksys_file_ops = {
60 /* Currently empty */
63 static int socksys_open(struct inode * inode, struct file * filp)
65 int family, type, protocol, fd;
66 struct dentry *dentry;
67 int (*sys_socket)(int,int,int) =
68 (int (*)(int,int,int))SUNOS(97);
69 struct sol_socket_struct * sock;
71 family = ((iminor(inode) >> 4) & 0xf);
72 switch (family) {
73 case AF_UNIX:
74 type = SOCK_STREAM;
75 protocol = 0;
76 break;
77 case AF_INET:
78 protocol = af_inet_protocols[iminor(inode) & 0xf];
79 switch (protocol) {
80 case IPPROTO_TCP: type = SOCK_STREAM; break;
81 case IPPROTO_UDP: type = SOCK_DGRAM; break;
82 default: type = SOCK_RAW; break;
84 break;
85 default:
86 type = SOCK_RAW;
87 protocol = 0;
88 break;
91 fd = sys_socket(family, type, protocol);
92 if (fd < 0)
93 return fd;
95 * N.B. The following operations are not legal!
97 * No shit. WTF is it supposed to do, anyway?
99 * Try instead:
100 * d_delete(filp->f_dentry), then d_instantiate with sock inode
102 dentry = filp->f_dentry;
103 filp->f_dentry = dget(fcheck(fd)->f_dentry);
104 filp->f_dentry->d_inode->i_rdev = inode->i_rdev;
105 filp->f_dentry->d_inode->i_flock = inode->i_flock;
106 SOCKET_I(filp->f_dentry->d_inode)->file = filp;
107 filp->f_op = &socksys_file_ops;
108 sock = (struct sol_socket_struct*)
109 mykmalloc(sizeof(struct sol_socket_struct), GFP_KERNEL);
110 if (!sock) return -ENOMEM;
111 SOLDD(("sock=%016lx(%016lx)\n", sock, filp));
112 sock->magic = SOLARIS_SOCKET_MAGIC;
113 sock->modcount = 0;
114 sock->state = TS_UNBND;
115 sock->offset = 0;
116 sock->pfirst = sock->plast = NULL;
117 filp->private_data = sock;
118 SOLDD(("filp->private_data %016lx\n", filp->private_data));
120 sys_close(fd);
121 dput(dentry);
122 return 0;
125 static int socksys_release(struct inode * inode, struct file * filp)
127 struct sol_socket_struct * sock;
128 struct T_primsg *it;
130 /* XXX: check this */
131 sock = (struct sol_socket_struct *)filp->private_data;
132 SOLDD(("sock release %016lx(%016lx)\n", sock, filp));
133 it = sock->pfirst;
134 while (it) {
135 struct T_primsg *next = it->next;
137 SOLDD(("socksys_release %016lx->%016lx\n", it, next));
138 mykfree((char*)it);
139 it = next;
141 filp->private_data = NULL;
142 SOLDD(("socksys_release %016lx\n", sock));
143 mykfree((char*)sock);
144 return 0;
147 static unsigned int socksys_poll(struct file * filp, poll_table * wait)
149 struct inode *ino;
150 unsigned int mask = 0;
152 ino=filp->f_dentry->d_inode;
153 if (ino && S_ISSOCK(ino->i_mode)) {
154 struct sol_socket_struct *sock;
155 sock = (struct sol_socket_struct*)filp->private_data;
156 if (sock && sock->pfirst) {
157 mask |= POLLIN | POLLRDNORM;
158 if (sock->pfirst->pri == MSG_HIPRI)
159 mask |= POLLPRI;
162 if (sock_poll)
163 mask |= (*sock_poll)(filp, wait);
164 return mask;
167 static struct file_operations socksys_fops = {
168 .open = socksys_open,
169 .release = socksys_release,
172 int __init
173 init_socksys(void)
175 int ret;
176 struct file * file;
177 int (*sys_socket)(int,int,int) =
178 (int (*)(int,int,int))SUNOS(97);
179 int (*sys_close)(unsigned int) =
180 (int (*)(unsigned int))SYS(close);
182 ret = register_chrdev (30, "socksys", &socksys_fops);
183 if (ret < 0) {
184 printk ("Couldn't register socksys character device\n");
185 return ret;
187 ret = sys_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
188 if (ret < 0) {
189 printk ("Couldn't create socket\n");
190 return ret;
193 devfs_mk_cdev(MKDEV(30, 0), S_IFCHR|S_IRUSR|S_IWUSR, "socksys");
195 file = fcheck(ret);
196 /* N.B. Is this valid? Suppose the f_ops are in a module ... */
197 socksys_file_ops = *file->f_op;
198 sys_close(ret);
199 sock_poll = socksys_file_ops.poll;
200 socksys_file_ops.poll = socksys_poll;
201 socksys_file_ops.release = socksys_release;
202 return 0;
205 void
206 cleanup_socksys(void)
208 if (unregister_chrdev(30, "socksys"))
209 printk ("Couldn't unregister socksys character device\n");
210 devfs_remove ("socksys");