mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 08:42:40 +01:00 
			
		
		
		
	The "move problem" has been present in littlefs for a while, but I haven't come across a solution worth implementing for various reasons. The problem is simple: how do we move directory entries across directories atomically? Since multiple directory entries are involved, we can't rely entirely on the atomic block updates. It ends up being a bit of a puzzle. To make the problem more complicated, any directory block update can fail due to wear, and cause the directory block to need to be relocated. This happens rarely, but brings a large number of corner cases. --- The solution in this patch is simple: 1. Mark source as "moving" 2. Copy source to destination 3. Remove source If littlefs ever runs into a "moving" entry, that means a power loss occured during a move. Either the destination entry exists or it doesn't. In this case we just search the entire filesystem for the destination entry. This is expensive, however the chance of a power loss during a move is relatively low.
		
			
				
	
	
		
			58 lines
		
	
	
		
			814 B
		
	
	
	
		
			Makefile
		
	
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
		
			814 B
		
	
	
	
		
			Makefile
		
	
	
	
	
	
| TARGET = lfs
 | |
| 
 | |
| CC = gcc
 | |
| AR = ar
 | |
| SIZE = size
 | |
| 
 | |
| SRC += $(wildcard *.c emubd/*.c)
 | |
| OBJ := $(SRC:.c=.o)
 | |
| DEP := $(SRC:.c=.d)
 | |
| ASM := $(SRC:.c=.s)
 | |
| 
 | |
| TEST := $(patsubst tests/%.sh,%,$(wildcard tests/test_*))
 | |
| 
 | |
| ifdef DEBUG
 | |
| CFLAGS += -O0 -g3
 | |
| else
 | |
| CFLAGS += -Os
 | |
| endif
 | |
| ifdef WORD
 | |
| CFLAGS += -m$(WORD)
 | |
| endif
 | |
| CFLAGS += -I.
 | |
| CFLAGS += -std=c99 -Wall -pedantic
 | |
| 
 | |
| 
 | |
| all: $(TARGET)
 | |
| 
 | |
| asm: $(ASM)
 | |
| 
 | |
| size: $(OBJ)
 | |
| 	$(SIZE) -t $^
 | |
| 
 | |
| .SUFFIXES:
 | |
| test: test_format test_dirs test_files test_seek test_parallel \
 | |
| 	test_alloc test_paths test_orphan test_move test_corrupt
 | |
| test_%: tests/test_%.sh
 | |
| 	./$<
 | |
| 
 | |
| -include $(DEP)
 | |
| 
 | |
| $(TARGET): $(OBJ)
 | |
| 	$(CC) $(CFLAGS) $^ $(LFLAGS) -o $@
 | |
| 
 | |
| %.a: $(OBJ)
 | |
| 	$(AR) rcs $@ $^
 | |
| 
 | |
| %.o: %.c
 | |
| 	$(CC) -c -MMD $(CFLAGS) $< -o $@
 | |
| 
 | |
| %.s: %.c
 | |
| 	$(CC) -S $(CFLAGS) $< -o $@
 | |
| 
 | |
| clean:
 | |
| 	rm -f $(TARGET)
 | |
| 	rm -f $(OBJ)
 | |
| 	rm -f $(DEP)
 | |
| 	rm -f $(ASM)
 |