From db971a6189e63802b4c7c0ee41bf00e9864f52a7 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Sat, 23 Oct 2021 13:40:06 +0000 Subject: kernel: fix stat bugs In a few places, we where using a fixed buffer of sizeof(Dir)+100 size for stat. This is not correct and fails if the name returned in stat is long. This results in being unable to seek to the end of file with a long filename. The kernel should do the same thing as dirfstat() from libc; handling the conversion and buffer allocation and returning a freeable Dir* pointer. For this, a new dirchanstat() function was added. The fstat syscall was not rewriting the name to the last path element; fix it. In addition, gracefully handle the mountfix case, reallocating the buffer to accomidate the required stat length plus size of the new name so dirsetname() does not fail. --- sys/src/9/port/sdloop.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'sys/src/9/port/sdloop.c') diff --git a/sys/src/9/port/sdloop.c b/sys/src/9/port/sdloop.c index 49ea6886d..5b3419cef 100644 --- a/sys/src/9/port/sdloop.c +++ b/sys/src/9/port/sdloop.c @@ -47,21 +47,14 @@ SDifc sdloopifc; static void identify(Ctlr *c, SDunit *u) { - int n; uvlong s, osectors; - uchar buf[sizeof(Dir) + 100]; - Dir dir; + Dir *dir; - if(waserror()){ - iprint("sdloop: identify: %s\n", up->errstr); - nexterror(); - } osectors = c->sectors; - n = devtab[c->c->type]->stat(c->c, buf, sizeof buf); - if(convM2D(buf, n, &dir, nil) == 0) - error("internal error: stat error in seek"); - s = dir.length / c->sectsize; - poperror(); + + dir = dirchanstat(c->c); + s = dir->length / c->sectsize; + free(dir); memset(u->inquiry, 0, sizeof u->inquiry); u->inquiry[2] = 2; -- cgit v1.2.3