dirinfo command
This commit is contained in:
		
							parent
							
								
									44d29a33df
								
							
						
					
					
						commit
						20853582d5
					
				
					 7 changed files with 104 additions and 22 deletions
				
			
		
							
								
								
									
										19
									
								
								doc/ints.txt
									
										
									
									
									
								
							
							
						
						
									
										19
									
								
								doc/ints.txt
									
										
									
									
									
								
							|  | @ -25,7 +25,7 @@ invalid system call numbers change eax to -1, and have no other effect. | ||||||
| table 1: | table 1: | ||||||
| 
 | 
 | ||||||
|  function      | eax | eax out       | ebx           | ecx         | edx         | esi    | edi |  function      | eax | eax out       | ebx           | ecx         | edx         | esi    | edi | ||||||
| ---------------|-----|---------------|---------------|-------------|-----------|--------|----- | ---------------|-----|---------------|---------------|-------------|-------------|--------|----- | ||||||
|  open file     | 0x0 | handle        | drive number  | path        |             |        | |  open file     | 0x0 | handle        | drive number  | path        |             |        | | ||||||
|  close file    | 0x1 |               | handle        |             |             |        | |  close file    | 0x1 |               | handle        |             |             |        | | ||||||
|  file read     | 0x2 | read          | handle        | file offset | count       | buffer | |  file read     | 0x2 | read          | handle        | file offset | count       | buffer | | ||||||
|  | @ -36,8 +36,7 @@ table 1: | ||||||
|  allocate ram  | 0x7 | start pointer | pages         |             |             |        | |  allocate ram  | 0x7 | start pointer | pages         |             |             |        | | ||||||
|  memory info   | 0x8 | see table 2   | see table 2   |             |             |        | |  memory info   | 0x8 | see table 2   | see table 2   |             |             |        | | ||||||
|  wait for task | 0x9 |               | handle        |             |             |        | |  wait for task | 0x9 |               | handle        |             |             |        | | ||||||
| 
 |  enumerate dir | 0xa | count         | drive number  | path        | see table 3 | max    | | ||||||
| 
 |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| table 2: | table 2: | ||||||
|  | @ -51,3 +50,17 @@ eax -1 indicates unrecognized ebx | ||||||
|  0x2 | total userspace size |  0x2 | total userspace size | ||||||
|  0x3 | total userspace left |  0x3 | total userspace left | ||||||
|  0x4 | this process memory left |  0x4 | this process memory left | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | table 3: | ||||||
|  | edx of "enumerate dir" is a pointer to a buffer where an array of "directory info"s can be put. | ||||||
|  | esi is the maximum number of "directory info"s to be placed in the buffer. | ||||||
|  | the "directory info" structure is defined as follows: | ||||||
|  |   struct { | ||||||
|  |     bool is_dir; | ||||||
|  |     char name[100]; | ||||||
|  |     uint32_t size; | ||||||
|  |   } | ||||||
|  | "is_dir" here indicates whether or not the entry is another directory. | ||||||
|  | "name" is a null-terminated string, up to 99 characters, indicating the name of the entry. | ||||||
|  | "size" is the size of the file this entry refers to, in bytes. | ||||||
							
								
								
									
										6
									
								
								makefile
									
										
									
									
									
								
							
							
						
						
									
										6
									
								
								makefile
									
										
									
									
									
								
							|  | @ -29,7 +29,8 @@ out/fs/bin/%: obj/%.elf | ||||||
| 	objcopy -S $< $@ | 	objcopy -S $< $@ | ||||||
| 
 | 
 | ||||||
| out/fs: out/fs/bin/init    out/fs/bin/meminfo  out/fs/bin/highway \ | out/fs: out/fs/bin/init    out/fs/bin/meminfo  out/fs/bin/highway \ | ||||||
|         out/fs/bin/hello out/fs/bin/dumptext out/fs/bin/dumphex |         out/fs/bin/hello   out/fs/bin/dumptext out/fs/bin/dumphex \
 | ||||||
