vfs: add the readdir stuff support
[profile/ivi/syslinux.git] / core / dir.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <sys/dirent.h>
4 #include <fs.h>
5 #include <core.h>
6
7 extern struct fs_info *this_fs;
8
9 /* 
10  * open dir, return the file structure pointer in _eax_, or NULL if failed 
11  */
12 void opendir(com32sys_t *regs)
13 {
14     char *src = MK_PTR(regs->es, regs->esi.w[0]);
15     char *dst = MK_PTR(regs->ds, regs->edi.w[0]);
16     strcpy(dst, src);
17     searchdir(regs);
18     regs->eax.l = (uint32_t)handle_to_file(regs->esi.w[0]);     
19 }
20
21 /*
22  * Read one dirent at one time. 
23  *
24  * @input: _esi_ register stores the address of DIR structure
25  * @output: _eax_ register stores the address of newly read dirent structure
26  */
27 void readdir(com32sys_t *regs)
28 {
29     DIR *dir = (DIR *)regs->esi.l;      
30     struct dirent *de = NULL;
31     
32     if (dir->dd_dir)
33         de = this_fs->fs_ops->readdir(dir->dd_dir);
34     else
35         de = NULL;
36     
37     /* Return the newly read de in _eax_ register */
38     regs->eax.l = (uint32_t)de;
39 }
40
41 void closedir(com32sys_t *regs)
42 {
43     DIR *dir = (DIR *)regs->esi.l;
44     _close_file(dir->dd_dir);
45 }
46
47