From: John Hodge Date: Sun, 27 Sep 2009 08:43:12 +0000 (+0800) Subject: Fixed FAT_Read to return number of bytes read. Created a simple `cat` command X-Git-Tag: rel0.06~448 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=b38fc2132b470db041f844255404930eafe2de48;p=tpg%2Facess2.git Fixed FAT_Read to return number of bytes read. Created a simple `cat` command --- diff --git a/Kernel/vfs/fs/fat.c b/Kernel/vfs/fs/fat.c index 8a558273..e03df096 100644 --- a/Kernel/vfs/fs/fat.c +++ b/Kernel/vfs/fs/fat.c @@ -342,6 +342,15 @@ Uint64 FAT_Read(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer) return 0; } + // Sanity Check offset + if(offset > node->Size){ + return 0; + } + // Clamp Size + if(length + offset > node->Size) { + length = offset - node->Size; + } + // Single Cluster including offset if(length + offset < bpc) { @@ -349,7 +358,7 @@ Uint64 FAT_Read(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer) memcpy( buffer, (void*)( tmpBuf + offset%bpc ), length ); free(tmpBuf); LEAVE('i', 1); - return 1; + return length; } preSkip = offset / bpc; @@ -379,7 +388,7 @@ Uint64 FAT_Read(tVFS_Node *node, Uint64 offset, Uint64 length, void *buffer) if (count == 1) { free(tmpBuf); LEAVE('i', 1); - return 1; + return length; } cluster = FAT_int_GetFatValue(handle, cluster); diff --git a/Usermode/Applications/cat_src/Makefile b/Usermode/Applications/cat_src/Makefile new file mode 100644 index 00000000..dcd326d8 --- /dev/null +++ b/Usermode/Applications/cat_src/Makefile @@ -0,0 +1,33 @@ +# Project: cat + +CC = gcc +AS = nasm +LD = ld +RM = @rm -f + +COBJ = main.o +BIN = ../cat +ACESSDIR = /home/hodgeja/Projects/Acess2/Usermode + +INCS = -I$(ACESSDIR)/include -I./include +CFLAGS = -Wall -fno-builtin -fno-stack-protector $(INCS) +ASFLAGS = -felf +LDFLAGS = -T $(ACESSDIR)/Libraries/acess.ld -I /Acess/Libs/ld-acess.so -lc + +.PHONY : all clean + +all: $(BIN) + +$(BIN): $(COBJ) + @echo --- $(LD) -o $@ + @$(LD) $(LDFLAGS) -o $@ $(COBJ) -Map Map.txt + objdump -d $(BIN) > $(BIN).dsm + cp $(BIN) /mnt/AcessHDD/Acess2/ + +clean: + $(RM) $(COBJ) $(BIN) + +$(COBJ): %.o: %.c + @echo --- GCC -o $@ + @$(CC) $(CFLAGS) -c $? -o $@ + diff --git a/Usermode/Applications/cat_src/main.c b/Usermode/Applications/cat_src/main.c new file mode 100644 index 00000000..c60ab27b --- /dev/null +++ b/Usermode/Applications/cat_src/main.c @@ -0,0 +1,38 @@ +/* + * Acess2 CAT command + */ +#include +#include +#include + +#define BUF_SIZE 1024 + +int main(int argc, char *argv[]) +{ + int fd; + int num; + char buf[BUF_SIZE+1]; + + if(argc < 2) { + printf("Usage: cat \n"); + return -1; + } + + fd = open(argv[1], OPENFLAG_READ); + if(fd == -1) { + printf("Unable to open '%s' for reading\n", argv[1]); + return -1; + } + + do { + num = read(fd, BUF_SIZE, buf); + printf("num = %i\n", num); + buf[num] = '\0'; + printf("%s", buf); + } while(num == BUF_SIZE); + + close(fd); + printf("\n"); + + return 0; +}