XINU
shell
xsh_ls.c
Go to the documentation of this file.
1
/* xsh_ls.c - xsh_ls */
2
3
#include <
xinu.h
>
4
#include <
stdio.h
>
5
6
/*------------------------------------------------------------------------
7
* xhs_ls - list the contents of the local file system directory
8
*------------------------------------------------------------------------
9
*/
10
shellcmd
xsh_ls
(
int
nargs,
char
*args[])
11
{
12
struct
lfdir
*dirptr;
/* Ptr to in-memory directory */
13
int32
i;
14
struct
ldentry
*ldptr;
/* Ptr to an entry in directory */
15
16
/* For argument '--help', emit help about the 'ls' command */
17
18
if
(nargs == 2 &&
strncmp
(args[1],
"--help"
, 7) == 0) {
19
printf
(
"Use: %s\n\n"
, args[0]);
20
printf
(
"Description:\n"
);
21
printf
(
"\tlists the names of files\n"
);
22
printf
(
"Options:\n"
);
23
printf
(
"\t--help\t display this help and exit\n"
);
24
return
0;
25
}
26
27
if
(nargs != 1) {
28
printf
(
"illegal option: try --help for more information\n"
);
29
return
1;
30
}
31
32
/* Obtain copy of directory if not already present in memory */
33
34
dirptr = &
Lf_data
.
lf_dir
;
35
wait
(
Lf_data
.
lf_mutex
);
36
if
(!
Lf_data
.
lf_dirpresent
) {
37
if
(
read
(
Lf_data
.
lf_dskdev
, (
char
*)dirptr,
LF_AREA_DIR
) ==
SYSERR
) {
38
signal
(
Lf_data
.
lf_mutex
);
39
fprintf
(
stderr
,
"cannot read the directory\n"
);
40
}
41
if
(
lfscheck
(dirptr) ==
SYSERR
) {
42
fprintf
(
stderr
,
"THe disk does not contain a Xinu file system\n"
);
43
signal
(
Lf_data
.
lf_mutex
);
44
return
1;
45
}
46
Lf_data
.
lf_dirpresent
=
TRUE
;
47
}
48
signal
(
Lf_data
.
lf_mutex
);
49
50
/* Search directory and list the file names */
51
52
for
(i=0; i<dirptr->
lfd_nfiles
; i++) {
53
ldptr = &dirptr->
lfd_files
[i];
54
printf
(
"%s\n"
, ldptr->
ld_name
);
55
}
56
return
0;
57
}
lfdir::lfd_files
struct ldentry lfd_files[LF_NUM_DIR_ENT]
Definition:
lfilesys.h:123
strncmp
int32 strncmp(const char *, const char *, int32)
lfdata::lf_mutex
sid32 lf_mutex
Definition:
lfilesys.h:132
xinu.h
全てのシステムヘッダファイルをインクルードする。
SYSERR
#define SYSERR
処理が失敗した場合
Definition:
kernel.h:79
Lf_data
struct lfdata Lf_data
Definition:
lfsinit.c:5
stderr
#define stderr
Definition:
stdio.h:17
read
syscall read(did32, char *, uint32)
Definition:
read.c:9
lfdata::lf_dskdev
did32 lf_dskdev
Definition:
lfilesys.h:131
lfdir
Definition:
lfilesys.h:114
printf
int32 printf(const char *,...)
Definition:
printf.c:13
lfdata::lf_dirpresent
bool8 lf_dirpresent
Definition:
lfilesys.h:135
xsh_ls
shellcmd xsh_ls(int nargs, char *args[])
Definition:
xsh_ls.c:10
LF_AREA_DIR
#define LF_AREA_DIR
Definition:
lfilesys.h:67
lfdata::lf_dir
struct lfdir lf_dir
Definition:
lfilesys.h:134
ldentry::ld_name
char ld_name[LF_NAME_LEN]
Definition:
lfilesys.h:101
TRUE
#define TRUE
Boolean True(1)
Definition:
kernel.h:65
ldentry
Definition:
lfilesys.h:96
int32
int int32
符号あり32ビット整数(int)
Definition:
kernel.h:11
lfdir::lfd_nfiles
int32 lfd_nfiles
Definition:
lfilesys.h:122
stdio.h
shellcmd
int32 shellcmd
シェルコール関数 返り値の型
Definition:
kernel.h:51
fprintf
int32 fprintf(int, char *,...)
Definition:
fprintf.c:14
wait
syscall wait(sid32)
Definition:
wait.c:9
signal
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition:
signal.c:18
lfscheck
status lfscheck(struct lfdir *)
Definition:
lfscheck.c:10
Generated by
1.8.13