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:
Damien George 2019-10-29 12:25:30 +11:00
parent 7c8fb27f38
commit cfe1c5abf8
18 changed files with 72 additions and 72 deletions

View File

@ -45,11 +45,11 @@
#define MP_BLOCKDEV_FLAG_NO_FILESYSTEM (0x0008) // the block device has no filesystem on it
// constants for block protocol ioctl
#define BP_IOCTL_INIT (1)
#define BP_IOCTL_DEINIT (2)
#define BP_IOCTL_SYNC (3)
#define BP_IOCTL_SEC_COUNT (4)
#define BP_IOCTL_SEC_SIZE (5)
#define MP_BLOCKDEV_IOCTL_INIT (1)
#define MP_BLOCKDEV_IOCTL_DEINIT (2)
#define MP_BLOCKDEV_IOCTL_SYNC (3)
#define MP_BLOCKDEV_IOCTL_BLOCK_COUNT (4)
#define MP_BLOCKDEV_IOCTL_BLOCK_SIZE (5)
// At the moment the VFS protocol just has import_stat, but could be extended to other methods
typedef struct _mp_vfs_proto_t {

View File

@ -119,20 +119,20 @@ mp_obj_t mp_vfs_blockdev_ioctl(mp_vfs_blockdev_t *self, uintptr_t cmd, uintptr_t
} else {
// Old protocol with sync and count
switch (cmd) {
case BP_IOCTL_SYNC:
case MP_BLOCKDEV_IOCTL_SYNC:
if (self->u.old.sync[0] != MP_OBJ_NULL) {
mp_call_method_n_kw(0, 0, self->u.old.sync);
}
break;
case BP_IOCTL_SEC_COUNT:
case MP_BLOCKDEV_IOCTL_BLOCK_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
break;
case BP_IOCTL_INIT:
case MP_BLOCKDEV_IOCTL_INIT:
// Old protocol doesn't have init
break;
}

View File

@ -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
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]);
// mount the block device so the VFS methods can be used

View File

@ -113,10 +113,10 @@ DRESULT disk_ioctl (
// First part: call the relevant method of the underlying block device
static const uint8_t op_map[8] = {
[CTRL_SYNC] = BP_IOCTL_SYNC,
[GET_SECTOR_COUNT] = BP_IOCTL_SEC_COUNT,
[GET_SECTOR_SIZE] = BP_IOCTL_SEC_SIZE,
[IOCTL_INIT] = BP_IOCTL_INIT,
[CTRL_SYNC] = MP_BLOCKDEV_IOCTL_SYNC,
[GET_SECTOR_COUNT] = MP_BLOCKDEV_IOCTL_BLOCK_COUNT,
[GET_SECTOR_SIZE] = MP_BLOCKDEV_IOCTL_BLOCK_SIZE,
[IOCTL_INIT] = MP_BLOCKDEV_IOCTL_INIT,
};
uint8_t bp_op = op_map[cmd & 7];
mp_obj_t ret = mp_const_none;

View File

@ -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) {
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) {
@ -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->sync = MP_VFS_LFSx(dev_sync);
MP_VFS_LFSx(dev_ioctl)(config, BP_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 bc = MP_VFS_LFSx(dev_ioctl)(config, BP_IOCTL_SEC_COUNT, 0, true); // get block count
MP_VFS_LFSx(dev_ioctl)(config, MP_BLOCKDEV_IOCTL_INIT, 0, false); // initialise block device
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, MP_BLOCKDEV_IOCTL_BLOCK_COUNT, 0, true); // get block count
self->blockdev.block_size = bs;
config->read_size = read_size;

View File

@ -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) {
mp_int_t cmd = mp_obj_get_int(cmd_in);
switch (cmd) {
case BP_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 BP_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 BP_IOCTL_SEC_SIZE: return MP_OBJ_NEW_SMALL_INT(SFLASH_SECTOR_SIZE);
case MP_BLOCKDEV_IOCTL_INIT: return MP_OBJ_NEW_SMALL_INT(sflash_disk_init() != RES_OK);
case MP_BLOCKDEV_IOCTL_DEINIT: 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 MP_BLOCKDEV_IOCTL_BLOCK_COUNT: return MP_OBJ_NEW_SMALL_INT(SFLASH_SECTOR_COUNT);
case MP_BLOCKDEV_IOCTL_BLOCK_SIZE: return MP_OBJ_NEW_SMALL_INT(SFLASH_SECTOR_SIZE);
default: return mp_const_none;
}
}

