mirror of
https://github.com/SmallPond/MIT6.828_OS.git
synced 2026-04-30 21:59:45 +08:00
my solution to lab5
This commit is contained in:
35
lab/user/lsfd.c
Normal file
35
lab/user/lsfd.c
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <inc/lib.h>
|
||||
|
||||
void
|
||||
usage(void)
|
||||
{
|
||||
cprintf("usage: lsfd [-1]\n");
|
||||
exit();
|
||||
}
|
||||
|
||||
void
|
||||
umain(int argc, char **argv)
|
||||
{
|
||||
int i, usefprint = 0;
|
||||
struct Stat st;
|
||||
struct Argstate args;
|
||||
|
||||
argstart(&argc, argv, &args);
|
||||
while ((i = argnext(&args)) >= 0)
|
||||
if (i == '1')
|
||||
usefprint = 1;
|
||||
else
|
||||
usage();
|
||||
|
||||
for (i = 0; i < 32; i++)
|
||||
if (fstat(i, &st) >= 0) {
|
||||
if (usefprint)
|
||||
fprintf(1, "fd %d: name %s isdir %d size %d dev %s\n",
|
||||
i, st.st_name, st.st_isdir,
|
||||
st.st_size, st.st_dev->dev_name);
|
||||
else
|
||||
cprintf("fd %d: name %s isdir %d size %d dev %s\n",
|
||||
i, st.st_name, st.st_isdir,
|
||||
st.st_size, st.st_dev->dev_name);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user