예제 #1
0
static int do_open(void *msg, anvil_msginfo_t *msg_info) {

    struct anvil_open_msg   *openmsg;
    char                    name[1024];
    file_struct             *pfile;
    int                     found;
    fcb_t                   *fcb;
#if 0
    openmsg = (struct anvil_open_msg *)msg;

    if (openmsg->pathlen > 1023) {
        msg_reply(msg_info->pid, msg_info->tid, ENAMETOOLONG, NULL, 0);
        return -1;
    }

    msg_peek(msg_info->pid, msg_info->tid, name, openmsg->pathlen, sizeof(struct anvil_open_msg));
    name[openmsg->pathlen] = 0;
    anvil_syslog(0, "INITRD: do_open file <%s>\n", name);

    pfile = (file_struct *)dlist_peek_head(&filelist);
    found = 0;
    while (pfile) {
        if (!strcmp(pfile->filename, name)) {
            anvil_syslog(0, "*** INITRD: Found file %s\n", pfile->filename);
            found = 1;
            break; /* Break so that pfile is valid */
        }
        pfile = (file_struct *)dlist_peek_next(&filelist, (dlist_item_t *)pfile);
    }

    if (!found) {
        anvil_syslog(0, "INITRD: do_open couldn't find %s\n", name);
        msg_reply(msg_info->pid, msg_info->tid, ENOENT, NULL, 0);
        return -1;
    }

    fcb = (fcb_t *)malloc(sizeof(fcb_t));
    fcb->fs = pfile;
    fcb->pos = 0;
    fcb->data = pfile->addr;

    //anvil_syslog(0, "INITRD: do_open file <%s> fcb=%016lx\n", name, fcb);

    msg_port_allow(msg_info->pid, msg_info->tid, (void *)fcb, NULL);

    msg_reply(msg_info->pid, msg_info->tid, 0, NULL, 0);
#endif
    return 0;
}
예제 #2
0
파일: tty.c 프로젝트: jack2684/yalnix
/* Check if the process is at the head of the tty_read_queue
 */
int is_tty_read_head(pcb_t *proc, int tty_id){
    pcb_t *hproc = (pcb_t*) dlist_peek_head(tty_read_queues[tty_id]);
    return hproc == proc;
}
예제 #3
0
int init() {

    /*
     * Let's just check the file and make sure it makes sense. We just
     * need to be careful not to run past the end because we'll crash
     */

    tar_hdr     *tar_header;
    char        filename[110];
    char        timebuf[100];
    int         uid;
    int         gid;
    int         size;
    int         mtime;
    int         round_size;
    int         remaining;
    file_struct *pfile;
    int         err;
    char        *initrd_addr;
    char        *initrd_end;
    size_t      initrd_len;
    char        *basenam;

    anvil_sysinfo->initrd_info.base_addr;

    //anvil_syslog(0, "INITRD: Checking the tar file from %016lx len %016lx\n",
    //        anvil_sysinfo->initrd_info.base_addr, anvil_sysinfo->initrd_info.length);

    initrd_len = anvil_sysinfo->initrd_info.length;

    //anvil_syslog(0, "INITRD: End = %016lx\n", anvil_sysinfo->initrd_info.base_addr + anvil_sysinfo->initrd_info.length);

    dlist_init(&filelist);

    initrd_addr = (char *)mmap(0, initrd_len, PROT_READ, MAP_PHYS | MAP_PRIVATE, -1, anvil_sysinfo->initrd_info.base_addr);

    tar_header = (tar_hdr *)initrd_addr;

    initrd_end = initrd_addr + initrd_len;

    //anvil_syslog(0, "INITRD file list\n");

    while (1) {
        /* Check we haven't reached the end of the tar file */
        remaining = initrd_end - (char *)tar_header;
        //kdebug("Remaining = %d\n", remaining);
        if (remaining <= 1024) {
            /* There are always 1024 NUL chars at the end of the file */
            break;
        }
        /* Check the filename */
        strncpy(filename, tar_header->filename, 99);
        //anvil_syslog(0, "%12s - ", filename);
        basenam = basename(filename);
        uid   = strtol(tar_header->uid, NULL, 8);
        gid   = strtol(tar_header->gid, NULL, 8);
        size  = strtol(tar_header->size, NULL, 8);
        mtime = strtol(tar_header->mtime, NULL, 8);
        if (size == 0) {
            round_size = 0;
        }
        else {
            round_size = (((size-1)/512)+1)*512;
        }
        strcpy(timebuf, asctime(gmtime((const time_t *)&mtime)));

        //anvil_syslog(0, "%12s - ", basenam);
        //anvil_syslog(0, "%s %3d,%3d %7d bytes %s", tar_header->filemode+3, uid,
        //        gid, size, timebuf);

        pfile = (file_struct *)malloc(sizeof(file_struct) + strlen(filename) + 1);
        pfile->open = 0;
        pfile->offs = (char *)tar_header - initrd_addr;
        pfile->size = size;
        /* The data starts right after the header */
        pfile->addr = (char *)(tar_header + 1);
        strcpy(pfile->filename, basenam);

        dlist_add_tail(&filelist, (dlist_item_t *)pfile);
        tar_header = (tar_hdr *)((char *)tar_header + 512 + round_size);
    }
    //anvil_syslog(0, "INITRD file list end\n");

    pfile = (file_struct *)dlist_peek_head(&filelist);
    while (pfile) {
        //anvil_syslog(0, "*** INITRD: Found file %s\n", pfile->filename);
        pfile = (file_struct *)dlist_peek_next(&filelist, (dlist_item_t *)pfile);
    }

    /* All okay so return 0 */
    return 0;
}