XINU
Functions
xsh_ls.c File Reference
#include <xinu.h>
#include <stdio.h>
Include dependency graph for xsh_ls.c:

Go to the source code of this file.

Functions

shellcmd xsh_ls (int nargs, char *args[])
 

Function Documentation

◆ xsh_ls()

shellcmd xsh_ls ( int  nargs,
char *  args[] 
)

Definition at line 10 of file xsh_ls.c.

References fprintf(), ldentry::ld_name, LF_AREA_DIR, Lf_data, lfdata::lf_dir, lfdata::lf_dirpresent, lfdata::lf_dskdev, lfdata::lf_mutex, lfdir::lfd_files, lfdir::lfd_nfiles, lfscheck(), printf(), read(), signal(), stderr, strncmp(), SYSERR, TRUE, and wait().

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 }
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
#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 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
Here is the call graph for this function: