Ejemplo n.º 1
0
/**
 * addr_offset
 */
void fs_reset_specific(u32_t addr_offset, u32_t phys_addr, u32_t phys_size,
    u32_t phys_sector_size,
    u32_t log_block_size, u32_t log_page_size) {
  fs_create(phys_size + phys_addr - addr_offset,
            phys_sector_size,
            log_page_size,
            DEFAULT_NUM_FD,
            DEFAULT_NUM_CACHE_PAGES);
  fs_set_addr_offset(addr_offset);
  memset(&AREA(addr_offset), 0xcc, _area_sz);
  memset(&AREA(phys_addr), 0xff, phys_size);
  memset(&__fs, 0, sizeof(__fs));

  s32_t res = fs_mount_specific(phys_addr, phys_size, phys_sector_size, log_block_size, log_page_size);

#if SPIFFS_USE_MAGIC
  if (res == SPIFFS_OK) {
    SPIFFS_unmount(&__fs);
  }
  res = SPIFFS_format(&__fs);
  if (res != SPIFFS_OK) {
    printf("format failed, %i\n", SPIFFS_errno(&__fs));
  }
  res = fs_mount_specific(phys_addr, phys_size, phys_sector_size, log_block_size, log_page_size);
  if (res != SPIFFS_OK) {
    printf("mount failed, %i\n", SPIFFS_errno(&__fs));
  }
#endif

  clear_flash_ops_log();
  log_flash_ops = 1;
  fs_check_fixes = 0;
}
Ejemplo n.º 2
0
void fs_reset_specific(uint32_t addr_offset, uint32_t phys_addr, uint32_t phys_size,
    uint32_t phys_sector_size,
    uint32_t log_block_size, uint32_t log_page_size) {
  fs_set_addr_offset(addr_offset);
  memset(area, 0xcc, sizeof(area));
  memset(&AREA(phys_addr), 0xff, phys_size);
  memset(&__fs, 0, sizeof(__fs));

  memset(erases,0,sizeof(erases));
  memset(_cache,0,sizeof(_cache));

  int32_t res = fs_mount_specific(phys_addr, phys_size, phys_sector_size, log_block_size, log_page_size);

#if SPIFFS_USE_MAGIC
  if (res == SPIFFS_OK) {
    SPIFFS_unmount(&__fs);
  }
  res = SPIFFS_format(&__fs);
  if (res != SPIFFS_OK) {
    printf("format failed, %i\n", SPIFFS_errno(&__fs));
  }
  res = fs_mount_specific(phys_addr, phys_size, phys_sector_size, log_block_size, log_page_size);
  if (res != SPIFFS_OK) {
    printf("mount failed, %i\n", SPIFFS_errno(&__fs));
  }
#endif

  clear_flash_ops_log();
  log_flash_ops = 1;
  fs_check_fixes = 0;
}
Ejemplo n.º 3
0
void copy(char *path, char *fname) {
  int size;
  u8_t *buf;
  struct stat st;
  spiffs_file sfd;
  int ifd;

  ifd = open(path, O_RDONLY);
  if (ifd == -1) {
    fprintf(stderr, "cannot open %s\n", path);
    perror("cannot open");
    return;
  }

  if (fstat(ifd, &st) == -1) {
    fprintf(stderr, "cannot stat %s\n", path);
    return;
  }
  size = st.st_size;

  if (size == -1) {
    fprintf(stderr, "skipping %s\n", path);
    return;
  }

  buf = malloc(size);

  if (read(ifd, buf, size) != size) {
    fprintf(stderr, "unable to read file %s\n", fname);
    return;
  }

  if ((sfd = SPIFFS_open(&fs, fname, SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_RDWR,
                         0)) == -1) {
    fprintf(stderr, "SPIFFS_open %s failed: %d\n", fname, SPIFFS_errno(&fs));
    goto cleanup;
  }

  if (SPIFFS_write(&fs, sfd, (uint8_t *) buf, size) == -1) {
    fprintf(stderr, "SPIFFS_write %s failed: %d\n", fname, SPIFFS_errno(&fs));
    goto spifs_cleanup;
  }

  fprintf(stderr, "a %s\n", fname);

spifs_cleanup:
  SPIFFS_close(&fs, sfd);
cleanup:
  free(buf);
  close(ifd);
}
Ejemplo n.º 4
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
Ejemplo n.º 5
0
void test_spiffs() {
  char buf[12];

  // Surely, I've mounted spiffs before entering here
  
  spiffs_file fd = SPIFFS_open(&fs, "my_file", SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_RDWR, 0);
  if (SPIFFS_write(&fs, fd, (u8_t *)"Hello world", 12) < 0) NODE_DBG("errno %i\n", SPIFFS_errno(&fs));
  SPIFFS_close(&fs, fd); 

  fd = SPIFFS_open(&fs, "my_file", SPIFFS_RDWR, 0);
  if (SPIFFS_read(&fs, fd, (u8_t *)buf, 12) < 0) NODE_DBG("errno %i\n", SPIFFS_errno(&fs));
  SPIFFS_close(&fs, fd);

  NODE_DBG("--> %s <--\n", buf);
}
Ejemplo n.º 6
0
void test_spiffs()
{
  char buf[12] = {0};

  // Surely, I've mounted spiffs before entering here
  
  spiffs_file fd;
  spiffs_stat st = {0};
  SPIFFS_stat(&_filesystemStorageHandle, "my_file.txt", &st);
  if (st.size <= 0)
  {
	  fd = SPIFFS_open(&_filesystemStorageHandle, "my_file.txt", SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_RDWR, 0);
	  if (SPIFFS_write(&_filesystemStorageHandle, fd, (u8_t *)"Hello world", 11) < 0)
		  debugf("errno %d\n", SPIFFS_errno(&_filesystemStorageHandle));
	  SPIFFS_close(&_filesystemStorageHandle, fd);
	  debugf("file created");
  }
  else
	  debugf("file %s exist :)", st.name);


  fd = SPIFFS_open(&_filesystemStorageHandle, "my_file.txt", SPIFFS_RDWR, 0);
  if (SPIFFS_read(&_filesystemStorageHandle, fd, (u8_t *)buf, 11) < 0) debugf("errno %d\n", SPIFFS_errno(&_filesystemStorageHandle));
  SPIFFS_close(&_filesystemStorageHandle, fd);

  debugf("--> %s <--\n", buf);
}
Ejemplo n.º 7
0
static void test_on_stop(test *t) {
  printf("  spiffs errno:%i\n", SPIFFS_errno(&__fs));
#if SPIFFS_TEST_VISUALISATION
  SPIFFS_vis(FS);
#endif

}
Ejemplo n.º 8
0
void set_errno(int res) {
  if (res < 0) {
    errno = SPIFFS_errno(&fs);
    /* NOTE(lsm): use DEBUG level, as "not found" error -10002 is too noisy */
    LOG(LL_DEBUG, ("spiffs error: %d", errno));
  }
}
Ejemplo n.º 9
0
Archivo: fs.c Proyecto: pellepl/wisleep
int32_t fs_mount(void) {
  int32_t res;
  const uint32_t fs_size =
      (sdk_flashchip.chip_size / 8 - SPI_FLASH_SEC_SIZE * FS_SLACK_END_SECTORS) & ~(FS_BLOCK_SZ-1);
  const uint32_t fs_addr =
      (sdk_flashchip.chip_size - fs_size - SPI_FLASH_SEC_SIZE * FS_SLACK_END_SECTORS)  & ~(FS_BLOCK_SZ-1);
  spiffs_config cfg = {
      .hal_read_f = _spiffs_hal_read,
      .hal_write_f = _spiffs_hal_write,
      .hal_erase_f = _spiffs_hal_erase,
      .phys_size = fs_size,
      .phys_addr = fs_addr,
      .phys_erase_block = SPI_FLASH_SEC_SIZE,
      .log_block_size = FS_BLOCK_SZ,
      .log_page_size = FS_PAGE_SZ,
      .fh_ix_offset = SPIFFS_FILEHDL_OFFSET_NUM
  };
  printf("mounting fs @ 0x%08x, %i kbytes\n", fs_addr, fs_size / 1024);
  res = SPIFFS_mount(FS,
      &cfg, (uint8_t *)_fs_work,
      (uint8_t *)_fs_desc, sizeof(_fs_desc),
      (uint8_t *)_fs_cache, sizeof(_fs_cache),
      _spiffs_check_cb_f);
  if (res != SPIFFS_OK && SPIFFS_errno(FS) == SPIFFS_ERR_NOT_A_FS) {
    printf("fs format\n");
    SPIFFS_clearerr(FS);
    res = SPIFFS_format(FS);
    if (res == SPIFFS_OK) {
      printf("remount\n");
      res = SPIFFS_mount(FS,
          &cfg, (uint8_t *)_fs_work,
          (uint8_t *)_fs_desc, sizeof(_fs_desc),
          (uint8_t *)_fs_cache, sizeof(_fs_cache),
          _spiffs_check_cb_f);
    }
  }
  if (res != SPIFFS_OK) {
    printf("err fs mount %i\n", res);
  } else {
    uint32_t total, used;
    SPIFFS_info(FS, &total, &used);
    printf("mounted fs: total %i kbytes, used %i kbytes\n", total / 1024, used / 1024);
  }
  printf("mount result:%i\n", SPIFFS_errno(FS));

  return res;
}
Ejemplo n.º 10
0
size_t myspiffs_read( int fd, void* ptr, size_t len){
  int res = SPIFFS_read(&fs, (spiffs_file)fd, ptr, len);
  if (res < 0) {
    NODE_DBG("read errno %i\n", SPIFFS_errno(&fs));
    return 0;
  }
  return res;
}
Ejemplo n.º 11
0
size_t fileRead(file_t file, void* data, size_t size)
{
  int res = SPIFFS_read(&_filesystemStorageHandle, file, data, size);
  if (res < 0)
  {
    debugf("read errno %d\n", SPIFFS_errno(&_filesystemStorageHandle));
    return res;
  }
  return res;
}
Ejemplo n.º 12
0
size_t fileWrite(file_t file, const void* data, size_t size)
{
  int res = SPIFFS_write(&_filesystemStorageHandle, file, (void *)data, size);
  if (res < 0)
  {
    debugf("write errno %d\n", SPIFFS_errno(&_filesystemStorageHandle));
    return res;
  }
  return res;
}
Ejemplo n.º 13
0
void ICACHE_FLASH_ATTR
test_spiffs() {
  spiffs_config cfg;
  cfg.phys_size = PHYS_FLASH_SIZE; // use all spi flash
  cfg.phys_addr = SPIFFS_FLASH_SIZE; // start spiffs at start of spi flash
  cfg.phys_erase_block = SECTOR_SIZE; // according to datasheet
  cfg.log_block_size = LOG_BLOCK; // let us not complicate things
  cfg.log_page_size = LOG_PAGE; // as we said
  
  cfg.hal_read_f = my_spiffs_read;
  cfg.hal_write_f = my_spiffs_write;
  cfg.hal_erase_f = my_spiffs_erase;
  
  int res = SPIFFS_mount(&fs,
    &cfg,
    spiffs_work_buf,
    spiffs_fds,
    sizeof(spiffs_fds),
    spiffs_cache_buf,
    sizeof(spiffs_cache_buf),
    0);
  os_printf("mount res: %d\n", res);

  char buf[12];
  // Surely, I've mounted spiffs before entering here
  spiffs_file fd = SPIFFS_open(&fs, "my_file", SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_RDWR, 0);
  os_printf("fd = %d\n", fd);
  if (SPIFFS_write(&fs, fd, (u8_t *)"Hello world", 12) < 0) {
    os_printf("errno %d\n", SPIFFS_errno(&fs));
    return;
  }
  SPIFFS_close(&fs, fd); 

  fd = SPIFFS_open(&fs, "my_file", SPIFFS_RDWR, 0);
  if (SPIFFS_read(&fs, fd, (u8_t *)buf, 12) < 0) {
    os_printf("errno %d\n", SPIFFS_errno(&fs));
    return;
  }
  SPIFFS_close(&fs, fd);

  os_printf("--> %s <--\n", buf);
}
Ejemplo n.º 14
0
} TEST_END


