|
|
|
|
#define __LIBRARY__
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
|
#include <linux/sched.h>
|
|
|
|
|
#include <asm/segment.h>
|
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
|
|
#define BUF_MAX 128
|
|
|
|
|
#define DIRBUF 8192
|
|
|
|
|
#define NAME_MAX 14
|
|
|
|
|
|
|
|
|
|
struct dirent { /* Ŀ¼<C4BF><C2BC>ṹ<EFBFBD><E1B9B9> */
|
|
|
|
|
long d_ino; /* i<>ڵ<EFBFBD> */
|
|
|
|
|
off_t d_off; /* λ<><CEBB> */
|
|
|
|
|
unsigned short d_reclen; /* <20>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
char d_name[NAME_MAX + 1]; /* <20>ļ<EFBFBD><C4BC><EFBFBD> */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int sys_getdents(unsigned int fd, struct dirent* dirp, unsigned int count) {
|
|
|
|
|
struct file* file;
|
|
|
|
|
struct m_inode* inode;
|
|
|
|
|
struct buffer_head* head;
|
|
|
|
|
struct dir_entry* de_tmp;
|
|
|
|
|
struct dirent* self_tmp; /* ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD>ṹ<EFBFBD><E1B9B9><EFBFBD><EFBFBD><EFBFBD>ʱָ<CAB1><D6B8> */
|
|
|
|
|
char* buf;
|
|
|
|
|
int dir_size, dire_size, read_bytes, addr_off, i;
|
|
|
|
|
|
|
|
|
|
dir_size = sizeof(struct dirent); /* <20><>ǰĿ¼<C4BF>ṹ<EFBFBD><E1B9B9>Ĵ<EFBFBD>С */
|
|
|
|
|
dire_size = sizeof(struct dir_entry); /* Ŀ¼<C4BF><C2BC>ṹ<EFBFBD><E1B9B9>Ĵ<EFBFBD>С */
|
|
|
|
|
|
|
|
|
|
self_tmp = (struct dirent*)malloc(dir_size); /* <20>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD>ʼ<EFBFBD>ռ<EFBFBD> */
|
|
|
|
|
buf = (char*)malloc(dir_size);
|
|
|
|
|
|
|
|
|
|
file = current->filp[fd]; /* <20><>ȡ<EFBFBD><C8A1>ǰĿ¼<C4BF><C2BC><EFBFBD><EFBFBD>Ϣ */
|
|
|
|
|
inode = file->f_inode;
|
|
|
|
|
head = bread(inode->i_dev, inode->i_zone[0]);
|
|
|
|
|
|
|
|
|
|
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>dirpΪ<70><CEAA><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>read_bytes<65>洢<EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD> */
|
|
|
|
|
read_bytes = 0;
|
|
|
|
|
for (addr_off = 0; addr_off < inode->i_size; addr_off += dire_size) { /* <20>ӵ<EFBFBD>ǰĿ¼<C4BF><C2BC><EFBFBD><EFBFBD>ڿ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ȡÿһ<C3BF><D2BB>Ŀ¼<C4BF><C2BC>Ļ<EFBFBD><C4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
|
|
|
|
if (read_bytes >= count - dir_size) /* <20><><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD>˳<EFBFBD>ѭ<EFBFBD><D1AD> */
|
|
|
|
|
break;
|
|
|
|
|
de_tmp = (struct dir_entry*)(head->b_data + addr_off); /* deָ<65><D6B8>Ŀ¼<C4BF><EFBFBD><EEBBBA><EFBFBD><EFBFBD><EFBFBD>Ľṹ<C4BD><E1B9B9> */
|
|
|
|
|
if (!de_tmp->inode) /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<C4BF><EFBFBD><EEA3AC><EFBFBD><EFBFBD> */
|
|
|
|
|
continue;
|
|
|
|
|
self_tmp->d_ino = de_tmp->inode; /* Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>deָ<65><D6B8>Ľṹ<C4BD><E1B9B9><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD><C7BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱָ<CAB1><D6B8>self_tmpָ<70><D6B8>Ľṹ<C4BD><E1B9B9><EFBFBD><EFBFBD> */
|
|
|
|
|
self_tmp->d_off = 0;
|
|
|
|
|
self_tmp->d_reclen = dir_size;
|
|
|
|
|
strcpy(self_tmp->d_name, de_tmp->name);
|
|
|
|
|
memcpy(buf, self_tmp, dir_size); /* <20>Ѹն<D1B8><D5B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>buf<75><66><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD> */
|
|
|
|
|
for (i = 0; i < dir_size; i++) /* <20><><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ֽڵؿ<DAB5><D8BF><EFBFBD><EFBFBD><EFBFBD>dirp<72><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ */
|
|
|
|
|
put_fs_byte(*(buf + i), ((char*)dirp) + i + read_bytes);
|
|
|
|
|
read_bytes += dir_size;
|
|
|
|
|
}
|
|
|
|
|
return read_bytes;
|
|
|
|
|
}
|