Skip to content

Commit

Permalink
Remove filesystem flattening hack use subdirs
Browse files Browse the repository at this point in the history
Remove the hack that replaced the dir tree with files in the root
directory.  ESP8266 LittleFS now handles subdirs.
  • Loading branch information
Earle F. Philhower, III authored and Earle F. Philhower, III committed Dec 17, 2018
1 parent 5166def commit 54d5f95
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 33 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# mklittlefs
Tool to build and unpack [littlefs](https://github.com/ARMmbed/littlefs) images.

Based off of [mkspiffs](https://github.com/igrr/mkspiffs) by Ivan Grokhotkov.

## Usage

Expand Down
36 changes: 4 additions & 32 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,6 @@ int lfs_flash_sync(const struct lfs_config *c) {
}


// Because "/" is an actual full-fledged dir separator in LFS, we need to
// replace it with a reserved character to avoid dir-not-found/etc.
// problems when using ported SPIFFS apps.
static char *spiffsNameToLFS(const char *src, char *dst) {
char *ret = dst;
char c;
while (0 != (c = *(src++))) {
*(dst++) = (c=='/')?0x01:c;
}
*dst = 0;
// Strip leading "/"s
while ((*ret) == 0x01) ret++;
return ret;
}
static char *lfsNameToSPIFFS(const char *src, char *dst) {
char *ret = dst;
char c;
while (0 != (c = *(src++))) {
*(dst++) = (c==0x01)?'/':c;
}
*dst = 0;
return ret;
}


// Implementation

static lfs_t s_fs;
Expand Down Expand Up @@ -162,9 +137,8 @@ int addFile(char* name, const char* path) {
return 1;
}

char lfsName[LFS_NAME_MAX+1];
lfs_file_t dst;
int ret = lfs_file_open(&s_fs, &dst, spiffsNameToLFS(name, lfsName), LFS_O_CREAT | LFS_O_TRUNC | LFS_O_WRONLY);
int ret = lfs_file_open(&s_fs, &dst, name, LFS_O_CREAT | LFS_O_TRUNC | LFS_O_WRONLY);
if (ret < 0) {
std::cerr << "unable to open '" << name << "." << std::endl;
return 1;
Expand Down Expand Up @@ -322,7 +296,7 @@ void listFiles() {
continue;
}

std::cout << it.size << '\t' << lfsNameToSPIFFS(it.name, it.name) << std::endl;
std::cout << it.size << '\t' << it.name << std::endl;
}
lfs_dir_close(&s_fs, &dir);
lfs_unmount(&s_fs);
Expand Down Expand Up @@ -452,9 +426,7 @@ bool unpackFiles(std::string sDest) {

// Check if content is a file.
if ((int)(ent.type) == LFS_TYPE_REG) {
char realName[LFS_NAME_MAX+1];
lfsNameToSPIFFS(ent.name, realName);
std::string name = (const char*)(realName);
std::string name = (const char*)(ent.name);
std::string sDestFilePath = sDest + name;
size_t pos = name.find_first_of("/", 1);

Expand Down Expand Up @@ -482,7 +454,7 @@ bool unpackFiles(std::string sDest) {

// Output stuff.
std::cout
<< realName
<< ent.name
<< '\t'
<< " > " << sDestFilePath
<< '\t'
Expand Down

0 comments on commit 54d5f95

Please sign in to comment.