Implementing fsobj

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
pulkin
Posts: 49
Joined: Tue Feb 19, 2019 10:22 pm

Implementing fsobj

Post by pulkin » Wed Dec 18, 2019 10:47 pm

Hi,

The port I am working on https://github.com/pulkin/micropython/t ... ts/gprs_a9 has, pretty much, a copy-paste implementation of vfs where file and folder-related operations are replaced by static port functions. I think that implementing an actual vfs object might be a better choice such that it can be mounted and dismounted.

https://docs.micropython.org/en/latest/ ... #uos.mount

Is it true? Presumably, I need to provide various entry points for vfs, like reading files, list folders, etc. How do I do that? Is there a list of such operations?

pulkin
Posts: 49
Joined: Tue Feb 19, 2019 10:22 pm

Re: Implementing fsobj

Post by pulkin » Wed Dec 18, 2019 10:54 pm

It seems like this gives an idea of what to implement:

Code: Select all

█ grep proxy ../../extmod/vfs.c 
// For mp_vfs_proxy_call, the maximum number of additional args that can be passed.
STATIC mp_obj_t mp_vfs_proxy_call(mp_vfs_mount_t *vfs, qstr meth_name, size_t n_args, const mp_obj_t *args) {
        stat = mp_vfs_proxy_call(vfs, MP_QSTR_stat, 1, &path_o);
    mp_vfs_proxy_call(vfs, MP_QSTR_mount, 2, (mp_obj_t*)&args);
    mp_vfs_proxy_call(vfs, MP_QSTR_umount, 0, NULL);
    return mp_vfs_proxy_call(vfs, MP_QSTR_open, 2, (mp_obj_t*)&args);
                mp_vfs_proxy_call(vfs, MP_QSTR_chdir, 1, &root);
        mp_vfs_proxy_call(vfs, MP_QSTR_chdir, 1, &path_out);
    mp_obj_t cwd_o = mp_vfs_proxy_call(MP_STATE_VM(vfs_cur), MP_QSTR_getcwd, 0, NULL);
            self->cur.iter = mp_vfs_proxy_call(vfs, MP_QSTR_ilistdir, 1, &root);
    return mp_vfs_proxy_call(vfs, MP_QSTR_ilistdir, 1, &path_out);
    return mp_vfs_proxy_call(vfs, MP_QSTR_mkdir, 1, &path_out);
    return mp_vfs_proxy_call(vfs, MP_QSTR_remove, 1, &path_out);
    return mp_vfs_proxy_call(old_vfs, MP_QSTR_rename, 2, args);
    return mp_vfs_proxy_call(vfs, MP_QSTR_rmdir, 1, &path_out);
    return mp_vfs_proxy_call(vfs, MP_QSTR_stat, 1, &path_out);
    return mp_vfs_proxy_call(vfs, MP_QSTR_statvfs, 1, &path_out);
However, I am confused not seeing 'close' in the list. Is file object type for this fs another thing that I have to implement?

Post Reply