/* * block_device.h * * Copyright (C) 2015 Aleksandar Andrejevic * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ #ifndef _BLOCK_DEVICE_H_ #define _BLOCK_DEVICE_H_ #include #include #include #include #define MAX_BLOCK_DEV_NAME 32 #define BLOCK_DEVICE_REMOVABLE_MEDIA (1 << 0) #define IOCTL_BLOCK_DEV_INFO 0xB0000000 #define IOCTL_BLOCK_DEV_MEDIA_INFO 0xB0000001 #define IOCTL_BLOCK_DEV_MEDIA_LOAD 0xB0000002 #define IOCTL_BLOCK_DEV_MEDIA_EJECT 0xB0000003 #ifndef BLOCK_DEVICE_TYPEDEF #define BLOCK_DEVICE_TYPEDEF typedef struct block_device block_device_t; #endif typedef dword_t (*block_dev_init_proc_t)(void); typedef dword_t (*block_dev_cleanup_proc_t)(void); typedef dword_t (*block_dev_read_proc_t)(block_device_t *device, void *buffer, qword_t offset, size_t length, size_t *bytes_read); typedef dword_t (*block_dev_write_proc_t)(block_device_t *device, const void *buffer, qword_t offset, size_t length, size_t *bytes_written); typedef dword_t (*block_dev_ioctl_proc_t)( block_device_t *device, dword_t control_code, const void *in_buffer, size_t in_length, void *out_buffer, size_t out_length ); typedef struct { list_entry_t list; dword_t mounted_devices; block_dev_init_proc_t init_proc; block_dev_cleanup_proc_t cleanup_proc; block_dev_read_proc_t read_proc; block_dev_write_proc_t write_proc; block_dev_ioctl_proc_t ioctl_proc; } block_dev_driver_t; struct block_device { list_entry_t list; dword_t flags; block_dev_driver_t *driver; char name[MAX_BLOCK_DEV_NAME]; qword_t capacity; resource_t resource; }; typedef struct { dword_t heads; dword_t tracks; dword_t sectors_per_track; dword_t bytes_per_sector; } block_dev_media_info_t; dword_t register_block_dev_driver(block_dev_driver_t *driver); dword_t unregister_block_dev_driver(block_dev_driver_t *driver); block_device_t *get_block_device(const char *name); dword_t register_block_device(block_device_t *device); dword_t unregister_block_device(block_device_t *device); dword_t enum_block_devices(char *device_names, size_t *size); dword_t block_device_read(const char *name, void *buffer, qword_t offset, size_t length, size_t *bytes_read); dword_t block_device_write(const char *name, const void *buffer, qword_t offset, size_t length, size_t *bytes_written); dword_t block_device_ioctl(const char *name, dword_t control_code, const void *in_buffer, size_t in_length, void *out_buffer, size_t out_length); #endif