Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
3d00ccd2
提交
3d00ccd2
3月 05, 2012
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rejigger xls
上级
0889f006
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
17 行增加
和
30 行删除
+17
-30
xls.cc
bin/xls.cc
+17
-30
没有找到文件。
bin/xls.cc
浏览文件 @
3d00ccd2
...
...
@@ -5,8 +5,9 @@
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include "user/dirit.hh"
#define ST_SIZE(st) (st).st_size
#define ST_TYPE(st)
0
#define ST_TYPE(st)
(ST_ISDIR(st) ? 1 : ST_ISREG(st) ? 2 : 3)
#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)
...
...
@@ -16,40 +17,22 @@
#include "stat.h"
#include "user.h"
#include "fs.h"
#include "lib.h"
#include "dirit.hh"
#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 BSIZ
E
(DIRSIZ + 1)
#define BSIZ (DIRSIZ + 1)
#define stderr 2
#endif
const
char
*
fmtname
(
const
char
*
path
)
{
static
char
buf
[
BSIZ
];
const
char
*
p
;
// Find first character after last slash.
for
(
p
=
path
+
strlen
(
path
);
p
>=
path
&&
*
p
!=
'/'
;
p
--
)
;
p
++
;
// Return blank-padded name.
if
(
strlen
(
p
)
>=
BSIZ
-
1
)
return
p
;
memmove
(
buf
,
p
,
strlen
(
p
));
memset
(
buf
+
strlen
(
p
),
' '
,
BSIZ
-
1
-
strlen
(
p
));
return
buf
;
}
void
ls
(
const
char
*
path
)
{
char
buf
[
512
],
*
p
;
int
fd
;
struct
dirent
de
;
struct
stat
st
;
if
((
fd
=
open
(
path
,
0
))
<
0
){
...
...
@@ -64,7 +47,7 @@ ls(const char *path)
}
if
(
ST_ISREG
(
st
))
{
printf
(
"%
s %d %d %d
\n
"
,
fmtname
(
path
),
ST_TYPE
(
st
),
ST_INO
(
st
),
ST_SIZE
(
st
)
);
printf
(
"%
u %10lu %10lu %s
\n
"
,
ST_TYPE
(
st
),
ST_INO
(
st
),
ST_SIZE
(
st
),
path
);
}
else
if
(
ST_ISDIR
(
st
))
{
if
(
strlen
(
path
)
+
1
+
BSIZ
>
sizeof
buf
)
{
printf
(
"ls: path too long
\n
"
);
...
...
@@ -72,16 +55,20 @@ ls(const char *path)
strcpy
(
buf
,
path
);
p
=
buf
+
strlen
(
buf
);
*
p
++
=
'/'
;
while
(
read
(
fd
,
&
de
,
sizeof
(
de
))
==
sizeof
(
de
)){
if
(
de
.
inum
==
0
)
continue
;
memmove
(
p
,
de
.
name
,
BSIZ
-
1
);
p
[
BSIZ
-
1
]
=
0
;
if
(
stat
(
buf
,
&
st
)
<
0
){
dirit
di
(
fd
);
for
(;
!
di
.
end
();
++
di
)
{
const
char
*
name
=
*
di
;
size_t
len
=
strlen
(
name
);
memmove
(
p
,
name
,
len
);
p
[
len
]
=
0
;
if
(
stat
(
buf
,
&
st
)
<
0
){
free
((
void
*
)
name
);
printf
(
"ls: cannot stat %s
\n
"
,
buf
);
continue
;
}
printf
(
"%s %d %d %d
\n
"
,
fmtname
(
buf
),
ST_TYPE
(
st
),
ST_INO
(
st
),
ST_SIZE
(
st
));
printf
(
"%u %10lu %10lu %s
\n
"
,
ST_TYPE
(
st
),
ST_INO
(
st
),
ST_SIZE
(
st
),
name
);
free
((
void
*
)
name
);
}
}
close
(
fd
);
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论