Exemplo n.º 1
0
static long ReadDirEntry( InodePtr dirInode, long * fileInodeNum,
                          long long * dirIndex, char ** name )
{
    struct direct *dir;
    char          *buffer;
    long long     index;
    long          dirBlockNum, dirBlockOffset;

    while (1) {
        index = *dirIndex;
    
        dirBlockOffset = (long) (index % DIRBLKSIZ);
        dirBlockNum    = (long) (index / DIRBLKSIZ);

        buffer = ReadFileBlock(dirInode, dirBlockNum, 0, DIRBLKSIZ, 0, 1);
        if (buffer == 0) return -1;

        dir = (struct direct *)(buffer + dirBlockOffset);
        byte_swap_dir_block_in((char *)dir, 1);

        *dirIndex += dir->d_reclen;
        
        if (dir->d_ino != 0) break;
        
        if (dirBlockOffset != 0) return -1;
    }

    *fileInodeNum = dir->d_ino;
    *name = strlcpy(gTempName2, dir->d_name, dir->d_namlen+1);

    return 0;
}
Exemplo n.º 2
0
Arquivo: sys.c Projeto: aosm/boot
/*
 * get next entry in a directory.
 */
struct direct *
readdir(struct dirstuff *dirp)
{
	struct direct *dp;
	register struct iob *io;
	daddr_t lbn, d;
	int off;
#if DCACHE
	char *bp;
	int dirblkno;

	if (dcache == 0)
		dcache = cacheInit(DCACHE_SIZE, DIRBLKSIZ);
#endif DCACHE
	io = dirp->io;
	for(;;)
	{
		if (dirp->loc >= io->i_ino.i_size)
			return (NULL);
		off = blkoff(io->i_fs, dirp->loc);
		lbn = lblkno(io->i_fs, dirp->loc);

#if DCACHE
		dirblkno = dirp->loc / DIRBLKSIZ;
		if (cacheFind(dcache, io->i_ino.i_number, dirblkno, &bp)) {
		    dp = (struct direct *)(bp + (dirp->loc % DIRBLKSIZ));
		} else
#else DCACHE
		if (io->dirbuf_blkno != lbn)
#endif DCACHE
		{
		    if((d = sbmap(io, lbn)) == 0)
			    return NULL;
		    io->i_bn = fsbtodb(io->i_fs, d) + io->i_boff;
		    io->i_ma = io->i_buf;
		    io->i_cc = blksize(io->i_fs, &io->i_ino, lbn);
		
		    if (devread(io) < 0)
		    {
#if	SYS_MESSAGES
			    error("bn %d: directory read error\n",
				    io->i_bn);
#endif
			    return (NULL);
		    }
#if	BIG_ENDIAN_FS
		    byte_swap_dir_block_in(io->i_buf, io->i_cc);
#endif	BIG_ENDIAN_FS
#if DCACHE
		    bcopy(io->i_buf + dirblkno * DIRBLKSIZ, bp, DIRBLKSIZ);
		    dp = (struct direct *)(io->i_buf + off);
#endif
		}
#if !DCACHE
		dp = (struct direct *)(io->i_buf + off);
#endif
		dirp->loc += dp->d_reclen;

		if (dp->d_ino != 0) return (dp);
	}
}