Beispiel #1
0
int read(int fdesc, char * buf, int count)
{
	struct iob * io;

	if ((io = iob_from_fdesc(fdesc)) == NULL)
	{
		return (-1);
	}

	if ((io->i_offset + count) > (unsigned int)io->i_filesize)
	{
		count = io->i_filesize - io->i_offset;
	}

	if (count <= 0)
	{
		return 0;  // end of file
	}

	bcopy(io->i_buf + io->i_offset, buf, count);

	io->i_offset += count;

	return count;
}
Beispiel #2
0
Datei: sys.c Projekt: aosm/boot
int file_size(int fdesc)
{
	register struct iob *io;
    
	if ((io = iob_from_fdesc(fdesc)) == 0) {
		return (-1);
	}
	return io->i_ino.i_size;
}
Beispiel #3
0
int file_size(int fdesc)
{
    struct iob * io;

    if ((io = iob_from_fdesc(fdesc)) == 0)
        return 0;

    return io->i_filesize;
}
Beispiel #4
0
int tell(int fdesc)
{
    struct iob * io;

    if ((io = iob_from_fdesc(fdesc)) == NULL)
        return 0;

    return io->i_offset;
}
Beispiel #5
0
int b_lseek(int fdesc, int offset, int ptr)
{
    struct iob * io;

    if ((io = iob_from_fdesc(fdesc)) == NULL)
        return (-1);

    io->i_offset = offset;

    return offset;
}
Beispiel #6
0
int close(int fdesc)
{
    struct iob * io;

    if ((io = iob_from_fdesc(fdesc)) == NULL)
        return (-1);

    io->i_flgs = 0;

    return 0;
}
Beispiel #7
0
int writebyte(int fdesc, char value)
{
    struct iob * io;
    
    if ((io = iob_from_fdesc(fdesc)) == NULL)
        return (-1);
	
    if ((io->i_offset + 1) > (unsigned int)io->i_filesize)
        return 0;  // end of file
	
    io->i_buf[io->i_offset++] = value;
	
    return 1;
}
Beispiel #8
0
int writeint(int fdesc, int value)
{
    struct iob * io;
    
    if ((io = iob_from_fdesc(fdesc)) == NULL)
        return (-1);
	
    if ((io->i_offset + 4) > (unsigned int)io->i_filesize)
        return 0;  // end of file
	
    bcopy(&value, io->i_buf + io->i_offset, 4);
	
    io->i_offset += 4;
	
    return 4;
}
Beispiel #9
0
Datei: sys.c Projekt: aosm/boot
static int getch(int fdesc)
{
	register struct iob *io;
	struct fs *fs;
	char *p;
	int c, lbn, off, size, diff;

	if ((io = iob_from_fdesc(fdesc)) == 0) {
		return (-1);
	}
	p = io->i_ma;
	if (io->i_cc <= 0) {
		if ((io->i_flgs & F_FILE) != 0) {
			diff = io->i_ino.i_size - io->i_offset;
			if (diff <= 0)
				return (-1);
			fs = io->i_fs;
			lbn = lblkno(fs, io->i_offset);
			io->i_bn = fsbtodb(fs, sbmap(io, lbn)) + io->i_boff;
			off = blkoff(fs, io->i_offset);
			size = blksize(fs, &io->i_ino, lbn);
		} else {
			diff = 0;
#ifndef	SMALL
			io->i_bn = io->i_offset / DEV_BSIZE;
			off = 0;
			size = DEV_BSIZE;
#endif	SMALL
		}
		io->i_ma = io->i_buf;
		io->i_cc = size;
		if (devread(io) < 0) {
			return (-1);
		}
		if ((io->i_flgs & F_FILE) != 0) {
			if (io->i_offset - off + size >= io->i_ino.i_size)
				io->i_cc = diff + off;
			io->i_cc -= off;
		}
		p = &io->i_buf[off];
	}
	io->i_cc--;
	io->i_offset++;
	c = (unsigned)*p++;
	io->i_ma = p;
	return (c);
}
Beispiel #10
0
Datei: sys.c Projekt: aosm/boot
int
b_lseek(int fdesc, unsigned int addr, int ptr)
{
	register struct iob *io;

#if	CHECK_CAREFULLY
	if (ptr != 0) {
		error("Seek not from beginning of file\n");
		return (-1);
	}
#endif	CHECK_CAREFULLY
	if ((io = iob_from_fdesc(fdesc)) == 0) {
		return (-1);
	}
	io->i_offset = addr;
	io->i_bn = addr / DEV_BSIZE;
	io->i_cc = 0;
	return (0);
}
Beispiel #11
0
int write(int fdesc, const char * buf, int count)
{
    struct iob * io;
    
    if ((io = iob_from_fdesc(fdesc)) == NULL)
        return (-1);
	
    if ((io->i_offset + count) > (unsigned int)io->i_filesize)
        count = io->i_filesize - io->i_offset;
	
    if (count <= 0)
        return 0;  // end of file
	
    bcopy(buf, io->i_buf + io->i_offset, count);
	
    io->i_offset += count;
	
    return count;
}
Beispiel #12
0
Datei: sys.c Projekt: aosm/boot
int
close(int fdesc)
{
	register struct iob *file;
	register int i;

	if ((file = iob_from_fdesc(fdesc)) == 0) {
		return (-1);
	}
//	free((char *)file->i_fs);
	file->i_fs = NULL;
	free(file->i_buf); file->i_buf = NULL;
	for (i=0;i<NBUFS;i++)
	{
		if (b[i])
		{	free(b[i]); 
			b[i] = NULL;
		}
		blknos[i] = 0;
	}

	file->i_flgs = 0;
	return (0);
}
Beispiel #13
0
Datei: sys.c Projekt: aosm/boot
int
read(int fdesc, char *buf, int count)
{
	int i, size;
	register struct iob *file;
	struct fs *fs;
	int lbn, off;

	if ((file = iob_from_fdesc(fdesc)) == 0) {
		return (-1);
	}
	if ((file->i_flgs&F_READ) == 0) {
		return (-1);
	}
#ifndef	SMALL
	if ((file->i_flgs & F_FILE) == 0) {
		file->i_cc = count;
		file->i_ma = buf;
		file->i_bn = file->i_boff + (file->i_offset / DEV_BSIZE);
		i = devread(file);
		file->i_offset += count;
		return (i);
	}
#endif	SMALL
	if (file->i_offset+count > file->i_ino.i_size)
		count = file->i_ino.i_size - file->i_offset;
	if ((i = count) <= 0)
		return (0);
	/*
	 * While reading full blocks, do I/O into user buffer.
	 * Anything else uses getc().
	 */
	fs = file->i_fs;
	while (i) {
		off = blkoff(fs, file->i_offset);
		lbn = lblkno(fs, file->i_offset);
		size = blksize(fs, &file->i_ino, lbn);
		if (off == 0 && size <= i) {
			file->i_bn = fsbtodb(fs, sbmap(file, lbn)) +
			    file->i_boff;
			file->i_cc = size;
			file->i_ma = buf;
			if (devread(file) < 0) {
				return (-1);
			}
			file->i_offset += size;
			file->i_cc = 0;
			buf += size;
			i -= size;
		} else {
			size -= off;
			if (size > i)
				size = i;
			i -= size;
			do {
				*buf++ = getch(fdesc);
			} while (--size);
		}
	}
	return (count);
}