| 1 | /* |
|---|
| 2 | This file is part of MutekP. |
|---|
| 3 | |
|---|
| 4 | MutekP is free software; you can redistribute it and/or modify it |
|---|
| 5 | under the terms of the GNU General Public License as published by |
|---|
| 6 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 7 | (at your option) any later version. |
|---|
| 8 | |
|---|
| 9 | MutekP is distributed in the hope that it will be useful, but |
|---|
| 10 | WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 12 | General Public License for more details. |
|---|
| 13 | |
|---|
| 14 | You should have received a copy of the GNU General Public License |
|---|
| 15 | along with MutekP; if not, write to the Free Software Foundation, |
|---|
| 16 | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 17 | |
|---|
| 18 | UPMC / LIP6 / SOC (c) 2008 |
|---|
| 19 | Copyright Ghassan Almaless <ghassan.almaless@gmail.com> |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | #include <stdint.h> |
|---|
| 23 | #include <vfs.h> |
|---|
| 24 | #include <kminiShell.h> |
|---|
| 25 | #include <errno.h> |
|---|
| 26 | |
|---|
| 27 | static struct vfs_dirent_s dirent ; |
|---|
| 28 | |
|---|
| 29 | void show3(void); |
|---|
| 30 | void show1(void); |
|---|
| 31 | void show2(void); |
|---|
| 32 | |
|---|
| 33 | error_t ls_func(void *param) |
|---|
| 34 | { |
|---|
| 35 | char *path_name; |
|---|
| 36 | error_t err; |
|---|
| 37 | uint32_t argc; |
|---|
| 38 | uint32_t i; |
|---|
| 39 | uint_t count; |
|---|
| 40 | struct vfs_file_s dir; |
|---|
| 41 | struct ku_obj kuo; |
|---|
| 42 | ms_args_t *args; |
|---|
| 43 | // char ch; |
|---|
| 44 | |
|---|
| 45 | args = (ms_args_t *) param; |
|---|
| 46 | err = 0; |
|---|
| 47 | |
|---|
| 48 | if(args->argc == 1) |
|---|
| 49 | { |
|---|
| 50 | argc = 2; |
|---|
| 51 | args->argv[1][0] = '.'; |
|---|
| 52 | args->argv[1][1] = 0; |
|---|
| 53 | } |
|---|
| 54 | else |
|---|
| 55 | argc = args->argc; |
|---|
| 56 | |
|---|
| 57 | for(i=1; i < argc; i++) |
|---|
| 58 | { |
|---|
| 59 | if(argc == 1) |
|---|
| 60 | path_name = "."; |
|---|
| 61 | else |
|---|
| 62 | path_name = args->argv[i]; |
|---|
| 63 | |
|---|
| 64 | #if 0 |
|---|
| 65 | ksh_print("calling vfs for path_name |%s|\n", path_name); |
|---|
| 66 | #endif |
|---|
| 67 | |
|---|
| 68 | KK_BUFF(kuo, path_name); |
|---|
| 69 | if((err=vfs_opendir(ms_n_cwd, &kuo,0,&dir))) |
|---|
| 70 | return err; |
|---|
| 71 | |
|---|
| 72 | ksh_print("Name\t\tType\t\tSize\n", path_name); |
|---|
| 73 | ksh_print("----\t\t----\t\t----\n", path_name); |
|---|
| 74 | count = 0; |
|---|
| 75 | |
|---|
| 76 | KK_OBJ(kuo, &dirent); |
|---|
| 77 | while(!(err=vfs_readdir(&dir,&kuo))) |
|---|
| 78 | { |
|---|
| 79 | count++; |
|---|
| 80 | show3(); |
|---|
| 81 | |
|---|
| 82 | #if 0 |
|---|
| 83 | ch=getChar(); |
|---|
| 84 | |
|---|
| 85 | if(ch == '\n') |
|---|
| 86 | { |
|---|
| 87 | ch=getChar(); |
|---|
| 88 | continue; |
|---|
| 89 | } |
|---|
| 90 | if(ch == 'q') goto LS_END; |
|---|
| 91 | #endif |
|---|
| 92 | } |
|---|
| 93 | ksh_print("\n%d found\n",count); |
|---|
| 94 | // LS_END: |
|---|
| 95 | vfs_closedir(&dir, &count); |
|---|
| 96 | if(err != EEODIR) return err; |
|---|
| 97 | } |
|---|
| 98 | return 0; |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | void show3(void) |
|---|
| 102 | { |
|---|
| 103 | ksh_print("%s\t\t", dirent.d_name); |
|---|
| 104 | |
|---|
| 105 | switch(dirent.d_attr) |
|---|
| 106 | { |
|---|
| 107 | case VFS_DIR: |
|---|
| 108 | ksh_print("<DIR>"); |
|---|
| 109 | break; |
|---|
| 110 | case VFS_FIFO: |
|---|
| 111 | ksh_print("<FIFO>"); |
|---|
| 112 | break; |
|---|
| 113 | case VFS_DEV_BLK: |
|---|
| 114 | ksh_print("<DEV-BLK>"); |
|---|
| 115 | break; |
|---|
| 116 | case VFS_DEV_CHR: |
|---|
| 117 | ksh_print("<DEV-CHR>"); |
|---|
| 118 | break; |
|---|
| 119 | default: |
|---|
| 120 | ksh_print("<RegFile>"); |
|---|
| 121 | } |
|---|
| 122 | ksh_print("\n"); |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | void show1(void) |
|---|
| 126 | { |
|---|
| 127 | ksh_print("=============================\n"); |
|---|
| 128 | ksh_print("Entry name %s\t", dirent.d_name); |
|---|
| 129 | ksh_print("\tType: %s\n", (VFS_IS(dirent.d_attr, VFS_DIR)) ? "<DIR>" : |
|---|
| 130 | (VFS_IS(dirent.d_attr, VFS_FIFO)) ? "FIFO file" : "Reg file"); |
|---|
| 131 | ksh_print("=============================\n"); |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | void show2(void) |
|---|
| 135 | { |
|---|
| 136 | ksh_print("=============================\n"); |
|---|
| 137 | ksh_print("Entry name %s\t\t\t\t", |
|---|
| 138 | dirent.d_name); |
|---|
| 139 | |
|---|
| 140 | ksh_print("\t\tType: %s\n", (VFS_IS(dirent.d_attr, VFS_DIR)) ? "<DIR>" : |
|---|
| 141 | (VFS_IS(dirent.d_attr, VFS_FIFO)) ? "FIFO file" : "Reg file"); |
|---|
| 142 | ksh_print("=============================\n"); |
|---|
| 143 | } |
|---|