Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
0889f006
提交
0889f006
3月 05, 2012
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Parially port xls to Linux
上级
750ed4e1
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
35 行增加
和
22 行删除
+35
-22
xdu.cc
bin/xdu.cc
+0
-1
xls.cc
bin/xls.cc
+35
-21
没有找到文件。
bin/xdu.cc
浏览文件 @
0889f006
#if defined(LINUX)
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
...
...
bin/xls.cc
浏览文件 @
0889f006
#if defined(LINUX)
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#define ST_SIZE(st) (st).st_size
#define ST_TYPE(st) 0
#define ST_INO(st) (st).st_ino
#define ST_ISDIR(st) S_ISDIR((st).st_mode)
#define ST_ISREG(st) S_ISREG((st).st_mode)
#define BSIZ 256
#else // assume xv6
#include "types.h"
#include "stat.h"
#include "user.h"
#include "fs.h"
#define ST_SIZE(st) (st).size
#define ST_TYPE(st) (st).type
#define ST_INO(st) (st).ino
#define ST_ISDIR(st) ((st).type == T_DIR)
#define ST_ISREG(st) ((st).type == T_FILE)
#define BSIZE (DIRSIZ + 1)
#define stderr 2
#endif
const
char
*
fmtname
(
const
char
*
path
)
{
static
char
buf
[
DIRSIZ
+
1
];
static
char
buf
[
BSIZ
];
const
char
*
p
;
// Find first character after last slash.
...
...
@@ -18,10 +37,10 @@ fmtname(const char *path)
p
++
;
// Return blank-padded name.
if
(
strlen
(
p
)
>=
DIRSIZ
)
if
(
strlen
(
p
)
>=
BSIZ
-
1
)
return
p
;
memmove
(
buf
,
p
,
strlen
(
p
));
memset
(
buf
+
strlen
(
p
),
' '
,
DIRSIZ
-
strlen
(
p
));
memset
(
buf
+
strlen
(
p
),
' '
,
BSIZ
-
1
-
strlen
(
p
));
return
buf
;
}
...
...
@@ -34,25 +53,21 @@ ls(const char *path)
struct
stat
st
;
if
((
fd
=
open
(
path
,
0
))
<
0
){
fprintf
(
2
,
"ls: cannot open %s
\n
"
,
path
);
fprintf
(
stderr
,
"ls: cannot open %s
\n
"
,
path
);
return
;
}
if
(
fstat
(
fd
,
&
st
)
<
0
){
fprintf
(
2
,
"ls: cannot stat %s
\n
"
,
path
);
fprintf
(
stderr
,
"ls: cannot stat %s
\n
"
,
path
);
close
(
fd
);
return
;
}
switch
(
st
.
type
){
case
T_FILE
:
fprintf
(
1
,
"%s %d %d %d
\n
"
,
fmtname
(
path
),
st
.
type
,
st
.
ino
,
st
.
size
);
break
;
case
T_DIR
:
if
(
strlen
(
path
)
+
1
+
DIRSIZ
+
1
>
sizeof
buf
){
fprintf
(
1
,
"ls: path too long
\n
"
);
break
;
if
(
ST_ISREG
(
st
))
{
printf
(
"%s %d %d %d
\n
"
,
fmtname
(
path
),
ST_TYPE
(
st
),
ST_INO
(
st
),
ST_SIZE
(
st
));
}
else
if
(
ST_ISDIR
(
st
))
{
if
(
strlen
(
path
)
+
1
+
BSIZ
>
sizeof
buf
)
{
printf
(
"ls: path too long
\n
"
);
}
strcpy
(
buf
,
path
);
p
=
buf
+
strlen
(
buf
);
...
...
@@ -60,15 +75,14 @@ ls(const char *path)
while
(
read
(
fd
,
&
de
,
sizeof
(
de
))
==
sizeof
(
de
)){
if
(
de
.
inum
==
0
)
continue
;
memmove
(
p
,
de
.
name
,
DIRSIZ
);
p
[
DIRSIZ
]
=
0
;
memmove
(
p
,
de
.
name
,
BSIZ
-
1
);
p
[
BSIZ
-
1
]
=
0
;
if
(
stat
(
buf
,
&
st
)
<
0
){
fprintf
(
1
,
"ls: cannot stat %s
\n
"
,
buf
);
printf
(
"ls: cannot stat %s
\n
"
,
buf
);
continue
;
}
fprintf
(
1
,
"%s %d %d %d
\n
"
,
fmtname
(
buf
),
st
.
type
,
st
.
ino
,
st
.
size
);
printf
(
"%s %d %d %d
\n
"
,
fmtname
(
buf
),
ST_TYPE
(
st
),
ST_INO
(
st
),
ST_SIZE
(
st
)
);
}
break
;
}
close
(
fd
);
}
...
...
@@ -80,9 +94,9 @@ main(int argc, char *argv[])
if
(
argc
<
2
){
ls
(
"."
);
exit
()
;
return
0
;
}
for
(
i
=
1
;
i
<
argc
;
i
++
)
ls
(
argv
[
i
]);
exit
()
;
return
0
;
}
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论