block_device.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * block_device.h
  3. *
  4. * Copyright (C) 2015 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as
  8. * published by the Free Software Foundation, either version 3 of the
  9. * License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef _BLOCK_DEVICE_H_
  20. #define _BLOCK_DEVICE_H_
  21. #include <common.h>
  22. #include <sync.h>
  23. #include <list.h>
  24. #include <cache.h>
  25. #define MAX_BLOCK_DEV_NAME 32
  26. #define BLOCK_DEVICE_REMOVABLE_MEDIA (1 << 0)
  27. #define IOCTL_BLOCK_DEV_INFO 0xB0000000
  28. #define IOCTL_BLOCK_DEV_MEDIA_INFO 0xB0000001
  29. #define IOCTL_BLOCK_DEV_MEDIA_LOAD 0xB0000002
  30. #define IOCTL_BLOCK_DEV_MEDIA_EJECT 0xB0000003
  31. #ifndef BLOCK_DEVICE_TYPEDEF
  32. #define BLOCK_DEVICE_TYPEDEF
  33. typedef struct block_device block_device_t;
  34. #endif
  35. typedef dword_t (*block_dev_init_proc_t)(void);
  36. typedef dword_t (*block_dev_cleanup_proc_t)(void);
  37. typedef dword_t (*block_dev_read_proc_t)(block_device_t *device, void *buffer, qword_t offset, size_t length, size_t *bytes_read);
  38. 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);
  39. typedef dword_t (*block_dev_ioctl_proc_t)(
  40. block_device_t *device,
  41. dword_t control_code,
  42. const void *in_buffer,
  43. size_t in_length,
  44. void *out_buffer,
  45. size_t out_length
  46. );
  47. typedef struct
  48. {
  49. list_entry_t list;
  50. dword_t mounted_devices;
  51. block_dev_init_proc_t init_proc;
  52. block_dev_cleanup_proc_t cleanup_proc;
  53. block_dev_read_proc_t read_proc;
  54. block_dev_write_proc_t write_proc;
  55. block_dev_ioctl_proc_t ioctl_proc;
  56. } block_dev_driver_t;
  57. struct block_device
  58. {
  59. list_entry_t list;
  60. dword_t flags;
  61. block_dev_driver_t *driver;
  62. char name[MAX_BLOCK_DEV_NAME];
  63. qword_t capacity;
  64. resource_t resource;
  65. };
  66. typedef struct
  67. {
  68. dword_t heads;
  69. dword_t tracks;
  70. dword_t sectors_per_track;
  71. dword_t bytes_per_sector;
  72. } block_dev_media_info_t;
  73. dword_t register_block_dev_driver(block_dev_driver_t *driver);
  74. dword_t unregister_block_dev_driver(block_dev_driver_t *driver);
  75. block_device_t *get_block_device(const char *name);
  76. dword_t register_block_device(block_device_t *device);
  77. dword_t unregister_block_device(block_device_t *device);
  78. dword_t enum_block_devices(char *device_names, size_t *size);
  79. dword_t block_device_read(const char *name, void *buffer, qword_t offset, size_t length, size_t *bytes_read);
  80. dword_t block_device_write(const char *name, const void *buffer, qword_t offset, size_t length, size_t *bytes_written);
  81. 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);
  82. #endif