extmod/vfs: Rename BP_IOCTL_xxx constants to MP_BLOCKDEV_IOCTL_xxx.
Also rename SEC_COUNT to BLOCK_COUNT and SEC_SIZE to BLOCK_SIZE.
This commit is contained in:
parent
7c8fb27f38
commit
cfe1c5abf8
10
extmod/vfs.h
10
extmod/vfs.h
|
@ -45,11 +45,11 @@
|
||||||
#define MP_BLOCKDEV_FLAG_NO_FILESYSTEM (0x0008) // the block device has no filesystem on it
|
#define MP_BLOCKDEV_FLAG_NO_FILESYSTEM (0x0008) // the block device has no filesystem on it
|
||||||
|
|
||||||
// constants for block protocol ioctl
|
// constants for block protocol ioctl
|
||||||
#define BP_IOCTL_INIT (1)
|
#define MP_BLOCKDEV_IOCTL_INIT (1)
|
||||||
#define BP_IOCTL_DEINIT (2)
|
#define MP_BLOCKDEV_IOCTL_DEINIT (2)
|
||||||
#define BP_IOCTL_SYNC (3)
|
#define MP_BLOCKDEV_IOCTL_SYNC (3)
|
||||||
#define BP_IOCTL_SEC_COUNT (4)
|
#define MP_BLOCKDEV_IOCTL_BLOCK_COUNT (4)
|
||||||
#define BP_IOCTL_SEC_SIZE (5)
|
#define MP_BLOCKDEV_IOCTL_BLOCK_SIZE (5)
|
||||||
|
|
||||||
// At the moment the VFS protocol just has import_stat, but could be extended to other methods
|
// At the moment the VFS protocol just has import_stat, but could be extended to other methods
|
||||||
typedef struct _mp_vfs_proto_t {
|
typedef struct _mp_vfs_proto_t {
|
||||||
|
|
|
@ -119,20 +119,20 @@ mp_obj_t mp_vfs_blockdev_ioctl(mp_vfs_blockdev_t *self, uintptr_t cmd, uintptr_t
|
||||||
} else {
|
} else {
|
||||||
// Old protocol with sync and count
|
// Old protocol with sync and count
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case BP_IOCTL_SYNC:
|
case MP_BLOCKDEV_IOCTL_SYNC:
|
||||||
if (self->u.old.sync[0] != MP_OBJ_NULL) {
|
if (self->u.old.sync[0] != MP_OBJ_NULL) {
|
||||||
mp_call_method_n_kw(0, 0, self->u.old.sync);
|
mp_call_method_n_kw(0, 0, self->u.old.sync);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BP_IOCTL_SEC_COUNT:
|
case MP_BLOCKDEV_IOCTL_BLOCK_COUNT:
|
||||||
return mp_call_method_n_kw(0, 0, self->u.old.count);
|
return mp_call_method_n_kw(0, 0, self->u.old.count);
|
||||||
|
|
||||||
case BP_IOCTL_SEC_SIZE:
|
case MP_BLOCKDEV_IOCTL_BLOCK_SIZE:
|
||||||
// Old protocol has fixed sector size of 512 bytes
|
// Old protocol has fixed sector size of 512 bytes
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BP_IOCTL_INIT:
|
case MP_BLOCKDEV_IOCTL_INIT:
|
||||||
// Old protocol doesn't have init
|
// Old protocol doesn't have init
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ STATIC mp_obj_t fat_vfs_make_new(const mp_obj_type_t *type, size_t n_args, size_
|
||||||
|
|
||||||
// Initialise underlying block device
|
// Initialise underlying block device
|
||||||
vfs->blockdev.flags = MP_BLOCKDEV_FLAG_FREE_OBJ;
|
vfs->blockdev.flags = MP_BLOCKDEV_FLAG_FREE_OBJ;
|
||||||
vfs->blockdev.block_size = FF_MIN_SS; // default, will be populated by call to BP_IOCTL_SEC_SIZE
|
vfs->blockdev.block_size = FF_MIN_SS; // default, will be populated by call to MP_BLOCKDEV_IOCTL_BLOCK_SIZE
|
||||||
mp_vfs_blockdev_init(&vfs->blockdev, args[0]);
|
mp_vfs_blockdev_init(&vfs->blockdev, args[0]);
|
||||||
|
|
||||||
// mount the block device so the VFS methods can be used
|
// mount the block device so the VFS methods can be used
|
||||||
|
|
|
@ -113,10 +113,10 @@ DRESULT disk_ioctl (
|
||||||
|
|
||||||
// First part: call the relevant method of the underlying block device
|
// First part: call the relevant method of the underlying block device
|
||||||
static const uint8_t op_map[8] = {
|
static const uint8_t op_map[8] = {
|
||||||
[CTRL_SYNC] = BP_IOCTL_SYNC,
|
[CTRL_SYNC] = MP_BLOCKDEV_IOCTL_SYNC,
|
||||||
[GET_SECTOR_COUNT] = BP_IOCTL_SEC_COUNT,
|
[GET_SECTOR_COUNT] = MP_BLOCKDEV_IOCTL_BLOCK_COUNT,
|
||||||
[GET_SECTOR_SIZE] = BP_IOCTL_SEC_SIZE,
|
[GET_SECTOR_SIZE] = MP_BLOCKDEV_IOCTL_BLOCK_SIZE,
|
||||||
[IOCTL_INIT] = BP_IOCTL_INIT,
|
[IOCTL_INIT] = MP_BLOCKDEV_IOCTL_INIT,
|
||||||
};
|
};
|
||||||
uint8_t bp_op = op_map[cmd & 7];
|
uint8_t bp_op = op_map[cmd & 7];
|
||||||
mp_obj_t ret = mp_const_none;
|
mp_obj_t ret = mp_const_none;
|
||||||
|
|
|
@ -56,7 +56,7 @@ STATIC int MP_VFS_LFSx(dev_erase)(const struct LFSx_API(config) *c, LFSx_API(blo
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC int MP_VFS_LFSx(dev_sync)(const struct LFSx_API(config) *c) {
|
STATIC int MP_VFS_LFSx(dev_sync)(const struct LFSx_API(config) *c) {
|
||||||
return MP_VFS_LFSx(dev_ioctl)(c, BP_IOCTL_SYNC, 0, false);
|
return MP_VFS_LFSx(dev_ioctl)(c, MP_BLOCKDEV_IOCTL_SYNC, 0, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void MP_VFS_LFSx(init_config)(MP_OBJ_VFS_LFSx *self, mp_obj_t bdev, size_t read_size, size_t prog_size, size_t lookahead) {
|
STATIC void MP_VFS_LFSx(init_config)(MP_OBJ_VFS_LFSx *self, mp_obj_t bdev, size_t read_size, size_t prog_size, size_t lookahead) {
|
||||||
|
@ -73,9 +73,9 @@ STATIC void MP_VFS_LFSx(init_config)(MP_OBJ_VFS_LFSx *self, mp_obj_t bdev, size_
|
||||||
config->erase = MP_VFS_LFSx(dev_erase);
|
config->erase = MP_VFS_LFSx(dev_erase);
|
||||||
config->sync = MP_VFS_LFSx(dev_sync);
|
config->sync = MP_VFS_LFSx(dev_sync);
|
||||||
|
|
||||||
MP_VFS_LFSx(dev_ioctl)(config, BP_IOCTL_INIT, 0, false); // initialise block device
|
MP_VFS_LFSx(dev_ioctl)(config, MP_BLOCKDEV_IOCTL_INIT, 0, false); // initialise block device
|
||||||
int bs = MP_VFS_LFSx(dev_ioctl)(config, BP_IOCTL_SEC_SIZE, 0, true); // get block size
|
int bs = MP_VFS_LFSx(dev_ioctl)(config, MP_BLOCKDEV_IOCTL_BLOCK_SIZE, 0, true); // get block size
|
||||||
int bc = MP_VFS_LFSx(dev_ioctl)(config, BP_IOCTL_SEC_COUNT, 0, true); // get block count
|
int bc = MP_VFS_LFSx(dev_ioctl)(config, MP_BLOCKDEV_IOCTL_BLOCK_COUNT, 0, true); // get block count
|
||||||
self->blockdev.block_size = bs;
|
self->blockdev.block_size = bs;
|
||||||
|
|
||||||
config->read_size = read_size;
|
config->read_size = read_size;
|
||||||
|
|
|
@ -69,11 +69,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_writeblocks_obj, pyb_flash_writeblock
|
||||||
STATIC mp_obj_t pyb_flash_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) {
|
STATIC mp_obj_t pyb_flash_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) {
|
||||||
mp_int_t cmd = mp_obj_get_int(cmd_in);
|
mp_int_t cmd = mp_obj_get_int(cmd_in);
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case BP_IOCTL_INIT: return MP_OBJ_NEW_SMALL_INT(sflash_disk_init() != RES_OK);
|
case MP_BLOCKDEV_IOCTL_INIT: return MP_OBJ_NEW_SMALL_INT(sflash_disk_init() != RES_OK);
|
||||||
case BP_IOCTL_DEINIT: sflash_disk_flush(); return MP_OBJ_NEW_SMALL_INT(0);
|
case MP_BLOCKDEV_IOCTL_DEINIT: sflash_disk_flush(); return MP_OBJ_NEW_SMALL_INT(0);
|
||||||
case BP_IOCTL_SYNC: sflash_disk_flush(); return MP_OBJ_NEW_SMALL_INT(0);
|
case MP_BLOCKDEV_IOCTL_SYNC: sflash_disk_flush(); return MP_OBJ_NEW_SMALL_INT(0);
|
||||||
case BP_IOCTL_SEC_COUNT: return MP_OBJ_NEW_SMALL_INT(SFLASH_SECTOR_COUNT);
|
case MP_BLOCKDEV_IOCTL_BLOCK_COUNT: return MP_OBJ_NEW_SMALL_INT(SFLASH_SECTOR_COUNT);
|
||||||
case BP_IOCTL_SEC_SIZE: return MP_OBJ_NEW_SMALL_INT(SFLASH_SECTOR_SIZE);
|
case MP_BLOCKDEV_IOCTL_BLOCK_SIZE: return MP_OBJ_NEW_SMALL_INT(SFLASH_SECTOR_SIZE);
|
||||||
default: return mp_const_none;
|
default: return mp_const_none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -184,16 +184,16 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_sd_writeblocks_obj, pyb_sd_writeblocks);
|
||||||
STATIC mp_obj_t pyb_sd_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) {
|
STATIC mp_obj_t pyb_sd_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) {
|
||||||
mp_int_t cmd = mp_obj_get_int(cmd_in);
|
mp_int_t cmd = mp_obj_get_int(cmd_in);
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case BP_IOCTL_INIT:
|
case MP_BLOCKDEV_IOCTL_INIT:
|
||||||
case BP_IOCTL_DEINIT:
|
case MP_BLOCKDEV_IOCTL_DEINIT:
|
||||||
case BP_IOCTL_SYNC:
|
case MP_BLOCKDEV_IOCTL_SYNC:
|
||||||
// nothing to do
|
// nothing to do
|
||||||
return MP_OBJ_NEW_SMALL_INT(0); // success
|
return MP_OBJ_NEW_SMALL_INT(0); // success
|
||||||
|
|
||||||
case BP_IOCTL_SEC_COUNT:
|
case MP_BLOCKDEV_IOCTL_BLOCK_COUNT:
|
||||||
return MP_OBJ_NEW_SMALL_INT(sd_disk_info.ulNofBlock * (sd_disk_info.ulBlockSize / 512));
|
return MP_OBJ_NEW_SMALL_INT(sd_disk_info.ulNofBlock * (sd_disk_info.ulBlockSize / 512));
|
||||||
|
|
||||||
case BP_IOCTL_SEC_SIZE:
|
case MP_BLOCKDEV_IOCTL_BLOCK_SIZE:
|
||||||
return MP_OBJ_NEW_SMALL_INT(SD_SECTOR_SIZE);
|
return MP_OBJ_NEW_SMALL_INT(SD_SECTOR_SIZE);
|
||||||
|
|
||||||
default: // unknown command
|
default: // unknown command
|
||||||
|
|
|
@ -173,11 +173,11 @@ STATIC mp_obj_t esp32_partition_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_
|
||||||
esp32_partition_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
esp32_partition_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||||
mp_int_t cmd = mp_obj_get_int(cmd_in);
|
mp_int_t cmd = mp_obj_get_int(cmd_in);
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case BP_IOCTL_INIT: return MP_OBJ_NEW_SMALL_INT(0);
|
case MP_BLOCKDEV_IOCTL_INIT: return MP_OBJ_NEW_SMALL_INT(0);
|
||||||
case BP_IOCTL_DEINIT: return MP_OBJ_NEW_SMALL_INT(0);
|
case MP_BLOCKDEV_IOCTL_DEINIT: return MP_OBJ_NEW_SMALL_INT(0);
|
||||||
case BP_IOCTL_SYNC: return MP_OBJ_NEW_SMALL_INT(0);
|
case MP_BLOCKDEV_IOCTL_SYNC: return MP_OBJ_NEW_SMALL_INT(0);
|
||||||
case BP_IOCTL_SEC_COUNT: return MP_OBJ_NEW_SMALL_INT(self->part->size / BLOCK_SIZE_BYTES);
|
case MP_BLOCKDEV_IOCTL_BLOCK_COUNT: return MP_OBJ_NEW_SMALL_INT(self->part->size / BLOCK_SIZE_BYTES);
|
||||||
case BP_IOCTL_SEC_SIZE: return MP_OBJ_NEW_SMALL_INT(BLOCK_SIZE_BYTES);
|
case MP_BLOCKDEV_IOCTL_BLOCK_SIZE: return MP_OBJ_NEW_SMALL_INT(BLOCK_SIZE_BYTES);
|
||||||
default: return mp_const_none;
|
default: return mp_const_none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -337,26 +337,26 @@ STATIC mp_obj_t machine_sdcard_ioctl(mp_obj_t self_in, mp_obj_t cmd_in, mp_obj_t
|
||||||
mp_int_t cmd = mp_obj_get_int(cmd_in);
|
mp_int_t cmd = mp_obj_get_int(cmd_in);
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case BP_IOCTL_INIT:
|
case MP_BLOCKDEV_IOCTL_INIT:
|
||||||
err = sdcard_ensure_card_init(self, false);
|
err = sdcard_ensure_card_init(self, false);
|
||||||
return MP_OBJ_NEW_SMALL_INT((err == ESP_OK) ? 0 : -1);
|
return MP_OBJ_NEW_SMALL_INT((err == ESP_OK) ? 0 : -1);
|
||||||
|
|
||||||
case BP_IOCTL_DEINIT:
|
case MP_BLOCKDEV_IOCTL_DEINIT:
|
||||||
// Ensure that future attempts to look at info re-read the card
|
// Ensure that future attempts to look at info re-read the card
|
||||||
self->flags &= ~SDCARD_CARD_FLAGS_CARD_INIT_DONE;
|
self->flags &= ~SDCARD_CARD_FLAGS_CARD_INIT_DONE;
|
||||||
return MP_OBJ_NEW_SMALL_INT(0); // success
|
return MP_OBJ_NEW_SMALL_INT(0); // success
|
||||||
|
|
||||||
case BP_IOCTL_SYNC:
|
case MP_BLOCKDEV_IOCTL_SYNC:
|
||||||
// nothing to do
|
// nothing to do
|
||||||
return MP_OBJ_NEW_SMALL_INT(0); // success
|
return MP_OBJ_NEW_SMALL_INT(0); // success
|
||||||
|
|
||||||
case BP_IOCTL_SEC_COUNT:
|
case MP_BLOCKDEV_IOCTL_BLOCK_COUNT:
|
||||||
err = sdcard_ensure_card_init(self, false);
|
err = sdcard_ensure_card_init(self, false);
|
||||||
if (err != ESP_OK)
|
if (err != ESP_OK)
|
||||||
return MP_OBJ_NEW_SMALL_INT(-1);
|
return MP_OBJ_NEW_SMALL_INT(-1);
|
||||||
return MP_OBJ_NEW_SMALL_INT(self->card.csd.capacity);
|
return MP_OBJ_NEW_SMALL_INT(self->card.csd.capacity);
|
||||||
|
|
||||||
case BP_IOCTL_SEC_SIZE:
|
case MP_BLOCKDEV_IOCTL_BLOCK_SIZE:
|
||||||
err = sdcard_ensure_card_init(self, false);
|
err = sdcard_ensure_card_init(self, false);
|
||||||
if (err != ESP_OK)
|
if (err != ESP_OK)
|
||||||
return MP_OBJ_NEW_SMALL_INT(-1);
|
return MP_OBJ_NEW_SMALL_INT(-1);
|
||||||
|
|
|
@ -22,9 +22,9 @@ class FlashBdev:
|
||||||
|
|
||||||
def ioctl(self, op, arg):
|
def ioctl(self, op, arg):
|
||||||
#print("ioctl(%d, %r)" % (op, arg))
|
#print("ioctl(%d, %r)" % (op, arg))
|
||||||
if op == 4: # BP_IOCTL_SEC_COUNT
|
if op == 4: # MP_BLOCKDEV_IOCTL_BLOCK_COUNT
|
||||||
return self.blocks
|
return self.blocks
|
||||||
if op == 5: # BP_IOCTL_SEC_SIZE
|
if op == 5: # MP_BLOCKDEV_IOCTL_BLOCK_SIZE
|
||||||
return self.SEC_SIZE
|
return self.SEC_SIZE
|
||||||
|
|
||||||
size = esp.flash_size()
|
size = esp.flash_size()
|
||||||
|
|
|
@ -812,24 +812,24 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_sdcard_writeblocks_obj, pyb_sdcard_writeblo
|
||||||
STATIC mp_obj_t pyb_sdcard_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) {
|
STATIC mp_obj_t pyb_sdcard_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) {
|
||||||
mp_int_t cmd = mp_obj_get_int(cmd_in);
|
mp_int_t cmd = mp_obj_get_int(cmd_in);
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case BP_IOCTL_INIT:
|
case MP_BLOCKDEV_IOCTL_INIT:
|
||||||
if (!sdcard_power_on()) {
|
if (!sdcard_power_on()) {
|
||||||
return MP_OBJ_NEW_SMALL_INT(-1); // error
|
return MP_OBJ_NEW_SMALL_INT(-1); // error
|
||||||
}
|
}
|
||||||
return MP_OBJ_NEW_SMALL_INT(0); // success
|
return MP_OBJ_NEW_SMALL_INT(0); // success
|
||||||
|
|
||||||
case BP_IOCTL_DEINIT:
|
case MP_BLOCKDEV_IOCTL_DEINIT:
|
||||||
sdcard_power_off();
|
sdcard_power_off();
|
||||||
return MP_OBJ_NEW_SMALL_INT(0); // success
|
return MP_OBJ_NEW_SMALL_INT(0); // success
|
||||||
|
|
||||||
case BP_IOCTL_SYNC:
|
case MP_BLOCKDEV_IOCTL_SYNC:
|
||||||
// nothing to do
|
// nothing to do
|
||||||
return MP_OBJ_NEW_SMALL_INT(0); // success
|
return MP_OBJ_NEW_SMALL_INT(0); // success
|
||||||
|
|
||||||
case BP_IOCTL_SEC_COUNT:
|
case MP_BLOCKDEV_IOCTL_BLOCK_COUNT:
|
||||||
return MP_OBJ_NEW_SMALL_INT(sdcard_get_capacity_in_bytes() / SDCARD_BLOCK_SIZE);
|
return MP_OBJ_NEW_SMALL_INT(sdcard_get_capacity_in_bytes() / SDCARD_BLOCK_SIZE);
|
||||||
|
|
||||||
case BP_IOCTL_SEC_SIZE:
|
case MP_BLOCKDEV_IOCTL_BLOCK_SIZE:
|
||||||
return MP_OBJ_NEW_SMALL_INT(SDCARD_BLOCK_SIZE);
|
return MP_OBJ_NEW_SMALL_INT(SDCARD_BLOCK_SIZE);
|
||||||
|
|
||||||
default: // unknown command
|
default: // unknown command
|
||||||
|
|
|
@ -263,11 +263,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(pyb_flash_writeblocks_obj, pyb_flash_writeblock
|
||||||
STATIC mp_obj_t pyb_flash_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) {
|
STATIC mp_obj_t pyb_flash_ioctl(mp_obj_t self, mp_obj_t cmd_in, mp_obj_t arg_in) {
|
||||||
mp_int_t cmd = mp_obj_get_int(cmd_in);
|
mp_int_t cmd = mp_obj_get_int(cmd_in);
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case BP_IOCTL_INIT: storage_init(); return MP_OBJ_NEW_SMALL_INT(0);
|
case MP_BLOCKDEV_IOCTL_INIT: storage_init(); return MP_OBJ_NEW_SMALL_INT(0);
|
||||||
case BP_IOCTL_DEINIT: storage_flush(); return MP_OBJ_NEW_SMALL_INT(0); // TODO properly
|
case MP_BLOCKDEV_IOCTL_DEINIT: storage_flush(); return MP_OBJ_NEW_SMALL_INT(0); // TODO properly
|
||||||
case BP_IOCTL_SYNC: storage_flush(); return MP_OBJ_NEW_SMALL_INT(0);
|
case MP_BLOCKDEV_IOCTL_SYNC: storage_flush(); return MP_OBJ_NEW_SMALL_INT(0);
|
||||||
case BP_IOCTL_SEC_COUNT: return MP_OBJ_NEW_SMALL_INT(storage_get_block_count());
|
case MP_BLOCKDEV_IOCTL_BLOCK_COUNT: return MP_OBJ_NEW_SMALL_INT(storage_get_block_count());
|
||||||
case BP_IOCTL_SEC_SIZE: return MP_OBJ_NEW_SMALL_INT(storage_get_block_size());
|
case MP_BLOCKDEV_IOCTL_BLOCK_SIZE: return MP_OBJ_NEW_SMALL_INT(storage_get_block_size());
|
||||||
default: return mp_const_none;
|
default: return mp_const_none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,17 +121,17 @@ STATIC int lu_ioctl(uint8_t lun, int op, uint32_t *data) {
|
||||||
|
|
||||||
if (lu == &pyb_flash_type) {
|
if (lu == &pyb_flash_type) {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case BP_IOCTL_INIT:
|
case MP_BLOCKDEV_IOCTL_INIT:
|
||||||
storage_init();
|
storage_init();
|
||||||
*data = 0;
|
*data = 0;
|
||||||
return 0;
|
return 0;
|
||||||
case BP_IOCTL_SYNC:
|
case MP_BLOCKDEV_IOCTL_SYNC:
|
||||||
storage_flush();
|
storage_flush();
|
||||||
return 0;
|
return 0;
|
||||||
case BP_IOCTL_SEC_SIZE:
|
case MP_BLOCKDEV_IOCTL_BLOCK_SIZE:
|
||||||
*data = storage_get_block_size();
|
*data = storage_get_block_size();
|
||||||
return 0;
|
return 0;
|
||||||
case BP_IOCTL_SEC_COUNT:
|
case MP_BLOCKDEV_IOCTL_BLOCK_COUNT:
|
||||||
*data = storage_get_block_count();
|
*data = storage_get_block_count();
|
||||||
return 0;
|
return 0;
|
||||||
default:
|
default:
|
||||||
|
@ -144,18 +144,18 @@ STATIC int lu_ioctl(uint8_t lun, int op, uint32_t *data) {
|
||||||
#endif
|
#endif
|
||||||
) {
|
) {
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case BP_IOCTL_INIT:
|
case MP_BLOCKDEV_IOCTL_INIT:
|
||||||
if (!sdcard_power_on()) {
|
if (!sdcard_power_on()) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
*data = 0;
|
*data = 0;
|
||||||
return 0;
|
return 0;
|
||||||
case BP_IOCTL_SYNC:
|
case MP_BLOCKDEV_IOCTL_SYNC:
|
||||||
return 0;
|
return 0;
|
||||||
case BP_IOCTL_SEC_SIZE:
|
case MP_BLOCKDEV_IOCTL_BLOCK_SIZE:
|
||||||
*data = SDCARD_BLOCK_SIZE;
|
*data = SDCARD_BLOCK_SIZE;
|
||||||
return 0;
|
return 0;
|
||||||
case BP_IOCTL_SEC_COUNT:
|
case MP_BLOCKDEV_IOCTL_BLOCK_COUNT:
|
||||||
*data = sdcard_get_capacity_in_bytes() / (uint64_t)SDCARD_BLOCK_SIZE;
|
*data = sdcard_get_capacity_in_bytes() / (uint64_t)SDCARD_BLOCK_SIZE;
|
||||||
return 0;
|
return 0;
|
||||||
default:
|
default:
|
||||||
|
@ -174,7 +174,7 @@ STATIC int8_t usbd_msc_Init(uint8_t lun_in) {
|
||||||
}
|
}
|
||||||
for (int lun = 0; lun < usbd_msc_lu_num; ++lun) {
|
for (int lun = 0; lun < usbd_msc_lu_num; ++lun) {
|
||||||
uint32_t data = 0;
|
uint32_t data = 0;
|
||||||
int res = lu_ioctl(lun, BP_IOCTL_INIT, &data);
|
int res = lu_ioctl(lun, MP_BLOCKDEV_IOCTL_INIT, &data);
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
lu_flag_clr(lun, FLAGS_STARTED);
|
lu_flag_clr(lun, FLAGS_STARTED);
|
||||||
} else {
|
} else {
|
||||||
|
@ -234,12 +234,12 @@ STATIC int usbd_msc_Inquiry(uint8_t lun, const uint8_t *params, uint8_t *data_ou
|
||||||
// Get storage capacity of a logical unit
|
// Get storage capacity of a logical unit
|
||||||
STATIC int8_t usbd_msc_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *block_size) {
|
STATIC int8_t usbd_msc_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *block_size) {
|
||||||
uint32_t block_size_u32 = 0;
|
uint32_t block_size_u32 = 0;
|
||||||
int res = lu_ioctl(lun, BP_IOCTL_SEC_SIZE, &block_size_u32);
|
int res = lu_ioctl(lun, MP_BLOCKDEV_IOCTL_BLOCK_SIZE, &block_size_u32);
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
*block_size = block_size_u32;
|
*block_size = block_size_u32;
|
||||||
return lu_ioctl(lun, BP_IOCTL_SEC_COUNT, block_num);
|
return lu_ioctl(lun, MP_BLOCKDEV_IOCTL_BLOCK_COUNT, block_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if a logical unit is ready
|
// Check if a logical unit is ready
|
||||||
|
@ -275,7 +275,7 @@ STATIC int8_t usbd_msc_StartStopUnit(uint8_t lun, uint8_t started) {
|
||||||
STATIC int8_t usbd_msc_PreventAllowMediumRemoval(uint8_t lun, uint8_t param) {
|
STATIC int8_t usbd_msc_PreventAllowMediumRemoval(uint8_t lun, uint8_t param) {
|
||||||
uint32_t dummy;
|
uint32_t dummy;
|
||||||
// Sync the logical unit so the device can be unplugged/turned off
|
// Sync the logical unit so the device can be unplugged/turned off
|
||||||
return lu_ioctl(lun, BP_IOCTL_SYNC, &dummy);
|
return lu_ioctl(lun, MP_BLOCKDEV_IOCTL_SYNC, &dummy);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read data from a logical unit
|
// Read data from a logical unit
|
||||||
|
|
|
@ -31,9 +31,9 @@ class RAMFS:
|
||||||
|
|
||||||
def ioctl(self, op, arg):
|
def ioctl(self, op, arg):
|
||||||
#print("ioctl(%d, %r)" % (op, arg))
|
#print("ioctl(%d, %r)" % (op, arg))
|
||||||
if op == 4: # BP_IOCTL_SEC_COUNT
|
if op == 4: # MP_BLOCKDEV_IOCTL_BLOCK_COUNT
|
||||||
return len(self.data) // self.SEC_SIZE
|
return len(self.data) // self.SEC_SIZE
|
||||||
if op == 5: # BP_IOCTL_SEC_SIZE
|
if op == 5: # MP_BLOCKDEV_IOCTL_BLOCK_SIZE
|
||||||
return self.SEC_SIZE
|
return self.SEC_SIZE
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,9 +31,9 @@ class RAMFS:
|
||||||
|
|
||||||
def ioctl(self, op, arg):
|
def ioctl(self, op, arg):
|
||||||
#print("ioctl(%d, %r)" % (op, arg))
|
#print("ioctl(%d, %r)" % (op, arg))
|
||||||
if op == 4: # BP_IOCTL_SEC_COUNT
|
if op == 4: # MP_BLOCKDEV_IOCTL_BLOCK_COUNT
|
||||||
return len(self.data) // self.SEC_SIZE
|
return len(self.data) // self.SEC_SIZE
|
||||||
if op == 5: # BP_IOCTL_SEC_SIZE
|
if op == 5: # MP_BLOCKDEV_IOCTL_BLOCK_SIZE
|
||||||
return self.SEC_SIZE
|
return self.SEC_SIZE
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,9 +30,9 @@ class RAMFS:
|
||||||
|
|
||||||
def ioctl(self, op, arg):
|
def ioctl(self, op, arg):
|
||||||
#print("ioctl(%d, %r)" % (op, arg))
|
#print("ioctl(%d, %r)" % (op, arg))
|
||||||
if op == 4: # BP_IOCTL_SEC_COUNT
|
if op == 4: # MP_BLOCKDEV_IOCTL_BLOCK_COUNT
|
||||||
return len(self.data) // self.SEC_SIZE
|
return len(self.data) // self.SEC_SIZE
|
||||||
if op == 5: # BP_IOCTL_SEC_SIZE
|
if op == 5: # MP_BLOCKDEV_IOCTL_BLOCK_SIZE
|
||||||
return self.SEC_SIZE
|
return self.SEC_SIZE
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,9 +31,9 @@ class RAMFS:
|
||||||
|
|
||||||
def ioctl(self, op, arg):
|
def ioctl(self, op, arg):
|
||||||
#print("ioctl(%d, %r)" % (op, arg))
|
#print("ioctl(%d, %r)" % (op, arg))
|
||||||
if op == 4: # BP_IOCTL_SEC_COUNT
|
if op == 4: # MP_BLOCKDEV_IOCTL_BLOCK_COUNT
|
||||||
return len(self.data) // self.SEC_SIZE
|
return len(self.data) // self.SEC_SIZE
|
||||||
if op == 5: # BP_IOCTL_SEC_SIZE
|
if op == 5: # MP_BLOCKDEV_IOCTL_BLOCK_SIZE
|
||||||
return self.SEC_SIZE
|
return self.SEC_SIZE
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,9 +39,9 @@ class RAMBDevSparse:
|
||||||
|
|
||||||
def ioctl(self, op, arg):
|
def ioctl(self, op, arg):
|
||||||
#print("ioctl(%d, %r)" % (op, arg))
|
#print("ioctl(%d, %r)" % (op, arg))
|
||||||
if op == 4: # BP_IOCTL_SEC_COUNT
|
if op == 4: # MP_BLOCKDEV_IOCTL_BLOCK_COUNT
|
||||||
return self.blocks
|
return self.blocks
|
||||||
if op == 5: # BP_IOCTL_SEC_SIZE
|
if op == 5: # MP_BLOCKDEV_IOCTL_BLOCK_SIZE
|
||||||
return self.SEC_SIZE
|
return self.SEC_SIZE
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue