XINU
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;
36  if (! Lf_data.lf_dirpresent) {
37  if (read(Lf_data.lf_dskdev, (char *)dirptr, LF_AREA_DIR) == SYSERR ) {
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");
44  return 1;
45  }
47  }
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 }
struct ldentry lfd_files[LF_NUM_DIR_ENT]
Definition: lfilesys.h:123
int32 strncmp(const char *, const char *, int32)
sid32 lf_mutex
Definition: lfilesys.h:132
全てのシステムヘッダファイルをインクルードする。
#define SYSERR
処理が失敗した場合
Definition: kernel.h:79
struct lfdata Lf_data
Definition: lfsinit.c:5
#define stderr
Definition: stdio.h:17
syscall read(did32, char *, uint32)
Definition: read.c:9
did32 lf_dskdev
Definition: lfilesys.h:131
int32 printf(const char *,...)
Definition: printf.c:13
bool8 lf_dirpresent
Definition: lfilesys.h:135
shellcmd xsh_ls(int nargs, char *args[])
Definition: xsh_ls.c:10
#define LF_AREA_DIR
Definition: lfilesys.h:67
struct lfdir lf_dir
Definition: lfilesys.h:134
char ld_name[LF_NAME_LEN]
Definition: lfilesys.h:101
#define TRUE
Boolean True(1)
Definition: kernel.h:65
int int32
符号あり32ビット整数(int)
Definition: kernel.h:11
int32 lfd_nfiles
Definition: lfilesys.h:122
int32 shellcmd
シェルコール関数 返り値の型
Definition: kernel.h:51
int32 fprintf(int, char *,...)
Definition: fprintf.c:14
syscall wait(sid32)
Definition: wait.c:9
syscall signal(sid32)
セマフォにシグナルを送り、待機プロセスがある場合は解除する。
Definition: signal.c:18
status lfscheck(struct lfdir *)
Definition: lfscheck.c:10