Skip to content

Commit

Permalink
Merge pull request #2224 from mikee47/fix/ifs-attributes
Browse files Browse the repository at this point in the history
Fix IFS attribute handling and other improvements
  • Loading branch information
slaff authored Feb 23, 2021
2 parents 49e2248 + 723c5cb commit 14b50ee
Show file tree
Hide file tree
Showing 29 changed files with 130 additions and 412 deletions.
Empty file modified .ci/build.cmd
100755 → 100644
Empty file.
Empty file modified .ci/install.cmd
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion Sming/Arch/Esp32/app.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ LDFLAGS += \


.PHONY: application
application: $(CUSTOM_TARGETS) $(TARGET_BIN)
application: $(TARGET_BIN)

# $1 -> Linker script
define LinkTarget
Expand Down
2 changes: 1 addition & 1 deletion Sming/Arch/Esp8266/app.mk
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ LDFLAGS += \


.PHONY: application
application: $(CUSTOM_TARGETS) $(FW_FILE_1) $(FW_FILE_2)
application: $(FW_FILE_1) $(FW_FILE_2)

# $1 -> Linker script
define LinkTarget
Expand Down
38 changes: 17 additions & 21 deletions Sming/Arch/Host/Components/spi_flash/flashmem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@
#include "flashmem.h"
#include <string.h>
#include <esp_spi_flash.h>
#include <IFS/Host/FileSystem.h>
#include <IFS/File.h>

namespace
{
IFS::IFileSystem& fileSys{IFS::Host::fileSystem};
IFS::File::Handle flashFile{-1};
IFS::File flashFile(&IFS::Host::getFileSystem());
size_t flashFileSize{0x400000U};
char flashFileName[256];
const char defaultFlashFileName[]{"flash.bin"};
Expand Down Expand Up @@ -59,26 +58,24 @@ bool host_flashmem_init(FlashmemConfig& config)
config.filename = flashFileName;
}

