You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.2 KiB
46 lines
1.2 KiB
3 years ago
|
#define __LIBRARY__
|
||
|
#include <unistd.h>
|
||
|
#include <fcntl.h>
|
||
|
#include <sys/types.h>
|
||
|
#include <string.h>
|
||
|
#include <asm/segment.h>
|
||
|
#include <linux/sched.h>
|
||
|
#include <linux/kernel.h>
|
||
|
struct linux_dirent {
|
||
|
long d_ino;
|
||
|
off_t d_off;
|
||
|
unsigned short d_reclen;
|
||
|
char d_name[14];
|
||
|
};
|
||
|
|
||
|
int sys_getdents(unsigned int fd, struct linux_dirent *dirp, unsigned int count)
|
||
|
{
|
||
|
struct m_inode *m_ino;
|
||
|
struct buffer_head *buff_hd;
|
||
|
struct dir_entry *dir;
|
||
|
struct linux_dirent usr;
|
||
|
int i, j, res;
|
||
|
i = 0;
|
||
|
res = 0;
|
||
|
m_ino = current->filp[fd]->f_inode;
|
||
|
buff_hd = bread(m_ino->i_dev, m_ino->i_zone[0]);
|
||
|
dir = (struct dir_entry *)buff_hd->b_data;
|
||
|
while (dir[i].inode > 0)
|
||
|
{
|
||
|
if (res + sizeof(struct linux_dirent) > count)
|
||
|
break;
|
||
|
usr.d_ino = dir[i].inode;
|
||
|
usr.d_off = 0;
|
||
|
usr.d_reclen = sizeof(struct linux_dirent);
|
||
|
for (j = 0; j < 14; j++)
|
||
|
{
|
||
|
usr.d_name[j] = dir[i].name[j];
|
||
|
}
|
||
|
for(j = 0;j <sizeof(struct linux_dirent); j++){
|
||
|
put_fs_byte(((char *)(&usr))[j],(char *)dirp + res);
|
||
|
res++;
|
||
|
}
|
||
|
i++;
|
||
|
}
|
||
|
return res;
|
||
|
}
|