kern_descrip.c

Go to the documentation of this file.
00001 /*****************************************************************************************
00002  Copyright (c) 2002-2004 The UbixOS Project
00003  All rights reserved.
00004 
00005  Redistribution and use in source and binary forms, with or without modification, are
00006  permitted provided that the following conditions are met:
00007 
00008  Redistributions of source code must retain the above copyright notice, this list of
00009  conditions, the following disclaimer and the list of authors.  Redistributions in binary
00010  form must reproduce the above copyright notice, this list of conditions, the following
00011  disclaimer and the list of authors in the documentation and/or other materials provided
00012  with the distribution. Neither the name of the UbixOS Project nor the names of its
00013  contributors may be used to endorse or promote products derived from this software
00014  without specific prior written permission.
00015 
00016  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
00017  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00018  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
00019  THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00020  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00021  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00022  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
00023  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00024  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025 
00026  $Id$
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   if (td->o_files[uap->fd] == 0x0) {
00043     kprintf("ERROR!!!\n");
00044     return(-1);
00045     }
00046 
00047   fp = (struct file *)td->o_files[uap->fd];
00048   switch (uap->cmd) {
00049     case 3:
00050       td->td_retval[0] = fp->f_flag;
00051       break;
00052     case 4:
00053        fp->f_flag &= ~FCNTLFLAGS;
00054        fp->f_flag |= FFLAGS(uap->arg & ~O_ACCMODE) & FCNTLFLAGS;
00055        break;
00056     default:
00057       kprintf("ERROR DEFAULT");
00058     }
00059 
00060   return(0x0);
00061   }
00062 
00063 int falloc(struct thread *td,struct file **resultfp, int *resultfd) {
00064   struct file *fp = 0x0;
00065   int i = 0;
00066 
00067   fp = (struct file *)kmalloc(sizeof(struct file));
00068   /* First 5 Descriptors Are Reserved */
00069   for (i = 5;i<1024;i++) {
00070     if (td->o_files[i] == 0x0) {
00071        td->o_files[i] = (uInt32)fp;
00072        if (resultfd)
00073          *resultfd = i;
00074        if (resultfp)
00075          *resultfp = fp;
00076       break;
00077       }
00078     } 
00079   return(0x0);
00080   }
00081 
00082 int close(struct thread *td,struct close_args *uap) {
00083   kfree((void *)td->o_files[uap->fd]);
00084   td->o_files[uap->fd] = 0x0;
00085   td->td_retval[0] = 0x0;  
00086   return(0x0);
00087   }
00088 
00089   /* HACK */
00090 int getdtablesize(struct thread *td, struct getdtablesize_args *uap) {
00091   td->td_retval[0] = 20;
00092   return (0);
00093   }
00094 
00095 /* HACK */
00096 int fstat(struct thread *td,struct fstat_args *uap) {
00097   struct file *fp = 0x0;
00098 
00099   fp = _current->td.o_files[uap->fd];
00100   uap->sb->st_mode    = 0x2180;
00101   uap->sb->st_blksize = 0x1000;
00102   return(0x0);
00103   }
00104 
00108 int ioctl(struct thread *td, struct ioctl_args *uap) {
00109   td->td_retval[0] = 0x0;
00110   return(0x0);
00111   }
00112 
00113 
00114 
00115 /***
00116  END
00117  ***/
00118 

Generated on Tue Dec 5 11:01:15 2006 for UbixOS V2 by  doxygen 1.4.7