예제 #1
0
static void scr_status_init(void) {
		spiffs_file fd = SPIFFS_open(&fs, "u/status", SPIFFS_RDONLY, 0);
		if (fd >= 0) {
				SPIFFS_lseek(&fs, fd, 0, SPIFFS_SEEK_SET);
				scr_mngr_show_screen_with_param(SCR_WATCH_SET, 2<<24 | fd);
		}
}
예제 #2
0
파일: esp_fs.c 프로젝트: xzflin/smart.js
_off_t _lseek_r(struct _reent *r, int fd, _off_t where, int whence) {
    ssize_t res;
    if (fd < NUM_SYS_FD) {
        res = -1;
    } else {
        res = SPIFFS_lseek(&fs, fd - NUM_SYS_FD, where, whence);
    }
    set_errno(res);
    return res;
}
예제 #3
0
} TEST_END


TEST(zero_sized_file_44) {
  fs_reset();

  spiffs_file fd = SPIFFS_open(FS, "zero", SPIFFS_RDWR | SPIFFS_CREAT, 0);
  TEST_CHECK_GE(fd, 0);

  int res = SPIFFS_close(FS, fd);
  TEST_CHECK_GE(res, 0);

  fd = SPIFFS_open(FS, "zero", SPIFFS_RDWR, 0);
  TEST_CHECK_GE(fd, 0);

  u8_t buf[8];
  res = SPIFFS_read(FS, fd, buf, 8);
  TEST_CHECK_LT(res, 0);
  TEST_CHECK_EQ(SPIFFS_errno(FS), SPIFFS_ERR_END_OF_OBJECT);

  res = SPIFFS_read(FS, fd, buf, 0);
  TEST_CHECK_GE(res, 0);

  res = SPIFFS_read(FS, fd, buf, 0);
  TEST_CHECK_GE(res, 0);

  buf[0] = 1;
  buf[1] = 2;

  res = SPIFFS_write(FS, fd, buf, 2);
  TEST_CHECK_EQ(res, 2);

  res = SPIFFS_lseek(FS, fd, 0, SPIFFS_SEEK_SET);
  TEST_CHECK_GE(res, 0);

  u8_t b;
  res = SPIFFS_read(FS, fd, &b, 1);
  TEST_CHECK_EQ(res, 1);
  TEST_CHECK_EQ(b, 1);

  res = SPIFFS_read(FS, fd, &b, 1);
  TEST_CHECK_EQ(res, 1);
  TEST_CHECK_EQ(b, 2);

  res = SPIFFS_read(FS, fd, buf, 8);
  TEST_CHECK_LT(res, 0);
  TEST_CHECK_EQ(SPIFFS_errno(FS), SPIFFS_ERR_END_OF_OBJECT);

  return TEST_RES_OK;
} TEST_END
예제 #4
0
파일: file.c 프로젝트: Zhang-Jia/WiFiMCU
//file.seek(whence, offset)
static int file_seek (lua_State *L) 
{
  static const int mode[] = {SPIFFS_SEEK_SET, SPIFFS_SEEK_CUR, SPIFFS_SEEK_END};
  static const char *const modenames[] = {"set", "cur", "end", NULL};
  if(FILE_NOT_OPENED==file_fd)
    return luaL_error(L, "open a file first");
  int op = luaL_checkoption(L, 1, "cur", modenames);
  long offset = luaL_optlong(L, 2, 0);
  op = SPIFFS_lseek(&fs,file_fd, offset, mode[op]);
  if (op)
    lua_pushnil(L);  /* error */
  else
  {
    spiffs_fd *fd;
    spiffs_fd_get(&fs, file_fd, &fd);
    lua_pushinteger(L, fd->fdoffset);
  }
  return 1;
}
예제 #5
0
int run_file_config(int cfg_count, tfile_conf* cfgs, int max_runs, int max_concurrent_files, int dbg) {
  int res;
  tfile *tfiles = malloc(sizeof(tfile) * max_concurrent_files);
  memset(tfiles, 0, sizeof(tfile) * max_concurrent_files);
  int run = 0;
  int cur_config_ix = 0;
  char name[32];
  while (run < max_runs)  {
    if (dbg) printf(" run %i/%i\n", run, max_runs);
    int i;
    for (i = 0; i < max_concurrent_files; i++) {
      sprintf(name, "file%i_%i", (1+run), i);
      tfile *tf = &tfiles[i];
      if (tf->state == 0 && cur_config_ix < cfg_count) {
// create a new file
        strcpy(tf->name, name);
        tf->state = 1;
        tf->cfg = cfgs[cur_config_ix];
        int size = tfile_get_size(tf->cfg.tsize);
        if (dbg) printf("   create new %s with cfg %i/%i, size %i\n", name, (1+cur_config_ix), cfg_count, size);

        if (tf->cfg.tsize == EMPTY) {
          res = SPIFFS_creat(FS, name, 0);
          CHECK_RES(res);
          int pfd = open(make_test_fname(name), O_TRUNC | O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
          close(pfd);
          int extra_flags = tf->cfg.ttype == APPENDED ? SPIFFS_APPEND : 0;
          spiffs_file fd = SPIFFS_open(FS, name, extra_flags | SPIFFS_RDWR, 0);
          CHECK(fd > 0);
          tf->fd = fd;
        } else {
          int extra_flags = tf->cfg.ttype == APPENDED ? SPIFFS_APPEND : 0;
          spiffs_file fd = SPIFFS_open(FS, name, extra_flags | SPIFFS_TRUNC | SPIFFS_CREAT | SPIFFS_RDWR, 0);
          CHECK(fd > 0);
          extra_flags = tf->cfg.ttype == APPENDED ? O_APPEND : 0;
          int pfd = open(make_test_fname(name), extra_flags | O_TRUNC | O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
          tf->fd = fd;
          uint8_t *buf = malloc(size);
          memrand(buf, size);
          res = SPIFFS_write(FS, fd, buf, size);
          CHECK_RES(res);
          write(pfd, buf, size);
          close(pfd);
          free(buf);
          res = read_and_verify(name);
          CHECK_RES(res);
        }

        cur_config_ix++;
      } else if (tf->state > 0) {
// hande file lifecycle
        switch (tf->cfg.ttype) {
        case UNTAMPERED: {
          break;
        }
        case APPENDED: {
          if (dbg) printf("   appending %s\n", tf->name);
          int size = SPIFFS_DATA_PAGE_SIZE(FS)*3;
          uint8_t *buf = malloc(size);
          memrand(buf, size);
          res = SPIFFS_write(FS, tf->fd, buf, size);
          CHECK_RES(res);
          int pfd = open(make_test_fname(tf->name), O_APPEND | O_RDWR);
          write(pfd, buf, size);
          close(pfd);
          free(buf);
          res = read_and_verify(tf->name);
          CHECK_RES(res);
          break;
        }
        case MODIFIED: {
          if (dbg) printf("   modify %s\n", tf->name);
          spiffs_stat stat;
          res = SPIFFS_fstat(FS, tf->fd, &stat);
          CHECK_RES(res);
          int size = stat.size / tf->cfg.tlife + SPIFFS_DATA_PAGE_SIZE(FS)/3;
          int offs = (stat.size / tf->cfg.tlife) * tf->state;
          res = SPIFFS_lseek(FS, tf->fd, offs, SPIFFS_SEEK_SET);
          CHECK_RES(res);
          uint8_t *buf = malloc(size);
          memrand(buf, size);
          res = SPIFFS_write(FS, tf->fd, buf, size);
          CHECK_RES(res);
          int pfd = open(make_test_fname(tf->name), O_RDWR);
          lseek(pfd, offs, SEEK_SET);
          write(pfd, buf, size);
          close(pfd);
          free(buf);
          res = read_and_verify(tf->name);
          CHECK_RES(res);
          break;
        }
        case REWRITTEN: {
          if (tf->fd > 0) {
            SPIFFS_close(FS, tf->fd);
          }
          if (dbg) printf("   rewriting %s\n", tf->name);
          spiffs_file fd = SPIFFS_open(FS, tf->name, SPIFFS_TRUNC | SPIFFS_CREAT | SPIFFS_RDWR, 0);
          CHECK(fd > 0);
          int pfd = open(make_test_fname(tf->name), O_TRUNC | O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
          tf->fd = fd;
          int size = tfile_get_size(tf->cfg.tsize);
          uint8_t *buf = malloc(size);
          memrand(buf, size);
          res = SPIFFS_write(FS, fd, buf, size);
          CHECK_RES(res);
          write(pfd, buf, size);
          close(pfd);
          free(buf);
          res = read_and_verify(tf->name);
          CHECK_RES(res);
          break;
        }
        }
        tf->state++;
        if (tf->state > tf->cfg.tlife) {
// file outlived its time, kill it
          if (tf->fd > 0) {
            SPIFFS_close(FS, tf->fd);
          }
          if (dbg) printf("   removing %s\n", tf->name);
          res = read_and_verify(tf->name);
          CHECK_RES(res);
          res = SPIFFS_remove(FS, tf->name);
          CHECK_RES(res);
          remove(make_test_fname(tf->name));
          memset(tf, 0, sizeof(tf));
        }

      }
    }

    run++;
  }
  free(tfiles);
  return 0;
}
예제 #6
0
int myspiffs_ungetc( int c, int fd ){
  return SPIFFS_lseek(&fs, (spiffs_file)fd, -1, SEEK_CUR);
}
예제 #7
0
int myspiffs_lseek( int fd, int off, int whence ){
  return SPIFFS_lseek(&fs, (spiffs_file)fd, off, whence);
}
예제 #8
0
off_t fs_spiffs_lseek(int fd, off_t offset, int whence) {
  struct mount_info *m = &s_fsm;
  if (!m->valid) return set_errno(EBADF);
  return set_spiffs_errno(m, SPIFFS_lseek(&m->fs, fd, offset, whence));
}
예제 #9
0
size_t myspiffs_size( int fd ){
  int32_t curpos = SPIFFS_tell(&fs, (spiffs_file) fd);
  int32_t size = SPIFFS_lseek(&fs, (spiffs_file) fd, SPIFFS_SEEK_END, 0);
  (void) SPIFFS_lseek(&fs, (spiffs_file) fd, SPIFFS_SEEK_SET, curpos);
  return size;
}
예제 #10
0
파일: v7_fs.c 프로젝트: fast01/smart.js
ICACHE_FLASH_ATTR void spiffs_rewind(int fd) {
  int res = SPIFFS_lseek(&fs, fd, 0, SPIFFS_SEEK_SET);
  set_errno(res);
}
예제 #11
0
int fileSeek(file_t file, int offset, SeekOriginFlags origin)
{
  return SPIFFS_lseek(&_filesystemStorageHandle, file, offset, origin);
}
예제 #12
0
} TEST_END
#endif

TEST(eof_tell_72) {
  fs_reset();

  s32_t res;

  spiffs_file fd = SPIFFS_open(FS, "file", SPIFFS_CREAT | SPIFFS_RDWR | SPIFFS_APPEND, 0);
  TEST_CHECK_GT(fd, 0);
  TEST_CHECK_EQ(SPIFFS_eof(FS, fd), 1);
  TEST_CHECK_EQ(SPIFFS_tell(FS, fd), 0);

  res = SPIFFS_write(FS, fd, "test", 4);
  TEST_CHECK_EQ(res, 4);
  TEST_CHECK_EQ(SPIFFS_eof(FS, fd), 1);
  TEST_CHECK_EQ(SPIFFS_tell(FS, fd), 4);

  res = SPIFFS_fflush(FS, fd);
  TEST_CHECK_EQ(res, SPIFFS_OK);
  TEST_CHECK_EQ(SPIFFS_eof(FS, fd), 1);
  TEST_CHECK_EQ(SPIFFS_tell(FS, fd), 4);

  res = SPIFFS_lseek(FS, fd, 2, SPIFFS_SEEK_SET);
  TEST_CHECK_EQ(res, 2);
  TEST_CHECK_EQ(SPIFFS_eof(FS, fd), 0);
  TEST_CHECK_EQ(SPIFFS_tell(FS, fd), 2);

  res = SPIFFS_write(FS, fd, "test", 4);
  TEST_CHECK_EQ(res, 4);
  TEST_CHECK_EQ(SPIFFS_eof(FS, fd), 1);
  TEST_CHECK_EQ(SPIFFS_tell(FS, fd), 8);

  res = SPIFFS_fflush(FS, fd);
  TEST_CHECK_EQ(res, SPIFFS_OK);
  TEST_CHECK_EQ(SPIFFS_eof(FS, fd), 1);
  TEST_CHECK_EQ(SPIFFS_tell(FS, fd), 8);

  res = SPIFFS_close(FS, fd);
  TEST_CHECK_EQ(res, SPIFFS_OK);
  TEST_CHECK_LT(SPIFFS_eof(FS, fd), SPIFFS_OK);
  TEST_CHECK_LT(SPIFFS_tell(FS, fd), SPIFFS_OK);

  fd = SPIFFS_open(FS, "file", SPIFFS_RDWR, 0);
  TEST_CHECK_GT(fd, 0);
  TEST_CHECK_EQ(SPIFFS_eof(FS, fd), 0);
  TEST_CHECK_EQ(SPIFFS_tell(FS, fd), 0);

  res = SPIFFS_lseek(FS, fd, 2, SPIFFS_SEEK_SET);
  TEST_CHECK_EQ(res, 2);
  TEST_CHECK_EQ(SPIFFS_eof(FS, fd), 0);
  TEST_CHECK_EQ(SPIFFS_tell(FS, fd), 2);

  res = SPIFFS_write(FS, fd, "test", 4);
  TEST_CHECK_EQ(res, 4);
  TEST_CHECK_EQ(SPIFFS_eof(FS, fd), 0);
  TEST_CHECK_EQ(SPIFFS_tell(FS, fd), 6);

  res = SPIFFS_fflush(FS, fd);
  TEST_CHECK_EQ(res, SPIFFS_OK);
  TEST_CHECK_EQ(SPIFFS_eof(FS, fd), 0);
  TEST_CHECK_EQ(SPIFFS_tell(FS, fd), 6);

  res = SPIFFS_lseek(FS, fd, 0, SPIFFS_SEEK_END);
  TEST_CHECK_EQ(res, 8);
  TEST_CHECK_EQ(SPIFFS_eof(FS, fd), 1);
  TEST_CHECK_EQ(SPIFFS_tell(FS, fd), 8);

  return TEST_RES_OK;
} TEST_END