/* Newproc fixes up the tables for the child of a fork but also for init * Call in the processes context! * This process MUST be run immediately (since it sets status P_RUNNING) */ void newproc(ptptr p) { /* Passed New process table entry */ uint8_t *j; irqflags_t irq; irq = di(); /* Note that ptab_alloc clears most of the entry */ /* calculate base page of process based on ptab table offset */ udata.u_page = p->p_page; udata.u_page2 = p->p_page2; program_vectors(&p->p_page); /* set up vectors in new process and if needed copy any common code */ p->p_status = P_RUNNING; nready++; /* runnable process count */ p->p_pptr = udata.u_ptab; p->p_ignored = udata.u_ptab->p_ignored; p->p_tty = udata.u_ptab->p_tty; p->p_uid = udata.u_ptab->p_uid; /* Set default priority */ p->p_priority = MAXTICKS; /* For systems where udata is actually a pointer or a register object */ #ifdef udata p->p_udata = &udata; #endif udata.u_ptab = p; memset(&udata.u_utime, 0, 4 * sizeof(clock_t)); /* Clear tick counters */ rdtime32(&udata.u_time); if (udata.u_cwd) i_ref(udata.u_cwd); if (udata.u_root) i_ref(udata.u_root); udata.u_cursig = 0; udata.u_error = 0; for (j = udata.u_files; j < (udata.u_files + UFTSIZE); ++j) { if (*j != NO_FILE) ++of_tab[*j].o_refs; } irqrestore(irq); }
arg_t _fchdir(void) { inoptr newcwd; if ((newcwd = getinode(fd)) == NULLINODE) return (-1); i_ref(newcwd); return chdiroot_op(newcwd, &udata.u_cwd); }
void fuzix_main(void) { /* setup state */ inint = false; udata.u_insys = true; #ifdef PROGTOP /* FIXME */ ramtop = (uaddr_t)PROGTOP; #endif tty_init(); if (d_open(TTYDEV, 0) != 0) panic(PANIC_NOTTY); /* Sign on messages */ kprintf( "FUZIX version %s\n" "Copyright (c) 1988-2002 by H.F.Bower, D.Braun, S.Nitschke, H.Peraza\n" "Copyright (c) 1997-2001 by Arcady Schekochikhin, Adriano C. R. da Cunha\n" "Copyright (c) 2013-2015 Will Sowerbutts <*****@*****.**>\n" "Copyright (c) 2014-2015 Alan Cox <*****@*****.**>\nDevboot\n", sysinfo.uname); #ifndef SWAPDEV #ifdef PROC_SIZE maxproc = procmem / PROC_SIZE; /* Check we don't exceed the process table size limit */ if (maxproc > PTABSIZE) { kprintf("WARNING: Increase PTABSIZE to %d to use available RAM\n", maxproc); maxproc = PTABSIZE; } #else maxproc = PTABSIZE; #endif #else maxproc = PTABSIZE; #endif /* Used as a stop marker to make compares fast on process scheduling and the like */ ptab_end = &ptab[maxproc]; /* Parameters message */ kprintf("%dkB total RAM, %dkB available to processes (%d processes max)\n", ramsize, procmem, maxproc); bufinit(); fstabinit(); pagemap_init(); create_init(); /* runtime configurable, defaults to build time setting */ ticks_per_dsecond = TICKSPERSEC / 10; kputs("Enabling interrupts ... "); __hard_ei(); /* Physical interrupts on */ kputs("ok.\n"); /* get the root device */ root_dev = get_root_dev(); /* finish building argv */ complete_init(); /* initialise hardware devices */ device_init(); /* Mount the root device */ kprintf("Mounting root fs (root_dev=%d, r%c): ", root_dev, ro ? 'o' : 'w'); if (fmount(root_dev, NULLINODE, ro)) panic(PANIC_NOFILESYS); root = i_open(root_dev, ROOTINODE); if (!root) panic(PANIC_NOROOT); kputs("OK\n"); udata.u_cwd = i_ref(root); udata.u_root = i_ref(root); rdtime32(&udata.u_time); exec_or_die(); }
inoptr kn_open(char *namep, inoptr *parent) { staticfast inoptr wd; /* the directory we are currently searching. */ staticfast inoptr ninode; inoptr temp; staticfast char *name; name = namep; #ifdef DEBUG kprintf("kn_open(\"%s\")\n", name); #endif if(*name == '/') wd = udata.u_root; else wd = udata.u_cwd; i_ref(ninode = wd); i_ref(ninode); for(;;) { if(ninode) magic(ninode); /* cheap way to spot rename inside yourself */ if (udata.u_rename == ninode) udata.u_rename = NULLINODE; /* See if we are at a mount point */ if(ninode) ninode = srch_mt(ninode); while(*name == '/') /* Skip(possibly repeated) slashes */ ++name; if(!*name) /* No more components of path? */ break; if(!ninode){ udata.u_error = ENOENT; goto nodir; } i_deref(wd); wd = ninode; if(getmode(wd) != F_DIR){ udata.u_error = ENOTDIR; goto nodir; } if(!(getperm(wd) & OTH_EX)){ udata.u_error = EPERM; goto nodir; } /* See if we are going up through a mount point */ if((wd == udata.u_root || (wd->c_num == ROOTINODE && wd->c_dev != root_dev)) && name[0] == '.' && name[1] == '.' && (name[2] == '/' || name[2] == '\0')){ if (wd == udata.u_root) { ninode = wd; name += 2; continue; } temp = fs_tab_get(wd->c_dev)->m_fs->s_mntpt; ++temp->c_refs; i_deref(wd); wd = temp; } ninode = srch_dir(wd, name); while(*name != '/' && *name) ++name; } if(parent) *parent = wd; else i_deref(wd); if(!(parent || ninode)) udata.u_error = ENOENT; return ninode; nodir: if(parent) *parent = NULLINODE; i_deref(wd); return NULLINODE; }
void fuzix_main(void) { /* setup state */ inint = false; udata.u_insys = true; ramtop = PROGTOP; tty_init(); if (d_open(TTYDEV, 0) != 0) panic("no tty"); /* Sign on messages (stashed in a buffer so we can bin them */ kprintf((char *)bufpool[0].bf_data, uname_str); #ifndef SWAPDEV #ifdef PROC_SIZE maxproc = procmem / PROC_SIZE; /* Check we don't exceed the process table size limit */ if (maxproc > PTABSIZE) { kprintf((char *)bufpool[1].bf_data, maxproc); maxproc = PTABSIZE; } #else maxproc = PTABSIZE; #endif #else maxproc = PTABSIZE; #endif /* Parameters message */ kprintf((char *)bufpool[2].bf_data, ramsize, procmem, maxproc); /* Now blow away the strings */ bufinit(); pagemap_init(); create_init(); kprintf("%x:%x\n", udata.u_page, udata.u_page2); kprintf("%x:%x\n", udata.u_ptab->p_page, udata.u_ptab->p_page2); kputs("Enabling interrupts ... "); ei(); kputs("ok.\n"); /* initialise hardware devices */ device_init(); root_dev = DEFAULT_ROOT; if (cmdline && *cmdline) { while (*cmdline == ' ') ++cmdline; root_dev = *cmdline - '0'; } else { kputs("bootdev: "); udata.u_base = bootline; udata.u_sysio = 1; udata.u_count = 2; udata.u_euid = 0; /* Always begin as superuser */ cdread(TTYDEV, O_RDONLY); /* read root filesystem name from tty */ if (*bootline >= '0') root_dev = *bootline - '0'; } /* Mount the root device */ kprintf("Mounting root fs (root_dev=%d): ", root_dev); if (fmount(root_dev, NULLINODE, 0)) panic("no filesys"); root = i_open(root_dev, ROOTINODE); if (!root) panic("no root"); kputs("OK\n"); i_ref(udata.u_cwd = root); i_ref(udata.u_root = root); rdtime32(&udata.u_time); exec_or_die(); }