TEST(spiffs_12) {
  fs_reset_specific(0x4024c000, 0x4024c000 + 0, 192*1024, 4096, 4096*2, 256);

  int res;
  spiffs_file fd;
  int j = 1;

  while (1) {
    char fname[32];
    sprintf(fname, "file%i.txt", j);
    fd = SPIFFS_open(FS, fname, SPIFFS_RDWR | SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_DIRECT, 0);
    if (fd <=0) break;

    int i;
    res = SPIFFS_OK;
    for (i = 1; i <= 100; i++) {
      char *buf = "0123456789ABCDE\n";
      res = SPIFFS_write(FS, fd, buf, strlen(buf));
      if (res < 0) break;
    }
    SPIFFS_close(FS, fd);
    j++;
  }

  int errno = SPIFFS_errno(FS);
  TEST_CHECK(errno == SPIFFS_ERR_FULL);

  u32_t total;
  u32_t used;

  SPIFFS_info(FS, &total, &used);
  printf("total:%i (%iK)\nused:%i (%iK)\nremain:%i (%iK)\nerrno:%i\n", total, total/1024, used, used/1024, total-used, (total-used)/1024, errno);

  spiffs_DIR d;
  struct spiffs_dirent e;
  struct spiffs_dirent *pe = &e;

  SPIFFS_opendir(FS, "/", &d);
  while ((pe = SPIFFS_readdir(&d, pe))) {
    printf("%s [%04x] size:%i\n", pe->name, pe->obj_id, pe->size);
  }
  SPIFFS_closedir(&d);

  //SPIFFS_vis(FS);

  //dump_page(FS, 0);
  //dump_page(FS, 1);

  return TEST_RES_OK;

} TEST_END
Ejemplo n.º 15
0
} TEST_END