|  |         out/fs/bin/dirinfo | ||||||
| 	mkdir -p out/fs | 	mkdir -p out/fs | ||||||
| 	cp -r fs-skel/* out/fs/ | 	cp -r fs-skel/* out/fs/ | ||||||
| 
 | 
 | ||||||
|  | @ -86,3 +87,6 @@ obj/dumptext.elf: obj/dumptext/dumptext.o obj/knob.so | ||||||
| 
 | 
 | ||||||
| obj/dumphex.elf: obj/dumphex/dumphex.o obj/knob.so | obj/dumphex.elf: obj/dumphex/dumphex.o obj/knob.so | ||||||
| 	ld -T src/user/elf.ld obj/dumphex/* obj/knob.so -o obj/dumphex.elf | 	ld -T src/user/elf.ld obj/dumphex/* obj/knob.so -o obj/dumphex.elf | ||||||
|  | 
 | ||||||
|  | obj/dirinfo.elf: obj/dirinfo/dirinfo.o obj/knob.so | ||||||
|  | 	ld -T src/user/elf.ld obj/dirinfo/* obj/knob.so -o obj/dirinfo.elf | ||||||
|  | @ -96,6 +96,10 @@ static void sc_wait_for_task(uint32_t handle) { | ||||||
|   active_task->wait_arg = handle; |   active_task->wait_arg = handle; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | static uint32_t sc_enumerate_dir(uint32_t drive_number, const char *path, struct directory_content_info *buffer, uint32_t max_entries) { | ||||||
|  |   return drives[drive_number].enumerate_dir(drives + drive_number, path, buffer, max_entries); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void const *syscall_table[] = { | void const *syscall_table[] = { | ||||||
|   &sc_open_file, |   &sc_open_file, | ||||||
|   &sc_close_file, |   &sc_close_file, | ||||||
|  | @ -106,7 +110,8 @@ void const *syscall_table[] = { | ||||||
|   &get_key_code, |   &get_key_code, | ||||||
|   &sc_allocate_ram, |   &sc_allocate_ram, | ||||||
|   &sc_memory_info, |   &sc_memory_info, | ||||||
|   &sc_wait_for_task |   &sc_wait_for_task, | ||||||
|  |   &sc_enumerate_dir | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| //these aren't really void ()'s, but gcc complains if we take an address of a void, so we give it a type
 | //these aren't really void ()'s, but gcc complains if we take an address of a void, so we give it a type
 | ||||||
|  |  | ||||||
|  | @ -23,7 +23,7 @@ extern on_kbd_isr | ||||||
| extern make_sure_tasks | extern make_sure_tasks | ||||||
| extern exception_halt | extern exception_halt | ||||||
| 
 | 
 | ||||||
| n_syscalls equ 0xa | n_syscalls equ 0xb | ||||||
| 
 | 
 | ||||||
| ;section .bss | ;section .bss | ||||||
| ;_debug_is_start_task resb 1 | ;_debug_is_start_task resb 1 | ||||||
|  |  | ||||||
							
								
								
									
										49
									
								
								src/user/dirinfo/dirinfo.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								src/user/dirinfo/dirinfo.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,49 @@ | ||||||
|  | #include <pland/syscall.h> | ||||||
|  | #include <knob/format.h> | ||||||
|  | #include <knob/file.h> | ||||||
|  | #include <knob/user.h> | ||||||
|  | 
 | ||||||
|  | #define MAX_DIR_ENTRIES 20 | ||||||
|  | 
 | ||||||
|  | void main(const char *arg) { | ||||||
|  |   uint8_t dn; | ||||||
|  |   const char *path = remove_prefix(arg, &dn); | ||||||
|  | 
 | ||||||
|  |   tell_user_sz("Directory info for "); | ||||||
|  |   tell_user_sz(*arg ? arg : "drive root"); | ||||||
|  |   tell_user_sz("\n"); | ||||||
|  | 
 | ||||||
|  |   _dir_info_entry infos[MAX_DIR_ENTRIES]; | ||||||
|  |   uint8_t count = _enumerate_dir(dn, path, infos, MAX_DIR_ENTRIES); | ||||||
|  |   tell_user_sz( | ||||||
|  |     count == MAX_DIR_ENTRIES | ||||||
|  |     ? "Truncated to 20 entries.\n\n" | ||||||
|  |     : "\n" | ||||||
|  |   ); | ||||||
|  | 
 | ||||||
|  |   uint32_t total_size = 0; | ||||||
|  | 
 | ||||||
|  |   if (!count) | ||||||
|  |     tell_user_sz("(none)\n"); | ||||||
|  | 
 | ||||||
|  |   for (uint8_t i = 0; i < count; ++i) { | ||||||
|  |     tell_user_sz(infos[i].name); | ||||||
|  |     tell_user_sz(": "); | ||||||
|  |     if (infos[i].is_dir) | ||||||
|  |       tell_user_sz("dir"); | ||||||
|  |     else { | ||||||
|  |       char nbuf[11]; | ||||||
|  |       itosz(infos[i].size, nbuf); | ||||||
|  |       tell_user_sz(nbuf); | ||||||
|  |       tell_user_sz(" bytes"); | ||||||
|  |       total_size += infos[i].size; | ||||||
|  |     } | ||||||
|  |     tell_user_sz("\n"); | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   tell_user_sz("\nTotal size without subdirectories: "); | ||||||
|  |   char nbuf[11]; | ||||||
|  |   itosz(total_size, nbuf); | ||||||
|  |   tell_user_sz(nbuf); | ||||||
|  |   tell_user_sz(" bytes\n"); | ||||||
|  | } | ||||||
|  | @ -45,9 +45,16 @@ enum _scn { | ||||||
|   _SCN_GET_KEY, |   _SCN_GET_KEY, | ||||||
|   _SCN_ALLOCATE_RAM, |   _SCN_ALLOCATE_RAM, | ||||||
|   _SCN_MEMORY_INFO, |   _SCN_MEMORY_INFO, | ||||||
|   _SCN_WAIT_FOR_TASK |   _SCN_WAIT_FOR_TASK, | ||||||
|  |   _SCN_ENUMERATE_DIR | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | typedef struct { | ||||||
|  |   bool is_dir; | ||||||
|  |   char name[100]; | ||||||
|  |   uint32_t size; | ||||||
|  | } _dir_info_entry; | ||||||
|  | 
 | ||||||
| static inline uint32_t _sc0(enum _scn eax) { | static inline uint32_t _sc0(enum _scn eax) { | ||||||
|   volatile uint32_t out; |   volatile uint32_t out; | ||||||
|   asm ( |   asm ( | ||||||
|  | @ -166,4 +173,8 @@ static inline void _wait_for_task(_process_handle_t handle) { | ||||||
|   _sc1(_SCN_WAIT_FOR_TASK, handle); |   _sc1(_SCN_WAIT_FOR_TASK, handle); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | static inline uint32_t _enumerate_dir(_drive_number_t drive_number, const char *path, _dir_info_entry *buffer, uint32_t max_count) { | ||||||
|  |   return _sc4(_SCN_ENUMERATE_DIR, drive_number, (uint32_t)path, (uint32_t)buffer, max_count); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| #endif | #endif | ||||||
|  | @ -19,5 +19,5 @@ _entry: | ||||||
|   jmp main |   jmp main | ||||||
| 
 | 
 | ||||||
| section .stack nobits alloc noexec write align=16 | section .stack nobits alloc noexec write align=16 | ||||||
| resb 1024 | resb 4096 | ||||||
| stack: | stack: | ||||||
		Reference in a new issue