flashFile = fileSys.open(flashFileName, IFS::File::Create | IFS::File::ReadWrite);
if(flashFile < 0) {
if(!flashFile.open(flashFileName, IFS::File::Create | IFS::File::ReadWrite)) {
hostmsg("Error opening \"%s\"", flashFileName);
return false;
}

int res = fileSys.lseek(flashFile, 0, SeekOrigin::End);
int res = flashFile.seek(0, SeekOrigin::End);
if(res < 0) {
hostmsg("Error seeking \"%s\": %s", flashFileName, fileSys.getErrorString(res).c_str());
fileSys.close(flashFile);
flashFile = -1;
hostmsg("Error seeking \"%s\": %s", flashFileName, flashFile.getErrorString(res).c_str());
flashFile.close();
return false;
}

if(res == 0) {
size_t size = config.createSize ?: flashFileSize;
res = fileSys.lseek(flashFile, size, SeekOrigin::Start);
res = flashFile.seek(size, SeekOrigin::Start);
if(res != int(size)) {
hostmsg("Error seeking beyond end of file \"%s\"", flashFileName);
} else if(fileSys.truncate(flashFile, size) < 0) {
} else if(!flashFile.truncate(size)) {
hostmsg("Error truncating \"%s\" to %u bytes", flashFileName, size);
} else {
hostmsg("Created blank \"%s\", %u bytes", flashFileName, size);
Expand All @@ -95,37 +92,36 @@ bool host_flashmem_init(FlashmemConfig& config)

void host_flashmem_cleanup()
{
fileSys.close(flashFile);
flashFile = -1;
flashFile.close();
hostmsg("Closed \"%s\"", flashFileName);
}

static int readFlashFile(uint32_t offset, void* buffer, size_t count)
{
if(flashFile < 0) {
if(!flashFile) {
return -1;
}
int res = fileSys.lseek(flashFile, offset, SeekOrigin::Start);
int res = flashFile.seek(offset, SeekOrigin::Start);
if(res >= 0) {
res = fileSys.read(flashFile, buffer, count);
res = flashFile.read(buffer, count);
}
if(res < 0) {
debug_w("readFlashFile(0x%08x, %u) failed: %s", offset, count, fileSys.getErrorString(res).c_str());
debug_w("readFlashFile(0x%08x, %u) failed: %s", offset, count, flashFile.getErrorString(res).c_str());
}
return res;
}

static int writeFlashFile(uint32_t offset, const void* data, size_t count)
{
if(flashFile < 0) {
if(!flashFile) {
return -1;
}
int res = fileSys.lseek(flashFile, offset, SeekOrigin::Start);
int res = flashFile.seek(offset, SeekOrigin::Start);
if(res >= 0) {
res = fileSys.write(flashFile, data, count);
res = flashFile.write(data, count);
}
if(res < 0) {
debug_w("writeFlashFile(0x%08x, %u) failed: %s", offset, count, fileSys.getErrorString(res).c_str());
debug_w("writeFlashFile(0x%08x, %u) failed: %s", offset, count, flashFile.getErrorString(res).c_str());
}
return res;
}
Expand Down
3 changes: 1 addition & 2 deletions Sming/Arch/Host/Core/Data/Stream/HostFileStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
****/

#include "HostFileStream.h"
#include <IFS/Host/FileSystem.h>

HostFileStream::HostFileStream() : IFS::FileStream(&IFS::Host::fileSystem)
HostFileStream::HostFileStream() : IFS::FileStream(&IFS::Host::getFileSystem())
{
}
2 changes: 1 addition & 1 deletion Sming/Arch/Host/Core/Data/Stream/HostFileStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class HostFileStream : public IFS::FileStream
public:
HostFileStream();

HostFileStream(const String& fileName, IFS::File::OpenFlags openFlags = IFS::File::ReadOnly) : HostFileStream()
HostFileStream(const String& fileName, IFS::OpenFlags openFlags = IFS::OpenFlag::Read) : HostFileStream()
{
open(fileName, openFlags);
}
Expand Down
2 changes: 1 addition & 1 deletion Sming/Arch/Host/app.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ TARGET_OUT_0 := $(FW_BASE)/$(APP_NAME)$(TOOL_EXT)
# Target definitions

.PHONY: application
application: $(CUSTOM_TARGETS) $(TARGET_OUT_0)
application: $(TARGET_OUT_0)

$(TARGET_OUT_0): $(COMPONENTS_AR)
$(info $(notdir $(PROJECT_DIR)): Linking $@)
Expand Down
6 changes: 5 additions & 1 deletion Sming/Arch/Host/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ GCC_UPGRADE_URL := https://sming.readthedocs.io/en/latest/arch/host/host-emulato

CPPFLAGS += \
-m32 \
-Wno-deprecated-declarations
-Wno-deprecated-declarations \
-D_FILE_OFFSET_BITS=64

# => Tools
MEMANALYZER = size
Expand All @@ -33,6 +34,9 @@ CLI_TARGET_OPTIONS =
# $1 -> Command to execute
ifeq ($(UNAME),Windows)
DetachCommand = start $1
# May be required by some applications (e.g. openssl)
HOME ?= $(USERPROFILE)
export HOME
else
DetachCommand = gnome-terminal -- bash -c "sleep 1; $1"
endif
2 changes: 1 addition & 1 deletion Sming/Components/IFS
Submodule IFS updated 80 files
+17 −8 README.rst
+9 −2 component.mk
+53 −0 history.rst
+43 −0 src/Access.cpp
+226 −53 src/Arch/Host/FileSystem.cpp
+74 −0 src/Arch/Host/Windows/README.rst
+159 −0 src/Arch/Host/Windows/xattr.cpp
+32 −0 src/Arch/Host/Windows/xattr.h
+36 −40 src/Arch/Host/include/IFS/Host/FileSystem.h
+52 −0 src/Compression.cpp
+110 −0 src/Directory.cpp
+18 −4 src/Error.cpp
+89 −42 src/FWFS/FileSystem.cpp
+18 −4 src/FWFS/ObjectStore.cpp
+32 −0 src/File.cpp
+0 −34 src/File/Access.cpp
+0 −50 src/File/Attributes.cpp
+0 −27 src/File/Compression.cpp
+0 −26 src/File/OpenFlags.cpp
+62 −0 src/FileAttributes.cpp
+17 −2 src/FileDevice.cpp
+84 −50 src/FileSystem.cpp
+0 −32 src/Flags.cpp
+0 −24 src/Flags.h
+31 −17 src/GdbFileSystem.cpp
+75 −42 src/HYFS/FileSystem.cpp
+18 −4 src/Helpers.cpp
+24 −13 src/HostUtil.cpp
+55 −0 src/IFileSystem.cpp
+19 −5 src/Object.cpp
+40 −0 src/OpenFlags.cpp
+20 −5 src/SPIFFS/Error.cpp
+191 −158 src/SPIFFS/FileSystem.cpp
+22 −9 src/UserRole.cpp
+65 −0 src/include/IFS/Access.h
+80 −0 src/include/IFS/Compression.h
+51 −0 src/include/IFS/Control.h
+120 −0 src/include/IFS/Directory.h
+19 −4 src/include/IFS/Error.h
+42 −34 src/include/IFS/FWFS/FileSystem.h
+18 −4 src/include/IFS/FWFS/ObjRefCache.h
+17 −4 src/include/IFS/FWFS/ObjectStore.h
+359 −0 src/include/IFS/File.h
+0 −43 src/include/IFS/File/Access.h
+0 −37 src/include/IFS/File/Compression.h
+26 −15 src/include/IFS/FileAttributes.h
+95 −389 src/include/IFS/FileSystem.h
+80 −0 src/include/IFS/FsBase.h
+39 −27 src/include/IFS/Gdb/FileSystem.h
+43 −34 src/include/IFS/HYFS/FileSystem.h
+19 −6 src/include/IFS/Helpers.h
+19 −7 src/include/IFS/Host/Util.h
+445 −0 src/include/IFS/IFileSystem.h
+0 −47 src/include/IFS/Media.h
+19 −5 src/include/IFS/NameBuffer.h
+21 −9 src/include/IFS/Object.h
+19 −5 src/include/IFS/ObjectStore.h
+22 −20 src/include/IFS/OpenFlags.h
+19 −4 src/include/IFS/SPIFFS/Error.h
+148 −0 src/include/IFS/SPIFFS/FileMeta.h
+41 −80 src/include/IFS/SPIFFS/FileSystem.h
+34 −23 src/include/IFS/Stat.h
+17 −2 src/include/IFS/TimeStamp.h
+18 −5 src/include/IFS/Types.h
+30 −9 src/include/IFS/UserRole.h
+18 −5 src/include/IFS/Util.h
+22 −6 src/include/Storage/FileDevice.h
+136 −0 test/app/FsTest.cpp
+20 −0 test/backup.fwfs
+9 −4 test/component.mk
+ test/files/backup.fwfs
+3 −1 test/fwfsImage1.fwfs
+51 −0 test/include/FsTest.h
+3 −1 test/include/modules.h
+123 −0 test/modules/Attributes.cpp
+437 −0 test/modules/Hybrid.cpp
+0 −505 test/modules/fstest.cpp
+8 −49 todo.rst
+54 −19 tools/fsbuild/FWFS.py
+2 −0 tools/fsbuild/README.rst
5 changes: 3 additions & 2 deletions Sming/Components/spiffs/spiffsgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,10 @@ def to_binary(self):
magic = 0xE3457A77
mtime = self.mtime
attr = 0
flags = 0xff
userRole_admin = 0x04
meta = struct.pack(b'<LLBBBB', magic, mtime, attr, flags, userRole_admin, userRole_admin)
compression_none = 0
original_size = 0
meta = struct.pack(b'<LLBBBBB', magic, mtime, attr, userRole_admin, userRole_admin, compression_none, original_size)
meta += b'\x00' * (self.build_config.meta_len - 12)
else:
meta = b'\00' * self.build_config.meta_len
Expand Down
28 changes: 0 additions & 28 deletions Sming/Core/Data/Stream/Directory.h

This file was deleted.

102 changes: 0 additions & 102 deletions Sming/Core/Data/Stream/IFS/Directory.cpp

This file was deleted.

Loading

0 comments on commit 14b50ee

Please sign in to comment.