Welcome to The Fiwix Project
A UNIX-like kernel for the i386 architecture
1 /* 2 * fiwix/kernel/syscalls/getdents.c 3 * 4 * Copyright 2018, Jordi Sanfeliu. All rights reserved. 5 * Distributed under the terms of the Fiwix License. 6 */ 7 8 #include <fiwix/fs.h> 9 #include <fiwix/dirent.h> 10 #include <fiwix/process.h> 11 #include <fiwix/stat.h> 12 #include <fiwix/errno.h> 13 14 #ifdef __DEBUG__ 15 #include <fiwix/stdio.h> 16 #endif /*__DEBUG__ */ 17 18 int sys_getdents(unsigned int ufd, struct dirent *dirent, unsigned int count) 19 { 20 struct inode *i; 21 int errno; 22 23 #ifdef __DEBUG__ 24 printk("(pid %d) sys_getdents(%d, 0x%08x, %d)", current->pid, ufd, (unsigned int)dirent, count); 25 #endif /*__DEBUG__ */ 26 27 CHECK_UFD(ufd); 28 if((errno = check_user_area(VERIFY_WRITE, dirent, sizeof(struct dirent)))) { 29 return errno; 30 } 31 i = fd_table[current->fd[ufd]].inode; 32 33 if(!S_ISDIR(i->i_mode)) { 34 return -ENOTDIR; 35 } 36 37 if(i->fsop && i->fsop->readdir) { 38 errno = i->fsop->readdir(i, &fd_table[current->fd[ufd]], dirent, count); 39 #ifdef __DEBUG__ 40 printk(" -> returning %d\n", errno); 41 #endif /*__DEBUG__ */ 42 return errno; 43 } 44 return -EINVAL; 45 }