seekvfsminix

Writing to a file from the PM or VFS servers (Minix)


I'm trying to write a system call for the Minix system. The system call is required to to seek a position and write to a file in that position.

However I am unable to call lseek or write, or fseek, fwrite, from inside the pm server. If I include any of the libraries which have those functions, the compiler does not seem to recognize the functions, it says they are undefined, thus gives me a crash on compiling.

My bet is that by the time PM,VFS servers are compiling, stdio, unistd, were not compile yet, thus the errors, but in that case, how am I supposed to seek or write to a file ?

Any clues ?

Thanks in advance.


Solution

  • You need to create new PM_ constants in com.h and handle them (e.g. with do_seek) in servers/vfs/main.c and use sendrec(VFS_PROC_NR, &m) in servers/pm/*.c code to call from PM into VFS and execute that code.

    The message for sendrec must be set up according to the expectation of the receiving VFS code (see seek.c or open.c or whatever inside of servers/vfs).

    The code inside PM to call VFS will look like library calls that use syscall() but will use sendrec() instead of syscall(), with m_type

    e.g. in some servers/pm/*.c file you want to write from:

    static int kwrite(int fd, const void * buf, int len)
     {
        message m;
    
        memset(&m, 0, sizeof(m));
    
        m.m_type = PM_WRITE;
        m.PM_VFS_FD = fd;
        m.PM_VFS_BUFLEN = len;
        m.PM_VFS_BUF = (void *)buf;
    
        /* printf("SYS PM Sending %s to VFS for write\n", (char *)buf); */
    
        if (sendrec(VFS_PROC_NR, &m) != 0)
            printf("SYS PM Error sending write of %d bytes to VFS from PM\n", len);
    
        return m.PM_STATUS;
     }
    

    and on the servers/vfs/main.c side inside service_pm()

    case PM_WRITE:
     {
        endpoint_t proc_e = job_m_in.PM_PROC;
        m_out.m_type = PM_WRITE_REPLY;
        m_out.PM_STATUS = do_write();
        m_out.PM_PROC = proc_e;
     }
    break;