Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Change dev read/write functions
to take inode* instead of minor number.

Unlock console inode during console_read
and console_write.  Otherwise background
processes cannot write to console while the
shell is reading it waiting for input.
  • Loading branch information
rsc committed Aug 28, 2007
1 parent e3f271e commit d844f0f
Showing 3 changed files with 12 additions and 7 deletions.
11 changes: 8 additions & 3 deletions console.c
Original file line number Diff line number Diff line change
@@ -164,14 +164,16 @@ cprintf(char *fmt, ...)
}

int
console_write(int minor, char *buf, int n)
console_write(struct inode *ip, char *buf, int n)
{
int i;

iunlock(ip);
acquire(&console_lock);
for(i = 0; i < n; i++)
cons_putc(buf[i] & 0xff);
release(&console_lock);
ilock(ip);

return n;
}
@@ -230,17 +232,19 @@ console_intr(int (*getc)(void))
}

int
console_read(int minor, char *dst, int n)
console_read(struct inode *ip, char *dst, int n)
{
uint target;
int c;

iunlock(ip);
target = n;
acquire(&input.lock);
while(n > 0){
while(input.r == input.w){
if(cp->killed){
release(&input.lock);
ilock(ip);
return -1;
}
sleep(&input.r, &input.lock);
@@ -262,6 +266,7 @@ console_read(int minor, char *dst, int n)
input.r = 0;
}
release(&input.lock);
ilock(ip);

return target - n;
}
@@ -274,7 +279,7 @@ console_init(void)

devsw[CONSOLE].write = console_write;
devsw[CONSOLE].read = console_read;
use_console_lock = 1;
//use_console_lock = 1;

irq_enable(IRQ_KBD);
ioapic_enable(IRQ_KBD, 0);
4 changes: 2 additions & 2 deletions dev.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
struct devsw {
int (*read)(int, char*, int);
int (*write)(int, char*, int);
int (*read)(struct inode*, char*, int);
int (*write)(struct inode*, char*, int);
};

extern struct devsw devsw[];
4 changes: 2 additions & 2 deletions fs.c
Original file line number Diff line number Diff line change
@@ -411,7 +411,7 @@ readi(struct inode *ip, char *dst, uint off, uint n)
if(ip->type == T_DEV) {
if(ip->major < 0 || ip->major >= NDEV || !devsw[ip->major].read)
return -1;
return devsw[ip->major].read(ip->minor, dst, n);
return devsw[ip->major].read(ip, dst, n);
}

if(off > ip->size || off + n < off)
@@ -439,7 +439,7 @@ writei(struct inode *ip, char *src, uint off, uint n)
if(ip->type == T_DEV) {
if(ip->major < 0 || ip->major >= NDEV || !devsw[ip->major].write)
return -1;
return devsw[ip->major].write(ip->minor, src, n);
return devsw[ip->major].write(ip, src, n);
}

if(off + n < off)

0 comments on commit d844f0f

Please sign in to comment.