txtfs

A textual disk filesystem for Plan 9
git clone git://git.stellar-nexus.ru/txtfs
Log | Files | Refs

commit 86ab4b4cc47a6ba5e329feea32e3140f7f9ffe5f
parent 3025d1cec268938d097a6379e1b960cecfd2e4a7
Author: Plat <plat@stellar-nexus.ru>
Date:   Fri, 25 Sep 2026 16:27:18 +0000

Added filestat

Diffstat:
Afile.c | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 73 insertions(+), 0 deletions(-)

diff --git a/file.c b/file.c @@ -0,0 +1,73 @@ +#include <u.h> +#include <libc.h> + +#include "fs.h" + +File * +filestat(u64int filepos) +{ + u64int pos; /* to avoid a conversion */ + u64int blk; + char buf[BLKSZ]; + char field[STRSIZ+1]; + + pos = dentrypos % BLKSZ; + blk = dentrypos / BLKSZ; + + if(blkread(blk, buf) < 0) { + werrstr("blkread: %r"); + return nil; + } + + File *out = calloc(1, sizeof(File)); + if(out == nil) { + werrstr("calloc: %r"); + return nil; + } + + /* Dir */ + out->dir = dirstat(filepos); + if(out->dir == nil) { + werrstr("dirstat: %r"); + return nil; + } + + /* non-fragmented */ + if(buf[pos] == '+') { + out->nfrags = 1; + + Frag *frag = calloc(1, sizeof(Frag)); + if(frag == nil) { + werrstr("calloc: %r"); + return nil; + } + + frag->block = out->dir->qid.path; + frag->size = out->dir->length; + + out->frags = frag; + } + + + /* nfrags */ + out->nfrags = countfrags(filepos, 0); + + out->*frags = malloc((sizeof out->frags) * nfrags); + if(out->frags == nil) { + werrstr("malloc: %r"); + return nil; + } + uint *count = calloc(1, sizeof count); + if(count == nil) { + werrstr("calloc: %r"); + return nil; + } + if(buildfragarr(filepos, 0, out->frags, count) > 0) { + werrstr("buildfragarr: %r"); + free(count); + return nil; + } + + free(count); + return out; +}