1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-12-04 04:48:06 +11:00

tools: add blkpack

This commit is contained in:
Virgil Dupras 2020-04-13 22:05:03 -04:00
parent 7292d486dc
commit d4cdb659b4
6 changed files with 87 additions and 2 deletions

View File

@ -41,11 +41,12 @@ path to giving Collapse OS a try.
from this folder. from this folder.
* `recipes`: collection of recipes that assemble parts together on a specific * `recipes`: collection of recipes that assemble parts together on a specific
machine. machine.
* `blk`: Collapse OS filesystem's content. See `000` for intro.
* `doc`: User guide for when you've successfully installed Collapse OS. * `doc`: User guide for when you've successfully installed Collapse OS.
* `tools`: Tools for working with Collapse OS from "modern" environments. For * `tools`: Tools for working with Collapse OS from "modern" environments. For
example, tools for facilitating data upload to a Collapse OS machine example, tools for facilitating data upload to a Collapse OS machine
through a serial port. through a serial port.
* `emul`: Emulated applications, such as zasm and the shell. * `emul`: Emulated applications.
* `tests`: Automated test suite for the whole project. * `tests`: Automated test suite for the whole project.
## Status ## Status

15
blk/000 Normal file
View File

@ -0,0 +1,15 @@
Collapse OS file system
This is a Forth-style filesystems which is very simple. It is a
list of 1024 bytes block, organised in 16 lines of 64 columns
each. You refer to blocks by numbers. You show them with LIST.
You interpret them with LOAD.
Conventions: When you see "(cont.)" at the bottom right of a
block, it means that the next block continues the same kind of
contents. This of course only work for informational text.
Block numbers are abbreviated with prefix "B". "BX" means
"block X".
The master index of this filesystem is at B1.

2
blk/001 Normal file
View File

@ -0,0 +1,2 @@
MASTER INDEX

1
tools/.gitignore vendored
View File

@ -8,3 +8,4 @@
/stripfc /stripfc
/bin2c /bin2c
/exec /exec
/blkpack

View File

@ -8,9 +8,10 @@ SLATEST_TGT = slatest
STRIPFC_TGT = stripfc STRIPFC_TGT = stripfc
BIN2C_TGT = bin2c BIN2C_TGT = bin2c
EXEC_TGT = exec EXEC_TGT = exec
BLKPACK_TGT = blkpack
TARGETS = $(MEMDUMP_TGT) $(BLKDUMP_TGT) $(UPLOAD_TGT) $(FONTCOMPILE_TGT) \ TARGETS = $(MEMDUMP_TGT) $(BLKDUMP_TGT) $(UPLOAD_TGT) $(FONTCOMPILE_TGT) \
$(TTYSAFE_TGT) $(PINGPONG_TGT) $(SLATEST_TGT) $(STRIPFC_TGT) \ $(TTYSAFE_TGT) $(PINGPONG_TGT) $(SLATEST_TGT) $(STRIPFC_TGT) \
$(BIN2C_TGT) $(EXEC_TGT) $(BIN2C_TGT) $(EXEC_TGT) $(BLKPACK_TGT)
OBJS = common.o OBJS = common.o
all: $(TARGETS) all: $(TARGETS)
@ -29,6 +30,7 @@ $(SLATEST_TGT): $(SLATEST_TGT).c
$(STRIPFC_TGT): $(STRIPFC_TGT).c $(STRIPFC_TGT): $(STRIPFC_TGT).c
$(BIN2C_TGT): $(BIN2C_TGT).c $(BIN2C_TGT): $(BIN2C_TGT).c
$(EXEC_TGT): $(EXEC_TGT).c $(EXEC_TGT): $(EXEC_TGT).c
$(BLKPACK_TGT): $(BLKPACK_TGT).c
$(TARGETS): $(OBJS) $(TARGETS): $(OBJS)
$(CC) $(CFLAGS) $@.c $(OBJS) -o $@ $(CC) $(CFLAGS) $@.c $(OBJS) -o $@

64
tools/blkpack.c Normal file
View File

@ -0,0 +1,64 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>
void usage()
{
fprintf(stderr, "Usage: blkpack dirname\n");
}
int main(int argc, char *argv[])
{
DIR *dp;
struct dirent *ep;
char *buf = NULL;
int blkcnt = 0;
if (argc != 2) {
usage();
return 1;
}
dp = opendir(argv[1]);
if (dp == NULL) {
fprintf(stderr, "Couldn't open directory.\n");
return 1;
}
while ((ep = readdir(dp))) {
if ((strcmp(ep->d_name, ".") == 0) || strcmp(ep->d_name, "..") == 0) {
continue;
}
if (ep->d_type != DT_REG) {
continue;
}
int blkid = atoi(ep->d_name);
if (blkid >= blkcnt) {
int newcnt = blkid+1;
buf = realloc(buf, newcnt*1024);
bzero(buf+(blkcnt*1024), (newcnt-blkcnt)*1024);
blkcnt = newcnt;
}
char fullpath[0x200];
strcpy(fullpath, argv[1]);
strcat(fullpath, "/");
strcat(fullpath, ep->d_name);
FILE *fp = fopen(fullpath, "r");
char *line = NULL;
size_t n = 0;
for (int i=0; i<16; i++) {
ssize_t cnt = getline(&line, &n, fp);
if (cnt < 0) break;
if (cnt > 65) {
fprintf(stderr, "Line %d too long in blk %s\n", i+1, ep->d_name);
}
strncpy(buf+(blkid*1024)+(i*64), line, cnt-1);
}
free(line);
}
fwrite(buf, 1024, blkcnt, stdout);
free(buf);
closedir(dp);
return 0;
}