TEST(nodemcu_309) {
  fs_reset_specific(0, 0, 4096*20, 4096, 4096, 256);

  int res;
  spiffs_file fd;
  int j;

  for (j = 1; j <= 3; j++) {
    char fname[32];
    sprintf(fname, "20K%i.txt", j);
    fd = SPIFFS_open(FS, fname, SPIFFS_RDWR | SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_DIRECT, 0);
    TEST_CHECK(fd > 0);
    int i;
    spiffs_stat s;
    res = SPIFFS_OK;
    u8_t err = 0;
    for (i = 1; i <= 1280; i++) {
      char *buf = "0123456789ABCDE\n";
      res = SPIFFS_write(FS, fd, buf, strlen(buf));
      if (!err && res < 0) {
        printf("err @ %i,%i\n", i, j);
        err = 1;
      }
    }
  }

  int errno = SPIFFS_errno(FS);
  TEST_CHECK(errno == SPIFFS_ERR_FULL);

  u32_t total;
  u32_t used;

  SPIFFS_info(FS, &total, &used);
  printf("total:%i\nused:%i\nremain:%i\nerrno:%i\n", total, used, total-used, errno);
  //TEST_CHECK(total-used < 11000); // disabled, depends on too many variables

  spiffs_DIR d;
  struct spiffs_dirent e;
  struct spiffs_dirent *pe = &e;

  SPIFFS_opendir(FS, "/", &d);
  int spoon_guard = 0;
  while ((pe = SPIFFS_readdir(&d, pe))) {
    printf("%s [%04x] size:%i\n", pe->name, pe->obj_id, pe->size);
    TEST_CHECK(spoon_guard++ < 3);
  }
  TEST_CHECK(spoon_guard == 3);
  SPIFFS_closedir(&d);

  return TEST_RES_OK;

} TEST_END
Ejemplo n.º 16
0
int fs_mount(spiffs *spf, uint32_t addr, uint32_t size, uint8_t *workbuf,
             uint8_t *fds, size_t fds_size) {
  LOG(LL_DEBUG, ("Mount %d@%X", size, addr));
  spiffs_config cfg;

  cfg.phys_addr = addr;
  cfg.phys_size = size;

  cfg.phys_erase_block = FLASH_BLOCK_SIZE;
  cfg.log_block_size = FLASH_BLOCK_SIZE;
  cfg.log_page_size = LOG_PAGE_SIZE;

  cfg.hal_read_f = esp_spiffs_read;
  cfg.hal_write_f = esp_spiffs_write;
  cfg.hal_erase_f = esp_spiffs_erase;

  if (SPIFFS_mount(spf, &cfg, workbuf, fds, fds_size, 0, 0, 0) != SPIFFS_OK) {
    LOG(LL_ERROR, ("SPIFFS_mount failed: %d", SPIFFS_errno(spf)));
    return SPIFFS_errno(spf);
  }

  return 0;
}
Ejemplo n.º 17
0
size_t myspiffs_write( int fd, const void* ptr, size_t len ){
#if 0
  if(fd==c_stdout || fd==c_stderr){
    uart0_tx_buffer((u8_t*)ptr, len);
    return len;
  }
#endif
  int res = SPIFFS_write(&fs, (spiffs_file)fd, (void *)ptr, len);
  if (res < 0) {
    NODE_DBG("write errno %i\n", SPIFFS_errno(&fs));
    return 0;
  }
  return res;
}
Ejemplo n.º 18
0
int myspiffs_getc( int fd ){
  unsigned char c = 0xFF;
  int res;
  if(!myspiffs_eof(fd)){
    res = SPIFFS_read(&fs, (spiffs_file)fd, &c, 1);
    if (res != 1) {
      NODE_DBG("getc errno %i\n", SPIFFS_errno(&fs));
      return (int)EOF;
    } else {
      return (int)c;
    }
  }
  return (int)EOF;
}
Ejemplo n.º 19
0
} TEST_END

