standardize various * conventions
This commit is contained in:
parent
03b6376f56
commit
9e9bcaf143
8
bio.c
8
bio.c
|
@ -32,7 +32,7 @@ binit(void)
|
|||
}
|
||||
}
|
||||
|
||||
struct buf *
|
||||
struct buf*
|
||||
getblk(uint dev, uint sector)
|
||||
{
|
||||
struct buf *b;
|
||||
|
@ -67,7 +67,7 @@ getblk(uint dev, uint sector)
|
|||
}
|
||||
}
|
||||
|
||||
struct buf *
|
||||
struct buf*
|
||||
bread(uint dev, uint sector)
|
||||
{
|
||||
void *c;
|
||||
|
@ -80,7 +80,7 @@ bread(uint dev, uint sector)
|
|||
|
||||
acquire(&ide_lock);
|
||||
c = ide_start_rw(dev & 0xff, sector, b->data, 1, 1);
|
||||
sleep (c, &ide_lock);
|
||||
sleep(c, &ide_lock);
|
||||
ide_finish(c);
|
||||
b->flags |= B_VALID;
|
||||
release(&ide_lock);
|
||||
|
@ -96,7 +96,7 @@ bwrite(struct buf *b, uint sector)
|
|||
|
||||
acquire(&ide_lock);
|
||||
c = ide_start_rw(b->dev & 0xff, sector, b->data, 1, 0);
|
||||
sleep (c, &ide_lock);
|
||||
sleep(c, &ide_lock);
|
||||
ide_finish(c);
|
||||
b->flags |= B_VALID;
|
||||
release(&ide_lock);
|
||||
|
|
14
bootmain.c
14
bootmain.c
|
@ -31,7 +31,7 @@
|
|||
**********************************************************************/
|
||||
|
||||
#define SECTSIZE 512
|
||||
#define ELFHDR ((struct elfhdr *) 0x10000) // scratch space
|
||||
#define ELFHDR ((struct elfhdr*) 0x10000) // scratch space
|
||||
|
||||
void readsect(void*, uint);
|
||||
void readseg(uint, uint, uint);
|
||||
|
@ -45,18 +45,18 @@ cmain(void)
|
|||
readseg((uint) ELFHDR, SECTSIZE*8, 0);
|
||||
|
||||
// is this a valid ELF?
|
||||
if (ELFHDR->magic != ELF_MAGIC)
|
||||
if(ELFHDR->magic != ELF_MAGIC)
|
||||
goto bad;
|
||||
|
||||
// load each program segment (ignores ph flags)
|
||||
ph = (struct proghdr *) ((uchar *) ELFHDR + ELFHDR->phoff);
|
||||
ph = (struct proghdr*) ((uchar*) ELFHDR + ELFHDR->phoff);
|
||||
eph = ph + ELFHDR->phnum;
|
||||
for (; ph < eph; ph++)
|
||||
for(; ph < eph; ph++)
|
||||
readseg(ph->va, ph->memsz, ph->offset);
|
||||
|
||||
// call the entry point from the ELF header
|
||||
// note: does not return!
|
||||
((void (*)(void)) (ELFHDR->entry & 0xFFFFFF))();
|
||||
((void(*)(void)) (ELFHDR->entry & 0xFFFFFF))();
|
||||
|
||||
bad:
|
||||
outw(0x8A00, 0x8A00);
|
||||
|
@ -84,7 +84,7 @@ readseg(uint va, uint count, uint offset)
|
|||
// If this is too slow, we could read lots of sectors at a time.
|
||||
// We'd write more to memory than asked, but it doesn't matter --
|
||||
// we load in increasing order.
|
||||
while (va < end_va) {
|
||||
while(va < end_va) {
|
||||
readsect((uchar*) va, offset);
|
||||
va += SECTSIZE;
|
||||
offset++;
|
||||
|
@ -95,7 +95,7 @@ void
|
|||
waitdisk(void)
|
||||
{
|
||||
// wait for disk reaady
|
||||
while ((inb(0x1F7) & 0xC0) != 0x40)
|
||||
while((inb(0x1F7) & 0xC0) != 0x40)
|
||||
/* do nothing */;
|
||||
}
|
||||
|
||||
|
|
2
cat.c
2
cat.c
|
@ -24,7 +24,7 @@ main(int argc, char *argv[])
|
|||
{
|
||||
int fd, i;
|
||||
|
||||
if (argc <= 1) {
|
||||
if(argc <= 1) {
|
||||
rfile(0);
|
||||
} else {
|
||||
for(i = 1; i < argc; i++){
|
||||
|
|
28
console.c
28
console.c
|
@ -20,7 +20,7 @@ lpt_putc(int c)
|
|||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; !(inb(0x378+1) & 0x80) && i < 12800; i++)
|
||||
for(i = 0; !(inb(0x378+1) & 0x80) && i < 12800; i++)
|
||||
;
|
||||
outb(0x378+0, c);
|
||||
outb(0x378+2, 0x08|0x04|0x01);
|
||||
|
@ -31,7 +31,7 @@ static void
|
|||
cons_putc(int c)
|
||||
{
|
||||
int crtport = 0x3d4; // io port of CGA
|
||||
ushort *crt = (ushort *) 0xB8000; // base of CGA memory
|
||||
ushort *crt = (ushort*) 0xB8000; // base of CGA memory
|
||||
int ind;
|
||||
|
||||
if(panicked){
|
||||
|
@ -104,7 +104,7 @@ void
|
|||
cprintf(char *fmt, ...)
|
||||
{
|
||||
int i, state = 0, c, locking = 0;
|
||||
uint *ap = (uint *)(void*)&fmt + 1;
|
||||
uint *ap = (uint*)(void*)&fmt + 1;
|
||||
|
||||
if(use_console_lock){
|
||||
locking = 1;
|
||||
|
@ -166,13 +166,13 @@ panic(char *s)
|
|||
}
|
||||
|
||||
int
|
||||
console_write (int minor, char *buf, int n)
|
||||
console_write(int minor, char *buf, int n)
|
||||
{
|
||||
int i;
|
||||
|
||||
acquire(&console_lock);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
for(i = 0; i < n; i++) {
|
||||
cons_putc(buf[i] & 0xff);
|
||||
}
|
||||
|
||||
|
@ -311,23 +311,23 @@ kbd_intr()
|
|||
acquire(&kbd_lock);
|
||||
|
||||
st = inb(KBSTATP);
|
||||
if ((st & KBS_DIB) == 0){
|
||||
if((st & KBS_DIB) == 0){
|
||||
release(&kbd_lock);
|
||||
return;
|
||||
}
|
||||
data = inb(KBDATAP);
|
||||
|
||||
if (data == 0xE0) {
|
||||
if(data == 0xE0) {
|
||||
shift |= E0ESC;
|
||||
release(&kbd_lock);
|
||||
return;
|
||||
} else if (data & 0x80) {
|
||||
} else if(data & 0x80) {
|
||||
// Key released
|
||||
data = (shift & E0ESC ? data : data & 0x7F);
|
||||
shift &= ~(shiftcode[data] | E0ESC);
|
||||
release(&kbd_lock);
|
||||
return;
|
||||
} else if (shift & E0ESC) {
|
||||
} else if(shift & E0ESC) {
|
||||
// Last character was an E0 escape; or with 0x80
|
||||
data |= 0x80;
|
||||
shift &= ~E0ESC;
|
||||
|
@ -337,15 +337,15 @@ kbd_intr()
|
|||
shift ^= togglecode[data];
|
||||
|
||||
c = charcode[shift & (CTL | SHIFT)][data];
|
||||
if (shift & CAPSLOCK) {
|
||||
if ('a' <= c && c <= 'z')
|
||||
if(shift & CAPSLOCK) {
|
||||
if('a' <= c && c <= 'z')
|
||||
c += 'A' - 'a';
|
||||
else if ('A' <= c && c <= 'Z')
|
||||
else if('A' <= c && c <= 'Z')
|
||||
c += 'a' - 'A';
|
||||
}
|
||||
|
||||
// xxx hack
|
||||
if (c == 0x0) {
|
||||
if(c == 0x0) {
|
||||
release(&kbd_lock);
|
||||
return;
|
||||
}
|
||||
|
@ -397,7 +397,7 @@ console_init()
|
|||
devsw[CONSOLE].d_write = console_write;
|
||||
devsw[CONSOLE].d_read = console_read;
|
||||
|
||||
ioapic_enable (IRQ_KBD, 0);
|
||||
ioapic_enable(IRQ_KBD, 0);
|
||||
|
||||
use_console_lock = 1;
|
||||
}
|
||||
|
|
8
defs.h
8
defs.h
|
@ -1,5 +1,5 @@
|
|||
// kalloc.c
|
||||
char *kalloc(int);
|
||||
char* kalloc(int);
|
||||
void kfree(char*, int);
|
||||
void kinit(void);
|
||||
|
||||
|
@ -18,7 +18,7 @@ struct proc* copyproc(struct proc*);
|
|||
struct spinlock;
|
||||
uint growproc(int);
|
||||
void sleep(void*, struct spinlock*);
|
||||
void wakeup(void *);
|
||||
void wakeup(void*);
|
||||
void scheduler(void);
|
||||
void proc_exit(void);
|
||||
int proc_kill(int);
|
||||
|
@ -35,9 +35,9 @@ void tvinit(void);
|
|||
void idtinit(void);
|
||||
|
||||
// string.c
|
||||
void * memset(void*, int, uint);
|
||||
void* memset(void*, int, uint);
|
||||
int memcmp(const void*, const void*, uint);
|
||||
void *memmove(void*, const void*, uint);
|
||||
void* memmove(void*, const void*, uint);
|
||||
int strncmp(const char*, const char*, uint);
|
||||
|
||||
// syscall.c
|
||||
|
|
6
dev.h
6
dev.h
|
@ -1,7 +1,7 @@
|
|||
struct devsw {
|
||||
int (*d_open)(char *, int);
|
||||
int (*d_read)(int, char *, int);
|
||||
int (*d_write)(int, char *, int);
|
||||
int (*d_open)(char*, int);
|
||||
int (*d_read)(int, char*, int);
|
||||
int (*d_write)(int, char*, int);
|
||||
int (*d_close)(int);
|
||||
};
|
||||
|
||||
|
|
8
fd.c
8
fd.c
|
@ -39,7 +39,7 @@ fd_ualloc(void)
|
|||
/*
|
||||
* allocate a file descriptor structure
|
||||
*/
|
||||
struct fd *
|
||||
struct fd*
|
||||
fd_alloc(void)
|
||||
{
|
||||
int i;
|
||||
|
@ -67,10 +67,10 @@ fd_write(struct fd *fd, char *addr, int n)
|
|||
return -1;
|
||||
if(fd->type == FD_PIPE){
|
||||
return pipe_write(fd->pipe, addr, n);
|
||||
} else if (fd->type == FD_FILE) {
|
||||
} else if(fd->type == FD_FILE) {
|
||||
ilock(fd->ip);
|
||||
int r = writei (fd->ip, addr, fd->off, n);
|
||||
if (r > 0) {
|
||||
int r = writei(fd->ip, addr, fd->off, n);
|
||||
if(r > 0) {
|
||||
fd->off += r;
|
||||
}
|
||||
iunlock(fd->ip);
|
||||
|
|
144
fs.c
144
fs.c
|
@ -39,26 +39,26 @@ balloc(uint dev)
|
|||
uchar m;
|
||||
|
||||
bp = bread(dev, 1);
|
||||
sb = (struct superblock *) bp->data;
|
||||
sb = (struct superblock*) bp->data;
|
||||
size = sb->size;
|
||||
ninodes = sb->ninodes;
|
||||
|
||||
for (b = 0; b < size; b++) {
|
||||
if (b % BPB == 0) {
|
||||
for(b = 0; b < size; b++) {
|
||||
if(b % BPB == 0) {
|
||||
brelse(bp);
|
||||
bp = bread(dev, BBLOCK(b, ninodes));
|
||||
}
|
||||
bi = b % BPB;
|
||||
m = 0x1 << (bi % 8);
|
||||
if ((bp->data[bi/8] & m) == 0) { // is block free?
|
||||
if((bp->data[bi/8] & m) == 0) { // is block free?
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (b >= size)
|
||||
if(b >= size)
|
||||
panic("balloc: out of blocks");
|
||||
|
||||
bp->data[bi/8] |= 0x1 << (bi % 8);
|
||||
bwrite (bp, BBLOCK(b, ninodes)); // mark it allocated on disk
|
||||
bwrite(bp, BBLOCK(b, ninodes)); // mark it allocated on disk
|
||||
brelse(bp);
|
||||
return b;
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ bfree(int dev, uint b)
|
|||
uchar m;
|
||||
|
||||
bp = bread(dev, 1);
|
||||
sb = (struct superblock *) bp->data;
|
||||
sb = (struct superblock*) bp->data;
|
||||
ninodes = sb->ninodes;
|
||||
brelse(bp);
|
||||
|
||||
|
@ -86,7 +86,7 @@ bfree(int dev, uint b)
|
|||
bi = b % BPB;
|
||||
m = ~(0x1 << (bi %8));
|
||||
bp->data[bi/8] &= m;
|
||||
bwrite (bp, BBLOCK(b, ninodes)); // mark it free on disk
|
||||
bwrite(bp, BBLOCK(b, ninodes)); // mark it free on disk
|
||||
brelse(bp);
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,7 @@ bfree(int dev, uint b)
|
|||
* in use, otherwise read from the disk.
|
||||
* returns an inode with busy set and incremented reference count.
|
||||
*/
|
||||
struct inode *
|
||||
struct inode*
|
||||
iget(uint dev, uint inum)
|
||||
{
|
||||
struct inode *ip, *nip;
|
||||
|
@ -132,7 +132,7 @@ iget(uint dev, uint inum)
|
|||
release(&inode_table_lock);
|
||||
|
||||
bp = bread(dev, IBLOCK(inum));
|
||||
dip = &((struct dinode *)(bp->data))[inum % IPB];
|
||||
dip = &((struct dinode*)(bp->data))[inum % IPB];
|
||||
nip->type = dip->type;
|
||||
nip->major = dip->major;
|
||||
nip->minor = dip->minor;
|
||||
|
@ -145,24 +145,24 @@ iget(uint dev, uint inum)
|
|||
}
|
||||
|
||||
void
|
||||
iupdate (struct inode *ip)
|
||||
iupdate(struct inode *ip)
|
||||
{
|
||||
struct buf *bp;
|
||||
struct dinode *dip;
|
||||
|
||||
bp = bread(ip->dev, IBLOCK(ip->inum));
|
||||
dip = &((struct dinode *)(bp->data))[ip->inum % IPB];
|
||||
dip = &((struct dinode*)(bp->data))[ip->inum % IPB];
|
||||
dip->type = ip->type;
|
||||
dip->major = ip->major;
|
||||
dip->minor = ip->minor;
|
||||
dip->nlink = ip->nlink;
|
||||
dip->size = ip->size;
|
||||
memmove(dip->addrs, ip->addrs, sizeof(ip->addrs));
|
||||
bwrite (bp, IBLOCK(ip->inum)); // mark it allocated on the disk
|
||||
bwrite(bp, IBLOCK(ip->inum)); // mark it allocated on the disk
|
||||
brelse(bp);
|
||||
}
|
||||
|
||||
struct inode *
|
||||
struct inode*
|
||||
ialloc(uint dev, short type)
|
||||
{
|
||||
struct inode *ip;
|
||||
|
@ -173,27 +173,27 @@ ialloc(uint dev, short type)
|
|||
struct buf *bp;
|
||||
|
||||
bp = bread(dev, 1);
|
||||
sb = (struct superblock *) bp->data;
|
||||
sb = (struct superblock*) bp->data;
|
||||
ninodes = sb->ninodes;
|
||||
brelse(bp);
|
||||
|
||||
for (inum = 1; inum < ninodes; inum++) { // loop over inode blocks
|
||||
for(inum = 1; inum < ninodes; inum++) { // loop over inode blocks
|
||||
bp = bread(dev, IBLOCK(inum));
|
||||
dip = &((struct dinode *)(bp->data))[inum % IPB];
|
||||
if (dip->type == 0) { // a free inode
|
||||
dip = &((struct dinode*)(bp->data))[inum % IPB];
|
||||
if(dip->type == 0) { // a free inode
|
||||
break;
|
||||
}
|
||||
brelse(bp);
|
||||
}
|
||||
|
||||
if (inum >= ninodes)
|
||||
panic ("ialloc: no inodes left");
|
||||
if(inum >= ninodes)
|
||||
panic("ialloc: no inodes left");
|
||||
|
||||
memset(dip, 0, sizeof(*dip));
|
||||
dip->type = type;
|
||||
bwrite (bp, IBLOCK(inum)); // mark it allocated on the disk
|
||||
bwrite(bp, IBLOCK(inum)); // mark it allocated on the disk
|
||||
brelse(bp);
|
||||
ip = iget (dev, inum);
|
||||
ip = iget(dev, inum);
|
||||
return ip;
|
||||
}
|
||||
|
||||
|
@ -244,18 +244,18 @@ bmap(struct inode *ip, uint bn)
|
|||
|
||||
if(bn >= MAXFILE)
|
||||
panic("bmap 1");
|
||||
if (bn < NDIRECT) {
|
||||
if(bn < NDIRECT) {
|
||||
x = ip->addrs[bn];
|
||||
if (x == 0)
|
||||
if(x == 0)
|
||||
panic("bmap 2");
|
||||
} else {
|
||||
if(ip->addrs[INDIRECT] == 0)
|
||||
panic("bmap 3");
|
||||
inbp = bread(ip->dev, ip->addrs[INDIRECT]);
|
||||
a = (uint *) inbp->data;
|
||||
a = (uint*) inbp->data;
|
||||
x = a[bn - NDIRECT];
|
||||
brelse(inbp);
|
||||
if (x == 0)
|
||||
if(x == 0)
|
||||
panic("bmap 4");
|
||||
}
|
||||
return x;
|
||||
|
@ -267,13 +267,13 @@ itrunc(struct inode *ip)
|
|||
int i, j;
|
||||
struct buf *inbp;
|
||||
|
||||
for (i = 0; i < NADDRS; i++) {
|
||||
if (ip->addrs[i] != 0) {
|
||||
if (i == INDIRECT) {
|
||||
for(i = 0; i < NADDRS; i++) {
|
||||
if(ip->addrs[i] != 0) {
|
||||
if(i == INDIRECT) {
|
||||
inbp = bread(ip->dev, ip->addrs[INDIRECT]);
|
||||
uint *a = (uint *) inbp->data;
|
||||
for (j = 0; j < NINDIRECT; j++) {
|
||||
if (a[j] != 0) {
|
||||
uint *a = (uint*) inbp->data;
|
||||
for(j = 0; j < NINDIRECT; j++) {
|
||||
if(a[j] != 0) {
|
||||
bfree(ip->dev, a[j]);
|
||||
a[j] = 0;
|
||||
}
|
||||
|
@ -296,7 +296,7 @@ iput(struct inode *ip)
|
|||
if(ip->count < 1 || ip->busy != 1)
|
||||
panic("iput");
|
||||
|
||||
if ((ip->count == 1) && (ip->nlink == 0)) {
|
||||
if((ip->count == 1) && (ip->nlink == 0)) {
|
||||
itrunc(ip);
|
||||
ifree(ip);
|
||||
}
|
||||
|
@ -343,10 +343,10 @@ readi(struct inode *ip, char *dst, uint off, uint n)
|
|||
uint target = n, n1;
|
||||
struct buf *bp;
|
||||
|
||||
if (ip->type == T_DEV) {
|
||||
if (ip->major < 0 || ip->major >= NDEV || !devsw[ip->major].d_read)
|
||||
if(ip->type == T_DEV) {
|
||||
if(ip->major < 0 || ip->major >= NDEV || !devsw[ip->major].d_read)
|
||||
return -1;
|
||||
return devsw[ip->major].d_read (ip->minor, dst, n);
|
||||
return devsw[ip->major].d_read(ip->minor, dst, n);
|
||||
}
|
||||
|
||||
while(n > 0 && off < ip->size){
|
||||
|
@ -370,23 +370,23 @@ newblock(struct inode *ip, uint lbn)
|
|||
uint *inaddrs;
|
||||
uint b;
|
||||
|
||||
if (lbn < NDIRECT) {
|
||||
if (ip->addrs[lbn] == 0) {
|
||||
if(lbn < NDIRECT) {
|
||||
if(ip->addrs[lbn] == 0) {
|
||||
b = balloc(ip->dev);
|
||||
if (b <= 0) return -1;
|
||||
if(b <= 0) return -1;
|
||||
ip->addrs[lbn] = b;
|
||||
}
|
||||
} else {
|
||||
if (ip->addrs[INDIRECT] == 0) {
|
||||
if(ip->addrs[INDIRECT] == 0) {
|
||||
b = balloc(ip->dev);
|
||||
if (b <= 0) return -1;
|
||||
if(b <= 0) return -1;
|
||||
ip->addrs[INDIRECT] = b;
|
||||
}
|
||||
inbp = bread(ip->dev, ip->addrs[INDIRECT]);
|
||||
inaddrs = (uint *) inbp->data;
|
||||
if (inaddrs[lbn - NDIRECT] == 0) {
|
||||
inaddrs = (uint*) inbp->data;
|
||||
if(inaddrs[lbn - NDIRECT] == 0) {
|
||||
b = balloc(ip->dev);
|
||||
if (b <= 0) return -1;
|
||||
if(b <= 0) return -1;
|
||||
inaddrs[lbn - NDIRECT] = b;
|
||||
bwrite(inbp, ip->addrs[INDIRECT]);
|
||||
}
|
||||
|
@ -398,40 +398,40 @@ newblock(struct inode *ip, uint lbn)
|
|||
int
|
||||
writei(struct inode *ip, char *addr, uint off, uint n)
|
||||
{
|
||||
if (ip->type == T_DEV) {
|
||||
if (ip->major < 0 || ip->major >= NDEV || !devsw[ip->major].d_write)
|
||||
if(ip->type == T_DEV) {
|
||||
if(ip->major < 0 || ip->major >= NDEV || !devsw[ip->major].d_write)
|
||||
return -1;
|
||||
return devsw[ip->major].d_write (ip->minor, addr, n);
|
||||
} else if (ip->type == T_FILE || ip->type == T_DIR) {
|
||||
return devsw[ip->major].d_write(ip->minor, addr, n);
|
||||
} else if(ip->type == T_FILE || ip->type == T_DIR) {
|
||||
struct buf *bp;
|
||||
int r = 0;
|
||||
int m;
|
||||
int lbn;
|
||||
while (r < n) {
|
||||
while(r < n) {
|
||||
lbn = off / BSIZE;
|
||||
if (lbn >= MAXFILE) return r;
|
||||
if (newblock(ip, lbn) < 0) {
|
||||
if(lbn >= MAXFILE) return r;
|
||||
if(newblock(ip, lbn) < 0) {
|
||||
cprintf("newblock failed\n");
|
||||
return r;
|
||||
}
|
||||
m = min(BSIZE - off % BSIZE, n-r);
|
||||
bp = bread(ip->dev, bmap(ip, lbn));
|
||||
memmove (bp->data + off % BSIZE, addr, m);
|
||||
bwrite (bp, bmap(ip, lbn));
|
||||
brelse (bp);
|
||||
memmove(bp->data + off % BSIZE, addr, m);
|
||||
bwrite(bp, bmap(ip, lbn));
|
||||
brelse(bp);
|
||||
r += m;
|
||||
off += m;
|
||||
}
|
||||
if (r > 0) {
|
||||
if (off > ip->size) {
|
||||
if (ip->type == T_DIR) ip->size = ((off / BSIZE) + 1) * BSIZE;
|
||||
if(r > 0) {
|
||||
if(off > ip->size) {
|
||||
if(ip->type == T_DIR) ip->size = ((off / BSIZE) + 1) * BSIZE;
|
||||
else ip->size = off;
|
||||
}
|
||||
iupdate(ip);
|
||||
}
|
||||
return r;
|
||||
} else {
|
||||
panic ("writei: unknown type");
|
||||
panic("writei: unknown type");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -445,7 +445,7 @@ writei(struct inode *ip, char *addr, uint off, uint n)
|
|||
// *ret_ip and *ret_last may be zero even if return value is zero.
|
||||
// NAMEI_DELETE: return locked parent inode, offset of dirent in *ret_off.
|
||||
// return 0 if name doesn't exist.
|
||||
struct inode *
|
||||
struct inode*
|
||||
namei(char *path, int mode, uint *ret_off, char **ret_last, struct inode **ret_ip)
|
||||
{
|
||||
struct inode *dp;
|
||||
|
@ -464,7 +464,7 @@ namei(char *path, int mode, uint *ret_off, char **ret_last, struct inode **ret_i
|
|||
if(ret_ip)
|
||||
*ret_ip = 0;
|
||||
|
||||
if (*cp == '/') dp = iget(rootdev, 1);
|
||||
if(*cp == '/') dp = iget(rootdev, 1);
|
||||
else {
|
||||
dp = p->cwd;
|
||||
iincref(dp);
|
||||
|
@ -493,8 +493,8 @@ namei(char *path, int mode, uint *ret_off, char **ret_last, struct inode **ret_i
|
|||
|
||||
for(off = 0; off < dp->size; off += BSIZE){
|
||||
bp = bread(dp->dev, bmap(dp, off / BSIZE));
|
||||
for(ep = (struct dirent *) bp->data;
|
||||
ep < (struct dirent *) (bp->data + BSIZE);
|
||||
for(ep = (struct dirent*) bp->data;
|
||||
ep < (struct dirent*) (bp->data + BSIZE);
|
||||
ep++){
|
||||
if(ep->inum == 0)
|
||||
continue;
|
||||
|
@ -553,7 +553,7 @@ wdir(struct inode *dp, char *name, uint ino)
|
|||
int i;
|
||||
|
||||
for(off = 0; off < dp->size; off += sizeof(de)){
|
||||
if(readi(dp, (char *) &de, off, sizeof(de)) != sizeof(de))
|
||||
if(readi(dp, (char*) &de, off, sizeof(de)) != sizeof(de))
|
||||
panic("wdir read");
|
||||
if(de.inum == 0)
|
||||
break;
|
||||
|
@ -565,17 +565,17 @@ wdir(struct inode *dp, char *name, uint ino)
|
|||
for( ; i < DIRSIZ; i++)
|
||||
de.name[i] = '\0';
|
||||
|
||||
if(writei(dp, (char *) &de, off, sizeof(de)) != sizeof(de))
|
||||
if(writei(dp, (char*) &de, off, sizeof(de)) != sizeof(de))
|
||||
panic("wdir write");
|
||||
}
|
||||
|
||||
struct inode *
|
||||
struct inode*
|
||||
mknod(char *cp, short type, short major, short minor)
|
||||
{
|
||||
struct inode *ip, *dp;
|
||||
char *last;
|
||||
|
||||
if ((dp = namei(cp, NAMEI_CREATE, 0, &last, 0)) == 0)
|
||||
if((dp = namei(cp, NAMEI_CREATE, 0, &last, 0)) == 0)
|
||||
return 0;
|
||||
|
||||
ip = mknod1(dp, last, type, major, minor);
|
||||
|
@ -585,20 +585,20 @@ mknod(char *cp, short type, short major, short minor)
|
|||
return ip;
|
||||
}
|
||||
|
||||
struct inode *
|
||||
struct inode*
|
||||
mknod1(struct inode *dp, char *name, short type, short major, short minor)
|
||||
{
|
||||
struct inode *ip;
|
||||
|
||||
ip = ialloc(dp->dev, type);
|
||||
if (ip == 0)
|
||||
if(ip == 0)
|
||||
return 0;
|
||||
ip->major = major;
|
||||
ip->minor = minor;
|
||||
ip->size = 0;
|
||||
ip->nlink = 1;
|
||||
|
||||
iupdate (ip); // write new inode to disk
|
||||
iupdate(ip); // write new inode to disk
|
||||
|
||||
wdir(dp, name, ip->inum);
|
||||
|
||||
|
@ -649,7 +649,7 @@ link(char *name1, char *name2)
|
|||
struct inode *ip, *dp;
|
||||
char *last;
|
||||
|
||||
if ((ip = namei(name1, NAMEI_LOOKUP, 0, 0, 0)) == 0)
|
||||
if((ip = namei(name1, NAMEI_LOOKUP, 0, 0, 0)) == 0)
|
||||
return -1;
|
||||
if(ip->type == T_DIR){
|
||||
iput(ip);
|
||||
|
@ -658,7 +658,7 @@ link(char *name1, char *name2)
|
|||
|
||||
iunlock(ip);
|
||||
|
||||
if ((dp = namei(name2, NAMEI_CREATE, 0, &last, 0)) == 0) {
|
||||
if((dp = namei(name2, NAMEI_CREATE, 0, &last, 0)) == 0) {
|
||||
idecref(ip);
|
||||
return -1;
|
||||
}
|
||||
|
@ -670,7 +670,7 @@ link(char *name1, char *name2)
|
|||
|
||||
ilock(ip);
|
||||
ip->nlink += 1;
|
||||
iupdate (ip);
|
||||
iupdate(ip);
|
||||
|
||||
wdir(dp, last, ip->inum);
|
||||
iput(dp);
|
||||
|
|
30
ide.c
30
ide.c
|
@ -37,10 +37,10 @@ ide_wait_ready(int check_error)
|
|||
{
|
||||
int r;
|
||||
|
||||
while (((r = inb(0x1F7)) & (IDE_BSY|IDE_DRDY)) != IDE_DRDY)
|
||||
while(((r = inb(0x1F7)) & (IDE_BSY|IDE_DRDY)) != IDE_DRDY)
|
||||
/* do nothing */;
|
||||
|
||||
if (check_error && (r & (IDE_DF|IDE_ERR)) != 0)
|
||||
if(check_error && (r & (IDE_DF|IDE_ERR)) != 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
@ -74,13 +74,13 @@ ide_probe_disk1(void)
|
|||
outb(0x1F6, 0xE0 | (1<<4));
|
||||
|
||||
// check for Device 1 to be ready for a while
|
||||
for (x = 0; x < 1000 && (r = inb(0x1F7)) == 0; x++)
|
||||
for(x = 0; x < 1000 && (r = inb(0x1F7)) == 0; x++)
|
||||
/* do nothing */;
|
||||
|
||||
// switch back to Device 0
|
||||
outb(0x1F6, 0xE0 | (0<<4));
|
||||
|
||||
return (x < 1000);
|
||||
return x < 1000;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -88,7 +88,7 @@ ide_start_request (void)
|
|||
{
|
||||
struct ide_request *r;
|
||||
|
||||
if (head != tail) {
|
||||
if(head != tail) {
|
||||
r = &request[tail];
|
||||
ide_wait_ready(0);
|
||||
outb(0x3f6, 0); // generate interrupt
|
||||
|
@ -97,7 +97,7 @@ ide_start_request (void)
|
|||
outb(0x1F4, (r->secno >> 8) & 0xFF);
|
||||
outb(0x1F5, (r->secno >> 16) & 0xFF);
|
||||
outb(0x1F6, 0xE0 | ((r->diskno&1)<<4) | ((r->secno>>24)&0x0F));
|
||||
if (r->read) outb(0x1F7, 0x20); // read
|
||||
if(r->read) outb(0x1F7, 0x20); // read
|
||||
else {
|
||||
outb(0x1F7, 0x30); // write
|
||||
outsl(0x1F0, r->addr, 512/4);
|
||||
|
@ -105,7 +105,7 @@ ide_start_request (void)
|
|||
}
|
||||
}
|
||||
|
||||
void *
|
||||
void*
|
||||
ide_start_rw(int diskno, uint secno, void *addr, uint nsecs, int read)
|
||||
{
|
||||
struct ide_request *r;
|
||||
|
@ -113,8 +113,8 @@ ide_start_rw(int diskno, uint secno, void *addr, uint nsecs, int read)
|
|||
if(diskno && !disk_1_present)
|
||||
panic("ide disk 1 not present");
|
||||
|
||||
while ((head + 1) % NREQUEST == tail)
|
||||
sleep (&disk_channel, &ide_lock);
|
||||
while((head + 1) % NREQUEST == tail)
|
||||
sleep(&disk_channel, &ide_lock);
|
||||
|
||||
r = &request[head];
|
||||
r->secno = secno;
|
||||
|
@ -134,14 +134,14 @@ int
|
|||
ide_finish(void *c)
|
||||
{
|
||||
int r;
|
||||
struct ide_request *req = (struct ide_request *) c;
|
||||
struct ide_request *req = (struct ide_request*) c;
|
||||
|
||||
if (req->read) {
|
||||
if ((r = ide_wait_ready(1)) >= 0)
|
||||
if(req->read) {
|
||||
if((r = ide_wait_ready(1)) >= 0)
|
||||
insl(0x1F0, req->addr, 512/4);
|
||||
}
|
||||
|
||||
if ((head + 1) % NREQUEST == tail) {
|
||||
if((head + 1) % NREQUEST == tail) {
|
||||
wakeup(&disk_channel);
|
||||
}
|
||||
|
||||
|
@ -168,8 +168,8 @@ ide_write(int diskno, uint secno, const void *src, uint nsecs)
|
|||
outb(0x1F6, 0xE0 | ((diskno&1)<<4) | ((secno>>24)&0x0F));
|
||||
outb(0x1F7, 0x30); // CMD 0x30 means write sector
|
||||
|
||||
for (; nsecs > 0; nsecs--, src += 512) {
|
||||
if ((r = ide_wait_ready(1)) < 0)
|
||||
for(; nsecs > 0; nsecs--, src += 512) {
|
||||
if((r = ide_wait_ready(1)) < 0)
|
||||
return r;
|
||||
outsl(0x1F0, src, 512/4);
|
||||
}
|
||||
|
|
12
ioapic.c
12
ioapic.c
|
@ -18,7 +18,7 @@ static uint
|
|||
ioapic_read(struct ioapic *io, int reg)
|
||||
{
|
||||
io->ioregsel = reg;
|
||||
return (io->iowin);
|
||||
return io->iowin;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -37,13 +37,13 @@ ioapic_init(void)
|
|||
uchar id;
|
||||
int i;
|
||||
|
||||
io = (struct ioapic *) IO_APIC_BASE;
|
||||
io = (struct ioapic*) IO_APIC_BASE;
|
||||
l = ioapic_read(io, IOAPIC_VER);
|
||||
nintr = ((l & IOART_VER_MAXREDIR) >> MAXREDIRSHIFT) + 1;
|
||||
id = ioapic_read(io, IOAPIC_ID) >> APIC_ID_SHIFT;
|
||||
if (id != ioapic_id)
|
||||
panic ("ioapic_init: id isn't equal to ioapic_id\n");
|
||||
for (i = 0; i < nintr; i++) {
|
||||
if(id != ioapic_id)
|
||||
panic("ioapic_init: id isn't equal to ioapic_id\n");
|
||||
for(i = 0; i < nintr; i++) {
|
||||
// active-hi and edge-triggered for ISA interrupts
|
||||
// Assume that pin 0 on the first I/O APIC is an ExtINT pin.
|
||||
// Assume that pins 1-15 are ISA interrupts
|
||||
|
@ -68,7 +68,7 @@ ioapic_enable (int irq, int cpunum)
|
|||
uint l, h;
|
||||
struct ioapic *io;
|
||||
|
||||
io = (struct ioapic *) IO_APIC_BASE;
|
||||
io = (struct ioapic*) IO_APIC_BASE;
|
||||
l = ioapic_read(io, IOAPIC_REDTBL_LO(irq));
|
||||
l = l & ~IOART_INTMASK; // allow INTs
|
||||
ioapic_write(io, IOAPIC_REDTBL_LO(irq), l);
|
||||
|
|
14
kalloc.c
14
kalloc.c
|
@ -36,8 +36,8 @@ kinit(void)
|
|||
char *start;
|
||||
|
||||
initlock(&kalloc_lock, "kalloc");
|
||||
start = (char *) &end;
|
||||
start = (char *) (((uint)start + PAGE) & ~(PAGE-1));
|
||||
start = (char*) &end;
|
||||
start = (char*) (((uint)start + PAGE) & ~(PAGE-1));
|
||||
mem = 256; // assume 256 pages of RAM
|
||||
cprintf("mem = %d\n", mem * PAGE);
|
||||
kfree(start, mem * PAGE);
|
||||
|
@ -47,8 +47,8 @@ void
|
|||
kfree(char *cp, int len)
|
||||
{
|
||||
struct run **rr;
|
||||
struct run *p = (struct run *) cp;
|
||||
struct run *pend = (struct run *) (cp + len);
|
||||
struct run *p = (struct run*) cp;
|
||||
struct run *pend = (struct run*) (cp + len);
|
||||
int i;
|
||||
|
||||
if(len % PAGE)
|
||||
|
@ -62,7 +62,7 @@ kfree(char *cp, int len)
|
|||
|
||||
rr = &freelist;
|
||||
while(*rr){
|
||||
struct run *rend = (struct run *) ((char *)(*rr) + (*rr)->len);
|
||||
struct run *rend = (struct run*) ((char*)(*rr) + (*rr)->len);
|
||||
if(p >= *rr && p < rend)
|
||||
panic("freeing free page");
|
||||
if(pend == *rr){
|
||||
|
@ -116,10 +116,10 @@ kalloc(int n)
|
|||
if(r->len == n){
|
||||
*rr = r->next;
|
||||
release(&kalloc_lock);
|
||||
return (char *) r;
|
||||
return (char*) r;
|
||||
}
|
||||
if(r->len > n){
|
||||
char *p = (char *)r + (r->len - n);
|
||||
char *p = (char*)r + (r->len - n);
|
||||
r->len -= n;
|
||||
release(&kalloc_lock);
|
||||
return p;
|
||||
|
|
10
lapic.c
10
lapic.c
|
@ -114,7 +114,7 @@ lapic_timerinit(void)
|
|||
void
|
||||
lapic_timerintr(void)
|
||||
{
|
||||
lapic_write (LAPIC_EOI, 0);
|
||||
lapic_write(LAPIC_EOI, 0);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -165,7 +165,7 @@ lapic_disableintr(void)
|
|||
void
|
||||
lapic_eoi(void)
|
||||
{
|
||||
lapic_write (LAPIC_EOI, 0);
|
||||
lapic_write(LAPIC_EOI, 0);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -185,15 +185,15 @@ lapic_startap(uchar apicid, int v)
|
|||
lapic_write(LAPIC_ICRHI, crhi);
|
||||
lapic_write(LAPIC_ICRLO, LAPIC_FIELD|APIC_LEVEL|LAPIC_ASSERT|APIC_INIT);
|
||||
|
||||
while (j++ < 10000) {;}
|
||||
while(j++ < 10000) {;}
|
||||
lapic_write(LAPIC_ICRLO, LAPIC_FIELD|APIC_LEVEL|LAPIC_DEASSERT|APIC_INIT);
|
||||
|
||||
while (j++ < 1000000) {;}
|
||||
while(j++ < 1000000) {;}
|
||||
|
||||
// in p9 code, this was i < 2, which is what the spec says on page B-3
|
||||
for(i = 0; i < 1; i++){
|
||||
lapic_write(LAPIC_ICRHI, crhi);
|
||||
lapic_write(LAPIC_ICRLO, LAPIC_FIELD|APIC_EDGE|APIC_STARTUP|(v/4096));
|
||||
while (j++ < 100000) {;}
|
||||
while(j++ < 100000) {;}
|
||||
}
|
||||
}
|
||||
|
|
16
ls.c
16
ls.c
|
@ -12,10 +12,10 @@ pname(char *n)
|
|||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; (i < DIRSIZ) && (n[i] != '\0') ; i++) {
|
||||
for(i = 0; (i < DIRSIZ) && (n[i] != '\0') ; i++) {
|
||||
printf(1, "%c", n[i]);
|
||||
}
|
||||
for (; i < DIRSIZ; i++)
|
||||
for(; i < DIRSIZ; i++)
|
||||
printf(1, " ");
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ main(int argc, char *argv[])
|
|||
exit();
|
||||
}
|
||||
|
||||
if (argc == 2) {
|
||||
if(argc == 2) {
|
||||
fd = open(argv[1], 0);
|
||||
if(fd < 0){
|
||||
printf(2, "ls: cannot open %s\n", argv[1]);
|
||||
|
@ -45,12 +45,12 @@ main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
if (fstat(fd, &st) < 0) {
|
||||
if(fstat(fd, &st) < 0) {
|
||||
printf(2, "ls: cannot stat dir\n");
|
||||
exit();
|
||||
}
|
||||
|
||||
switch (st.st_type) {
|
||||
switch(st.st_type) {
|
||||
case T_FILE:
|
||||
pname(argv[1]);
|
||||
printf(1, "%d %d %d\n", st.st_type, st.st_ino, st.st_size);
|
||||
|
@ -58,13 +58,13 @@ main(int argc, char *argv[])
|
|||
case T_DIR:
|
||||
sz = st.st_size;
|
||||
for(off = 0; off < sz; off += sizeof(struct dirent)) {
|
||||
if (read(fd, &dirent, sizeof(struct dirent)) != sizeof(struct dirent)) {
|
||||
if(read(fd, &dirent, sizeof(struct dirent)) != sizeof(struct dirent)) {
|
||||
printf(1, "ls: read error\n");
|
||||
break;
|
||||
}
|
||||
if (dirent.inum != 0) {
|
||||
if(dirent.inum != 0) {
|
||||
// xxx prepend to name the pathname supplied to ls (e.g. .. in ls ..)
|
||||
if (stat (dirent.name, &st) < 0) {
|
||||
if(stat (dirent.name, &st) < 0) {
|
||||
printf(1, "stat: failed %s\n", dirent.name);
|
||||
continue;
|
||||
}
|
||||
|
|
10
main.c
10
main.c
|
@ -152,19 +152,19 @@ load_icode(struct proc *p, uchar *binary, uint size)
|
|||
struct proghdr *ph;
|
||||
|
||||
elf = (struct elfhdr*) binary;
|
||||
if (elf->magic != ELF_MAGIC)
|
||||
if(elf->magic != ELF_MAGIC)
|
||||
panic("load_icode: not an ELF binary");
|
||||
|
||||
p->tf->eip = elf->entry;
|
||||
|
||||
// Map and load segments as directed.
|
||||
ph = (struct proghdr*) (binary + elf->phoff);
|
||||
for (i = 0; i < elf->phnum; i++, ph++) {
|
||||
if (ph->type != ELF_PROG_LOAD)
|
||||
for(i = 0; i < elf->phnum; i++, ph++) {
|
||||
if(ph->type != ELF_PROG_LOAD)
|
||||
continue;
|
||||
if (ph->va + ph->memsz < ph->va)
|
||||
if(ph->va + ph->memsz < ph->va)
|
||||
panic("load_icode: overflow in elf header segment");
|
||||
if (ph->va + ph->memsz >= p->sz)
|
||||
if(ph->va + ph->memsz >= p->sz)
|
||||
panic("load_icode: icode wants to be above UTOP");
|
||||
|
||||
// Load/clear the segment
|
||||
|
|
2
mkdir.c
2
mkdir.c
|
@ -12,7 +12,7 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
for(i = 1; i < argc; i++){
|
||||
if (mkdir(argv[i]) < 0) {
|
||||
if(mkdir(argv[i]) < 0) {
|
||||
printf(2, "mkdir: %s failed to create\n", argv[i]);
|
||||
break;
|
||||
}
|
||||
|
|
28
mkfs.c
28
mkfs.c
|
@ -21,8 +21,8 @@ uint bitblocks;
|
|||
uint freeinode = 1;
|
||||
|
||||
void balloc(int);
|
||||
void wsect(uint, void *);
|
||||
void winode(uint, struct dinode *);
|
||||
void wsect(uint, void*);
|
||||
void winode(uint, struct dinode*);
|
||||
void rinode(uint inum, struct dinode *ip);
|
||||
void rsect(uint sec, void *buf);
|
||||
uint ialloc(ushort type);
|
||||
|
@ -33,7 +33,7 @@ ushort
|
|||
xshort(ushort x)
|
||||
{
|
||||
ushort y;
|
||||
uchar *a = (uchar *) &y;
|
||||
uchar *a = (uchar*) &y;
|
||||
a[0] = x;
|
||||
a[1] = x >> 8;
|
||||
return y;
|
||||
|
@ -43,7 +43,7 @@ uint
|
|||
xint(uint x)
|
||||
{
|
||||
uint y;
|
||||
uchar *a = (uchar *) &y;
|
||||
uchar *a = (uchar*) &y;
|
||||
a[0] = x;
|
||||
a[1] = x >> 8;
|
||||
a[2] = x >> 16;
|
||||
|
@ -84,7 +84,7 @@ main(int argc, char *argv[])
|
|||
printf("used %d (bit %d ninode %d) free %d total %d\n", usedblocks,
|
||||
bitblocks, ninodes/IPB + 1, freeblock, nblocks+usedblocks);
|
||||
|
||||
assert (nblocks + usedblocks == size);
|
||||
assert(nblocks + usedblocks == size);
|
||||
|
||||
for(i = 0; i < nblocks + usedblocks; i++)
|
||||
wsect(i, zeroes);
|
||||
|
@ -165,7 +165,7 @@ winode(uint inum, struct dinode *ip)
|
|||
|
||||
bn = i2b(inum);
|
||||
rsect(bn, buf);
|
||||
dip = ((struct dinode *) buf) + (inum % IPB);
|
||||
dip = ((struct dinode*) buf) + (inum % IPB);
|
||||
*dip = *ip;
|
||||
wsect(bn, buf);
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ rinode(uint inum, struct dinode *ip)
|
|||
|
||||
bn = i2b(inum);
|
||||
rsect(bn, buf);
|
||||
dip = ((struct dinode *) buf) + (inum % IPB);
|
||||
dip = ((struct dinode*) buf) + (inum % IPB);
|
||||
*ip = *dip;
|
||||
}
|
||||
|
||||
|
@ -217,9 +217,9 @@ balloc(int used)
|
|||
int i;
|
||||
|
||||
printf("balloc: first %d blocks have been allocated\n", used);
|
||||
assert (used < 512);
|
||||
assert(used < 512);
|
||||
bzero(buf, 512);
|
||||
for (i = 0; i < used; i++) {
|
||||
for(i = 0; i < used; i++) {
|
||||
buf[i/8] = buf[i/8] | (0x1 << (i%8));
|
||||
}
|
||||
printf("balloc: write bitmap block at sector %d\n", ninodes/IPB + 3);
|
||||
|
@ -231,7 +231,7 @@ balloc(int used)
|
|||
void
|
||||
iappend(uint inum, void *xp, int n)
|
||||
{
|
||||
char *p = (char *) xp;
|
||||
char *p = (char*) xp;
|
||||
uint fbn, off, n1;
|
||||
struct dinode din;
|
||||
char buf[512];
|
||||
|
@ -244,7 +244,7 @@ iappend(uint inum, void *xp, int n)
|
|||
while(n > 0){
|
||||
fbn = off / 512;
|
||||
assert(fbn < MAXFILE);
|
||||
if (fbn < NDIRECT) {
|
||||
if(fbn < NDIRECT) {
|
||||
if(xint(din.addrs[fbn]) == 0) {
|
||||
din.addrs[fbn] = xint(freeblock++);
|
||||
usedblocks++;
|
||||
|
@ -257,11 +257,11 @@ iappend(uint inum, void *xp, int n)
|
|||
usedblocks++;
|
||||
}
|
||||
printf("read indirect block\n");
|
||||
rsect(xint(din.addrs[INDIRECT]), (char *) indirect);
|
||||
if (indirect[fbn - NDIRECT] == 0) {
|
||||
rsect(xint(din.addrs[INDIRECT]), (char*) indirect);
|
||||
if(indirect[fbn - NDIRECT] == 0) {
|
||||
indirect[fbn - NDIRECT] = xint(freeblock++);
|
||||
usedblocks++;
|
||||
wsect(xint(din.addrs[INDIRECT]), (char *) indirect);
|
||||
wsect(xint(din.addrs[INDIRECT]), (char*) indirect);
|
||||
}
|
||||
x = xint(indirect[fbn-NDIRECT]);
|
||||
}
|
||||
|
|
12
mmu.h
12
mmu.h
|
@ -84,21 +84,21 @@ struct taskstate {
|
|||
uint esp0; // Stack pointers and segment selectors
|
||||
ushort ss0; // after an increase in privilege level
|
||||
ushort padding1;
|
||||
uint * esp1;
|
||||
uint *esp1;
|
||||
ushort ss1;
|
||||
ushort padding2;
|
||||
uint * esp2;
|
||||
uint *esp2;
|
||||
ushort ss2;
|
||||
ushort padding3;
|
||||
void * cr3; // Page directory base
|
||||
uint * eip; // Saved state from last task switch
|
||||
void *cr3; // Page directory base
|
||||
uint *eip; // Saved state from last task switch
|
||||
uint eflags;
|
||||
uint eax; // More saved state (registers)
|
||||
uint ecx;
|
||||
uint edx;
|
||||
uint ebx;
|
||||
uint * esp;
|
||||
uint * ebp;
|
||||
uint *esp;
|
||||
uint *ebp;
|
||||
uint esi;
|
||||
uint edi;
|
||||
ushort es; // Even more saved state (segment selectors)
|
||||
|
|
34
mp.c
34
mp.c
|
@ -7,7 +7,7 @@
|
|||
#include "mmu.h"
|
||||
#include "proc.h"
|
||||
|
||||
static char* buses[] = {
|
||||
static char *buses[] = {
|
||||
"CBUSI ",
|
||||
"CBUSII",
|
||||
"EISA ",
|
||||
|
@ -34,7 +34,7 @@ int ncpu;
|
|||
uchar ioapic_id;
|
||||
|
||||
static struct cpu *bcpu;
|
||||
static struct mp* mp; // The MP floating point structure
|
||||
static struct mp *mp; // The MP floating point structure
|
||||
|
||||
static struct mp*
|
||||
mp_scan(uchar *addr, int len)
|
||||
|
@ -50,7 +50,7 @@ mp_scan(uchar *addr, int len)
|
|||
for(i = 0; i < sizeof(struct mp); i++)
|
||||
sum += p[i];
|
||||
if(sum == 0)
|
||||
return (struct mp *)p;
|
||||
return (struct mp*)p;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ mp_detect(void)
|
|||
if((mp = mp_search()) == 0 || mp->physaddr == 0)
|
||||
return 1;
|
||||
|
||||
pcmp = (struct mpctb *) mp->physaddr;
|
||||
pcmp = (struct mpctb*) mp->physaddr;
|
||||
if(memcmp(pcmp, "PCMP", 4))
|
||||
return 2;
|
||||
|
||||
|
@ -128,31 +128,31 @@ mp_init(void)
|
|||
uchar byte;
|
||||
|
||||
ncpu = 0;
|
||||
if ((r = mp_detect()) != 0) return;
|
||||
if((r = mp_detect()) != 0) return;
|
||||
|
||||
/*
|
||||
* Run through the table saving information needed for starting
|
||||
* application processors and initialising any I/O APICs. The table
|
||||
* is guaranteed to be in order such that only one pass is necessary.
|
||||
*/
|
||||
mpctb = (struct mpctb *) mp->physaddr;
|
||||
lapicaddr = (uint *) mpctb->lapicaddr;
|
||||
mpctb = (struct mpctb*) mp->physaddr;
|
||||
lapicaddr = (uint*) mpctb->lapicaddr;
|
||||
p = ((uchar*)mpctb)+sizeof(struct mpctb);
|
||||
e = ((uchar*)mpctb)+mpctb->length;
|
||||
|
||||
while(p < e) {
|
||||
switch(*p){
|
||||
case MPPROCESSOR:
|
||||
proc = (struct mppe *) p;
|
||||
proc = (struct mppe*) p;
|
||||
cpus[ncpu].apicid = proc->apicid;
|
||||
if (proc->flags & MPBP) {
|
||||
if(proc->flags & MPBP) {
|
||||
bcpu = &cpus[ncpu];
|
||||
}
|
||||
ncpu++;
|
||||
p += sizeof(struct mppe);
|
||||
continue;
|
||||
case MPBUS:
|
||||
bus = (struct mpbe *) p;
|
||||
bus = (struct mpbe*) p;
|
||||
for(i = 0; buses[i]; i++){
|
||||
if(strncmp(buses[i], bus->string, sizeof(bus->string)) == 0)
|
||||
break;
|
||||
|
@ -160,12 +160,12 @@ mp_init(void)
|
|||
p += sizeof(struct mpbe);
|
||||
continue;
|
||||
case MPIOAPIC:
|
||||
ioapic = (struct mpioapic *) p;
|
||||
ioapic = (struct mpioapic*) p;
|
||||
ioapic_id = ioapic->apicno;
|
||||
p += sizeof(struct mpioapic);
|
||||
continue;
|
||||
case MPIOINTR:
|
||||
intr = (struct mpie *) p;
|
||||
intr = (struct mpie*) p;
|
||||
p += sizeof(struct mpie);
|
||||
continue;
|
||||
default:
|
||||
|
@ -178,7 +178,7 @@ mp_init(void)
|
|||
}
|
||||
}
|
||||
|
||||
if (mp->imcrp) { // it appears that bochs doesn't support IMCR, and code won't run
|
||||
if(mp->imcrp) { // it appears that bochs doesn't support IMCR, and code won't run
|
||||
outb(0x22, 0x70); /* select IMCR */
|
||||
byte = inb(0x23); /* current contents */
|
||||
byte |= 0x01; /* mask external INTR */
|
||||
|
@ -204,13 +204,13 @@ mp_startthem(void)
|
|||
extern int main();
|
||||
int c;
|
||||
|
||||
memmove((void *) APBOOTCODE,_binary_bootother_start,
|
||||
memmove((void*) APBOOTCODE,_binary_bootother_start,
|
||||
(uint) _binary_bootother_size);
|
||||
|
||||
for(c = 0; c < ncpu; c++){
|
||||
if (c == cpu()) continue;
|
||||
*(uint *)(APBOOTCODE-4) = (uint) (cpus[c].mpstack) + MPSTACK; // tell it what to use for %esp
|
||||
*(uint *)(APBOOTCODE-8) = (uint)mpmain; // tell it where to jump to
|
||||
if(c == cpu()) continue;
|
||||
*(uint*)(APBOOTCODE-4) = (uint) (cpus[c].mpstack) + MPSTACK; // tell it what to use for %esp
|
||||
*(uint*)(APBOOTCODE-8) = (uint)mpmain; // tell it where to jump to
|
||||
lapic_startap(cpus[c].apicid, (uint) APBOOTCODE);
|
||||
while(cpus[c].booted == 0)
|
||||
;
|
||||
|
|
8
mp.h
8
mp.h
|
@ -5,7 +5,7 @@
|
|||
|
||||
struct mp { /* floating pointer */
|
||||
uchar signature[4]; /* "_MP_" */
|
||||
void* physaddr; /* physical address of MP configuration table */
|
||||
void *physaddr; /* physical address of MP configuration table */
|
||||
uchar length; /* 1 */
|
||||
uchar specrev; /* [14] */
|
||||
uchar checksum; /* all bytes must add up to 0 */
|
||||
|
@ -20,10 +20,10 @@ struct mpctb { /* configuration table header */
|
|||
uchar version; /* [14] */
|
||||
uchar checksum; /* all bytes must add up to 0 */
|
||||
uchar product[20]; /* product id */
|
||||
uint * oemtable; /* OEM table pointer */
|
||||
uint *oemtable; /* OEM table pointer */
|
||||
ushort oemlength; /* OEM table length */
|
||||
ushort entry; /* entry count */
|
||||
uint * lapicaddr; /* address of local APIC */
|
||||
uint *lapicaddr; /* address of local APIC */
|
||||
ushort xlength; /* extended table length */
|
||||
uchar xchecksum; /* extended table checksum */
|
||||
uchar reserved;
|
||||
|
@ -50,7 +50,7 @@ struct mpioapic { /* I/O APIC table entry */
|
|||
uchar apicno; /* I/O APIC id */
|
||||
uchar version; /* I/O APIC version */
|
||||
uchar flags; /* I/O APIC flags */
|
||||
uint * addr; /* I/O APIC address */
|
||||
uint *addr; /* I/O APIC address */
|
||||
};
|
||||
|
||||
struct mpie { /* interrupt table entry */
|
||||
|
|
2
picirq.c
2
picirq.c
|
@ -73,6 +73,6 @@ pic_init(void)
|
|||
outb(IO_PIC2, 0x68); /* OCW3 */
|
||||
outb(IO_PIC2, 0x0a); /* OCW3 */
|
||||
|
||||
if (irq_mask_8259A != 0xFFFF)
|
||||
if(irq_mask_8259A != 0xFFFF)
|
||||
irq_setmask_8259A(irq_mask_8259A);
|
||||
}
|
||||
|
|
6
pipe.c
6
pipe.c
|
@ -28,7 +28,7 @@ pipe_alloc(struct fd **fd1, struct fd **fd2)
|
|||
goto oops;
|
||||
if((*fd2 = fd_alloc()) == 0)
|
||||
goto oops;
|
||||
if((p = (struct pipe *) kalloc(PAGE)) == 0)
|
||||
if((p = (struct pipe*) kalloc(PAGE)) == 0)
|
||||
goto oops;
|
||||
p->readopen = 1;
|
||||
p->writeopen = 1;
|
||||
|
@ -46,7 +46,7 @@ pipe_alloc(struct fd **fd1, struct fd **fd2)
|
|||
return 0;
|
||||
oops:
|
||||
if(p)
|
||||
kfree((char *) p, PAGE);
|
||||
kfree((char*) p, PAGE);
|
||||
if(*fd1){
|
||||
(*fd1)->type = FD_NONE;
|
||||
fd_close(*fd1);
|
||||
|
@ -74,7 +74,7 @@ pipe_close(struct pipe *p, int writeable)
|
|||
release(&p->lock);
|
||||
|
||||
if(p->readopen == 0 && p->writeopen == 0)
|
||||
kfree((char *) p, PAGE);
|
||||
kfree((char*) p, PAGE);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
4
printf.c
4
printf.c
|
@ -5,7 +5,7 @@
|
|||
static void
|
||||
putc(int fd, char c)
|
||||
{
|
||||
write (fd, &c, 1);
|
||||
write(fd, &c, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -40,7 +40,7 @@ void
|
|||
printf(int fd, char *fmt, ...)
|
||||
{
|
||||
int i, state = 0, c;
|
||||
uint *ap = (uint *)(void*)&fmt + 1;
|
||||
uint *ap = (uint*)(void*)&fmt + 1;
|
||||
|
||||
for(i = 0; fmt[i]; i++){
|
||||
c = fmt[i] & 0xff;
|
||||
|
|
4
proc.c
4
proc.c
|
@ -78,8 +78,8 @@ allocproc(void)
|
|||
// Does not copy the kernel stack.
|
||||
// Instead, sets up stack to return as if from system call.
|
||||
// Caller must arrange for process to run (set state to RUNNABLE).
|
||||
struct proc *
|
||||
copyproc(struct proc* p)
|
||||
struct proc*
|
||||
copyproc(struct proc *p)
|
||||
{
|
||||
int i;
|
||||
struct proc *np;
|
||||
|
|
2
rm.c
2
rm.c
|
@ -12,7 +12,7 @@ main(int argc, char *argv[])
|
|||
}
|
||||
|
||||
for(i = 1; i < argc; i++){
|
||||
if (unlink(argv[i]) < 0) {
|
||||
if(unlink(argv[i]) < 0) {
|
||||
printf(2, "mkdir: %s failed to create\n", argv[i]);
|
||||
break;
|
||||
}
|
||||
|
|
120
sh.c
120
sh.c
|
@ -43,9 +43,9 @@ main(void)
|
|||
{
|
||||
while(1){
|
||||
puts("$ ");
|
||||
memset (buf, '\0', sizeof(buf));
|
||||
memset(buf, '\0', sizeof(buf));
|
||||
gets(buf, sizeof(buf));
|
||||
if (parse(buf) < 0)
|
||||
if(parse(buf) < 0)
|
||||
continue;
|
||||
runcmd();
|
||||
}
|
||||
|
@ -61,15 +61,15 @@ parse(char *s)
|
|||
|
||||
nextio = 0;
|
||||
nextcmd = 0;
|
||||
for (i = 0; i < MAXCMD; i++) {
|
||||
for(i = 0; i < MAXCMD; i++) {
|
||||
cmdlist[i].argc = 0;
|
||||
cmdlist[i].token = 0;
|
||||
}
|
||||
while (1) {
|
||||
switch ((c = gettoken(0, &t))) {
|
||||
while(1) {
|
||||
switch((c = gettoken(0, &t))) {
|
||||
|
||||
case 'w': // Add an argument
|
||||
if (cmdlist[nextcmd].argc >= MAXARGS) {
|
||||
if(cmdlist[nextcmd].argc >= MAXARGS) {
|
||||
printf(2, "too many arguments\n");
|
||||
return -1;
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ parse(char *s)
|
|||
|
||||
case '<': // Input redirection
|
||||
// Grab the filename from the argument list
|
||||
if (gettoken(0, &t) != 'w') {
|
||||
if(gettoken(0, &t) != 'w') {
|
||||
printf(2, "syntax error: < not followed by word\n");
|
||||
return -1;
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ parse(char *s)
|
|||
|
||||
case '>': // Output redirection
|
||||
// Grab the filename from the argument list
|
||||
if (gettoken(0, &t) != 'w') {
|
||||
if(gettoken(0, &t) != 'w') {
|
||||
printf(2, "syntax error: > not followed by word\n");
|
||||
return -1;
|
||||
}
|
||||
|
@ -120,17 +120,17 @@ runcmd(void)
|
|||
|
||||
// Return immediately if command line was empty.
|
||||
if(cmdlist[0].argc == 0) {
|
||||
if (debug)
|
||||
if(debug)
|
||||
printf(2, "EMPTY COMMAND\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (c = 0; c <= nextcmd; c++) {
|
||||
for(c = 0; c <= nextcmd; c++) {
|
||||
// Clean up command line.
|
||||
// Read all commands from the filesystem: add an initial '/' to
|
||||
// the command name.
|
||||
// This essentially acts like 'PATH=/'.
|
||||
if (cmdlist[c].argv[0][0] != '/') {
|
||||
if(cmdlist[c].argv[0][0] != '/') {
|
||||
cmdlist[c].argv0buf[0] = '/';
|
||||
strcpy(cmdlist[c].argv0buf + 1, cmdlist[c].argv[0]);
|
||||
cmdlist[c].argv[0] = cmdlist[c].argv0buf;
|
||||
|
@ -138,72 +138,72 @@ runcmd(void)
|
|||
cmdlist[c].argv[cmdlist[c].argc] = 0;
|
||||
|
||||
// Print the command.
|
||||
if (debug) {
|
||||
if(debug) {
|
||||
printf(2, "[%d] SPAWN:", getpid());
|
||||
for (i = 0; cmdlist[c].argv[i]; i++)
|
||||
for(i = 0; cmdlist[c].argv[i]; i++)
|
||||
printf(2, " %s", cmdlist[c].argv[i]);
|
||||
for (i = 0; i < nextio; i++) {
|
||||
for(i = 0; i < nextio; i++) {
|
||||
printf(2, "%c %s", iolist[i].token, iolist[i].s);
|
||||
}
|
||||
printf(2, "\n");
|
||||
}
|
||||
|
||||
if (strcmp(cmdlist[c].argv[0], "/cd") == 0) {
|
||||
if (debug) printf (2, "/cd %s is build in\n", cmdlist[c].argv[1]);
|
||||
if(strcmp(cmdlist[c].argv[0], "/cd") == 0) {
|
||||
if(debug) printf (2, "/cd %s is build in\n", cmdlist[c].argv[1]);
|
||||
chdir(cmdlist[c].argv[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
if (cmdlist[c].token == '|')
|
||||
if (pipe(fdarray) < 0)
|
||||
if(cmdlist[c].token == '|')
|
||||
if(pipe(fdarray) < 0)
|
||||
printf(2, "cmd %d pipe failed\n", c);
|
||||
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
if (cmdlist[c].token == '|') {
|
||||
if (close(1) < 0)
|
||||
if(pid == 0) {
|
||||
if(cmdlist[c].token == '|') {
|
||||
if(close(1) < 0)
|
||||
printf(2, "close 1 failed\n");
|
||||
if ((tfd = dup(fdarray[1])) < 0)
|
||||
if((tfd = dup(fdarray[1])) < 0)
|
||||
printf(2, "dup failed\n");
|
||||
if (close(fdarray[0]) < 0)
|
||||
if(close(fdarray[0]) < 0)
|
||||
printf(2, "close fdarray[0] failed\n");
|
||||
if (close(fdarray[1]) < 0)
|
||||
if(close(fdarray[1]) < 0)
|
||||
printf(2, "close fdarray[1] failed\n");
|
||||
}
|
||||
if (c > 0 && cmdlist[c-1].token == '|') {
|
||||
if (close(0) < 0)
|
||||
if(c > 0 && cmdlist[c-1].token == '|') {
|
||||
if(close(0) < 0)
|
||||
printf(2, "close 0 failed\n");
|
||||
if ((tfd = dup(fdarray[0])) < 0)
|
||||
if((tfd = dup(fdarray[0])) < 0)
|
||||
printf(2, "dup failed\n");
|
||||
if (close(fdarray[0]) < 0)
|
||||
if(close(fdarray[0]) < 0)
|
||||
printf(2, "close fdarray[0] failed\n");
|
||||
if (close(fdarray[1]) < 0)
|
||||
if(close(fdarray[1]) < 0)
|
||||
printf(2, "close fdarray[1] failed\n");
|
||||
}
|
||||
if (ioredirection() < 0)
|
||||
if(ioredirection() < 0)
|
||||
exit();
|
||||
if ((r = exec(cmdlist[c].argv0buf, (char**) cmdlist[c].argv)) < 0) {
|
||||
if((r = exec(cmdlist[c].argv0buf, (char**) cmdlist[c].argv)) < 0) {
|
||||
printf(2, "exec %s: %d\n", cmdlist[c].argv[0], r);
|
||||
exit();
|
||||
}
|
||||
} else if (pid > 0) {
|
||||
} else if(pid > 0) {
|
||||
int p;
|
||||
if (debug)
|
||||
if(debug)
|
||||
printf(2, "[%d] FORKED child %d\n", getpid(), pid);
|
||||
|
||||
if (c > 0 && cmdlist[c-1].token == '|') {
|
||||
if(c > 0 && cmdlist[c-1].token == '|') {
|
||||
close(fdarray[0]);
|
||||
close(fdarray[1]);
|
||||
}
|
||||
if (cmdlist[c].token != '|') {
|
||||
if (debug)
|
||||
if(cmdlist[c].token != '|') {
|
||||
if(debug)
|
||||
printf(2, "[%d] WAIT for children\n", getpid());
|
||||
do {
|
||||
p = wait();
|
||||
if (debug)
|
||||
if(debug)
|
||||
printf(2, "[%d] WAIT child %d finished\n", getpid(), p);
|
||||
} while (p > 0);
|
||||
if (debug)
|
||||
} while(p > 0);
|
||||
if(debug)
|
||||
printf(2, "[%d] wait finished\n", getpid());
|
||||
}
|
||||
}
|
||||
|
@ -215,26 +215,26 @@ ioredirection(void)
|
|||
{
|
||||
int i, fd;
|
||||
|
||||
for (i = 0; i < nextio; i++) {
|
||||
switch (iolist[i].token) {
|
||||
for(i = 0; i < nextio; i++) {
|
||||
switch(iolist[i].token) {
|
||||
case '<':
|
||||
if (close(0) < 0)
|
||||
if(close(0) < 0)
|
||||
printf(2, "close 0 failed\n");
|
||||
if ((fd = open(iolist[i].s, O_RDONLY)) < 0) {
|
||||
if((fd = open(iolist[i].s, O_RDONLY)) < 0) {
|
||||
printf(2, "failed to open %s for read: %d", iolist[i].s, fd);
|
||||
return -1;
|
||||
}
|
||||
if (debug)
|
||||
if(debug)
|
||||
printf(2, "redirect 0 from %s\n", iolist[i].s);
|
||||
break;
|
||||
case '>':
|
||||
if (close(1) < 0)
|
||||
if(close(1) < 0)
|
||||
printf(2, "close 1 failed\n");
|
||||
if ((fd = open(iolist[i].s, O_WRONLY|O_CREATE)) < 0) {
|
||||
if((fd = open(iolist[i].s, O_WRONLY|O_CREATE)) < 0) {
|
||||
printf(2, "failed to open %s for write: %d", iolist[i].s, fd);
|
||||
exit();
|
||||
}
|
||||
if (debug)
|
||||
if(debug)
|
||||
printf(2, "redirect 1 to %s\n", iolist[i].s);
|
||||
break;
|
||||
}
|
||||
|
@ -245,7 +245,7 @@ ioredirection(void)
|
|||
void
|
||||
addio(int token, char *s)
|
||||
{
|
||||
if (nextio >= MAXNODE) {
|
||||
if(nextio >= MAXNODE) {
|
||||
printf(2, "addio: ran out of nodes\n");
|
||||
return;
|
||||
}
|
||||
|
@ -267,9 +267,9 @@ int
|
|||
gettoken(char *s, char **p1)
|
||||
{
|
||||
static int c, nc;
|
||||
static char* np1, *np2;
|
||||
static char *np1, *np2;
|
||||
|
||||
if (s) {
|
||||
if(s) {
|
||||
nc = _gettoken(s, &np1, &np2);
|
||||
return 0;
|
||||
}
|
||||
|
@ -299,39 +299,39 @@ _gettoken(char *s, char **p1, char **p2)
|
|||
{
|
||||
int t;
|
||||
|
||||
if (s == 0) {
|
||||
if (debug > 1)
|
||||
if(s == 0) {
|
||||
if(debug > 1)
|
||||
printf(2, "GETTOKEN NULL\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (debug > 1)
|
||||
if(debug > 1)
|
||||
printf(2, "GETTOKEN: %s\n", s);
|
||||
|
||||
*p1 = 0;
|
||||
*p2 = 0;
|
||||
|
||||
while (strchr(WHITESPACE, *s))
|
||||
while(strchr(WHITESPACE, *s))
|
||||
*s++ = 0;
|
||||
if (*s == 0) {
|
||||
if (debug > 1)
|
||||
if(*s == 0) {
|
||||
if(debug > 1)
|
||||
printf(2, "EOL\n");
|
||||
return 0;
|
||||
}
|
||||
if (strchr(SYMBOLS, *s)) {
|
||||
if(strchr(SYMBOLS, *s)) {
|
||||
t = *s;
|
||||
*p1 = s;
|
||||
*s++ = 0;
|
||||
*p2 = s;
|
||||
if (debug > 1)
|
||||
if(debug > 1)
|
||||
printf(2, "TOK %c\n", t);
|
||||
return t;
|
||||
}
|
||||
*p1 = s;
|
||||
while (*s && !strchr(WHITESPACE SYMBOLS, *s))
|
||||
while(*s && !strchr(WHITESPACE SYMBOLS, *s))
|
||||
s++;
|
||||
*p2 = s;
|
||||
if (debug > 1) {
|
||||
if(debug > 1) {
|
||||
t = **p2;
|
||||
**p2 = 0;
|
||||
printf(2, "WORD: %s\n", *p1);
|
||||
|
|
|
@ -29,7 +29,7 @@ getcallerpcs(void *v, uint pcs[])
|
|||
}
|
||||
|
||||
void
|
||||
acquire(struct spinlock * lock)
|
||||
acquire(struct spinlock *lock)
|
||||
{
|
||||
if(holding(lock))
|
||||
panic("acquire");
|
||||
|
@ -46,7 +46,7 @@ acquire(struct spinlock * lock)
|
|||
}
|
||||
|
||||
void
|
||||
release(struct spinlock * lock)
|
||||
release(struct spinlock *lock)
|
||||
{
|
||||
|
||||
if(!holding(lock))
|
||||
|
|
24
string.c
24
string.c
|
@ -1,10 +1,10 @@
|
|||
#include "types.h"
|
||||
#include "defs.h"
|
||||
|
||||
void *
|
||||
void*
|
||||
memset(void *dst, int c, uint n)
|
||||
{
|
||||
char *d = (char *) dst;
|
||||
char *d = (char*) dst;
|
||||
|
||||
while(n-- > 0)
|
||||
*d++ = c;
|
||||
|
@ -15,11 +15,11 @@ memset(void *dst, int c, uint n)
|
|||
int
|
||||
memcmp(const void *v1, const void *v2, uint n)
|
||||
{
|
||||
const uchar *s1 = (const uchar *) v1;
|
||||
const uchar *s2 = (const uchar *) v2;
|
||||
const uchar *s1 = (const uchar*) v1;
|
||||
const uchar *s2 = (const uchar*) v2;
|
||||
|
||||
while (n-- > 0) {
|
||||
if (*s1 != *s2)
|
||||
while(n-- > 0) {
|
||||
if(*s1 != *s2)
|
||||
return (int) *s1 - (int) *s2;
|
||||
s1++, s2++;
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ memcmp(const void *v1, const void *v2, uint n)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void *
|
||||
void*
|
||||
memmove(void *dst, const void *src, uint n)
|
||||
{
|
||||
const char *s;
|
||||
|
@ -35,13 +35,13 @@ memmove(void *dst, const void *src, uint n)
|
|||
|
||||
s = src;
|
||||
d = dst;
|
||||
if (s < d && s + n > d) {
|
||||
if(s < d && s + n > d) {
|
||||
s += n;
|
||||
d += n;
|
||||
while (n-- > 0)
|
||||
while(n-- > 0)
|
||||
*--d = *--s;
|
||||
} else
|
||||
while (n-- > 0)
|
||||
while(n-- > 0)
|
||||
*d++ = *s++;
|
||||
|
||||
return dst;
|
||||
|
@ -50,9 +50,9 @@ memmove(void *dst, const void *src, uint n)
|
|||
int
|
||||
strncmp(const char *p, const char *q, uint n)
|
||||
{
|
||||
while (n > 0 && *p && *p == *q)
|
||||
while(n > 0 && *p && *p == *q)
|
||||
n--, p++, q++;
|
||||
if (n == 0)
|
||||
if(n == 0)
|
||||
return 0;
|
||||
else
|
||||
return (int) ((uchar) *p - (uchar) *q);
|
||||
|
|
26
syscall.c
26
syscall.c
|
@ -41,7 +41,7 @@ fetchint(struct proc *p, uint addr, int *ip)
|
|||
// Fetch byte from a user-supplied pointer.
|
||||
// Returns 0 on success, -1 if pointer is illegal.
|
||||
int
|
||||
fetchbyte(struct proc *p, uint addr, char* c)
|
||||
fetchbyte(struct proc *p, uint addr, char *c)
|
||||
{
|
||||
if(addr >= p->sz)
|
||||
return -1;
|
||||
|
@ -262,10 +262,10 @@ sys_open(void)
|
|||
|
||||
iunlock(ip);
|
||||
fd->type = FD_FILE;
|
||||
if (arg1 & O_RDWR) {
|
||||
if(arg1 & O_RDWR) {
|
||||
fd->readable = 1;
|
||||
fd->writeable = 1;
|
||||
} else if (arg1 & O_WRONLY) {
|
||||
} else if(arg1 & O_WRONLY) {
|
||||
fd->readable = 0;
|
||||
fd->writeable = 1;
|
||||
} else {
|
||||
|
@ -297,7 +297,7 @@ sys_mknod(void)
|
|||
if(l >= DIRSIZ)
|
||||
return -1;
|
||||
|
||||
nip = mknod (cp->mem + arg0, (short) arg1, (short) arg2, (short) arg3);
|
||||
nip = mknod(cp->mem + arg0, (short) arg1, (short) arg2, (short) arg3);
|
||||
if(nip)
|
||||
iput(nip);
|
||||
return (nip == 0) ? -1 : 0;
|
||||
|
@ -333,14 +333,14 @@ sys_mkdir(void)
|
|||
dp->nlink += 1;
|
||||
iupdate(dp);
|
||||
|
||||
memset (de.name, '\0', DIRSIZ);
|
||||
memset(de.name, '\0', DIRSIZ);
|
||||
de.name[0] = '.';
|
||||
de.inum = nip->inum;
|
||||
writei (nip, (char *) &de, 0, sizeof(de));
|
||||
writei(nip, (char*) &de, 0, sizeof(de));
|
||||
|
||||
de.inum = dp->inum;
|
||||
de.name[1] = '.';
|
||||
writei (nip, (char *) &de, sizeof(de), sizeof(de));
|
||||
writei(nip, (char*) &de, sizeof(de), sizeof(de));
|
||||
|
||||
iput(dp);
|
||||
iput(nip);
|
||||
|
@ -363,15 +363,15 @@ sys_chdir(void)
|
|||
if((l = checkstring(arg0)) < 0)
|
||||
return -1;
|
||||
|
||||
if ((ip = namei(cp->mem + arg0, NAMEI_LOOKUP, 0, 0, 0)) == 0)
|
||||
if((ip = namei(cp->mem + arg0, NAMEI_LOOKUP, 0, 0, 0)) == 0)
|
||||
return -1;
|
||||
|
||||
if (ip == cp->cwd) {
|
||||
iput (ip);
|
||||
if(ip == cp->cwd) {
|
||||
iput(ip);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ip->type != T_DIR) {
|
||||
if(ip->type != T_DIR) {
|
||||
iput(ip);
|
||||
return -1;
|
||||
}
|
||||
|
@ -414,7 +414,7 @@ sys_fstat(void)
|
|||
return -1;
|
||||
if(addr + sizeof(struct stat) > cp->sz)
|
||||
return -1;
|
||||
r = fd_stat (cp->fds[fd], (struct stat *)(cp->mem + addr));
|
||||
r = fd_stat(cp->fds[fd], (struct stat*)(cp->mem + addr));
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -430,7 +430,7 @@ sys_dup(void)
|
|||
return -1;
|
||||
if(cp->fds[fd] == 0)
|
||||
return -1;
|
||||
if ((ufd1 = fd_ualloc()) < 0)
|
||||
if((ufd1 = fd_ualloc()) < 0)
|
||||
return -1;
|
||||
cp->fds[ufd1] = cp->fds[fd];
|
||||
fd_incref(cp->fds[ufd1]);
|
||||
|
|
12
ulib.c
12
ulib.c
|
@ -23,7 +23,7 @@ strcpy(char *s, char *t)
|
|||
int
|
||||
strcmp(const char *p, const char *q)
|
||||
{
|
||||
while (*p && *p == *q)
|
||||
while(*p && *p == *q)
|
||||
p++, q++;
|
||||
return (int) ((unsigned char) *p - (unsigned char) *q);
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ strlen(char *s)
|
|||
void*
|
||||
memset(void *dst, int c, unsigned int n)
|
||||
{
|
||||
char *d = (char *) dst;
|
||||
char *d = (char*) dst;
|
||||
|
||||
while(n-- > 0)
|
||||
*d++ = c;
|
||||
|
@ -51,9 +51,9 @@ memset(void *dst, int c, unsigned int n)
|
|||
char*
|
||||
strchr(const char *s, char c)
|
||||
{
|
||||
for (; *s; s++)
|
||||
if (*s == c)
|
||||
return (char *) s;
|
||||
for(; *s; s++)
|
||||
if(*s == c)
|
||||
return (char*) s;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -82,7 +82,7 @@ stat(char *n, struct stat *st)
|
|||
int r;
|
||||
|
||||
fd = open(n, O_RDONLY);
|
||||
if (fd < 0) return -1;
|
||||
if(fd < 0) return -1;
|
||||
r = fstat(fd, st);
|
||||
close(fd);
|
||||
return r;
|
||||
|
|
36
umalloc.c
36
umalloc.c
|
@ -26,16 +26,16 @@ free(void *ap)
|
|||
{
|
||||
Header *bp, *p;
|
||||
|
||||
bp = (Header *) ap - 1;
|
||||
for (p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
|
||||
if (p >= p->s.ptr && (bp > p || bp < p->s.ptr))
|
||||
bp = (Header*) ap - 1;
|
||||
for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
|
||||
if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
|
||||
break;
|
||||
if (bp + bp->s.size == p->s.ptr) {
|
||||
if(bp + bp->s.size == p->s.ptr) {
|
||||
bp->s.size += p->s.ptr->s.size;
|
||||
bp->s.ptr = p->s.ptr->s.ptr;
|
||||
} else
|
||||
bp->s.ptr = p->s.ptr;
|
||||
if (p + p->s.size == bp) {
|
||||
if(p + p->s.size == bp) {
|
||||
p->s.size += bp->s.size;
|
||||
p->s.ptr = bp->s.ptr;
|
||||
} else
|
||||
|
@ -43,37 +43,37 @@ free(void *ap)
|
|||
freep = p;
|
||||
}
|
||||
|
||||
static Header *
|
||||
static Header*
|
||||
morecore(uint nu)
|
||||
{
|
||||
char *cp;
|
||||
Header *up;
|
||||
|
||||
if (nu < PAGE)
|
||||
if(nu < PAGE)
|
||||
nu = PAGE;
|
||||
cp = sbrk(nu * sizeof(Header));
|
||||
if (cp == (char *) -1)
|
||||
if(cp == (char*) -1)
|
||||
return 0;
|
||||
up = (Header *) cp;
|
||||
up = (Header*) cp;
|
||||
up->s.size = nu;
|
||||
free((void *)(up + 1));
|
||||
free((void*)(up + 1));
|
||||
return freep;
|
||||
}
|
||||
|
||||
void *
|
||||
void*
|
||||
malloc(uint nbytes)
|
||||
{
|
||||
Header *p, *prevp;
|
||||
uint nunits;
|
||||
|
||||
nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
|
||||
if ((prevp = freep) == 0) {
|
||||
if((prevp = freep) == 0) {
|
||||
base.s.ptr = freep = prevp = &base;
|
||||
base.s.size = 0;
|
||||
}
|
||||
for (p = prevp->s.ptr; ; prevp = p, p = p->s.ptr) {
|
||||
if (p->s.size >= nunits) {
|
||||
if (p->s.size == nunits)
|
||||
for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr) {
|
||||
if(p->s.size >= nunits) {
|
||||
if(p->s.size == nunits)
|
||||
prevp->s.ptr = p->s.ptr;
|
||||
else {
|
||||
p->s.size -= nunits;
|
||||
|
@ -81,10 +81,10 @@ malloc(uint nbytes)
|
|||
p->s.size = nunits;
|
||||
}
|
||||
freep = prevp;
|
||||
return (void *) (p + 1);
|
||||
return (void*) (p + 1);
|
||||
}
|
||||
if (p == freep)
|
||||
if ((p = morecore(nunits)) == 0)
|
||||
if(p == freep)
|
||||
if((p = morecore(nunits)) == 0)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
36
user.h
36
user.h
|
@ -7,27 +7,27 @@ int write(int, void*, int);
|
|||
int read(int, void*, int);
|
||||
int close(int);
|
||||
int kill(int);
|
||||
int exec(char *, char **);
|
||||
int open(char *, int);
|
||||
int mknod (char*,short,short,short);
|
||||
int unlink (char*);
|
||||
int fstat (int fd, struct stat *stat);
|
||||
int link(char *, char *);
|
||||
int mkdir(char *);
|
||||
int chdir(char *);
|
||||
int exec(char*, char**);
|
||||
int open(char*, int);
|
||||
int mknod(char*, short, short, short);
|
||||
int unlink(char*);
|
||||
int fstat(int fd, struct stat*);
|
||||
int link(char*, char*);
|
||||
int mkdir(char*);
|
||||
int chdir(char*);
|
||||
int dup(int);
|
||||
int getpid();
|
||||
char *sbrk(int);
|
||||
char* sbrk(int);
|
||||
|
||||
// ulib.c
|
||||
int stat(char *, struct stat *stat);
|
||||
int stat(char*, struct stat*);
|
||||
int puts(char*);
|
||||
char* strcpy(char*, char*);
|
||||
char *strchr(const char *s, char c);
|
||||
int strcmp(const char *p, const char *q);
|
||||
void printf(int fd, char *fmt, ...);
|
||||
char *gets(char *, int max);
|
||||
unsigned int strlen(char *);
|
||||
void * memset(void *dst, int c, unsigned int n);
|
||||
void *malloc(uint);
|
||||
void free(void *);
|
||||
char* strchr(const char*, char c);
|
||||
int strcmp(const char*, const char*);
|
||||
void printf(int, char*, ...);
|
||||
char* gets(char*, int max);
|
||||
unsigned int strlen(char*);
|
||||
void* memset(void*, int, unsigned int);
|
||||
void* malloc(uint);
|
||||
void free(void*);
|
||||
|
|
48
userfs.c
48
userfs.c
|
@ -47,12 +47,12 @@ writetest(void)
|
|||
printf(stdout, "error: creat small failed!\n");
|
||||
exit();
|
||||
}
|
||||
for (i = 0; i < 100; i++) {
|
||||
if (write (fd, "aaaaaaaaaa", 10) != 10) {
|
||||
for(i = 0; i < 100; i++) {
|
||||
if(write(fd, "aaaaaaaaaa", 10) != 10) {
|
||||
printf(stdout, "error: write aa %d new file failed\n", i);
|
||||
exit();
|
||||
}
|
||||
if (write (fd, "bbbbbbbbbb", 10) != 10) {
|
||||
if(write(fd, "bbbbbbbbbb", 10) != 10) {
|
||||
printf(stdout, "error: write bb %d new file failed\n", i);
|
||||
exit();
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ writetest(void)
|
|||
exit();
|
||||
}
|
||||
i = read(fd, buf, 2000);
|
||||
if (i == 2000) {
|
||||
if(i == 2000) {
|
||||
printf(stdout, "read succeeded\n");
|
||||
} else {
|
||||
printf(stdout, "read failed\n");
|
||||
|
@ -75,7 +75,7 @@ writetest(void)
|
|||
}
|
||||
close(fd);
|
||||
|
||||
if (unlink("small") < 0) {
|
||||
if(unlink("small") < 0) {
|
||||
printf(stdout, "unlink small failed\n");
|
||||
exit();
|
||||
}
|
||||
|
@ -94,9 +94,9 @@ writetest1(void)
|
|||
exit();
|
||||
}
|
||||
|
||||
for (i = 0; i < MAXFILE; i++) {
|
||||
((int *) buf)[0] = i;
|
||||
if (write (fd, buf, 512) != 512) {
|
||||
for(i = 0; i < MAXFILE; i++) {
|
||||
((int*) buf)[0] = i;
|
||||
if(write(fd, buf, 512) != 512) {
|
||||
printf(stdout, "error: write big file failed\n", i);
|
||||
exit();
|
||||
}
|
||||
|
@ -111,26 +111,26 @@ writetest1(void)
|
|||
}
|
||||
|
||||
n = 0;
|
||||
while (1) {
|
||||
while(1) {
|
||||
i = read(fd, buf, 512);
|
||||
if (i == 0) {
|
||||
if (n == MAXFILE - 1) {
|
||||
if(i == 0) {
|
||||
if(n == MAXFILE - 1) {
|
||||
printf(stdout, "read only %d blocks from big", n);
|
||||
exit();
|
||||
}
|
||||
break;
|
||||
} else if (i != 512) {
|
||||
} else if(i != 512) {
|
||||
printf(stdout, "read failed %d\n", i);
|
||||
exit();
|
||||
}
|
||||
if (((int *)buf)[0] != n) {
|
||||
printf(stdout, "read content of block %d is %d\n", n, ((int *)buf)[0]);
|
||||
if(((int*)buf)[0] != n) {
|
||||
printf(stdout, "read content of block %d is %d\n", n, ((int*)buf)[0]);
|
||||
exit();
|
||||
}
|
||||
n++;
|
||||
}
|
||||
close(fd);
|
||||
if (unlink("big") < 0) {
|
||||
if(unlink("big") < 0) {
|
||||
printf(stdout, "unlink big failed\n");
|
||||
exit();
|
||||
}
|
||||
|
@ -145,14 +145,14 @@ createtest(void)
|
|||
|
||||
name[0] = 'a';
|
||||
name[2] = '\0';
|
||||
for (i = 0; i < 52; i++) {
|
||||
for(i = 0; i < 52; i++) {
|
||||
name[1] = '0' + i;
|
||||
fd = open(name, O_CREATE|O_RDWR);
|
||||
close(fd);
|
||||
}
|
||||
name[0] = 'a';
|
||||
name[2] = '\0';
|
||||
for (i = 0; i < 52; i++) {
|
||||
for(i = 0; i < 52; i++) {
|
||||
name[1] = '0' + i;
|
||||
unlink(name);
|
||||
}
|
||||
|
@ -162,22 +162,22 @@ void dirtest(void)
|
|||
{
|
||||
printf(stdout, "mkdir\n");
|
||||
|
||||
if (mkdir("dir0") < 0) {
|
||||
if(mkdir("dir0") < 0) {
|
||||
printf(stdout, "mkdir failed\n");
|
||||
exit();
|
||||
}
|
||||
|
||||
if (chdir("dir0") < 0) {
|
||||
if(chdir("dir0") < 0) {
|
||||
printf(stdout, "chdir dir0 failed\n");
|
||||
exit();
|
||||
}
|
||||
|
||||
if (chdir("..") < 0) {
|
||||
if(chdir("..") < 0) {
|
||||
printf(stdout, "chdir .. failed\n");
|
||||
exit ();
|
||||
exit();
|
||||
}
|
||||
|
||||
if (unlink("dir0") < 0) {
|
||||
if(unlink("dir0") < 0) {
|
||||
printf(stdout, "unlink dir0 failed\n");
|
||||
exit();
|
||||
}
|
||||
|
@ -186,11 +186,11 @@ void dirtest(void)
|
|||
void
|
||||
exectest(void)
|
||||
{
|
||||
if (exec("echo", echo_args) < 0) {
|
||||
if(exec("echo", echo_args) < 0) {
|
||||
printf(stdout, "exec echo failed\n");
|
||||
exit();
|
||||
}
|
||||
if (exec("cat", cat_args) < 0) {
|
||||
if(exec("cat", cat_args) < 0) {
|
||||
printf(stdout, "exec cat failed\n");
|
||||
exit();
|
||||
}
|
||||
|
|
10
usertests.c
10
usertests.c
|
@ -131,17 +131,17 @@ mem(void)
|
|||
|
||||
if((pid = fork()) == 0){
|
||||
m1 = 0;
|
||||
while ((m2 = malloc(10001)) != 0) {
|
||||
*(char **) m2 = m1;
|
||||
while((m2 = malloc(10001)) != 0) {
|
||||
*(char**) m2 = m1;
|
||||
m1 = m2;
|
||||
}
|
||||
while (m1) {
|
||||
m2 = *(char **)m1;
|
||||
while(m1) {
|
||||
m2 = *(char**)m1;
|
||||
free(m1);
|
||||
m1 = m2;
|
||||
}
|
||||
m1 = malloc(1024*20);
|
||||
if (m1 == 0) {
|
||||
if(m1 == 0) {
|
||||
puts("couldn't allocate mem?!!\n");
|
||||
exit();
|
||||
}
|
||||
|
|
8
x86.h
8
x86.h
|
@ -91,13 +91,13 @@ cpuid(uint info, uint *eaxp, uint *ebxp, uint *ecxp, uint *edxp)
|
|||
asm volatile("cpuid" :
|
||||
"=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx) :
|
||||
"a" (info));
|
||||
if (eaxp)
|
||||
if(eaxp)
|
||||
*eaxp = eax;
|
||||
if (ebxp)
|
||||
if(ebxp)
|
||||
*ebxp = ebx;
|
||||
if (ecxp)
|
||||
if(ecxp)
|
||||
*ecxp = ecx;
|
||||
if (edxp)
|
||||
if(edxp)
|
||||
*edxp = edx;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue