view src/file_read.cbc @ 146:fd166dda4361

tweak return value at file_read.cbc
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Sun, 15 Dec 2019 14:15:27 +0900
parents f70c4ec3fb8a
children 06449f2ae0c7
line wrap: on
line source

#include "../context.h"
#interface "SysRead.h"

// ----
// typedef struct FileRead<Type, Isa> impl SysRead {
//   struct file* f;
//   int r;
//   __code cbc_fileread1(Type* file_read, struct file* f,int r,__code next(r,...));
//   __code next(...);
// } FileRead;
// ----

SysRead* createFileRead(struct Context* cbc_context) {
    struct SysRead* sys_read  = new SysRead();
    struct FileRead* file_read = new FileRead();
    sys_read->sys_read = (union Data*)file_read;
    file_read->f = NULL;
    file_read->r  = 0;
    sys_read->impl = NULL;
    sys_read->addr = NULL;
    sys_read->n  = 0;
    sys_read->read = C_readFileRead;
    sys_read->next = C_nextFileRead;
    return sys_read;
}

SysRead* createFileReadInstFromFile(struct Context* cbc_context, struct file* f,char* addr, int n) {
    if (f->type == FD_PIPE) {
        return create_piperead(cbc_context, f->pipe, addr, n, next);
    }

    if (f->type == FD_INODE) {
        ilock(f->ip);
        return create_readi(cbc_context, f->ip, addr, f->off, n, cbc_fileread1);
    }
    return NULL; //Error?
}


__code cbc_fileread1FileRead(struct FileRead* file_read, struct file* f,int r,__code next(r,...)) {

  goto next(r,...);
}

__code nextFileRead(...) {

}

__code readFileRead(struct FileRead* sys_read, union Data* impl, char* addr, int n, __code next(int ret,...)) {

  goto next(int ret,...);
}

__code selectReadInstance(struct file* f) {
  if (f->readable == 0) {
    goto next(-1);
  } 
  SysRead* read = createFileReadInstFromFile(proc->cbc_context, f);
  goto read->read(f,addr,n);
}

__code nextFileRead(...) {

}