ref: aa0d4ea543fec82928fc1ff6f57eb681e1b50716
dir: /ext4srv.c/
#include <ext4.h>
#include <fcall.h>
#include <thread.h>
#include <9p.h>
typedef struct Aux Aux;
typedef struct Root Root;
struct Aux {
int type;
Aux *raux;
union {
ext4_file *file;
ext4_dir *dir;
Root *r;
};
};
struct Root {
struct ext4_blockdev *dev;
QLock lock;
int id;
int f;
};
enum {
Aroot,
Afile,
Adir,
Frdonly = 1<<0,
};
#define BDEV2AUX(bdev) (Aux*)(bdev-1)
static int
bdopen(struct ext4_blockdev *bdev)
{
Aux *a;
a = BDEV2AUX(bdev);
return 0;
}
static int
bdread(struct ext4_blockdev *bdev, void *buf, u64int blkid, u32int blkcnt)
{
Aux *a;
a = BDEV2AUX(bdev);
return 0;
}
static int
bdwrite(struct ext4_blockdev *bdev, const void *buf, u64int blkid, u32int blkcnt)
{
Aux *a;
a = BDEV2AUX(bdev);
return 0;
}
static int
bdnowrite(struct ext4_blockdev *bdev, const void *buf, u64int blkid, u32int blkcnt)
{
USED(bdev, buf, blkid, blkcnt);
return -1;
}
static int
bdclose(struct ext4_blockdev *bdev)
{
Aux *a;
a = BDEV2AUX(bdev);
return 0;
}
static int
bdlock(struct ext4_blockdev *bdev)
{
Aux *a;
a = BDEV2AUX(bdev);
qlock(&a->root.b.lock);
return 0;
}
static int
bdunlock(struct ext4_blockdev *bdev)
{
Aux *a;
a = BDEV2AUX(bdev);
qunlock(&a->root.b.lock);
return 0;
}
static Aux *
newroot(char *dev, int flags)
{
static int newid;
static QLock lock;
int id;
Aux *a;
Root *r;
int f;
qlock(&lock);
id = newid++;
if(id < 0){
werrstr("root id overflow");
/* no unlock on purpose, get stuck forever */
return nil;
}
qunlock(&lock);
if((f = open(dev, ORDWR)) < 0)
return nil;
if((a = calloc(1, sizeof(*a)+sizeof(*r)) == nil){
close(f);
return nil;
}
a->type = Aroot;
a->raux = a;
a->r = r = (struct ext4_blockdev*)(a+1);
r->open = bdopen;
r->bread = bdread;
r->bwrite = (flags & Frdonly) != 0 ? bdwrite : bdnowrite;
r->close = bdclose;
r->lock = bdlock;
r->unlock = bdunlock;
r->ph_bsize =
return a;
}
static struct ext4_blockdev_iface iface0 = {
/**@brief Block size (bytes): physical*/
uint32_t ph_bsize;
/**@brief Block count: physical*/
uint64_t ph_bcnt;
/**@brief Block size buffer: physical*/
uint8_t *ph_bbuf;
/**@brief Reference counter to block device interface*/
uint32_t ph_refctr;
/**@brief Physical read counter*/
uint32_t bread_ctr;
/**@brief Physical write counter*/
uint32_t bwrite_ctr;
/**@brief User data pointer*/
void* p_user;
static void
rattach(Req *r)
{
}
static void
rauth(Req *r)
{
}
static void
ropen(Req *r)
{
}
static void
rcreate(Req *r)
{
}
static void
rread(Req *r)
{
}
static void
rwrite(Req *r)
{
}
static void
rremove(Req *r)
{
}
static void
rstat(Req *r)
{
}
static void
rwstat(Req *r)
{
}
static char *
rwalk1(Fid *fid, char *name, Qid *qid)
{
return nil;
}
static char *
rclone(Fid *oldfid, Fid *newfid)
{
return nil;
}
static void
rdestroyfid(Fid *fid)
{
}
static void
rstart(Srv *s)
{
}
static void
rend(Srv *s)
{
}
static Srv fs = {
.attach = rattach,
.open = ropen,
.create = rcreate,
.read = rread,
.write = rwrite,
.remove = rremove,
.stat = rstat,
.wstat = rwstat,
.walk1 = rwalk1,
.clone = rclone,
.destroyfid = rdestroyfid,
.start = rstart,
.end = rend,
};
void
threadmain(int argc, char **argv)
{
ARGBEGIN{
}ARGEND
threadexitsall(nil);
}