#if !SPIFFS_READ_ONLY
TEST(truncate_48) {
  fs_reset();

  u32_t len = SPIFFS_DATA_PAGE_SIZE(FS)/2;

  s32_t res = test_create_and_write_file("small", len, len);
  TEST_CHECK_GE(res, 0);

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

  spiffs_fd *desc;
#if SPIFFS_FILEHDL_OFFSET
  res = spiffs_fd_get(FS, fd - TEST_SPIFFS_FILEHDL_OFFSET, &desc);
#else
  res = spiffs_fd_get(FS, fd, &desc);
#endif

  TEST_CHECK_GE(res, 0);

  TEST_CHECK_EQ(desc->size, len);

  u32_t new_len = len/2;
  res = spiffs_object_truncate(desc, new_len, 0);
  TEST_CHECK_GE(res, 0);

  TEST_CHECK_EQ(desc->size, new_len);

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

  spiffs_stat s;
  res = SPIFFS_stat(FS, "small", &s);
  TEST_CHECK_GE(res, 0);
  TEST_CHECK_EQ(s.size, new_len);

  res = SPIFFS_remove(FS, "small");
  TEST_CHECK_GE(res, 0);

  fd = SPIFFS_open(FS, "small", SPIFFS_RDWR, 0);
  TEST_CHECK_LT(fd, 0);
  TEST_CHECK_EQ(SPIFFS_errno(FS), SPIFFS_ERR_NOT_FOUND);

  return TEST_RES_OK;
} TEST_END
Ejemplo n.º 20
0
int main(int argc, char **argv) {
  const char *root_dir;
  DIR *dir;

  if (argc < 3) {
    fprintf(stderr, "usage: %s <size> <root_dir>\n", argv[0]);
    return 1;
  }

  image_size = atoi(argv[1]);
  if (image_size == 0) {
    fprintf(stderr, "invalid size '%s'\n", argv[1]);
    return 1;
  }
  root_dir = argv[2];

  image = malloc(image_size);
  if (image == NULL) {
    fprintf(stderr, "cannot allocate %lu bytes\n", image_size);
    return 1;
  }

  mem_spiffs_erase(0, image_size);
  mem_spiffs_mount();  // Will fail but is required.
  SPIFFS_format(&fs);
  if (mem_spiffs_mount() != SPIFFS_OK) {
    fprintf(stderr, "SPIFFS_mount failed: %d\n", SPIFFS_errno(&fs));
    return 1;
  }

  fprintf(stderr, "adding files in directory %s\n", root_dir);
  if ((dir = opendir(root_dir)) == NULL) {
    fprintf(stderr, "unable to open directory %s\n", root_dir);
    return 1;
  } else {
    read_dir(dir, root_dir);
  }

  fwrite(image, image_size, 1, stdout);

  u32_t total, used;
  SPIFFS_info(&fs, &total, &used);
  fprintf(stderr, "Image stats: size=%u, space: total=%u, used=%u, free=%u\n",
          (unsigned int) image_size, total, used, total - used);

  return 0;
}
Ejemplo n.º 21
0
file_t fileOpen(const String name, FileOpenFlags flags)
{
  int res;

  // Special fix to prevent known spifFS bug: manual delete file
  if ((flags & eFO_CreateNewAlways) == eFO_CreateNewAlways)
  {
	  if (fileExist(name))
		  fileDelete(name);
	  flags = (FileOpenFlags)((int)flags & ~eFO_Truncate);
  }

  res = SPIFFS_open(&_filesystemStorageHandle, name.c_str(), (spiffs_flags)flags, 0);
  if (res < 0)
	  debugf("open errno %d\n", SPIFFS_errno(&_filesystemStorageHandle));

  return res;
}
Ejemplo n.º 22
0
} TEST_END