View File

@ -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) {
mp_int_t cmd = mp_obj_get_int(cmd_in);
switch (cmd) {
case BP_IOCTL_INIT:
case BP_IOCTL_DEINIT:
case BP_IOCTL_SYNC:
case MP_BLOCKDEV_IOCTL_INIT:
case MP_BLOCKDEV_IOCTL_DEINIT:
case MP_BLOCKDEV_IOCTL_SYNC:
// nothing to do
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));
case BP_IOCTL_SEC_SIZE:
case MP_BLOCKDEV_IOCTL_BLOCK_SIZE:
return MP_OBJ_NEW_SMALL_INT(SD_SECTOR_SIZE);
default: // unknown command

View File

@ -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);
mp_int_t cmd = mp_obj_get_int(cmd_in);
switch (cmd) {
case BP_IOCTL_INIT: return MP_OBJ_NEW_SMALL_INT(0);
case BP_IOCTL_DEINIT: return MP_OBJ_NEW_SMALL_INT(0);
case BP_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 BP_IOCTL_SEC_SIZE: return MP_OBJ_NEW_SMALL_INT(BLOCK_SIZE_BYTES);
case MP_BLOCKDEV_IOCTL_INIT: return MP_OBJ_NEW_SMALL_INT(0);
case MP_BLOCKDEV_IOCTL_DEINIT: return MP_OBJ_NEW_SMALL_INT(0);
case MP_BLOCKDEV_IOCTL_SYNC: return MP_OBJ_NEW_SMALL_INT(0);
case MP_BLOCKDEV_IOCTL_BLOCK_COUNT: return MP_OBJ_NEW_SMALL_INT(self->part->size / BLOCK_SIZE_BYTES);
case MP_BLOCKDEV_IOCTL_BLOCK_SIZE: return MP_OBJ_NEW_SMALL_INT(BLOCK_SIZE_BYTES);
default: return mp_const_none;
}
}

View File

@ -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);
switch (cmd) {
case BP_IOCTL_INIT:
case MP_BLOCKDEV_IOCTL_INIT:
err = sdcard_ensure_card_init(self, false);
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
self->flags &= ~SDCARD_CARD_FLAGS_CARD_INIT_DONE;
return MP_OBJ_NEW_SMALL_INT(0); // success
case BP_IOCTL_SYNC:
case MP_BLOCKDEV_IOCTL_SYNC:
// nothing to do
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);
if (err != ESP_OK)
return MP_OBJ_NEW_SMALL_INT(-1);
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);
if (err != ESP_OK)
return MP_OBJ_NEW_SMALL_INT(-1);

View File

@ -22,9 +22,9 @@ class FlashBdev:
def ioctl(self, 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
if op == 5: # BP_IOCTL_SEC_SIZE
if op == 5: # MP_BLOCKDEV_IOCTL_BLOCK_SIZE
return self.SEC_SIZE
size = esp.flash_size()

View File

@ -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) {
mp_int_t cmd = mp_obj_get_int(cmd_in);
switch (cmd) {
case BP_IOCTL_INIT:
case MP_BLOCKDEV_IOCTL_INIT:
if (!sdcard_power_on()) {
return MP_OBJ_NEW_SMALL_INT(-1); // error
}
return MP_OBJ_NEW_SMALL_INT(0); // success
case BP_IOCTL_DEINIT:
case MP_BLOCKDEV_IOCTL_DEINIT:
sdcard_power_off();
return MP_OBJ_NEW_SMALL_INT(0); // success
case BP_IOCTL_SYNC:
case MP_BLOCKDEV_IOCTL_SYNC:
// nothing to do
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);
case BP_IOCTL_SEC_SIZE:
case MP_BLOCKDEV_IOCTL_BLOCK_SIZE:
return MP_OBJ_NEW_SMALL_INT(SDCARD_BLOCK_SIZE);
default: // unknown command

View File

@ -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) {
mp_int_t cmd = mp_obj_get_int(cmd_in);
switch (cmd) {
case BP_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 BP_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 BP_IOCTL_SEC_SIZE: return MP_OBJ_NEW_SMALL_INT(storage_get_block_size());
case MP_BLOCKDEV_IOCTL_INIT: storage_init(); return MP_OBJ_NEW_SMALL_INT(0);
case MP_BLOCKDEV_IOCTL_DEINIT: storage_flush(); return MP_OBJ_NEW_SMALL_INT(0); // TODO properly
case MP_BLOCKDEV_IOCTL_SYNC: storage_flush(); return MP_OBJ_NEW_SMALL_INT(0);
case MP_BLOCKDEV_IOCTL_BLOCK_COUNT: return MP_OBJ_NEW_SMALL_INT(storage_get_block_count());
case MP_BLOCKDEV_IOCTL_BLOCK_SIZE: return MP_OBJ_NEW_SMALL_INT(storage_get_block_size());
default: return mp_const_none;
}
}

