3 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@zexos.org)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 static vfs_dirent_t
*getdir (const char *path
)
31 char *cwd
= getcwd (0, 0);
42 : "=g" (d
) :: "%eax");
51 DIR *opendir (const char *name
)
58 vfs_dirent_t
*ent
= getdir (name
);
65 DIR *dir
= (DIR *) malloc (sizeof (DIR));
72 unsigned l
= strlen (name
);
77 memcpy (dir
->name
, name
, l
);
82 /* count entries in dir structure */
83 for (id
= 0; ent
[id
].next
; id
++);
87 dir
->entry
= (struct dirent
*) malloc (sizeof (struct dirent
) * (m
+ 1));
95 /* create entires as dirents */
96 for (id
= 0; id
< m
; id
++) {
97 dir
->entry
[id
].d_ino
= 0; /* TODO */
98 dir
->entry
[id
].d_off
= id
* sizeof (struct dirent
);
99 dir
->entry
[id
].d_reclen
= sizeof (struct dirent
);
104 l
= strlen (ent
[id
].name
);
109 memcpy (dir
->entry
[id
].d_name
, ent
[id
].name
, l
);
110 dir
->entry
[id
].d_name
[l
] = '\0';
113 /* create last entry as eof */
114 dir
->entry
[m
].d_ino
= -1;
115 dir
->entry
[m
].d_off
= m
* sizeof (struct dirent
);
116 dir
->entry
[m
].d_reclen
= 0;
117 dir
->entry
[m
].d_name
[0] = '\0';