standardize various * conventions
This commit is contained in:
parent
03b6376f56
commit
9e9bcaf143
43 changed files with 503 additions and 503 deletions
10
bio.c
10
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);
|
||||
|
@ -107,7 +107,7 @@ brelse(struct buf *b)
|
|||
{
|
||||
if((b->flags & B_BUSY) == 0)
|
||||
panic("brelse");
|
||||
|
||||
|
||||
acquire(&buf_table_lock);
|
||||
|
||||
b->next->prev = b->prev;
|
||||
|
|
30
bootasm.S
30
bootasm.S
|
@ -1,23 +1,23 @@
|
|||
#include "asm.h"
|
||||
|
||||
|
||||
.set PROT_MODE_CSEG,0x8 # code segment selector
|
||||
.set PROT_MODE_DSEG,0x10 # data segment selector
|
||||
.set CR0_PE_ON,0x1 # protected mode enable flag
|
||||
|
||||
|
||||
###################################################################################
|
||||
# ENTRY POINT
|
||||
# ENTRY POINT
|
||||
# This code should be stored in the first sector of the hard disk.
|
||||
# After the BIOS initializes the hardware on startup or system reset,
|
||||
# it loads this code at physical address 0x7c00 - 0x7d00 (512 bytes).
|
||||
# Then the BIOS jumps to the beginning of it, address 0x7c00,
|
||||
# while running in 16-bit real-mode (8086 compatibility mode).
|
||||
# The Code Segment register (CS) is initially zero on entry.
|
||||
#
|
||||
#
|
||||
# This code switches into 32-bit protected mode so that all of
|
||||
# memory can accessed, then calls into C.
|
||||
###################################################################################
|
||||
|
||||
.globl start # Entry point
|
||||
|
||||
.globl start # Entry point
|
||||
start:
|
||||
.code16 # This runs in real mode
|
||||
cli # Disable interrupts
|
||||
|
@ -31,7 +31,7 @@ start:
|
|||
|
||||
# Set up the stack pointer, growing downward from 0x7c00.
|
||||
movw $start,%sp # Stack Pointer
|
||||
|
||||
|
||||
#### Enable A20:
|
||||
#### For fascinating historical reasons (related to the fact that
|
||||
#### the earliest 8086-based PCs could only address 1MB of physical memory
|
||||
|
@ -39,7 +39,7 @@ start:
|
|||
#### physical address line 20 is tied to low when the machine boots.
|
||||
#### Obviously this a bit of a drag for us, especially when trying to
|
||||
#### address memory above 1MB. This code undoes this.
|
||||
|
||||
|
||||
seta20.1:
|
||||
inb $0x64,%al # Get status
|
||||
testb $0x2,%al # Busy?
|
||||
|
@ -54,7 +54,7 @@ seta20.2:
|
|||
movb $0xdf,%al # Enable
|
||||
outb %al,$0x60 # A20
|
||||
|
||||
#### Switch from real to protected mode
|
||||
#### Switch from real to protected mode
|
||||
#### The descriptors in our GDT allow all physical memory to be accessed.
|
||||
#### Furthermore, the descriptors have base addresses of 0, so that the
|
||||
#### segment translation is a NOP, ie. virtual addresses are identical to
|
||||
|
@ -63,21 +63,21 @@ seta20.2:
|
|||
#### that it is running directly on physical memory with no translation.
|
||||
#### This initial NOP-translation setup is required by the processor
|
||||
#### to ensure that the transition to protected mode occurs smoothly.
|
||||
|
||||
|
||||
real_to_prot:
|
||||
cli # Mandatory since we dont set up an IDT
|
||||
lgdt gdtdesc # load GDT -- mandatory in protected mode
|
||||
movl %cr0, %eax # turn on protected mode
|
||||
orl $CR0_PE_ON, %eax #
|
||||
movl %eax, %cr0 #
|
||||
orl $CR0_PE_ON, %eax #
|
||||
movl %eax, %cr0 #
|
||||
### CPU magic: jump to relocation, flush prefetch queue, and reload %cs
|
||||
### Has the effect of just jmp to the next instruction, but simultaneous
|
||||
### loads CS with $PROT_MODE_CSEG.
|
||||
ljmp $PROT_MODE_CSEG, $protcseg
|
||||
|
||||
|
||||
#### we are in 32-bit protected mode (hence the .code32)
|
||||
.code32
|
||||
protcseg:
|
||||
protcseg:
|
||||
# Set up the protected-mode data segment registers
|
||||
movw $PROT_MODE_DSEG, %ax # Our data segment selector
|
||||
movw %ax, %ds # -> DS: Data Segment
|
||||
|
@ -97,7 +97,7 @@ gdt:
|
|||
SEG_NULLASM # null seg
|
||||
SEG_ASM(STA_X|STA_R, 0x0, 0xffffffff) # code seg
|
||||
SEG_ASM(STA_W, 0x0, 0xffffffff) # data seg
|
||||
|
||||
|
||||
gdtdesc:
|
||||
.word 0x17 # sizeof(gdt) - 1
|
||||
.long gdt # address gdt
|
||||
|
|
24
bootmain.c
24
bootmain.c
|
@ -9,16 +9,16 @@
|
|||
* DISK LAYOUT
|
||||
* * This program(boot.S and main.c) is the bootloader. It should
|
||||
* be stored in the first sector of the disk.
|
||||
*
|
||||
*
|
||||
* * The 2nd sector onward holds the kernel image.
|
||||
*
|
||||
*
|
||||
* * The kernel image must be in ELF format.
|
||||
*
|
||||
* BOOT UP STEPS
|
||||
* BOOT UP STEPS
|
||||
* * when the CPU boots it loads the BIOS into memory and executes it
|
||||
*
|
||||
* * the BIOS intializes devices, sets of the interrupt routines, and
|
||||
* reads the first sector of the boot device(e.g., hard-drive)
|
||||
* reads the first sector of the boot device(e.g., hard-drive)
|
||||
* into memory and jumps to it.
|
||||
*
|
||||
* * Assuming this boot loader is stored in the first sector of the
|
||||
|
@ -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);
|
||||
|
@ -74,7 +74,7 @@ readseg(uint va, uint count, uint offset)
|
|||
|
||||
va &= 0xFFFFFF;
|
||||
end_va = va + count;
|
||||
|
||||
|
||||
// round down to sector boundary
|
||||
va &= ~(SECTSIZE - 1);
|
||||
|
||||
|
@ -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 */;
|
||||
}
|
||||
|
||||
|
|
22
bootother.S
22
bootother.S
|
@ -1,5 +1,5 @@
|
|||
#include "asm.h"
|
||||
|
||||
|
||||
/*
|
||||
* Start an Application Processor. This must be placed on a 4KB boundary
|
||||
* somewhere in the 1st MB of conventional memory (APBOOTSTRAP). However,
|
||||
|
@ -13,7 +13,7 @@
|
|||
* mp.c causes each non-boot CPU in turn to jump to start.
|
||||
* mp.c puts the correct %esp in start-4, and the place to jump
|
||||
* to in start-8.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
.set PROT_MODE_CSEG,0x8 # code segment selector
|
||||
|
@ -34,8 +34,8 @@ start:
|
|||
|
||||
# Set up the stack pointer, growing downward from 0x7000-8.
|
||||
movw $start-8,%sp # Stack Pointer
|
||||
|
||||
#### Switch from real to protected mode
|
||||
|
||||
#### Switch from real to protected mode
|
||||
#### The descriptors in our GDT allow all physical memory to be accessed.
|
||||
#### Furthermore, the descriptors have base addresses of 0, so that the
|
||||
#### segment translation is a NOP, ie. virtual addresses are identical to
|
||||
|
@ -44,11 +44,11 @@ start:
|
|||
#### that it is running directly on physical memory with no translation.
|
||||
#### This initial NOP-translation setup is required by the processor
|
||||
#### to ensure that the transition to protected mode occurs smoothly.
|
||||
|
||||
|
||||
lgdt gdtdesc # load GDT -- mandatory in protected mode
|
||||
movl %cr0, %eax # turn on protected mode
|
||||
orl $CR0_PE_ON, %eax #
|
||||
movl %eax, %cr0 #
|
||||
orl $CR0_PE_ON, %eax #
|
||||
movl %eax, %cr0 #
|
||||
### CPU magic: jump to relocation, flush prefetch queue, and reload %cs
|
||||
### Has the effect of just jmp to the next instruction, but simultaneous
|
||||
### loads CS with $PROT_MODE_CSEG.
|
||||
|
@ -56,7 +56,7 @@ start:
|
|||
|
||||
#### we are in 32-bit protected mode (hence the .code32)
|
||||
.code32
|
||||
protcseg:
|
||||
protcseg:
|
||||
# Set up the protected-mode data segment registers
|
||||
movw $PROT_MODE_DSEG, %ax # Our data segment selector
|
||||
movw %ax, %ds # -> DS: Data Segment
|
||||
|
@ -67,14 +67,14 @@ protcseg:
|
|||
|
||||
movl start-8, %eax
|
||||
movl start-4, %esp
|
||||
jmp *%eax
|
||||
|
||||
jmp *%eax
|
||||
|
||||
.p2align 2 # force 4 byte alignment
|
||||
gdt:
|
||||
SEG_NULLASM # null seg
|
||||
SEG_ASM(STA_X|STA_R, 0x0, 0xffffffff) # code seg
|
||||
SEG_ASM(STA_W, 0x0, 0xffffffff) # data seg
|
||||
|
||||
|
||||
gdtdesc:
|
||||
.word 0x17 # sizeof(gdt) - 1
|
||||
.long gdt # address gdt
|
||||
|
|
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++){
|
||||
|
|
48
console.c
48
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){
|
||||
|
@ -79,7 +79,7 @@ printint(int xx, int base, int sgn)
|
|||
char digits[] = "0123456789ABCDEF";
|
||||
int i = 0, neg = 0;
|
||||
uint x;
|
||||
|
||||
|
||||
if(sgn && xx < 0){
|
||||
neg = 1;
|
||||
x = 0 - xx;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -211,7 +211,7 @@ console_write (int minor, char *buf, int n)
|
|||
#define KEY_INS 0xE8
|
||||
#define KEY_DEL 0xE9
|
||||
|
||||
static uchar shiftcode[256] =
|
||||
static uchar shiftcode[256] =
|
||||
{
|
||||
[0x1D] CTL,
|
||||
[0x2A] SHIFT,
|
||||
|
@ -221,7 +221,7 @@ static uchar shiftcode[256] =
|
|||
[0xB8] ALT
|
||||
};
|
||||
|
||||
static uchar togglecode[256] =
|
||||
static uchar togglecode[256] =
|
||||
{
|
||||
[0x3A] CAPSLOCK,
|
||||
[0x45] NUMLOCK,
|
||||
|
@ -249,7 +249,7 @@ static uchar normalmap[256] =
|
|||
[0xD2] KEY_INS, [0xD3] KEY_DEL
|
||||
};
|
||||
|
||||
static uchar shiftmap[256] =
|
||||
static uchar shiftmap[256] =
|
||||
{
|
||||
NO, 033, '!', '@', '#', '$', '%', '^', // 0x00
|
||||
'&', '*', '(', ')', '_', '+', '\b', '\t',
|
||||
|
@ -272,13 +272,13 @@ static uchar shiftmap[256] =
|
|||
|
||||
#define C(x) (x - '@')
|
||||
|
||||
static uchar ctlmap[256] =
|
||||
static uchar ctlmap[256] =
|
||||
{
|
||||
NO, NO, NO, NO, NO, NO, NO, NO,
|
||||
NO, NO, NO, NO, NO, NO, NO, NO,
|
||||
NO, NO, NO, NO, NO, NO, NO, NO,
|
||||
NO, NO, NO, NO, NO, NO, NO, NO,
|
||||
C('Q'), C('W'), C('E'), C('R'), C('T'), C('Y'), C('U'), C('I'),
|
||||
C('O'), C('P'), NO, NO, '\r', NO, C('A'), C('S'),
|
||||
C('D'), C('F'), C('G'), C('H'), C('J'), C('K'), C('L'), NO,
|
||||
C('D'), C('F'), C('G'), C('H'), C('J'), C('K'), C('L'), NO,
|
||||
NO, NO, NO, C('\\'), C('Z'), C('X'), C('C'), C('V'),
|
||||
C('B'), C('N'), C('M'), NO, NO, C('/'), NO, NO,
|
||||
[0x97] KEY_HOME,
|
||||
|
@ -311,41 +311,41 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
shift |= shiftcode[data];
|
||||
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);
|
||||
|
|
172
fs.c
172
fs.c
|
@ -27,8 +27,8 @@ iinit(void)
|
|||
/*
|
||||
* allocate a disk block
|
||||
*/
|
||||
static uint
|
||||
balloc(uint dev)
|
||||
static uint
|
||||
balloc(uint dev)
|
||||
{
|
||||
int b;
|
||||
struct buf *bp;
|
||||
|
@ -39,31 +39,31 @@ 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;
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
bfree(int dev, uint b)
|
||||
{
|
||||
struct buf *bp;
|
||||
|
@ -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,16 +86,16 @@ 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);
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* fetch an inode, from the in-core table if it's already
|
||||
* 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;
|
||||
|
@ -144,25 +144,25 @@ iget(uint dev, uint inum)
|
|||
return nip;
|
||||
}
|
||||
|
||||
void
|
||||
iupdate (struct inode *ip)
|
||||
void
|
||||
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
|
||||
brelse(bp);
|
||||
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,42 +244,42 @@ 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;
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
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;
|
||||
}
|
||||
}
|
||||
brelse(inbp);
|
||||
}
|
||||
}
|
||||
bfree(ip->dev, ip->addrs[i]);
|
||||
ip->addrs[i] = 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,10 +493,10 @@ 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)
|
||||
if(ep->inum == 0)
|
||||
continue;
|
||||
for(i = 0; i < DIRSIZ && cp[i] != '/' && cp[i]; i++)
|
||||
if(cp[i] != ep->name[i])
|
||||
|
@ -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,21 +585,21 @@ 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);
|
||||
|
||||
return ip;
|
||||
|
@ -611,7 +611,7 @@ unlink(char *cp)
|
|||
struct inode *ip, *dp;
|
||||
struct dirent de;
|
||||
uint off, inum, dev;
|
||||
|
||||
|
||||
dp = namei(cp, NAMEI_DELETE, &off, 0, 0);
|
||||
if(dp == 0)
|
||||
return -1;
|
||||
|
@ -626,7 +626,7 @@ unlink(char *cp)
|
|||
memset(&de, 0, sizeof(de));
|
||||
if(writei(dp, (char*)&de, off, sizeof(de)) != sizeof(de))
|
||||
panic("unlink dir write");
|
||||
|
||||
|
||||
iupdate(dp);
|
||||
iput(dp);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -667,10 +667,10 @@ link(char *name1, char *name2)
|
|||
iput(dp);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
ilock(ip);
|
||||
ip->nlink += 1;
|
||||
iupdate (ip);
|
||||
iupdate(ip);
|
||||
|
||||
wdir(dp, last, ip->inum);
|
||||
iput(dp);
|
||||
|
|
|
@ -151,7 +151,7 @@ createdelete()
|
|||
|
||||
if(pid)
|
||||
exit();
|
||||
else
|
||||
else
|
||||
exit();
|
||||
|
||||
for(i = 0; i < n; i++){
|
||||
|
@ -198,7 +198,7 @@ void
|
|||
unlinkread()
|
||||
{
|
||||
int fd, fd1;
|
||||
|
||||
|
||||
fd = open("unlinkread", O_CREATE | O_RDWR);
|
||||
if(fd < 0){
|
||||
puts("create unlinkread failed\n");
|
||||
|
@ -278,7 +278,7 @@ linktest()
|
|||
exit();
|
||||
}
|
||||
close(fd);
|
||||
|
||||
|
||||
if(link("lf2", "lf2") >= 0){
|
||||
puts("link lf2 lf2 succeeded! oops\n");
|
||||
exit();
|
||||
|
@ -591,7 +591,7 @@ bigfile()
|
|||
}
|
||||
}
|
||||
close(fd);
|
||||
|
||||
|
||||
fd = open("bigfile", 0);
|
||||
if(fd < 0){
|
||||
puts("cannot open bigfile\n");
|
||||
|
|
32
ide.c
32
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,17 +134,17 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
tail = (tail + 1) % NREQUEST;
|
||||
ide_start_request();
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
2
init.c
2
init.c
|
@ -12,7 +12,7 @@ int
|
|||
main(void)
|
||||