aboutsummaryrefslogtreecommitdiff
path: root/src/fs
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi92@disroot.org>2025-11-11 20:35:20 +0100
committerXavier Del Campo Romero <xavi92@disroot.org>2025-11-11 20:55:58 +0100
commit5ce25ae3b5d8666d373f7d7e336546ce8508c213 (patch)
tree4aacb570241c1005590a47ac49adb4b75a8ffd8d /src/fs
parentf7ad4d9216b488f76ed4b3c8e423cd926e134b9d (diff)
downloadwnix-5ce25ae3b5d8666d373f7d7e336546ce8508c213.tar.gz
fixes
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/devfs/src/open.c2
-rw-r--r--src/fs/devfs/src/read.c2
-rw-r--r--src/fs/devfs/src/read_nb.c2
-rw-r--r--src/fs/devfs/src/write.c2
-rw-r--r--src/fs/include/fs/fs.h3
-rw-r--r--src/fs/include/fs/inode.h2
-rw-r--r--src/fs/iso9660/src/mount.c8
-rw-r--r--src/fs/iso9660/src/open.c8
-rw-r--r--src/fs/iso9660/src/search.c24
-rw-r--r--src/fs/src/inode/free.c4
-rw-r--r--src/fs/src/inode/search.c36
11 files changed, 53 insertions, 40 deletions
diff --git a/src/fs/devfs/src/open.c b/src/fs/devfs/src/open.c
index 551061f..229ff49 100644
--- a/src/fs/devfs/src/open.c
+++ b/src/fs/devfs/src/open.c
@@ -49,7 +49,7 @@ int devfs_open(const struct fs_open *const o, const struct fs_mp *const mp,
*o->fd = (const struct fs_fd)
{
.inode = *inode,
- .mp = mp
+ .mp = *mp
};
*r = (const struct fs_ret){.f = done, .args = op};
diff --git a/src/fs/devfs/src/read.c b/src/fs/devfs/src/read.c
index e968eb2..d7214ff 100644
--- a/src/fs/devfs/src/read.c
+++ b/src/fs/devfs/src/read.c
@@ -58,7 +58,7 @@ int devfs_read(const struct fs_read *const fr, struct fs_ret *const r)
{
struct read *re = NULL;
struct fs_fd *const fd = fr->fd;
- const struct fs_mp *const mp = fd->mp;
+ const struct fs_mp *const mp = &fd->mp;
const struct inode *const inode = fd->inode.memi;
const struct devfs_ops *const o = devfs_ops(mp->prv, inode->name);
diff --git a/src/fs/devfs/src/read_nb.c b/src/fs/devfs/src/read_nb.c
index 2f30d5c..75b6c25 100644
--- a/src/fs/devfs/src/read_nb.c
+++ b/src/fs/devfs/src/read_nb.c
@@ -25,7 +25,7 @@
int devfs_read_nb(const struct fs_read *const fr)
{
struct fs_fd *const fd = fr->fd;
- const struct fs_mp *const mp = fd->mp;
+ const struct fs_mp *const mp = &fd->mp;
const struct inode *const inode = fd->inode.memi;
const struct devfs_ops *const o = devfs_ops(mp->prv, inode->name);
diff --git a/src/fs/devfs/src/write.c b/src/fs/devfs/src/write.c
index 392666c..fbb0ac8 100644
--- a/src/fs/devfs/src/write.c
+++ b/src/fs/devfs/src/write.c
@@ -55,7 +55,7 @@ static enum state wait(void *const args)
int devfs_write(const struct fs_write *const fw, struct fs_ret *const r)
{
struct fs_fd *const fd = fw->fd;
- const struct fs_mp *const mp = fd->mp;
+ const struct fs_mp *const mp = &fd->mp;
const struct inode *const inode = fd->inode.memi;
const struct devfs_ops *const o = devfs_ops(mp->prv, inode->name);
struct write *const w = malloc(sizeof *w);
diff --git a/src/fs/include/fs/fs.h b/src/fs/include/fs/fs.h
index aebe1db..60c1788 100644
--- a/src/fs/include/fs/fs.h
+++ b/src/fs/include/fs/fs.h
@@ -126,7 +126,8 @@ struct fs_fd
int error;
off_t start, offset, size;
struct fs_fd_prv *prv;
- const struct fs_mp *mp, *tgt_mp;
+ struct fs_mp mp;
+ const struct fs_mp *tgt_mp;
union inode_result inode, tgt_inode;
};
diff --git a/src/fs/include/fs/inode.h b/src/fs/include/fs/inode.h
index fc24d74..a7759f9 100644
--- a/src/fs/include/fs/inode.h
+++ b/src/fs/include/fs/inode.h
@@ -48,7 +48,7 @@ struct inode
struct timespec atim, mtim, ctim;
struct inode *parent, *child, *left, *right;
struct inode_prv *prv;
- void (*free)(void *);
+ void (*dealloc)(void *);
};
union inode_result
diff --git a/src/fs/iso9660/src/mount.c b/src/fs/iso9660/src/mount.c
index 83e7a6d..941d4f9 100644
--- a/src/fs/iso9660/src/mount.c
+++ b/src/fs/iso9660/src/mount.c
@@ -35,7 +35,7 @@ struct mount
struct fs_ret *r;
struct fs_mount mount;
struct iso9660_header header;
- const struct fs_mp *mp;
+ struct fs_mp mp;
};
static void free_mount(struct mount *const m)
@@ -43,7 +43,7 @@ static void free_mount(struct mount *const m)
if (!m)
return;
- m->mp->fs->close(&m->fd);
+ m->mp.fs->close(&m->fd);
free(m->src);
free(m->tgt);
free(m);
@@ -71,7 +71,7 @@ static enum state read_header(void *const args)
{
struct mount *const m = args;
struct fs_fd *const fd = &m->fd;
- const struct fs *const fs = m->mp->fs;
+ const struct fs *const fs = m->mp.fs;
const struct fs_read r =
{
.buf = &m->header,
@@ -134,7 +134,7 @@ static int search_done(const enum state state, const char *const relpath,
if (mp->fs->open(&o, mp, inode, m->r))
goto failure;
- m->mp = mp;
+ m->mp = *mp;
return 0;
failure:
diff --git a/src/fs/iso9660/src/open.c b/src/fs/iso9660/src/open.c
index 1ea6ad7..9818719 100644
--- a/src/fs/iso9660/src/open.c
+++ b/src/fs/iso9660/src/open.c
@@ -30,7 +30,7 @@ struct open
struct inode inode;
struct fs_fd *fd;
struct fs_ret *pr, r;
- const struct fs_mp *mp;
+ struct fs_mp mp;
};
static int search_done(const enum state state, const char *const relpath,
@@ -59,9 +59,9 @@ static int search_done(const enum state state, const char *const relpath,
.start = mpinode->prv->offset,
.tgt_inode.cachei = op->inode,
.size = mpinode->size,
- .tgt_mp = op->mp,
+ .tgt_mp = &op->mp,
.inode = *inode,
- .mp = mp
+ .mp = *mp
};
*op->pr = op->r;
@@ -91,7 +91,7 @@ int iso9660_open(const struct fs_open *const o, const struct fs_mp *const mp,
{
.fd = o->fd,
.inode = *i,
- .mp = mp,
+ .mp = *mp,
.pr = r,
.r = *r
};
diff --git a/src/fs/iso9660/src/search.c b/src/fs/iso9660/src/search.c
index a7a5150..959e8d5 100644
--- a/src/fs/iso9660/src/search.c
+++ b/src/fs/iso9660/src/search.c
@@ -40,7 +40,7 @@ struct id
struct search
{
union inode_result *inode;
- const struct fs_mp *src_mp;
+ struct fs_mp src_mp;
struct iso9660_entry entry;
const char *src, *path;
struct fs_ret r, *pr;
@@ -59,14 +59,22 @@ static void free_search(struct search *const s)
{
if (!s)
return;
- else if (s->src_mp)
- s->src_mp->fs->close(&s->fd);
+
+ const struct fs *const fs = s->src_mp.fs;
+
+ if (fs)
+ fs->close(&s->fd);
free(s->buf);
free(s->token);
free(s);
}
+static void dealloc(void *const p)
+{
+ free(p);
+}
+
static int set_inode(struct search *const s,
const struct iso9660_entry *const e, const struct id *const id)
{
@@ -97,7 +105,7 @@ static int set_inode(struct search *const s,
.name = namedup,
.mode = 0555,
.atim = atim,
- .free = free,
+ .dealloc = dealloc,
.ctim = ts,
.mtim = ts,
.prv = p
@@ -287,7 +295,7 @@ static enum state entry_read(void *const args)
}
char *const buf = s->id.buf;
- const struct fs_mp *const mp = s->fd.mp;
+ const struct fs_mp *const mp = &s->fd.mp;
const struct fs_read r =
{
.buf = buf,
@@ -328,7 +336,7 @@ static int prepare_entry(struct search *const s)
};
s->offset = s->fd.offset;
- return s->src_mp->fs->read(&r, s->pr);
+ return s->src_mp.fs->read(&r, s->pr);
}
static int next_entry(struct search *const s)
@@ -483,7 +491,7 @@ static enum state read_pvd(void *const args)
fd->offset = 16 * ISO9660_SECTOR_SZ;
- if (s->src_mp->fs->read(&r, s->pr))
+ if (s->src_mp.fs->read(&r, s->pr))
goto failure;
return STATE_AGAIN;
@@ -505,7 +513,7 @@ static int src_done(const enum state state, const char *const relpath,
return -1;
}
- s->src_mp = mp;
+ s->src_mp = *mp;
*s->pr = (const struct fs_ret)
{
.f = read_pvd,
diff --git a/src/fs/src/inode/free.c b/src/fs/src/inode/free.c
index 3eca47d..294b1f5 100644
--- a/src/fs/src/inode/free.c
+++ b/src/fs/src/inode/free.c
@@ -26,8 +26,8 @@ void inode_free(struct inode *const i)
inode_free(i->child);
free(i->name);
- if (i->free)
- i->free(i->prv);
+ if (i->dealloc)
+ i->dealloc(i->prv);
}
free(i);
diff --git a/src/fs/src/inode/search.c b/src/fs/src/inode/search.c
index 4715dd2..07b65ed 100644
--- a/src/fs/src/inode/search.c
+++ b/src/fs/src/inode/search.c
@@ -35,10 +35,14 @@ struct search
static void free_search(struct search *const s)
{
+ if (!s)
+ return;
+
+ free(s->mp);
free(s);
}
-static enum state search_mp(struct search *const s)
+static int search_mp(struct search *const s)
{
const struct inode_search *const is = &s->search;
const struct fs_mp *const cur = &s->mp[s->mp_i],
@@ -51,48 +55,48 @@ static enum state search_mp(struct search *const s)
relpath += strlen(s->mp[s->mp_i].tgt);
if (fs && fs->iops.search(relpath, cur, &s->inode, s->r))
- return STATE_FATAL;
+ return -1;
s->mp_i++;
- return STATE_AGAIN;
+ return 0;
}
static enum state search(void *const args)
{
+ enum state ret = STATE_FATAL;
struct search *const s = args;
const struct inode_search *const is = &s->search;
if (!s->mp)
{
- const int ret = is->done(STATE_FATAL, NULL, NULL, NULL, is->args);
-
- free_search(s);
- return ret ? STATE_FATAL : STATE_AGAIN;
+ if (!is->done(STATE_FATAL, NULL, NULL, NULL, is->args))
+ ret = STATE_AGAIN;
}
else if (s->mp_i < s->n)
- return search_mp(s);
+ {
+ if (!search_mp(s))
+ return STATE_AGAIN;
+ }
else
{
const char *relpath = is->path;
+ const struct fs_mp mp = s->mp[s->n - 1];
for (size_t i = 0; i < s->n; i++)
relpath += strlen(s->mp[i].tgt);
- const int ret = is->done(STATE_OK, relpath, &s->mp[s->n - 1],
- &s->inode, is->args);
-
- free_search(s);
- return ret ? STATE_FATAL : STATE_AGAIN;
+ if (!is->done(STATE_OK, relpath, &mp, &s->inode, is->args))
+ ret = STATE_AGAIN;
}
- return STATE_FATAL;
+ free_search(s);
+ return ret;
}
int inode_search(const struct inode_search *const is, struct fs_ret *const r)
{
- struct search *s = NULL;
size_t n;
- /* TODO: do not check for errors yet. */
+ struct search *s = NULL;
struct fs_mp *const mp = fs_mps_from_path(is->path, &n);
if (!(s = malloc(sizeof *s)))