View File

@ -121,17 +121,17 @@ STATIC int lu_ioctl(uint8_t lun, int op, uint32_t *data) {
if (lu == &pyb_flash_type) {
switch (op) {
case BP_IOCTL_INIT:
case MP_BLOCKDEV_IOCTL_INIT:
storage_init();
*data = 0;
return 0;
case BP_IOCTL_SYNC:
case MP_BLOCKDEV_IOCTL_SYNC:
storage_flush();
return 0;
case BP_IOCTL_SEC_SIZE:
case MP_BLOCKDEV_IOCTL_BLOCK_SIZE:
*data = storage_get_block_size();
return 0;
case BP_IOCTL_SEC_COUNT:
case MP_BLOCKDEV_IOCTL_BLOCK_COUNT:
*data = storage_get_block_count();
return 0;
default:
@ -144,18 +144,18 @@ STATIC int lu_ioctl(uint8_t lun, int op, uint32_t *data) {
#endif
) {
switch (op) {
case BP_IOCTL_INIT:
case MP_BLOCKDEV_IOCTL_INIT:
if (!sdcard_power_on()) {
return -1;
}
*data = 0;
return 0;
case BP_IOCTL_SYNC:
case MP_BLOCKDEV_IOCTL_SYNC:
return 0;
case BP_IOCTL_SEC_SIZE:
case MP_BLOCKDEV_IOCTL_BLOCK_SIZE:
*data = SDCARD_BLOCK_SIZE;
return 0;
case BP_IOCTL_SEC_COUNT:
case MP_BLOCKDEV_IOCTL_BLOCK_COUNT:
*data = sdcard_get_capacity_in_bytes() / (uint64_t)SDCARD_BLOCK_SIZE;
return 0;
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) {
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) {
lu_flag_clr(lun, FLAGS_STARTED);
} 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
STATIC int8_t usbd_msc_GetCapacity(uint8_t lun, uint32_t *block_num, uint16_t *block_size) {
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) {
return -1;
}
*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
@ -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) {
uint32_t dummy;
// 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

View File

@ -31,9 +31,9 @@ class RAMFS:
def ioctl(self, 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
if op == 5: # BP_IOCTL_SEC_SIZE
if op == 5: # MP_BLOCKDEV_IOCTL_BLOCK_SIZE
return self.SEC_SIZE

View File

@ -31,9 +31,9 @@ class RAMFS:
def ioctl(self, 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
if op == 5: # BP_IOCTL_SEC_SIZE
if op == 5: # MP_BLOCKDEV_IOCTL_BLOCK_SIZE
return self.SEC_SIZE

View File

@ -30,9 +30,9 @@ class RAMFS:
def ioctl(self, 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
if op == 5: # BP_IOCTL_SEC_SIZE
if op == 5: # MP_BLOCKDEV_IOCTL_BLOCK_SIZE
return self.SEC_SIZE

View File

@ -31,9 +31,9 @@ class RAMFS:
def ioctl(self, 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
if op == 5: # BP_IOCTL_SEC_SIZE
if op == 5: # MP_BLOCKDEV_IOCTL_BLOCK_SIZE
return self.SEC_SIZE

View File

@ -39,9 +39,9 @@ class RAMBDevSparse:
def ioctl(self, 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
if op == 5: # BP_IOCTL_SEC_SIZE
if op == 5: # MP_BLOCKDEV_IOCTL_BLOCK_SIZE
return self.SEC_SIZE