Esempio n. 1
0
/*
 * Find a pathname
 */
void
getpathname(char *namebuf, ino_t curdir, ino_t ino)
{
    int len;
    char *cp;
    struct inodesc idesc;
    static int busy = 0;

    if (curdir == ino && ino == ROOTINO) {
        (void)strcpy(namebuf, "/");
        return;
    }
    if (busy || !INO_IS_DVALID(curdir)) {
        (void)strcpy(namebuf, "?");
        return;
    }
    busy = 1;
    memset(&idesc, 0, sizeof(struct inodesc));
    idesc.id_type = DATA;
    idesc.id_fix = IGNORE;
    cp = &namebuf[MAXPATHLEN - 1];
    *cp = '\0';
    if (curdir != ino) {
        idesc.id_parent = curdir;
        goto namelookup;
    }
    while (ino != ROOTINO) {
        idesc.id_number = ino;
        idesc.id_func = findino;
        idesc.id_name = strdup("..");
        if ((ckinode(ginode(ino), &idesc) & FOUND) == 0)
            break;
namelookup:
        idesc.id_number = idesc.id_parent;
        idesc.id_parent = ino;
        idesc.id_func = findname;
        idesc.id_name = namebuf;
        if ((ckinode(ginode(idesc.id_number), &idesc)&FOUND) == 0)
            break;
        len = strlen(namebuf);
        cp -= len;
        memmove(cp, namebuf, (size_t)len);
        *--cp = '/';
        if (cp < &namebuf[MAXNAMLEN])
            break;
        ino = idesc.id_number;
    }
    busy = 0;
    if (ino != ROOTINO)
        *--cp = '?';
    memmove(namebuf, cp, (size_t)(&namebuf[MAXPATHLEN] - cp));
}
Esempio n. 2
0
/*
 * allocate a new directory
 */
ino_t
allocdir(ino_t parent, ino_t request, int mode)
{
	ino_t ino;
	char *cp;
	union dinode *dp;
	struct bufarea *bp;
	struct inoinfo *inp;
	struct dirtemplate *dirp;

	ino = allocino(request, IFDIR|mode);
	dirp = &dirhead;
	dirp->dot_ino = ino;
	dirp->dotdot_ino = parent;
	dp = ginode(ino);
	bp = getdirblk(DIP(dp, di_db[0]), sblock.fs_fsize);
	if (bp->b_errs) {
		freeino(ino);
		return (0);
	}
	memmove(bp->b_un.b_buf, dirp, sizeof(struct dirtemplate));
	for (cp = &bp->b_un.b_buf[DIRBLKSIZ];
	     cp < &bp->b_un.b_buf[sblock.fs_fsize];
	     cp += DIRBLKSIZ)
		memmove(cp, &emptydir, sizeof emptydir);
	dirty(bp);
	DIP_SET(dp, di_nlink, 2);
	inodirty();
	if (ino == ROOTINO) {
		inoinfo(ino)->ino_linkcnt = DIP(dp, di_nlink);
		cacheino(dp, ino);
		return(ino);
	}
	if (!INO_IS_DVALID(parent)) {
		freeino(ino);
		return (0);
	}
	cacheino(dp, ino);
	inp = getinoinfo(ino);
	inp->i_parent = parent;
	inp->i_dotdot = parent;
	inoinfo(ino)->ino_state = inoinfo(parent)->ino_state;
	if (inoinfo(ino)->ino_state == DSTATE) {
		inoinfo(ino)->ino_linkcnt = DIP(dp, di_nlink);
		inoinfo(parent)->ino_linkcnt++;
	}
	dp = ginode(parent);
	DIP_SET(dp, di_nlink, DIP(dp, di_nlink) + 1);
	inodirty();
	return (ino);
}