forked from mit-pdos/xv6-public
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
convert userfs to use printf bfree ifree writei start on unlink
- Loading branch information
kaashoek
committed
Aug 10, 2006
1 parent
939f9ed
commit 28d9ef0
Showing
11 changed files
with
238 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#include "user.h" | ||
#include "types.h" | ||
|
||
static void | ||
putc(int fd, char c) | ||
{ | ||
write (fd, &c, 1); | ||
} | ||
|
||
static void | ||
printint(int fd, int xx, int base, int sgn) | ||
{ | ||
char buf[16]; | ||
char digits[] = "0123456789ABCDEF"; | ||
int i = 0, neg = 0; | ||
uint x; | ||
|
||
if(sgn && xx < 0){ | ||
neg = 1; | ||
x = 0 - xx; | ||
} else { | ||
x = xx; | ||
} | ||
|
||
do { | ||
buf[i++] = digits[x % base]; | ||
} while((x /= base) != 0); | ||
if(neg) | ||
buf[i++] = '-'; | ||
|
||
while(--i >= 0) | ||
putc(fd, buf[i]); | ||
} | ||
|
||
/* | ||
* printf to the stdout. only understands %d, %x, %p, %s. | ||
*/ | ||
void | ||
printf(int fd, char *fmt, ...) | ||
{ | ||
int i, state = 0, c; | ||
uint *ap = (uint *)(void*)&fmt + 1; | ||
|
||
for(i = 0; fmt[i]; i++){ | ||
c = fmt[i] & 0xff; | ||
if(state == 0){ | ||
if(c == '%'){ | ||
state = '%'; | ||
} else { | ||
putc(fd, c); | ||
} | ||
} else if(state == '%'){ | ||
if(c == 'd'){ | ||
printint(fd, *ap, 10, 1); | ||
ap++; | ||
} else if(c == 'x' || c == 'p'){ | ||
printint(fd, *ap, 16, 0); | ||
ap++; | ||
} else if(c == 's'){ | ||
char *s = (char*)*ap; | ||
ap++; | ||
while(*s != 0){ | ||
putc(fd, *s); | ||
s++; | ||
} | ||
} else if(c == '%'){ | ||
putc(fd, c); | ||
} else { | ||
// Unknown % sequence. Print it to draw attention. | ||
putc(fd, '%'); | ||
putc(fd, c); | ||
} | ||
state = 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,5 @@ | |
#define SYS_exec 13 | ||
#define SYS_open 14 | ||
#define SYS_mknod 15 | ||
#define SYS_unlink 16 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.