29typedef struct hdd_blkio_fs_driver_mount_info_
32} hdd_blkio_fs_driver_mount_info;
35static hdd_blkio_fs_driver_mount_info fs_driver_mount_info[BLKIO_MAX_VOLUMES];
37#define HDD_BLKIO_FS_DRIVER_MOUNT_INFO_MAX ((int)(sizeof(fs_driver_mount_info) / sizeof(fs_driver_mount_info[0])))
39static int _fs_lock_sema_id = -1;
41static int _fs_init_lock(
void)
49 if ((_fs_lock_sema_id = CreateSema(&sp)) < 0) {
56static void _fs_lock(
void)
58 WaitSema(_fs_lock_sema_id);
61static void _fs_unlock(
void)
63 SignalSema(_fs_lock_sema_id);
66static void fs_reset(
void)
68 if (_fs_lock_sema_id >= 0)
69 DeleteSema(_fs_lock_sema_id);
74static void hdd_blkio_fs_driver_initialize_all_mount_info(
void)
77 for (i = 0; i < HDD_BLKIO_FS_DRIVER_MOUNT_INFO_MAX; i += 1) {
78 fs_driver_mount_info[i].mounted_bd = NULL;
82static int hdd_blkio_fs_driver_find_mount_info_index_from_block_device(
const struct block_device *bd)
85 for (i = 0; i < HDD_BLKIO_FS_DRIVER_MOUNT_INFO_MAX; i += 1) {
86 if (fs_driver_mount_info[i].mounted_bd == bd) {
93static int hdd_blkio_fs_driver_find_mount_info_index_free(
void)
95 return hdd_blkio_fs_driver_find_mount_info_index_from_block_device(NULL);
98static struct block_device *hdd_blkio_fs_driver_get_mounted_bd_from_index(
int mount_info_index)
101 if (mount_info_index >= HDD_BLKIO_FS_DRIVER_MOUNT_INFO_MAX) {
104 mounted_bd = fs_driver_mount_info[mount_info_index].mounted_bd;
108static int hdd_blkio_fs_driver_mount_bd(
int mount_info_index,
struct block_device *bd)
110 fs_driver_mount_info[mount_info_index].mounted_bd = bd;
111 hddDevices[mount_info_index].status = 3;
113 if (bd->sectorSize != 512)
115 fs_driver_mount_info[mount_info_index].mounted_bd = NULL;
118 hddDevices[mount_info_index].status -= 1;
119 hddDevices[mount_info_index].totalLBA = bd->sectorCount;
120 hddDevices[mount_info_index].partitionMaxSize = apaGetPartitionMax(hddDevices[mount_info_index].totalLBA);
121 hddDevices[mount_info_index].status -= 1;
122 if (apaJournalRestore(mount_info_index) != 0)
124 fs_driver_mount_info[mount_info_index].mounted_bd = NULL;
128 if (apaGetFormat(mount_info_index, &hddDevices[mount_info_index].format) != 0)
130 hddDevices[mount_info_index].status -= 1;
132 if (hddDevices[mount_info_index].status != 0)
134 fs_driver_mount_info[mount_info_index].mounted_bd = NULL;
140static void hdd_blkio_fs_driver_unmount_bd(
int mount_info_index)
142 fs_driver_mount_info[mount_info_index].mounted_bd = NULL;
143 hddDevices[mount_info_index].status = 3;
148 int mount_info_index;
151 mount_info_index = hdd_blkio_fs_driver_find_mount_info_index_free();
152 if (mount_info_index != -1) {
153 if (hdd_blkio_fs_driver_mount_bd(mount_info_index, bd) == 0) {
162static void hdd_blkio_disconnect_bd(
struct block_device *bd)
164 int mount_info_index;
167 mount_info_index = hdd_blkio_fs_driver_find_mount_info_index_from_block_device(bd);
168 if (mount_info_index != -1) {
169 hdd_blkio_fs_driver_unmount_bd(mount_info_index);
177 .connect_bd = hdd_blkio_connect_bd,
178 .disconnect_bd = hdd_blkio_disconnect_bd,
191typedef struct vhdd_diskinfo_
198static vhdd_diskinfo_t hdd_blkio_vhdd_diskinfo[BLKIO_MAX_VOLUMES];
200static void hdd_blkio_vhdd_clear_slot(
int slot)
202 vhdd_diskinfo_t *diskinfo;
203 diskinfo = &hdd_blkio_vhdd_diskinfo[slot];
204 if (diskinfo->fd >= 0) {
205 iomanX_close(diskinfo->fd);
207 memset(diskinfo, 0,
sizeof(vhdd_diskinfo_t));
211static int hdd_blkio_vhdd_validate(
int slot,
int check_mounted)
213 vhdd_diskinfo_t *diskinfo;
215 if (slot > BLKIO_MAX_VOLUMES) {
219 diskinfo = &hdd_blkio_vhdd_diskinfo[slot];
222 if (diskinfo->fd < 0) {
229int hdd_blkio_vhdd_mount(
int slot,
const char *filename)
234 vhdd_diskinfo_t *diskinfo;
236 r = hdd_blkio_vhdd_validate(slot, 0);
241 diskinfo = &hdd_blkio_vhdd_diskinfo[slot];
243 fd = iomanX_open(filename, FIO_O_RDWR, 0);
251 disksize = iomanX_lseek64(fd, 0, FIO_SEEK_END);
252 diskinfo->sectorcount = disksize >> 9;
253 iomanX_lseek64(fd, 0, FIO_SEEK_SET);
257 hddDevices[slot].status = 3;
258 hddDevices[slot].status -= 1;
259 hddDevices[slot].totalLBA = diskinfo->sectorcount;
260 hddDevices[slot].partitionMaxSize = apaGetPartitionMax(hddDevices[slot].totalLBA);
261 hddDevices[slot].status -= 1;
262 if (apaJournalRestore(slot) != 0)
268 if (apaGetFormat(slot, &hddDevices[slot].format) != 0)
270 hddDevices[slot].status -= 1;
272 if (hddDevices[slot].status != 0)
281 hdd_blkio_vhdd_clear_slot(slot);
286int hdd_blkio_vhdd_umount(
int slot)
290 r = hdd_blkio_vhdd_validate(slot, 1);
295 hdd_blkio_vhdd_clear_slot(slot);
307 hdd_blkio_fs_driver_initialize_all_mount_info();
308 bdm_connect_fs(&g_fs);
313int blkIoDmaTransfer(
int device,
void *buf, u32 lba, u32 nsectors,
int dir)
318 mounted_bd = hdd_blkio_fs_driver_get_mounted_bd_from_index(device);
320 if (mounted_bd == NULL)
325 if (dir == BLKIO_DIR_READ)
327 return (mounted_bd->read(mounted_bd, lba, buf, nsectors) == nsectors) ? 0 : -1;
329 else if (dir == BLKIO_DIR_WRITE)
331 return (mounted_bd->write(mounted_bd, lba, buf, nsectors) == nsectors) ? 0 : -1;
333#elif defined(APA_USE_IOMANX)
336 vhdd_diskinfo_t *diskinfo;
338 r = hdd_blkio_vhdd_validate(device, 1);
342 diskinfo = &hdd_blkio_vhdd_diskinfo[device];
345 int sector_to_byte_count;
346 sector_to_byte_count = nsectors * 512;
347 iomanX_lseek64(diskinfo->fd, (s64)lba * (s64)512, FIO_SEEK_SET);
348 if (dir == BLKIO_DIR_READ)
350 return (iomanX_read(diskinfo->fd, buf, sector_to_byte_count) == sector_to_byte_count) ? 0 : -1;
352 else if (dir == BLKIO_DIR_WRITE)
354 return (iomanX_write(diskinfo->fd, buf, sector_to_byte_count) == sector_to_byte_count) ? 0 : -1;
368int blkIoIdle(
int device,
int period)
375int blkIoGetSceId(
int device,
void *data)
382int blkIoSmartReturnStatus(
int device)
388int blkIoSmartSaveAttr(
int device)
393 mounted_bd = hdd_blkio_fs_driver_get_mounted_bd_from_index(device);
395 if (mounted_bd == NULL)
400 mounted_bd->stop(mounted_bd);
407int blkIoFlushCache(
int device)
412 mounted_bd = hdd_blkio_fs_driver_get_mounted_bd_from_index(device);
414 if (mounted_bd == NULL)
419 mounted_bd->flush(mounted_bd);
426int blkIoIdleImmediate(
int device)