mirror of
				https://github.com/eledio-devices/thirdparty-littlefs.git
				synced 2025-10-31 08:42:40 +01:00 
			
		
		
		
	In writing the initial allocator, I ran into the rather difficult problem of trying to iterate through the entire filesystem cheaply and with only constant memory consumption (which prohibits recursive functions). The solution was to simply thread all directory blocks onto a massive linked-list that spans the entire filesystem. With the linked-list it was easy to create a traverse function for all blocks in use on the filesystem (which has potential for other utility), and add the rudimentary block allocator using a bit-vector. While the linked-list may add complexity (especially where needing to maintain atomic operations), the linked-list helps simplify what is currently the most expensive operation in the filesystem, with no cost to space (the linked-list can reuse the pointers used for chained directory blocks).
		
			
				
	
	
		
			57 lines
		
	
	
		
			741 B
		
	
	
	
		
			Makefile
		
	
	
	
	
	
			
		
		
	
	
			57 lines
		
	
	
		
			741 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_alloc
 | |
| 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)
 |