00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef __FD32_BLOCK_H
00014 #define __FD32_BLOCK_H
00015
00016
00046 #define BLOCK_ERROR_CATEGORY 0x80800000
00047
00054 #define BLOCK_ERROR(sense, code) ((int) (BLOCK_ERROR_CATEGORY | (sense) | ((code) & 0xFFFF)))
00055
00058 #define BLOCK_GET_SENSE(value) ((value) & 0x003F0000)
00059
00062 #define BLOCK_IS_ERROR(value) (((value) & 0xFFC00000) == BLOCK_ERROR_CATEGORY)
00063
00067 enum BlockSenseKeys
00068 {
00069 BLOCK_SENSE_NONE = 0 << 16,
00070 BLOCK_SENSE_RECOVERED = 1 << 16,
00071 BLOCK_SENSE_NOTREADY = 2 << 16,
00072 BLOCK_SENSE_MEDIUM = 3 << 16,
00073 BLOCK_SENSE_HW = 4 << 16,
00074 BLOCK_SENSE_ILLREQ = 5 << 16,
00075 BLOCK_SENSE_ATTENTION = 6 << 16,
00076 BLOCK_SENSE_DATAPROT = 7 << 16,
00077 BLOCK_SENSE_BLANK = 8 << 16,
00078 BLOCK_SENSE_ABORTED = 11 << 16,
00079 BLOCK_SENSE_MISCOMPARE = 14 << 16
00080 };
00081
00082
00083 typedef unsigned long ssize_t;
00084
00103 enum BlockDeviceInfoFlags
00104 {
00105
00106 BLOCK_DEVICE_INFO_PARTID = 0xFF,
00107 BLOCK_DEVICE_INFO_TYPEMASK = 15 << 8,
00108 BLOCK_DEVICE_INFO_TGENERIC = 0 << 8,
00109 BLOCK_DEVICE_INFO_TACTIVE = 1 << 8,
00110 BLOCK_DEVICE_INFO_TLOGICAL = 2 << 8,
00111 BLOCK_DEVICE_INFO_TPRIMARY = 3 << 8,
00112 BLOCK_DEVICE_INFO_TFLOPPY = 4 << 8,
00113 BLOCK_DEVICE_INFO_TCDDVD = 5 << 8,
00114 BLOCK_DEVICE_INFO_REMOVABLE = 1 << 12,
00115 BLOCK_DEVICE_INFO_MEDIACHG = 1 << 13,
00116 BLOCK_DEVICE_INFO_WRITABLE = 1 << 14
00117 };
00118
00119
00121 typedef struct BlockDeviceInfo BlockDeviceInfo;
00122
00123
00130 struct BlockDeviceInfo
00131 {
00133 unsigned flags;
00135 uint32_t multiboot_id;
00136 };
00137
00138
00140 typedef struct BlockMediumInfo BlockMediumInfo;
00141
00142
00149 struct BlockMediumInfo
00150 {
00152 uint64_t blocks_count;
00154 unsigned block_bytes;
00155 };
00156
00157
00161 enum BlockReadWriteFlags
00162 {
00163 BLOCK_RW_NOCACHE = 1 << 0
00164 };
00165
00166
00170 #define BLOCK_OPERATIONS_TYPE 1
00171
00172
00174 typedef struct BlockOperations BlockOperations;
00175
00176
00181 struct BlockOperations
00182 {
00191 int (*request)(int function, ...);
00208 int (*open)(void *handle);
00228 int (*revalidate)(void *handle);
00239 int (*close)(void *handle);
00250 int (*get_device_info)(void *handle, BlockDeviceInfo *buf);
00262 int (*get_medium_info)(void *handle, BlockMediumInfo *buf);
00274 ssize_t (*read)(void *handle, void *buffer, uint64_t start, size_t count, int flags);
00286 ssize_t (*write)(void *handle, const void *buffer, uint64_t start, size_t count, int flags);
00298 int (*sync)(void *handle);
00306 int (*test_unit_ready)(void *handle);
00307 };
00308
00309
00310
00311
00323 #define REQ_GET_OPERATIONS 0
00324
00332 #define REQ_GET_REFERENCES 1
00333
00343 #define REQ_RELEASE 2
00344
00345
00349
00350
00351
00352
00354 static inline int req_get_operations(int (*r)(int function, ...), int type, void **operations)
00355 {
00356 return r(REQ_GET_OPERATIONS, type, operations);
00357 }
00358
00360 static inline int req_get_references(int (*r)(int function, ...))
00361 {
00362 return r(REQ_GET_REFERENCES);
00363 }
00364
00366 static inline int req_release(int (*r)(int function, ...), void *handle)
00367 {
00368 return r(REQ_RELEASE, handle);
00369 }
00370
00371 const char *block_enumerate (void **iterator);
00372 int block_get (const char *name, int type, void **operations, void **handle);
00373 int block_register (const char *name, int (*request)(int function, ...), void *handle);
00374 int block_unregister(const char *name);
00375
00376
00377
00378
00379 #endif