New developer version 0.6.8; added select () function; added demonstrating example...
[ZeXOS.git] / kernel / core / ioctl.c
blob2b84590006ccf451f8c2d37993cca0b65129ba78
1 /*
2 * ZeX/OS
3 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <system.h>
21 #include <string.h>
22 #include <config.h>
23 #include <ioctl.h>
25 int ioctl_call (unsigned id, void *buf, int l)
27 switch (id) {
28 case IOIFADDRSET:
30 struct ioifaddr_t *io = buf;
32 if (l != sizeof (struct ioifaddr_t))
33 return -1;
35 netif_t *netif = netif_findbyname (io->dev);
37 if (!netif)
38 return -1;
40 netif_ip_addr (netif, io->ipv4, IF_CFG_TYPE_STATIC);
41 netif_ipv6_addr (netif, io->ipv6, IF_CFG_TYPE_STATIC);
43 return 0;
45 case IOIFADDRGET:
47 struct ioifaddr_t *io = buf;
49 if (l != sizeof (struct ioifaddr_t))
50 return -1;
52 netif_t *netif = netif_findbyname (io->dev);
54 if (!netif)
55 return -1;
57 memcpy (&io->ipv4, &netif->ip, sizeof (net_ipv4));
58 memcpy (&io->ipv6, netif->ipv6, sizeof (net_ipv6));
60 return 0;
62 case IOATAREAD:
64 struct ioatarq_t *io = buf;
66 if (l != sizeof (struct ioatarq_t))
67 return -1;
69 dev_t *dev = dev_find (io->dev);
71 if (!dev)
72 return -1;
74 partition_t p;
75 p.base_io = 0;
77 switch (io->dev[7]) {
78 case 'a':
79 p.id = 0;
80 p.base_io = 0x1F0;
81 break;
82 case 'b':
83 p.id = 1;
84 p.base_io = 0x1F0;
85 break;
86 case 'c':
87 p.id = 0;
88 p.base_io = 0x170;
89 break;
90 case 'd':
91 p.id = 1;
92 p.base_io = 0x170;
93 break;
96 if (!dev->handler (DEV_ACT_READ, &p, io->data, "", io->sector))
97 return -1;
99 return 0;
101 case IOATAWRITE:
103 struct ioatarq_t *io = buf;
105 if (l != sizeof (struct ioatarq_t))
106 return -1;
108 dev_t *dev = dev_find (io->dev);
110 if (!dev)
111 return -1;
113 partition_t p;
114 p.base_io = 0;
116 switch (io->dev[7]) {
117 case 'a':
118 p.id = 0;
119 p.base_io = 0x1F0;
120 break;
121 case 'b':
122 p.id = 1;
123 p.base_io = 0x1F0;
124 break;
125 case 'c':
126 p.id = 0;
127 p.base_io = 0x170;
128 break;
129 case 'd':
130 p.id = 1;
131 p.base_io = 0x170;
132 break;
135 if (!dev->handler (DEV_ACT_WRITE, &p, io->data, "", io->sector))
136 return -1;
138 return 0;
142 return 1;