2 meinOS - A unix-like x86 microkernel operating system
3 Copyright (C) 2008 Janosch Gräf <janosch.graef@gmx.net>
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/>.
30 static llist_t cdrom_devices
;
32 static ssize_t
cdrom_devfs_read(devfs_dev_t
*devfs
,void *buf
,size_t count
,off_t offset
) {
33 struct cdrom_device
*dev
= devfs
->user_data
;
35 size_t lba
= offset
/dev
->block_size
;
36 size_t off
= offset
%dev
->block_size
;
37 size_t count_rem
= count
;
40 size_t count_cur
= off
+count_rem
>dev
->block_size
?dev
->block_size
-off
:count_rem
;
41 void *cdrom_buf
= cdrom_read(dev
,lba
,1);
42 memcpy(buf
,cdrom_buf
+off
,count_cur
);
45 count_rem
-= count_cur
;
52 static int cdrom_device_init(char *name
) {
53 struct cdrom_device
*dev
= cdrom_device_create(name
);
55 if (cdrom_inquiry(dev
)==0) {
56 if (cdrom_start(dev
,1,1)==0) {
57 if (cdrom_read_capacity(dev
)==0) {
59 asprintf(&devname
,"cdrom%d",llist_size(cdrom_devices
));
60 dev
->devfs
= devfs_createdev(devname
);
62 if (dev
->devfs
!=NULL
) {
63 devfs_onread(dev
->devfs
,cdrom_devfs_read
);
64 dev
->devfs
->user_data
= dev
;
65 llist_push(cdrom_devices
,dev
);
72 cdrom_device_destroy(dev
);
76 cdrom_device_destroy(dev
);
80 static int cdrom_init() {
81 if (cdrom_buf_init()==-1) return -1;
83 cdrom_devices
= llist_create();
85 llist_t list
= rpc_list();
87 while ((name
= llist_pop(list
))) {
88 if (strncmp(name
,"scsi_request_atapi",18)==0) {
89 char *dev
= name
+13; // dev = "atapiXX"
90 if (cdrom_device_init(dev
)==-1) fprintf(stderr
,"Could not initialize ATAPI device %s\n",dev
);
99 static int cdrom_destroy() {
100 struct cdrom_device
*dev
;
101 while ((dev
= llist_pop(cdrom_devices
))) {
102 devfs_removedev(dev
->devfs
);
103 cdrom_device_destroy(dev
);
105 llist_destroy(cdrom_devices
);
109 int main(int argc
,char *argv
[]) {