コード例 #1
0
ファイル: mount.c プロジェクト: disrvptor/xinu
/*------------------------------------------------------------------------
 *  mount  -  Add a prefix mapping to the name space
 *------------------------------------------------------------------------
 */
syscall	mount(
	  char		*prefix,	/* prefix to add		*/
	  char		*replace,	/* replacement string		*/
	  did32		device		/* device ID to use		*/
)
{
	intmask	mask;			/* saved interrupt mask		*/
	struct	nmentry	*namptr;	/* pointer to unused table entry*/
	int32	psiz, rsiz;		/* sizes of prefix & replacement*/
	int32	i;			/* counter for copy loop	*/

        mask = disable();

	psiz = namlen(prefix, NM_PRELEN);
	rsiz = namlen(replace, NM_REPLLEN);
	if ((psiz == SYSERR) || (rsiz == SYSERR) || isbaddev(device)) {
		restore(mask);
		return SYSERR;
	}

	if (nnames >= NNAMES) {		/* if table full return error */
		restore(mask);
		return SYSERR;
	}

	/* allocate a slot in the table */

	namptr = &nametab[nnames];	/* next unused entry in table	*/

	/* copy prefix and replacement strings and record device ID */
	
	for (i=0; i<psiz; i++) {	/* copy prefix into table entry	*/
		namptr->nprefix[i] = *prefix++;
	}

	for (i=0; i<rsiz; i++) {	/* copy replacement into entry	*/
		namptr->nreplace[i] = *replace++;
	}

	namptr->ndevice = device;	/* record the device ID		*/

        nnames++;			/* increment number of names	*/

	restore(mask);
	return OK;
}
コード例 #2
0
static int seqlist_populate(seqlist_t *lst, FILE *f){
  
  char *buf, *tmp;
  int i;
  
  /* allocate buffer for reading */
  if ((buf = malloc(BUFFLEN)) == NULL) 
	 err(EXIT_FAILURE, "memory: malloc failed"); 
  i = 0;
  while (fgets(buf, BUFFLEN, f) != NULL) {
	 if (*buf == '#' || *buf == '\n') continue;
	 i++;
	 tmp = strndup(buf, namlen(buf));
	 seqlist_add(lst, tmp); 
  }
  free(buf);
  return i;
}
コード例 #3
0
ファイル: fsdir.c プロジェクト: ragnar76/emutos
long xmkdir(char *s) 
{
        register OFD *f;
        register FCB *f2;
        OFD     *fd,*f0;
        FCB     *b;
        DND     *dn;
        int     h,cl,plen;
        long    rc;

        if ((h = rc = ixcreat(s,FA_SUBDIR)) < 0)
                return(rc);

        f = getofd(h);

        /* build a DND in the tree */

        fd = f->o_dirfil;

        ixlseek(fd,f->o_dirbyt);
        b = (FCB *) ixread(fd,32L,NULLPTR);

        /* is the total path length too long? */     /* M01.01.1107.01 */

        plen = namlen( b->f_name );
        for ( dn = f->o_dnode; dn; dn = dn->d_parent )
                plen += namlen( dn->d_name );
        if ( plen >= (LEN_ZPATH-3) )
        {
                ixdel( f->o_dnode, b, f->o_dirbyt );
                return ( EACCDN );
        }

        if( (dn = makdnd(f->o_dnode,b)) == NULLPTR )
        {
                ixdel( f->o_dnode, b, f->o_dirbyt );    /* M01.01.1103.01 */
                return (ENSMEM);
        }

        if( (dn->d_ofd = f0 = makofd(dn)) == (OFD*)NULLPTR )
        {
                ixdel( f->o_dnode, b, f->o_dirbyt );    /* M01.01.1103.01 */
                f->o_dnode->d_left = NULLPTR;            /* M01.01.1103.01 */
                xmfreblk((char *)dn);
                return (ENSMEM);
        }

        /* initialize dir cluster */

        if (nextcl(f0,1))
        {
                ixdel( f->o_dnode, b, f->o_dirbyt );    /* M01.01.1103.01 */
                f->o_dnode->d_left = NULLPTR;            /* M01.01.1103.01 */
                freednd(dn);                    /* M01.01.1031.02 */
                return(EACCDN);
        }

        f2 = dirinit(dn);                       /* pointer to dirty dir block */

        /* write identifier */

        memcpy(f2, dots, 22);
        f2->f_attrib = FA_SUBDIR;
        f2->f_time = time;
        swpw( f2->f_time ) ;           /*  M01.01.SCC.FS.04  */
        f2->f_date = date;
        swpw( f2->f_date ) ;           /*  M01.01.SCC.FS.04  */
        cl = f0->o_strtcl;
        swpw(cl);
        f2->f_clust = cl;
        f2->f_fileln = 0;
        f2++;

        /* write parent entry .. */

        memcpy(f2, dots, 22);
        f2->f_name[1] = '.';           /* This is .. */
        f2->f_attrib = FA_SUBDIR;
        f2->f_time = time;
        swpw( f2->f_time ) ;           /*  M01.01.SCC.FS.06  */
        f2->f_date = date;
        swpw( f2->f_date ) ;           /*  M01.01.SCC.FS.06  */
        cl = f->o_dirfil->o_strtcl;

        if (!fd->o_dnode)              /* if creating a folder in the root, the */
                cl = 0;                /*  cluster# of the .. entry must be 0   */

        swpw(cl);
        f2->f_clust = cl;
        f2->f_fileln = 0;
        memcpy(f, f0, sizeof(OFD));
        f->o_flag |= O_DIRTY;
        ixclose(f,CL_DIR | CL_FULL);    /* force flush and write */
        xmfreblk((char*)f);
        sft[h-NUMSTD].f_own = 0;
        sft[h-NUMSTD].f_ofd = 0;
        return(E_OK);
}