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.
91 lines
2.2 KiB
91 lines
2.2 KiB
#define __LIBRARY__
|
|
#include <unistd.h>
|
|
#include <stdarg.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
#include <sys/types.h>
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/sched.h>
|
|
#include <asm/segment.h>
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#define BUF_MAX 4096
|
|
#define DIRBUF 8192
|
|
#define NAME_MAX 14
|
|
|
|
struct dirent {
|
|
long d_ino;
|
|
off_t d_off;
|
|
unsigned short d_reclen;
|
|
char d_name[NAME_MAX+1];
|
|
};
|
|
|
|
/*参数count指定该缓冲区的大小*/
|
|
int sys_getdents(unsigned int fd,struct linux_dirent *dirp,unsigned int count)
|
|
{
|
|
if(!count)return -1;/*count is zero*/
|
|
if(fd>=NR_OPEN)return -EINVAL;/*fd is over range*/
|
|
|
|
struct file *file;
|
|
struct m_inode * inode;
|
|
int ret;
|
|
struct buffer_head *hd;
|
|
struct dir_entry *de;
|
|
struct dirent * temp;
|
|
char * buf;
|
|
int desize,ldsize,i,ldi;
|
|
|
|
file=current->filp[fd];
|
|
if(!file)return ENOTDIR;/*the file is not exist or not file*/
|
|
ldsize = sizeof(struct dirent);
|
|
desize = sizeof(struct dir_entry);
|
|
inode = file ->f_inode;
|
|
temp = (struct dirent *)malloc(ldsize);/* //the inter veriable */
|
|
buf = (char*)malloc(ldsize);
|
|
|
|
/*get the inode's bread*/
|
|
hd = bread(inode->i_dev , inode->i_zone[0]);
|
|
|
|
ldi=0;
|
|
ret=0;
|
|
|
|
for (;ret<inode->i_size;ret += desize){
|
|
if (ldi >= count-ldsize)
|
|
break; /* full */
|
|
de = (struct dir_entry *)(hd->b_data + ret);/* de is set to the current dir_entry */
|
|
if (!de -> inode )/* to skip if there is no data in de */
|
|
continue;
|
|
/*To write, copying current dirent, */
|
|
temp->d_ino = de->inode;
|
|
temp->d_off = 0;
|
|
temp->d_reclen = ldsize;
|
|
strcpy(temp->d_name,de->name);
|
|
|
|
|
|
/* by put_fs_byte to write back data to the usr */
|
|
memcpy(buf, temp, ldsize);
|
|
for (i=0;i < ldsize;i++){
|
|
put_fs_byte(*(buf+i), ((char*)dirp)+i+ldi);
|
|
}
|
|
/* memcpy(temp, buf, ldsize); */
|
|
ldi += ldsize;
|
|
}
|
|
return ldi;
|
|
}
|
|
|
|
int sys_execve2(const char * filename, char ** argv, char ** envp)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
long sys_getcwd(char *buf,size_t size)
|
|
{
|
|
return 0;
|
|
}
|
|
int sys_sleep(unsigned int seconds)
|
|
{
|
|
return 0;
|
|
} |