static int esp8266_Sync(sqlite3_file *id, int flags) { esp8266_file *file = (esp8266_file*) id; int rc = vfs_flush( file->fd ); dbg_printf("esp8266_Sync: %d\n", rc); return rc ? SQLITE_IOERR_FSYNC : SQLITE_OK; }
int fsync(int fd) { struct fdtab_entry *e = fdtab_get(fd); switch(e->type) { case FDTAB_TYPE_FILE: { errval_t err = vfs_flush((vfs_handle_t)e->handle); if(err_is_fail(err)) { return -1; } } break; default: errno = EINVAL; return -1; } return 0; }
static int rand_bench_time(char *target, uint8_t *buffer, size_t filesize, size_t blocksize, size_t count, size_t randval, struct bench_res *result) { size_t randbit; size_t rsize = 0; size_t wsize = 0; int ret = 0; #define RAND_NEXT do {\ randbit = ((randval >> 0) ^ (randval >> 3)) & 1;\ randval = (randval >> 1) | (randbit << (sizeof(size_t) * CHAR_BIT - 1));\ } while (0) #define RAND_BLOCK ((randval % (filesize / blocksize)) * blocksize) if (filesize % blocksize != 0) { printf("Please spcifiy the filesize as a multiple of blocksize\n"); return 0; } errval_t err; vfs_handle_t f = NULL; char *path = vfs_path_mkabsolute(cwd, target); err = vfs_open(path, &f); if (err_is_fail(err)) { printf("%s: %s\n", path, err_getstring(err)); return 1; } #if defined(__x86_64__) || defined(__i386__) uint64_t tscperms; err = sys_debug_get_tsc_per_ms(&tscperms); assert(err_is_ok(err)); //printf("ticks per millisec: %" PRIu64 "\n", tscperms); uint64_t start = rdtsc(); #endif size_t count2 = count; while (count2--) { RAND_NEXT; vfs_seek(f, VFS_SEEK_SET, RAND_BLOCK); err = vfs_read(f, buffer, blocksize, &rsize); if (err_is_fail(err)) { DEBUG_ERR(err, "error reading file"); ret = 1; goto out; } assert(rsize == blocksize); } #if defined(__x86_64__) || defined(__i386__) uint64_t stop = rdtsc(); uint64_t elapsed_msecs = ((stop - start) / tscperms); double elapsed_secs = (double)elapsed_msecs/1000.0; result->read = elapsed_secs; start = rdtsc(); #endif count2 = count; while(count2--) { RAND_NEXT; vfs_seek(f, VFS_SEEK_SET, RAND_BLOCK); err = vfs_write(f, buffer, blocksize, &wsize); if (err_is_fail(err) || wsize == 0) { DEBUG_ERR(err, "error writing file"); ret = 1; goto out; } assert(wsize == blocksize); vfs_flush(f); } #if defined(__x86_64__) || defined(__i386__) stop = rdtsc(); elapsed_msecs = ((stop - start) / tscperms); elapsed_secs = (double)elapsed_msecs/1000.0; result->write = elapsed_secs; #endif out: if (f != NULL) { err = vfs_close(f); if (err_is_fail(err)) { DEBUG_ERR(err, "in vfs_close"); } } return ret; }