From kevin at tyndur.org Sat Jan 3 21:19:05 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 3 Jan 2009 21:19:05 +0100 Subject: [tyndur-devel] [PATCH] cdi: CD-ROM-Unterstuetzung Message-ID: <1231013945-17825-1-git-send-email-kevin@tyndur.org> + cdi: Storage: Zusaetzliche Funktionen get_size() und get_block_size(), da SCSI-Geraete die Variablen nicht haben + cdi: SCSI: Grundfunktionalitaet + cdi: SCSI: Storage-Backend scsi/disk (momentan nur fuer CD-ROM geeignet) * cdi: Storage nimmt jetzt auch SCSI-Geraete * cdi: Storage-Treiber und -Geraete werden einzeln initialisiert * ata/floppy: An geaenderte Interfaces geanpasst --- src/modules/cdi/ata/atapi.c | 3 + src/modules/cdi/ata/device.c | 19 ++- src/modules/cdi/ata/device.h | 6 +- src/modules/cdi/ata/main.c | 4 +- src/modules/cdi/floppy/device.c | 29 +++- src/modules/cdi/floppy/device.h | 6 +- src/modules/cdi/floppy/main.c | 8 +- src/modules/cdi/include/cdi.h | 3 +- src/modules/cdi/include/cdi/scsi.h | 86 +++++++++++ src/modules/cdi/include/cdi/storage.h | 19 ++- src/modules/cdi/lib/cdi.c | 1 + src/modules/cdi/lib/scsi/disk.c | 264 +++++++++++++++++++++++++++++++++ src/modules/cdi/lib/scsi/driver.c | 56 +++++++ src/modules/cdi/lib/storage.c | 89 ++++++++---- 14 files changed, 546 insertions(+), 47 deletions(-) create mode 100644 src/modules/cdi/include/cdi/scsi.h create mode 100644 src/modules/cdi/lib/scsi/disk.c create mode 100644 src/modules/cdi/lib/scsi/driver.c diff --git a/src/modules/cdi/ata/atapi.c b/src/modules/cdi/ata/atapi.c index 67dc140..ecff315 100644 --- a/src/modules/cdi/ata/atapi.c +++ b/src/modules/cdi/ata/atapi.c @@ -86,7 +86,10 @@ int atapi_drv_identify(struct ata_device* dev) void atapi_init_device(struct cdi_device* device) { + struct cdi_scsi_device* scsi = (struct cdi_scsi_device*) device; + scsi->type = CDI_STORAGE; + cdi_scsi_device_init(scsi); } void atapi_remove_device(struct cdi_device* device) diff --git a/src/modules/cdi/ata/device.c b/src/modules/cdi/ata/device.c index f9ccf21..b9763d4 100644 --- a/src/modules/cdi/ata/device.c +++ b/src/modules/cdi/ata/device.c @@ -333,6 +333,8 @@ void ata_remove_controller(struct ata_controller* controller) void ata_init_device(struct cdi_device* device) { + struct ata_device* dev = (struct ata_device*) device; + cdi_storage_device_init(&dev->dev.storage); } void ata_remove_device(struct cdi_device* device) @@ -344,7 +346,7 @@ void ata_remove_device(struct cdi_device* device) /** * Blocks von einem ATA(PI) Geraet lesen */ -int ata_read_blocks(struct cdi_storage_device* device, uint64_t block, +int ata_read_blocks(struct cdi_device* device, uint64_t block, uint64_t count, void* buffer) { struct ata_device* dev = (struct ata_device*) device; @@ -374,7 +376,7 @@ int ata_read_blocks(struct cdi_storage_device* device, uint64_t block, /** * Blocks auf ein ATA(PI) Geraet schreiben */ -int ata_write_blocks(struct cdi_storage_device* device, uint64_t block, +int ata_write_blocks(struct cdi_device* device, uint64_t block, uint64_t count, void* buffer) { struct ata_device* dev = (struct ata_device*) device; @@ -401,3 +403,16 @@ int ata_write_blocks(struct cdi_storage_device* device, uint64_t block, } } +uint64_t ata_get_size(struct cdi_device* device) +{ + struct cdi_storage_device* storage = (struct cdi_storage_device*) device; + + return storage->block_size * storage->block_count; +} + +uint64_t ata_get_block_size(struct cdi_device* device) +{ + struct cdi_storage_device* storage = (struct cdi_storage_device*) device; + + return storage->block_size; +} diff --git a/src/modules/cdi/ata/device.h b/src/modules/cdi/ata/device.h index 140f037..eaa890a 100644 --- a/src/modules/cdi/ata/device.h +++ b/src/modules/cdi/ata/device.h @@ -411,11 +411,13 @@ void ata_init_controller(struct ata_controller* controller); void ata_remove_controller(struct ata_controller* controller); void ata_init_device(struct cdi_device* device); void ata_remove_device(struct cdi_device* device); -int ata_read_blocks(struct cdi_storage_device* device, uint64_t block, +int ata_read_blocks(struct cdi_device* device, uint64_t block, uint64_t count, void* buffer); -int ata_write_blocks(struct cdi_storage_device* device, uint64_t block, +int ata_write_blocks(struct cdi_device* device, uint64_t block, uint64_t count, void* buffer); +uint64_t ata_get_size(struct cdi_device* device); +uint64_t ata_get_block_size(struct cdi_device* device); // Einen ATA-Request absenden und ausfuehren int ata_request(struct ata_request* request); diff --git a/src/modules/cdi/ata/main.c b/src/modules/cdi/ata/main.c index 750f7b2..18e7225 100644 --- a/src/modules/cdi/ata/main.c +++ b/src/modules/cdi/ata/main.c @@ -80,7 +80,7 @@ static void ata_driver_init() // Konstruktor der Vaterklasse cdi_storage_driver_init((struct cdi_storage_driver*) &driver_storage); cdi_scsi_driver_init((struct cdi_scsi_driver*) &driver_scsi); - + // Namen setzen driver_storage.drv.name = driver_storage_name; driver_scsi.drv.name = driver_scsi_name; @@ -91,6 +91,8 @@ static void ata_driver_init() driver_storage.drv.remove_device = ata_remove_device; driver_storage.read_blocks = ata_read_blocks; driver_storage.write_blocks = ata_write_blocks; + driver_storage.get_size = ata_get_size; + driver_storage.get_block_size = ata_get_block_size; driver_scsi.drv.destroy = atapi_driver_destroy; driver_scsi.drv.init_device = atapi_init_device; diff --git a/src/modules/cdi/floppy/device.c b/src/modules/cdi/floppy/device.c index 6614e1e..4435630 100644 --- a/src/modules/cdi/floppy/device.c +++ b/src/modules/cdi/floppy/device.c @@ -796,6 +796,8 @@ void floppy_init_device(struct cdi_device* device) dev->dev.block_size = FLOPPY_SECTOR_SIZE(dev); dev->dev.block_count = FLOPPY_SECTOR_COUNT(dev); + + cdi_storage_device_init(&dev->dev); } /** @@ -808,7 +810,7 @@ void floppy_remove_device(struct cdi_device* device) /** * Sektoren einlesen */ -int floppy_read_blocks(struct cdi_storage_device* dev, uint64_t block, +int floppy_read_blocks(struct cdi_device* dev, uint64_t block, uint64_t count, void* buffer) { struct floppy_device* device = (struct floppy_device*) dev; @@ -823,7 +825,7 @@ int floppy_read_blocks(struct cdi_storage_device* dev, uint64_t block, // Wenn das schief geht, wird mehrmals probiert for (j = 0; (j < 5) && (result != 0); j++) { result = floppy_drive_sector_read(device, (uint32_t) block + i, - buffer + i * dev->block_size); + buffer + i * device->dev.block_size); } } @@ -833,7 +835,7 @@ int floppy_read_blocks(struct cdi_storage_device* dev, uint64_t block, /** * Sektoren schreiben */ -int floppy_write_blocks(struct cdi_storage_device* dev, uint64_t block, +int floppy_write_blocks(struct cdi_device* dev, uint64_t block, uint64_t count, void* buffer) { struct floppy_device* device = (struct floppy_device*) dev; @@ -848,13 +850,32 @@ int floppy_write_blocks(struct cdi_storage_device* dev, uint64_t block, // Wenn das schief geht, wird mehrmals probiert for (j = 0; (j < 5) && (result != 0); j++) { result = floppy_drive_sector_write(device, (uint32_t) block + i, - buffer + i * dev->block_size); + buffer + i * device->dev.block_size); } } return result; } +/** + * Gibt die Groesse des Mediums zurueck + */ +uint64_t floppy_get_size(struct cdi_device* device) +{ + struct cdi_storage_device* storage = (struct cdi_storage_device*) device; + + return storage->block_size * storage->block_count; +} + +/** + * Gibt die Sektorgroesse des Mediums zurueck + */ +uint64_t floppy_get_block_size(struct cdi_device* device) +{ + struct cdi_storage_device* storage = (struct cdi_storage_device*) device; + + return storage->block_size; +} /** * IRQ-Handler fuer den Kontroller; Erhoeht nur den IRQ-Zaehler in der diff --git a/src/modules/cdi/floppy/device.h b/src/modules/cdi/floppy/device.h index 24d16f9..6c3bfcf 100644 --- a/src/modules/cdi/floppy/device.h +++ b/src/modules/cdi/floppy/device.h @@ -137,10 +137,12 @@ int floppy_init_controller(struct floppy_controller* controller); void floppy_init_device(struct cdi_device* device); void floppy_remove_device(struct cdi_device* device); -int floppy_read_blocks(struct cdi_storage_device* device, uint64_t block, +int floppy_read_blocks(struct cdi_device* device, uint64_t block, uint64_t count, void* buffer); -int floppy_write_blocks(struct cdi_storage_device* device, uint64_t block, +int floppy_write_blocks(struct cdi_device* device, uint64_t block, uint64_t count, void* buffer); +uint64_t floppy_get_size(struct cdi_device* device); +uint64_t floppy_get_block_size(struct cdi_device* device); void floppy_handle_interrupt(struct cdi_device* device); diff --git a/src/modules/cdi/floppy/main.c b/src/modules/cdi/floppy/main.c index 435ff1f..aa32ed5 100644 --- a/src/modules/cdi/floppy/main.c +++ b/src/modules/cdi/floppy/main.c @@ -87,7 +87,7 @@ static int floppy_driver_init(struct floppy_driver* driver) // Konstruktor der Vaterklasse cdi_storage_driver_init((struct cdi_storage_driver*) driver); - + // Namen setzen driver->storage.drv.name = driver_name; @@ -95,9 +95,11 @@ static int floppy_driver_init(struct floppy_driver* driver) driver->storage.drv.destroy = floppy_driver_destroy; driver->storage.drv.init_device = floppy_init_device; driver->storage.drv.remove_device = floppy_remove_device; - driver->storage.read_blocks = floppy_read_blocks; + driver->storage.read_blocks = floppy_read_blocks; driver->storage.write_blocks = floppy_write_blocks; - + driver->storage.get_size = floppy_get_size; + driver->storage.get_block_size = floppy_get_block_size; + // Geraete erstellen (TODO: Was wenn eines oder beide nicht vorhanden // sind?) for (i = 0; i < 2; i++) { diff --git a/src/modules/cdi/include/cdi.h b/src/modules/cdi/include/cdi.h index 42e4643..5fb7025 100644 --- a/src/modules/cdi/include/cdi.h +++ b/src/modules/cdi/include/cdi.h @@ -23,7 +23,8 @@ typedef enum { CDI_UNKNOWN = 0, CDI_NETWORK = 1, - CDI_STORAGE = 2 + CDI_STORAGE = 2, + CDI_SCSI = 3, } cdi_device_type_t; struct cdi_driver; diff --git a/src/modules/cdi/include/cdi/scsi.h b/src/modules/cdi/include/cdi/scsi.h new file mode 100644 index 0000000..78f0c30 --- /dev/null +++ b/src/modules/cdi/include/cdi/scsi.h @@ -0,0 +1,86 @@ +#ifndef _CDI_SCSI_H_ +#define _CDI_SCSI_H_ + +#include +#include + +#include "cdi.h" + +// SCSI-Paket +struct cdi_scsi_packet { + // Buffer zum Senden oder Empfangen von Daten + void *buffer; + + // Groesse des Buffers + size_t bufsize; + + // Ob gelesen oder geschrieben werden soll + enum { + CDI_SCSI_NODATA, + CDI_SCSI_READ, + CDI_SCSI_WRITE, + } direction; + + // SCSI Command + uint8_t command[16]; + + // Groesse des SCSI Commands + size_t cmdsize; +}; + +// SCSI-Geraet +struct cdi_scsi_device { + + struct cdi_device dev; + + // Geraetetyp, der ueber SCSI angesteuert wird + cdi_device_type_t type; + +}; + +// SCSI-Driver +struct cdi_scsi_driver { + struct cdi_driver drv; + + int (*request)(struct cdi_scsi_device *device,struct cdi_scsi_packet *packet); +}; + +/** + * Ein SCSI-Paket allozieren + * + * @param size Benoetigte Groesse + * + * @return Pointer auf das Paket oder NULL im Fehlerfall + */ +struct cdi_scsi_packet* cdi_scsi_packet_alloc(size_t size); + +/** + * Ein SCSI-Paket freigeben + * + * @param packet Pointer auf das Paket + */ +void cdi_scsi_packet_free(struct cdi_scsi_packet* packet); + +/** + * Initialisiert die Datenstrukturen fuer einen SCSI-Treiber + */ +void cdi_scsi_driver_init(struct cdi_scsi_driver* driver); + +/** + * Deinitialisiert die Datenstrukturen fuer einen SCSI-Treiber + */ +void cdi_scsi_driver_destroy(struct cdi_scsi_driver* driver); + +/** + * Registiert einen SCSI-Treiber + */ +void cdi_scsi_driver_register(struct cdi_scsi_driver* driver); + +/** + * Initialisiert ein neues SCSI-Geraet + * + * Der Typ der Geraetes muss bereits gesetzt sein + */ +void cdi_scsi_device_init(struct cdi_scsi_device* device); + +#endif diff --git a/src/modules/cdi/include/cdi/storage.h b/src/modules/cdi/include/cdi/storage.h index 73ae245..781a158 100644 --- a/src/modules/cdi/include/cdi/storage.h +++ b/src/modules/cdi/include/cdi/storage.h @@ -40,7 +40,7 @@ struct cdi_storage_driver { * * @return 0 bei Erfolg, -1 im Fehlerfall. */ - int (*read_blocks)(struct cdi_storage_device* device, uint64_t start, + int (*read_blocks)(struct cdi_device* device, uint64_t start, uint64_t count, void* buffer); /** @@ -53,8 +53,18 @@ struct cdi_storage_driver { * * @return 0 bei Erfolg, -1 im Fehlerfall */ - int (*write_blocks)(struct cdi_storage_device* device, uint64_t start, + int (*write_blocks)(struct cdi_device* device, uint64_t start, uint64_t count, void* buffer); + + /** + * Gibt die Groesse des Mediums in Bytes zurueck + */ + uint64_t (*get_size)(struct cdi_device* device); + + /** + * Gibt die Blockgroesse des Geraets in Bytes zurueck + */ + uint64_t (*get_block_size)(struct cdi_device* device); }; @@ -75,6 +85,11 @@ void cdi_storage_driver_destroy(struct cdi_storage_driver* driver); */ void cdi_storage_driver_register(struct cdi_storage_driver* driver); +/** + * Initialisiert einen Massenspeicher + */ +void cdi_storage_device_init(struct cdi_storage_device* device); + #endif /*\@}*/ diff --git a/src/modules/cdi/lib/cdi.c b/src/modules/cdi/lib/cdi.c index d8c7819..487887e 100644 --- a/src/modules/cdi/lib/cdi.c +++ b/src/modules/cdi/lib/cdi.c @@ -86,6 +86,7 @@ void cdi_run_drivers(void) for (j = 0; (device = cdi_list_get(driver->devices, j)); j++) { device->driver = driver; + device->type = driver->type; if (driver->init_device) { driver->init_device(device); diff --git a/src/modules/cdi/lib/scsi/disk.c b/src/modules/cdi/lib/scsi/disk.c new file mode 100644 index 0000000..9bd5a74 --- /dev/null +++ b/src/modules/cdi/lib/scsi/disk.c @@ -0,0 +1,264 @@ +/* + * Copyright (C) 2008 Mathias Gottschlag + * Copyright (C) 2009 Kevin Wolf + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include +#include +#include + +#include +#include +#include + +#define big_endian_word(x) ((((x) & 0xFF) << 8) | (((x) & 0xFF00) >> 8)) +#define big_endian_dword(x) \ + ((big_endian_word((x) & 0xFFFF) << 16) | \ + (big_endian_word((x) >> 16))) + +static int cdi_scsi_disk_read(struct cdi_device* device, + uint64_t start, uint64_t count, void* buffer); + +static int cdi_scsi_disk_write(struct cdi_device* device, + uint64_t start, uint64_t count, void* buffer); + +static uint64_t cdi_scsi_disk_get_size(struct cdi_device* device); +static uint64_t cdi_scsi_disk_get_block_size(struct cdi_device* device); + +struct cdi_storage_driver cdi_scsi_disk_driver = { + .read_blocks = cdi_scsi_disk_read, + .write_blocks = cdi_scsi_disk_write, + .get_size = cdi_scsi_disk_get_size, + .get_block_size = cdi_scsi_disk_get_block_size, +}; + +// TODO: This is kind of incomplete... -.- +// FIXME Das ist alles sehr CD-ROM-spezifisch hartkodiert... + +union cdrom_command +{ + struct + { + uint8_t opcode; + uint8_t reserved0; + uint32_t address; + uint8_t reserved1; + uint16_t length; + uint8_t reserved2; + } __attribute__ ((packed)) dfl; + struct + { + uint8_t opcode; + uint8_t reserved0; + uint32_t address; + uint32_t length; + uint16_t reserved1; + } __attribute__ ((packed)) ext; +}; + +static int cdrom_read_sector( + struct cdi_scsi_device *device, uint32_t sector, char *buffer) +{ + struct cdi_scsi_packet packet; + struct cdi_scsi_driver* drv = (struct cdi_scsi_driver*) device->dev.driver; + union cdrom_command* cmd = (union cdrom_command*) &packet.command; + + memset(&packet, 0, sizeof(packet)); + packet.direction = CDI_SCSI_READ; + packet.buffer = buffer; + packet.bufsize = 2048; + packet.cmdsize = 12; + + cmd->ext.opcode = 0xA8; + cmd->ext.address = big_endian_dword(sector); + cmd->ext.length = 0x01000000; + + if (drv->request(device, &packet)) { + return -1; + } + + return 0; +} + +static int cdrom_capacity(struct cdi_scsi_device *device, + uint32_t* num_sectors, uint32_t* sector_size) +{ + uint32_t buffer[32]; + struct cdi_scsi_packet packet; + struct cdi_scsi_driver* drv = (struct cdi_scsi_driver*) device->dev.driver; + union cdrom_command* cmd = (union cdrom_command*) &packet.command; + + memset(&packet, 0, sizeof(packet)); + packet.direction = CDI_SCSI_READ; + packet.buffer = buffer; + packet.bufsize = sizeof(buffer); + packet.cmdsize = 12; + + cmd->ext.opcode = 0x25; + + if (drv->request(device, &packet)) { + return -1; + } + + *num_sectors = big_endian_dword(buffer[0]); + *sector_size = big_endian_dword(buffer[1]); + + return 0; +} + +#if 0 +static int cdrom_lock_device(FsSCSIDevice *device, int index, int lock) +{ + // Lock drive + FsSCSIPacket packet; + memset(&packet, 0, sizeof(FsSCSIPacket)); + packet.direction = CDI_SCSI_NO_DATA; + ((union cdrom_command*)packet.command)->dfl.opcode = 0x1E; + packet.command[4] = 1; + packet.buffer = 0; + packet.length = 0; + packet.commandsize = 12; + uint32_t status = device->request(device, &packet); + if (status) + { + kePrint("cdrom %d: Lock failed, %x\n", index, status); + fsCloseSCSIDevice(device); + return KE_ERROR_UNKNOWN; + } + return 0; +} + +static void cdrom_sense(FsSCSIDevice *device, uint32_t index) +{ + char sense_data[18]; + FsSCSIPacket packet; + packet.direction = CDI_SCSI_READ; + packet.buffer = sense_data; + packet.length = 18; + packet.commandsize = 12; + ((union cdrom_command*)packet.command)->dfl.opcode = 0x12; +} +#endif + +int cdrom_init(struct cdi_scsi_device* device) +{ + // Send inquiry command + struct cdi_scsi_driver* drv = (struct cdi_scsi_driver*) device->dev.driver; + struct cdi_scsi_packet packet; + uint32_t status; + unsigned char inqdata[96]; + + memset(&packet, 0, sizeof(packet)); + memset(inqdata, 0xF0, sizeof(inqdata)); + + packet.direction = CDI_SCSI_READ; + packet.buffer = inqdata; + packet.bufsize = 96; + packet.cmdsize = 12; + + ((union cdrom_command*)packet.command)->dfl.opcode = 0x12; + packet.command[4] = 96; + status = drv->request(device, &packet); + if (status) + { + return -1; + } + +#if 0 + if (cdrom_lock_device(device, index, 1)) + return KE_ERROR_UNKNOWN; +#endif + + // Start drive + packet.direction = CDI_SCSI_NODATA; + ((union cdrom_command*)packet.command)->dfl.opcode = 0x1B; + packet.buffer = 0; + packet.bufsize = 0; + packet.command[4] = 0; + packet.command[4] = 3; + packet.cmdsize = 12; + + status = drv->request(device, &packet); + if (status) + { + printf("cdrom %d: Start failed, %x\n", index, status); + return -1; + } + + return 0; +} + +static int cdi_scsi_disk_read(struct cdi_device* device, + uint64_t start, uint64_t count, void* buffer) +{ + struct cdi_scsi_device* dev = (struct cdi_scsi_device*) device; + + while (count--) { + if (cdrom_read_sector(dev, start, buffer)) { + return -1; + } + start ++; + buffer += 2048; + } + + return 0; +} + +static int cdi_scsi_disk_write(struct cdi_device* device, + uint64_t start, uint64_t count, void* buffer) +{ + return -1; +} + +static uint64_t cdi_scsi_disk_get_size(struct cdi_device* device) +{ + struct cdi_scsi_device* dev = (struct cdi_scsi_device*) device; + uint32_t num_sectors, sector_size; + + + // TODO Einmal beim Initialisieren eines Mediums einlesen und dann bei + // jedem Aufruf wiederverwenden + cdrom_capacity(dev, &num_sectors, §or_size); + + return num_sectors * sector_size; +} + +static uint64_t cdi_scsi_disk_get_block_size(struct cdi_device* device) +{ + struct cdi_scsi_device* dev = (struct cdi_scsi_device*) device; + uint32_t num_sectors, sector_size; + + + // TODO s.o. + cdrom_capacity(dev, &num_sectors, §or_size); + + return sector_size; +} + +int lostio_mst_if_newdev(struct cdi_device* device); + +void cdi_scsi_disk_init(struct cdi_scsi_device* device) +{ + if (cdrom_init(device) == 0) { + // LostIO-Verzeichnisknoten anlegen + lostio_mst_if_newdev(&device->dev); + } +} diff --git a/src/modules/cdi/lib/scsi/driver.c b/src/modules/cdi/lib/scsi/driver.c new file mode 100644 index 0000000..745bd25 --- /dev/null +++ b/src/modules/cdi/lib/scsi/driver.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2009 Kevin Wolf + * + * This program is free software. It comes without any warranty, to + * the extent permitted by applicable law. You can redistribute it + * and/or modify it under the terms of the Do What The Fuck You Want + * To Public License, Version 2, as published by Sam Hocevar. See + * http://sam.zoy.org/projects/COPYING.WTFPL for more details. + */ + +#include +#include +#include +#include +#include + +#include "cdi/scsi.h" + +extern void cdi_scsi_disk_init(struct cdi_scsi_device* device); + +/** + * Initialisiert die Datenstrukturen fuer einen SCSI-Treiber + */ +void cdi_scsi_driver_init(struct cdi_scsi_driver* driver) +{ + driver->drv.type = CDI_SCSI; + cdi_driver_init((struct cdi_driver*) driver); +} + +/** + * Deinitialisiert die Datenstrukturen fuer einen SCSI-Treiber + */ +void cdi_scsi_driver_destroy(struct cdi_scsi_driver* driver) +{ + cdi_driver_destroy((struct cdi_driver*) driver); +} + +/** + * Initialisiert ein neues SCSI-Geraet + * + * Der Typ der Geraetes muss bereits gesetzt sein + */ +void cdi_scsi_device_init(struct cdi_scsi_device* device) +{ + if (device->type == CDI_STORAGE) { + cdi_scsi_disk_init(device); + } +} + +/** + * Registiert den Treiber fuer SCSI-Geraete + */ +void cdi_scsi_driver_register(struct cdi_scsi_driver* driver) +{ + cdi_driver_register((struct cdi_driver*) driver); +} diff --git a/src/modules/cdi/lib/storage.c b/src/modules/cdi/lib/storage.c index 9dd9746..16e4a7e 100644 --- a/src/modules/cdi/lib/storage.c +++ b/src/modules/cdi/lib/storage.c @@ -17,7 +17,7 @@ #include "cdi/storage.h" static void lostio_mst_if_init(void); -static int lostio_mst_if_newdev(struct cdi_storage_device* device); +int lostio_mst_if_newdev(struct cdi_device* device); static size_t lostio_mst_read_handler(lostio_filehandle_t* fh, void* buf, size_t blocksize, size_t blockcount); @@ -63,8 +63,6 @@ void cdi_storage_driver_destroy(struct cdi_storage_driver* driver) void cdi_storage_driver_register(struct cdi_storage_driver* driver) { static int initialized = 0; - int i; - struct cdi_storage_device* device; cdi_driver_register((struct cdi_driver*) driver); @@ -72,11 +70,32 @@ void cdi_storage_driver_register(struct cdi_storage_driver* driver) lostio_mst_if_init(); initialized = 1; } +} + +/** + * Initialisiert einen Massenspeicher + */ +void cdi_storage_device_init(struct cdi_storage_device* device) +{ + device->dev.type = CDI_STORAGE; // Geraeteknoten fuer LostIO erstellen - for (i = 0; (device = cdi_list_get(driver->drv.devices, i)); i++) { - lostio_mst_if_newdev(device); + lostio_mst_if_newdev(&device->dev); +} + +extern struct cdi_storage_driver cdi_scsi_disk_driver; + +static struct cdi_storage_driver* get_storage_drv(struct cdi_device* dev) +{ + struct cdi_storage_driver* driver = NULL; + + if (dev->type == CDI_STORAGE) { + driver = (struct cdi_storage_driver*) dev->driver; + } else if (dev->type == CDI_SCSI) { + driver = &cdi_scsi_disk_driver; } + + return driver; } /** @@ -86,12 +105,12 @@ void cdi_storage_driver_register(struct cdi_storage_driver* driver) * @param size Anzahl der zu lesenden Bytes * @param dest Buffer */ -int cdi_storage_read(struct cdi_storage_device* device, uint64_t pos, +int cdi_storage_read(struct cdi_device* device, uint64_t pos, size_t size, void* dest) { - struct cdi_storage_driver* driver = (struct cdi_storage_driver*) device-> - dev.driver; - size_t block_size = device->block_size; + struct cdi_storage_driver* driver = get_storage_drv(device); + size_t block_size = driver->get_block_size(device); + // Start- und Endblock uint64_t block_read_start = pos / block_size; uint64_t block_read_end = (pos + size) / block_size; @@ -128,13 +147,12 @@ int cdi_storage_read(struct cdi_storage_device* device, uint64_t pos, * @param size Anzahl der zu schreibendes Bytes * @param src Buffer */ -int cdi_storage_write(struct cdi_storage_device* device, uint64_t pos, +int cdi_storage_write(struct cdi_device* device, uint64_t pos, size_t size, void* src) { - struct cdi_storage_driver* driver = (struct cdi_storage_driver*) device-> - dev.driver; - - size_t block_size = device->block_size; + struct cdi_storage_driver* driver = get_storage_drv(device); + size_t block_size = driver->get_block_size(device); + uint64_t block_write_start = pos / block_size; uint8_t buffer[block_size]; size_t offset; @@ -206,15 +224,17 @@ static void lostio_mst_if_init() /** * Erstellt den Dateisystemknoten fuer ein Geraet. */ -static int lostio_mst_if_newdev(struct cdi_storage_device* device) +int lostio_mst_if_newdev(struct cdi_device* device) { + struct cdi_storage_driver* driver = get_storage_drv(device); + // Slash vor Pfad angaengen - char path[strlen(device->dev.name) + 2]; - strcpy(path + 1, device->dev.name); + char path[strlen(device->name) + 2]; + strcpy(path + 1, device->name); *path = '/'; - if (vfstree_create_node(path, CDI_LOSTIO_TYPE_MST, device->block_size * - device->block_count, (void*) device, 0) == FALSE) + if (vfstree_create_node(path, CDI_LOSTIO_TYPE_MST, + driver->get_size(device), (void*) device, 0) == FALSE) { return -1; } @@ -227,13 +247,19 @@ static int lostio_mst_if_newdev(struct cdi_storage_device* device) static size_t lostio_mst_read_handler(lostio_filehandle_t* fh, void* buf, size_t blocksize, size_t blockcount) { - struct cdi_storage_device* device = (struct cdi_storage_device*) fh->node-> - data; + struct cdi_device* device = (struct cdi_device*) fh->node->data; + struct cdi_storage_driver* drv = get_storage_drv(device); + size_t size = blocksize * blockcount; + size_t devsize = drv->get_size(device); // Groesse anpassen, wenn ueber das Medium hinaus gelesen werden soll - if (size > (device->block_count * device->block_size - fh->pos)) { - size = device->block_count * device->block_size - fh->pos; + if (size > (devsize - fh->pos)) { + size = devsize - fh->pos; + if (size == 0) { + fh->flags |= LOSTIO_FLAG_EOF; + return 0; + } } // In den uebergebenen Buffer einlesen @@ -253,14 +279,16 @@ static size_t lostio_mst_read_handler(lostio_filehandle_t* fh, static size_t lostio_mst_write_handler(lostio_filehandle_t* fh, size_t blocksize, size_t blockcount, void* data) { - struct cdi_storage_device* device = (struct cdi_storage_device*) fh->node-> - data; + struct cdi_device* device = (struct cdi_device*) fh->node->data; + struct cdi_storage_driver* drv = get_storage_drv(device); + size_t size = blocksize * blockcount; + size_t devsize = drv->get_size(device); size_t result = size; // Groesse anpassen, wenn ueber das Medium hinaus geschrieben werden soll - if (size > (device->block_count * device->block_size - fh->pos)) { - size = device->block_count * device->block_size - fh->pos; + if (size > (devsize - fh->pos)) { + size = devsize - fh->pos; } // Daten schreiben @@ -279,10 +307,11 @@ static size_t lostio_mst_write_handler(lostio_filehandle_t* fh, static int lostio_mst_seek_handler(lostio_filehandle_t* fh, uint64_t offset, int origin) { - struct cdi_storage_device* device = (struct cdi_storage_device*) fh->node-> - data; + struct cdi_device* device = (struct cdi_device*) fh->node->data; + struct cdi_storage_driver* drv = get_storage_drv(device); + uint64_t new_pos = fh->pos; - uint64_t size = device->block_size * device->block_count; + uint64_t size = drv->get_size(device); switch (origin) { case SEEK_SET: -- 1.5.4.5 From toni at tyndur.org Sat Jan 3 21:52:46 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 3 Jan 2009 21:52:46 +0100 Subject: [tyndur-devel] [PATCH] cdi: CD-ROM-Unterstuetzung In-Reply-To: <1231013945-17825-1-git-send-email-kevin@tyndur.org> References: <1231013945-17825-1-git-send-email-kevin@tyndur.org> Message-ID: <20090103205246.GA31201@thales.produktiv.lan> On Sat, Jan 03 21:19, Kevin Wolf wrote: > + cdi: Storage: Zusaetzliche Funktionen get_size() und get_block_size(), da SCSI-Geraete die Variablen nicht haben > + cdi: SCSI: Grundfunktionalitaet > + cdi: SCSI: Storage-Backend scsi/disk (momentan nur fuer CD-ROM geeignet) > * cdi: Storage nimmt jetzt auch SCSI-Geraete > * cdi: Storage-Treiber und -Geraete werden einzeln initialisiert > * ata/floppy: An geaenderte Interfaces geanpasst > --- > src/modules/cdi/ata/atapi.c | 3 + > src/modules/cdi/ata/device.c | 19 ++- > src/modules/cdi/ata/device.h | 6 +- > src/modules/cdi/ata/main.c | 4 +- > src/modules/cdi/floppy/device.c | 29 +++- > src/modules/cdi/floppy/device.h | 6 +- > src/modules/cdi/floppy/main.c | 8 +- > src/modules/cdi/include/cdi.h | 3 +- > src/modules/cdi/include/cdi/scsi.h | 86 +++++++++++ > src/modules/cdi/include/cdi/storage.h | 19 ++- > src/modules/cdi/lib/cdi.c | 1 + > src/modules/cdi/lib/scsi/disk.c | 264 +++++++++++++++++++++++++++++++++ > src/modules/cdi/lib/scsi/driver.c | 56 +++++++ > src/modules/cdi/lib/storage.c | 89 ++++++++---- > 14 files changed, 546 insertions(+), 47 deletions(-) > create mode 100644 src/modules/cdi/include/cdi/scsi.h > create mode 100644 src/modules/cdi/lib/scsi/disk.c > create mode 100644 src/modules/cdi/lib/scsi/driver.c > > diff --git a/src/modules/cdi/ata/atapi.c b/src/modules/cdi/ata/atapi.c > index 67dc140..ecff315 100644 > --- a/src/modules/cdi/ata/atapi.c > +++ b/src/modules/cdi/ata/atapi.c > @@ -86,7 +86,10 @@ int atapi_drv_identify(struct ata_device* dev) > > void atapi_init_device(struct cdi_device* device) > { > + struct cdi_scsi_device* scsi = (struct cdi_scsi_device*) device; > > + scsi->type = CDI_STORAGE; > + cdi_scsi_device_init(scsi); > } > > void atapi_remove_device(struct cdi_device* device) > diff --git a/src/modules/cdi/ata/device.c b/src/modules/cdi/ata/device.c > index f9ccf21..b9763d4 100644 > --- a/src/modules/cdi/ata/device.c > +++ b/src/modules/cdi/ata/device.c > @@ -333,6 +333,8 @@ void ata_remove_controller(struct ata_controller* controller) > > void ata_init_device(struct cdi_device* device) > { > + struct ata_device* dev = (struct ata_device*) device; > + cdi_storage_device_init(&dev->dev.storage); > } > > void ata_remove_device(struct cdi_device* device) > @@ -344,7 +346,7 @@ void ata_remove_device(struct cdi_device* device) > /** > * Blocks von einem ATA(PI) Geraet lesen > */ > -int ata_read_blocks(struct cdi_storage_device* device, uint64_t block, > +int ata_read_blocks(struct cdi_device* device, uint64_t block, > uint64_t count, void* buffer) > { > struct ata_device* dev = (struct ata_device*) device; > @@ -374,7 +376,7 @@ int ata_read_blocks(struct cdi_storage_device* device, uint64_t block, > /** > * Blocks auf ein ATA(PI) Geraet schreiben > */ > -int ata_write_blocks(struct cdi_storage_device* device, uint64_t block, > +int ata_write_blocks(struct cdi_device* device, uint64_t block, > uint64_t count, void* buffer) > { > struct ata_device* dev = (struct ata_device*) device; > @@ -401,3 +403,16 @@ int ata_write_blocks(struct cdi_storage_device* device, uint64_t block, > } > } > > +uint64_t ata_get_size(struct cdi_device* device) > +{ > + struct cdi_storage_device* storage = (struct cdi_storage_device*) device; > + > + return storage->block_size * storage->block_count; > +} > + > +uint64_t ata_get_block_size(struct cdi_device* device) > +{ > + struct cdi_storage_device* storage = (struct cdi_storage_device*) device; > + > + return storage->block_size; > +} > diff --git a/src/modules/cdi/ata/device.h b/src/modules/cdi/ata/device.h > index 140f037..eaa890a 100644 > --- a/src/modules/cdi/ata/device.h > +++ b/src/modules/cdi/ata/device.h > @@ -411,11 +411,13 @@ void ata_init_controller(struct ata_controller* controller); > void ata_remove_controller(struct ata_controller* controller); > void ata_init_device(struct cdi_device* device); > void ata_remove_device(struct cdi_device* device); > -int ata_read_blocks(struct cdi_storage_device* device, uint64_t block, > +int ata_read_blocks(struct cdi_device* device, uint64_t block, > uint64_t count, void* buffer); > -int ata_write_blocks(struct cdi_storage_device* device, uint64_t block, > +int ata_write_blocks(struct cdi_device* device, uint64_t block, > uint64_t count, void* buffer); > > +uint64_t ata_get_size(struct cdi_device* device); > +uint64_t ata_get_block_size(struct cdi_device* device); > > // Einen ATA-Request absenden und ausfuehren > int ata_request(struct ata_request* request); > diff --git a/src/modules/cdi/ata/main.c b/src/modules/cdi/ata/main.c > index 750f7b2..18e7225 100644 > --- a/src/modules/cdi/ata/main.c > +++ b/src/modules/cdi/ata/main.c > @@ -80,7 +80,7 @@ static void ata_driver_init() > // Konstruktor der Vaterklasse > cdi_storage_driver_init((struct cdi_storage_driver*) &driver_storage); > cdi_scsi_driver_init((struct cdi_scsi_driver*) &driver_scsi); Hm sicher dass dein diff hier korrekt ist? Haben wir da wirklich schon ein cdi_scsi_driver_init drin? :-/ > - > + Und hier haben wir noch eine Whitespace Änderung, sowas aber auch. ;-) > // Namen setzen > driver_storage.drv.name = driver_storage_name; > driver_scsi.drv.name = driver_scsi_name; > @@ -91,6 +91,8 @@ static void ata_driver_init() > driver_storage.drv.remove_device = ata_remove_device; > driver_storage.read_blocks = ata_read_blocks; > driver_storage.write_blocks = ata_write_blocks; > + driver_storage.get_size = ata_get_size; > + driver_storage.get_block_size = ata_get_block_size; > > driver_scsi.drv.destroy = atapi_driver_destroy; > driver_scsi.drv.init_device = atapi_init_device; > diff --git a/src/modules/cdi/floppy/device.c b/src/modules/cdi/floppy/device.c > index 6614e1e..4435630 100644 > --- a/src/modules/cdi/floppy/device.c > +++ b/src/modules/cdi/floppy/device.c > @@ -796,6 +796,8 @@ void floppy_init_device(struct cdi_device* device) > > dev->dev.block_size = FLOPPY_SECTOR_SIZE(dev); > dev->dev.block_count = FLOPPY_SECTOR_COUNT(dev); > + > + cdi_storage_device_init(&dev->dev); > } > > /** > @@ -808,7 +810,7 @@ void floppy_remove_device(struct cdi_device* device) > /** > * Sektoren einlesen > */ > -int floppy_read_blocks(struct cdi_storage_device* dev, uint64_t block, > +int floppy_read_blocks(struct cdi_device* dev, uint64_t block, > uint64_t count, void* buffer) > { > struct floppy_device* device = (struct floppy_device*) dev; > @@ -823,7 +825,7 @@ int floppy_read_blocks(struct cdi_storage_device* dev, uint64_t block, > // Wenn das schief geht, wird mehrmals probiert > for (j = 0; (j < 5) && (result != 0); j++) { > result = floppy_drive_sector_read(device, (uint32_t) block + i, > - buffer + i * dev->block_size); > + buffer + i * device->dev.block_size); > } > } > > @@ -833,7 +835,7 @@ int floppy_read_blocks(struct cdi_storage_device* dev, uint64_t block, > /** > * Sektoren schreiben > */ > -int floppy_write_blocks(struct cdi_storage_device* dev, uint64_t block, > +int floppy_write_blocks(struct cdi_device* dev, uint64_t block, > uint64_t count, void* buffer) > { > struct floppy_device* device = (struct floppy_device*) dev; > @@ -848,13 +850,32 @@ int floppy_write_blocks(struct cdi_storage_device* dev, uint64_t block, > // Wenn das schief geht, wird mehrmals probiert > for (j = 0; (j < 5) && (result != 0); j++) { > result = floppy_drive_sector_write(device, (uint32_t) block + i, > - buffer + i * dev->block_size); > + buffer + i * device->dev.block_size); > } > } > > return result; > } > > +/** > + * Gibt die Groesse des Mediums zurueck > + */ > +uint64_t floppy_get_size(struct cdi_device* device) > +{ > + struct cdi_storage_device* storage = (struct cdi_storage_device*) device; > + > + return storage->block_size * storage->block_count; > +} > + > +/** > + * Gibt die Sektorgroesse des Mediums zurueck > + */ > +uint64_t floppy_get_block_size(struct cdi_device* device) > +{ > + struct cdi_storage_device* storage = (struct cdi_storage_device*) device; > + > + return storage->block_size; > +} > > /** > * IRQ-Handler fuer den Kontroller; Erhoeht nur den IRQ-Zaehler in der > diff --git a/src/modules/cdi/floppy/device.h b/src/modules/cdi/floppy/device.h > index 24d16f9..6c3bfcf 100644 > --- a/src/modules/cdi/floppy/device.h > +++ b/src/modules/cdi/floppy/device.h > @@ -137,10 +137,12 @@ int floppy_init_controller(struct floppy_controller* controller); > > void floppy_init_device(struct cdi_device* device); > void floppy_remove_device(struct cdi_device* device); > -int floppy_read_blocks(struct cdi_storage_device* device, uint64_t block, > +int floppy_read_blocks(struct cdi_device* device, uint64_t block, > uint64_t count, void* buffer); > -int floppy_write_blocks(struct cdi_storage_device* device, uint64_t block, > +int floppy_write_blocks(struct cdi_device* device, uint64_t block, > uint64_t count, void* buffer); > +uint64_t floppy_get_size(struct cdi_device* device); > +uint64_t floppy_get_block_size(struct cdi_device* device); > > void floppy_handle_interrupt(struct cdi_device* device); > > diff --git a/src/modules/cdi/floppy/main.c b/src/modules/cdi/floppy/main.c > index 435ff1f..aa32ed5 100644 > --- a/src/modules/cdi/floppy/main.c > +++ b/src/modules/cdi/floppy/main.c > @@ -87,7 +87,7 @@ static int floppy_driver_init(struct floppy_driver* driver) > > // Konstruktor der Vaterklasse > cdi_storage_driver_init((struct cdi_storage_driver*) driver); > - > + Schon wieder nur leerzeichen entfernt > // Namen setzen > driver->storage.drv.name = driver_name; > > @@ -95,9 +95,11 @@ static int floppy_driver_init(struct floppy_driver* driver) > driver->storage.drv.destroy = floppy_driver_destroy; > driver->storage.drv.init_device = floppy_init_device; > driver->storage.drv.remove_device = floppy_remove_device; > - driver->storage.read_blocks = floppy_read_blocks; > + driver->storage.read_blocks = floppy_read_blocks; Hier auch wieder > driver->storage.write_blocks = floppy_write_blocks; > - > + driver->storage.get_size = floppy_get_size; > + driver->storage.get_block_size = floppy_get_block_size; > + > // Geraete erstellen (TODO: Was wenn eines oder beide nicht vorhanden > // sind?) > for (i = 0; i < 2; i++) { > diff --git a/src/modules/cdi/include/cdi.h b/src/modules/cdi/include/cdi.h > index 42e4643..5fb7025 100644 > --- a/src/modules/cdi/include/cdi.h > +++ b/src/modules/cdi/include/cdi.h > @@ -23,7 +23,8 @@ > typedef enum { > CDI_UNKNOWN = 0, > CDI_NETWORK = 1, > - CDI_STORAGE = 2 > + CDI_STORAGE = 2, > + CDI_SCSI = 3, > } cdi_device_type_t; > > struct cdi_driver; > diff --git a/src/modules/cdi/include/cdi/scsi.h b/src/modules/cdi/include/cdi/scsi.h > new file mode 100644 > index 0000000..78f0c30 > --- /dev/null > +++ b/src/modules/cdi/include/cdi/scsi.h > @@ -0,0 +1,86 @@ Gibts hier keinen Lizenzheader? Dann könntest du auch noch gleich die Doxygen-Anweisungen reinpacken, damit das ins SCSI-Modul kommt. > +#ifndef _CDI_SCSI_H_ > +#define _CDI_SCSI_H_ > + > +#include > +#include > + > +#include "cdi.h" > + > +// SCSI-Paket Hier bitte alles so kommentieren dass Doxygen es versteht, also entweder /** blub */ oder /// blub. > +struct cdi_scsi_packet { > + // Buffer zum Senden oder Empfangen von Daten > + void *buffer; > + > + // Groesse des Buffers > + size_t bufsize; > + > + // Ob gelesen oder geschrieben werden soll > + enum { > + CDI_SCSI_NODATA, > + CDI_SCSI_READ, > + CDI_SCSI_WRITE, > + } direction; > + > + // SCSI Command > + uint8_t command[16]; > + > + // Groesse des SCSI Commands > + size_t cmdsize; > +}; > + > +// SCSI-Geraet > +struct cdi_scsi_device { > + > + struct cdi_device dev; > + > + // Geraetetyp, der ueber SCSI angesteuert wird > + cdi_device_type_t type; > + > +}; > + > +// SCSI-Driver > +struct cdi_scsi_driver { > + struct cdi_driver drv; > + Hier hätte ich eigentlich auch irgend einen kommentar erwartet. > + int (*request)(struct cdi_scsi_device *device,struct cdi_scsi_packet *packet); > +}; > + > +/** > + * Ein SCSI-Paket allozieren > + * > + * @param size Benoetigte Groesse > + * > + * @return Pointer auf das Paket oder NULL im Fehlerfall > + */ > +struct cdi_scsi_packet* cdi_scsi_packet_alloc(size_t size); > + > +/** > + * Ein SCSI-Paket freigeben > + * > + * @param packet Pointer auf das Paket > + */ > +void cdi_scsi_packet_free(struct cdi_scsi_packet* packet); > + > +/** > + * Initialisiert die Datenstrukturen fuer einen SCSI-Treiber > + */ > +void cdi_scsi_driver_init(struct cdi_scsi_driver* driver); > + > +/** > + * Deinitialisiert die Datenstrukturen fuer einen SCSI-Treiber > + */ > +void cdi_scsi_driver_destroy(struct cdi_scsi_driver* driver); > + > +/** > + * Registiert einen SCSI-Treiber > + */ > +void cdi_scsi_driver_register(struct cdi_scsi_driver* driver); > + > +/** > + * Initialisiert ein neues SCSI-Geraet > + * > + * Der Typ der Geraetes muss bereits gesetzt sein > + */ > +void cdi_scsi_device_init(struct cdi_scsi_device* device); > + > +#endif > diff --git a/src/modules/cdi/include/cdi/storage.h b/src/modules/cdi/include/cdi/storage.h > index 73ae245..781a158 100644 > --- a/src/modules/cdi/include/cdi/storage.h > +++ b/src/modules/cdi/include/cdi/storage.h > @@ -40,7 +40,7 @@ struct cdi_storage_driver { > * > * @return 0 bei Erfolg, -1 im Fehlerfall. > */ > - int (*read_blocks)(struct cdi_storage_device* device, uint64_t start, > + int (*read_blocks)(struct cdi_device* device, uint64_t start, > uint64_t count, void* buffer); > > /** > @@ -53,8 +53,18 @@ struct cdi_storage_driver { > * > * @return 0 bei Erfolg, -1 im Fehlerfall > */ > - int (*write_blocks)(struct cdi_storage_device* device, uint64_t start, > + int (*write_blocks)(struct cdi_device* device, uint64_t start, > uint64_t count, void* buffer); > + > + /** > + * Gibt die Groesse des Mediums in Bytes zurueck > + */ > + uint64_t (*get_size)(struct cdi_device* device); > + > + /** > + * Gibt die Blockgroesse des Geraets in Bytes zurueck > + */ > + uint64_t (*get_block_size)(struct cdi_device* device); > }; > > > @@ -75,6 +85,11 @@ void cdi_storage_driver_destroy(struct cdi_storage_driver* driver); > */ > void cdi_storage_driver_register(struct cdi_storage_driver* driver); > > +/** > + * Initialisiert einen Massenspeicher > + */ > +void cdi_storage_device_init(struct cdi_storage_device* device); > + > #endif > > /*\@}*/ > diff --git a/src/modules/cdi/lib/cdi.c b/src/modules/cdi/lib/cdi.c > index d8c7819..487887e 100644 > --- a/src/modules/cdi/lib/cdi.c > +++ b/src/modules/cdi/lib/cdi.c > @@ -86,6 +86,7 @@ void cdi_run_drivers(void) > > for (j = 0; (device = cdi_list_get(driver->devices, j)); j++) { > device->driver = driver; > + device->type = driver->type; > > if (driver->init_device) { > driver->init_device(device); > diff --git a/src/modules/cdi/lib/scsi/disk.c b/src/modules/cdi/lib/scsi/disk.c > new file mode 100644 > index 0000000..9bd5a74 > --- /dev/null > +++ b/src/modules/cdi/lib/scsi/disk.c > @@ -0,0 +1,264 @@ > +/* > + * Copyright (C) 2008 Mathias Gottschlag > + * Copyright (C) 2009 Kevin Wolf > + * > + * Permission is hereby granted, free of charge, to any person obtaining a copy > + * of this software and associated documentation files (the "Software"), to > + * deal in the Software without restriction, including without limitation the > + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or > + * sell copies of the Software, and to permit persons to whom the Software is > + * furnished to do so, subject to the following conditions: > + * > + * The above copyright notice and this permission notice shall be included in > + * all copies or substantial portions of the Software. > + * > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE > + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING > + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS > + * IN THE SOFTWARE. > + */ Hm müsste da nicht noch ein Hinweis in doc/COPYRIGHT? > + > +#include > +#include > +#include > + > +#include > +#include > +#include > + > +#define big_endian_word(x) ((((x) & 0xFF) << 8) | (((x) & 0xFF00) >> 8)) > +#define big_endian_dword(x) \ > + ((big_endian_word((x) & 0xFFFF) << 16) | \ > + (big_endian_word((x) >> 16))) > + > +static int cdi_scsi_disk_read(struct cdi_device* device, > + uint64_t start, uint64_t count, void* buffer); > + > +static int cdi_scsi_disk_write(struct cdi_device* device, > + uint64_t start, uint64_t count, void* buffer); > + > +static uint64_t cdi_scsi_disk_get_size(struct cdi_device* device); > +static uint64_t cdi_scsi_disk_get_block_size(struct cdi_device* device); > + > +struct cdi_storage_driver cdi_scsi_disk_driver = { > + .read_blocks = cdi_scsi_disk_read, > + .write_blocks = cdi_scsi_disk_write, > + .get_size = cdi_scsi_disk_get_size, > + .get_block_size = cdi_scsi_disk_get_block_size, > +}; > + > +// TODO: This is kind of incomplete... -.- > +// FIXME Das ist alles sehr CD-ROM-spezifisch hartkodiert... > + > +union cdrom_command > +{ > + struct > + { > + uint8_t opcode; > + uint8_t reserved0; > + uint32_t address; > + uint8_t reserved1; > + uint16_t length; > + uint8_t reserved2; > + } __attribute__ ((packed)) dfl; > + struct > + { > + uint8_t opcode; > + uint8_t reserved0; > + uint32_t address; > + uint32_t length; > + uint16_t reserved1; > + } __attribute__ ((packed)) ext; > +}; > + > +static int cdrom_read_sector( > + struct cdi_scsi_device *device, uint32_t sector, char *buffer) > +{ > + struct cdi_scsi_packet packet; > + struct cdi_scsi_driver* drv = (struct cdi_scsi_driver*) device->dev.driver; > + union cdrom_command* cmd = (union cdrom_command*) &packet.command; > + > + memset(&packet, 0, sizeof(packet)); > + packet.direction = CDI_SCSI_READ; > + packet.buffer = buffer; > + packet.bufsize = 2048; > + packet.cmdsize = 12; > + > + cmd->ext.opcode = 0xA8; > + cmd->ext.address = big_endian_dword(sector); > + cmd->ext.length = 0x01000000; > + > + if (drv->request(device, &packet)) { > + return -1; > + } > + > + return 0; > +} > + > +static int cdrom_capacity(struct cdi_scsi_device *device, > + uint32_t* num_sectors, uint32_t* sector_size) > +{ > + uint32_t buffer[32]; > + struct cdi_scsi_packet packet; > + struct cdi_scsi_driver* drv = (struct cdi_scsi_driver*) device->dev.driver; > + union cdrom_command* cmd = (union cdrom_command*) &packet.command; > + > + memset(&packet, 0, sizeof(packet)); > + packet.direction = CDI_SCSI_READ; > + packet.buffer = buffer; > + packet.bufsize = sizeof(buffer); > + packet.cmdsize = 12; > + > + cmd->ext.opcode = 0x25; > + > + if (drv->request(device, &packet)) { > + return -1; > + } > + > + *num_sectors = big_endian_dword(buffer[0]); > + *sector_size = big_endian_dword(buffer[1]); > + > + return 0; > +} > + > +#if 0 > +static int cdrom_lock_device(FsSCSIDevice *device, int index, int lock) > +{ > + // Lock drive > + FsSCSIPacket packet; > + memset(&packet, 0, sizeof(FsSCSIPacket)); > + packet.direction = CDI_SCSI_NO_DATA; > + ((union cdrom_command*)packet.command)->dfl.opcode = 0x1E; > + packet.command[4] = 1; > + packet.buffer = 0; > + packet.length = 0; > + packet.commandsize = 12; > + uint32_t status = device->request(device, &packet); > + if (status) > + { > + kePrint("cdrom %d: Lock failed, %x\n", index, status); > + fsCloseSCSIDevice(device); > + return KE_ERROR_UNKNOWN; > + } > + return 0; > +} > + > +static void cdrom_sense(FsSCSIDevice *device, uint32_t index) > +{ > + char sense_data[18]; > + FsSCSIPacket packet; > + packet.direction = CDI_SCSI_READ; > + packet.buffer = sense_data; > + packet.length = 18; > + packet.commandsize = 12; > + ((union cdrom_command*)packet.command)->dfl.opcode = 0x12; > +} > +#endif > + > +int cdrom_init(struct cdi_scsi_device* device) > +{ > + // Send inquiry command > + struct cdi_scsi_driver* drv = (struct cdi_scsi_driver*) device->dev.driver; > + struct cdi_scsi_packet packet; > + uint32_t status; > + unsigned char inqdata[96]; > + > + memset(&packet, 0, sizeof(packet)); > + memset(inqdata, 0xF0, sizeof(inqdata)); > + > + packet.direction = CDI_SCSI_READ; > + packet.buffer = inqdata; > + packet.bufsize = 96; > + packet.cmdsize = 12; > + > + ((union cdrom_command*)packet.command)->dfl.opcode = 0x12; > + packet.command[4] = 96; > + status = drv->request(device, &packet); > + if (status) > + { > + return -1; > + } > + > +#if 0 > + if (cdrom_lock_device(device, index, 1)) > + return KE_ERROR_UNKNOWN; > +#endif > + > + // Start drive > + packet.direction = CDI_SCSI_NODATA; > + ((union cdrom_command*)packet.command)->dfl.opcode = 0x1B; > + packet.buffer = 0; > + packet.bufsize = 0; > + packet.command[4] = 0; > + packet.command[4] = 3; > + packet.cmdsize = 12; > + > + status = drv->request(device, &packet); > + if (status) > + { > + printf("cdrom %d: Start failed, %x\n", index, status); > + return -1; > + } > + > + return 0; > +} > + > +static int cdi_scsi_disk_read(struct cdi_device* device, > + uint64_t start, uint64_t count, void* buffer) > +{ > + struct cdi_scsi_device* dev = (struct cdi_scsi_device*) device; > + > + while (count--) { > + if (cdrom_read_sector(dev, start, buffer)) { Hm SCSI kann doch mehrere Sektoren in einem Rutsch lesen? > + return -1; > + } > + start ++; > + buffer += 2048; > + } > + > + return 0; > +} > + > +static int cdi_scsi_disk_write(struct cdi_device* device, > + uint64_t start, uint64_t count, void* buffer) > +{ > + return -1; > +} > + > +static uint64_t cdi_scsi_disk_get_size(struct cdi_device* device) > +{ > + struct cdi_scsi_device* dev = (struct cdi_scsi_device*) device; > + uint32_t num_sectors, sector_size; > + > + > + // TODO Einmal beim Initialisieren eines Mediums einlesen und dann bei > + // jedem Aufruf wiederverwenden > + cdrom_capacity(dev, &num_sectors, §or_size); > + > + return num_sectors * sector_size; > +} > + > +static uint64_t cdi_scsi_disk_get_block_size(struct cdi_device* device) > +{ > + struct cdi_scsi_device* dev = (struct cdi_scsi_device*) device; > + uint32_t num_sectors, sector_size; > + > + > + // TODO s.o. > + cdrom_capacity(dev, &num_sectors, §or_size); > + > + return sector_size; > +} > + > +int lostio_mst_if_newdev(struct cdi_device* device); > + > +void cdi_scsi_disk_init(struct cdi_scsi_device* device) > +{ > + if (cdrom_init(device) == 0) { > + // LostIO-Verzeichnisknoten anlegen > + lostio_mst_if_newdev(&device->dev); > + } > +} > diff --git a/src/modules/cdi/lib/scsi/driver.c b/src/modules/cdi/lib/scsi/driver.c > new file mode 100644 > index 0000000..745bd25 > --- /dev/null > +++ b/src/modules/cdi/lib/scsi/driver.c > @@ -0,0 +1,56 @@ > +/* > + * Copyright (c) 2009 Kevin Wolf > + * > + * This program is free software. It comes without any warranty, to > + * the extent permitted by applicable law. You can redistribute it > + * and/or modify it under the terms of the Do What The Fuck You Want > + * To Public License, Version 2, as published by Sam Hocevar. See > + * http://sam.zoy.org/projects/COPYING.WTFPL for more details. > + */ > + > +#include > +#include > +#include > +#include > +#include > + > +#include "cdi/scsi.h" > + > +extern void cdi_scsi_disk_init(struct cdi_scsi_device* device); > + > +/** > + * Initialisiert die Datenstrukturen fuer einen SCSI-Treiber > + */ > +void cdi_scsi_driver_init(struct cdi_scsi_driver* driver) > +{ > + driver->drv.type = CDI_SCSI; > + cdi_driver_init((struct cdi_driver*) driver); > +} > + > +/** > + * Deinitialisiert die Datenstrukturen fuer einen SCSI-Treiber > + */ > +void cdi_scsi_driver_destroy(struct cdi_scsi_driver* driver) > +{ > + cdi_driver_destroy((struct cdi_driver*) driver); > +} > + > +/** > + * Initialisiert ein neues SCSI-Geraet > + * > + * Der Typ der Geraetes muss bereits gesetzt sein > + */ > +void cdi_scsi_device_init(struct cdi_scsi_device* device) > +{ > + if (device->type == CDI_STORAGE) { > + cdi_scsi_disk_init(device); > + } > +} > + > +/** > + * Registiert den Treiber fuer SCSI-Geraete > + */ > +void cdi_scsi_driver_register(struct cdi_scsi_driver* driver) > +{ > + cdi_driver_register((struct cdi_driver*) driver); > +} > diff --git a/src/modules/cdi/lib/storage.c b/src/modules/cdi/lib/storage.c > index 9dd9746..16e4a7e 100644 > --- a/src/modules/cdi/lib/storage.c > +++ b/src/modules/cdi/lib/storage.c > @@ -17,7 +17,7 @@ > #include "cdi/storage.h" > > static void lostio_mst_if_init(void); > -static int lostio_mst_if_newdev(struct cdi_storage_device* device); > +int lostio_mst_if_newdev(struct cdi_device* device); > > static size_t lostio_mst_read_handler(lostio_filehandle_t* fh, > void* buf, size_t blocksize, size_t blockcount); > @@ -63,8 +63,6 @@ void cdi_storage_driver_destroy(struct cdi_storage_driver* driver) > void cdi_storage_driver_register(struct cdi_storage_driver* driver) > { > static int initialized = 0; > - int i; > - struct cdi_storage_device* device; > > cdi_driver_register((struct cdi_driver*) driver); > > @@ -72,11 +70,32 @@ void cdi_storage_driver_register(struct cdi_storage_driver* driver) > lostio_mst_if_init(); > initialized = 1; > } > +} > + > +/** > + * Initialisiert einen Massenspeicher > + */ > +void cdi_storage_device_init(struct cdi_storage_device* device) > +{ > + device->dev.type = CDI_STORAGE; > > // Geraeteknoten fuer LostIO erstellen > - for (i = 0; (device = cdi_list_get(driver->drv.devices, i)); i++) { > - lostio_mst_if_newdev(device); > + lostio_mst_if_newdev(&device->dev); > +} > + > +extern struct cdi_storage_driver cdi_scsi_disk_driver; > + > +static struct cdi_storage_driver* get_storage_drv(struct cdi_device* dev) > +{ > + struct cdi_storage_driver* driver = NULL; > + > + if (dev->type == CDI_STORAGE) { > + driver = (struct cdi_storage_driver*) dev->driver; > + } else if (dev->type == CDI_SCSI) { > + driver = &cdi_scsi_disk_driver; > } > + > + return driver; > } > > /** > @@ -86,12 +105,12 @@ void cdi_storage_driver_register(struct cdi_storage_driver* driver) > * @param size Anzahl der zu lesenden Bytes > * @param dest Buffer > */ > -int cdi_storage_read(struct cdi_storage_device* device, uint64_t pos, > +int cdi_storage_read(struct cdi_device* device, uint64_t pos, > size_t size, void* dest) > { > - struct cdi_storage_driver* driver = (struct cdi_storage_driver*) device-> > - dev.driver; > - size_t block_size = device->block_size; > + struct cdi_storage_driver* driver = get_storage_drv(device); > + size_t block_size = driver->get_block_size(device); > + > // Start- und Endblock > uint64_t block_read_start = pos / block_size; > uint64_t block_read_end = (pos + size) / block_size; > @@ -128,13 +147,12 @@ int cdi_storage_read(struct cdi_storage_device* device, uint64_t pos, > * @param size Anzahl der zu schreibendes Bytes > * @param src Buffer > */ > -int cdi_storage_write(struct cdi_storage_device* device, uint64_t pos, > +int cdi_storage_write(struct cdi_device* device, uint64_t pos, > size_t size, void* src) > { > - struct cdi_storage_driver* driver = (struct cdi_storage_driver*) device-> > - dev.driver; > - > - size_t block_size = device->block_size; > + struct cdi_storage_driver* driver = get_storage_drv(device); > + size_t block_size = driver->get_block_size(device); > + > uint64_t block_write_start = pos / block_size; > uint8_t buffer[block_size]; > size_t offset; > @@ -206,15 +224,17 @@ static void lostio_mst_if_init() > /** > * Erstellt den Dateisystemknoten fuer ein Geraet. > */ > -static int lostio_mst_if_newdev(struct cdi_storage_device* device) > +int lostio_mst_if_newdev(struct cdi_device* device) > { > + struct cdi_storage_driver* driver = get_storage_drv(device); > + > // Slash vor Pfad angaengen > - char path[strlen(device->dev.name) + 2]; > - strcpy(path + 1, device->dev.name); > + char path[strlen(device->name) + 2]; > + strcpy(path + 1, device->name); > *path = '/'; > > - if (vfstree_create_node(path, CDI_LOSTIO_TYPE_MST, device->block_size * > - device->block_count, (void*) device, 0) == FALSE) > + if (vfstree_create_node(path, CDI_LOSTIO_TYPE_MST, > + driver->get_size(device), (void*) device, 0) == FALSE) > { > return -1; > } > @@ -227,13 +247,19 @@ static int lostio_mst_if_newdev(struct cdi_storage_device* device) > static size_t lostio_mst_read_handler(lostio_filehandle_t* fh, > void* buf, size_t blocksize, size_t blockcount) > { > - struct cdi_storage_device* device = (struct cdi_storage_device*) fh->node-> > - data; > + struct cdi_device* device = (struct cdi_device*) fh->node->data; > + struct cdi_storage_driver* drv = get_storage_drv(device); > + > size_t size = blocksize * blockcount; > + size_t devsize = drv->get_size(device); > > // Groesse anpassen, wenn ueber das Medium hinaus gelesen werden soll > - if (size > (device->block_count * device->block_size - fh->pos)) { > - size = device->block_count * device->block_size - fh->pos; > + if (size > (devsize - fh->pos)) { > + size = devsize - fh->pos; > + if (size == 0) { > + fh->flags |= LOSTIO_FLAG_EOF; > + return 0; > + } > } > > // In den uebergebenen Buffer einlesen > @@ -253,14 +279,16 @@ static size_t lostio_mst_read_handler(lostio_filehandle_t* fh, > static size_t lostio_mst_write_handler(lostio_filehandle_t* fh, > size_t blocksize, size_t blockcount, void* data) > { > - struct cdi_storage_device* device = (struct cdi_storage_device*) fh->node-> > - data; > + struct cdi_device* device = (struct cdi_device*) fh->node->data; > + struct cdi_storage_driver* drv = get_storage_drv(device); > + > size_t size = blocksize * blockcount; > + size_t devsize = drv->get_size(device); > size_t result = size; > > // Groesse anpassen, wenn ueber das Medium hinaus geschrieben werden soll > - if (size > (device->block_count * device->block_size - fh->pos)) { > - size = device->block_count * device->block_size - fh->pos; > + if (size > (devsize - fh->pos)) { > + size = devsize - fh->pos; > } > > // Daten schreiben > @@ -279,10 +307,11 @@ static size_t lostio_mst_write_handler(lostio_filehandle_t* fh, > static int lostio_mst_seek_handler(lostio_filehandle_t* fh, uint64_t offset, > int origin) > { > - struct cdi_storage_device* device = (struct cdi_storage_device*) fh->node-> > - data; > + struct cdi_device* device = (struct cdi_device*) fh->node->data; > + struct cdi_storage_driver* drv = get_storage_drv(device); > + > uint64_t new_pos = fh->pos; > - uint64_t size = device->block_size * device->block_count; > + uint64_t size = drv->get_size(device); > > switch (origin) { > case SEEK_SET: -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From mail at kevin-wolf.de Sat Jan 3 22:44:37 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sat, 3 Jan 2009 22:44:37 +0100 Subject: [tyndur-devel] [PATCH] cdi: CD-ROM-Unterstuetzung In-Reply-To: <20090103205246.GA31201@thales.produktiv.lan> References: <1231013945-17825-1-git-send-email-kevin@tyndur.org> <20090103205246.GA31201@thales.produktiv.lan> Message-ID: <200901032244.37511@kevin-wolf.de> Am Samstag, 3. Januar 2009 21:52:46 schrieb Antoine Kaufmann: > On Sat, Jan 03 21:19, Kevin Wolf wrote: > > + cdi: Storage: Zusaetzliche Funktionen get_size() und get_block_size(), > > da SCSI-Geraete die Variablen nicht haben + cdi: SCSI: > > Grundfunktionalitaet > > + cdi: SCSI: Storage-Backend scsi/disk (momentan nur fuer CD-ROM > > geeignet) * cdi: Storage nimmt jetzt auch SCSI-Geraete > > * cdi: Storage-Treiber und -Geraete werden einzeln initialisiert > > * ata/floppy: An geaenderte Interfaces geanpasst > > --- > > src/modules/cdi/ata/atapi.c | 3 + > > src/modules/cdi/ata/device.c | 19 ++- > > src/modules/cdi/ata/device.h | 6 +- > > src/modules/cdi/ata/main.c | 4 +- > > src/modules/cdi/floppy/device.c | 29 +++- > > src/modules/cdi/floppy/device.h | 6 +- > > src/modules/cdi/floppy/main.c | 8 +- > > src/modules/cdi/include/cdi.h | 3 +- > > src/modules/cdi/include/cdi/scsi.h | 86 +++++++++++ > > src/modules/cdi/include/cdi/storage.h | 19 ++- > > src/modules/cdi/lib/cdi.c | 1 + > > src/modules/cdi/lib/scsi/disk.c | 264 > > +++++++++++++++++++++++++++++++++ src/modules/cdi/lib/scsi/driver.c | > > 56 +++++++ > > src/modules/cdi/lib/storage.c | 89 ++++++++---- > > 14 files changed, 546 insertions(+), 47 deletions(-) > > create mode 100644 src/modules/cdi/include/cdi/scsi.h > > create mode 100644 src/modules/cdi/lib/scsi/disk.c > > create mode 100644 src/modules/cdi/lib/scsi/driver.c > > > > diff --git a/src/modules/cdi/ata/atapi.c b/src/modules/cdi/ata/atapi.c > > index 67dc140..ecff315 100644 > > --- a/src/modules/cdi/ata/atapi.c > > +++ b/src/modules/cdi/ata/atapi.c > > @@ -86,7 +86,10 @@ int atapi_drv_identify(struct ata_device* dev) > > > > void atapi_init_device(struct cdi_device* device) > > { > > + struct cdi_scsi_device* scsi = (struct cdi_scsi_device*) device; > > > > + scsi->type = CDI_STORAGE; > > + cdi_scsi_device_init(scsi); > > } > > > > void atapi_remove_device(struct cdi_device* device) > > diff --git a/src/modules/cdi/ata/device.c b/src/modules/cdi/ata/device.c > > index f9ccf21..b9763d4 100644 > > --- a/src/modules/cdi/ata/device.c > > +++ b/src/modules/cdi/ata/device.c > > @@ -333,6 +333,8 @@ void ata_remove_controller(struct ata_controller* > > controller) > > > > void ata_init_device(struct cdi_device* device) > > { > > + struct ata_device* dev = (struct ata_device*) device; > > + cdi_storage_device_init(&dev->dev.storage); > > } > > > > void ata_remove_device(struct cdi_device* device) > > @@ -344,7 +346,7 @@ void ata_remove_device(struct cdi_device* device) > > /** > > * Blocks von einem ATA(PI) Geraet lesen > > */ > > -int ata_read_blocks(struct cdi_storage_device* device, uint64_t block, > > +int ata_read_blocks(struct cdi_device* device, uint64_t block, > > uint64_t count, void* buffer) > > { > > struct ata_device* dev = (struct ata_device*) device; > > @@ -374,7 +376,7 @@ int ata_read_blocks(struct cdi_storage_device* > > device, uint64_t block, /** > > * Blocks auf ein ATA(PI) Geraet schreiben > > */ > > -int ata_write_blocks(struct cdi_storage_device* device, uint64_t block, > > +int ata_write_blocks(struct cdi_device* device, uint64_t block, > > uint64_t count, void* buffer) > > { > > struct ata_device* dev = (struct ata_device*) device; > > @@ -401,3 +403,16 @@ int ata_write_blocks(struct cdi_storage_device* > > device, uint64_t block, } > > } > > > > +uint64_t ata_get_size(struct cdi_device* device) > > +{ > > + struct cdi_storage_device* storage = (struct cdi_storage_device*) > > device; + > > + return storage->block_size * storage->block_count; > > +} > > + > > +uint64_t ata_get_block_size(struct cdi_device* device) > > +{ > > + struct cdi_storage_device* storage = (struct cdi_storage_device*) > > device; + > > + return storage->block_size; > > +} > > diff --git a/src/modules/cdi/ata/device.h b/src/modules/cdi/ata/device.h > > index 140f037..eaa890a 100644 > > --- a/src/modules/cdi/ata/device.h > > +++ b/src/modules/cdi/ata/device.h > > @@ -411,11 +411,13 @@ void ata_init_controller(struct ata_controller* > > controller); void ata_remove_controller(struct ata_controller* > > controller); > > void ata_init_device(struct cdi_device* device); > > void ata_remove_device(struct cdi_device* device); > > -int ata_read_blocks(struct cdi_storage_device* device, uint64_t block, > > +int ata_read_blocks(struct cdi_device* device, uint64_t block, > > uint64_t count, void* buffer); > > -int ata_write_blocks(struct cdi_storage_device* device, uint64_t block, > > +int ata_write_blocks(struct cdi_device* device, uint64_t block, > > uint64_t count, void* buffer); > > > > +uint64_t ata_get_size(struct cdi_device* device); > > +uint64_t ata_get_block_size(struct cdi_device* device); > > > > // Einen ATA-Request absenden und ausfuehren > > int ata_request(struct ata_request* request); > > diff --git a/src/modules/cdi/ata/main.c b/src/modules/cdi/ata/main.c > > index 750f7b2..18e7225 100644 > > --- a/src/modules/cdi/ata/main.c > > +++ b/src/modules/cdi/ata/main.c > > @@ -80,7 +80,7 @@ static void ata_driver_init() > > // Konstruktor der Vaterklasse > > cdi_storage_driver_init((struct cdi_storage_driver*) > > &driver_storage); cdi_scsi_driver_init((struct cdi_scsi_driver*) > > &driver_scsi); > > Hm sicher dass dein diff hier korrekt ist? Haben wir da wirklich schon > ein cdi_scsi_driver_init drin? :-/ Da drunter ist noch janoschs ATAPI-Patch, zu dem es ja keine Kommentare mehr gab. Der fügt das ein. > > - > > + > > Und hier haben wir noch eine Whitespace Änderung, sowas aber auch. ;-) Bäh. > > > // Namen setzen > > driver_storage.drv.name = driver_storage_name; > > driver_scsi.drv.name = driver_scsi_name; > > @@ -91,6 +91,8 @@ static void ata_driver_init() > > driver_storage.drv.remove_device = ata_remove_device; > > driver_storage.read_blocks = ata_read_blocks; > > driver_storage.write_blocks = ata_write_blocks; > > + driver_storage.get_size = ata_get_size; > > + driver_storage.get_block_size = ata_get_block_size; > > > > driver_scsi.drv.destroy = atapi_driver_destroy; > > driver_scsi.drv.init_device = atapi_init_device; > > diff --git a/src/modules/cdi/floppy/device.c > > b/src/modules/cdi/floppy/device.c index 6614e1e..4435630 100644 > > --- a/src/modules/cdi/floppy/device.c > > +++ b/src/modules/cdi/floppy/device.c > > @@ -796,6 +796,8 @@ void floppy_init_device(struct cdi_device* device) > > > > dev->dev.block_size = FLOPPY_SECTOR_SIZE(dev); > > dev->dev.block_count = FLOPPY_SECTOR_COUNT(dev); > > + > > + cdi_storage_device_init(&dev->dev); > > } > > > > /** > > @@ -808,7 +810,7 @@ void floppy_remove_device(struct cdi_device* device) > > /** > > * Sektoren einlesen > > */ > > -int floppy_read_blocks(struct cdi_storage_device* dev, uint64_t block, > > +int floppy_read_blocks(struct cdi_device* dev, uint64_t block, > > uint64_t count, void* buffer) > > { > > struct floppy_device* device = (struct floppy_device*) dev; > > @@ -823,7 +825,7 @@ int floppy_read_blocks(struct cdi_storage_device* > > dev, uint64_t block, // Wenn das schief geht, wird mehrmals probiert > > for (j = 0; (j < 5) && (result != 0); j++) { > > result = floppy_drive_sector_read(device, (uint32_t) block + > > i, - buffer + i * dev->block_size); > > + buffer + i * device->dev.block_size); > > } > > } > > > > @@ -833,7 +835,7 @@ int floppy_read_blocks(struct cdi_storage_device* > > dev, uint64_t block, /** > > * Sektoren schreiben > > */ > > -int floppy_write_blocks(struct cdi_storage_device* dev, uint64_t block, > > +int floppy_write_blocks(struct cdi_device* dev, uint64_t block, > > uint64_t count, void* buffer) > > { > > struct floppy_device* device = (struct floppy_device*) dev; > > @@ -848,13 +850,32 @@ int floppy_write_blocks(struct cdi_storage_device* > > dev, uint64_t block, // Wenn das schief geht, wird mehrmals probiert > > for (j = 0; (j < 5) && (result != 0); j++) { > > result = floppy_drive_sector_write(device, (uint32_t) block > > + i, - buffer + i * dev->block_size); > > + buffer + i * device->dev.block_size); > > } > > } > > > > return result; > > } > > > > +/** > > + * Gibt die Groesse des Mediums zurueck > > + */ > > +uint64_t floppy_get_size(struct cdi_device* device) > > +{ > > + struct cdi_storage_device* storage = (struct cdi_storage_device*) > > device; + > > + return storage->block_size * storage->block_count; > > +} > > + > > +/** > > + * Gibt die Sektorgroesse des Mediums zurueck > > + */ > > +uint64_t floppy_get_block_size(struct cdi_device* device) > > +{ > > + struct cdi_storage_device* storage = (struct cdi_storage_device*) > > device; + > > + return storage->block_size; > > +} > > > > /** > > * IRQ-Handler fuer den Kontroller; Erhoeht nur den IRQ-Zaehler in der > > diff --git a/src/modules/cdi/floppy/device.h > > b/src/modules/cdi/floppy/device.h index 24d16f9..6c3bfcf 100644 > > --- a/src/modules/cdi/floppy/device.h > > +++ b/src/modules/cdi/floppy/device.h > > @@ -137,10 +137,12 @@ int floppy_init_controller(struct > > floppy_controller* controller); > > > > void floppy_init_device(struct cdi_device* device); > > void floppy_remove_device(struct cdi_device* device); > > -int floppy_read_blocks(struct cdi_storage_device* device, uint64_t > > block, +int floppy_read_blocks(struct cdi_device* device, uint64_t block, > > uint64_t count, void* buffer); > > -int floppy_write_blocks(struct cdi_storage_device* device, uint64_t > > block, +int floppy_write_blocks(struct cdi_device* device, uint64_t > > block, uint64_t count, void* buffer); > > +uint64_t floppy_get_size(struct cdi_device* device); > > +uint64_t floppy_get_block_size(struct cdi_device* device); > > > > void floppy_handle_interrupt(struct cdi_device* device); > > > > diff --git a/src/modules/cdi/floppy/main.c > > b/src/modules/cdi/floppy/main.c index 435ff1f..aa32ed5 100644 > > --- a/src/modules/cdi/floppy/main.c > > +++ b/src/modules/cdi/floppy/main.c > > @@ -87,7 +87,7 @@ static int floppy_driver_init(struct floppy_driver* > > driver) > > > > // Konstruktor der Vaterklasse > > cdi_storage_driver_init((struct cdi_storage_driver*) driver); > > - > > + > > Schon wieder nur leerzeichen entfernt > > > // Namen setzen > > driver->storage.drv.name = driver_name; > > > > @@ -95,9 +95,11 @@ static int floppy_driver_init(struct floppy_driver* > > driver) driver->storage.drv.destroy = floppy_driver_destroy; > > driver->storage.drv.init_device = floppy_init_device; > > driver->storage.drv.remove_device = floppy_remove_device; > > - driver->storage.read_blocks = floppy_read_blocks; > > + driver->storage.read_blocks = floppy_read_blocks; > > Hier auch wieder > > > driver->storage.write_blocks = floppy_write_blocks; > > - > > + driver->storage.get_size = floppy_get_size; > > + driver->storage.get_block_size = floppy_get_block_size; > > + > > // Geraete erstellen (TODO: Was wenn eines oder beide nicht > > vorhanden // sind?) > > for (i = 0; i < 2; i++) { > > diff --git a/src/modules/cdi/include/cdi.h > > b/src/modules/cdi/include/cdi.h index 42e4643..5fb7025 100644 > > --- a/src/modules/cdi/include/cdi.h > > +++ b/src/modules/cdi/include/cdi.h > > @@ -23,7 +23,8 @@ > > typedef enum { > > CDI_UNKNOWN = 0, > > CDI_NETWORK = 1, > > - CDI_STORAGE = 2 > > + CDI_STORAGE = 2, > > + CDI_SCSI = 3, > > } cdi_device_type_t; > > > > struct cdi_driver; > > diff --git a/src/modules/cdi/include/cdi/scsi.h > > b/src/modules/cdi/include/cdi/scsi.h new file mode 100644 > > index 0000000..78f0c30 > > --- /dev/null > > +++ b/src/modules/cdi/include/cdi/scsi.h > > @@ -0,0 +1,86 @@ > > Gibts hier keinen Lizenzheader? > > Dann könntest du auch noch gleich die Doxygen-Anweisungen reinpacken, > damit das ins SCSI-Modul kommt. Ok > > > +#ifndef _CDI_SCSI_H_ > > +#define _CDI_SCSI_H_ > > + > > +#include > > +#include > > + > > +#include "cdi.h" > > + > > +// SCSI-Paket > > Hier bitte alles so kommentieren dass Doxygen es versteht, also entweder > /** blub */ oder /// blub. Das ist doch alles gar nicht mein Code. Hach... ;-) > > > +struct cdi_scsi_packet { > > + // Buffer zum Senden oder Empfangen von Daten > > + void *buffer; > > + > > + // Groesse des Buffers > > + size_t bufsize; > > + > > + // Ob gelesen oder geschrieben werden soll > > + enum { > > + CDI_SCSI_NODATA, > > + CDI_SCSI_READ, > > + CDI_SCSI_WRITE, > > + } direction; > > + > > + // SCSI Command > > + uint8_t command[16]; > > + > > + // Groesse des SCSI Commands > > + size_t cmdsize; > > +}; > > + > > +// SCSI-Geraet > > +struct cdi_scsi_device { > > + > > + struct cdi_device dev; > > + > > + // Geraetetyp, der ueber SCSI angesteuert wird > > + cdi_device_type_t type; > > + > > +}; > > + > > +// SCSI-Driver > > +struct cdi_scsi_driver { > > + struct cdi_driver drv; > > + > > Hier hätte ich eigentlich auch irgend einen kommentar erwartet. > > > + int (*request)(struct cdi_scsi_device *device,struct cdi_scsi_packet > > *packet); +}; > > + > > +/** > > + * Ein SCSI-Paket allozieren > > + * > > + * @param size Benoetigte Groesse > > + * > > + * @return Pointer auf das Paket oder NULL im Fehlerfall > > + */ > > +struct cdi_scsi_packet* cdi_scsi_packet_alloc(size_t size); > > + > > +/** > > + * Ein SCSI-Paket freigeben > > + * > > + * @param packet Pointer auf das Paket > > + */ > > +void cdi_scsi_packet_free(struct cdi_scsi_packet* packet); > > + > > +/** > > + * Initialisiert die Datenstrukturen fuer einen SCSI-Treiber > > + */ > > +void cdi_scsi_driver_init(struct cdi_scsi_driver* driver); > > + > > +/** > > + * Deinitialisiert die Datenstrukturen fuer einen SCSI-Treiber > > + */ > > +void cdi_scsi_driver_destroy(struct cdi_scsi_driver* driver); > > + > > +/** > > + * Registiert einen SCSI-Treiber > > + */ > > +void cdi_scsi_driver_register(struct cdi_scsi_driver* driver); > > + > > +/** > > + * Initialisiert ein neues SCSI-Geraet > > + * > > + * Der Typ der Geraetes muss bereits gesetzt sein > > + */ > > +void cdi_scsi_device_init(struct cdi_scsi_device* device); > > + > > +#endif > > diff --git a/src/modules/cdi/include/cdi/storage.h > > b/src/modules/cdi/include/cdi/storage.h index 73ae245..781a158 100644 > > --- a/src/modules/cdi/include/cdi/storage.h > > +++ b/src/modules/cdi/include/cdi/storage.h > > @@ -40,7 +40,7 @@ struct cdi_storage_driver { > > * > > * @return 0 bei Erfolg, -1 im Fehlerfall. > > */ > > - int (*read_blocks)(struct cdi_storage_device* device, uint64_t > > start, + int (*read_blocks)(struct cdi_device* device, uint64_t start, > > uint64_t count, void* buffer); > > > > /** > > @@ -53,8 +53,18 @@ struct cdi_storage_driver { > > * > > * @return 0 bei Erfolg, -1 im Fehlerfall > > */ > > - int (*write_blocks)(struct cdi_storage_device* device, uint64_t > > start, + int (*write_blocks)(struct cdi_device* device, uint64_t > > start, uint64_t count, void* buffer); > > + > > + /** > > + * Gibt die Groesse des Mediums in Bytes zurueck > > + */ > > + uint64_t (*get_size)(struct cdi_device* device); > > + > > + /** > > + * Gibt die Blockgroesse des Geraets in Bytes zurueck > > + */ > > + uint64_t (*get_block_size)(struct cdi_device* device); > > }; > > > > > > @@ -75,6 +85,11 @@ void cdi_storage_driver_destroy(struct > > cdi_storage_driver* driver); */ > > void cdi_storage_driver_register(struct cdi_storage_driver* driver); > > > > +/** > > + * Initialisiert einen Massenspeicher > > + */ > > +void cdi_storage_device_init(struct cdi_storage_device* device); > > + > > #endif > > > > /*\@}*/ > > diff --git a/src/modules/cdi/lib/cdi.c b/src/modules/cdi/lib/cdi.c > > index d8c7819..487887e 100644 > > --- a/src/modules/cdi/lib/cdi.c > > +++ b/src/modules/cdi/lib/cdi.c > > @@ -86,6 +86,7 @@ void cdi_run_drivers(void) > > > > for (j = 0; (device = cdi_list_get(driver->devices, j)); j++) { > > device->driver = driver; > > + device->type = driver->type; > > > > if (driver->init_device) { > > driver->init_device(device); > > diff --git a/src/modules/cdi/lib/scsi/disk.c > > b/src/modules/cdi/lib/scsi/disk.c new file mode 100644 > > index 0000000..9bd5a74 > > --- /dev/null > > +++ b/src/modules/cdi/lib/scsi/disk.c > > @@ -0,0 +1,264 @@ > > +/* > > + * Copyright (C) 2008 Mathias Gottschlag > > + * Copyright (C) 2009 Kevin Wolf > > + * > > + * Permission is hereby granted, free of charge, to any person obtaining > > a copy + * of this software and associated documentation files (the > > "Software"), to + * deal in the Software without restriction, including > > without limitation the + * rights to use, copy, modify, merge, publish, > > distribute, sublicense, and/or + * sell copies of the Software, and to > > permit persons to whom the Software is + * furnished to do so, subject to > > the following conditions: > > + * > > + * The above copyright notice and this permission notice shall be > > included in + * all copies or substantial portions of the Software. > > + * > > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, > > EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF > > MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND > > NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS > > BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN > > ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN > > CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE > > SOFTWARE. > > + */ > > Hm müsste da nicht noch ein Hinweis in doc/COPYRIGHT? Gute Frage. Ich pack es mal dazu rein. From kevin at tyndur.org Sat Jan 3 22:47:39 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 3 Jan 2009 22:47:39 +0100 Subject: [tyndur-devel] [PATCH v2] cdi: CD-ROM-Unterstuetzung Message-ID: <1231019259-18776-1-git-send-email-kevin@tyndur.org> + cdi: Storage: Zusaetzliche Funktionen get_size() und get_block_size(), da SCSI-Geraete die Variablen nicht haben + cdi: SCSI: Grundfunktionalitaet + cdi: SCSI: Storage-Backend scsi/disk (momentan nur fuer CD-ROM geeignet) * cdi: Storage nimmt jetzt auch SCSI-Geraete * cdi: Storage-Treiber und -Geraete werden einzeln initialisiert * ata/floppy: An geaenderte Interfaces geanpasst --- doc/COPYRIGHT | 23 +++ src/modules/cdi/ata/atapi.c | 3 + src/modules/cdi/ata/device.c | 19 ++- src/modules/cdi/ata/device.h | 6 +- src/modules/cdi/ata/main.c | 2 + src/modules/cdi/floppy/device.c | 29 +++- src/modules/cdi/floppy/device.h | 6 +- src/modules/cdi/floppy/main.c | 4 +- src/modules/cdi/include/cdi.h | 3 +- src/modules/cdi/include/cdi/scsi.h | 111 ++++++++++++++ src/modules/cdi/include/cdi/storage.h | 19 ++- src/modules/cdi/lib/cdi.c | 1 + src/modules/cdi/lib/scsi/disk.c | 264 +++++++++++++++++++++++++++++++++ src/modules/cdi/lib/scsi/driver.c | 56 +++++++ src/modules/cdi/lib/storage.c | 89 ++++++++---- 15 files changed, 591 insertions(+), 44 deletions(-) create mode 100644 src/modules/cdi/include/cdi/scsi.h create mode 100644 src/modules/cdi/lib/scsi/disk.c create mode 100644 src/modules/cdi/lib/scsi/driver.c diff --git a/doc/COPYRIGHT b/doc/COPYRIGHT index 66abeb4..a69002f 100644 --- a/doc/COPYRIGHT +++ b/doc/COPYRIGHT @@ -129,3 +129,26 @@ Parts of tyndur are derived from ZLib and are distributed under the Zlib terms: Portions of this software are copyright (c) 2007 The FreeType Project (www.freetype.org). All rights reserved. + +Parts of tyndur are derived from software under the following license: + + Copyright (C) 2008 Mathias Gottschlag + Copyright (C) 2009 Kevin Wolf + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. diff --git a/src/modules/cdi/ata/atapi.c b/src/modules/cdi/ata/atapi.c index 67dc140..ecff315 100644 --- a/src/modules/cdi/ata/atapi.c +++ b/src/modules/cdi/ata/atapi.c @@ -86,7 +86,10 @@ int atapi_drv_identify(struct ata_device* dev) void atapi_init_device(struct cdi_device* device) { + struct cdi_scsi_device* scsi = (struct cdi_scsi_device*) device; + scsi->type = CDI_STORAGE; + cdi_scsi_device_init(scsi); } void atapi_remove_device(struct cdi_device* device) diff --git a/src/modules/cdi/ata/device.c b/src/modules/cdi/ata/device.c index f9ccf21..b9763d4 100644 --- a/src/modules/cdi/ata/device.c +++ b/src/modules/cdi/ata/device.c @@ -333,6 +333,8 @@ void ata_remove_controller(struct ata_controller* controller) void ata_init_device(struct cdi_device* device) { + struct ata_device* dev = (struct ata_device*) device; + cdi_storage_device_init(&dev->dev.storage); } void ata_remove_device(struct cdi_device* device) @@ -344,7 +346,7 @@ void ata_remove_device(struct cdi_device* device) /** * Blocks von einem ATA(PI) Geraet lesen */ -int ata_read_blocks(struct cdi_storage_device* device, uint64_t block, +int ata_read_blocks(struct cdi_device* device, uint64_t block, uint64_t count, void* buffer) { struct ata_device* dev = (struct ata_device*) device; @@ -374,7 +376,7 @@ int ata_read_blocks(struct cdi_storage_device* device, uint64_t block, /** * Blocks auf ein ATA(PI) Geraet schreiben */ -int ata_write_blocks(struct cdi_storage_device* device, uint64_t block, +int ata_write_blocks(struct cdi_device* device, uint64_t block, uint64_t count, void* buffer) { struct ata_device* dev = (struct ata_device*) device; @@ -401,3 +403,16 @@ int ata_write_blocks(struct cdi_storage_device* device, uint64_t block, } } +uint64_t ata_get_size(struct cdi_device* device) +{ + struct cdi_storage_device* storage = (struct cdi_storage_device*) device; + + return storage->block_size * storage->block_count; +} + +uint64_t ata_get_block_size(struct cdi_device* device) +{ + struct cdi_storage_device* storage = (struct cdi_storage_device*) device; + + return storage->block_size; +} diff --git a/src/modules/cdi/ata/device.h b/src/modules/cdi/ata/device.h index 140f037..eaa890a 100644 --- a/src/modules/cdi/ata/device.h +++ b/src/modules/cdi/ata/device.h @@ -411,11 +411,13 @@ void ata_init_controller(struct ata_controller* controller); void ata_remove_controller(struct ata_controller* controller); void ata_init_device(struct cdi_device* device); void ata_remove_device(struct cdi_device* device); -int ata_read_blocks(struct cdi_storage_device* device, uint64_t block, +int ata_read_blocks(struct cdi_device* device, uint64_t block, uint64_t count, void* buffer); -int ata_write_blocks(struct cdi_storage_device* device, uint64_t block, +int ata_write_blocks(struct cdi_device* device, uint64_t block, uint64_t count, void* buffer); +uint64_t ata_get_size(struct cdi_device* device); +uint64_t ata_get_block_size(struct cdi_device* device); // Einen ATA-Request absenden und ausfuehren int ata_request(struct ata_request* request); diff --git a/src/modules/cdi/ata/main.c b/src/modules/cdi/ata/main.c index 750f7b2..81fb165 100644 --- a/src/modules/cdi/ata/main.c +++ b/src/modules/cdi/ata/main.c @@ -91,6 +91,8 @@ static void ata_driver_init() driver_storage.drv.remove_device = ata_remove_device; driver_storage.read_blocks = ata_read_blocks; driver_storage.write_blocks = ata_write_blocks; + driver_storage.get_size = ata_get_size; + driver_storage.get_block_size = ata_get_block_size; driver_scsi.drv.destroy = atapi_driver_destroy; driver_scsi.drv.init_device = atapi_init_device; diff --git a/src/modules/cdi/floppy/device.c b/src/modules/cdi/floppy/device.c index 6614e1e..4435630 100644 --- a/src/modules/cdi/floppy/device.c +++ b/src/modules/cdi/floppy/device.c @@ -796,6 +796,8 @@ void floppy_init_device(struct cdi_device* device) dev->dev.block_size = FLOPPY_SECTOR_SIZE(dev); dev->dev.block_count = FLOPPY_SECTOR_COUNT(dev); + + cdi_storage_device_init(&dev->dev); } /** @@ -808,7 +810,7 @@ void floppy_remove_device(struct cdi_device* device) /** * Sektoren einlesen */ -int floppy_read_blocks(struct cdi_storage_device* dev, uint64_t block, +int floppy_read_blocks(struct cdi_device* dev, uint64_t block, uint64_t count, void* buffer) { struct floppy_device* device = (struct floppy_device*) dev; @@ -823,7 +825,7 @@ int floppy_read_blocks(struct cdi_storage_device* dev, uint64_t block, // Wenn das schief geht, wird mehrmals probiert for (j = 0; (j < 5) && (result != 0); j++) { result = floppy_drive_sector_read(device, (uint32_t) block + i, - buffer + i * dev->block_size); + buffer + i * device->dev.block_size); } } @@ -833,7 +835,7 @@ int floppy_read_blocks(struct cdi_storage_device* dev, uint64_t block, /** * Sektoren schreiben */ -int floppy_write_blocks(struct cdi_storage_device* dev, uint64_t block, +int floppy_write_blocks(struct cdi_device* dev, uint64_t block, uint64_t count, void* buffer) { struct floppy_device* device = (struct floppy_device*) dev; @@ -848,13 +850,32 @@ int floppy_write_blocks(struct cdi_storage_device* dev, uint64_t block, // Wenn das schief geht, wird mehrmals probiert for (j = 0; (j < 5) && (result != 0); j++) { result = floppy_drive_sector_write(device, (uint32_t) block + i, - buffer + i * dev->block_size); + buffer + i * device->dev.block_size); } } return result; } +/** + * Gibt die Groesse des Mediums zurueck + */ +uint64_t floppy_get_size(struct cdi_device* device) +{ + struct cdi_storage_device* storage = (struct cdi_storage_device*) device; + + return storage->block_size * storage->block_count; +} + +/** + * Gibt die Sektorgroesse des Mediums zurueck + */ +uint64_t floppy_get_block_size(struct cdi_device* device) +{ + struct cdi_storage_device* storage = (struct cdi_storage_device*) device; + + return storage->block_size; +} /** * IRQ-Handler fuer den Kontroller; Erhoeht nur den IRQ-Zaehler in der diff --git a/src/modules/cdi/floppy/device.h b/src/modules/cdi/floppy/device.h index 24d16f9..6c3bfcf 100644 --- a/src/modules/cdi/floppy/device.h +++ b/src/modules/cdi/floppy/device.h @@ -137,10 +137,12 @@ int floppy_init_controller(struct floppy_controller* controller); void floppy_init_device(struct cdi_device* device); void floppy_remove_device(struct cdi_device* device); -int floppy_read_blocks(struct cdi_storage_device* device, uint64_t block, +int floppy_read_blocks(struct cdi_device* device, uint64_t block, uint64_t count, void* buffer); -int floppy_write_blocks(struct cdi_storage_device* device, uint64_t block, +int floppy_write_blocks(struct cdi_device* device, uint64_t block, uint64_t count, void* buffer); +uint64_t floppy_get_size(struct cdi_device* device); +uint64_t floppy_get_block_size(struct cdi_device* device); void floppy_handle_interrupt(struct cdi_device* device); diff --git a/src/modules/cdi/floppy/main.c b/src/modules/cdi/floppy/main.c index 435ff1f..f701262 100644 --- a/src/modules/cdi/floppy/main.c +++ b/src/modules/cdi/floppy/main.c @@ -97,7 +97,9 @@ static int floppy_driver_init(struct floppy_driver* driver) driver->storage.drv.remove_device = floppy_remove_device; driver->storage.read_blocks = floppy_read_blocks; driver->storage.write_blocks = floppy_write_blocks; - + driver->storage.get_size = floppy_get_size; + driver->storage.get_block_size = floppy_get_block_size; + // Geraete erstellen (TODO: Was wenn eines oder beide nicht vorhanden // sind?) for (i = 0; i < 2; i++) { diff --git a/src/modules/cdi/include/cdi.h b/src/modules/cdi/include/cdi.h index 42e4643..5fb7025 100644 --- a/src/modules/cdi/include/cdi.h +++ b/src/modules/cdi/include/cdi.h @@ -23,7 +23,8 @@ typedef enum { CDI_UNKNOWN = 0, CDI_NETWORK = 1, - CDI_STORAGE = 2 + CDI_STORAGE = 2, + CDI_SCSI = 3, } cdi_device_type_t; struct cdi_driver; diff --git a/src/modules/cdi/include/cdi/scsi.h b/src/modules/cdi/include/cdi/scsi.h new file mode 100644 index 0000000..cd8cfd4 --- /dev/null +++ b/src/modules/cdi/include/cdi/scsi.h @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2008 Janosch Graef + * + * This program is free software. It comes without any warranty, to + * the extent permitted by applicable law. You can redistribute it + * and/or modify it under the terms of the Do What The Fuck You Want + * To Public License, Version 2, as published by Sam Hocevar. See + * http://sam.zoy.org/projects/COPYING.WTFPL for more details. + */ + +/** + * Treiber fuer SCSI-Geraete + * \defgroup net + */ +/*\@{*/ + +#ifndef _CDI_SCSI_H_ +#define _CDI_SCSI_H_ + +#include +#include + +#include "cdi.h" + +/// SCSI-Paket +struct cdi_scsi_packet { + /// Buffer zum Senden oder Empfangen von Daten + void *buffer; + + /// Groesse des Buffers + size_t bufsize; + + /// Ob gelesen oder geschrieben werden soll + enum { + CDI_SCSI_NODATA, + CDI_SCSI_READ, + CDI_SCSI_WRITE, + } direction; + + /// SCSI-Befehl + uint8_t command[16]; + + /// Groesse des SCSI-Befehls + size_t cmdsize; +}; + +/// SCSI-Geraet +struct cdi_scsi_device { + + struct cdi_device dev; + + /// Geraetetyp, der ueber SCSI angesteuert wird + cdi_device_type_t type; + +}; + +/// SCSI-Treiber +struct cdi_scsi_driver { + + struct cdi_driver drv; + + /** + * Sendet ein SCSI-Paket an das Geraet. + * + * @return SCSI-Fehlerstatus nach der Ausfuehrung des Befehls + */ + int (*request)(struct cdi_scsi_device *device, + struct cdi_scsi_packet *packet); +}; + +/** + * Ein SCSI-Paket allozieren + * + * @param size Benoetigte Groesse + * + * @return Pointer auf das Paket oder NULL im Fehlerfall + */ +struct cdi_scsi_packet* cdi_scsi_packet_alloc(size_t size); + +/** + * Ein SCSI-Paket freigeben + * + * @param packet Pointer auf das Paket + */ +void cdi_scsi_packet_free(struct cdi_scsi_packet* packet); + +/** + * Initialisiert die Datenstrukturen fuer einen SCSI-Treiber + */ +void cdi_scsi_driver_init(struct cdi_scsi_driver* driver); + +/** + * Deinitialisiert die Datenstrukturen fuer einen SCSI-Treiber + */ +void cdi_scsi_driver_destroy(struct cdi_scsi_driver* driver); + +/** + * Registiert einen SCSI-Treiber + */ +void cdi_scsi_driver_register(struct cdi_scsi_driver* driver); + +/** + * Initialisiert ein neues SCSI-Geraet + * + * Der Typ der Geraetes muss bereits gesetzt sein + */ +void cdi_scsi_device_init(struct cdi_scsi_device* device); + +#endif + +/*\@}*/ diff --git a/src/modules/cdi/include/cdi/storage.h b/src/modules/cdi/include/cdi/storage.h index 73ae245..781a158 100644 --- a/src/modules/cdi/include/cdi/storage.h +++ b/src/modules/cdi/include/cdi/storage.h @@ -40,7 +40,7 @@ struct cdi_storage_driver { * * @return 0 bei Erfolg, -1 im Fehlerfall. */ - int (*read_blocks)(struct cdi_storage_device* device, uint64_t start, + int (*read_blocks)(struct cdi_device* device, uint64_t start, uint64_t count, void* buffer); /** @@ -53,8 +53,18 @@ struct cdi_storage_driver { * * @return 0 bei Erfolg, -1 im Fehlerfall */ - int (*write_blocks)(struct cdi_storage_device* device, uint64_t start, + int (*write_blocks)(struct cdi_device* device, uint64_t start, uint64_t count, void* buffer); + + /** + * Gibt die Groesse des Mediums in Bytes zurueck + */ + uint64_t (*get_size)(struct cdi_device* device); + + /** + * Gibt die Blockgroesse des Geraets in Bytes zurueck + */ + uint64_t (*get_block_size)(struct cdi_device* device); }; @@ -75,6 +85,11 @@ void cdi_storage_driver_destroy(struct cdi_storage_driver* driver); */ void cdi_storage_driver_register(struct cdi_storage_driver* driver); +/** + * Initialisiert einen Massenspeicher + */ +void cdi_storage_device_init(struct cdi_storage_device* device); + #endif /*\@}*/ diff --git a/src/modules/cdi/lib/cdi.c b/src/modules/cdi/lib/cdi.c index d8c7819..487887e 100644 --- a/src/modules/cdi/lib/cdi.c +++ b/src/modules/cdi/lib/cdi.c @@ -86,6 +86,7 @@ void cdi_run_drivers(void) for (j = 0; (device = cdi_list_get(driver->devices, j)); j++) { device->driver = driver; + device->type = driver->type; if (driver->init_device) { driver->init_device(device); diff --git a/src/modules/cdi/lib/scsi/disk.c b/src/modules/cdi/lib/scsi/disk.c new file mode 100644 index 0000000..c54bdf2 --- /dev/null +++ b/src/modules/cdi/lib/scsi/disk.c @@ -0,0 +1,264 @@ +/* + * Copyright (C) 2008 Mathias Gottschlag + * Copyright (C) 2009 Kevin Wolf + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include +#include +#include + +#include +#include +#include + +#define big_endian_word(x) ((((x) & 0xFF) << 8) | (((x) & 0xFF00) >> 8)) +#define big_endian_dword(x) \ + ((big_endian_word((x) & 0xFFFF) << 16) | \ + (big_endian_word((x) >> 16))) + +static int cdi_scsi_disk_read(struct cdi_device* device, + uint64_t start, uint64_t count, void* buffer); + +static int cdi_scsi_disk_write(struct cdi_device* device, + uint64_t start, uint64_t count, void* buffer); + +static uint64_t cdi_scsi_disk_get_size(struct cdi_device* device); +static uint64_t cdi_scsi_disk_get_block_size(struct cdi_device* device); + +struct cdi_storage_driver cdi_scsi_disk_driver = { + .read_blocks = cdi_scsi_disk_read, + .write_blocks = cdi_scsi_disk_write, + .get_size = cdi_scsi_disk_get_size, + .get_block_size = cdi_scsi_disk_get_block_size, +}; + +// TODO: This is kind of incomplete... -.- +// FIXME Das ist alles sehr CD-ROM-spezifisch hartkodiert... + +union cdrom_command +{ + struct + { + uint8_t opcode; + uint8_t reserved0; + uint32_t address; + uint8_t reserved1; + uint16_t length; + uint8_t reserved2; + } __attribute__ ((packed)) dfl; + struct + { + uint8_t opcode; + uint8_t reserved0; + uint32_t address; + uint32_t length; + uint16_t reserved1; + } __attribute__ ((packed)) ext; +}; + +static int cdrom_read_sector( + struct cdi_scsi_device *device, uint32_t sector, char *buffer) +{ + struct cdi_scsi_packet packet; + struct cdi_scsi_driver* drv = (struct cdi_scsi_driver*) device->dev.driver; + union cdrom_command* cmd = (union cdrom_command*) &packet.command; + + memset(&packet, 0, sizeof(packet)); + packet.direction = CDI_SCSI_READ; + packet.buffer = buffer; + packet.bufsize = 2048; + packet.cmdsize = 12; + + cmd->ext.opcode = 0xA8; + cmd->ext.address = big_endian_dword(sector); + cmd->ext.length = 0x01000000; + + if (drv->request(device, &packet)) { + return -1; + } + + return 0; +} + +static int cdrom_capacity(struct cdi_scsi_device *device, + uint32_t* num_sectors, uint32_t* sector_size) +{ + uint32_t buffer[32]; + struct cdi_scsi_packet packet; + struct cdi_scsi_driver* drv = (struct cdi_scsi_driver*) device->dev.driver; + union cdrom_command* cmd = (union cdrom_command*) &packet.command; + + memset(&packet, 0, sizeof(packet)); + packet.direction = CDI_SCSI_READ; + packet.buffer = buffer; + packet.bufsize = sizeof(buffer); + packet.cmdsize = 12; + + cmd->ext.opcode = 0x25; + + if (drv->request(device, &packet)) { + return -1; + } + + *num_sectors = big_endian_dword(buffer[0]); + *sector_size = big_endian_dword(buffer[1]); + + return 0; +} + +#if 0 +static int cdrom_lock_device(FsSCSIDevice *device, int index, int lock) +{ + // Lock drive + FsSCSIPacket packet; + memset(&packet, 0, sizeof(FsSCSIPacket)); + packet.direction = CDI_SCSI_NO_DATA; + ((union cdrom_command*)packet.command)->dfl.opcode = 0x1E; + packet.command[4] = 1; + packet.buffer = 0; + packet.length = 0; + packet.commandsize = 12; + uint32_t status = device->request(device, &packet); + if (status) + { + kePrint("cdrom %d: Lock failed, %x\n", index, status); + fsCloseSCSIDevice(device); + return KE_ERROR_UNKNOWN; + } + return 0; +} + +static void cdrom_sense(FsSCSIDevice *device, uint32_t index) +{ + char sense_data[18]; + FsSCSIPacket packet; + packet.direction = CDI_SCSI_READ; + packet.buffer = sense_data; + packet.length = 18; + packet.commandsize = 12; + ((union cdrom_command*)packet.command)->dfl.opcode = 0x12; +} +#endif + +int cdrom_init(struct cdi_scsi_device* device) +{ + // Send inquiry command + struct cdi_scsi_driver* drv = (struct cdi_scsi_driver*) device->dev.driver; + struct cdi_scsi_packet packet; + uint32_t status; + unsigned char inqdata[96]; + + memset(&packet, 0, sizeof(packet)); + memset(inqdata, 0xF0, sizeof(inqdata)); + + packet.direction = CDI_SCSI_READ; + packet.buffer = inqdata; + packet.bufsize = 96; + packet.cmdsize = 12; + + ((union cdrom_command*)packet.command)->dfl.opcode = 0x12; + packet.command[4] = 96; + status = drv->request(device, &packet); + if (status) + { + return -1; + } + +#if 0 + if (cdrom_lock_device(device, index, 1)) + return KE_ERROR_UNKNOWN; +#endif + + // Start drive + packet.direction = CDI_SCSI_NODATA; + ((union cdrom_command*)packet.command)->dfl.opcode = 0x1B; + packet.buffer = 0; + packet.bufsize = 0; + packet.command[4] = 0; + packet.command[4] = 3; + packet.cmdsize = 12; + + status = drv->request(device, &packet); + if (status) + { + printf("cdrom %d: Start failed, %x\n", index, status); + return -1; + } + + return 0; +} + +static int cdi_scsi_disk_read(struct cdi_device* device, + uint64_t start, uint64_t count, void* buffer) +{ + struct cdi_scsi_device* dev = (struct cdi_scsi_device*) device; + + while (count--) { + if (cdrom_read_sector(dev, start, buffer)) { + return -1; + } + start ++; + buffer += 2048; + } + + return 0; +} + +static int cdi_scsi_disk_write(struct cdi_device* device, + uint64_t start, uint64_t count, void* buffer) +{ + return -1; +} + +static uint64_t cdi_scsi_disk_get_size(struct cdi_device* device) +{ + struct cdi_scsi_device* dev = (struct cdi_scsi_device*) device; + uint32_t num_sectors, sector_size; + + + // TODO Einmal beim Initialisieren eines Mediums einlesen und dann bei + // jedem Aufruf wiederverwenden + cdrom_capacity(dev, &num_sectors, §or_size); + + return num_sectors * sector_size; +} + +static uint64_t cdi_scsi_disk_get_block_size(struct cdi_device* device) +{ + struct cdi_scsi_device* dev = (struct cdi_scsi_device*) device; + uint32_t num_sectors, sector_size; + + + // TODO s.o. + cdrom_capacity(dev, &num_sectors, §or_size); + + return sector_size; +} + +int lostio_mst_if_newdev(struct cdi_device* device); + +void cdi_scsi_disk_init(struct cdi_scsi_device* device) +{ + if (cdrom_init(device) == 0) { + // LostIO-Verzeichnisknoten anlegen + lostio_mst_if_newdev(&device->dev); + } +} diff --git a/src/modules/cdi/lib/scsi/driver.c b/src/modules/cdi/lib/scsi/driver.c new file mode 100644 index 0000000..745bd25 --- /dev/null +++ b/src/modules/cdi/lib/scsi/driver.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2009 Kevin Wolf + * + * This program is free software. It comes without any warranty, to + * the extent permitted by applicable law. You can redistribute it + * and/or modify it under the terms of the Do What The Fuck You Want + * To Public License, Version 2, as published by Sam Hocevar. See + * http://sam.zoy.org/projects/COPYING.WTFPL for more details. + */ + +#include +#include +#include +#include +#include + +#include "cdi/scsi.h" + +extern void cdi_scsi_disk_init(struct cdi_scsi_device* device); + +/** + * Initialisiert die Datenstrukturen fuer einen SCSI-Treiber + */ +void cdi_scsi_driver_init(struct cdi_scsi_driver* driver) +{ + driver->drv.type = CDI_SCSI; + cdi_driver_init((struct cdi_driver*) driver); +} + +/** + * Deinitialisiert die Datenstrukturen fuer einen SCSI-Treiber + */ +void cdi_scsi_driver_destroy(struct cdi_scsi_driver* driver) +{ + cdi_driver_destroy((struct cdi_driver*) driver); +} + +/** + * Initialisiert ein neues SCSI-Geraet + * + * Der Typ der Geraetes muss bereits gesetzt sein + */ +void cdi_scsi_device_init(struct cdi_scsi_device* device) +{ + if (device->type == CDI_STORAGE) { + cdi_scsi_disk_init(device); + } +} + +/** + * Registiert den Treiber fuer SCSI-Geraete + */ +void cdi_scsi_driver_register(struct cdi_scsi_driver* driver) +{ + cdi_driver_register((struct cdi_driver*) driver); +} diff --git a/src/modules/cdi/lib/storage.c b/src/modules/cdi/lib/storage.c index 9dd9746..16e4a7e 100644 --- a/src/modules/cdi/lib/storage.c +++ b/src/modules/cdi/lib/storage.c @@ -17,7 +17,7 @@ #include "cdi/storage.h" static void lostio_mst_if_init(void); -static int lostio_mst_if_newdev(struct cdi_storage_device* device); +int lostio_mst_if_newdev(struct cdi_device* device); static size_t lostio_mst_read_handler(lostio_filehandle_t* fh, void* buf, size_t blocksize, size_t blockcount); @@ -63,8 +63,6 @@ void cdi_storage_driver_destroy(struct cdi_storage_driver* driver) void cdi_storage_driver_register(struct cdi_storage_driver* driver) { static int initialized = 0; - int i; - struct cdi_storage_device* device; cdi_driver_register((struct cdi_driver*) driver); @@ -72,11 +70,32 @@ void cdi_storage_driver_register(struct cdi_storage_driver* driver) lostio_mst_if_init(); initialized = 1; } +} + +/** + * Initialisiert einen Massenspeicher + */ +void cdi_storage_device_init(struct cdi_storage_device* device) +{ + device->dev.type = CDI_STORAGE; // Geraeteknoten fuer LostIO erstellen - for (i = 0; (device = cdi_list_get(driver->drv.devices, i)); i++) { - lostio_mst_if_newdev(device); + lostio_mst_if_newdev(&device->dev); +} + +extern struct cdi_storage_driver cdi_scsi_disk_driver; + +static struct cdi_storage_driver* get_storage_drv(struct cdi_device* dev) +{ + struct cdi_storage_driver* driver = NULL; + + if (dev->type == CDI_STORAGE) { + driver = (struct cdi_storage_driver*) dev->driver; + } else if (dev->type == CDI_SCSI) { + driver = &cdi_scsi_disk_driver; } + + return driver; } /** @@ -86,12 +105,12 @@ void cdi_storage_driver_register(struct cdi_storage_driver* driver) * @param size Anzahl der zu lesenden Bytes * @param dest Buffer */ -int cdi_storage_read(struct cdi_storage_device* device, uint64_t pos, +int cdi_storage_read(struct cdi_device* device, uint64_t pos, size_t size, void* dest) { - struct cdi_storage_driver* driver = (struct cdi_storage_driver*) device-> - dev.driver; - size_t block_size = device->block_size; + struct cdi_storage_driver* driver = get_storage_drv(device); + size_t block_size = driver->get_block_size(device); + // Start- und Endblock uint64_t block_read_start = pos / block_size; uint64_t block_read_end = (pos + size) / block_size; @@ -128,13 +147,12 @@ int cdi_storage_read(struct cdi_storage_device* device, uint64_t pos, * @param size Anzahl der zu schreibendes Bytes * @param src Buffer */ -int cdi_storage_write(struct cdi_storage_device* device, uint64_t pos, +int cdi_storage_write(struct cdi_device* device, uint64_t pos, size_t size, void* src) { - struct cdi_storage_driver* driver = (struct cdi_storage_driver*) device-> - dev.driver; - - size_t block_size = device->block_size; + struct cdi_storage_driver* driver = get_storage_drv(device); + size_t block_size = driver->get_block_size(device); + uint64_t block_write_start = pos / block_size; uint8_t buffer[block_size]; size_t offset; @@ -206,15 +224,17 @@ static void lostio_mst_if_init() /** * Erstellt den Dateisystemknoten fuer ein Geraet. */ -static int lostio_mst_if_newdev(struct cdi_storage_device* device) +int lostio_mst_if_newdev(struct cdi_device* device) { + struct cdi_storage_driver* driver = get_storage_drv(device); + // Slash vor Pfad angaengen - char path[strlen(device->dev.name) + 2]; - strcpy(path + 1, device->dev.name); + char path[strlen(device->name) + 2]; + strcpy(path + 1, device->name); *path = '/'; - if (vfstree_create_node(path, CDI_LOSTIO_TYPE_MST, device->block_size * - device->block_count, (void*) device, 0) == FALSE) + if (vfstree_create_node(path, CDI_LOSTIO_TYPE_MST, + driver->get_size(device), (void*) device, 0) == FALSE) { return -1; } @@ -227,13 +247,19 @@ static int lostio_mst_if_newdev(struct cdi_storage_device* device) static size_t lostio_mst_read_handler(lostio_filehandle_t* fh, void* buf, size_t blocksize, size_t blockcount) { - struct cdi_storage_device* device = (struct cdi_storage_device*) fh->node-> - data; + struct cdi_device* device = (struct cdi_device*) fh->node->data; + struct cdi_storage_driver* drv = get_storage_drv(device); + size_t size = blocksize * blockcount; + size_t devsize = drv->get_size(device); // Groesse anpassen, wenn ueber das Medium hinaus gelesen werden soll - if (size > (device->block_count * device->block_size - fh->pos)) { - size = device->block_count * device->block_size - fh->pos; + if (size > (devsize - fh->pos)) { + size = devsize - fh->pos; + if (size == 0) { + fh->flags |= LOSTIO_FLAG_EOF; + return 0; + } } // In den uebergebenen Buffer einlesen @@ -253,14 +279,16 @@ static size_t lostio_mst_read_handler(lostio_filehandle_t* fh, static size_t lostio_mst_write_handler(lostio_filehandle_t* fh, size_t blocksize, size_t blockcount, void* data) { - struct cdi_storage_device* device = (struct cdi_storage_device*) fh->node-> - data; + struct cdi_device* device = (struct cdi_device*) fh->node->data; + struct cdi_storage_driver* drv = get_storage_drv(device); + size_t size = blocksize * blockcount; + size_t devsize = drv->get_size(device); size_t result = size; // Groesse anpassen, wenn ueber das Medium hinaus geschrieben werden soll - if (size > (device->block_count * device->block_size - fh->pos)) { - size = device->block_count * device->block_size - fh->pos; + if (size > (devsize - fh->pos)) { + size = devsize - fh->pos; } // Daten schreiben @@ -279,10 +307,11 @@ static size_t lostio_mst_write_handler(lostio_filehandle_t* fh, static int lostio_mst_seek_handler(lostio_filehandle_t* fh, uint64_t offset, int origin) { - struct cdi_storage_device* device = (struct cdi_storage_device*) fh->node-> - data; + struct cdi_device* device = (struct cdi_device*) fh->node->data; + struct cdi_storage_driver* drv = get_storage_drv(device); + uint64_t new_pos = fh->pos; - uint64_t size = device->block_size * device->block_count; + uint64_t size = drv->get_size(device); switch (origin) { case SEEK_SET: -- 1.5.4.5 From kevin at tyndur.org Sun Jan 4 15:20:38 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 4 Jan 2009 15:20:38 +0100 Subject: [tyndur-devel] [PATCH v3 5/5] cdi/storage: EOF setzen In-Reply-To: <1231078838-3065-1-git-send-email-kevin@tyndur.org> References: <1231078838-3065-1-git-send-email-kevin@tyndur.org> Message-ID: <1231078838-3065-6-git-send-email-kevin@tyndur.org> ! cdi/storage: Wenn ueber das Ende des Geraets hinausgelesen wird, EOF setzen --- src/modules/cdi/lib/storage.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/src/modules/cdi/lib/storage.c b/src/modules/cdi/lib/storage.c index 88a4528..992ae00 100644 --- a/src/modules/cdi/lib/storage.c +++ b/src/modules/cdi/lib/storage.c @@ -238,6 +238,10 @@ static size_t lostio_mst_read_handler(lostio_filehandle_t* fh, // Groesse anpassen, wenn ueber das Medium hinaus gelesen werden soll if (size > (device->block_count * device->block_size - fh->pos)) { size = device->block_count * device->block_size - fh->pos; + if (size == 0) { + fh->flags |= LOSTIO_FLAG_EOF; + return 0; + } } // In den uebergebenen Buffer einlesen -- 1.5.4.5 From kevin at tyndur.org Sun Jan 4 15:20:33 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 4 Jan 2009 15:20:33 +0100 Subject: [tyndur-devel] [PATCH v3 0/5] cdi: Unterstuetzung fuer CD-ROM Message-ID: <1231078838-3065-1-git-send-email-kevin@tyndur.org> Hier also der dritte Anlauf, dieses Mal sauber als Patchserie aufgetrennt und mit weniger einschneidenden Aenderungen an den CDI-Schnittstellen. Ich hoffe, in der Form sagt es auch Janosch zu. ;-) From kevin at tyndur.org Sun Jan 4 15:20:34 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 4 Jan 2009 15:20:34 +0100 Subject: [tyndur-devel] [PATCH v3 1/5] cdi/storage: Initialisierungsfunktion fuer Geraete In-Reply-To: <1231078838-3065-1-git-send-email-kevin@tyndur.org> References: <1231078838-3065-1-git-send-email-kevin@tyndur.org> Message-ID: <1231078838-3065-2-git-send-email-kevin@tyndur.org> + cdi/storage: Initialisierungsfunktion fuer Geraete * floppy, ata: Initialisierungsfunktion aufrufen --- src/modules/cdi/ata/device.c | 2 ++ src/modules/cdi/floppy/device.c | 2 ++ src/modules/cdi/include/cdi/storage.h | 6 ++++++ src/modules/cdi/lib/storage.c | 14 +++++++++----- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/modules/cdi/ata/device.c b/src/modules/cdi/ata/device.c index 9c443e9..fcedeae 100644 --- a/src/modules/cdi/ata/device.c +++ b/src/modules/cdi/ata/device.c @@ -323,6 +323,8 @@ void ata_remove_controller(struct ata_controller* controller) void ata_init_device(struct cdi_device* device) { + struct ata_device* dev = (struct ata_device*) device; + cdi_storage_device_init(&dev->storage); } void ata_remove_device(struct cdi_device* device) diff --git a/src/modules/cdi/floppy/device.c b/src/modules/cdi/floppy/device.c index 6614e1e..2262c23 100644 --- a/src/modules/cdi/floppy/device.c +++ b/src/modules/cdi/floppy/device.c @@ -796,6 +796,8 @@ void floppy_init_device(struct cdi_device* device) dev->dev.block_size = FLOPPY_SECTOR_SIZE(dev); dev->dev.block_count = FLOPPY_SECTOR_COUNT(dev); + + cdi_storage_device_init(&dev->dev); } /** diff --git a/src/modules/cdi/include/cdi/storage.h b/src/modules/cdi/include/cdi/storage.h index 73ae245..d19fc6f 100644 --- a/src/modules/cdi/include/cdi/storage.h +++ b/src/modules/cdi/include/cdi/storage.h @@ -75,6 +75,12 @@ void cdi_storage_driver_destroy(struct cdi_storage_driver* driver); */ void cdi_storage_driver_register(struct cdi_storage_driver* driver); +/** + * Initialisiert einen Massenspeicher + */ +void cdi_storage_device_init(struct cdi_storage_device* device); + + #endif /*\@}*/ diff --git a/src/modules/cdi/lib/storage.c b/src/modules/cdi/lib/storage.c index 9dd9746..df84be1 100644 --- a/src/modules/cdi/lib/storage.c +++ b/src/modules/cdi/lib/storage.c @@ -63,8 +63,6 @@ void cdi_storage_driver_destroy(struct cdi_storage_driver* driver) void cdi_storage_driver_register(struct cdi_storage_driver* driver) { static int initialized = 0; - int i; - struct cdi_storage_device* device; cdi_driver_register((struct cdi_driver*) driver); @@ -72,11 +70,17 @@ void cdi_storage_driver_register(struct cdi_storage_driver* driver) lostio_mst_if_init(); initialized = 1; } +} + +/** + * Initialisiert einen Massenspeicher + */ +void cdi_storage_device_init(struct cdi_storage_device* device) +{ + device->dev.type = CDI_STORAGE; // Geraeteknoten fuer LostIO erstellen - for (i = 0; (device = cdi_list_get(driver->drv.devices, i)); i++) { - lostio_mst_if_newdev(device); - } + lostio_mst_if_newdev(device); } /** -- 1.5.4.5 From kevin at tyndur.org Sun Jan 4 15:20:35 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 4 Jan 2009 15:20:35 +0100 Subject: [tyndur-devel] [PATCH v3 2/5] cdi: SCSI In-Reply-To: <1231078838-3065-1-git-send-email-kevin@tyndur.org> References: <1231078838-3065-1-git-send-email-kevin@tyndur.org> Message-ID: <1231078838-3065-3-git-send-email-kevin@tyndur.org> + cdi: Headerdatei und leere Implementierung fuer SCSI-Geraete --- src/modules/cdi/include/cdi.h | 3 +- src/modules/cdi/include/cdi/scsi.h | 111 ++++++++++++++++++++++++++++++++++++ src/modules/cdi/lib/scsi/driver.c | 51 ++++++++++++++++ 3 files changed, 164 insertions(+), 1 deletions(-) create mode 100644 src/modules/cdi/include/cdi/scsi.h create mode 100644 src/modules/cdi/lib/scsi/driver.c diff --git a/src/modules/cdi/include/cdi.h b/src/modules/cdi/include/cdi.h index 42e4643..5fb7025 100644 --- a/src/modules/cdi/include/cdi.h +++ b/src/modules/cdi/include/cdi.h @@ -23,7 +23,8 @@ typedef enum { CDI_UNKNOWN = 0, CDI_NETWORK = 1, - CDI_STORAGE = 2 + CDI_STORAGE = 2, + CDI_SCSI = 3, } cdi_device_type_t; struct cdi_driver; diff --git a/src/modules/cdi/include/cdi/scsi.h b/src/modules/cdi/include/cdi/scsi.h new file mode 100644 index 0000000..9f5b0e7 --- /dev/null +++ b/src/modules/cdi/include/cdi/scsi.h @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2008 Janosch Graef + * + * This program is free software. It comes without any warranty, to + * the extent permitted by applicable law. You can redistribute it + * and/or modify it under the terms of the Do What The Fuck You Want + * To Public License, Version 2, as published by Sam Hocevar. See + * http://sam.zoy.org/projects/COPYING.WTFPL for more details. + */ + +/** + * Treiber fuer SCSI-Geraete + * \defgroup scsi + */ +/*\@{*/ + +#ifndef _CDI_SCSI_H_ +#define _CDI_SCSI_H_ + +#include +#include + +#include "cdi.h" + +/// SCSI-Paket +struct cdi_scsi_packet { + /// Buffer zum Senden oder Empfangen von Daten + void *buffer; + + /// Groesse des Buffers + size_t bufsize; + + /// Ob gelesen oder geschrieben werden soll + enum { + CDI_SCSI_NODATA, + CDI_SCSI_READ, + CDI_SCSI_WRITE, + } direction; + + /// SCSI-Befehl + uint8_t command[16]; + + /// Groesse des SCSI-Befehls + size_t cmdsize; +}; + +/// SCSI-Geraet +struct cdi_scsi_device { + + struct cdi_device dev; + + /// Geraetetyp, der ueber SCSI angesteuert wird + cdi_device_type_t type; + +}; + +/// SCSI-Treiber +struct cdi_scsi_driver { + + struct cdi_driver drv; + + /** + * Sendet ein SCSI-Paket an das Geraet. + * + * @return SCSI-Fehlerstatus nach der Ausfuehrung des Befehls + */ + int (*request)(struct cdi_scsi_device *device, + struct cdi_scsi_packet *packet); +}; + +/** + * Ein SCSI-Paket allozieren + * + * @param size Benoetigte Groesse + * + * @return Pointer auf das Paket oder NULL im Fehlerfall + */ +struct cdi_scsi_packet* cdi_scsi_packet_alloc(size_t size); + +/** + * Ein SCSI-Paket freigeben + * + * @param packet Pointer auf das Paket + */ +void cdi_scsi_packet_free(struct cdi_scsi_packet* packet); + +/** + * Initialisiert die Datenstrukturen fuer einen SCSI-Treiber + */ +void cdi_scsi_driver_init(struct cdi_scsi_driver* driver); + +/** + * Deinitialisiert die Datenstrukturen fuer einen SCSI-Treiber + */ +void cdi_scsi_driver_destroy(struct cdi_scsi_driver* driver); + +/** + * Registiert einen SCSI-Treiber + */ +void cdi_scsi_driver_register(struct cdi_scsi_driver* driver); + +/** + * Initialisiert ein neues SCSI-Geraet + * + * Der Typ der Geraetes muss bereits gesetzt sein + */ +void cdi_scsi_device_init(struct cdi_scsi_device* device); + +#endif + +/*\@}*/ diff --git a/src/modules/cdi/lib/scsi/driver.c b/src/modules/cdi/lib/scsi/driver.c new file mode 100644 index 0000000..63e1e8c --- /dev/null +++ b/src/modules/cdi/lib/scsi/driver.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2009 Kevin Wolf + * + * This program is free software. It comes without any warranty, to + * the extent permitted by applicable law. You can redistribute it + * and/or modify it under the terms of the Do What The Fuck You Want + * To Public License, Version 2, as published by Sam Hocevar. See + * http://sam.zoy.org/projects/COPYING.WTFPL for more details. + */ + +#include +#include +#include +#include +#include + +#include "cdi/scsi.h" + +/** + * Initialisiert die Datenstrukturen fuer einen SCSI-Treiber + */ +void cdi_scsi_driver_init(struct cdi_scsi_driver* driver) +{ + driver->drv.type = CDI_SCSI; + cdi_driver_init((struct cdi_driver*) driver); +} + +/** + * Deinitialisiert die Datenstrukturen fuer einen SCSI-Treiber + */ +void cdi_scsi_driver_destroy(struct cdi_scsi_driver* driver) +{ + cdi_driver_destroy((struct cdi_driver*) driver); +} + +/** + * Initialisiert ein neues SCSI-Geraet + * + * Der Typ der Geraetes muss bereits gesetzt sein + */ +void cdi_scsi_device_init(struct cdi_scsi_device* device) +{ +} + +/** + * Registiert den Treiber fuer SCSI-Geraete + */ +void cdi_scsi_driver_register(struct cdi_scsi_driver* driver) +{ + cdi_driver_register((struct cdi_driver*) driver); +} -- 1.5.4.5 From kevin at tyndur.org Sun Jan 4 15:20:36 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 4 Jan 2009 15:20:36 +0100 Subject: [tyndur-devel] [PATCH v3 3/5] cdi/ata: ATAPI-Unterstuetzung (Janosch Graef) In-Reply-To: <1231078838-3065-1-git-send-email-kevin@tyndur.org> References: <1231078838-3065-1-git-send-email-kevin@tyndur.org> Message-ID: <1231078838-3065-4-git-send-email-kevin@tyndur.org> + cdi/ata: ATAPI-Unterstuetzung --- src/modules/cdi/ata/ata.c | 172 +--------------------------------- src/modules/cdi/ata/atapi.c | 96 ++++++++++++++++--- src/modules/cdi/ata/device.c | 58 +++++++----- src/modules/cdi/ata/device.h | 205 +++++++++++++++++++++++++++++++++++++++-- src/modules/cdi/ata/main.c | 48 ++++++---- src/modules/cdi/ata/request.c | 71 ++++++++++---- 6 files changed, 394 insertions(+), 256 deletions(-) diff --git a/src/modules/cdi/ata/ata.c b/src/modules/cdi/ata/ata.c index d18089f..14e777b 100644 --- a/src/modules/cdi/ata/ata.c +++ b/src/modules/cdi/ata/ata.c @@ -44,172 +44,6 @@ #include "device.h" /** - * Resultat beim IDENTIFY DEVICE Befehl - */ -struct ata_identfiy_data { - struct { - uint8_t : 7; - uint8_t removable : 1; - uint8_t : 7; - uint8_t ata : 1; - } __attribute__((packed)) general_config; - - uint16_t log_cyl; // Veraltet - uint16_t : 16; - uint16_t log_heads; // Veraltet - uint16_t : 16; - uint16_t : 16; - uint16_t log_spt; // Veraltet - uint16_t : 16; - // 8 - uint16_t : 16; - uint16_t : 16; - char serial_number[20]; - // 20 - uint16_t : 16; - uint16_t : 16; - uint16_t : 16; - char firmware_revision[8]; - // 27 - char model_number[40]; - uint8_t : 8; // Immer 0x80 - uint8_t max_sec_per_irq; - // 48 - uint16_t : 16; - struct { - uint16_t : 8; - uint8_t dma : 1; - uint8_t lba : 1; - uint8_t iordy_disabled : 1; - uint8_t irdy_supported : 1; - uint8_t : 1; - uint8_t : 1; // Irgendwas mit Standbytimer - uint8_t : 2; - } __attribute__((packed)) capabilities; - uint16_t : 16; // Noch ein paar Faehigkeiten, - // die wir aber sicher nicht - // brauchen - uint8_t : 8; - uint8_t pio_mode_number; - uint16_t : 16; - struct { - uint8_t current_chs : 1; // Words 54-56 - uint8_t transfer_settings : 1; // Words 64-70 - uint8_t ultra_dma : 1; // Word 88 - uint16_t : 13; - } __attribute__((packed)) valid_words; - uint16_t cur_log_cyl; // Veraltet - uint16_t cur_log_heads; // Veraltet - // 56 - uint16_t cur_log_spt; // Veraltet - uint16_t chs_capacity[2]; // Veraltet - struct { - uint8_t cur_sec_per_int : 8; - uint8_t setting_valid : 1; - uint8_t : 7; - } __attribute__((packed)) multi_sector; - uint32_t lba_sector_count; // LBA28 - uint16_t : 16; - struct { - uint8_t : 1; - uint8_t mode0_supported : 1; - uint8_t mode1_supported : 1; - uint8_t mode2_supported : 1; - uint8_t : 4; - uint8_t mode0_selected : 1; - uint8_t mode1_selected : 1; - uint8_t mode2_selected : 1; - uint8_t : 5; - } __attribute__((packed)) multiword_dma; - // 64 - uint8_t pio_modes_supported; - uint8_t : 8; - // Multiword dma Zeiten - uint16_t mwd_time1; - uint16_t mwd_time2; - uint16_t mwd_time3; - uint16_t mwd_time4; - uint16_t : 16; - uint16_t : 16; - uint16_t : 16; - // 72 - uint16_t : 16; - uint16_t : 16; - uint16_t : 16; - struct { - uint8_t max_depth : 5; - uint16_t : 11; - } __attribute__((packed)) queue_depth; - uint16_t : 16; - uint16_t : 16; - uint16_t : 16; - uint16_t : 16; - // 80 - union { - uint16_t raw; - struct { - uint8_t : 1; - uint8_t ata1 : 1; - uint8_t ata2 : 1; - uint8_t ata3 : 1; - uint8_t ata4 : 1; - uint8_t ata5 : 1; - uint8_t ata6 : 1; - uint8_t ata7 : 1; - uint16_t : 8; - } __attribute__((packed)) bits; - } major_version; - uint16_t minor_version; - - union { - uint16_t raw[2]; - struct { - // Word 82 - uint8_t smart : 1; - uint8_t security_mode : 1; - uint8_t removable_media : 1; - uint8_t power_management : 1; - uint8_t packet : 1; - uint8_t write_cache : 1; - uint8_t look_ahead : 1; - uint8_t release_int : 1; - uint8_t service_int : 1; - uint8_t device_reset : 1; - uint8_t hpa : 1; // Host protected area - uint8_t : 1; - uint8_t write_buffer : 1; - uint8_t read_buffer : 1; - uint8_t nop : 1; - uint8_t : 1; - - // Word 83 - uint8_t download_microcode : 1; - uint8_t rw_dma_queued : 1; - uint8_t cfa : 1; - uint8_t apm : 1; // Advanced power management - uint8_t removable_media_sn : 1; // R. Media Status notification - uint8_t power_up_standby : 1; - uint8_t set_features_spinup : 1; - uint8_t : 1; - uint8_t set_max_security : 1; - uint8_t auto_acoustic_mngmnt: 1; // Automatic acoustic management - uint8_t lba48 : 1; - uint8_t dev_config_overlay : 1; - uint8_t flush_cache : 1; - uint8_t flush_cache_ext : 1; - uint8_t : 2; - } __attribute__((packed)) bits; - } features_support; - // 83 - uint16_t todo[17]; - // 100 - uint64_t max_lba48_address; - // 107 - uint16_t todo2[153]; -} __attribute__((packed)); - - -/** * ATA-Geraet identifizieren * * @return 0 Wenn das Geraet erfolgreich identifiziert wurde, != 0 sonst @@ -245,17 +79,17 @@ int ata_drv_identify(struct ata_device* dev) // Pruefen, welche LBA-Modi dabei sind if (id.features_support.bits.lba48) { dev->lba48 = 1; - dev->storage.block_count = id.max_lba48_address; + dev->dev.storage.block_count = id.max_lba48_address; } if (id.capabilities.lba) { dev->lba28 = 1; - dev->storage.block_count = id.lba_sector_count; + dev->dev.storage.block_count = id.lba_sector_count; } // Wenn keiner der LBA-Modi unterstuetzt wird, muss abgebrochen werden, da // CHS noch nicht implementiert ist. if (!dev->lba48 && !dev->lba28) { - printf("ata: Geraet unterstuetzt nur CHS.\n"); + DEBUG("Geraet unterstuetzt nur CHS.\n"); return 0; } diff --git a/src/modules/cdi/ata/atapi.c b/src/modules/cdi/ata/atapi.c index a596edb..ecff315 100644 --- a/src/modules/cdi/ata/atapi.c +++ b/src/modules/cdi/ata/atapi.c @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) 2007 The tyndur Project. All rights reserved. * * This code is derived from software contributed to the tyndur Project @@ -20,16 +20,16 @@ * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ @@ -40,6 +40,7 @@ #include "cdi/storage.h" #include "cdi/misc.h" #include "cdi/io.h" +#include "cdi/scsi.h" #include "device.h" @@ -51,7 +52,7 @@ */ int atapi_drv_identify(struct ata_device* dev) { - uint8_t buffer[ATA_SECTOR_SIZE]; + struct ata_identfiy_data id; // Request vorbereiten struct ata_request request = { @@ -66,22 +67,87 @@ int atapi_drv_identify(struct ata_device* dev) .registers.ata.command = IDENTIFY_PACKET_DEVICE, .block_count = 1, .block_size = ATA_SECTOR_SIZE, - .buffer = buffer, + .buffer = &id, .error = 0 }; - + // Request starten if (!ata_request(&request)) { // Pech gehabt return 0; } - + // Es handelt sich um ein ATAPI-Geraet dev->atapi = 1; - // TODO: Informationen verarbeiten - return 1; } +void atapi_init_device(struct cdi_device* device) +{ + struct cdi_scsi_device* scsi = (struct cdi_scsi_device*) device; + + scsi->type = CDI_STORAGE; + cdi_scsi_device_init(scsi); +} + +void atapi_remove_device(struct cdi_device* device) +{ + +} + +int atapi_request(struct cdi_scsi_device* scsi,struct cdi_scsi_packet* packet) +{ + struct ata_device *dev = (struct ata_device*)scsi; + struct ata_request request = { + .dev = dev, + .protocol = PIO, + .flags = { + .direction = WRITE, + .poll = 1, + .ata = 0, // Ich brauch nur ATA-Befehle (Packet) + .lba = 0 // Der Kommentar in device.h ist kein deutscher Satz! + }, + .registers = { + .ata = { + .command = PACKET, + .lba = 0x00FFFF00 // Sonst hat bei mir nachher nichts in den + // LBA-Registern dringestanden und die + // braucht man ja fuer die Paketgroesse. + } + }, + .block_count = 1, + .block_size = packet->cmdsize, + .blocks_done = 0, + .buffer = packet->command, + .error = 0 + }; + + if (ata_request(&request)) + { + struct ata_request rw_request = { + .dev = dev, + .flags = { + .poll = 1, + .lba = 1, + .ata = 1 + }, + .block_count = 1, + .block_size = packet->bufsize, + .blocks_done = 0, + .buffer = packet->buffer, + .error = 0 + }; + + // Lesen bzw. Schreiben der Daten + // TODO: DMA + if (packet->direction==CDI_SCSI_READ) ata_protocol_pio_in(&rw_request); + else if (packet->direction==CDI_SCSI_WRITE) ata_protocol_pio_in(&rw_request); + + // Sense Key zurueck + return (ata_reg_inb(dev->controller,REG_ERROR)>>4); + } + + return 0xB; +} diff --git a/src/modules/cdi/ata/device.c b/src/modules/cdi/ata/device.c index fcedeae..4bf4a14 100644 --- a/src/modules/cdi/ata/device.c +++ b/src/modules/cdi/ata/device.c @@ -40,12 +40,11 @@ #include "cdi/storage.h" #include "cdi/misc.h" #include "cdi/io.h" +#include "cdi/scsi.h" #include "device.h" #include "libpartition.h" -#define MAX(a, b) (a > b ? a : b) - // IRQ-Handler static inline void ata_controller_irq(struct cdi_device* dev); @@ -76,6 +75,8 @@ static int ata_bus_floating(struct ata_controller* controller) ata_reg_outb(controller, REG_DEVICE, DEVICE_DEV(1)); ATA_DELAY(controller); status = ata_reg_inb(controller, REG_STATUS); + + // Wenn alle Bits gesetzt sind, ist der Bus floating return (status == 0xFF); } @@ -182,13 +183,13 @@ void ata_parse_partitions(struct ata_device* dev) // Die Partitionstabelle liegt im MBR if (!dev->read_sectors(dev, 0, 1, mbr)) { - printf("ata: Fehler beim Einlesen der Partitionstabelle"); + DEBUG("Fehler beim Einlesen der Partitionstabelle"); return; } // Partitionstabelle Verarbeiten if (!partition_table_fill(&partition_table, mbr)) { - printf("ata: Fehler beim Verarbeiten der Partitionstabelle"); + DEBUG("Fehler beim Verarbeiten der Partitionstabelle"); return; } @@ -197,23 +198,23 @@ void ata_parse_partitions(struct ata_device* dev) if (partition_table.entries[i].used) { // Erweiterter Eintrag => ueberspringen if (partition_table.entries[i].type == PARTITION_TYPE_EXTENDED) { - printf("ata: TODO Erweiterte Partitionstabelleneintraege\n"); + DEBUG("TODO Erweiterte Partitionstabelleneintraege\n"); continue; } struct ata_partition* partition = malloc(sizeof(*partition)); - partition->dev = dev; + partition->realdev = dev; partition->null = NULL; partition->start = partition_table.entries[i].start; - partition->storage.block_size = ATA_SECTOR_SIZE; - partition->storage.block_count = partition_table.entries[i].size; - printf("ata: Partition von %d bis %d\n", partition->start, partition->storage.block_count + partition->start - 1); - asprintf((char**) &(partition->storage.dev.name), "ata%01d%01d_p%01d", + partition->dev.storage.block_size = ATA_SECTOR_SIZE; + partition->dev.storage.block_count = partition_table.entries[i].size; + DEBUG("Partition von %d bis %d\n", partition->start, partition->dev.storage.block_count + partition->start - 1); + asprintf((char**) &(partition->dev.storage.dev.name), "ata%01d%01d_p%01d", (uint32_t) dev->controller->id, dev->id, cdi_list_size(dev-> partition_list)); // Geraet registrieren - cdi_list_push(dev->controller->driver->drv.devices, partition); + cdi_list_push(dev->controller->storage->drv.devices, partition); // An Partitionsliste fuer das aktuelle Geraet anhaengen cdi_list_push(dev->partition_list, partition); @@ -233,11 +234,11 @@ void ata_init_controller(struct ata_controller* controller) // Ports registrieren if (cdi_ioports_alloc(controller->port_cmd_base, 8) != 0) { - printf("ata: Fehler beim allozieren der I/O-Ports\n"); + DEBUG("Fehler beim allozieren der I/O-Ports\n"); return; } if (cdi_ioports_alloc(controller->port_ctl_base, 1) != 0) { - printf("ata: Fehler beim allozieren der I/O-Ports\n"); + DEBUG("Fehler beim allozieren der I/O-Ports\n"); cdi_ioports_free(controller->port_cmd_base, 8); return; } @@ -267,7 +268,7 @@ void ata_init_controller(struct ata_controller* controller) // Jetzt pruefen wir ob der Bus leer ist (mehr dazu bei ata_bus_floating). if (ata_bus_floating(controller)) { - printf("ata: Floating Bus %d\n", controller->id); + DEBUG("Floating Bus %d\n", controller->id); return; } @@ -275,7 +276,7 @@ void ata_init_controller(struct ata_controller* controller) // darauf geachtet werden, dass der Master auch antworten muss, wenn zwar // der Slave ausgewaehlt ist, aber nicht existiert. if (!ata_bus_responsive_drv(controller)) { - printf("ata: No responsive drive on Bus %d\n", controller->id); + DEBUG("No responsive drive on Bus %d\n", controller->id); return; } @@ -285,30 +286,39 @@ void ata_init_controller(struct ata_controller* controller) struct ata_device* dev = malloc(sizeof(*dev)); dev->controller = controller; dev->id = i; - dev->storage.block_size = ATA_SECTOR_SIZE; dev->partition_list = cdi_list_create(); if (ata_drv_identify(dev)) { - printf("Bus %d Device %d: ATAPI=%d\n", (uint32_t) controller->id, i, dev->atapi); + DEBUG("Bus %d Device %d: ATAPI=%d\n", (uint32_t) controller->id, i, dev->atapi); + +#ifdef ATAPI_ENABLE if (dev->atapi == 0) { +#endif + dev->dev.storage.block_size = ATA_SECTOR_SIZE; + // Handler setzen dev->read_sectors = ata_drv_read_sectors; dev->write_sectors = ata_drv_write_sectors; // Name setzen - asprintf((char**) &(dev->storage.dev.name), "ata%01d%01d", + asprintf((char**) &(dev->dev.storage.dev.name), "ata%01d%01d", (uint32_t) controller->id, i); // Partitionen parsen ata_parse_partitions(dev); + + // Geraet registrieren + cdi_list_push(controller->storage->drv.devices, dev); +#ifdef ATAPI_ENABLE } else { // Name setzen - asprintf((char**) &(dev->storage.dev.name), "atapi%01d%01d", + asprintf((char**) &(dev->dev.scsi.dev.name),"atapi%01d%01d", (uint32_t) controller->id, i); - } // Geraet registrieren - cdi_list_push(controller->driver->drv.devices, dev); + cdi_list_push(controller->scsi->drv.devices, dev); + } +#endif } else { free(dev); } @@ -324,7 +334,7 @@ void ata_remove_controller(struct ata_controller* controller) void ata_init_device(struct cdi_device* device) { struct ata_device* dev = (struct ata_device*) device; - cdi_storage_device_init(&dev->storage); + cdi_storage_device_init(&dev->dev.storage); } void ata_remove_device(struct cdi_device* device) @@ -346,7 +356,7 @@ int ata_read_blocks(struct cdi_storage_device* device, uint64_t block, // Partition if (dev->controller == NULL) { partition = (struct ata_partition*) dev; - dev = partition->dev; + dev = partition->realdev; } // Natuerlich nur ausfuehren wenn ein Handler eingetragen ist @@ -376,7 +386,7 @@ int ata_write_blocks(struct cdi_storage_device* device, uint64_t block, // Partition if (dev->controller == NULL) { partition = (struct ata_partition*) dev; - dev = partition->dev; + dev = partition->realdev; } // Natuerlich nur ausfuehren wenn ein Handler eingetragen ist diff --git a/src/modules/cdi/ata/device.h b/src/modules/cdi/ata/device.h index be1e86b..140f037 100644 --- a/src/modules/cdi/ata/device.h +++ b/src/modules/cdi/ata/device.h @@ -36,12 +36,17 @@ #ifndef _ATA_DEVICE_H_ #define _ATA_DEVICE_H_ +#undef DEBUG_ENABLE + #include #include "cdi.h" #include "cdi/storage.h" #include "cdi/io.h" #include "cdi/lists.h" +#include "cdi/scsi.h" + +#define ATAPI_ENABLE #define ATA_PRIMARY_CMD_BASE 0x1F0 #define ATA_PRIMARY_CTL_BASE 0x3F6 @@ -105,20 +110,198 @@ #define CONTROL_SRST (1 << 2) #define CONTROL_NIEN (1 << 1) +// Debug +#ifdef DEBUG_ENABLE + #define DEBUG(fmt, ...) printf("ata: " fmt, __VA_ARGS__) +#else + #define DEBUG(...) +#endif + +/** + * Resultat beim IDENTIFY DEVICE Befehl + */ +struct ata_identfiy_data { + struct { + uint8_t : 7; + uint8_t removable : 1; + uint8_t : 7; + uint8_t ata : 1; + } __attribute__((packed)) general_config; + + uint16_t log_cyl; // Veraltet + uint16_t : 16; + uint16_t log_heads; // Veraltet + uint16_t : 16; + uint16_t : 16; + uint16_t log_spt; // Veraltet + uint16_t : 16; + // 8 + uint16_t : 16; + uint16_t : 16; + char serial_number[20]; + // 20 + uint16_t : 16; + uint16_t : 16; + uint16_t : 16; + char firmware_revision[8]; + // 27 + char model_number[40]; + uint8_t : 8; // Immer 0x80 + uint8_t max_sec_per_irq; + // 48 + uint16_t : 16; + struct { + uint16_t : 8; + uint8_t dma : 1; + uint8_t lba : 1; + uint8_t iordy_disabled : 1; + uint8_t irdy_supported : 1; + uint8_t : 1; + uint8_t : 1; // Irgendwas mit Standbytimer + uint8_t : 2; + } __attribute__((packed)) capabilities; + uint16_t : 16; // Noch ein paar Faehigkeiten, + // die wir aber sicher nicht + // brauchen + uint8_t : 8; + uint8_t pio_mode_number; + uint16_t : 16; + struct { + uint8_t current_chs : 1; // Words 54-56 + uint8_t transfer_settings : 1; // Words 64-70 + uint8_t ultra_dma : 1; // Word 88 + uint16_t : 13; + } __attribute__((packed)) valid_words; + uint16_t cur_log_cyl; // Veraltet + uint16_t cur_log_heads; // Veraltet + // 56 + uint16_t cur_log_spt; // Veraltet + uint16_t chs_capacity[2]; // Veraltet + struct { + uint8_t cur_sec_per_int : 8; + uint8_t setting_valid : 1; + uint8_t : 7; + } __attribute__((packed)) multi_sector; + uint32_t lba_sector_count; // LBA28 + uint16_t : 16; + struct { + uint8_t : 1; + uint8_t mode0_supported : 1; + uint8_t mode1_supported : 1; + uint8_t mode2_supported : 1; + uint8_t : 4; + uint8_t mode0_selected : 1; + uint8_t mode1_selected : 1; + uint8_t mode2_selected : 1; + uint8_t : 5; + } __attribute__((packed)) multiword_dma; + // 64 + uint8_t pio_modes_supported; + uint8_t : 8; + // Multiword dma Zeiten + uint16_t mwd_time1; + uint16_t mwd_time2; + uint16_t mwd_time3; + uint16_t mwd_time4; + uint16_t : 16; + uint16_t : 16; + uint16_t : 16; + // 72 + uint16_t : 16; + uint16_t : 16; + uint16_t : 16; + struct { + uint8_t max_depth : 5; + uint16_t : 11; + } __attribute__((packed)) queue_depth; + uint16_t : 16; + uint16_t : 16; + uint16_t : 16; + uint16_t : 16; + // 80 + union { + uint16_t raw; + struct { + uint8_t : 1; + uint8_t ata1 : 1; + uint8_t ata2 : 1; + uint8_t ata3 : 1; + uint8_t ata4 : 1; + uint8_t ata5 : 1; + uint8_t ata6 : 1; + uint8_t ata7 : 1; + uint16_t : 8; + } __attribute__((packed)) bits; + } major_version; + uint16_t minor_version; + union { + uint16_t raw[2]; + struct { + // Word 82 + uint8_t smart : 1; + uint8_t security_mode : 1; + uint8_t removable_media : 1; + uint8_t power_management : 1; + uint8_t packet : 1; + uint8_t write_cache : 1; + uint8_t look_ahead : 1; + uint8_t release_int : 1; + uint8_t service_int : 1; + uint8_t device_reset : 1; + uint8_t hpa : 1; // Host protected area + uint8_t : 1; + uint8_t write_buffer : 1; + uint8_t read_buffer : 1; + uint8_t nop : 1; + uint8_t : 1; + + // Word 83 + uint8_t download_microcode : 1; + uint8_t rw_dma_queued : 1; + uint8_t cfa : 1; + uint8_t apm : 1; // Advanced power management + uint8_t removable_media_sn : 1; // R. Media Status notification + uint8_t power_up_standby : 1; + uint8_t set_features_spinup : 1; + uint8_t : 1; + uint8_t set_max_security : 1; + uint8_t auto_acoustic_mngmnt: 1; // Automatic acoustic management + uint8_t lba48 : 1; + uint8_t dev_config_overlay : 1; + uint8_t flush_cache : 1; + uint8_t flush_cache_ext : 1; + uint8_t : 2; + } __attribute__((packed)) bits; + } features_support; + // 83 + uint16_t todo[17]; + // 100 + uint64_t max_lba48_address; + // 107 + uint16_t todo2[153]; +} __attribute__((packed)); struct ata_partition { - struct cdi_storage_device storage; + union { + struct cdi_storage_device storage; + struct cdi_scsi_device scsi; + } dev; + // Muss auf NULL gesetzt werden void* null; - struct ata_device* dev; + struct ata_device* realdev; // Startsektor uint32_t start; }; struct ata_device { - struct cdi_storage_device storage; + union { + struct cdi_storage_device storage; + struct cdi_scsi_device scsi; + } dev; + // In der Partitionstruktur ist dieses Feld null, um Partitionen erkennen // zu koennen. struct ata_controller* controller; @@ -129,6 +312,7 @@ struct ata_device { uint8_t id; // 1 wenn es sich um ein ATAPI-Gerat handelt, 0 sonst + // Bei ATAPI-Geraeten wir im union dev scsi verwendet, ansonsten storage uint8_t atapi; // 1 Wenn das Geraet lba48 unterstuetzt @@ -145,7 +329,8 @@ struct ata_device { }; struct ata_controller { - struct cdi_storage_driver* driver; + struct cdi_storage_driver *storage; + struct cdi_scsi_driver *scsi; uint8_t id; uint16_t port_cmd_base; @@ -191,16 +376,13 @@ struct ata_request { enum { IDENTIFY_DEVICE = 0xEC, IDENTIFY_PACKET_DEVICE = 0xA1, + PACKET = 0xA0, READ_SECTORS = 0x20, WRITE_SECTORS = 0x30 } command; uint8_t count; uint64_t lba; } ata; - - // Parameter fuer ATAPI-Operationen - struct { - } atapi; } registers; // Anzahl der Blocks die uebertragen werden sollen @@ -225,7 +407,6 @@ struct ata_request { } error; }; - void ata_init_controller(struct ata_controller* controller); void ata_remove_controller(struct ata_controller* controller); void ata_init_device(struct cdi_device* device); @@ -239,6 +420,9 @@ int ata_write_blocks(struct cdi_storage_device* device, uint64_t block, // Einen ATA-Request absenden und ausfuehren int ata_request(struct ata_request* request); +int ata_protocol_pio_out(struct ata_request* request); +int ata_protocol_pio_in(struct ata_request* request); + // ATA-Funktionen int ata_drv_identify(struct ata_device* dev); int ata_drv_read_sectors(struct ata_device* dev, uint64_t start, size_t count, @@ -248,6 +432,9 @@ int ata_drv_write_sectors(struct ata_device* dev, uint64_t start, size_t count, // ATAPI-Funktionen int atapi_drv_identify(struct ata_device* dev); +void atapi_init_device(struct cdi_device* device); +void atapi_remove_device(struct cdi_device* device); +int atapi_request(struct cdi_scsi_device* dev,struct cdi_scsi_packet* packet); // Auf einen IRQ warten int ata_wait_irq(struct ata_controller* controller, uint32_t timeout); diff --git a/src/modules/cdi/ata/main.c b/src/modules/cdi/ata/main.c index f7a94cf..750f7b2 100644 --- a/src/modules/cdi/ata/main.c +++ b/src/modules/cdi/ata/main.c @@ -38,21 +38,19 @@ #include #include "cdi/storage.h" -#include "cdi/pci.h" #include "cdi/lists.h" #include "device.h" -struct ata_driver { - struct cdi_storage_driver storage; -}; - -static struct ata_driver driver; -static const char* driver_name = "ata"; +static struct cdi_storage_driver driver_storage; +static struct cdi_scsi_driver driver_scsi; +static const char* driver_storage_name = "ata"; +static const char* driver_scsi_name = "atapi"; static cdi_list_t controller_list = NULL; static void ata_driver_init(void); static void ata_driver_destroy(struct cdi_driver* driver); +static void atapi_driver_destroy(struct cdi_driver* driver); #ifdef CDI_STANDALONE int main(void) @@ -62,7 +60,8 @@ int init_ata(void) { cdi_init(); ata_driver_init(); - cdi_storage_driver_register((struct cdi_storage_driver*) &driver); + cdi_storage_driver_register((struct cdi_storage_driver*) &driver_storage); + cdi_scsi_driver_register((struct cdi_scsi_driver*) &driver_scsi); #ifdef CDI_STANDALONE cdi_run_drivers(); @@ -79,29 +78,36 @@ static void ata_driver_init() struct ata_controller* controller; // Konstruktor der Vaterklasse - cdi_storage_driver_init((struct cdi_storage_driver*) &driver); + cdi_storage_driver_init((struct cdi_storage_driver*) &driver_storage); + cdi_scsi_driver_init((struct cdi_scsi_driver*) &driver_scsi); // Namen setzen - driver.storage.drv.name = driver_name; + driver_storage.drv.name = driver_storage_name; + driver_scsi.drv.name = driver_scsi_name; // Funktionspointer initialisieren - driver.storage.drv.destroy = ata_driver_destroy; - driver.storage.drv.init_device = ata_init_device; - driver.storage.drv.remove_device = ata_remove_device; - driver.storage.read_blocks = ata_read_blocks; - driver.storage.write_blocks = ata_write_blocks; + driver_storage.drv.destroy = ata_driver_destroy; + driver_storage.drv.init_device = ata_init_device; + driver_storage.drv.remove_device = ata_remove_device; + driver_storage.read_blocks = ata_read_blocks; + driver_storage.write_blocks = ata_write_blocks; + + driver_scsi.drv.destroy = atapi_driver_destroy; + driver_scsi.drv.init_device = atapi_init_device; + driver_scsi.drv.remove_device = atapi_remove_device; + driver_scsi.request = atapi_request; // Liste mit Controllern initialisieren controller_list = cdi_list_create(); - // Primaeren Controller vorbereiten controller = malloc(sizeof(*controller)); controller->port_cmd_base = ATA_PRIMARY_CMD_BASE; controller->port_ctl_base = ATA_PRIMARY_CTL_BASE; controller->irq = ATA_PRIMARY_IRQ; controller->id = 0; - controller->driver = (struct cdi_storage_driver*) &driver; + controller->storage = (struct cdi_storage_driver*) &driver_storage; + controller->scsi = (struct cdi_scsi_driver*) &driver_scsi; ata_init_controller(controller); cdi_list_push(controller_list, controller); @@ -111,7 +117,8 @@ static void ata_driver_init() controller->port_ctl_base = ATA_SECONDARY_CTL_BASE; controller->irq = ATA_SECONDARY_IRQ; controller->id = 1; - controller->driver = (struct cdi_storage_driver*) &driver; + controller->storage = (struct cdi_storage_driver*) &driver_storage; + controller->scsi = (struct cdi_scsi_driver*) &driver_scsi; ata_init_controller(controller); cdi_list_push(controller_list, controller); } @@ -125,3 +132,8 @@ static void ata_driver_destroy(struct cdi_driver* driver) // TODO Alle Karten deinitialisieren } + +static void atapi_driver_destroy(struct cdi_driver* driver) +{ + cdi_scsi_driver_destroy((struct cdi_scsi_driver*) driver); +} diff --git a/src/modules/cdi/ata/request.c b/src/modules/cdi/ata/request.c index 9bd91a5..5071048 100644 --- a/src/modules/cdi/ata/request.c +++ b/src/modules/cdi/ata/request.c @@ -162,7 +162,7 @@ static int ata_protocol_non_data(struct ata_request* request) // Auf IRQ warten if (ata_wait_irq(ctrl, ATA_IRQ_TIMEOUT)) { request->error = IRQ_TIMEOUT; - printf("ata: non_data IRQ-Timeout\n"); + DEBUG("non_data IRQ-Timeout\n"); return 0; } @@ -192,10 +192,11 @@ static int ata_protocol_non_data(struct ata_request* request) * sollen. * Nach Kapitel 11 in der ATA7-Spec */ -static int ata_protocol_pio_in(struct ata_request* request) +int ata_protocol_pio_in(struct ata_request* request) { struct ata_device* dev = request->dev; struct ata_controller* ctrl = dev->controller; + size_t packet_size = 0; // Aktueller Status im Protokol enum { @@ -217,10 +218,16 @@ static int ata_protocol_pio_in(struct ata_request* request) // Auf IRQ warten if (ata_wait_irq(ctrl, ATA_IRQ_TIMEOUT)) { request->error = IRQ_TIMEOUT; - printf("ata: pio_in IRQ-Timeout\n"); + DEBUG("pio_in IRQ-Timeout\n"); return 0; } + if (request->flags.ata && packet_size==0) // ATAPI + { + // Paketgroesse einlesen, da sonst unendlich viel gelesen wird + packet_size = ata_reg_inb(ctrl,REG_LBA_MID)|(ata_reg_inb(ctrl,REG_LBA_HIG)<<8); + } + // Jetzt muss der Status ueberprueft werden state = CHECK_STATUS; break; @@ -233,7 +240,7 @@ static int ata_protocol_pio_in(struct ata_request* request) // gelaufen. if ((status & (STATUS_BSY | STATUS_DRQ)) == 0) { // TODO: Fehlerbehandlung - printf("ata: pio_in unerwarteter Status: 0x%x\n", status); + DEBUG("pio_in unerwarteter Status: 0x%x\n", status); return 0; } else if ((status & STATUS_BSY) == STATUS_BSY) { // Wenn das Busy-Flag gesetzt ist, muss gewartet werden, @@ -252,7 +259,6 @@ static int ata_protocol_pio_in(struct ata_request* request) uint16_t* buffer = (uint16_t*) (request->buffer + (request-> blocks_done * request->block_size)); - // Einen Block einlesen ata_insw(ata_reg_base(ctrl, REG_DATA) + REG_DATA, buffer, request->block_size / 2); @@ -260,10 +266,17 @@ static int ata_protocol_pio_in(struct ata_request* request) request->blocks_done++; // Naechste Transaktion ausfindig machen - if (request->blocks_done >= request->block_count) { + if (!request->flags.ata && + request->blocks_done >= request->block_count) { // Wenn alle Blocks gelesen wurden ist der Transfer // abgeschlossen. return 1; + } else if (request->flags.ata && + request->blocks_done*request->block_size>=packet_size) + { + // Wenn alle Bytes des ATAPI-Paketes gelesen wurden + // ist der Transfer abgeschlossen + return 1; } else if (request->flags.poll) { // Wenn gepollt wird, muss jetzt gewartet werden, bis der // Status wieder stimmt um den naechsten Block zu lesen. @@ -282,10 +295,11 @@ static int ata_protocol_pio_in(struct ata_request* request) * Verarbeitet einen ATA-Request bei dem Daten ueber PIO geschrieben werden * sollen */ -static int ata_protocol_pio_out(struct ata_request* request) +int ata_protocol_pio_out(struct ata_request* request) { struct ata_device* dev = request->dev; struct ata_controller* ctrl = dev->controller; + size_t packet_size = 0; // Aktueller Status im Protokol enum { @@ -301,10 +315,17 @@ static int ata_protocol_pio_out(struct ata_request* request) // Auf IRQ warten if (ata_wait_irq(ctrl, ATA_IRQ_TIMEOUT)) { request->error = IRQ_TIMEOUT; - printf("ata: pio_out IRQ-Timeout\n"); + DEBUG("pio_out IRQ-Timeout\n"); return 0; } + if (request->flags.ata && packet_size==0) // ATAPI + { + // Paketgroesse einlesen, da sonst unendlich viel geschrieben wird + packet_size = ata_reg_inb(ctrl,REG_LBA_MID)|(ata_reg_inb(ctrl,REG_LBA_HIG)<<8); + DEBUG("packet_size = %d\n",packet_size); + } + // Jetzt muss der Status ueberprueft werden state = CHECK_STATUS; break; @@ -312,18 +333,26 @@ static int ata_protocol_pio_out(struct ata_request* request) case CHECK_STATUS: { uint8_t status = ata_reg_inb(ctrl, REG_STATUS); - // Status ueberpruefen - // Wenn DRQ und BSY geloescht wurden ist irgendetwas schief - // gelaufen, falls der Befehl noch nicht zu Ende ist - if ((status & (STATUS_BSY | STATUS_DRQ)) == 0) { - if (request->blocks_done != request->block_count) { - // TODO: Fehlerbehandlung - printf("ata: pio_out unerwarteter Status: 0x%x\n", - status); - return 0; - } else { - return 1; - } + if (request->flags.ata && + request->blocks_done * request->block_size>=packet_size) + { + // Das Paket wurde vollstaendig gelesen. DRQ wird nicht + // gesetzt, deswegen muss so beendet werden. + return 1; + } + else if (!request->flags.ata && + request->blocks_done==request->block_count) + { + // Der Buffer wurde komplett gelesen. Dies sollte bei + // ATAPI nicht passieren! + return 1; + } + else if ((status & (STATUS_BSY | STATUS_DRQ)) == 0) + { + // TODO: Fehlerbehandlung + DEBUG("pio_out unerwarteter Status: 0x%x\n", status); + return 0; + } else if ((status & STATUS_BSY) == STATUS_BSY) { // Wenn das Busy-Flag gesetzt ist, muss gewartet werden, // bis es geloescht wird. @@ -375,7 +404,7 @@ int ata_request(struct ata_request* request) // printf("ata: [%d:%d] Request command=%x count=%x lba=%llx protocol=%x\n", request->dev->controller->id, request->dev->id, request->registers.ata.command, request->registers.ata.count, request->registers.ata.lba, request->protocol); // Befehl ausfuehren if (!ata_request_command(request)) { - printf("ata: Fehler bei der Befehlsausfuehrung\n"); + DEBUG("Fehler bei der Befehlsausfuehrung\n"); return 0; } -- 1.5.4.5 From kevin at tyndur.org Sun Jan 4 15:20:37 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Sun, 4 Jan 2009 15:20:37 +0100 Subject: [tyndur-devel] [PATCH v3 4/5] cdi/scsi: Unterstuetzung fuer CD-ROM-Laufwerke In-Reply-To: <1231078838-3065-1-git-send-email-kevin@tyndur.org> References: <1231078838-3065-1-git-send-email-kevin@tyndur.org> Message-ID: <1231078838-3065-5-git-send-email-kevin@tyndur.org> + cdi/scsi: Unterstuetzung fuer CD-ROM-Laufwerke --- doc/COPYRIGHT | 23 ++++ src/modules/cdi/include/cdi.h | 3 + src/modules/cdi/include/cdi/scsi.h | 6 + src/modules/cdi/lib/scsi/disk.c | 253 ++++++++++++++++++++++++++++++++++++ src/modules/cdi/lib/scsi/driver.c | 12 ++ src/modules/cdi/lib/storage.c | 4 +- 6 files changed, 299 insertions(+), 2 deletions(-) create mode 100644 src/modules/cdi/lib/scsi/disk.c diff --git a/doc/COPYRIGHT b/doc/COPYRIGHT index 66abeb4..a69002f 100644 --- a/doc/COPYRIGHT +++ b/doc/COPYRIGHT @@ -129,3 +129,26 @@ Parts of tyndur are derived from ZLib and are distributed under the Zlib terms: Portions of this software are copyright (c) 2007 The FreeType Project (www.freetype.org). All rights reserved. + +Parts of tyndur are derived from software under the following license: + + Copyright (C) 2008 Mathias Gottschlag + Copyright (C) 2009 Kevin Wolf + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to + deal in the Software without restriction, including without limitation the + rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + sell copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. diff --git a/src/modules/cdi/include/cdi.h b/src/modules/cdi/include/cdi.h index 5fb7025..c6215a6 100644 --- a/src/modules/cdi/include/cdi.h +++ b/src/modules/cdi/include/cdi.h @@ -32,6 +32,9 @@ struct cdi_device { cdi_device_type_t type; const char* name; struct cdi_driver* driver; + + // tyndur-spezifisch + void* backdev; }; struct cdi_driver { diff --git a/src/modules/cdi/include/cdi/scsi.h b/src/modules/cdi/include/cdi/scsi.h index 9f5b0e7..7b80975 100644 --- a/src/modules/cdi/include/cdi/scsi.h +++ b/src/modules/cdi/include/cdi/scsi.h @@ -52,6 +52,12 @@ struct cdi_scsi_device { /// Geraetetyp, der ueber SCSI angesteuert wird cdi_device_type_t type; + /** + * tyndur-spezifisch: Frontend-Geraet (z.B. CDI_STORAGE-Geraet, das ueber + * SCSI angesteuert wird) + */ + void* frontdev; + }; /// SCSI-Treiber diff --git a/src/modules/cdi/lib/scsi/disk.c b/src/modules/cdi/lib/scsi/disk.c new file mode 100644 index 0000000..e82d0d7 --- /dev/null +++ b/src/modules/cdi/lib/scsi/disk.c @@ -0,0 +1,253 @@ +/* + * Copyright (C) 2008 Mathias Gottschlag + * Copyright (C) 2009 Kevin Wolf + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include +#include +#include + +#include +#include +#include + +extern int lostio_mst_if_newdev(struct cdi_storage_device* device); + +#define big_endian_word(x) ((((x) & 0xFF) << 8) | (((x) & 0xFF00) >> 8)) +#define big_endian_dword(x) \ + ((big_endian_word((x) & 0xFFFF) << 16) | \ + (big_endian_word((x) >> 16))) + +static int cdi_scsi_disk_read(struct cdi_storage_device* device, + uint64_t start, uint64_t count, void* buffer); + +static int cdi_scsi_disk_write(struct cdi_storage_device* device, + uint64_t start, uint64_t count, void* buffer); + +struct cdi_storage_driver cdi_scsi_disk_driver = { + .read_blocks = cdi_scsi_disk_read, + .write_blocks = cdi_scsi_disk_write, +}; + +// TODO: This is kind of incomplete... -.- +// FIXME Das ist alles sehr CD-ROM-spezifisch hartkodiert... + +union cdrom_command +{ + struct + { + uint8_t opcode; + uint8_t reserved0; + uint32_t address; + uint8_t reserved1; + uint16_t length; + uint8_t reserved2; + } __attribute__ ((packed)) dfl; + struct + { + uint8_t opcode; + uint8_t reserved0; + uint32_t address; + uint32_t length; + uint16_t reserved1; + } __attribute__ ((packed)) ext; +}; + +static int cdrom_read_sector( + struct cdi_scsi_device *device, uint32_t sector, char *buffer) +{ + struct cdi_scsi_packet packet; + struct cdi_scsi_driver* drv = (struct cdi_scsi_driver*) device->dev.driver; + union cdrom_command* cmd = (union cdrom_command*) &packet.command; + + memset(&packet, 0, sizeof(packet)); + packet.direction = CDI_SCSI_READ; + packet.buffer = buffer; + packet.bufsize = 2048; + packet.cmdsize = 12; + + cmd->ext.opcode = 0xA8; + cmd->ext.address = big_endian_dword(sector); + cmd->ext.length = 0x01000000; + + if (drv->request(device, &packet)) { + return -1; + } + + return 0; +} + +static int cdrom_capacity(struct cdi_scsi_device *device, + uint32_t* num_sectors, uint32_t* sector_size) +{ + uint32_t buffer[32]; + struct cdi_scsi_packet packet; + struct cdi_scsi_driver* drv = (struct cdi_scsi_driver*) device->dev.driver; + union cdrom_command* cmd = (union cdrom_command*) &packet.command; + + memset(&packet, 0, sizeof(packet)); + packet.direction = CDI_SCSI_READ; + packet.buffer = buffer; + packet.bufsize = sizeof(buffer); + packet.cmdsize = 12; + + cmd->ext.opcode = 0x25; + + if (drv->request(device, &packet)) { + return -1; + } + + *num_sectors = big_endian_dword(buffer[0]); + *sector_size = big_endian_dword(buffer[1]); + + return 0; +} + +#if 0 +static int cdrom_lock_device(FsSCSIDevice *device, int index, int lock) +{ + // Lock drive + FsSCSIPacket packet; + memset(&packet, 0, sizeof(FsSCSIPacket)); + packet.direction = CDI_SCSI_NO_DATA; + ((union cdrom_command*)packet.command)->dfl.opcode = 0x1E; + packet.command[4] = 1; + packet.buffer = 0; + packet.length = 0; + packet.commandsize = 12; + uint32_t status = device->request(device, &packet); + if (status) + { + kePrint("cdrom %d: Lock failed, %x\n", index, status); + fsCloseSCSIDevice(device); + return KE_ERROR_UNKNOWN; + } + return 0; +} + +static void cdrom_sense(FsSCSIDevice *device, uint32_t index) +{ + char sense_data[18]; + FsSCSIPacket packet; + packet.direction = CDI_SCSI_READ; + packet.buffer = sense_data; + packet.length = 18; + packet.commandsize = 12; + ((union cdrom_command*)packet.command)->dfl.opcode = 0x12; +} +#endif + +int cdrom_init(struct cdi_scsi_device* device) +{ + // Send inquiry command + struct cdi_scsi_driver* drv = (struct cdi_scsi_driver*) device->dev.driver; + struct cdi_scsi_packet packet; + uint32_t status; + unsigned char inqdata[96]; + + memset(&packet, 0, sizeof(packet)); + memset(inqdata, 0xF0, sizeof(inqdata)); + + packet.direction = CDI_SCSI_READ; + packet.buffer = inqdata; + packet.bufsize = 96; + packet.cmdsize = 12; + + ((union cdrom_command*)packet.command)->dfl.opcode = 0x12; + packet.command[4] = 96; + status = drv->request(device, &packet); + if (status) + { + return -1; + } + +#if 0 + if (cdrom_lock_device(device, index, 1)) + return KE_ERROR_UNKNOWN; +#endif + + // Start drive + packet.direction = CDI_SCSI_NODATA; + ((union cdrom_command*)packet.command)->dfl.opcode = 0x1B; + packet.buffer = 0; + packet.bufsize = 0; + packet.command[4] = 0; + packet.command[4] = 3; + packet.cmdsize = 12; + + status = drv->request(device, &packet); + if (status) + { + printf("cdrom %d: Start failed, %x\n", index, status); + return -1; + } + + return 0; +} + +static int cdi_scsi_disk_read(struct cdi_storage_device* device, + uint64_t start, uint64_t count, void* buffer) +{ + struct cdi_scsi_device* dev = device->dev.backdev; + + while (count--) { + if (cdrom_read_sector(dev, start, buffer)) { + return -1; + } + start ++; + buffer += 2048; + } + + return 0; +} + +static int cdi_scsi_disk_write(struct cdi_storage_device* device, + uint64_t start, uint64_t count, void* buffer) +{ + return -1; +} + +int cdi_scsi_disk_init(struct cdi_scsi_device* device) +{ + struct cdi_storage_device* frontdev; + uint32_t num_sectors = 0, sector_size = 0; + + if (cdrom_init(device)) { + return -1; + } + + frontdev = calloc(1, sizeof(*frontdev)); + frontdev->dev.driver = (struct cdi_driver*) &cdi_scsi_disk_driver; + frontdev->dev.type = CDI_STORAGE; + frontdev->dev.name = device->dev.name; + + cdrom_capacity(device, &num_sectors, §or_size); + frontdev->block_size = sector_size; + frontdev->block_count = num_sectors; + + frontdev->dev.backdev = device; + device->frontdev = frontdev; + + // LostIO-Verzeichnisknoten anlegen + lostio_mst_if_newdev(frontdev); + + return 0; +} diff --git a/src/modules/cdi/lib/scsi/driver.c b/src/modules/cdi/lib/scsi/driver.c index 63e1e8c..22d7843 100644 --- a/src/modules/cdi/lib/scsi/driver.c +++ b/src/modules/cdi/lib/scsi/driver.c @@ -16,6 +16,8 @@ #include "cdi/scsi.h" +int cdi_scsi_disk_init(struct cdi_scsi_device* device); + /** * Initialisiert die Datenstrukturen fuer einen SCSI-Treiber */ @@ -40,6 +42,16 @@ void cdi_scsi_driver_destroy(struct cdi_scsi_driver* driver) */ void cdi_scsi_device_init(struct cdi_scsi_device* device) { + switch (device->type) { + case CDI_STORAGE: + cdi_scsi_disk_init(device); + break; + + default: + printf("Kein Frontend fuer SCSI-Geraete des Typs %d\n", + device->type); + break; + } } /** diff --git a/src/modules/cdi/lib/storage.c b/src/modules/cdi/lib/storage.c index df84be1..88a4528 100644 --- a/src/modules/cdi/lib/storage.c +++ b/src/modules/cdi/lib/storage.c @@ -17,7 +17,7 @@ #include "cdi/storage.h" static void lostio_mst_if_init(void); -static int lostio_mst_if_newdev(struct cdi_storage_device* device); +int lostio_mst_if_newdev(struct cdi_storage_device* device); static size_t lostio_mst_read_handler(lostio_filehandle_t* fh, void* buf, size_t blocksize, size_t blockcount); @@ -210,7 +210,7 @@ static void lostio_mst_if_init() /** * Erstellt den Dateisystemknoten fuer ein Geraet. */ -static int lostio_mst_if_newdev(struct cdi_storage_device* device) +int lostio_mst_if_newdev(struct cdi_storage_device* device) { // Slash vor Pfad angaengen char path[strlen(device->dev.name) + 2]; -- 1.5.4.5 From toni at tyndur.org Sun Jan 4 15:24:46 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 4 Jan 2009 15:24:46 +0100 Subject: [tyndur-devel] [PATCH v3 1/5] cdi/storage: Initialisierungsfunktion fuer Geraete In-Reply-To: <1231078838-3065-2-git-send-email-kevin@tyndur.org> References: <1231078838-3065-1-git-send-email-kevin@tyndur.org> <1231078838-3065-2-git-send-email-kevin@tyndur.org> Message-ID: <20090104142445.GA3101@thales.produktiv.lan> On Sun, Jan 04 15:20, Kevin Wolf wrote: > + cdi/storage: Initialisierungsfunktion fuer Geraete > * floppy, ata: Initialisierungsfunktion aufrufen Ack. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From janosch.graef at gmx.net Sun Jan 4 18:16:37 2009 From: janosch.graef at gmx.net (=?ISO-8859-1?Q?Janosch_Gr=E4f?=) Date: Sun, 04 Jan 2009 18:16:37 +0100 Subject: [tyndur-devel] [PATCH v3 2/5] cdi: SCSI In-Reply-To: <1231078838-3065-3-git-send-email-kevin@tyndur.org> References: <1231078838-3065-1-git-send-email-kevin@tyndur.org> <1231078838-3065-3-git-send-email-kevin@tyndur.org> Message-ID: <4960EEF5.8090305@gmx.net> Kevin Wolf schrieb: > + cdi: Headerdatei und leere Implementierung fuer SCSI-Geraete Ack. From kevin at tyndur.org Mon Jan 5 22:23:50 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 5 Jan 2009 22:23:50 +0100 Subject: [tyndur-devel] [PATCH 2/6] libc: POSIX: getuid/getgid In-Reply-To: <1231190634-3631-1-git-send-email-kevin@tyndur.org> References: <1231190634-3631-1-git-send-email-kevin@tyndur.org> Message-ID: <1231190634-3631-3-git-send-email-kevin@tyndur.org> + libc: POSIX: Stubs fuer getuid(), geteuid(), getgid(), getegid() --- src/modules/include/unistd.h | 13 +++++++++ src/modules/lib/posix/user.c | 60 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 0 deletions(-) create mode 100644 src/modules/lib/posix/user.c diff --git a/src/modules/include/unistd.h b/src/modules/include/unistd.h index 341b363..c7b7bbb 100644 --- a/src/modules/include/unistd.h +++ b/src/modules/include/unistd.h @@ -145,6 +145,19 @@ unsigned int sleep(unsigned int seconds); /// Datei umbenennen oder verschieben int rename(const char* path_old, const char* path_new); + +/// Gibt die aktuelle Benutzer-ID zurueck +uid_t getuid(void); + +/// Gibt die effektive Benutzer-ID zurueck +uid_t geteuid(void); + +/// Gibt die aktuelle Gruppen-ID zurueck +gid_t getgid(void); +// +/// Gibt die effektive Gruppen-ID zurueck +gid_t getegid(void); + #endif #endif diff --git a/src/modules/lib/posix/user.c b/src/modules/lib/posix/user.c new file mode 100644 index 0000000..4499b9c --- /dev/null +++ b/src/modules/lib/posix/user.c @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +/// Gibt die aktuelle Benutzer-ID zurueck +uid_t getuid(void) +{ + return 0; +} + +/// Gibt die effektive Benutzer-ID zurueck +uid_t geteuid(void) +{ + return 0; +} + +/// Gibt die aktuelle Gruppen-ID zurueck +gid_t getgid(void) +{ + return 0; +} + +/// Gibt die effektive Gruppen-ID zurueck +gid_t getegid(void) +{ + return 0; +} -- 1.5.4.5 From kevin at tyndur.org Mon Jan 5 22:23:48 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 5 Jan 2009 22:23:48 +0100 Subject: [tyndur-devel] [PATCH 0/6] Eine Runde POSIX Message-ID: <1231190634-3631-1-git-send-email-kevin@tyndur.org> Die folgenden Patches implementieren einige weitere POSIX-Funktionen (oder zumindest Stubs). Mit diesen Aenderungen laesst sich der e2fsprogs-lbuild bauen. From kevin at tyndur.org Mon Jan 5 22:23:49 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 5 Jan 2009 22:23:49 +0100 Subject: [tyndur-devel] [PATCH 1/6] libc: POSIX: pread() und pwrite() In-Reply-To: <1231190634-3631-1-git-send-email-kevin@tyndur.org> References: <1231190634-3631-1-git-send-email-kevin@tyndur.org> Message-ID: <1231190634-3631-2-git-send-email-kevin@tyndur.org> + libc: POSIX: pread() und pwrite() --- src/modules/include/unistd.h | 6 +++++ src/modules/lib/posix/posix_files.c | 41 +++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 0 deletions(-) diff --git a/src/modules/include/unistd.h b/src/modules/include/unistd.h index fa7dc2a..341b363 100644 --- a/src/modules/include/unistd.h +++ b/src/modules/include/unistd.h @@ -115,6 +115,12 @@ char* mktemp(char* template); /// Temporaere Datei anlegen int mkstemp(char* template); +/// In eine Datei mit gegebenem Offset lesen +ssize_t pread(int fd, void *buf, size_t count, off_t offset); + +/// In eine Datei mit gegebenem Offset schreiben +ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset); + #ifndef CONFIG_LIBC_NO_STUBS /// Prozess klonen pid_t fork(void); diff --git a/src/modules/lib/posix/posix_files.c b/src/modules/lib/posix/posix_files.c index bfa3601..659de16 100644 --- a/src/modules/lib/posix/posix_files.c +++ b/src/modules/lib/posix/posix_files.c @@ -346,6 +346,47 @@ int close(int fd) return 0; } +/// In eine Datei mit gegebenem Offset lesen +ssize_t pread(int fd, void *buf, size_t count, off_t offset) +{ + FILE* file = fd_to_file(fd); + off_t old_pos; + ssize_t ret; + + // Bei einem ungueltigen Deskriptor wird abgebrochen + if (file == NULL) { + errno = EBADF; + return -1; + } + + old_pos = ftell(file); + fseek(file, offset, SEEK_SET); + ret = read(fd, buf, count); + fseek(file, old_pos, SEEK_SET); + + return ret; +} + +/// In eine Datei mit gegebenem Offset schreiben +ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset) +{ + FILE* file = fd_to_file(fd); + off_t old_pos; + ssize_t ret; + + // Bei einem ungueltigen Deskriptor wird abgebrochen + if (file == NULL) { + errno = EBADF; + return -1; + } + + old_pos = ftell(file); + fseek(file, offset, SEEK_SET); + ret = write(fd, buf, count); + fseek(file, old_pos, SEEK_SET); + + return ret; +} #ifndef CONFIG_LIBC_NO_STUBS /** -- 1.5.4.5 From kevin at tyndur.org Mon Jan 5 22:23:51 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 5 Jan 2009 22:23:51 +0100 Subject: [tyndur-devel] [PATCH 3/6] libc: POSIX: Endianess-Umwandlung In-Reply-To: <1231190634-3631-1-git-send-email-kevin@tyndur.org> References: <1231190634-3631-1-git-send-email-kevin@tyndur.org> Message-ID: <1231190634-3631-4-git-send-email-kevin@tyndur.org> + libc: POSIX: htonl(), htons(), ntohl(), ntohs() --- src/modules/include/netinet/in.h | 45 ++++++++++++++++++++++++++++++ src/modules/lib/posix/net.c | 57 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 0 deletions(-) create mode 100644 src/modules/include/netinet/in.h create mode 100644 src/modules/lib/posix/net.c diff --git a/src/modules/include/netinet/in.h b/src/modules/include/netinet/in.h new file mode 100644 index 0000000..effc214 --- /dev/null +++ b/src/modules/include/netinet/in.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _NETINET_IN_H_ +#define _NETINET_IN_H_ + +unsigned long int htonl(unsigned long int hostlong); +unsigned short int htons(unsigned short int hostshort); +unsigned long int ntohl(unsigned long int netlong); +unsigned short int ntohs(unsigned short int netshort); + +#endif + diff --git a/src/modules/lib/posix/net.c b/src/modules/lib/posix/net.c new file mode 100644 index 0000000..c03bfd0 --- /dev/null +++ b/src/modules/lib/posix/net.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +unsigned long int htonl(unsigned long int hostlong) +{ + return big_endian_dword(hostlong); +} + +unsigned short int htons(unsigned short int hostshort) +{ + return big_endian_word(hostshort); +} + +unsigned long int ntohl(unsigned long int netlong) +{ + return big_endian_dword(netlong); +} + +unsigned short int ntohs(unsigned short int netshort) +{ + return big_endian_dword(netshort); +} -- 1.5.4.5 From kevin at tyndur.org Mon Jan 5 22:23:52 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 5 Jan 2009 22:23:52 +0100 Subject: [tyndur-devel] [PATCH 4/6] libc: POSIX: strtoul() und strtoull() In-Reply-To: <1231190634-3631-1-git-send-email-kevin@tyndur.org> References: <1231190634-3631-1-git-send-email-kevin@tyndur.org> Message-ID: <1231190634-3631-5-git-send-email-kevin@tyndur.org> + libc: POSIX: strtoul() und strtoull() --- src/include/stdlib.h | 3 + src/lib/stdlibc/strtoul.c | 4 ++ src/lib/string.c | 93 ++++++++++++++++++++++++++++++++++++--------- 3 files changed, 82 insertions(+), 18 deletions(-) diff --git a/src/include/stdlib.h b/src/include/stdlib.h index 0ecd514..1691441 100644 --- a/src/include/stdlib.h +++ b/src/include/stdlib.h @@ -53,6 +53,9 @@ void* realloc(void* address, size_t size); void* calloc(size_t size, size_t count); void init_memory_manager(void); +unsigned long int strtoul(const char *nptr, char **endptr, int base); +unsigned long long int strtoull(const char *nptr, char **endptr, int base); + long strtol(const char* str, char** endptr, int base); unsigned long strtoul(const char* str, char** endptr, int base); char* getenv(const char* name); diff --git a/src/lib/stdlibc/strtoul.c b/src/lib/stdlibc/strtoul.c index e3da745..17c82f1 100644 --- a/src/lib/stdlibc/strtoul.c +++ b/src/lib/stdlibc/strtoul.c @@ -27,6 +27,8 @@ * SUCH DAMAGE. */ +#if 0 + #include "limits.h" #include "ctype.h" #include "errno.h" @@ -110,3 +112,5 @@ noconv: *endptr = (char *)(any ? s - 1 : nptr); return (acc); } + +#endif diff --git a/src/lib/string.c b/src/lib/string.c index d8e41e6..2f8afdf 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -69,27 +69,84 @@ void itoa(unsigned int n, char *s, unsigned int base) } s[y] = '\0'; } -unsigned int atoi(const char *s) + +unsigned long long int strtoull(const char *nptr, char **endptr, int base) { - size_t digit = 0; - size_t highest = 0; - size_t i; - for (i=0;s[i] != '\0';i++) - { - if (s[i] < '0' || - s[i] > '9')break; - if (highest == 0)highest = 1; - else highest *= 10; - digit++; - } - unsigned int result = 0; - for (i=0;i < digit;i++) - { - result += (s[i] - '0') * highest; - highest /= 10; - } + unsigned long long int result = 0; + + // TODO Vorzeichen + + // Basis feststellen + // Bei Basis 16 darf der String mit 0x anfangen + // Bei Basis 0 ist automatische Erkennung + // Anfang ist 0x: Basis 16 + // Anfang ist 0: Basis 8 + // Ansonsten: Basis 10 + switch (base) { + case 0: + base = 10; + if (*nptr == '0') { + if (*++nptr == 'x') { + base = 16; + nptr++; + } else { + base = 8; + } + } + break; + + case 16: + if ((*nptr == '0') && (*(nptr+1) == 'x')) { + nptr += 2; + } + break; + } + + // Ergebnis berechnen + result = 0; + while (*nptr) { + switch (*nptr) { + case '0' ... '9': + if (*nptr - '0' > base - 1) { + goto out; + } + result = result * base + (*nptr - '0'); + break; + case 'A' ... 'Z': + if (*nptr - 'A' + 10 > base - 1) { + goto out; + } + result = result * base + (*nptr - 'A' + 10); + break; + case 'a' ... 'z': + if (*nptr - 'a' + 10 > base - 1) { + goto out; + } + result = result * base + (*nptr - 'a' + 10); + break; + } + nptr++; + } +out: + + if (endptr != NULL) { + *endptr = (char*) nptr; + } + return result; } + +unsigned long int strtoul(const char *nptr, char **endptr, int base) +{ + return (unsigned long int) strtoull(nptr, endptr, base); +} + + +unsigned int atoi(const char *s) +{ + // FIXME Eigentlich ist atoi ja signed... + return (unsigned int) strtoull(s, NULL, 10); +} // long atol(const char *str) -- 1.5.4.5 From kevin at tyndur.org Mon Jan 5 22:23:53 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 5 Jan 2009 22:23:53 +0100 Subject: [tyndur-devel] [PATCH 5/6] libc: POSIX: alarm() In-Reply-To: <1231190634-3631-1-git-send-email-kevin@tyndur.org> References: <1231190634-3631-1-git-send-email-kevin@tyndur.org> Message-ID: <1231190634-3631-6-git-send-email-kevin@tyndur.org> + lib: POSIX: Weniger gefakte Implementierung von alarm() --- src/modules/include/unistd.h | 6 +++--- src/modules/lib/posix/signal.c | 19 ++++++++++++++++--- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/modules/include/unistd.h b/src/modules/include/unistd.h index c7b7bbb..18ffd07 100644 --- a/src/modules/include/unistd.h +++ b/src/modules/include/unistd.h @@ -121,6 +121,9 @@ ssize_t pread(int fd, void *buf, size_t count, off_t offset); /// In eine Datei mit gegebenem Offset schreiben ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset); +/// Timer setzen nach dem ein SIGALARM gesendet werden soll +long alarm(long seconds); + #ifndef CONFIG_LIBC_NO_STUBS /// Prozess klonen pid_t fork(void); @@ -137,9 +140,6 @@ int dup(int fd); /// Dateideskriptor duplizieren int dup2(int fd, int new_fd); -/// Timer setzen nach dem ein SIGALARM gesendet werden soll -long alarm(long seconds); - /// Warten bis zeit abgelaufen ist, oder Signal eintrifft unsigned int sleep(unsigned int seconds); diff --git a/src/modules/lib/posix/signal.c b/src/modules/lib/posix/signal.c index ee37e27..63d54b3 100644 --- a/src/modules/lib/posix/signal.c +++ b/src/modules/lib/posix/signal.c @@ -259,14 +259,27 @@ int sigismember(const sigset_t *sigset, int signum) return ((sigset->bitmask[signum / 8] & (1 <<(signum % 8))) != 0); } +/** + * Callbackfunktion fuer alarm() + */ +static void do_alarm(void) +{ + raise(SIGALRM); +} -#ifndef CONFIG_LIBC_NO_STUBS /** * Timer setzen, der beim ablaufen ein SIGALARM sendet */ long alarm(long seconds) { + static dword id = 0; + + if (id != 0) { + timer_cancel(id); + } + + id = timer_register(do_alarm, seconds * 1000000); + + // FIXME return 0; } -#endif - -- 1.5.4.5 From kevin at tyndur.org Mon Jan 5 22:23:54 2009 From: kevin at tyndur.org (Kevin Wolf) Date: Mon, 5 Jan 2009 22:23:54 +0100 Subject: [tyndur-devel] [PATCH 6/6] libc: POSIX: Stub fuer gettimeofday() In-Reply-To: <1231190634-3631-1-git-send-email-kevin@tyndur.org> References: <1231190634-3631-1-git-send-email-kevin@tyndur.org> Message-ID: <1231190634-3631-7-git-send-email-kevin@tyndur.org> + libc: POSIX: Stub fuer gettimeofday() --- src/modules/include/sys/time.h | 10 ++++++++ src/modules/lib/posix/time.c | 48 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 0 deletions(-) create mode 100644 src/modules/lib/posix/time.c diff --git a/src/modules/include/sys/time.h b/src/modules/include/sys/time.h index f72098c..2a713b9 100644 --- a/src/modules/include/sys/time.h +++ b/src/modules/include/sys/time.h @@ -40,5 +40,15 @@ struct timeval { time_t tv_sec; suseconds_t tv_usec; }; + +struct timezone { + int tz_minuteswest; + int tz_dsttime; +}; + +#ifndef CONFIG_LIBC_NO_STUBS +int gettimeofday(struct timeval *tv, struct timezone *tz); +#endif + #endif //ifndef _SYS_TIME_H_ diff --git a/src/modules/lib/posix/time.c b/src/modules/lib/posix/time.c new file mode 100644 index 0000000..476aa8b --- /dev/null +++ b/src/modules/lib/posix/time.c @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +#ifndef CONFIG_LIBC_NO_STUBS + +int gettimeofday(struct timeval *tv, struct timezone *tz) +{ + tv->tv_sec = 0; + tv->tv_usec = 0; + + return 0; +} + +#endif -- 1.5.4.5 From toni at tyndur.org Mon Jan 5 22:40:33 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Mon, 5 Jan 2009 22:40:33 +0100 Subject: [tyndur-devel] [PATCH 1/6] libc: POSIX: pread() und pwrite() In-Reply-To: <1231190634-3631-2-git-send-email-kevin@tyndur.org> References: <1231190634-3631-1-git-send-email-kevin@tyndur.org> <1231190634-3631-2-git-send-email-kevin@tyndur.org> Message-ID: <20090105214033.GA8893@thales.produktiv.lan> On Mon, Jan 05 22:23, Kevin Wolf wrote: > + libc: POSIX: pread() und pwrite() > --- > src/modules/include/unistd.h | 6 +++++ > src/modules/lib/posix/posix_files.c | 41 +++++++++++++++++++++++++++++++++++ > 2 files changed, 47 insertions(+), 0 deletions(-) > > diff --git a/src/modules/include/unistd.h b/src/modules/include/unistd.h > index fa7dc2a..341b363 100644 > --- a/src/modules/include/unistd.h > +++ b/src/modules/include/unistd.h > @@ -115,6 +115,12 @@ char* mktemp(char* template); > /// Temporaere Datei anlegen > int mkstemp(char* template); > > +/// In eine Datei mit gegebenem Offset lesen > +ssize_t pread(int fd, void *buf, size_t count, off_t offset); > + > +/// In eine Datei mit gegebenem Offset schreiben > +ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset); > + > #ifndef CONFIG_LIBC_NO_STUBS > /// Prozess klonen > pid_t fork(void); > diff --git a/src/modules/lib/posix/posix_files.c b/src/modules/lib/posix/posix_files.c > index bfa3601..659de16 100644 > --- a/src/modules/lib/posix/posix_files.c > +++ b/src/modules/lib/posix/posix_files.c > @@ -346,6 +346,47 @@ int close(int fd) > return 0; > } > > +/// In eine Datei mit gegebenem Offset lesen > +ssize_t pread(int fd, void *buf, size_t count, off_t offset) > +{ > + FILE* file = fd_to_file(fd); > + off_t old_pos; > + ssize_t ret; > + > + // Bei einem ungueltigen Deskriptor wird abgebrochen > + if (file == NULL) { > + errno = EBADF; > + return -1; > + } > + > + old_pos = ftell(file); > + fseek(file, offset, SEEK_SET); Politisch korrekt müsste wohl hier der Rückgabewert geprüft werden... > + ret = read(fd, buf, count); Nimm hier besser fread, dann sparen wir einmal Deskriptor raussuchen. > + fseek(file, old_pos, SEEK_SET); > + > + return ret; > +} > + > +/// In eine Datei mit gegebenem Offset schreiben > +ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset) > +{ > + FILE* file = fd_to_file(fd); > + off_t old_pos; > + ssize_t ret; > + > + // Bei einem ungueltigen Deskriptor wird abgebrochen > + if (file == NULL) { > + errno = EBADF; > + return -1; > + } > + > + old_pos = ftell(file); > + fseek(file, offset, SEEK_SET); > + ret = write(fd, buf, count); Hier gilt das Selbe. > + fseek(file, old_pos, SEEK_SET); > + > + return ret; > +} > > #ifndef CONFIG_LIBC_NO_STUBS > /** > -- > 1.5.4.5 > > _______________________________________________ > tyndur-devel mailing list > tyndur-devel at tyndur.org > http://list.tyndur.org/mailman/listinfo/tyndur-devel > -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Mon Jan 5 22:54:21 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Mon, 5 Jan 2009 22:54:21 +0100 Subject: [tyndur-devel] [PATCH 2/6] libc: POSIX: getuid/getgid In-Reply-To: <1231190634-3631-3-git-send-email-kevin@tyndur.org> References: <1231190634-3631-1-git-send-email-kevin@tyndur.org> <1231190634-3631-3-git-send-email-kevin@tyndur.org> Message-ID: <20090105215421.GB8893@thales.produktiv.lan> On Mon, Jan 05 22:23, Kevin Wolf wrote: > + libc: POSIX: Stubs fuer getuid(), geteuid(), getgid(), getegid() > --- > src/modules/include/unistd.h | 13 +++++++++ > src/modules/lib/posix/user.c | 60 ++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 73 insertions(+), 0 deletions(-) > create mode 100644 src/modules/lib/posix/user.c > > diff --git a/src/modules/include/unistd.h b/src/modules/include/unistd.h > index 341b363..c7b7bbb 100644 > --- a/src/modules/include/unistd.h > +++ b/src/modules/include/unistd.h > @@ -145,6 +145,19 @@ unsigned int sleep(unsigned int seconds); > > /// Datei umbenennen oder verschieben > int rename(const char* path_old, const char* path_new); > + > +/// Gibt die aktuelle Benutzer-ID zurueck > +uid_t getuid(void); > + > +/// Gibt die effektive Benutzer-ID zurueck > +uid_t geteuid(void); > + > +/// Gibt die aktuelle Gruppen-ID zurueck > +gid_t getgid(void); > +// > +/// Gibt die effektive Gruppen-ID zurueck > +gid_t getegid(void); > + Wenn du da hier ins ifdef reinpackst... > #endif > > #endif > diff --git a/src/modules/lib/posix/user.c b/src/modules/lib/posix/user.c > new file mode 100644 > index 0000000..4499b9c > --- /dev/null > +++ b/src/modules/lib/posix/user.c > @@ -0,0 +1,60 @@ > +/* > + * Copyright (c) 2009 The tyndur Project. All rights reserved. > + * > + * This code is derived from software contributed to the tyndur Project > + * by Kevin Wolf. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * 2. Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in the > + * documentation and/or other materials provided with the distribution. > + * 3. All advertising materials mentioning features or use of this software > + * must display the following acknowledgement: > + * This product includes software developed by the tyndur Project > + * and its contributors. > + * 4. Neither the name of the tyndur Project nor the names of its > + * contributors may be used to endorse or promote products derived > + * from this software without specific prior written permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED > + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR > + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR > + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, > + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, > + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; > + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, > + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR > + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF > + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > + ... würde ich hier auch eins erwarten. ;-) ? > +/// Gibt die aktuelle Benutzer-ID zurueck > +uid_t getuid(void) > +{ > + return 0; > +} > + > +/// Gibt die effektive Benutzer-ID zurueck > +uid_t geteuid(void) > +{ > + return 0; > +} > + > +/// Gibt die aktuelle Gruppen-ID zurueck > +gid_t getgid(void) > +{ > + return 0; > +} > + > +/// Gibt die effektive Gruppen-ID zurueck > +gid_t getegid(void) > +{ > + return 0; > +} > -- > 1.5.4.5 > > _______________________________________________ > tyndur-devel mailing list > tyndur-devel at tyndur.org > http://list.tyndur.org/mailman/listinfo/tyndur-devel > -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From dunklermeuchler at gmail.com Tue Jan 6 01:42:25 2009 From: dunklermeuchler at gmail.com (Alexander Siol) Date: Tue, 6 Jan 2009 01:42:25 +0100 Subject: [tyndur-devel] [PATCH 3/6] libc: POSIX: Endianess-Umwandlung In-Reply-To: <1231190634-3631-4-git-send-email-kevin@tyndur.org> References: <1231190634-3631-1-git-send-email-kevin@tyndur.org> <1231190634-3631-4-git-send-email-kevin@tyndur.org> Message-ID: <200901060142.33821.dunklermeuchler@gmail.com> Am Montag 05 Januar 2009 22:23:51 schrieb Kevin Wolf: > + libc: POSIX: htonl(), htons(), ntohl(), ntohs() > --- > src/modules/include/netinet/in.h | 45 ++++++++++++++++++++++++++++++ > src/modules/lib/posix/net.c | 57 > ++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), > 0 deletions(-) > create mode 100644 src/modules/include/netinet/in.h > create mode 100644 src/modules/lib/posix/net.c > > diff --git a/src/modules/include/netinet/in.h > b/src/modules/include/netinet/in.h new file mode 100644 > index 0000000..effc214 > --- /dev/null > +++ b/src/modules/include/netinet/in.h > @@ -0,0 +1,45 @@ > +/* > + * Copyright (c) 2009 The tyndur Project. All rights reserved. > + * > + * This code is derived from software contributed to the tyndur Project > + * by Kevin Wolf. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * 2. Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in the > + * documentation and/or other materials provided with the distribution. > + * 3. All advertising materials mentioning features or use of this > software + * must display the following acknowledgement: > + * This product includes software developed by the tyndur Project > + * and its contributors. > + * 4. Neither the name of the tyndur Project nor the names of its > + * contributors may be used to endorse or promote products derived > + * from this software without specific prior written permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT > LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A > PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT > HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, > SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT > LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, > DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY > THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT > (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#ifndef _NETINET_IN_H_ > +#define _NETINET_IN_H_ > + > +unsigned long int htonl(unsigned long int hostlong); > +unsigned short int htons(unsigned short int hostshort); > +unsigned long int ntohl(unsigned long int netlong); > +unsigned short int ntohs(unsigned short int netshort); > + > +#endif > + > diff --git a/src/modules/lib/posix/net.c b/src/modules/lib/posix/net.c > new file mode 100644 > index 0000000..c03bfd0 > --- /dev/null > +++ b/src/modules/lib/posix/net.c > @@ -0,0 +1,57 @@ > +/* > + * Copyright (c) 2009 The tyndur Project. All rights reserved. > + * > + * This code is derived from software contributed to the tyndur Project > + * by Kevin Wolf. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * 2. Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in the > + * documentation and/or other materials provided with the distribution. > + * 3. All advertising materials mentioning features or use of this > software + * must display the following acknowledgement: > + * This product includes software developed by the tyndur Project > + * and its contributors. > + * 4. Neither the name of the tyndur Project nor the names of its > + * contributors may be used to endorse or promote products derived > + * from this software without specific prior written permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT > LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A > PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT > HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, > SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT > LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, > DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY > THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT > (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > +#include > + > +unsigned long int htonl(unsigned long int hostlong) > +{ > + return big_endian_dword(hostlong); > +} > + > +unsigned short int htons(unsigned short int hostshort) > +{ > + return big_endian_word(hostshort); > +} > + > +unsigned long int ntohl(unsigned long int netlong) > +{ > + return big_endian_dword(netlong); > +} > + > +unsigned short int ntohs(unsigned short int netshort) > +{ > + return big_endian_dword(netshort); > +} Rein damit. Wobei das Makro eher switch_endian_* heißen sollte ;) -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 189 bytes Beschreibung: This is a digitally signed message part. URL : From dunklermeuchler at gmail.com Tue Jan 6 02:00:40 2009 From: dunklermeuchler at gmail.com (Alexander Siol) Date: Tue, 6 Jan 2009 02:00:40 +0100 Subject: [tyndur-devel] [PATCH 4/6] libc: POSIX: strtoul() und strtoull() In-Reply-To: <1231190634-3631-5-git-send-email-kevin@tyndur.org> References: <1231190634-3631-1-git-send-email-kevin@tyndur.org> <1231190634-3631-5-git-send-email-kevin@tyndur.org> Message-ID: <200901060200.52401.dunklermeuchler@gmail.com> Am Montag 05 Januar 2009 22:23:52 schrieb Kevin Wolf: > + libc: POSIX: strtoul() und strtoull() > --- > src/include/stdlib.h | 3 + > src/lib/stdlibc/strtoul.c | 4 ++ > src/lib/string.c | 93 > ++++++++++++++++++++++++++++++++++++--------- 3 files changed, 82 > insertions(+), 18 deletions(-) > > diff --git a/src/include/stdlib.h b/src/include/stdlib.h > index 0ecd514..1691441 100644 > --- a/src/include/stdlib.h > +++ b/src/include/stdlib.h > @@ -53,6 +53,9 @@ void* realloc(void* address, size_t size); > void* calloc(size_t size, size_t count); > void init_memory_manager(void); > > +unsigned long int strtoul(const char *nptr, char **endptr, int base); > +unsigned long long int strtoull(const char *nptr, char **endptr, int > base); + > long strtol(const char* str, char** endptr, int base); > unsigned long strtoul(const char* str, char** endptr, int base); strtoul muss keinen neuen Funktionsprototypen bekommen, hat schon einen ;) > char* getenv(const char* name); > diff --git a/src/lib/stdlibc/strtoul.c b/src/lib/stdlibc/strtoul.c > index e3da745..17c82f1 100644 > --- a/src/lib/stdlibc/strtoul.c > +++ b/src/lib/stdlibc/strtoul.c > @@ -27,6 +27,8 @@ > * SUCH DAMAGE. > */ > > +#if 0 > + Sinn? > #include "limits.h" > #include "ctype.h" > #include "errno.h" > @@ -110,3 +112,5 @@ noconv: > *endptr = (char *)(any ? s - 1 : nptr); > return (acc); > } > + > +#endif > diff --git a/src/lib/string.c b/src/lib/string.c > index d8e41e6..2f8afdf 100644 > --- a/src/lib/string.c > +++ b/src/lib/string.c > @@ -69,27 +69,84 @@ void itoa(unsigned int n, char *s, unsigned int base) > } > s[y] = '\0'; > } > -unsigned int atoi(const char *s) > + > +unsigned long long int strtoull(const char *nptr, char **endptr, int base) > { > - size_t digit = 0; > - size_t highest = 0; > - size_t i; > - for (i=0;s[i] != '\0';i++) > - { > - if (s[i] < '0' || > - s[i] > '9')break; > - if (highest == 0)highest = 1; > - else highest *= 10; > - digit++; > - } > - unsigned int result = 0; > - for (i=0;i < digit;i++) > - { > - result += (s[i] - '0') * highest; > - highest /= 10; > - } > + unsigned long long int result = 0; > + > + // TODO Vorzeichen > + > + // Basis feststellen > + // Bei Basis 16 darf der String mit 0x anfangen > + // Bei Basis 0 ist automatische Erkennung > + // Anfang ist 0x: Basis 16 > + // Anfang ist 0: Basis 8 > + // Ansonsten: Basis 10 > + switch (base) { > + case 0: > + base = 10; > + if (*nptr == '0') { > + if (*++nptr == 'x') { > + base = 16; > + nptr++; > + } else { > + base = 8; > + } > + } > + break; > + > + case 16: > + if ((*nptr == '0') && (*(nptr+1) == 'x')) { > + nptr += 2; > + } > + break; > + } > + > + // Ergebnis berechnen > + result = 0; > + while (*nptr) { > + switch (*nptr) { > + case '0' ... '9': > + if (*nptr - '0' > base - 1) { > + goto out; > + } > + result = result * base + (*nptr - '0'); > + break; > + case 'A' ... 'Z': > + if (*nptr - 'A' + 10 > base - 1) { > + goto out; > + } > + result = result * base + (*nptr - 'A' + 10); > + break; > + case 'a' ... 'z': > + if (*nptr - 'a' + 10 > base - 1) { > + goto out; > + } > + result = result * base + (*nptr - 'a' + 10); > + break; > + } > + nptr++; > + } > +out: > + > + if (endptr != NULL) { > + *endptr = (char*) nptr; > + } > + > return result; > } > + > +unsigned long int strtoul(const char *nptr, char **endptr, int base) > +{ > + return (unsigned long int) strtoull(nptr, endptr, base); > +} > + > + > +unsigned int atoi(const char *s) > +{ > + // FIXME Eigentlich ist atoi ja signed... > + return (unsigned int) strtoull(s, NULL, 10); > +} > // Sollte man da nicht lieber den korrekten Rückgabetyp behalten und lieber nen paar komische Werte liefern, bevor anderer Code nicht läuft? > > long atol(const char *str) Ansonsten siehts gut aus. -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 189 bytes Beschreibung: This is a digitally signed message part. URL : From dunklermeuchler at gmail.com Tue Jan 6 02:10:25 2009 From: dunklermeuchler at gmail.com (Alexander Siol) Date: Tue, 6 Jan 2009 02:10:25 +0100 Subject: [tyndur-devel] [PATCH 5/6] libc: POSIX: alarm() In-Reply-To: <1231190634-3631-6-git-send-email-kevin@tyndur.org> References: <1231190634-3631-1-git-send-email-kevin@tyndur.org> <1231190634-3631-6-git-send-email-kevin@tyndur.org> Message-ID: <200901060210.25365.dunklermeuchler@gmail.com> Am Montag 05 Januar 2009 22:23:53 schrieb Kevin Wolf: > + lib: POSIX: Weniger gefakte Implementierung von alarm() > --- > src/modules/include/unistd.h | 6 +++--- > src/modules/lib/posix/signal.c | 19 ++++++++++++++++--- > 2 files changed, 19 insertions(+), 6 deletions(-) > > diff --git a/src/modules/include/unistd.h b/src/modules/include/unistd.h > index c7b7bbb..18ffd07 100644 > --- a/src/modules/include/unistd.h > +++ b/src/modules/include/unistd.h > @@ -121,6 +121,9 @@ ssize_t pread(int fd, void *buf, size_t count, off_t > offset); /// In eine Datei mit gegebenem Offset schreiben > ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset); > > +/// Timer setzen nach dem ein SIGALARM gesendet werden soll > +long alarm(long seconds); > + > #ifndef CONFIG_LIBC_NO_STUBS > /// Prozess klonen > pid_t fork(void); > @@ -137,9 +140,6 @@ int dup(int fd); > /// Dateideskriptor duplizieren > int dup2(int fd, int new_fd); > > -/// Timer setzen nach dem ein SIGALARM gesendet werden soll > -long alarm(long seconds); > - > /// Warten bis zeit abgelaufen ist, oder Signal eintrifft > unsigned int sleep(unsigned int seconds); > > diff --git a/src/modules/lib/posix/signal.c > b/src/modules/lib/posix/signal.c index ee37e27..63d54b3 100644 > --- a/src/modules/lib/posix/signal.c > +++ b/src/modules/lib/posix/signal.c > @@ -259,14 +259,27 @@ int sigismember(const sigset_t *sigset, int signum) > return ((sigset->bitmask[signum / 8] & (1 <<(signum % 8))) != 0); > } > > +/** > + * Callbackfunktion fuer alarm() > + */ > +static void do_alarm(void) > +{ > + raise(SIGALRM); > +} > > -#ifndef CONFIG_LIBC_NO_STUBS > /** > * Timer setzen, der beim ablaufen ein SIGALARM sendet > */ > long alarm(long seconds) > { > + static dword id = 0; > + > + if (id != 0) { > + timer_cancel(id); > + } > + > + id = timer_register(do_alarm, seconds * 1000000); > + > + // FIXME > return 0; > } > -#endif > - Sieht gut aus, rein damit. -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 189 bytes Beschreibung: This is a digitally signed message part. URL : From dunklermeuchler at gmail.com Tue Jan 6 02:17:38 2009 From: dunklermeuchler at gmail.com (Alexander Siol) Date: Tue, 6 Jan 2009 02:17:38 +0100 Subject: [tyndur-devel] [PATCH 6/6] libc: POSIX: Stub fuer gettimeofday() In-Reply-To: <1231190634-3631-7-git-send-email-kevin@tyndur.org> References: <1231190634-3631-1-git-send-email-kevin@tyndur.org> <1231190634-3631-7-git-send-email-kevin@tyndur.org> Message-ID: <200901060217.39146.dunklermeuchler@gmail.com> Am Montag 05 Januar 2009 22:23:54 schrieb Kevin Wolf: > + libc: POSIX: Stub fuer gettimeofday() > --- > src/modules/include/sys/time.h | 10 ++++++++ > src/modules/lib/posix/time.c | 48 > ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), > 0 deletions(-) > create mode 100644 src/modules/lib/posix/time.c > > diff --git a/src/modules/include/sys/time.h > b/src/modules/include/sys/time.h index f72098c..2a713b9 100644 > --- a/src/modules/include/sys/time.h > +++ b/src/modules/include/sys/time.h > @@ -40,5 +40,15 @@ struct timeval { > time_t tv_sec; > suseconds_t tv_usec; > }; > + > +struct timezone { > + int tz_minuteswest; > + int tz_dsttime; > +}; > + > +#ifndef CONFIG_LIBC_NO_STUBS > +int gettimeofday(struct timeval *tv, struct timezone *tz); > +#endif > + > #endif //ifndef _SYS_TIME_H_ > > diff --git a/src/modules/lib/posix/time.c b/src/modules/lib/posix/time.c > new file mode 100644 > index 0000000..476aa8b > --- /dev/null > +++ b/src/modules/lib/posix/time.c > @@ -0,0 +1,48 @@ > +/* > + * Copyright (c) 2009 The tyndur Project. All rights reserved. > + * > + * This code is derived from software contributed to the tyndur Project > + * by Kevin Wolf. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * 2. Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in the > + * documentation and/or other materials provided with the distribution. > + * 3. All advertising materials mentioning features or use of this > software + * must display the following acknowledgement: > + * This product includes software developed by the tyndur Project > + * and its contributors. > + * 4. Neither the name of the tyndur Project nor the names of its > + * contributors may be used to endorse or promote products derived > + * from this software without specific prior written permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT > LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A > PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT > HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, > SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT > LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, > DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY > THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT > (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE > OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > + > +#ifndef CONFIG_LIBC_NO_STUBS > + > +int gettimeofday(struct timeval *tv, struct timezone *tz) > +{ > + tv->tv_sec = 0; > + tv->tv_usec = 0; > + > + return 0; > +} > + > +#endif Als Stub natürlich absolut okay. Aber muss die Definition mit zweitem Parameter als timezone sein? Lt. manpage undefiniert, lt. glibc obsolet :/ Aber prinzipiell rein damit. -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 189 bytes Beschreibung: This is a digitally signed message part. URL : From toni at tyndur.org Tue Jan 6 12:20:17 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Tue, 6 Jan 2009 12:20:17 +0100 Subject: [tyndur-devel] [PATCH 6/6] libc: POSIX: Stub fuer gettimeofday() In-Reply-To: <1231190634-3631-7-git-send-email-kevin@tyndur.org> References: <1231190634-3631-1-git-send-email-kevin@tyndur.org> <1231190634-3631-7-git-send-email-kevin@tyndur.org> Message-ID: <20090106112017.GA16222@thales.produktiv.lan> On Mon, Jan 05 22:23, Kevin Wolf wrote: > + libc: POSIX: Stub fuer gettimeofday() Sieht gut aus. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Tue Jan 6 12:23:11 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Tue, 6 Jan 2009 12:23:11 +0100 Subject: [tyndur-devel] [PATCH 5/6] libc: POSIX: alarm() In-Reply-To: <1231190634-3631-6-git-send-email-kevin@tyndur.org> References: <1231190634-3631-1-git-send-email-kevin@tyndur.org> <1231190634-3631-6-git-send-email-kevin@tyndur.org> Message-ID: <20090106112311.GA16295@thales.produktiv.lan> On Mon, Jan 05 22:23, Kevin Wolf wrote: > + lib: POSIX: Weniger gefakte Implementierung von alarm() Rein damit. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Tue Jan 6 12:42:46 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Tue, 6 Jan 2009 12:42:46 +0100 Subject: [tyndur-devel] [PATCH 3/6] libc: POSIX: Endianess-Umwandlung In-Reply-To: <1231190634-3631-4-git-send-email-kevin@tyndur.org> References: <1231190634-3631-1-git-send-email-kevin@tyndur.org> <1231190634-3631-4-git-send-email-kevin@tyndur.org> Message-ID: <20090106114246.GA16361@thales.produktiv.lan> On Mon, Jan 05 22:23, Kevin Wolf wrote: > + libc: POSIX: htonl(), htons(), ntohl(), ntohs() > --- > src/modules/include/netinet/in.h | 45 ++++++++++++++++++++++++++++++ > src/modules/lib/posix/net.c | 57 ++++++++++++++++++++++++++++++++++++++ > 2 files changed, 102 insertions(+), 0 deletions(-) > create mode 100644 src/modules/include/netinet/in.h > create mode 100644 src/modules/lib/posix/net.c > > diff --git a/src/modules/include/netinet/in.h b/src/modules/include/netinet/in.h > new file mode 100644 > index 0000000..effc214 > --- /dev/null > +++ b/src/modules/include/netinet/in.h > @@ -0,0 +1,45 @@ > +/* > + * Copyright (c) 2009 The tyndur Project. All rights reserved. > + * > + * This code is derived from software contributed to the tyndur Project > + * by Kevin Wolf. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * 2. Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in the > + * documentation and/or other materials provided with the distribution. > + * 3. All advertising materials mentioning features or use of this software > + * must display the following acknowledgement: > + * This product includes software developed by the tyndur Project > + * and its contributors. > + * 4. Neither the name of the tyndur Project nor the names of its > + * contributors may be used to endorse or promote products derived > + * from this software without specific prior written permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED > + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR > + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR > + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, > + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, > + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; > + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, > + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR > + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF > + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#ifndef _NETINET_IN_H_ > +#define _NETINET_IN_H_ > + > +unsigned long int htonl(unsigned long int hostlong); > +unsigned short int htons(unsigned short int hostshort); > +unsigned long int ntohl(unsigned long int netlong); > +unsigned short int ntohs(unsigned short int netshort); > + > +#endif > + > diff --git a/src/modules/lib/posix/net.c b/src/modules/lib/posix/net.c > new file mode 100644 > index 0000000..c03bfd0 > --- /dev/null > +++ b/src/modules/lib/posix/net.c > @@ -0,0 +1,57 @@ > +/* > + * Copyright (c) 2009 The tyndur Project. All rights reserved. > + * > + * This code is derived from software contributed to the tyndur Project > + * by Kevin Wolf. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * 2. Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in the > + * documentation and/or other materials provided with the distribution. > + * 3. All advertising materials mentioning features or use of this software > + * must display the following acknowledgement: > + * This product includes software developed by the tyndur Project > + * and its contributors. > + * 4. Neither the name of the tyndur Project nor the names of its > + * contributors may be used to endorse or promote products derived > + * from this software without specific prior written permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED > + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR > + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR > + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, > + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, > + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; > + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, > + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR > + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF > + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > +#include > + > +unsigned long int htonl(unsigned long int hostlong) > +{ > + return big_endian_dword(hostlong); > +} > + > +unsigned short int htons(unsigned short int hostshort) > +{ > + return big_endian_word(hostshort); > +} > + > +unsigned long int ntohl(unsigned long int netlong) > +{ > + return big_endian_dword(netlong); > +} > + > +unsigned short int ntohs(unsigned short int netshort) > +{ > + return big_endian_dword(netshort); > +} Hm, könntest du das nicht auch als Makro oder wenigstens static Inline implementieren? Oder schreibt POSIX da irgenwas vor? -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sat Jan 10 21:04:58 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 10 Jan 2009 21:04:58 +0100 Subject: [tyndur-devel] [PATCH 4/6] libc: POSIX: strtoul() und strtoull() In-Reply-To: <1231190634-3631-5-git-send-email-kevin@tyndur.org> References: <1231190634-3631-1-git-send-email-kevin@tyndur.org> <1231190634-3631-5-git-send-email-kevin@tyndur.org> Message-ID: <20090110200458.GA30003@thales.produktiv.lan> On Mon, Jan 05 22:23, Kevin Wolf wrote: > + libc: POSIX: strtoul() und strtoull() > --- > src/include/stdlib.h | 3 + > src/lib/stdlibc/strtoul.c | 4 ++ > src/lib/string.c | 93 ++++++++++++++++++++++++++++++++++++--------- > 3 files changed, 82 insertions(+), 18 deletions(-) > > diff --git a/src/include/stdlib.h b/src/include/stdlib.h > index 0ecd514..1691441 100644 > --- a/src/include/stdlib.h > +++ b/src/include/stdlib.h > @@ -53,6 +53,9 @@ void* realloc(void* address, size_t size); > void* calloc(size_t size, size_t count); > void init_memory_manager(void); > > +unsigned long int strtoul(const char *nptr, char **endptr, int base); > +unsigned long long int strtoull(const char *nptr, char **endptr, int base); > + > long strtol(const char* str, char** endptr, int base); > unsigned long strtoul(const char* str, char** endptr, int base); > char* getenv(const char* name); > diff --git a/src/lib/stdlibc/strtoul.c b/src/lib/stdlibc/strtoul.c > index e3da745..17c82f1 100644 > --- a/src/lib/stdlibc/strtoul.c > +++ b/src/lib/stdlibc/strtoul.c > @@ -27,6 +27,8 @@ > * SUCH DAMAGE. > */ > > +#if 0 > + > #include "limits.h" > #include "ctype.h" > #include "errno.h" > @@ -110,3 +112,5 @@ noconv: > *endptr = (char *)(any ? s - 1 : nptr); > return (acc); > } > + > +#endif Warum nicht einfach die Datei löschen? > diff --git a/src/lib/string.c b/src/lib/string.c > index d8e41e6..2f8afdf 100644 > --- a/src/lib/string.c > +++ b/src/lib/string.c > @@ -69,27 +69,84 @@ void itoa(unsigned int n, char *s, unsigned int base) > } > s[y] = '\0'; > } > -unsigned int atoi(const char *s) > + > +unsigned long long int strtoull(const char *nptr, char **endptr, int base) > { > - size_t digit = 0; > - size_t highest = 0; > - size_t i; > - for (i=0;s[i] != '\0';i++) > - { > - if (s[i] < '0' || > - s[i] > '9')break; > - if (highest == 0)highest = 1; > - else highest *= 10; > - digit++; > - } > - unsigned int result = 0; > - for (i=0;i < digit;i++) > - { > - result += (s[i] - '0') * highest; > - highest /= 10; > - } > + unsigned long long int result = 0; > + > + // TODO Vorzeichen > + > + // Basis feststellen > + // Bei Basis 16 darf der String mit 0x anfangen > + // Bei Basis 0 ist automatische Erkennung > + // Anfang ist 0x: Basis 16 > + // Anfang ist 0: Basis 8 > + // Ansonsten: Basis 10 > + switch (base) { > + case 0: > + base = 10; > + if (*nptr == '0') { > + if (*++nptr == 'x') { > + base = 16; > + nptr++; > + } else { > + base = 8; > + } > + } > + break; > + > + case 16: > + if ((*nptr == '0') && (*(nptr+1) == 'x')) { > + nptr += 2; > + } > + break; > + } > + > + // Ergebnis berechnen > + result = 0; > + while (*nptr) { > + switch (*nptr) { > + case '0' ... '9': > + if (*nptr - '0' > base - 1) { > + goto out; > + } > + result = result * base + (*nptr - '0'); > + break; > + case 'A' ... 'Z': > + if (*nptr - 'A' + 10 > base - 1) { > + goto out; > + } > + result = result * base + (*nptr - 'A' + 10); > + break; > + case 'a' ... 'z': > + if (*nptr - 'a' + 10 > base - 1) { > + goto out; > + } > + result = result * base + (*nptr - 'a' + 10); > + break; > + } > + nptr++; > + } > +out: > + > + if (endptr != NULL) { > + *endptr = (char*) nptr; > + } > + > return result; > } > + > +unsigned long int strtoul(const char *nptr, char **endptr, int base) > +{ > + return (unsigned long int) strtoull(nptr, endptr, base); > +} > + > + > +unsigned int atoi(const char *s) > +{ > + // FIXME Eigentlich ist atoi ja signed... > + return (unsigned int) strtoull(s, NULL, 10); > +} > // > > long atol(const char *str) Der Rest sieht gut aus. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sun Jan 18 16:43:40 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 18 Jan 2009 16:43:40 +0100 Subject: [tyndur-devel] [Lost] [PATCH v2 01/10] kernel2: Task Gate fuer Double Faults In-Reply-To: <1229813356-4252-2-git-send-email-kevin@tyndur.org> References: <1229813356-4252-1-git-send-email-kevin@tyndur.org> <1229813356-4252-2-git-send-email-kevin@tyndur.org> Message-ID: <20090118154340.GA10425@einstein.produktiv.lan> On Sat, Dec 20 23:49, Kevin Wolf wrote: > * kernel2: Double Faults werden mit einem Task Gate abgefangen, falls > der Kernelstack kaputt gegangen sein sollte. Ack. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sun Jan 18 17:01:53 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 18 Jan 2009 17:01:53 +0100 Subject: [tyndur-devel] [Lost] [PATCH v2 03/10] kernel2: print_tasks_backtrace() In-Reply-To: <1229813356-4252-4-git-send-email-kevin@tyndur.org> References: <1229813356-4252-1-git-send-email-kevin@tyndur.org> <1229813356-4252-4-git-send-email-kevin@tyndur.org> Message-ID: <20090118160152.GB10425@einstein.produktiv.lan> On Sat, Dec 20 23:49, Kevin Wolf wrote: > + kernel2 (i386): print_tasks_backtrace() fuer Debugging per gdb Sieht gut aus. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sun Jan 18 17:02:40 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 18 Jan 2009 17:02:40 +0100 Subject: [tyndur-devel] [Lost] [PATCH v2 04/10] kernel2: Fix in Fehlerbehandlung fuer RPC In-Reply-To: <1229813356-4252-5-git-send-email-kevin@tyndur.org> References: <1229813356-4252-1-git-send-email-kevin@tyndur.org> <1229813356-4252-5-git-send-email-kevin@tyndur.org> Message-ID: <20090118160240.GC10425@einstein.produktiv.lan> On Sat, Dec 20 23:49, Kevin Wolf wrote: > ! kernel2: RPC: Ungueltige Ziel-PID abfangen Sieht gut aus. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sun Jan 18 17:05:04 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 18 Jan 2009 17:05:04 +0100 Subject: [tyndur-devel] [Lost] [PATCH v2 05/10] kernel2: Syscall pm_get_parent_pid In-Reply-To: <1229813356-4252-6-git-send-email-kevin@tyndur.org> References: <1229813356-4252-1-git-send-email-kevin@tyndur.org> <1229813356-4252-6-git-send-email-kevin@tyndur.org> Message-ID: <20090118160504.GD10425@einstein.produktiv.lan> On Sat, Dec 20 23:49, Kevin Wolf wrote: > + kernel2: Fake-Implementierung von syscall_pm_get_parent_pid durch eine richtige ersetzt Ack. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sun Jan 18 17:14:01 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 18 Jan 2009 17:14:01 +0100 Subject: [tyndur-devel] [Lost] [PATCH v2 06/10] kernel2: Syscall add_timer In-Reply-To: <1229813356-4252-7-git-send-email-kevin@tyndur.org> References: <1229813356-4252-1-git-send-email-kevin@tyndur.org> <1229813356-4252-7-git-send-email-kevin@tyndur.org> Message-ID: <20090118161401.GE10425@einstein.produktiv.lan> On Sat, Dec 20 23:49, Kevin Wolf wrote: > + kernel2: Timer-Funkionen von kernel uebernommen > + kernel2: Syscall add_timer > --- > src/kernel2/include/syscall.h | 2 + > src/kernel2/include/timer.h | 47 ++++++++++++ > src/kernel2/src/interrupts/im.c | 4 + > src/kernel2/src/syscall.c | 2 + > src/kernel2/src/syscalls/misc.c | 9 +++ > src/kernel2/src/tasks/pm.c | 4 + > src/kernel2/src/timer.c | 150 +++++++++++++++++++++++++++++++++++++++ > 7 files changed, 218 insertions(+), 0 deletions(-) > create mode 100644 src/kernel2/include/timer.h > create mode 100644 src/kernel2/src/timer.c > > diff --git a/src/kernel2/include/syscall.h b/src/kernel2/include/syscall.h > index b65e57e..b30b389 100644 > --- a/src/kernel2/include/syscall.h > +++ b/src/kernel2/include/syscall.h > @@ -130,6 +130,8 @@ void* syscall_shm_attach(uint32_t id); > /// Shared Memory schliessen > void syscall_shm_detach(uint32_t id); > > +/// Einen Timer anlegen > +void syscall_add_timer(uint32_t timer_id, uint32_t usec); > > // RPC > /// RPC-Handler registrieren > diff --git a/src/kernel2/include/timer.h b/src/kernel2/include/timer.h > new file mode 100644 > index 0000000..856b37d > --- /dev/null > +++ b/src/kernel2/include/timer.h > @@ -0,0 +1,47 @@ > +/* > + * Copyright (c) 2006-2007 The LOST Project. All rights reserved. Ist mittlerweile nicht schon fast 2009? ;-) > + * > + * This code is derived from software contributed to the LOST Project > + * by Kevin Wolf. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * 2. Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in the > + * documentation and/or other materials provided with the distribution. > + * 3. All advertising materials mentioning features or use of this software > + * must display the following acknowledgement: > + * This product includes software developed by the LOST Project > + * and its contributors. > + * 4. Neither the name of the LOST Project nor the names of its > + * contributors may be used to endorse or promote products derived > + * from this software without specific prior written permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED > + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR > + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR > + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, > + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, > + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; > + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, > + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR > + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF > + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#ifndef _TIMER_H_ > +#define _TIMER_H_ > + > +#include > +#include "tasks.h" > + > +void timer_init(void); > +void timer_register(pm_process_t* task, uint32_t timer_id, uint32_t usec); > +void timer_notify(uint64_t microtime); > +void timer_cancel_all(pm_process_t* task); > + > +#endif > diff --git a/src/kernel2/src/interrupts/im.c b/src/kernel2/src/interrupts/im.c > index 560f5fe..1838b4d 100644 > --- a/src/kernel2/src/interrupts/im.c > +++ b/src/kernel2/src/interrupts/im.c > @@ -44,6 +44,7 @@ > #include "apic.h" > #include "kernel.h" > #include "syscall.h" > +#include "timer.h" > > extern size_t cpu_count; > > @@ -140,6 +141,9 @@ interrupt_stack_frame_t* im_handler(interrupt_stack_frame_t* isf) > > // Einen neuen Thread holen. > cpu_get_current()->thread = pm_scheduler_pop(); > + > + // Timer ausloesen, wenn noetig > + timer_notify(timer_ticks); > } else { > intr_to_send[int_num]++; > im_disable_irq(int_num - IM_IRQ_BASE); > diff --git a/src/kernel2/src/syscall.c b/src/kernel2/src/syscall.c > index f15021b..836d1e7 100644 > --- a/src/kernel2/src/syscall.c > +++ b/src/kernel2/src/syscall.c > @@ -74,6 +74,8 @@ void syscall_init() > syscall_register(SYSCALL_FASTRPC_RET, &syscall_fastrpc_ret, 0); > #endif > > + syscall_register(SYSCALL_ADD_TIMER, &syscall_add_timer, 2); > + > syscall_register(SYSCALL_PM_REQUEST_PORT, syscall_io_request_port, 2); > syscall_register(SYSCALL_ADD_INTERRUPT_HANDLER, > syscall_add_interrupt_handler, 1); > diff --git a/src/kernel2/src/syscalls/misc.c b/src/kernel2/src/syscalls/misc.c > index beed606..5095c9b 100644 > --- a/src/kernel2/src/syscalls/misc.c > +++ b/src/kernel2/src/syscalls/misc.c > @@ -39,6 +39,7 @@ > #include "syscall.h" > #include "kprintf.h" > #include "console.h" > +#include "timer.h" > > /** > * Debug-Ausgaben; Nur solange benutzen, bis der definitve Treiber im Usermode > @@ -61,3 +62,11 @@ uint64_t syscall_get_tick_count(void) > { > return timer_ticks; > } > + > +/** > + * Registriert einen neuen Timer > + */ > +void syscall_add_timer(uint32_t timer_id, uint32_t usec) > +{ > + timer_register(cpu_get_current()->thread->process, timer_id, usec); > +} > diff --git a/src/kernel2/src/tasks/pm.c b/src/kernel2/src/tasks/pm.c > index 0324c33..3f43688 100644 > --- a/src/kernel2/src/tasks/pm.c > +++ b/src/kernel2/src/tasks/pm.c > @@ -40,6 +40,7 @@ > > #include "tasks.h" > #include "lock.h" > +#include "timer.h" > > > struct on_destroy_info { > @@ -162,6 +163,9 @@ void pm_destroy(pm_process_t* process) > } > list_destroy(process->on_destroy); > > + // Timer freigeben > + timer_cancel_all(process); > + > // RPC-Strukturen freigeben > // TODO Die einzelnen Listenglieder freigeben > list_destroy(process->rpcs); > diff --git a/src/kernel2/src/timer.c b/src/kernel2/src/timer.c > new file mode 100644 > index 0000000..5c85827 > --- /dev/null > +++ b/src/kernel2/src/timer.c > @@ -0,0 +1,150 @@ > +/* > + * Copyright (c) 2006-2008 The tyndur Project. All rights reserved. Schon besser, reicht aber noch nicht. *g* Jaja ich weiss, ich bin schuld. ;-) > + * > + * This code is derived from software contributed to the tyndur Project > + * by Kevin Wolf. > + * > + * Redistribution and use in source and binary forms, with or without > + * modification, are permitted provided that the following conditions > + * are met: > + * 1. Redistributions of source code must retain the above copyright > + * notice, this list of conditions and the following disclaimer. > + * 2. Redistributions in binary form must reproduce the above copyright > + * notice, this list of conditions and the following disclaimer in the > + * documentation and/or other materials provided with the distribution. > + * 3. All advertising materials mentioning features or use of this software > + * must display the following acknowledgement: > + * This product includes software developed by the tyndur Project > + * and its contributors. > + * 4. Neither the name of the tyndur Project nor the names of its > + * contributors may be used to endorse or promote products derived > + * from this software without specific prior written permission. > + * > + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS > + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED > + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR > + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR > + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, > + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, > + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; > + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, > + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR > + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF > + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. > + */ > + > +#include > +#include > + > +#include "timer.h" > +#include "syscall.h" > + > +extern uint64_t timer_ticks; > + > +/** > + * Liste aller registrierten Timer > + */ > +static list_t* timers; > + > +/** > + * Repraesentiert einen registrierten Timer. Ein Timer gehoert zun einem > + * bestimmten Prozess und nach Ablauf der vorgegebenen Zeitspanne wird ein RPC > + * zu diesem Prozess durchgefuehrt > + */ > +struct timeout { > + pm_process_t* task; > + uint32_t timer_id; > + uint64_t timeout; > +}; > + > +/** > + * Initialisiert die Timerverwaltung > + */ > +void timer_init(void) > +{ > + timers = list_create(); > +} > + > +/** > + * Registriert einen neuen Timer > + */ > +void timer_register(pm_process_t* task, uint32_t timer_id, uint32_t usec) > +{ > + // Anlegen des Timeout-Objekts > + struct timeout* timeout = malloc(sizeof(struct timeout)); > + > + timeout->task = task; > + timeout->timer_id = timer_id; > + timeout->timeout = timer_ticks + usec; > + > + // An der richtigen Stelle in der Liste einsortieren, so dass immer nur > + // das erste Listenelement geprueft werden muss > + struct timeout* item; > + int i; > + for (i = 0; (item = list_get_element_at(timers, i)); i++) { > + if (item->timeout > timeout->timeout) { > + break; > + } > + } > + > + list_insert(timers, i, timeout); > +} > + > +/** > + * Auszurufen bei jeder Aktualisierung der Systemzeit. Fuehrt die KRITIKEL! > + * RPC-Benachrichtigungen fuer alle faelligen Timer aus. > + */ > +void timer_notify(uint64_t microtime) > +{ > + static uint64_t last_microtime = 0; > + static const uint32_t rpc_timer_function = 514; > + > + struct timeout* item; > + int i = 0; > + while ((item = list_get_element_at(timers, i))) > + { > + // Die Schleife soll nur so lange laufen, wie die Timeouts in der > + // Vergangenheit liegen. Da die Liste sortiert ist, kann beim ersten > + // Timeout, der in der Zukunft liegt, abgebrochen werden. > + // > + // Overflows muessen abgefangen werden, da in diesem Spezialfall eine > + // groessere Zahl dennoch Vergangenheit bedeutet. Wie ich grad sehe, > + // reden wir von einem qword und damit von einer Uptime von ein paar > + // hunderttausend Jahren, aber tyndur ist ja stabil und wir daher > + // optimistisch. > + if (((item->timeout > microtime) && (microtime > last_microtime)) > + || ((item->timeout < last_microtime) && (microtime < last_microtime))) > + { > + break; > + } > + > + // Task per RPC informieren, dass der Timer abgelaufen ist. > + // Im Fehlerfall ueberspringen und es beim naechsten Mal nochmal > + // versuchen. > + if (!syscall_fastrpc(item->task->pid, > + 4, (char*) &rpc_timer_function, > + 4, (char*) &item->timer_id)) > + { > + i++; > + continue; > + } > + > + free(list_remove(timers, i)); > + } > + > + last_microtime = microtime; > +} > + > +/** > + * Entfernt alle registrierten Timer eines Prozesses > + */ > +void timer_cancel_all(pm_process_t* task) > +{ > + struct timeout* item; > + int i; > + for (i = 0; (item = list_get_element_at(timers, i)); i++) { > + if (item->task == task) { > + list_remove(timers, i); > + } > + } > +} Sonst sieht es gut aus. Ich glaube du kriegst das noch in und kannst danach einchecken. ;-) -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sun Jan 18 17:19:33 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 18 Jan 2009 17:19:33 +0100 Subject: [tyndur-devel] [Lost] [PATCH v2 07/10] kernel2: Syscall pm_exit_process In-Reply-To: <1229813356-4252-8-git-send-email-kevin@tyndur.org> References: <1229813356-4252-1-git-send-email-kevin@tyndur.org> <1229813356-4252-8-git-send-email-kevin@tyndur.org> Message-ID: <20090118161932.GF10425@einstein.produktiv.lan> On Sat, Dec 20 23:49, Kevin Wolf wrote: > + kernel2: Syscall pm_exit_process > --- > src/kernel2/include/syscall.h | 3 +++ > src/kernel2/src/syscall.c | 1 + > src/kernel2/src/syscalls/pm.c | 24 ++++++++++++++++++++++++ > src/kernel2/src/tasks/pm.c | 6 ++++-- > src/kernel2/src/tasks/thread.c | 11 ++++++----- > 5 files changed, 38 insertions(+), 7 deletions(-) > > diff --git a/src/kernel2/include/syscall.h b/src/kernel2/include/syscall.h > index b30b389..160cbf3 100644 > --- a/src/kernel2/include/syscall.h > +++ b/src/kernel2/include/syscall.h > @@ -109,6 +109,9 @@ void syscall_pm_wait_for_rpc(void); > PID_T SYSCALL_PM_CREATE_PROCESS(VADDR_T START, UID_T UID, > const char* cmdline, pid_t parent_pid); > > +/// Aktuellen Prozess beenden > +void syscall_pm_exit_process(void); > + > /// Speicher an einen anderen Prozess uebergeben > void syscall_init_child_page(pid_t pid, vaddr_t src, vaddr_t dest, > size_t size); > diff --git a/src/kernel2/src/syscall.c b/src/kernel2/src/syscall.c > index 836d1e7..1749c7e 100644 > --- a/src/kernel2/src/syscall.c > +++ b/src/kernel2/src/syscall.c > @@ -67,6 +67,7 @@ void syscall_init() > > syscall_register(SYSCALL_PM_CREATE_PROCESS, &syscall_pm_create_process, 4); > syscall_register(SYSCALL_PM_INIT_PAGE, &syscall_init_child_page, 4); > + syscall_register(SYSCALL_PM_EXIT_PROCESS, &syscall_pm_exit_process, 0); > > syscall_register(SYSCALL_SET_RPC_HANDLER, &syscall_set_rpc_handler, 1); > #if CONFIG_ARCH == ARCH_I386 > diff --git a/src/kernel2/src/syscalls/pm.c b/src/kernel2/src/syscalls/pm.c > index 93845b3..34e1888 100644 > --- a/src/kernel2/src/syscalls/pm.c > +++ b/src/kernel2/src/syscalls/pm.c > @@ -64,6 +64,30 @@ pid_t syscall_pm_create_process(vaddr_t start, uid_t uid, const char* cmdline, > return process->pid; > } > > +/** > + * Beendet den aktuellen Prozess. > + */ > +void syscall_pm_exit_process(void) > +{ > + pm_process_t* old_task = cpu_get_current()->thread->process; > + pm_thread_t* thread; > + > + // Task abgeben > + pm_scheduler_push(cpu_get_current()->thread); > + > + // Genau jetzt muss der Prozess geloescht werden: Der Thread ist nicht mehr > + // aktiv, und er darf auch nicht wieder aktiviert werden. > + pm_destroy(old_task); > + > + // Einen neuen Task holen. > + // FIXME Da braucht es endlich eine Funktion dafuer > + thread = pm_scheduler_pop(); > + > + cpu_get_current()->tss.esp0 = (uintptr_t) thread->kernel_stack + sizeof(interrupt_stack_frame_t); > + cpu_get_current()->tss.ss0 = 2 << 3; > + > + cpu_get_current()->thread = thread; Hier wäre es nett, wenn das dann in der nächsten Zeit durch eine Funktion ersetzt würde, irgendwie glaube ich nämlich, dass das irgendwann zu seltsamen Bugs führt... ;-) Aber jo das ist was fuer einen anderen Patch. > +} > > /** > * PID des aktuellen Prozesses ausfindig machen > diff --git a/src/kernel2/src/tasks/pm.c b/src/kernel2/src/tasks/pm.c > index 3f43688..74a0f67 100644 > --- a/src/kernel2/src/tasks/pm.c > +++ b/src/kernel2/src/tasks/pm.c > @@ -221,11 +221,13 @@ bool pm_block(pm_process_t* process) > > // Die einzelnen Threads sperren > while ((thread = list_get_element_at(process->threads, i++))) { > - if (pm_thread_block(thread) != TRUE) { > + if ((thread->status != PM_STATUS_BLOCKED) > + && pm_thread_block(thread) != TRUE) > + { > result = FALSE; > } > } > - > + > process->status = PM_STATUS_BLOCKED; > > return result; > diff --git a/src/kernel2/src/tasks/thread.c b/src/kernel2/src/tasks/thread.c > index 6324b2a..d869595 100644 > --- a/src/kernel2/src/tasks/thread.c > +++ b/src/kernel2/src/tasks/thread.c > @@ -143,8 +143,11 @@ void pm_thread_destroy(pm_thread_t* thread) > // TODO: Den Userspacestack auch freigeben > > // Kernelstack freigeben > + /* > + * FIXME Wieder freigeben, und dieses Mal dann auch physisch > mmc_unmap(&thread->process->context, thread->kernel_stack_bottom, > NUM_PAGES(thread->kernel_stack_size)); > + */ > > // Aus der Threadliste enfernen > pm_thread_t* thread_; > @@ -177,8 +180,7 @@ bool pm_thread_block(pm_thread_t* thread) > // TODO: In SMP-Systemen sollte hier ein IPI kommen, falls der Thread auf > // einer anderen CPU am laufen ist, der sie dazu zwingt, den Thread > // abzugeben. > - bool result = FALSE; > - > + > // Wenn der Thread gesperrt ist, muss garnicht weiter probiert werden > if (locked(&thread->lock) == TRUE) { > return FALSE; > @@ -188,12 +190,11 @@ bool pm_thread_block(pm_thread_t* thread) > > if (thread->status == PM_STATUS_READY) { > thread->status = PM_STATUS_BLOCKED; > - result = TRUE; > } > - > + > unlock(&thread->lock); > > - return result; > + return (thread->status == PM_STATUS_BLOCKED); > } > > /** Sieht zwar nicht gut aus, kann aber rein. ;-) -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sun Jan 18 17:22:02 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 18 Jan 2009 17:22:02 +0100 Subject: [tyndur-devel] [Lost] [PATCH v2 08/10] kernel2: Syscall mem_allocate_physical In-Reply-To: <1229813356-4252-9-git-send-email-kevin@tyndur.org> References: <1229813356-4252-1-git-send-email-kevin@tyndur.org> <1229813356-4252-9-git-send-email-kevin@tyndur.org> Message-ID: <20090118162202.GG10425@einstein.produktiv.lan> On Sat, Dec 20 23:49, Kevin Wolf wrote: > + kernel2: Syscall syscall_mem_allocate_physical > --- > src/kernel2/include/syscall.h | 4 ++++ > src/kernel2/src/syscall.c | 2 ++ > src/kernel2/src/syscalls/mem.c | 33 +++++++++++++++++++++++++++++++++ > 3 files changed, 39 insertions(+), 0 deletions(-) > > diff --git a/src/kernel2/include/syscall.h b/src/kernel2/include/syscall.h > index 160cbf3..05715a3 100644 > --- a/src/kernel2/include/syscall.h > +++ b/src/kernel2/include/syscall.h > @@ -77,6 +77,10 @@ void syscall_init(); > /// Einen Speicherblock allokieren. > vaddr_t syscall_mem_allocate(size_t bytes, syscall_arg_t flags, paddr_t* phys); > > +/// Physischen Speicher mappen > +vaddr_t syscall_mem_allocate_physical( > + size_t bytes, paddr_t position, syscall_arg_t flags); > + > /// Einen Speicherblock freigeben > void syscall_mem_free(vaddr_t start, size_t bytes); > > diff --git a/src/kernel2/src/syscall.c b/src/kernel2/src/syscall.c > index 1749c7e..58c82de 100644 > --- a/src/kernel2/src/syscall.c > +++ b/src/kernel2/src/syscall.c > @@ -49,6 +49,8 @@ syscall_t syscalls[SYSCALL_MAX]; > void syscall_init() > { > syscall_register(SYSCALL_MEM_ALLOCATE, &syscall_mem_allocate, 3); > + syscall_register(SYSCALL_MEM_ALLOCATE_PHYSICAL, > + &syscall_mem_allocate_physical, 3); > syscall_register(SYSCALL_MEM_FREE, &syscall_mem_free, 2); > > syscall_register(SYSCALL_PM_GET_PID, (void*) &syscall_pm_get_pid, 0); > diff --git a/src/kernel2/src/syscalls/mem.c b/src/kernel2/src/syscalls/mem.c > index bd41073..91457da 100644 > --- a/src/kernel2/src/syscalls/mem.c > +++ b/src/kernel2/src/syscalls/mem.c > @@ -74,6 +74,39 @@ vaddr_t syscall_mem_allocate(size_t bytes, syscall_arg_t flags, paddr_t* phys) > } > > /** > + * Einen Speicherblock an bekannter physischer Adresse mappen. > + * > + * @param bytes Groesse des Speicherblocks > + * @param position Physische Adresse des Speicherblocks > + * @param flags Unbenutzt > + * > + * @return Virtuelle Adresse des Blocks > + * > + * --- TODO laut Mail von Freaky --- > + * Hm k??nnten wir hier vielleicht noch irgendwas einbauen um sicher zu Sind hier meine oder deine oder gar keine Umlaute kaputt? ;-) > + * gehen, dass sie dass diese Blocks in der physischen Speicherverwaltung > + * reserviert sind? Ok, jo sie _sollten_ in der Memory-Map reserviert > + * sein, aber irgendwie weiss ich nicht so recht ob wir da nicht besser auf > + * nummer sicher gehen sollten... > + * > + * Das andere Problem w??re SMU wenn ich den Treiber versehtentlich mehrmals > + * starte,oder sogar 2 verschiedene Treiber habe, die gerne den selben > + * Speicherbereich h??tten? > + * > + * Aber weit schlimmer k??nnte das ausgehen, wenn der Prozess sich beendet, > + * oder beendet wird. Dann wird der Speicher doch physisch freigegeben? > + * --- Ende des TODO --- > + */ > +vaddr_t syscall_mem_allocate_physical( > + size_t bytes, paddr_t position, syscall_arg_t flags) > +{ > + size_t page_count = NUM_PAGES(PAGE_ALIGN_ROUND_UP(bytes)); > + > + return mmc_automap(&mmc_current_context(), position, page_count, > + USER_MEM_START, USER_MEM_END, MM_FLAGS_USER_DATA); > +} > + > +/** > * Einen Speicherbereich freigeben > * > * @param start Startadresse des Bereichs Schieb rein. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sun Jan 18 17:23:52 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 18 Jan 2009 17:23:52 +0100 Subject: [tyndur-devel] [Lost] [PATCH v2 09/10] kernel2: IRQ-Verarbeitung fixen In-Reply-To: <1229813356-4252-10-git-send-email-kevin@tyndur.org> References: <1229813356-4252-1-git-send-email-kevin@tyndur.org> <1229813356-4252-10-git-send-email-kevin@tyndur.org> Message-ID: <20090118162352.GH10425@einstein.produktiv.lan> On Sat, Dec 20 23:49, Kevin Wolf wrote: > ! kernel2: Der RPC zur Benachrichtigung ueber einen IRQ muss immer von dem Task selbst kommen, der benachrichtigt wird. > * kernel2: Die RPC-Liste, in die eingetragen wird, dass es ein IRQ war, gehoert strenggenommen zum Callee, nicht zum Caller. Das ist mit dem oberen Fix zwar egal, weil es immer dieselben sind, aber schoener ist es schon so. > --- > src/kernel2/src/interrupts/im.c | 6 ++++++ > src/kernel2/src/syscalls/rpc.c | 3 +-- > 2 files changed, 7 insertions(+), 2 deletions(-) > > diff --git a/src/kernel2/src/interrupts/im.c b/src/kernel2/src/interrupts/im.c > index 1838b4d..d8e12fc 100644 > --- a/src/kernel2/src/interrupts/im.c > +++ b/src/kernel2/src/interrupts/im.c > @@ -226,6 +226,7 @@ bool im_add_handler(uint32_t intr, pm_process_t* handler) > void im_send_interrupts(void) > { > uint32_t intr; > + pm_thread_t* old_thread = cpu_get_current()->thread; > > for (intr = 0; intr < IM_NUM_INTERRUPTS; intr++) > { > @@ -235,7 +236,10 @@ void im_send_interrupts(void) > break; > } > > + // Dieses Wechseln des Tasks ist wichtig: IRQs werden nur > + // angenommen, wenn der Task sie sich selbst schickt > // TODO schedule_to_task(intr_handling_task[intr], esp); > + cpu_get_current()->thread = list_get_element_at(intr_handling_task[intr]->threads, 0); > > if (!fastrpc_irq(intr_handling_task[intr], 0, 0, > sizeof(intr), (char*) &intr, intr - IM_IRQ_BASE)) > @@ -245,4 +249,6 @@ void im_send_interrupts(void) > intr_to_send[intr]--; > } > } > + > + cpu_get_current()->thread = old_thread; > } > diff --git a/src/kernel2/src/syscalls/rpc.c b/src/kernel2/src/syscalls/rpc.c > index 14fbe11..aa978de 100644 > --- a/src/kernel2/src/syscalls/rpc.c > +++ b/src/kernel2/src/syscalls/rpc.c > @@ -323,8 +323,7 @@ bool fastrpc_irq(pm_process_t* callee, size_t metadata_size, void* metadata, > return FALSE; > } > > - rpc_t* rpc = list_get_element_at( > - cpu_get_current()->thread->process->rpcs, 0); > + rpc_t* rpc = list_get_element_at(callee->rpcs, 0); > rpc->reenable_irq = irq; > > return TRUE; Rein damit. -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sun Jan 18 17:37:01 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 18 Jan 2009 17:37:01 +0100 Subject: [tyndur-devel] [Lost] [PATCH v2 10/10] kernel2: Makros fuer aktuellen Thread/Prozess In-Reply-To: <1229813356-4252-11-git-send-email-kevin@tyndur.org> References: <1229813356-4252-1-git-send-email-kevin@tyndur.org> <1229813356-4252-11-git-send-email-kevin@tyndur.org> Message-ID: <20090118163701.GI10425@einstein.produktiv.lan> On Sat, Dec 20 23:49, Kevin Wolf wrote: > * kernel2: Makros current_task und current_process verwenden, statt sich von der CPU ausgehend durchzuhangeln > --- > src/kernel2/include/tasks.h | 4 ++++ > src/kernel2/src/arch/i386/debug.c | 2 +- > src/kernel2/src/arch/i386/mm/mm_context.c | 2 +- > src/kernel2/src/arch/i386/syscall.c | 6 ++---- > src/kernel2/src/interrupts/im.c | 25 ++++++++++++------------- > src/kernel2/src/mm/shm.c | 4 ++-- > src/kernel2/src/syscalls/misc.c | 2 +- > src/kernel2/src/syscalls/pm.c | 20 ++++++++++---------- > src/kernel2/src/syscalls/pv.c | 8 +++----- > src/kernel2/src/syscalls/rpc.c | 27 +++++++++++++-------------- > 10 files changed, 49 insertions(+), 51 deletions(-) > > diff --git a/src/kernel2/include/tasks.h b/src/kernel2/include/tasks.h > index b766b04..2f89065 100644 > --- a/src/kernel2/include/tasks.h > +++ b/src/kernel2/include/tasks.h > @@ -39,6 +39,7 @@ > #include > #include > > +#include "cpu.h" > #include "mm.h" > #include "lock.h" > > @@ -193,5 +194,8 @@ void load_init_module(struct multiboot_info* multiboot_info); > /// Alle weiteren Module an init uebergeben > void load_multiboot_modules(struct multiboot_info* multiboot_info); > > +#define current_thread (cpu_get_current()->thread) > +#define current_process (cpu_get_current()->thread->process) Eigentlich hätte ich da noch ein pm_ davor erwartet, aber jo, damit kann ich leben. ;-) > + > #endif //ifndef _TASKS_H_ > > diff --git a/src/kernel2/src/arch/i386/debug.c b/src/kernel2/src/arch/i386/debug.c > index 5642643..edb2b82 100644 > --- a/src/kernel2/src/arch/i386/debug.c > +++ b/src/kernel2/src/arch/i386/debug.c > @@ -207,5 +207,5 @@ void print_tasks_backtrace(void) > } > } > > - mmc_activate(&cpu_get_current()->thread->process->context); > + mmc_activate(¤t_process->context); > } > diff --git a/src/kernel2/src/arch/i386/mm/mm_context.c b/src/kernel2/src/arch/i386/mm/mm_context.c > index 49a2d52..e220857 100644 > --- a/src/kernel2/src/arch/i386/mm/mm_context.c > +++ b/src/kernel2/src/arch/i386/mm/mm_context.c > @@ -109,7 +109,7 @@ mmc_context_t mmc_create_kernel_context() > (uintptr_t) page_directory | PTE_W | PTE_P; > > // Die Rueckgabe von mmc_current_context muss von Anfang an korrekt sein > - cpu_get_current()->thread->process->context = context; > + current_process->context = context; > > //context.page_directory_virt = mmc_automap(&context, context.page_directory, > // 1, KERNEL_MEM_START, KERNEL_MEM_END, MM_FLAGS_KERNEL_DATA); > diff --git a/src/kernel2/src/arch/i386/syscall.c b/src/kernel2/src/arch/i386/syscall.c > index e67af12..268d4e4 100644 > --- a/src/kernel2/src/arch/i386/syscall.c > +++ b/src/kernel2/src/arch/i386/syscall.c > @@ -98,10 +98,8 @@ void syscall_arch(machine_state_t* isf) > > // 512 Bytes Sicherheitsabstand auf dem Stack, denn wenn der Kernel > // hier einen Stack Overflow produziert, haben wir ein Problem. > - if ((void*) (isf->esp - 0x200) < > - cpu_get_current()->thread->user_stack_bottom) > - { > - increase_user_stack_size(cpu_get_current()->thread, 1); > + if ((void*) (isf->esp - 0x200) < current_thread->user_stack_bottom) { > + increase_user_stack_size(current_thread, 1); > } > > // Die Syscallhandler werden mit dem Userspace-Stack aufgerufen, damit > diff --git a/src/kernel2/src/interrupts/im.c b/src/kernel2/src/interrupts/im.c > index d8e12fc..5057303 100644 > --- a/src/kernel2/src/interrupts/im.c > +++ b/src/kernel2/src/interrupts/im.c > @@ -69,17 +69,17 @@ static void handle_exception(interrupt_stack_frame_t* isf, uint8_t int_num) > asm("mov %%cr2, %0" : "=r" (cr2)); > > // kprintf("user_stack_bottom = %x\n", > -// cpu_get_current()->thread->user_stack_bottom); > +// current_thread->user_stack_bottom); > > if (int_num == 0x0e) { > // Ueberpr??fen ob der Pagefault durch einen Stackoverflow > // hervorgerufen wurde. Falls ja: Stack vergroessern und weitermachen > if ((cr2 <= isf->esp + 0x800) && (cr2 >= isf->esp - 0x20) > - && (cpu_get_current()->thread != NULL) > - && ((void*) cr2 >= cpu_get_current()->thread->user_stack_bottom - 0x1000000) > - && ((void*) cr2 < cpu_get_current()->thread->user_stack_bottom)) > + && (current_thread != NULL) > + && ((void*) cr2 >= current_thread->user_stack_bottom - 0x1000000) > + && ((void*) cr2 < current_thread->user_stack_bottom)) > { > - increase_user_stack_size(cpu_get_current()->thread, 1); > + increase_user_stack_size(current_thread, 1); > return; > } > } > @@ -90,8 +90,7 @@ static void handle_exception(interrupt_stack_frame_t* isf, uint8_t int_num) > cpu_get_current()->id, int_num, isf->error_code); > > kprintf("PID %d: %s\n", > - cpu_get_current()->thread->process->pid, > - cpu_get_current()->thread->process->cmdline); > + current_process->pid, current_process->cmdline); > cpu_dump(isf); > kprintf("\033[0;40m"); > > @@ -119,7 +118,7 @@ static void handle_exception(interrupt_stack_frame_t* isf, uint8_t int_num) > interrupt_stack_frame_t* im_handler(interrupt_stack_frame_t* isf) > { > // Pointer auf den aktuellen Thread holen > - pm_thread_t* thread = cpu_get_current()->thread; > + pm_thread_t* thread = current_thread; > pm_thread_t* old_thread = thread; > thread->kernel_stack = (vaddr_t) isf; > byte int_num = isf->interrupt_number; > @@ -140,7 +139,7 @@ interrupt_stack_frame_t* im_handler(interrupt_stack_frame_t* isf) > pm_scheduler_push(thread); > > // Einen neuen Thread holen. > - cpu_get_current()->thread = pm_scheduler_pop(); > + current_thread = pm_scheduler_pop(); > > // Timer ausloesen, wenn noetig > timer_notify(timer_ticks); > @@ -165,7 +164,7 @@ interrupt_stack_frame_t* im_handler(interrupt_stack_frame_t* isf) > > im_send_interrupts(); > > - thread = cpu_get_current()->thread; > + thread = current_thread; > if (thread != old_thread) { > cpu_get_current()->tss.ss0 = 2 << 3; > cpu_get_current()->tss.esp0 = > @@ -226,7 +225,7 @@ bool im_add_handler(uint32_t intr, pm_process_t* handler) > void im_send_interrupts(void) > { > uint32_t intr; > - pm_thread_t* old_thread = cpu_get_current()->thread; > + pm_thread_t* old_thread = current_thread; > > for (intr = 0; intr < IM_NUM_INTERRUPTS; intr++) > { > @@ -239,7 +238,7 @@ void im_send_interrupts(void) > // Dieses Wechseln des Tasks ist wichtig: IRQs werden nur > // angenommen, wenn der Task sie sich selbst schickt > // TODO schedule_to_task(intr_handling_task[intr], esp); > - cpu_get_current()->thread = list_get_element_at(intr_handling_task[intr]->threads, 0); > + current_thread = list_get_element_at(intr_handling_task[intr]->threads, 0); > > if (!fastrpc_irq(intr_handling_task[intr], 0, 0, > sizeof(intr), (char*) &intr, intr - IM_IRQ_BASE)) > @@ -250,5 +249,5 @@ void im_send_interrupts(void) > } > } > > - cpu_get_current()->thread = old_thread; > + current_thread = old_thread; > } > diff --git a/src/kernel2/src/mm/shm.c b/src/kernel2/src/mm/shm.c > index 6953369..72c5eac 100644 > --- a/src/kernel2/src/mm/shm.c > +++ b/src/kernel2/src/mm/shm.c > @@ -120,7 +120,7 @@ void* shm_attach(uint32_t id) > } > > shm_proc = calloc(1, sizeof(*shm_proc)); > - shm_proc->process = cpu_get_current()->thread->process; > + shm_proc->process = current_process; > shm_proc->vaddr = ret; > list_push(shm->processes, shm_proc); > > @@ -137,7 +137,7 @@ void shm_detach(uint32_t id) > { > struct shm_desc* shm = tree_search(shms, id); > struct shm_process* shm_proc; > - pm_process_t* current_proc = cpu_get_current()->thread->process; > + pm_process_t* current_proc = current_process; > int i; > > if (shm == NULL) { > diff --git a/src/kernel2/src/syscalls/misc.c b/src/kernel2/src/syscalls/misc.c > index 5095c9b..bd29073 100644 > --- a/src/kernel2/src/syscalls/misc.c > +++ b/src/kernel2/src/syscalls/misc.c > @@ -68,5 +68,5 @@ uint64_t syscall_get_tick_count(void) > */ > void syscall_add_timer(uint32_t timer_id, uint32_t usec) > { > - timer_register(cpu_get_current()->thread->process, timer_id, usec); > + timer_register(current_process, timer_id, usec); > } > diff --git a/src/kernel2/src/syscalls/pm.c b/src/kernel2/src/syscalls/pm.c > index 34e1888..b4f5cf7 100644 > --- a/src/kernel2/src/syscalls/pm.c > +++ b/src/kernel2/src/syscalls/pm.c > @@ -69,11 +69,11 @@ pid_t syscall_pm_create_process(vaddr_t start, uid_t uid, const char* cmdline, > */ > void syscall_pm_exit_process(void) > { > - pm_process_t* old_task = cpu_get_current()->thread->process; > + pm_process_t* old_task = current_process; > pm_thread_t* thread; > > // Task abgeben > - pm_scheduler_push(cpu_get_current()->thread); > + pm_scheduler_push(current_thread); > > // Genau jetzt muss der Prozess geloescht werden: Der Thread ist nicht mehr > // aktiv, und er darf auch nicht wieder aktiviert werden. > @@ -86,7 +86,7 @@ void syscall_pm_exit_process(void) > cpu_get_current()->tss.esp0 = (uintptr_t) thread->kernel_stack + sizeof(interrupt_stack_frame_t); > cpu_get_current()->tss.ss0 = 2 << 3; > > - cpu_get_current()->thread = thread; > + current_thread = thread; > } > > /** > @@ -96,7 +96,7 @@ void syscall_pm_exit_process(void) > */ > pid_t syscall_pm_get_pid() > { > - return cpu_get_current()->thread->process->pid; > + return current_process->pid; > } > > /** > @@ -111,7 +111,7 @@ pid_t syscall_pm_get_parent_pid(pid_t pid) > pm_process_t* process; > > if (pid == 0) { > - process = cpu_get_current()->thread->process; > + process = current_process; > } else { > process = pm_get(pid); > } > @@ -130,8 +130,8 @@ pid_t syscall_pm_get_parent_pid(pid_t pid) > */ > const char* syscall_pm_get_cmdline() > { > - const char* cmdline = cpu_get_current()->thread->process->cmdline; > - if (cpu_get_current()->thread->process->cmdline == NULL) { > + const char* cmdline = current_process->cmdline; > + if (cmdline == NULL) { > return NULL; > } > size_t cmdlinesize = strlen(cmdline) + 1; > @@ -210,7 +210,7 @@ void syscall_init_child_page(pid_t pid, vaddr_t dest, vaddr_t src, size_t size) > */ > void syscall_pm_sleep(void) > { > - pm_thread_t* thread = cpu_get_current()->thread; > + pm_thread_t* thread = current_thread; > > // Den aktuellen Thread an den Scheduler zurueckgeben > pm_scheduler_push(thread); > @@ -221,7 +221,7 @@ void syscall_pm_sleep(void) > cpu_get_current()->tss.esp0 = (uintptr_t) thread->kernel_stack + sizeof(interrupt_stack_frame_t); > cpu_get_current()->tss.ss0 = 2 << 3; > > - cpu_get_current()->thread = thread; > + current_thread = thread; > } > > /** > @@ -230,7 +230,7 @@ void syscall_pm_sleep(void) > */ > void syscall_pm_wait_for_rpc(void) > { > - pm_thread_t* thread = cpu_get_current()->thread; > + pm_thread_t* thread = current_thread; > syscall_pm_sleep(); > thread->status = PM_STATUS_WAIT_FOR_RPC; > } > diff --git a/src/kernel2/src/syscalls/pv.c b/src/kernel2/src/syscalls/pv.c > index 7f73e61..e587ca0 100644 > --- a/src/kernel2/src/syscalls/pv.c > +++ b/src/kernel2/src/syscalls/pv.c > @@ -47,8 +47,7 @@ > */ > int syscall_pm_p(void) > { > - pm_block_rpc(cpu_get_current()->thread->process, > - cpu_get_current()->thread->process->pid); > + pm_block_rpc(current_process, current_process->pid); > > return 0; > } > @@ -62,15 +61,14 @@ int syscall_pm_p(void) > int syscall_pm_v(pid_t pid) > { > if (pid == 0) { > - pm_unblock_rpc(cpu_get_current()->thread->process, > - cpu_get_current()->thread->process->pid); > + pm_unblock_rpc(current_process, current_process->pid); > } else { > pm_process_t* process = pm_get(pid); > if (process == NULL) { > return -1; > } > pm_unblock(process); > - pm_unblock_rpc(process, cpu_get_current()->thread->process->pid); > + pm_unblock_rpc(process, current_process->pid); > } > > return 0; > diff --git a/src/kernel2/src/syscalls/rpc.c b/src/kernel2/src/syscalls/rpc.c > index aa978de..688c4ea 100644 > --- a/src/kernel2/src/syscalls/rpc.c > +++ b/src/kernel2/src/syscalls/rpc.c > @@ -64,7 +64,7 @@ typedef struct { > */ > void syscall_set_rpc_handler(vaddr_t address) > { > - cpu_get_current()->thread->process->rpc_handler = address; > + current_process->rpc_handler = address; > } > > > @@ -154,7 +154,7 @@ int syscall_fastrpc(pid_t callee_pid, size_t metadata_size, void* metadata, > } > > /* > - if (callee == cpu_get_current()->thread) { > + if (callee == current_thread) { > kprintf("PID %d: Self-RPC ignoriert\n", callee->process->pid); > return 0; > } > @@ -214,9 +214,9 @@ int syscall_fastrpc(pid_t callee_pid, size_t metadata_size, void* metadata, > rpc->old_esp = callee_isf->esp; > rpc->eax = callee_isf->eax; > rpc->eflags = callee_isf->eflags; > - rpc->caller = cpu_get_current()->thread; > + rpc->caller = current_thread; > > - if (callee == cpu_get_current()->thread) { > + if (callee == current_thread) { > // Bei einem Self-RPC muss hinterher der Rueckgabewert > // des RPC-Syscalls in eax stehen > rpc->eax = 0; > @@ -239,7 +239,7 @@ int syscall_fastrpc(pid_t callee_pid, size_t metadata_size, void* metadata, > callee_isf->esp -= rounded_data_size; > > void* first_stack_page = mmc_automap_user( > - &cpu_get_current()->thread->process->context, > + ¤t_process->context, > &callee->process->context, > (vaddr_t) PAGE_ALIGN_ROUND_DOWN(callee_isf->esp), > NUM_PAGES(rounded_data_size + ((uintptr_t) callee_isf->esp % PAGE_SIZE)), > @@ -248,11 +248,11 @@ int syscall_fastrpc(pid_t callee_pid, size_t metadata_size, void* metadata, > void* stack = first_stack_page + ((uintptr_t) callee_isf->esp % PAGE_SIZE); > > ((uint32_t*) stack)[0] = data_size + metadata_size; > - ((uint32_t*) stack)[1] = cpu_get_current()->thread->process->pid; > + ((uint32_t*) stack)[1] = current_process->pid; > > #if 0 > kprintf("RPC PID %d => %d\n", > - cpu_get_current()->thread->process->pid, > + current_process->pid, > callee->process->pid); > kprintf("Kopiere: %08x => %08x, %d Bytes\n", > metadata, stack + 8, metadata_size); > @@ -268,13 +268,13 @@ int syscall_fastrpc(pid_t callee_pid, size_t metadata_size, void* metadata, > callee_isf->eip = (uintptr_t) callee->process->rpc_handler; > > // Temporaere Mappings wieder aufheben > - mmc_unmap(&cpu_get_current()->thread->process->context, first_stack_page, > + mmc_unmap(¤t_process->context, first_stack_page, > NUM_PAGES(rounded_data_size)); > > vmm_kernel_unmap(callee_isf, sizeof(*callee_isf)); > > // kprintf("[%d => %d] RPC durchgefuehrt.\n", > -// cpu_get_current()->thread->process->pid, > +// current_process->pid, > // callee->process->pid); > > // Der aufgerufene Task darf wieder laufen > @@ -345,9 +345,8 @@ bool fastrpc_irq(pm_process_t* callee, size_t metadata_size, void* metadata, > */ > void syscall_fastrpc_ret(void) > { > - rpc_t* rpc = list_pop(cpu_get_current()->thread->process->rpcs); > - interrupt_stack_frame_t* callee_isf = > - cpu_get_current()->thread->kernel_stack; > + rpc_t* rpc = list_pop(current_process->rpcs); > + interrupt_stack_frame_t* callee_isf = current_thread->kernel_stack; > > // Wenn der Task vom RPC-Handler zur??ckkehrt, obwohl der Handler > // gar nicht aufgerufen wurde, l??uft was schief > @@ -370,7 +369,7 @@ void syscall_fastrpc_ret(void) > > // kprintf("[%d => %d] RPC fertig.\n", > // rpc->caller->process->pid, > -// cpu_get_current()->thread->process->pid); > +// current_process->pid); > > // TODO Wechsel zum aufrufenden Task > #if 0 > @@ -414,7 +413,7 @@ void rpc_destroy_task_backlinks(struct task* destroyed_task) > > void syscall_add_interrupt_handler(uint32_t intr) > { > - im_add_handler(intr, cpu_get_current()->thread->process); > + im_add_handler(intr, current_process); > } > > #endif Sieht gut aus, rein damit. Puh... das wäre geschafft. ;-) -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From toni at tyndur.org Sun Jan 18 19:02:03 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 18 Jan 2009 19:02:03 +0100 Subject: [tyndur-devel] [PATCH] libc: Fake-Implementierung von getpwd{nam, uid} und getgr{nam, gid} Message-ID: <1232301724-25173-1-git-send-email-toni@tyndur.org> + libc: Implementierung der Funktionen getpwdnam und getpwduid aus pwd.h + libc: Implementierung der Funktionen getgrnam und getgrgid aus grp.h --- src/modules/include/grp.h | 75 ++++++++++++++++++++++++++++++++++++++ src/modules/include/pwd.h | 79 ++++++++++++++++++++++++++++++++++++++++ src/modules/lib/posix/grp.c | 84 +++++++++++++++++++++++++++++++++++++++++++ src/modules/lib/posix/pwd.c | 84 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 322 insertions(+), 0 deletions(-) create mode 100644 src/modules/include/grp.h create mode 100644 src/modules/include/pwd.h create mode 100644 src/modules/lib/posix/grp.c create mode 100644 src/modules/lib/posix/pwd.c diff --git a/src/modules/include/grp.h b/src/modules/include/grp.h new file mode 100644 index 0000000..c0af924 --- /dev/null +++ b/src/modules/include/grp.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Antoine Kaufmann. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef _GRP_H_ +#define _GRP_H_ + +#include +#include + +/** Repraesentiert einen Eintrag in der Gruppendatenbank */ +struct group { + /** Gruppenname */ + char* gr_name; + /** Gruppen-ID */ + gid_t gr_gid; + /** Zeiger auf ein Nullterminiertes Array mit den Mitgliedern */ + char** gr_mem; +}; + + +#ifndef CONFIG_LIBC_NO_STUBS + +/** + * Gruppendatebank-Eintrag anhand des Namens holen + * + * @param name Benutzername + * + * @return Pointer auf internen Speicher, der bei weiteren Aufrufen + * ueberschrieben wird. + */ +struct group* getgrnam(const char* name); + +/** + * Gruppendatebank-Eintrag ahnand der GID holen + * + * @return Pointer auf internen Speicher, der bei weiteren Aufrufen + * ueberschrieben wird. + */ +struct group* getgrgid(gid_t gid); + +#endif /* ndef CONFIG_LIBC_NO_STUBS */ + +#endif /* ndef _GRP_H */ + diff --git a/src/modules/include/pwd.h b/src/modules/include/pwd.h new file mode 100644 index 0000000..3200de6 --- /dev/null +++ b/src/modules/include/pwd.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Antoine Kaufmann. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef _PWD_H_ +#define _PWD_H_ + +#include +#include + +/** Repraesentiert einen Eintrag in der Benutzerdatenbank */ +struct passwd { + /** Benutzername */ + char* pw_name; + /** Benutzer-ID */ + uid_t pw_uid; + /** Gruppen-ID */ + gid_t pw_gid; + /** Homeverzeichnis */ + char* pw_dir; + /** Login-Shell */ + char* pw_shell; +}; + + +#ifndef CONFIG_LIBC_NO_STUBS + +/** + * Benutzerdatenbank-Eintrag anhand des Namens holen + * + * @param name Benutzername + * + * @return Pointer auf internen Speicher, der bei weiteren Aufrufen + * ueberschrieben wird. + */ +struct passwd* getpwnam(const char* name); + +/** + * Benutzerdatenbank-Eintrag ahnand der UID holen + * + * @return Pointer auf internen Speicher, der bei weiteren Aufrufen + * ueberschrieben wird. + */ +struct passwd* getpwuid(uid_t uid); + +#endif /* ndef CONFIG_LIBC_NO_STUBS */ + +#endif /* ndef _PWD_H */ + diff --git a/src/modules/lib/posix/grp.c b/src/modules/lib/posix/grp.c new file mode 100644 index 0000000..7aa6529 --- /dev/null +++ b/src/modules/lib/posix/grp.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Antoine Kaufmann. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + + +#ifndef CONFIG_LIBC_NO_STUBS + +static struct group grpent; +static char* grp_member[] = { "root", NULL }; + +/** + * Gruppendatebank-Eintrag anhand des Namens holen + * + * @param name Benutzername + * + * @return Pointer auf internen Speicher, der bei weiteren Aufrufen + * ueberschrieben wird. + */ +struct group* getgrnam(const char* name) +{ + // FIXME: Wir haben nur die Gruppe root + if (strcmp(name, "root")) { + return NULL; + } + + return getgrgid(0); +} + +/** + * Gruppendatebank-Eintrag ahnand der GID holen + * + * @return Pointer auf internen Speicher, der bei weiteren Aufrufen + * ueberschrieben wird. + */ +struct group* getgrgid(gid_t gid) +{ + // FIXME: Wir haben nur die Gruppe root + if (gid != 0) { + return NULL; + } + + grpent.gr_name = "root"; + grpent.gr_gid = 0; + grpent.gr_mem = grp_member; + return &grpent; +} + +#endif /* ndef CONFIG_LIBC_NO_STUBS */ + diff --git a/src/modules/lib/posix/pwd.c b/src/modules/lib/posix/pwd.c new file mode 100644 index 0000000..b5313c5 --- /dev/null +++ b/src/modules/lib/posix/pwd.c @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Antoine Kaufmann. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + + +#ifndef CONFIG_LIBC_NO_STUBS +static struct passwd pwdent; + +/** + * Benutzerdatenbank-Eintrag anhand des Namens holen + * + * @param name Benutzername + * + * @return Pointer auf internen Speicher, der bei weiteren Aufrufen + * ueberschrieben wird. + */ +struct passwd* getpwnam(const char* name) +{ + // FIXME: Wir haben nur den Bentuzer root + if (strcmp(name, "root")) { + return NULL; + } + + return getpwuid(0); +} + +/** + * Benutzerdatenbank-Eintrag ahnand der UID holen + * + * @return Pointer auf internen Speicher, der bei weiteren Aufrufen + * ueberschrieben wird. + */ +struct passwd* getpwuid(uid_t uid) +{ + // FIXME: Wir haben nur den Bentuzer root + if (uid != 0) { + return NULL; + } + + pwdent.pw_name = "root"; + pwdent.pw_uid = 0; + pwdent.pw_gid = 0; + pwdent.pw_dir = "file:/"; + pwdent.pw_shell = "file:/apps/sh"; + return &pwdent; +} + +#endif /* ndef CONFIG_LIBC_NO_STUBS */ + -- 1.6.0.6 From toni at tyndur.org Sun Jan 18 19:02:04 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 18 Jan 2009 19:02:04 +0100 Subject: [tyndur-devel] [PATCH] libc: wctomb() In-Reply-To: <1232301724-25173-1-git-send-email-toni@tyndur.org> References: <1232301724-25173-1-git-send-email-toni@tyndur.org> Message-ID: <1232301724-25173-2-git-send-email-toni@tyndur.org> + libc: wctomb() zum Umwandeln eines wchars in einen Multibyte-String --- src/include/stdlib.h | 15 +++++++++++++- src/lib/string/multibyte.c | 46 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/include/stdlib.h b/src/include/stdlib.h index bbabf8a..a817765 100644 --- a/src/include/stdlib.h +++ b/src/include/stdlib.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006 The tyndur Project. All rights reserved. + * Copyright (c) 2006-2009 The tyndur Project. All rights reserved. * * This code is derived from software contributed to the tyndur Project * by Antoine Kaufmann. @@ -107,6 +107,19 @@ int mblen(const char* s, size_t slen); */ int mbtowc(wchar_t* wc, const char* s, size_t len); +/** + * Einen wchar in ein Multibyte-Zeichen umwandeln. Der Aufrufer muss + * garantieren dass in buf mindestens MB_CUR_MAX Bytes verfuegbar sind. + * + * @param buf Puffer in dem das Multibyte-Zeichen abgelegt wird. Dabei koennen + * bis zu MB_CUR_MAX Bytes geschrieben werden. + * @param wc Der umzuwandelnde wchar + * + * @return Bei Erfolg wir die Anzahl der in buf geschrieben Bytes + * zurueckgegeben, im Fehlerfall -1. + */ +int wctomb(char* buf, wchar_t wc); + /** * Seed fuer Zufallszahlgenerator setzen diff --git a/src/lib/string/multibyte.c b/src/lib/string/multibyte.c index 6bd168e..f0bb4a0 100644 --- a/src/lib/string/multibyte.c +++ b/src/lib/string/multibyte.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008 The tyndur Project. All rights reserved. + * Copyright (c) 2008-2009 The tyndur Project. All rights reserved. * * This code is derived from software contributed to the tyndur Project * by Antoine Kaufmann. @@ -60,7 +60,7 @@ #define VAL_3 (BIT(7) | BIT(6) | BIT(5)) #define VAL_4 (BIT(7) | BIT(6) | BIT(5) | BIT(6)) -#define get_lower_bits(v, x) (v & (BIT(x + 1) - 1)) +#define get_lower_bits(v, x) (v & (BIT(x) - 1)) /** @@ -138,7 +138,7 @@ int mbtowc(wchar_t* wc, const char* s, size_t slen) } // Erstes Zeichen wird separat behandelt - bitpos = (len == 1 ? 7 : 7 - len); + bitpos = (len == 1 ? 7 : 6 - len); *wc = get_lower_bits(s[0], bitpos); // Die anderen Zeichen sind alle gleich @@ -150,3 +150,43 @@ int mbtowc(wchar_t* wc, const char* s, size_t slen) return len; } +extern void puts(const char*); +extern void printf(const char*,...); +extern void* stdout; +/** + * Einen wchar in ein Multibyte-Zeichen umwandeln. Der Aufrufer muss + * garantieren dass in buf mindestens MB_CUR_MAX Bytes verfuegbar sind. + * + * @param buf Puffer in dem das Multibyte-Zeichen abgelegt wird. Dabei koennen + * bis zu MB_CUR_MAX Bytes geschrieben werden. + * @param wc Der umzuwandelnde wchar + * + * @return Bei Erfolg wir die Anzahl der in buf geschrieben Bytes + * zurueckgegeben, im Fehlerfall -1. + */ +int wctomb(char* buf, wchar_t wc) +{ + if (buf == NULL) { + return 0; + } + + if (get_lower_bits(wc, 7) == wc) { + buf[0] = get_lower_bits(wc, 7) | VAL_1; + return 1; + } else if (get_lower_bits(wc, 11) == wc) { + buf[0] = get_lower_bits((wc >> 6), 5) | VAL_2; + buf[1] = get_lower_bits((wc >> 0), 6) | BIT(7); + return 2; + } else if (get_lower_bits(wc, 16) == wc) { + buf[0] = get_lower_bits((wc >> 12), 4) | VAL_3; + buf[1] = get_lower_bits((wc >> 6), 6) | BIT(7); + buf[2] = get_lower_bits((wc >> 0), 6) | BIT(7); + return 3; + } else { + buf[0] = get_lower_bits((wc >> 18), 3) | VAL_4; + buf[1] = get_lower_bits((wc >> 12), 6) | BIT(7); + buf[2] = get_lower_bits((wc >> 6), 6) | BIT(7); + buf[3] = get_lower_bits((wc >> 0), 6) | BIT(7); + return 4; + } +} -- 1.6.0.6 From toni at tyndur.org Sun Jan 18 19:35:52 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 18 Jan 2009 19:35:52 +0100 Subject: [tyndur-devel] PCI-Fixes Message-ID: <1232303755-28395-1-git-send-email-toni@tyndur.org> Fixes damit man PCI in CDI-Treibern anständig benutzen kann. From toni at tyndur.org Sun Jan 18 19:35:53 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 18 Jan 2009 19:35:53 +0100 Subject: [tyndur-devel] [PATCH] servmgr: RPC-Interface benutzbar machen In-Reply-To: <1232303755-28395-1-git-send-email-toni@tyndur.org> References: <1232303755-28395-1-git-send-email-toni@tyndur.org> Message-ID: <1232303755-28395-2-git-send-email-toni@tyndur.org> ! libc: Der Servicename wird in servmgr_need jetzt nullterminiert versendet... ! servmgr: ... und servmgr prueft jetzt sogar das richtige Byte um zu pruefen ob die Daten nulltermiert sind. ;-) --- src/modules/lib/servmgr.c | 4 ++-- src/modules/servmgr/rpcif.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modules/lib/servmgr.c b/src/modules/lib/servmgr.c index 56fb700..47a295b 100644 --- a/src/modules/lib/servmgr.c +++ b/src/modules/lib/servmgr.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008 The tyndur Project. All rights reserved. + * Copyright (c) 2008-2009 The tyndur Project. All rights reserved. * * This code is derived from software contributed to the tyndur Project * by Antoine Kaufmann. @@ -43,7 +43,7 @@ static pid_t servmgr_pid(void); bool servmgr_need(const char* service_name) { - return rpc_get_dword(servmgr_pid(), "NEEDSERV", strlen(service_name), + return rpc_get_dword(servmgr_pid(), "NEEDSERV", strlen(service_name) + 1, (char*) service_name); } diff --git a/src/modules/servmgr/rpcif.c b/src/modules/servmgr/rpcif.c index eda7a48..66c1a66 100644 --- a/src/modules/servmgr/rpcif.c +++ b/src/modules/servmgr/rpcif.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008 The tyndur Project. All rights reserved. + * Copyright (c) 2008-2009 The tyndur Project. All rights reserved. * * This code is derived from software contributed to the tyndur Project * by Antoine Kaufmann. @@ -58,7 +58,7 @@ static void rpc_needserv(pid_t pid, dword cid, size_t data_size, void* data) bool result; // Pruefen ob der Name nullterminiert ist - if (name[data_size] != 0) { + if (name[data_size - 1] != 0) { rpc_send_dword_response(pid, cid, 0); return; } -- 1.6.0.6 From toni at tyndur.org Sun Jan 18 19:35:54 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 18 Jan 2009 19:35:54 +0100 Subject: [tyndur-devel] [PATCH] cdi: Wenn PCI-Funktionen benutzt werden, auf PCI warten In-Reply-To: <1232303755-28395-1-git-send-email-toni@tyndur.org> References: <1232303755-28395-1-git-send-email-toni@tyndur.org> Message-ID: <1232303755-28395-3-git-send-email-toni@tyndur.org> ! cdi: Sicherstellen dass PCI laeuft, bevor versucht wird die Geraete einzulesen. --- src/modules/cdi/lib/pci.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/src/modules/cdi/lib/pci.c b/src/modules/cdi/lib/pci.c index 64d2352..90df6d0 100644 --- a/src/modules/cdi/lib/pci.c +++ b/src/modules/cdi/lib/pci.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007 Kevin Wolf + * Copyright (c) 2007-2009 Kevin Wolf * * This program is free software. It comes without any warranty, to * the extent permitted by applicable law. You can redistribute it @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -94,6 +95,8 @@ static struct cdi_pci_device* read_pci_device(char* filename) */ void cdi_pci_get_all_devices(cdi_list_t list) { + servmgr_need("pci"); + io_resource_t* dir_res = directory_open("pci:/devices/"); if (dir_res == NULL) { -- 1.6.0.6 From toni at tyndur.org Sun Jan 18 19:35:55 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 18 Jan 2009 19:35:55 +0100 Subject: [tyndur-devel] [PATCH] pci: Klasse und Revision richtig einlesen In-Reply-To: <1232303755-28395-1-git-send-email-toni@tyndur.org> References: <1232303755-28395-1-git-send-email-toni@tyndur.org> Message-ID: <1232303755-28395-4-git-send-email-toni@tyndur.org> ! pci: Richtigen Offset fuer Klasse eingetragen, dann funktioniert das auch wie erwartet. ! pci: Klasse und Revision sind jeweils nur ein Word und kein DWord --- src/modules/pci/include/pcihw.h | 37 ++++++++++++++++++++++++++++++++++++- src/modules/pci/pcihw.c | 6 +++--- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/modules/pci/include/pcihw.h b/src/modules/pci/include/pcihw.h index b2579ad..1cfa3ce 100644 --- a/src/modules/pci/include/pcihw.h +++ b/src/modules/pci/include/pcihw.h @@ -1,3 +1,38 @@ +/* + * Copyright (c) 2007-2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #ifndef _PCI_HW_ #define _PCI_HW_ @@ -9,7 +44,7 @@ #define PCI_COMMAND 0x04 #define PCI_STATUS 0x06 #define PCI_REVISION 0x08 -#define PCI_CLASS 0x09 +#define PCI_CLASS 0x0A #define PCI_HEADERTYPE 0x0E #define PCI_BAR0 0x10 #define PCI_INTERRUPT 0x3C diff --git a/src/modules/pci/pcihw.c b/src/modules/pci/pcihw.c index 4013617..05189e9 100644 --- a/src/modules/pci/pcihw.c +++ b/src/modules/pci/pcihw.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007 The tyndur Project. All rights reserved. + * Copyright (c) 2007-2009 The tyndur Project. All rights reserved. * * This code is derived from software contributed to the tyndur Project * by Kevin Wolf. @@ -213,8 +213,8 @@ struct pci_device pci_get_device(dword bus, dword device, dword func) .vendor_id = pci_config_read_word(bus, device, func, PCI_VENDOR_ID), .device_id = pci_config_read_word(bus, device, func, PCI_DEVICE_ID), - .class_id = pci_config_read_dword(bus, device, func, PCI_CLASS), - .rev_id = pci_config_read_dword(bus, device, func, PCI_REVISION), + .class_id = pci_config_read_word(bus, device, func, PCI_CLASS), + .rev_id = pci_config_read_word(bus, device, func, PCI_REVISION), .irq = pci_config_read_byte(bus, device, func, PCI_INTERRUPT), .resources = NULL -- 1.6.0.6 From mail at kevin-wolf.de Sun Jan 18 11:41:11 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sun, 18 Jan 2009 11:41:11 +0100 Subject: [tyndur-devel] [PATCH] libc: Fake-Implementierung von getpwd{nam, uid} und getgr{nam, gid} In-Reply-To: <1232301724-25173-1-git-send-email-toni@tyndur.org> References: <1232301724-25173-1-git-send-email-toni@tyndur.org> Message-ID: <49730747.2050307@kevin-wolf.de> Antoine Kaufmann schrieb: > + libc: Implementierung der Funktionen getpwdnam und getpwduid aus pwd.h > + libc: Implementierung der Funktionen getgrnam und getgrgid aus grp.h Also erstmal ein großes s/datebank/datenbank/ drüberlaufen lassen ;-) > + // FIXME: Wir haben nur die Gruppe root > + // FIXME: Wir haben nur den Bentuzer root Abgesehen vom Tippfehler im zweiten Kommentar sollten wir uns mal Gedanken machen, inwieweit das überhaupt fixbar ist. Also: Wie sieht die native Rechteverwaltung aus? Haben wir überhaupt sowas wie *nix-Benutzergruppen? Haben wir nur die Unterscheidung zwischen einem allmächtigen "root" (und ist dieser Name überhaupt toll?) und einfachen Benutzern oder eher eine feinere Abstufung, die auch überhaupt nichts mit UID 0 zu tun hat? Aber das ändert ja nichts an diesem Patch, insofern erstmal rein damit. From mail at kevin-wolf.de Sun Jan 18 11:57:54 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sun, 18 Jan 2009 11:57:54 +0100 Subject: [tyndur-devel] [PATCH] libc: wctomb() In-Reply-To: <1232301724-25173-2-git-send-email-toni@tyndur.org> References: <1232301724-25173-1-git-send-email-toni@tyndur.org> <1232301724-25173-2-git-send-email-toni@tyndur.org> Message-ID: <200901181157.54381@kevin-wolf.de> Am Sonntag, 18. Januar 2009 19:02 schrieb Antoine Kaufmann: > + libc: wctomb() zum Umwandeln eines wchars in einen Multibyte-String > --- > src/include/stdlib.h | 15 +++++++++++++- > src/lib/string/multibyte.c | 46 > +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 57 > insertions(+), 4 deletions(-) > > diff --git a/src/include/stdlib.h b/src/include/stdlib.h > index bbabf8a..a817765 100644 > --- a/src/include/stdlib.h > +++ b/src/include/stdlib.h > @@ -1,5 +1,5 @@ > /* > - * Copyright (c) 2006 The tyndur Project. All rights reserved. > + * Copyright (c) 2006-2009 The tyndur Project. All rights reserved. > * > * This code is derived from software contributed to the tyndur Project > * by Antoine Kaufmann. > @@ -107,6 +107,19 @@ int mblen(const char* s, size_t slen); > */ > int mbtowc(wchar_t* wc, const char* s, size_t len); > > +/** > + * Einen wchar in ein Multibyte-Zeichen umwandeln. Der Aufrufer muss > + * garantieren dass in buf mindestens MB_CUR_MAX Bytes verfuegbar sind. > + * > + * @param buf Puffer in dem das Multibyte-Zeichen abgelegt wird. Dabei > koennen + * bis zu MB_CUR_MAX Bytes geschrieben werden. > + * @param wc Der umzuwandelnde wchar > + * > + * @return Bei Erfolg wir die Anzahl der in buf geschrieben Bytes > + * zurueckgegeben, im Fehlerfall -1. > + */ > +int wctomb(char* buf, wchar_t wc); Wenn du das so implementierst wie im Kommentar beschrieben, dann fehlt der Fall buf == NULL. Ansonsten fehlt der passende Kommentar. (Also genaugenommen fehlt in beiden Fällen ein Kommentar, die Frage ist nur, ob er mit FIXME anfängt) > /** > * Seed fuer Zufallszahlgenerator setzen > diff --git a/src/lib/string/multibyte.c b/src/lib/string/multibyte.c > index 6bd168e..f0bb4a0 100644 > --- a/src/lib/string/multibyte.c > +++ b/src/lib/string/multibyte.c > @@ -1,5 +1,5 @@ > /* > - * Copyright (c) 2008 The tyndur Project. All rights reserved. > + * Copyright (c) 2008-2009 The tyndur Project. All rights reserved. > * > * This code is derived from software contributed to the tyndur Project > * by Antoine Kaufmann. > @@ -60,7 +60,7 @@ > #define VAL_3 (BIT(7) | BIT(6) | BIT(5)) > #define VAL_4 (BIT(7) | BIT(6) | BIT(5) | BIT(6)) > > -#define get_lower_bits(v, x) (v & (BIT(x + 1) - 1)) > +#define get_lower_bits(v, x) (v & (BIT(x) - 1)) > > > /** > @@ -138,7 +138,7 @@ int mbtowc(wchar_t* wc, const char* s, size_t slen) > } > > // Erstes Zeichen wird separat behandelt > - bitpos = (len == 1 ? 7 : 7 - len); > + bitpos = (len == 1 ? 7 : 6 - len); > *wc = get_lower_bits(s[0], bitpos); Diese zwei Hunks sind ein Bugfix und gehören eigentlich nicht hier rein, oder? Davon abgesehen: Wäre bitpos = 7 - (len - 1); nicht lesbarer? > // Die anderen Zeichen sind alle gleich > @@ -150,3 +150,43 @@ int mbtowc(wchar_t* wc, const char* s, size_t slen) > return len; > } > > +extern void puts(const char*); > +extern void printf(const char*,...); > +extern void* stdout; *hust* > +/** > + * Einen wchar in ein Multibyte-Zeichen umwandeln. Der Aufrufer muss > + * garantieren dass in buf mindestens MB_CUR_MAX Bytes verfuegbar sind. > + * > + * @param buf Puffer in dem das Multibyte-Zeichen abgelegt wird. Dabei > koennen + * bis zu MB_CUR_MAX Bytes geschrieben werden. > + * @param wc Der umzuwandelnde wchar > + * > + * @return Bei Erfolg wir die Anzahl der in buf geschrieben Bytes > + * zurueckgegeben, im Fehlerfall -1. > + */ > +int wctomb(char* buf, wchar_t wc) > +{ > + if (buf == NULL) { > + return 0; > + } > + > + if (get_lower_bits(wc, 7) == wc) { > + buf[0] = get_lower_bits(wc, 7) | VAL_1; > + return 1; > + } else if (get_lower_bits(wc, 11) == wc) { > + buf[0] = get_lower_bits((wc >> 6), 5) | VAL_2; > + buf[1] = get_lower_bits((wc >> 0), 6) | BIT(7); > + return 2; > + } else if (get_lower_bits(wc, 16) == wc) { > + buf[0] = get_lower_bits((wc >> 12), 4) | VAL_3; > + buf[1] = get_lower_bits((wc >> 6), 6) | BIT(7); > + buf[2] = get_lower_bits((wc >> 0), 6) | BIT(7); > + return 3; > + } else { > + buf[0] = get_lower_bits((wc >> 18), 3) | VAL_4; > + buf[1] = get_lower_bits((wc >> 12), 6) | BIT(7); > + buf[2] = get_lower_bits((wc >> 6), 6) | BIT(7); > + buf[3] = get_lower_bits((wc >> 0), 6) | BIT(7); > + return 4; > + } > +} Aber zumindest in der Umwandlung an sich sehe ich jetzt nicht auf Anhieb einen Fehler. ;-) From mail at kevin-wolf.de Sun Jan 18 12:14:59 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sun, 18 Jan 2009 12:14:59 +0100 Subject: [tyndur-devel] [Lost] [PATCH v2 08/10] kernel2: Syscall mem_allocate_physical In-Reply-To: <20090118162202.GG10425@einstein.produktiv.lan> References: <1229813356-4252-1-git-send-email-kevin@tyndur.org> <1229813356-4252-9-git-send-email-kevin@tyndur.org> <20090118162202.GG10425@einstein.produktiv.lan> Message-ID: <200901181215.00064@kevin-wolf.de> Am Sonntag, 18. Januar 2009 17:22 schrieb Antoine Kaufmann: > On Sat, Dec 20 23:49, Kevin Wolf wrote: > > + kernel2: Syscall syscall_mem_allocate_physical > > --- > > src/kernel2/include/syscall.h | 4 ++++ > > src/kernel2/src/syscall.c | 2 ++ > > src/kernel2/src/syscalls/mem.c | 33 +++++++++++++++++++++++++++++++++ > > 3 files changed, 39 insertions(+), 0 deletions(-) > > > > diff --git a/src/kernel2/include/syscall.h > > b/src/kernel2/include/syscall.h index 160cbf3..05715a3 100644 > > --- a/src/kernel2/include/syscall.h > > +++ b/src/kernel2/include/syscall.h > > @@ -77,6 +77,10 @@ void syscall_init(); > > /// Einen Speicherblock allokieren. > > vaddr_t syscall_mem_allocate(size_t bytes, syscall_arg_t flags, paddr_t* > > phys); > > > > +/// Physischen Speicher mappen > > +vaddr_t syscall_mem_allocate_physical( > > + size_t bytes, paddr_t position, syscall_arg_t flags); > > + > > /// Einen Speicherblock freigeben > > void syscall_mem_free(vaddr_t start, size_t bytes); > > > > diff --git a/src/kernel2/src/syscall.c b/src/kernel2/src/syscall.c > > index 1749c7e..58c82de 100644 > > --- a/src/kernel2/src/syscall.c > > +++ b/src/kernel2/src/syscall.c > > @@ -49,6 +49,8 @@ syscall_t syscalls[SYSCALL_MAX]; > > void syscall_init() > > { > > syscall_register(SYSCALL_MEM_ALLOCATE, &syscall_mem_allocate, 3); > > + syscall_register(SYSCALL_MEM_ALLOCATE_PHYSICAL, > > + &syscall_mem_allocate_physical, 3); > > syscall_register(SYSCALL_MEM_FREE, &syscall_mem_free, 2); > > > > syscall_register(SYSCALL_PM_GET_PID, (void*) &syscall_pm_get_pid, > > 0); diff --git a/src/kernel2/src/syscalls/mem.c > > b/src/kernel2/src/syscalls/mem.c index bd41073..91457da 100644 > > --- a/src/kernel2/src/syscalls/mem.c > > +++ b/src/kernel2/src/syscalls/mem.c > > @@ -74,6 +74,39 @@ vaddr_t syscall_mem_allocate(size_t bytes, > > syscall_arg_t flags, paddr_t* phys) } > > > > /** > > + * Einen Speicherblock an bekannter physischer Adresse mappen. > > + * > > + * @param bytes Groesse des Speicherblocks > > + * @param position Physische Adresse des Speicherblocks > > + * @param flags Unbenutzt > > + * > > + * @return Virtuelle Adresse des Blocks > > + * > > + * --- TODO laut Mail von Freaky --- > > + * Hm k??nnten wir hier vielleicht noch irgendwas einbauen um sicher zu > > Sind hier meine oder deine oder gar keine Umlaute kaputt? ;-) Die von git send-email, im Original sind sie richtig. Weißt du zufällig wie man dem erklärt, er soll die Mail als UTF-8 schicken? From toni at tyndur.org Sun Jan 18 12:15:09 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sun, 18 Jan 2009 12:15:09 +0100 Subject: [tyndur-devel] [Lost] [PATCH v2 08/10] kernel2: Syscall mem_allocate_physical In-Reply-To: <200901181215.00064@kevin-wolf.de> References: <1229813356-4252-1-git-send-email-kevin@tyndur.org> <1229813356-4252-9-git-send-email-kevin@tyndur.org> <20090118162202.GG10425@einstein.produktiv.lan> <200901181215.00064@kevin-wolf.de> Message-ID: <20090118111509.GB25571@einstein.produktiv.lan> On Sun, Jan 18 12:14, Kevin Wolf wrote: > Die von git send-email, im Original sind sie richtig. Weißt du zufällig wie > man dem erklärt, er soll die Mail als UTF-8 schicken? Ah, okay. Vielleicht hilft dir das weiter: http://blogs.liblime.com/developers/2008/11/19/git-config-change-utf-8/ -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 197 bytes Beschreibung: nicht verfügbar URL : From mail at kevin-wolf.de Sun Jan 18 12:21:45 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sun, 18 Jan 2009 12:21:45 +0100 Subject: [tyndur-devel] [PATCH] servmgr: RPC-Interface benutzbar machen In-Reply-To: <1232303755-28395-2-git-send-email-toni@tyndur.org> References: <1232303755-28395-1-git-send-email-toni@tyndur.org> <1232303755-28395-2-git-send-email-toni@tyndur.org> Message-ID: <497310C9.6070206@kevin-wolf.de> Antoine Kaufmann schrieb: > ! libc: Der Servicename wird in servmgr_need jetzt nullterminiert > versendet... > ! servmgr: ... und servmgr prueft jetzt sogar das richtige Byte um zu > pruefen ob die Daten nulltermiert sind. ;-) > --- > src/modules/lib/servmgr.c | 4 ++-- > src/modules/servmgr/rpcif.c | 4 ++-- > 2 files changed, 4 insertions(+), 4 deletions(-) > > diff --git a/src/modules/lib/servmgr.c b/src/modules/lib/servmgr.c > index 56fb700..47a295b 100644 > --- a/src/modules/lib/servmgr.c > +++ b/src/modules/lib/servmgr.c > @@ -1,5 +1,5 @@ > /* > - * Copyright (c) 2008 The tyndur Project. All rights reserved. > + * Copyright (c) 2008-2009 The tyndur Project. All rights reserved. > * > * This code is derived from software contributed to the tyndur Project > * by Antoine Kaufmann. > @@ -43,7 +43,7 @@ static pid_t servmgr_pid(void); > > bool servmgr_need(const char* service_name) > { > - return rpc_get_dword(servmgr_pid(), "NEEDSERV", strlen(service_name), > + return rpc_get_dword(servmgr_pid(), "NEEDSERV", strlen(service_name) + 1, > (char*) service_name); > } > > diff --git a/src/modules/servmgr/rpcif.c b/src/modules/servmgr/rpcif.c > index eda7a48..66c1a66 100644 > --- a/src/modules/servmgr/rpcif.c > +++ b/src/modules/servmgr/rpcif.c > @@ -1,5 +1,5 @@ > /* > - * Copyright (c) 2008 The tyndur Project. All rights reserved. > + * Copyright (c) 2008-2009 The tyndur Project. All rights reserved. > * > * This code is derived from software contributed to the tyndur Project > * by Antoine Kaufmann. > @@ -58,7 +58,7 @@ static void rpc_needserv(pid_t pid, dword cid, size_t data_size, void* data) > bool result; > > // Pruefen ob der Name nullterminiert ist > - if (name[data_size] != 0) { > + if (name[data_size - 1] != 0) { Underflows sind auch nicht viel besser als Overflows. ;-) Also lieber (data_size > 0) && (name[data_size - 1] != 0) Ansonsten kann das rein. From mail at kevin-wolf.de Sun Jan 18 12:28:19 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sun, 18 Jan 2009 12:28:19 +0100 Subject: [tyndur-devel] [PATCH] cdi: Wenn PCI-Funktionen benutzt werden, auf PCI warten In-Reply-To: <1232303755-28395-3-git-send-email-toni@tyndur.org> References: <1232303755-28395-1-git-send-email-toni@tyndur.org> <1232303755-28395-3-git-send-email-toni@tyndur.org> Message-ID: <49731253.9060000@kevin-wolf.de> Antoine Kaufmann schrieb: > ! cdi: Sicherstellen dass PCI laeuft, bevor versucht wird die Geraete > einzulesen. Ack. From mail at kevin-wolf.de Sun Jan 18 12:35:11 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sun, 18 Jan 2009 12:35:11 +0100 Subject: [tyndur-devel] [PATCH] pci: Klasse und Revision richtig einlesen In-Reply-To: <1232303755-28395-4-git-send-email-toni@tyndur.org> References: <1232303755-28395-1-git-send-email-toni@tyndur.org> <1232303755-28395-4-git-send-email-toni@tyndur.org> Message-ID: <497313EF.10205@kevin-wolf.de> Antoine Kaufmann schrieb: > ! pci: Richtigen Offset fuer Klasse eingetragen, dann funktioniert das > auch wie erwartet. > ! pci: Klasse und Revision sind jeweils nur ein Word und kein DWord In meiner Spezifikation hat der Class Code 48 Bit und fängt bei 0x09 an. Sicher, daß der Code nicht nur woanders falsch interpretiert wird? Die Revision sollte aber tatsächlich kein ganzes dword, sondern nur Byte sein. From toni at tyndur.org Tue Jan 20 22:09:40 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Tue, 20 Jan 2009 22:09:40 +0100 Subject: [tyndur-devel] [PATCH] buildmk.sh: qemu auch konfigurierbar machen Message-ID: <1232485780-11237-1-git-send-email-toni@tyndur.org> * buildmk.sh: qemu auch ueber config.sh/myconf.sh konfigurierbar machen --- buildmk.sh | 4 ++-- config.sh | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/buildmk.sh b/buildmk.sh index 4b40c1b..94453ec 100644 --- a/buildmk.sh +++ b/buildmk.sh @@ -247,10 +247,10 @@ image-hd: updateroot build/scripts/image_hd test-qemu: image-floppy - qemu -serial stdio -fda build/images/floppy.img -boot a -net user -net nic,model=rtl8139 | tee qemu-serial.log + $LOST_TOOLS_QEMU -serial stdio -fda build/images/floppy.img -boot a -net user -net nic,model=rtl8139 | tee qemu-serial.log test-qemu-hd: image-hd - qemu -serial stdio -hda build/images/hd.img -net user -net nic,model=rtl8139 | tee qemu-serial.log + $LOST_TOOLS_QEMU -serial stdio -hda build/images/hd.img -net user -net nic,model=rtl8139 | tee qemu-serial.log test-bochs: image-floppy bochs -f bochs.config diff --git a/config.sh b/config.sh index ec34f7f..a84916c 100644 --- a/config.sh +++ b/config.sh @@ -5,6 +5,7 @@ LOST_TOOLS_PPC=fpc LOST_GRUB_STAGESDIR=/boot/grub LOST_TOOLS_GRUB=grub LOST_TOOLS_MKE2FS=/sbin/mke2fs +LOST_TOOLS_QEMU=qemu [ -f $LOST_BUILDMK_ROOT/myconf.sh ] && source $LOST_BUILDMK_ROOT/myconf.sh -- 1.6.0.6 From toni at tyndur.org Fri Jan 30 03:11:46 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Fri, 30 Jan 2009 03:11:46 +0100 Subject: [tyndur-devel] PCI-Fixes In-Reply-To: <1232303755-28395-1-git-send-email-toni@tyndur.org> References: <1232303755-28395-1-git-send-email-toni@tyndur.org> Message-ID: <1233281509-19975-1-git-send-email-toni@tyndur.org> Noch ein Versuch mit dem Auslesen der Klasse von PCI-Geraeten. Ich habe Klasse, Subklasse und Interface jetzt in einzelne Member aufgeteilt, damit ist sofort klar was wo gefunden werden kann. From toni at tyndur.org Fri Jan 30 03:11:47 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Fri, 30 Jan 2009 03:11:47 +0100 Subject: [tyndur-devel] [PATCH] pci: Klasse und Revision richtig einlesen In-Reply-To: <1232303755-28395-1-git-send-email-toni@tyndur.org> References: <1232303755-28395-1-git-send-email-toni@tyndur.org> Message-ID: <1233281509-19975-2-git-send-email-toni@tyndur.org> ! pci: Revision ist nur ein Byte und kein DWord ! pci: Roher Classcode in 3 einzelne Felder in der PCI-Struktur aufgespalten (class, subclass, interface). --- src/modules/include/pci.h | 8 +++++--- src/modules/pci/include/pcihw.h | 39 ++++++++++++++++++++++++++++++++++++++- src/modules/pci/pcihw.c | 10 +++++++--- 3 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/modules/include/pci.h b/src/modules/include/pci.h index e0b15ca..9bb4a9c 100644 --- a/src/modules/include/pci.h +++ b/src/modules/include/pci.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007 The tyndur Project. All rights reserved. + * Copyright (c) 2007-2009 The tyndur Project. All rights reserved. * * This code is derived from software contributed to the tyndur Project * by Kevin Wolf. @@ -51,8 +51,10 @@ struct pci_device { word device_id; byte rev_id; byte irq; - - dword class_id; + + byte class_id; + byte subclass_id; + byte interface_id; list_t* resources; } __attribute__ ((packed)); diff --git a/src/modules/pci/include/pcihw.h b/src/modules/pci/include/pcihw.h index b2579ad..f423660 100644 --- a/src/modules/pci/include/pcihw.h +++ b/src/modules/pci/include/pcihw.h @@ -1,3 +1,38 @@ +/* + * Copyright (c) 2007-2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #ifndef _PCI_HW_ #define _PCI_HW_ @@ -9,7 +44,9 @@ #define PCI_COMMAND 0x04 #define PCI_STATUS 0x06 #define PCI_REVISION 0x08 -#define PCI_CLASS 0x09 +#define PCI_CLASS 0x0B +#define PCI_SUBCLASS 0x0A +#define PCI_INTERFACE 0x09 #define PCI_HEADERTYPE 0x0E #define PCI_BAR0 0x10 #define PCI_INTERRUPT 0x3C diff --git a/src/modules/pci/pcihw.c b/src/modules/pci/pcihw.c index 4013617..536ad74 100644 --- a/src/modules/pci/pcihw.c +++ b/src/modules/pci/pcihw.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007 The tyndur Project. All rights reserved. + * Copyright (c) 2007-2009 The tyndur Project. All rights reserved. * * This code is derived from software contributed to the tyndur Project * by Kevin Wolf. @@ -213,8 +213,12 @@ struct pci_device pci_get_device(dword bus, dword device, dword func) .vendor_id = pci_config_read_word(bus, device, func, PCI_VENDOR_ID), .device_id = pci_config_read_word(bus, device, func, PCI_DEVICE_ID), - .class_id = pci_config_read_dword(bus, device, func, PCI_CLASS), - .rev_id = pci_config_read_dword(bus, device, func, PCI_REVISION), + + .class_id = pci_config_read_byte(bus, device, func, PCI_CLASS), + .subclass_id = pci_config_read_byte(bus, device, func, PCI_SUBCLASS), + .interface_id = pci_config_read_byte(bus, device, func, PCI_INTERFACE), + + .rev_id = pci_config_read_byte(bus, device, func, PCI_REVISION), .irq = pci_config_read_byte(bus, device, func, PCI_INTERRUPT), .resources = NULL -- 1.6.0.6 From toni at tyndur.org Fri Jan 30 03:11:48 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Fri, 30 Jan 2009 03:11:48 +0100 Subject: [tyndur-devel] [PATCH] pci: Info an Aenderungen beim Auslesen der Klasse agepasst In-Reply-To: <1232303755-28395-1-git-send-email-toni@tyndur.org> References: <1232303755-28395-1-git-send-email-toni@tyndur.org> Message-ID: <1233281509-19975-3-git-send-email-toni@tyndur.org> * pci: pci:/info zeigt jetzt subclass und interface separat an --- src/modules/pci/pciscan.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/modules/pci/pciscan.c b/src/modules/pci/pciscan.c index 2ea4c7e..c82aa28 100644 --- a/src/modules/pci/pciscan.c +++ b/src/modules/pci/pciscan.c @@ -225,14 +225,17 @@ char* pciinfo() old_buffer = buffer; asprintf( &buffer, - "%s%x:%x:%x -- Hersteller %x, Geraete-ID %x [Klasse %x]\n", + "%s%x:%x:%x -- Hersteller %x, Geraete-ID %x [Klasse %x Sub %x " + "Int %x]\n", old_buffer ? old_buffer : "", dev->bus, dev->device, dev->function, dev->vendor_id, dev->device_id, - dev->class_id + dev->class_id, + dev->subclass_id, + dev->interface_id ); free(old_buffer); -- 1.6.0.6 From toni at tyndur.org Fri Jan 30 03:11:49 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Fri, 30 Jan 2009 03:11:49 +0100 Subject: [tyndur-devel] [PATCH] cdi/core: subclass und interface-Feld fuer pci_device-Struktur In-Reply-To: <1232303755-28395-1-git-send-email-toni@tyndur.org> References: <1232303755-28395-1-git-send-email-toni@tyndur.org> Message-ID: <1233281509-19975-4-git-send-email-toni@tyndur.org> * cdi/core: Einzelne Member in der pci_device-Struktur für die Subclass-ID und die Interface-ID. --- src/modules/cdi/include/cdi/pci.h | 6 +++++- src/modules/cdi/lib/pci.c | 2 ++ 2 files changed, 7 insertions(+), 1 deletions(-) diff --git a/src/modules/cdi/include/cdi/pci.h b/src/modules/cdi/include/cdi/pci.h index af1a79c..8a9cc18 100644 --- a/src/modules/cdi/include/cdi/pci.h +++ b/src/modules/cdi/include/cdi/pci.h @@ -23,7 +23,11 @@ struct cdi_pci_device { uint16_t vendor_id; uint16_t device_id; - uint16_t class_id; + + uint8_t class_id; + uint8_t subclass_id; + uint8_t interface_id; + uint8_t rev_id; uint8_t irq; diff --git a/src/modules/cdi/lib/pci.c b/src/modules/cdi/lib/pci.c index 90df6d0..e14f48a 100644 --- a/src/modules/cdi/lib/pci.c +++ b/src/modules/cdi/lib/pci.c @@ -47,6 +47,8 @@ static struct cdi_pci_device* read_pci_device(char* filename) cdi_device->vendor_id = device.vendor_id; cdi_device->device_id = device.device_id; cdi_device->class_id = device.class_id; + cdi_device->subclass_id = device.subclass_id; + cdi_device->interface_id = device.interface_id; cdi_device->rev_id = device.rev_id; cdi_device->irq = device.irq; cdi_device->resources = cdi_list_create(); -- 1.6.0.6 From toni at tyndur.org Fri Jan 30 03:15:57 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Fri, 30 Jan 2009 03:15:57 +0100 Subject: [tyndur-devel] Multibyte Message-ID: <1233281759-20044-1-git-send-email-toni@tyndur.org> Ich habe hier den wctomb()-Patch noch in zwei einzelne aufgeteilt. From toni at tyndur.org Fri Jan 30 03:15:58 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Fri, 30 Jan 2009 03:15:58 +0100 Subject: [tyndur-devel] [PATCH] libc: In multibyte.c irrefuehrende Makro korrigiert In-Reply-To: <1233281759-20044-1-git-send-email-toni@tyndur.org> References: <1233281759-20044-1-git-send-email-toni@tyndur.org> Message-ID: <1233281759-20044-2-git-send-email-toni@tyndur.org> ! libc: Das Makro get_lower_bits in multibyte.c tut jetzt auch was der Name vermuten laesst. --- src/lib/string/multibyte.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/string/multibyte.c b/src/lib/string/multibyte.c index 6bd168e..b6fa378 100644 --- a/src/lib/string/multibyte.c +++ b/src/lib/string/multibyte.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008 The tyndur Project. All rights reserved. + * Copyright (c) 2008-2009 The tyndur Project. All rights reserved. * * This code is derived from software contributed to the tyndur Project * by Antoine Kaufmann. @@ -60,7 +60,7 @@ #define VAL_3 (BIT(7) | BIT(6) | BIT(5)) #define VAL_4 (BIT(7) | BIT(6) | BIT(5) | BIT(6)) -#define get_lower_bits(v, x) (v & (BIT(x + 1) - 1)) +#define get_lower_bits(v, x) (v & (BIT(x) - 1)) /** @@ -138,7 +138,7 @@ int mbtowc(wchar_t* wc, const char* s, size_t slen) } // Erstes Zeichen wird separat behandelt - bitpos = (len == 1 ? 7 : 7 - len); + bitpos = 7 - (len - 1); *wc = get_lower_bits(s[0], bitpos); // Die anderen Zeichen sind alle gleich -- 1.6.0.6 From toni at tyndur.org Fri Jan 30 03:15:59 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Fri, 30 Jan 2009 03:15:59 +0100 Subject: [tyndur-devel] [PATCH] libc: wctomb() In-Reply-To: <1233281759-20044-1-git-send-email-toni@tyndur.org> References: <1233281759-20044-1-git-send-email-toni@tyndur.org> Message-ID: <1233281759-20044-3-git-send-email-toni@tyndur.org> + libc: wctomb() zum Umwandeln eines wchars in einen Multibyte-String --- src/include/stdlib.h | 21 ++++++++++++++++++++- src/lib/string/multibyte.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletions(-) diff --git a/src/include/stdlib.h b/src/include/stdlib.h index bbabf8a..0fa6549 100644 --- a/src/include/stdlib.h +++ b/src/include/stdlib.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006 The tyndur Project. All rights reserved. + * Copyright (c) 2006-2009 The tyndur Project. All rights reserved. * * This code is derived from software contributed to the tyndur Project * by Antoine Kaufmann. @@ -107,6 +107,25 @@ int mblen(const char* s, size_t slen); */ int mbtowc(wchar_t* wc, const char* s, size_t len); +/** + * Einen wchar in ein Multibyte-Zeichen umwandeln. Der Aufrufer muss + * garantieren dass in buf mindestens MB_CUR_MAX Bytes verfuegbar sind. + * + * Falls buf == NULL uebergeben wird, soll der interne "shift state" + * zurueckgesetzt werden und != 0 zurueckgegeben werden, falls die aktuelle + * Kodierung sowas hat. Solange wir nur UTF-8 benutzen brauchen wir uns aber + * darum nicht zu kuemmern. + * + * @param buf Puffer in dem das Multibyte-Zeichen abgelegt wird. Dabei koennen + * bis zu MB_CUR_MAX Bytes geschrieben werden. + * @param wc Der umzuwandelnde wchar + * + * @return Bei Erfolg wir die Anzahl der in buf geschrieben Bytes + * zurueckgegeben, im Fehlerfall -1. Falls buf == NULL war, wird 0 + * zurueckgegeben. + */ +int wctomb(char* buf, wchar_t wc); + /** * Seed fuer Zufallszahlgenerator setzen diff --git a/src/lib/string/multibyte.c b/src/lib/string/multibyte.c index b6fa378..68ef073 100644 --- a/src/lib/string/multibyte.c +++ b/src/lib/string/multibyte.c @@ -150,3 +150,47 @@ int mbtowc(wchar_t* wc, const char* s, size_t slen) return len; } +/** + * Einen wchar in ein Multibyte-Zeichen umwandeln. Der Aufrufer muss + * garantieren dass in buf mindestens MB_CUR_MAX Bytes verfuegbar sind. + * + * Falls buf == NULL uebergeben wird, soll der interne "shift state" + * zurueckgesetzt werden und != 0 zurueckgegeben werden, falls die aktuelle + * Kodierung sowas hat. Solange wir nur UTF-8 benutzen brauchen wir uns aber + * darum nicht zu kuemmern. + * + * @param buf Puffer in dem das Multibyte-Zeichen abgelegt wird. Dabei koennen + * bis zu MB_CUR_MAX Bytes geschrieben werden. + * @param wc Der umzuwandelnde wchar + * + * @return Bei Erfolg wir die Anzahl der in buf geschrieben Bytes + * zurueckgegeben, im Fehlerfall -1. Falls buf == NULL war, wird 0 + * zurueckgegeben. + */ +int wctomb(char* buf, wchar_t wc) +{ + if (buf == NULL) { + return 0; + } + + if (get_lower_bits(wc, 7) == wc) { + buf[0] = get_lower_bits(wc, 7) | VAL_1; + return 1; + } else if (get_lower_bits(wc, 11) == wc) { + buf[0] = get_lower_bits((wc >> 6), 5) | VAL_2; + buf[1] = get_lower_bits((wc >> 0), 6) | BIT(7); + return 2; + } else if (get_lower_bits(wc, 16) == wc) { + buf[0] = get_lower_bits((wc >> 12), 4) | VAL_3; + buf[1] = get_lower_bits((wc >> 6), 6) | BIT(7); + buf[2] = get_lower_bits((wc >> 0), 6) | BIT(7); + return 3; + } else { + buf[0] = get_lower_bits((wc >> 18), 3) | VAL_4; + buf[1] = get_lower_bits((wc >> 12), 6) | BIT(7); + buf[2] = get_lower_bits((wc >> 6), 6) | BIT(7); + buf[3] = get_lower_bits((wc >> 0), 6) | BIT(7); + return 4; + } +} + -- 1.6.0.6 From mail at kevin-wolf.de Sat Jan 31 13:39:35 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sat, 31 Jan 2009 13:39:35 +0100 Subject: [tyndur-devel] [PATCH] buildmk.sh: qemu auch konfigurierbar machen In-Reply-To: <1232485780-11237-1-git-send-email-toni@tyndur.org> References: <1232485780-11237-1-git-send-email-toni@tyndur.org> Message-ID: <200901311339.35813@kevin-wolf.de> Am Dienstag, 20. Januar 2009 22:09 schrieb Antoine Kaufmann: > * buildmk.sh: qemu auch ueber config.sh/myconf.sh konfigurierbar machen > --- > buildmk.sh | 4 ++-- > config.sh | 1 + > 2 files changed, 3 insertions(+), 2 deletions(-) Sieht gut aus. From mail at kevin-wolf.de Sat Jan 31 13:46:52 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sat, 31 Jan 2009 13:46:52 +0100 Subject: [tyndur-devel] [PATCH] pci: Klasse und Revision richtig einlesen In-Reply-To: <1233281509-19975-2-git-send-email-toni@tyndur.org> References: <1232303755-28395-1-git-send-email-toni@tyndur.org> <1233281509-19975-2-git-send-email-toni@tyndur.org> Message-ID: <200901311346.52695@kevin-wolf.de> Am Freitag, 30. Januar 2009 03:11 schrieb Antoine Kaufmann: > ! pci: Revision ist nur ein Byte und kein DWord > ! pci: Roher Classcode in 3 einzelne Felder in der PCI-Struktur > aufgespalten (class, subclass, interface). Letzteres ist kein Fix, sondern einfach eine Änderung. Eine ABI-Änderung noch dazu, also kann das so nicht in die 0.2.1 gehen. Wenn du vorhast, daß es dort reingeht, brauchst du noch ein Byte Padding an der richtigen Stelle (und ob die Reihenfolge richtig ist, habe ich noch nicht geschaut). From mail at kevin-wolf.de Sat Jan 31 13:48:46 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sat, 31 Jan 2009 13:48:46 +0100 Subject: [tyndur-devel] [PATCH] pci: Info an Aenderungen beim Auslesen der Klasse agepasst In-Reply-To: <1233281509-19975-3-git-send-email-toni@tyndur.org> References: <1232303755-28395-1-git-send-email-toni@tyndur.org> <1233281509-19975-3-git-send-email-toni@tyndur.org> Message-ID: <200901311348.46777@kevin-wolf.de> Am Freitag, 30. Januar 2009 03:11 schrieb Antoine Kaufmann: > * pci: pci:/info zeigt jetzt subclass und interface separat an Das gehört zum anderen PCI-Patch mit rein, wenn zwischenzeitlich nichts kaputtgehen soll. Sieht ansonsten gut aus, muß aber natürlich auf den anderen Patch warten. From mail at kevin-wolf.de Sat Jan 31 13:50:18 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sat, 31 Jan 2009 13:50:18 +0100 Subject: [tyndur-devel] [PATCH] cdi/core: subclass und interface-Feld fuer pci_device-Struktur In-Reply-To: <1233281509-19975-4-git-send-email-toni@tyndur.org> References: <1232303755-28395-1-git-send-email-toni@tyndur.org> <1233281509-19975-4-git-send-email-toni@tyndur.org> Message-ID: <200901311350.19059@kevin-wolf.de> Am Freitag, 30. Januar 2009 03:11 schrieb Antoine Kaufmann: > * cdi/core: Einzelne Member in der pci_device-Struktur für die > Subclass-ID und die Interface-ID. Aus meiner Sicht in Ordnung. Aber vielleicht sollten Janosch und Mathias noch was dazu sagen. > --- > src/modules/cdi/include/cdi/pci.h | 6 +++++- > src/modules/cdi/lib/pci.c | 2 ++ > 2 files changed, 7 insertions(+), 1 deletions(-) > > diff --git a/src/modules/cdi/include/cdi/pci.h > b/src/modules/cdi/include/cdi/pci.h index af1a79c..8a9cc18 100644 > --- a/src/modules/cdi/include/cdi/pci.h > +++ b/src/modules/cdi/include/cdi/pci.h > @@ -23,7 +23,11 @@ struct cdi_pci_device { > > uint16_t vendor_id; > uint16_t device_id; > - uint16_t class_id; > + > + uint8_t class_id; > + uint8_t subclass_id; > + uint8_t interface_id; > + > uint8_t rev_id; > > uint8_t irq; > diff --git a/src/modules/cdi/lib/pci.c b/src/modules/cdi/lib/pci.c > index 90df6d0..e14f48a 100644 > --- a/src/modules/cdi/lib/pci.c > +++ b/src/modules/cdi/lib/pci.c > @@ -47,6 +47,8 @@ static struct cdi_pci_device* read_pci_device(char* > filename) cdi_device->vendor_id = device.vendor_id; > cdi_device->device_id = device.device_id; > cdi_device->class_id = device.class_id; > + cdi_device->subclass_id = device.subclass_id; > + cdi_device->interface_id = device.interface_id; > cdi_device->rev_id = device.rev_id; > cdi_device->irq = device.irq; > cdi_device->resources = cdi_list_create(); From mail at kevin-wolf.de Sat Jan 31 13:53:40 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sat, 31 Jan 2009 13:53:40 +0100 Subject: [tyndur-devel] [PATCH] libc: In multibyte.c irrefuehrende Makro korrigiert In-Reply-To: <1233281759-20044-2-git-send-email-toni@tyndur.org> References: <1233281759-20044-1-git-send-email-toni@tyndur.org> <1233281759-20044-2-git-send-email-toni@tyndur.org> Message-ID: <200901311353.40429@kevin-wolf.de> Am Freitag, 30. Januar 2009 03:15 schrieb Antoine Kaufmann: > ! libc: Das Makro get_lower_bits in multibyte.c tut jetzt auch was der > Name vermuten laesst. Ack From mail at kevin-wolf.de Sat Jan 31 13:58:20 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sat, 31 Jan 2009 13:58:20 +0100 Subject: [tyndur-devel] [PATCH] libc: wctomb() In-Reply-To: <1233281759-20044-3-git-send-email-toni@tyndur.org> References: <1233281759-20044-1-git-send-email-toni@tyndur.org> <1233281759-20044-3-git-send-email-toni@tyndur.org> Message-ID: <200901311358.20343@kevin-wolf.de> Am Freitag, 30. Januar 2009 03:15 schrieb Antoine Kaufmann: > + libc: wctomb() zum Umwandeln eines wchars in einen Multibyte-String Ack From toni at tyndur.org Sat Jan 31 23:35:42 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 31 Jan 2009 23:35:42 +0100 Subject: [tyndur-devel] [PATCH] pci: Klasse und Revision richtig einlesen In-Reply-To: <200901311346.52695@kevin-wolf.de> References: <200901311346.52695@kevin-wolf.de> Message-ID: <1233441342-2143-1-git-send-email-toni@tyndur.org> ! pci: Revision ist nur ein Byte und kein DWord * pci: Roher Classcode in 3 einzelne Felder in der PCI-Struktur aufgespalten (class, subclass, interface). * pci: pci:/info zeigt jetzt subclass und interface separat an --- src/modules/include/pci.h | 11 ++++++++--- src/modules/pci/include/pcihw.h | 39 ++++++++++++++++++++++++++++++++++++++- src/modules/pci/pcihw.c | 10 +++++++--- src/modules/pci/pciscan.c | 7 +++++-- 4 files changed, 58 insertions(+), 9 deletions(-) diff --git a/src/modules/include/pci.h b/src/modules/include/pci.h index e0b15ca..ca2f1ec 100644 --- a/src/modules/include/pci.h +++ b/src/modules/include/pci.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007 The tyndur Project. All rights reserved. + * Copyright (c) 2007-2009 The tyndur Project. All rights reserved. * * This code is derived from software contributed to the tyndur Project * by Kevin Wolf. @@ -51,8 +51,13 @@ struct pci_device { word device_id; byte rev_id; byte irq; - - dword class_id; + + byte interface_id; + byte subclass_id; + byte class_id; + + /// XXX: Fuer Abwaertskompatibilitaet eingefuehrt + byte :8 ; list_t* resources; } __attribute__ ((packed)); diff --git a/src/modules/pci/include/pcihw.h b/src/modules/pci/include/pcihw.h index b2579ad..f423660 100644 --- a/src/modules/pci/include/pcihw.h +++ b/src/modules/pci/include/pcihw.h @@ -1,3 +1,38 @@ +/* + * Copyright (c) 2007-2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Kevin Wolf. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the tyndur Project + * and its contributors. + * 4. Neither the name of the tyndur Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #ifndef _PCI_HW_ #define _PCI_HW_ @@ -9,7 +44,9 @@ #define PCI_COMMAND 0x04 #define PCI_STATUS 0x06 #define PCI_REVISION 0x08 -#define PCI_CLASS 0x09 +#define PCI_CLASS 0x0B +#define PCI_SUBCLASS 0x0A +#define PCI_INTERFACE 0x09 #define PCI_HEADERTYPE 0x0E #define PCI_BAR0 0x10 #define PCI_INTERRUPT 0x3C diff --git a/src/modules/pci/pcihw.c b/src/modules/pci/pcihw.c index 4013617..536ad74 100644 --- a/src/modules/pci/pcihw.c +++ b/src/modules/pci/pcihw.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007 The tyndur Project. All rights reserved. + * Copyright (c) 2007-2009 The tyndur Project. All rights reserved. * * This code is derived from software contributed to the tyndur Project * by Kevin Wolf. @@ -213,8 +213,12 @@ struct pci_device pci_get_device(dword bus, dword device, dword func) .vendor_id = pci_config_read_word(bus, device, func, PCI_VENDOR_ID), .device_id = pci_config_read_word(bus, device, func, PCI_DEVICE_ID), - .class_id = pci_config_read_dword(bus, device, func, PCI_CLASS), - .rev_id = pci_config_read_dword(bus, device, func, PCI_REVISION), + + .class_id = pci_config_read_byte(bus, device, func, PCI_CLASS), + .subclass_id = pci_config_read_byte(bus, device, func, PCI_SUBCLASS), + .interface_id = pci_config_read_byte(bus, device, func, PCI_INTERFACE), + + .rev_id = pci_config_read_byte(bus, device, func, PCI_REVISION), .irq = pci_config_read_byte(bus, device, func, PCI_INTERRUPT), .resources = NULL diff --git a/src/modules/pci/pciscan.c b/src/modules/pci/pciscan.c index 2ea4c7e..c82aa28 100644 --- a/src/modules/pci/pciscan.c +++ b/src/modules/pci/pciscan.c @@ -225,14 +225,17 @@ char* pciinfo() old_buffer = buffer; asprintf( &buffer, - "%s%x:%x:%x -- Hersteller %x, Geraete-ID %x [Klasse %x]\n", + "%s%x:%x:%x -- Hersteller %x, Geraete-ID %x [Klasse %x Sub %x " + "Int %x]\n", old_buffer ? old_buffer : "", dev->bus, dev->device, dev->function, dev->vendor_id, dev->device_id, - dev->class_id + dev->class_id, + dev->subclass_id, + dev->interface_id ); free(old_buffer); -- 1.6.0.6 From toni at tyndur.org Sat Jan 31 23:36:29 2009 From: toni at tyndur.org (Antoine Kaufmann) Date: Sat, 31 Jan 2009 23:36:29 +0100 Subject: [tyndur-devel] [PATCH] init: Zwei moegliche Buffer-Overflows in RPCs gefixt Message-ID: <1233441389-2201-1-git-send-email-toni@tyndur.org> ! init: Buffer overflow in LOADELF und SERV_GET behoben --- src/modules/init/init.c | 17 ++++++++++++++++- 1 files changed, 16 insertions(+), 1 deletions(-) diff --git a/src/modules/init/init.c b/src/modules/init/init.c index 3931a4a..80e7af0 100644 --- a/src/modules/init/init.c +++ b/src/modules/init/init.c @@ -204,6 +204,11 @@ void rpc_service_get(pid_t pid, dword correlation_id, size_t data_size, void* da { int i; struct service_s* service; + + // Der Name muss nullterminiert sein + if (strnlen(data, data_size) == data_size) { + goto out_error; + } //5 Versuche einen Task zu finden for(i = 0; i < 5; i++) @@ -223,6 +228,7 @@ void rpc_service_get(pid_t pid, dword correlation_id, size_t data_size, void* da yield(); } +out_error: rpc_send_dword_response(pid, correlation_id, 0); } @@ -559,9 +565,18 @@ pid_t start_program(char* path, char* args, pid_t parent_pid) void rpc_loadelf(pid_t pid, dword correlation_id, size_t data_size, void* data) { - char* first_space = strchr(data, ' '); + char* first_space; pid_t new_pid; + // Wir erwarten einen Null-terminierten String + if (strnlen(data, data_size) == data_size) { + rpc_send_dword_response(pid, correlation_id, 0); + return; + } + + + first_space = strchr(data, ' '); + //Wenn kein leerschlag vorhanden ist, muessen keine Kommandozeilenargumente //abgetrennt werden. if (first_space == NULL) { -- 1.6.0.6 From mail at kevin-wolf.de Sat Jan 31 23:48:44 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sat, 31 Jan 2009 23:48:44 +0100 Subject: [tyndur-devel] [PATCH] init: Zwei moegliche Buffer-Overflows in RPCs gefixt In-Reply-To: <1233441389-2201-1-git-send-email-toni@tyndur.org> References: <1233441389-2201-1-git-send-email-toni@tyndur.org> Message-ID: <200901312348.44861@kevin-wolf.de> Am Samstag, 31. Januar 2009 23:36 schrieb Antoine Kaufmann: > ! init: Buffer overflow in LOADELF und SERV_GET behoben Ack From mail at kevin-wolf.de Sat Jan 31 23:51:35 2009 From: mail at kevin-wolf.de (Kevin Wolf) Date: Sat, 31 Jan 2009 23:51:35 +0100 Subject: [tyndur-devel] [PATCH] pci: Klasse und Revision richtig einlesen In-Reply-To: <1233441342-2143-1-git-send-email-toni@tyndur.org> References: <200901311346.52695@kevin-wolf.de> <1233441342-2143-1-git-send-email-toni@tyndur.org> Message-ID: <200901312351.36105@kevin-wolf.de> Am Samstag, 31. Januar 2009 23:35 schrieb Antoine Kaufmann: > ! pci: Revision ist nur ein Byte und kein DWord > * pci: Roher Classcode in 3 einzelne Felder in der PCI-Struktur > aufgespalten (class, subclass, interface). > * pci: pci:/info zeigt jetzt subclass und interface separat an Dürfte so stimmen.