TEST(robert) {
  // create a clean file system starting at address 0, 2 megabytes big,
  // sector size 65536, block size 65536, page size 256
  fs_reset_specific(0, 0, 1024*1024*2, 65536, 65536, 256);

  int res;
  spiffs_file fd;
  char fname[32];

  sprintf(fname, "test.txt");
  fd = SPIFFS_open(FS, fname, SPIFFS_RDWR | SPIFFS_CREAT | SPIFFS_TRUNC, 0);
  TEST_CHECK(fd > 0);
  int i;
  res = SPIFFS_OK;
  char buf[500];
  memset(buf, 0xaa, 500);
  res = SPIFFS_write(FS, fd, buf, 500);
  TEST_CHECK(res >= SPIFFS_OK);
  SPIFFS_close(FS, fd);

  int errno = SPIFFS_errno(FS);
  TEST_CHECK(errno == SPIFFS_OK);

  //SPIFFS_vis(FS);
  // unmount
  SPIFFS_unmount(FS);

  // remount
  res = fs_mount_specific(0, 1024*1024*2, 65536, 65536, 256);
  TEST_CHECK(res== SPIFFS_OK);

  //SPIFFS_vis(FS);

  spiffs_stat s;
  TEST_CHECK(SPIFFS_stat(FS, fname, &s) == SPIFFS_OK);
  printf("file %s stat size %i\n", s.name, s.size);
  TEST_CHECK(s.size == 500);

  return TEST_RES_OK;

} TEST_END
Ejemplo n.º 23
0
void mem_spiffs_mount() {
  spiffs_config cfg;

  cfg.phys_size = image_size;
  cfg.phys_addr = 0;

  cfg.phys_erase_block = FLASH_BLOCK_SIZE;
  cfg.log_block_size = FLASH_BLOCK_SIZE;
  cfg.log_page_size = LOG_PAGE_SIZE;

  cfg.hal_read_f = mem_spiffs_read;
  cfg.hal_write_f = mem_spiffs_write;
  cfg.hal_erase_f = mem_spiffs_erase;

  if (SPIFFS_mount(&fs, &cfg, spiffs_work_buf, spiffs_fds, sizeof(spiffs_fds),
                   0, 0, 0) == -1) {
    fprintf(stderr, "SPIFFS_mount failed: %d\n", SPIFFS_errno(&fs));
  }
}
static int fs_mount_idx(const char *cpfx, int cidx, struct mount_info *m) {
  int r;
  struct fs_container_info fsi;
  memset(m, 0, sizeof(*m));
  m->fh = -1;
  m->cidx = cidx;
  r = fs_get_info(cpfx, cidx, &fsi);
  if (r != 0) return r;
  m->cpfx = strdup(cpfx);
  m->seq = fsi.seq;
  m->valid = 1;
  LOG(LL_INFO, ("Mounting %s.%d 0x%llx", cpfx, cidx, fsi.seq));
  r = fs_mount_spiffs(m, fsi.fs_size, fsi.fs_block_size, fsi.fs_page_size,
                      fsi.fs_erase_size);
  DBG(("mount %d: %d %d", cidx, (int) r, (int) SPIFFS_errno(&m->fs)));
  if (r < 0) {
    LOG(LL_ERROR, ("Mount failed: %d", r));
  }
  return r;
}
Ejemplo n.º 25
0
int fs_mount(spiffs *spf, uint32_t addr, uint32_t size, uint8_t *workbuf,
             uint8_t *fds, size_t fds_size) {
    spiffs_config cfg;

    /* FS_SIZE & FS_ADDR are provided via Makefile */
    cfg.phys_addr = addr;
    cfg.phys_size = size;

    cfg.phys_erase_block = FLASH_BLOCK_SIZE;
    cfg.log_block_size = FLASH_BLOCK_SIZE;
    cfg.log_page_size = LOG_PAGE_SIZE;

    cfg.hal_read_f = esp_spiffs_read;
    cfg.hal_write_f = esp_spiffs_write;
    cfg.hal_erase_f = esp_spiffs_erase;

    if (SPIFFS_mount(spf, &cfg, workbuf, fds, fds_size, 0, 0, 0) != SPIFFS_OK) {
        return SPIFFS_errno(spf);
    }

    return 0;
}
Ejemplo n.º 26
0
void RamSpiffs::doInterrumptedWrite(){

    m_verbose = true;
    m_interruptTimer = 2;

    spiffs_file fd;

    const char *msg = "CALIFORNIA";
    int msglen = strlen(msg)+1;
    fd = SPIFFS_open(fs(), "interrupted.txt", SPIFFS_CREAT | SPIFFS_TRUNC | SPIFFS_RDWR, 0);

    // write a 2Kb file
    int i;
    for(i = 0; i < 4; i++){
        if (SPIFFS_write(fs(), fd, (u8_t *)msg, msglen) < 0){
            printf("errno %i\n", (int) SPIFFS_errno(fs()));
        }
    }

    SPIFFS_close(fs(), fd);

    m_verbose = false;
}
Ejemplo n.º 27
0
ICACHE_FLASH_ATTR void set_errno(int res) {
  if (res < 0) {
    errno = SPIFFS_errno(&fs);
  }
}
Ejemplo n.º 28
0
ICACHE_FLASH_ATTR int spiffs_ferror(int fd) {
  return SPIFFS_errno(&fs);
}
Ejemplo n.º 29
0
int myspiffs_error( int fd ){
  return SPIFFS_errno(&fs);
}
Ejemplo n.º 30
0
static int set_spiffs_errno(struct mount_info *m, int res) {
  int e = SPIFFS_errno(&m->fs);
  dprintf(("res = %d, e = %d\n", res, e));
  if (res >= 0) return res;
  return set_errno(spiffs_err_to_errno(e));
}