00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 #include <sys/kern_descrip.h>
00031 #include <ubixos/types.h>
00032 #include <sys/sysproto.h>
00033 #include <sys/thread.h>
00034 #include <lib/kprintf.h>
00035 #include <ubixos/endtask.h>
00036 #include <lib/kmalloc.h>
00037 #include <assert.h>
00038 
00039 int fcntl(struct thread *td, struct fcntl_args *uap) {
00040   struct file *fp = 0x0;
00041 
00042   #ifdef DEBUG
00043   kprintf("[%s:%i]",__FILE__,__LINE__);
00044   #endif
00045 
00046   if (td->o_files[uap->fd] == 0x0) {
00047     kprintf("ERROR!!!\n");
00048     return(-1);
00049     }
00050 
00051   fp = (struct file *)td->o_files[uap->fd];
00052   switch (uap->cmd) {
00053     case 3:
00054       td->td_retval[0] = fp->f_flag;
00055       break;
00056     case 4:
00057        fp->f_flag &= ~FCNTLFLAGS;
00058        fp->f_flag |= FFLAGS(uap->arg & ~O_ACCMODE) & FCNTLFLAGS;
00059        break;
00060     default:
00061       kprintf("ERROR DEFAULT");
00062     }
00063 
00064   return(0x0);
00065   }
00066 
00067 int falloc(struct thread *td,struct file **resultfp, int *resultfd) {
00068   struct file *fp = 0x0;
00069   int i = 0;
00070 
00071   #ifdef DEBUG
00072   kprintf("[%s:%i]",__FILE__,__LINE__);
00073   #endif
00074 
00075   fp = (struct file *)kmalloc(sizeof(struct file));
00076   
00077   for (i = 5;i<1024;i++) {
00078     if (td->o_files[i] == 0x0) {
00079        td->o_files[i] = (uInt32)fp;
00080        if (resultfd)
00081          *resultfd = i;
00082        if (resultfp)
00083          *resultfp = fp;
00084       break;
00085       }
00086     } 
00087   return(0x0);
00088   }
00089 
00090 int close(struct thread *td,struct close_args *uap) {
00091   #ifdef DEBUG
00092   kprintf("[%s:%i]",__FILE__,__LINE__);
00093   #endif
00094   kfree((void *)td->o_files[uap->fd]);
00095   td->o_files[uap->fd] = 0x0;
00096   td->td_retval[0] = 0x0;  
00097   return(0x0);
00098   }
00099 
00103 int getdtablesize(struct thread *td, struct getdtablesize_args *uap) {
00104   #ifdef DEBUG
00105   kprintf("[%s:%i]",__FILE__,__LINE__);
00106   #endif
00107   td->td_retval[0] = O_FILES;
00108   return (0);
00109   }
00110 
00111 
00112 int fstat(struct thread *td,struct fstat_args *uap) {
00113   struct file *fp = 0x0;
00114 
00115   #ifdef DEBUG
00116   kprintf("[%s:%i]",__FILE__,__LINE__);
00117   #endif
00118 
00119   fp = (struct file *)_current->td.o_files[uap->fd];
00120   uap->sb->st_mode    = 0x2180;
00121   uap->sb->st_blksize = 0x1000;
00122   kprintf("fstat: %i",uap->fd);
00123   return(0x0);
00124   }
00125 
00131 int ioctl(struct thread *td, struct ioctl_args *uap) {
00132   td->td_retval[0] = 0x0;
00133   return(0x0);
00134   }
00135 
00141 int getfd(struct thread *td,struct file **fp,int fd) {
00142   int error = 0x0;
00143 
00144   #ifdef DEBUG
00145   kprintf("[%s:%i]",__FILE__,__LINE__);
00146   #endif
00147 
00148   *fp = (struct file *)td->o_files[fd];
00149 
00150   if (fp == 0x0)
00151     error = -1;
00152 
00153   return(error);
00154   }
00155 
00156 
00157 
00158 
00159