diff options
| -rw-r--r-- | emu/FreeRTOS/devfs-posix.c | 175 | ||||
| -rw-r--r-- | emu/FreeRTOS/devfs.c | 2 | ||||
| -rw-r--r-- | emu/FreeRTOS/emu | 2 | ||||
| -rw-r--r-- | emu/FreeRTOS/mkfile | 2 | ||||
| -rw-r--r-- | libiot/vfs/include/esp_vfs.h | 6 | ||||
| -rw-r--r-- | libiot/vfs/vfs.c | 2 | ||||
| -rw-r--r-- | libiot/vfs/vfs.h | 2 |
7 files changed, 117 insertions, 74 deletions
diff --git a/emu/FreeRTOS/devfs-posix.c b/emu/FreeRTOS/devfs-posix.c index 958e941..800078f 100644 --- a/emu/FreeRTOS/devfs-posix.c +++ b/emu/FreeRTOS/devfs-posix.c @@ -8,8 +8,8 @@ #include "error.h" #include <sys/types.h> -#include <sys/stat.h> -#include <sys/fcntl.h> +//{} #include <sys/stat.h> +//{} #include <sys/fcntl.h> #include <sys/socket.h> #if 0 //{} #include <sys/un.h> @@ -27,15 +27,15 @@ typedef struct Fsinfo Fsinfo; struct Fsinfo { - int uid; - int gid; +//{} int uid; +//{} int gid; int mode; /* Unix mode */ DIR* dir; /* open directory */ struct dirent* de; /* directory reading */ int fd; /* open files */ ulong offset; /* offset when reading directory */ int eod; /* end of directory */ - int issocket; +//{} int issocket; QLock oq; /* mutex for offset */ char* spec; Cname* name; /* Unix's name for file */ @@ -93,10 +93,10 @@ static vlong osdisksize(int); /* defined by including file */ static int xstat(char *f, struct stat *sb) { - if(stat(f, sb) >= 0) + if(vfs.stat(f, sb) >= 0) return 0; /* could possibly generate ->name as rob once suggested */ - return lstat(f, sb); + return -1; //{} lstat(f, sb); } static void @@ -116,20 +116,20 @@ fsattach(char *spec) if(!emptystr(spec) && strcmp(spec, "*") != 0) error(Ebadspec); - if(stat(rootdir, &st) < 0) + if(vfs.stat(rootdir, &st) < 0) oserror(); if(!S_ISDIR(st.st_mode)) error(Enotdir); c = devattach('U', spec); - c->qid = fsqid(&st); +//{} c->qid = fsqid(&st); c->aux = smalloc(sizeof(Fsinfo)); FS(c)->dir = nil; FS(c)->de = nil; FS(c)->fd = -1; - FS(c)->issocket = 0; - FS(c)->gid = st.st_gid; - FS(c)->uid = st.st_uid; +//{} FS(c)->issocket = 0; +//{} FS(c)->gid = st.st_gid; +//{} FS(c)->uid = st.st_uid; FS(c)->mode = st.st_mode; lock(&l); c->dev = devno++; @@ -139,11 +139,20 @@ fsattach(char *spec) FS(c)->name = newcname(FS(c)->spec); }else FS(c)->name = newcname(rootdir); - FS(c)->rootqid = c->qid; +//{} FS(c)->rootqid = c->qid; return c; } + +static void fsinit(void) +{ + vfs_spiffs_mount("spiffs"); + + devinit(); +} + + Walkqid* fswalk(Chan *c, Chan *nc, char **name, int nname) { @@ -214,15 +223,15 @@ fswalk(Chan *c, Chan *nc, char **name, int nname) nc->aux = smalloc(sizeof(Fsinfo)); nc->type = c->type; if(nname > 0) { - FS(nc)->gid = st.st_gid; - FS(nc)->uid = st.st_uid; +//{} FS(nc)->gid = st.st_gid; +//{} FS(nc)->uid = st.st_uid; FS(nc)->mode = st.st_mode; - FS(nc)->issocket = S_ISSOCK(st.st_mode); +//{} FS(nc)->issocket = S_ISSOCK(st.st_mode); } else { - FS(nc)->gid = FS(c)->gid; - FS(nc)->uid = FS(c)->uid; +//{} FS(nc)->gid = FS(c)->gid; +//{} FS(nc)->uid = FS(c)->uid; FS(nc)->mode = FS(c)->mode; - FS(nc)->issocket = FS(c)->issocket; +//{} FS(nc)->issocket = FS(c)->issocket; } FS(nc)->name = current; FS(nc)->spec = FS(c)->spec; @@ -241,7 +250,7 @@ fsstat(Chan *c, uchar *dp, int n) char *p; if(FS(c)->fd >= 0){ - if(fstat(FS(c)->fd, &st) < 0) + if(vfs.fstat(FS(c)->fd, &st) < 0) oserror(); }else{ if(xstat(FS(c)->name->s, &st) < 0) @@ -256,6 +265,7 @@ fsstat(Chan *c, uchar *dp, int n) return n; } +#if 0 //{} static int opensocket(char *path) { @@ -278,7 +288,8 @@ opensocket(char *path) return fd; close(fd); return -1; -} +} +#endif //{} static Chan* fsopen(Chan *c, int mode) @@ -316,18 +327,18 @@ fsopen(Chan *c, int mode) c->mode = openmode(mode); if(isdir) { - FS(c)->dir = opendir(FS(c)->name->s); + FS(c)->dir = vfs.opendir(FS(c)->name->s); if(FS(c)->dir == nil) oserror(); FS(c)->eod = 0; } else { - if(!FS(c)->issocket){ +//{} if(!FS(c)->issocket){ if(mode & OTRUNC) m |= O_TRUNC; - FS(c)->fd = open(FS(c)->name->s, m, 0666); - }else - FS(c)->fd = opensocket(FS(c)->name->s); + FS(c)->fd = vfs.open(FS(c)->name->s, m, 0666); +//{} }else +//{} FS(c)->fd = opensocket(FS(c)->name->s); if(FS(c)->fd < 0) oserror(); } @@ -361,21 +372,27 @@ fscreate(Chan *c, char *name, int mode, ulong perm) if(m) error(Eperm); - perm &= ~0777 | (FS(c)->mode & 0777); - if(mkdir(n->s, perm) < 0) +//{} perm &= ~0777 | (FS(c)->mode & 0777); + if(vfs.mkdir(n->s, perm) < 0) oserror(); - fd = open(n->s, 0); +#if 0 //{} + fd = vfs.open(n->s, 0); if(fd < 0) oserror(); - fchmod(fd, perm); - fchown(fd, up->env->uid, FS(c)->gid); - if(fstat(fd, &st) <0){ - close(fd); +//{} fchmod(fd, perm); +//{} fchown(fd, up->env->uid, FS(c)->gid); + if(vfs.fstat(fd, &st) <0){ + vfs.close(fd); + oserror(); + } + vfs.close(fd); +#else //{} + if(vfs.stat(n->s, &st) <0){ oserror(); } - close(fd); - FS(c)->dir = opendir(n->s); +#endif //{} + FS(c)->dir = vfs.opendir(n->s); if(FS(c)->dir == nil) oserror(); FS(c)->eod = 0; @@ -383,14 +400,14 @@ fscreate(Chan *c, char *name, int mode, ulong perm) o = (O_CREAT | O_EXCL) | (mode&3); if(mode & OTRUNC) o |= O_TRUNC; - perm &= ~0666 | (FS(c)->mode & 0666); - fd = open(n->s, o, perm); +//{} perm &= ~0666 | (FS(c)->mode & 0666); + fd = vfs.open(n->s, o, perm); if(fd < 0) oserror(); - fchmod(fd, perm); - fchown(fd, up->env->uid, FS(c)->gid); - if(fstat(fd, &st) < 0){ - close(fd); +//{} fchmod(fd, perm); +//{} fchown(fd, up->env->uid, FS(c)->gid); + if(vfs.fstat(fd, &st) < 0){ + vfs.close(fd); oserror(); } FS(c)->fd = fd; @@ -400,13 +417,13 @@ fscreate(Chan *c, char *name, int mode, ulong perm) poperror(); c->qid = fsqid(&st); - FS(c)->gid = st.st_gid; - FS(c)->uid = st.st_uid; +//{} FS(c)->gid = st.st_gid; +//{} FS(c)->uid = st.st_uid; FS(c)->mode = st.st_mode; c->mode = openmode(mode); c->offset = 0; FS(c)->offset = 0; - FS(c)->issocket = 0; +//{} FS(c)->issocket = 0; c->flag |= COPEN; } @@ -415,9 +432,9 @@ fsclose(Chan *c) { if((c->flag & COPEN) != 0){ if(c->qid.type & QTDIR) - closedir(FS(c)->dir); + vfs.closedir(FS(c)->dir); else - close(FS(c)->fd); + vfs.close(FS(c)->fd); } if(c->flag & CRCLOSE) { if(!waserror()) { @@ -444,14 +461,14 @@ fsread(Chan *c, void *va, long n, vlong offset) poperror(); qunlock(&FS(c)->oq); }else{ - if(!FS(c)->issocket){ +//{} if(!FS(c)->issocket){ r = pread(FS(c)->fd, va, n, offset); if(r >= 0) return r; if(errno != ESPIPE && errno != EPIPE) oserror(); - } - r = read(FS(c)->fd, va, n); +//{} } + r = vfs.read(FS(c)->fd, va, n); if(r < 0) oserror(); } @@ -463,14 +480,14 @@ fswrite(Chan *c, void *va, long n, vlong offset) { long r; - if(!FS(c)->issocket){ +//{} if(!FS(c)->issocket){ r = pwrite(FS(c)->fd, va, n, offset); if(r >= 0) return r; if(errno != ESPIPE && errno != EPIPE) oserror(); - } - r = write(FS(c)->fd, va, n); +//{} } + r = vfs.write(FS(c)->fd, va, n); if(r < 0) oserror(); return r; @@ -481,13 +498,15 @@ fswchk(Cname *c) { struct stat st; - if(stat(c->s, &st) < 0) + if(vfs.stat(c->s, &st) < 0) oserror(); +#if 0 //{} if(st.st_uid == up->env->uid) st.st_mode >>= 6; else if(st.st_gid == up->env->gid || ingroup(up->env->uid, st.st_gid)) st.st_mode >>= 3; +#endif //{} if(st.st_mode & S_IWOTH) return; @@ -514,9 +533,10 @@ fsremove(Chan *c) cnameclose(dir); poperror(); if(c->qid.type & QTDIR) - n = rmdir(FS(c)->name->s); + n = vfs.rmdir(FS(c)->name->s); else - n = remove(FS(c)->name->s); + n = vfs.unlink(FS(c)->name->s); +// n = remove(FS(c)->name->s); if(n < 0) oserror(); poperror(); @@ -527,17 +547,17 @@ static int fswstat(Chan *c, uchar *buf, int nb) { Dir *d; - User *p; +//{} User *p; Cname *volatile ph; struct stat st; struct utimbuf utbuf; int tsync; if(FS(c)->fd >= 0){ - if(fstat(FS(c)->fd, &st) < 0) + if(vfs.fstat(FS(c)->fd, &st) < 0) oserror(); }else{ - if(stat(FS(c)->name->s, &st) < 0) + if(vfs.stat(FS(c)->name->s, &st) < 0) oserror(); } d = malloc(sizeof(*d)+nb); @@ -568,6 +588,7 @@ fswstat(Chan *c, uchar *buf, int nb) FS(c)->name = ph; } +#if 0 //{} if(d->mode != ~0 && (d->mode&0777) != (st.st_mode&0777)) { tsync = 0; if(up->env->uid != st.st_uid) @@ -582,12 +603,13 @@ fswstat(Chan *c, uchar *buf, int nb) FS(c)->mode &= ~0777; FS(c)->mode |= d->mode&0777; } +#endif //{} if(d->atime != ~0 && d->atime != st.st_atime || d->mtime != ~0 && d->mtime != st.st_mtime) { tsync = 0; - if(up->env->uid != st.st_uid) - error(Eowner); +//{} if(up->env->uid != st.st_uid) +//{} error(Eowner); if(d->mtime != ~0) utbuf.modtime = d->mtime; else @@ -600,6 +622,7 @@ fswstat(Chan *c, uchar *buf, int nb) oserror(); } +#if 0 //{} if(*d->gid){ tsync = 0; qlock(&idl); @@ -625,7 +648,9 @@ fswstat(Chan *c, uchar *buf, int nb) poperror(); qunlock(&idl); } +#endif //{} +#if 0 //{} if(d->length != ~(uvlong)0){ tsync = 0; if(FS(c)->fd >= 0){ @@ -638,10 +663,11 @@ fswstat(Chan *c, uchar *buf, int nb) oserror(); } } +#endif //{} poperror(); free(d); - if(tsync && FS(c)->fd >= 0 && fsync(FS(c)->fd) < 0) + if(tsync && FS(c)->fd >= 0 && vfs.fsync(FS(c)->fd) < 0) oserror(); return nb; } @@ -718,6 +744,7 @@ fsperm(Chan *c, int mask) int m; m = FS(c)->mode; +#if 0 //{} /* print("fsperm: %o %o uuid %d ugid %d cuid %d cgid %d\n", m, mask, up->env->uid, up->env->gid, FS(c)->uid, FS(c)->gid); @@ -726,6 +753,7 @@ fsperm(Chan *c, int mask) m >>= 6; else if(FS(c)->gid == up->env->gid || ingroup(up->env->uid, FS(c)->gid)) m >>= 3; +#endif //{} m &= mask; if(m == 0) @@ -742,12 +770,13 @@ static int fsdirconv(Chan *c, char *path, char *name, struct stat *s, uchar *va, int nb, int indir) { Dir d; - char uidbuf[NUMSIZE], gidbuf[NUMSIZE]; - User *u; - int fd; +//{} char uidbuf[NUMSIZE], gidbuf[NUMSIZE]; +//{} User *u; +//{} int fd; memset(&d, 0, sizeof(d)); d.name = name; +#if 0 //{} u = id2user(uidmap, s->st_uid, newuid); if(u == nil){ snprint(uidbuf, sizeof(uidbuf), "#%lud", (long)s->st_uid); @@ -762,19 +791,22 @@ fsdirconv(Chan *c, char *path, char *name, struct stat *s, uchar *va, int nb, in d.gid = u->name; d.muid = ""; d.qid = fsqid(s); +#endif //{} d.mode = (d.qid.type<<24)|(s->st_mode&0777); d.atime = s->st_atime; d.mtime = s->st_mtime; d.length = s->st_size; if(d.mode&DMDIR) d.length = 0; +#if 0 //{} else if(S_ISBLK(s->st_mode) && s->st_size == 0){ - fd = open(path, O_RDONLY); + fd = vfs.open(path, O_RDONLY); if(fd >= 0){ d.length = osdisksize(fd); close(fd); } } +#endif //{} d.type = 'U'; d.dev = c->dev; if(indir && sizeD2M(&d) > nb) @@ -796,11 +828,11 @@ fsdirread(Chan *c, uchar *va, int count, vlong offset) fspath(FS(c)->name, "", path); ep = path+strlen(path); if(FS(c)->offset != offset) { - seekdir(FS(c)->dir, 0); +//{} seekdir(FS(c)->dir, 0); FS(c)->de = nil; FS(c)->eod = 0; for(n=0; n<offset; ) { - de = readdir(FS(c)->dir); + de = vfs.readdir(FS(c)->dir); if(de == 0) { /* EOF, so stash offset and return 0 */ FS(c)->offset = n; @@ -844,7 +876,7 @@ fsdirread(Chan *c, uchar *va, int count, vlong offset) de = FS(c)->de; FS(c)->de = nil; if(de == nil) - de = readdir(FS(c)->dir); + de = vfs.readdir(FS(c)->dir); if(de == nil){ FS(c)->eod = 1; break; @@ -881,6 +913,7 @@ fsomode(int m) void setid(char *name, int owner) { +#if 0 //{} User *u; if(owner && !iseve()) @@ -899,8 +932,10 @@ setid(char *name, int owner) up->env->uid = u->id; up->env->gid = u->gid; qunlock(&idl); +#endif //{} } +#if 0 //{} static User** hashuser(User** tab, int id) { @@ -1076,12 +1111,14 @@ ingroup(int id, int gid) return 1; return 0; } +#endif //{} + Dev fsdevtab = { 'U', "fs", - devinit, + fsinit, fsattach, fswalk, fsstat, diff --git a/emu/FreeRTOS/devfs.c b/emu/FreeRTOS/devfs.c index d697d7b..877faaa 100644 --- a/emu/FreeRTOS/devfs.c +++ b/emu/FreeRTOS/devfs.c @@ -1,5 +1,6 @@ #include "devfs-posix.c" +#if 0 //{} #include <linux/hdreg.h> #include <linux/fs.h> #include <sys/ioctl.h> @@ -24,3 +25,4 @@ osdisksize(int fd) return (vlong)geo.heads*geo.sectors*geo.cylinders*512; return 0; } +#endif //{} diff --git a/emu/FreeRTOS/emu b/emu/FreeRTOS/emu index 3931b81..0141c36 100644 --- a/emu/FreeRTOS/emu +++ b/emu/FreeRTOS/emu @@ -22,7 +22,7 @@ dev # ip ipif6-posix ipaux # ip ipif-posix ipaux - eia +# eia # audio audio-oss mem diff --git a/emu/FreeRTOS/mkfile b/emu/FreeRTOS/mkfile index 27237d5..62ff5bc 100644 --- a/emu/FreeRTOS/mkfile +++ b/emu/FreeRTOS/mkfile @@ -48,7 +48,7 @@ CFLAGS='-DROOT="'$ROOT'"' -DEMU \ -I$ROOT/libiot/include \ $CTHREADFLAGS $CFLAGS $EMUOPTIONS #SYSLIBS= $X11LIBS -lm -lpthread -SYSLIBS= -lm -lpthread +SYSLIBS= -lm default:V: $O.$CONF diff --git a/libiot/vfs/include/esp_vfs.h b/libiot/vfs/include/esp_vfs.h index a0762d3..9e1136e 100644 --- a/libiot/vfs/include/esp_vfs.h +++ b/libiot/vfs/include/esp_vfs.h @@ -34,7 +34,7 @@ #include <string.h> //#include "sdkconfig.h" -#include "lwip/sockets.h" +//{} ??? #include "lwip/sockets.h" #ifdef __cplusplus extern "C" { @@ -193,10 +193,12 @@ typedef struct int (*ftruncate_p)(void* ctx, int fd, off_t length); int (*ftruncate)(int fd, off_t length); }; +#if 0 //{} union { int (*writev_p)(void* ctx, int fd, const struct iovec *iov, int iovcnt); int (*writev)(int fd, const struct iovec *iov, int iovcnt); }; +#endif //{} union { int (*select_p)(void* ctx, int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, struct timeval *timeout); int (*select)(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, struct timeval *timeout); @@ -415,7 +417,7 @@ void esp_vfs_select_triggered_isr(SemaphoreHandle_t *signal_sem, BaseType_t *wok * return value indicates a timed-out poll. -1 is return on failure and errno is set accordingly. * */ -int esp_vfs_poll(struct pollfd *fds, nfds_t nfds, int timeout); +//{} int esp_vfs_poll(struct pollfd *fds, nfds_t nfds, int timeout); #ifdef __cplusplus } // extern "C" diff --git a/libiot/vfs/vfs.c b/libiot/vfs/vfs.c index 2d40ee6..25bc385 100644 --- a/libiot/vfs/vfs.c +++ b/libiot/vfs/vfs.c @@ -263,6 +263,7 @@ ssize_t vfs_generic_write(vfs_fd_local_storage_t *local_storage, vfs_put_byte pu return bytes; } +#if 0 //{} ssize_t vfs_generic_writev(vfs_fd_local_storage_t *local_storage, vfs_put_byte put, int fd, const struct iovec *iov, int iovcnt) { int bytes = 0; int len = 0; @@ -284,6 +285,7 @@ ssize_t vfs_generic_writev(vfs_fd_local_storage_t *local_storage, vfs_put_byte p return bytes; } +#endif //{} int vfs_generic_select(vfs_fd_local_storage_t *local_storage, vfs_has_bytes has_bytes, vfs_free_bytes free_bytes, int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, struct timeval *timeout) { int to = 0xffffffff; // Default timeout diff --git a/libiot/vfs/vfs.h b/libiot/vfs/vfs.h index 4cea7c1..87fc29c 100644 --- a/libiot/vfs/vfs.h +++ b/libiot/vfs/vfs.h @@ -99,7 +99,7 @@ int vfs_fat_fsstat(const char *target, u32_t *total, u32_t *used); esp_vfs_t* vfs_spiffs_mount(const char *target); int vfs_spiffs_umount(const char *target); int vfs_spiffs_format(const char *target); -int vfs_spiffs_fsstat(const char *target, u32_t *total, u32_t *used); +//{} int vfs_spiffs_fsstat(const char *target, u32_t *total, u32_t *used); /* int vfs_lfs_mount(const char *target); |
