Example #1
0
inoptr newfile(inoptr pino, char *name)
{
    inoptr nindex;
    uint8_t j;

    /* First see if parent is writeable */
    if(!(getperm(pino) & OTH_WR))
        goto nogood;

    if(!(nindex = i_open(pino->c_dev, 0)))
        goto nogood;

    /* BUG FIX:  user/group setting was missing  SN */
    nindex->c_node.i_uid = udata.u_euid;
    nindex->c_node.i_gid = udata.u_egid;

    nindex->c_node.i_mode = F_REG;   /* For the time being */
    nindex->c_node.i_nlink = 1;
    nindex->c_node.i_size = 0;
    for(j=0; j <20; j++)
        nindex->c_node.i_addr[j] = 0;
    wr_inode(nindex);

    if(!ch_link(pino, "", name, nindex)) {
        i_deref(nindex);
        goto nogood;
    }
    i_deref(pino);
    return nindex;

nogood:
    i_deref(pino);
    return NULLINODE;
}
void ICVM_creat(void){
	s32 mode=rSTKu32(1);
	R_R0=i_open(
		(char *)Nptr(rSTKs32(0)),
		ICVM_O_TRUNC | ICVM_O_CREAT | ICVM_O_WRONLY,
		mode);
	icvm_returnerr();
}
Example #3
0
arg_t make_socket(struct sockinfo *s, struct socket **np)
{
	struct socket *n;
	int8_t uindex;
	int8_t oftindex;
	inoptr ino;

	/* RAW sockets are superuser */
	if (s->priv && esuper())
		return -1;

	if (np)
		n = *np;
	else {
		n = alloc_socket();
		if (n == NULL)
			return -1;
	}
	n->s_type = s - socktypes;	/* Pointer or uint8_t best ? */
	n->s_state = SS_INIT;

	if (net_init(n) == -1)
		goto nosock;

	/* Start by getting the file and inode table entries */
	if ((uindex = uf_alloc()) == -1)
		goto nosock;
	if ((oftindex = oft_alloc()) == -1)
		goto nooft;

	/* We need an inode : FIXME - do we want a pipedev aka Unix ? */
	if (!(ino = i_open(root_dev, 0)))
		goto noalloc;
	/* All good - now set it up */
	/* The nlink cheat needs to be taught to fsck! */
	ino->c_node.i_mode = F_SOCK | 0777;
	ino->c_node.i_nlink = n->s_num;	/* Cheat !! */
	ino->c_readers = 1;
	ino->c_writers = 1;

	of_tab[oftindex].o_inode = ino;
	of_tab[oftindex].o_access = O_RDWR;

	udata.u_files[uindex] = oftindex;

	sock_wait_leave(n, 0, SS_INIT);
	if (np)
		*np = n;
	return uindex;

noalloc:
	oft_deref(oftindex);	/* Will call i_deref! */
nooft:
	udata.u_files[uindex] = NO_FILE;
nosock:
	n->s_state = SS_UNUSED;
	return -1;
}
void ICVM_open(void){
	s32 flags=rSTKu32(1);
	s32 mode=0;
	if(flags & ICVM_O_CREAT)
		mode=rSTKu32(2);
	R_R0=i_open(
		(char *)Nptr(rSTKs32(0)),
		flags,
		mode);
	icvm_returnerr();
}
Example #5
0
arg_t make_socket(struct sockinfo *s, int8_t *np)
{
	int8_t n;
	int8_t uindex;
	int8_t oftindex;
	inoptr ino;

	/* RAW sockets are superuser */
	if (s->priv && esuper())
		return -1;

	/* Start by getting the file and inode table entries */
	if ((uindex = uf_alloc()) == -1)
		return -1;
	if ((oftindex = oft_alloc()) == -1)
		goto nooft;

	if (np)
		n = *np;
	else {
		n = alloc_socket();
		if (n == -1)
			goto noalloc;
	}
	/* We need an inode : FIXME - do we want a pipedev aka Unix ? */
	if (!(ino = i_open(root_dev, 0)))
		goto noalloc;
	/* All good - now set it up */
	/* The nlink cheat needs to be taught to fsck! */
	ino->c_node.i_mode = F_SOCK | 0777;
	ino->c_node.i_nlink = n;	/* Cheat !! */

	of_tab[oftindex].o_inode = ino;
	of_tab[oftindex].o_access = O_RDWR;

	udata.u_files[uindex] = oftindex;

	sockets[n].s_inode = ino;
	sockets[n].s_type = s - socktypes;	/* Pointer or uint8_t best ? */
	sockets[n].s_state = SS_UNCONNECTED;

	if (np)
		*np = n;
	return uindex;

noalloc:
	oft_deref(oftindex);	/* Will call i_deref! */
nooft:
	udata.u_files[uindex] = NO_FILE;
	return -1;
}
Example #6
0
inoptr srch_mt(inoptr ino)
{
    uint8_t j;
    struct mount *m = &fs_tab[0];

    for(j=0; j < NMOUNTS; ++j){
        if(m->m_dev != NO_DEVICE &&  m->m_fs->s_mntpt == ino) {
            i_deref(ino);
            return i_open(m->m_dev, ROOTINODE);
        }
        m++;
    };
    return ino;
}
Example #7
0
arg_t _pipe(void)
{
	int8_t u1, u2, oft1, oft2;
	inoptr ino;

/* bug fix SN */
	if ((u1 = uf_alloc()) == -1)
		goto nogood;
	if ((oft1 = oft_alloc()) == -1)
		goto nogood;
	udata.u_files[u1] = oft1;

	if ((u2 = uf_alloc()) == -1)
		goto nogood2;
	if ((oft2 = oft_alloc()) == -1)
		goto nogood2;

	if (!(ino = i_open(root_dev, 0))) {
		oft_deref(oft2);
		goto nogood2;
	}

	udata.u_files[u2] = oft2;

	of_tab[oft1].o_ptr = 0;
	of_tab[oft1].o_inode = ino;
	of_tab[oft1].o_access = O_RDONLY;

	of_tab[oft2].o_ptr = 0;
	of_tab[oft2].o_inode = ino;
	of_tab[oft2].o_access = O_WRONLY;

	++ino->c_refs;
	ino->c_node.i_mode = F_PIPE | 0777;	/* No permissions necessary on pipes */
	ino->c_node.i_nlink = 0;	/* a pipe is not in any directory */

	// write results to userspace
	uputw(u1, fildes);
	uputw(u2, fildes + 1);
	return (0);

      nogood2:
	oft_deref(oft1);
	udata.u_files[u1] = NO_FILE;
      nogood:
	return (-1);
}
Example #8
0
inoptr srch_dir(inoptr wd, char *compname)
{
    int curentry;
    blkno_t curblock;
    struct direct *buf;
    int nblocks;
    uint16_t inum;

    nblocks = (wd->c_node.i_size + BLKMASK) >> BLKSHIFT;

    for(curblock=0; curblock < nblocks; ++curblock) {
        buf = (struct direct *)bread(wd->c_dev, bmap(wd, curblock, 1), 0);
        for(curentry = 0; curentry < (512/DIR_LEN); ++curentry) {
            if(namecomp(compname, buf[curentry].d_name)) {
                inum = buf[curentry & 0x1f].d_ino;
                brelse(buf);
                return i_open(wd->c_dev, inum);
            }
        }
        brelse(buf);
    }
    return NULLINODE;
}
Example #9
0
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();
}
Example #10
0
/****************************************************************************
REMARKS:
VxD implementation of the ANSI C fopen function.
****************************************************************************/
FILE * fopen(
	const char *filename,
	const char *mode)
{
	FILE 	*f = malloc(sizeof(FILE));
	long	oldpos;

	if (f) {
		f->offset = 0;
		f->text = (mode[1] == 't' || mode[2] == 't');
		f->writemode = (mode[0] == 'w') || (mode[0] == 'a');
		f->unputc = EOF;
		f->endp = f->buf + sizeof(f->buf);
		f->curp = f->startp = f->buf;
		if (initComplete) {
			WORD	omode,error;
			BYTE	action;

			if (mode[0] == 'r') {
				omode = OPEN_ACCESS_READONLY | OPEN_SHARE_COMPATIBLE;
				action = ACTION_IFEXISTS_OPEN | ACTION_IFNOTEXISTS_FAIL;
				}
			else if (mode[0] == 'w') {
				omode = OPEN_ACCESS_WRITEONLY | OPEN_SHARE_COMPATIBLE;
				action = ACTION_IFEXISTS_TRUNCATE | ACTION_IFNOTEXISTS_CREATE;
				}
			else {
				omode = OPEN_ACCESS_READWRITE | OPEN_SHARE_COMPATIBLE;
				action = ACTION_IFEXISTS_OPEN | ACTION_IFNOTEXISTS_CREATE;
				}
			f->handle = (int)R0_OpenCreateFile(false,(char*)filename,omode,ATTR_NORMAL,action,0,&error,&action);
			if (f->handle == 0) {
				free(f);
				return NULL;
				}
			f->filesize = R0_GetFileSize((HANDLE)f->handle,&error);
			if (mode[0] == 'a')
				fseek(f,0,2);
			}
		else {
			int oflag,pmode;

			if (mode[0] == 'r') {
				pmode = _S_IREAD;
				oflag = _O_RDONLY;
				}
			else if (mode[0] == 'w') {
				pmode = _S_IWRITE;
				oflag = _O_WRONLY | _O_CREAT | _O_TRUNC;
				}
			else {
				pmode = _S_IWRITE;
				oflag = _O_RDWR | _O_CREAT | _O_APPEND;
				}
			if (f->text)
				oflag |= _O_TEXT;
			else
				oflag |= _O_BINARY;
			if ((f->handle = i_open(filename,oflag,pmode)) == -1) {
				free(f);
				return NULL;
				}
			oldpos = i_lseek(f->handle,0,1);
			f->filesize = i_lseek(f->handle,0,2);
			i_lseek(f->handle,oldpos,0);
			}
		}
	return f;
}
Example #11
0
File: start.c Project: Abioy/FUZIX
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();
}