ref: e05602598c19ed2708d56e4536a654d3998b2087
parent: 3d71a606cc2643a720a79752c7dbcebd816dcebc
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sat Nov 14 22:28:36 EST 2020
fix dir rewind
--- a/ext4srv.c
+++ b/ext4srv.c
@@ -16,6 +16,7 @@
Part *p;
u32int uid;
char *path;
+ int doff;
union {
ext4_file *file;
ext4_dir *dir;
@@ -38,7 +39,7 @@
linkresolve(Aux *a, char *s, char **value)
{
char *q, buf[4096+1];
- ulong sz;
+ uvlong sz;
if(ext4_readlink(s, buf, sizeof(buf), &sz) == 0){
if(sz == sizeof(buf)){
@@ -180,10 +181,10 @@
e = 0;
mode &= ~OCEXEC;
- if(mode & OTRUNC){
- mode &= ~OTRUNC;
+ if(mode & OTRUNC)
e |= O_TRUNC;
- }
+
+ mode &= 3;
if(mode == OWRITE)
e |= O_WRONLY;
else if(mode == ORDWR)
@@ -347,6 +348,11 @@
goto ext4errorrm;
ext4_owner_set(s, a->uid, ext4_inode_get_gid(&inode));
+ r->fid->qid.path = a->p->qidmask.path | a->file->inode;
+ r->fid->qid.vers = 0;
+ r->fid->qid.type = 0;
+ r->ofcall.qid = r->fid->qid;
+
free(a->path);
a->path = strdup(strchr(s+1, '/')+1);
free(s);
@@ -389,7 +395,7 @@
if((s = linkresolve(a, s, nil)) == nil)
return -1;
if((r = ext4_raw_inode_fill(s, &ino, &inode)) != 0){
- werrstr("%s: %s", s, errno2s(r));
+ werrstr("inode: %s: %s", s, errno2s(r));
free(s);
return -1;
}
@@ -397,6 +403,7 @@
dir->mode = ext4_inode_get_mode(a->p->sb, &inode) & 0x1ff;
dir->qid.path = a->p->qidmask.path | ino;
dir->qid.vers = ext4_inode_get_generation(&inode);
+ dir->qid.type = 0;
t = ext4_inode_type(a->p->sb, &inode);
if(t & EXT4_INODE_MODE_DIRECTORY){
dir->qid.type |= QTDIR;
@@ -432,17 +439,25 @@
Aux *a;
a = aux;
- if(n == 0)
+ if(n == 0 || n != a->doff){
ext4_dir_entry_rewind(a->dir);
+ a->doff = 0;
+ }
for(;;){
do{
if((e = ext4_dir_entry_next(a->dir)) == nil)
return -1;
- }while(strcmp((char*)e->name, ".") == 0 || strcmp((char*)e->name, "..") == 0);
+ }while(e->name == nil || strcmp((char*)e->name, ".") == 0 || strcmp((char*)e->name, "..") == 0);
+ if(a->doff++ != n)
+ continue;
+
if(dirfill(dir, a, (char*)e->name) == 0)
return 0;
+ else{
+ fprint(2, "dirfill failed on %s: %r\n", (char*)e->name);
+ }
}
}
@@ -449,7 +464,7 @@
static void
rread(Req *r)
{
- ulong n;
+ uvlong n;
int res;
Aux *a;
@@ -473,7 +488,7 @@
static void
rwrite(Req *r)
{
- ulong n;
+ uvlong n;
int res;
Aux *a;
@@ -666,11 +681,12 @@
/* truncate */
if(r->d.length >= 0){
- if((res = ext4_fopen2(&f, new, toext4mode(OWRITE, 0, 0))) != 0 ||
- (res = ext4_ftruncate(&f, r->d.length)) != 0){
+ if((res = ext4_fopen2(&f, new, toext4mode(OWRITE, 0, 0))) != 0)
goto ext4error;
- }
+ res = ext4_ftruncate(&f, r->d.length);
ext4_fclose(&f);
+ if(res != 0)
+ goto ext4error;
}
/* mode */
@@ -792,16 +808,12 @@
return;
fid->aux = nil;
- if(a->type == Adir){
- if(a->dir != nil){
- ext4_dir_close(a->dir);
- free(a->dir);
- }
- }else if(a->type == Afile){
- if(a->file != nil){
- ext4_fclose(a->file);
- free(a->file);
- }
+ if(a->type == Adir && a->dir != nil){
+ ext4_dir_close(a->dir);
+ free(a->dir);
+ }else if(a->type == Afile && a->file != nil){
+ ext4_fclose(a->file);
+ free(a->file);
}
if(decref(a->p) < 1)
--- a/part.c
+++ b/part.c
@@ -176,10 +176,9 @@
static void *
readfile(Part *p, char *path, uvlong *sz)
{
+ uvlong n, got;
char *s, *d;
ext4_file f;
- ulong got;
- uvlong n;
int r;
d = nil;