- Main Page
- Data Structures
- Files
- Directories

- Search for |

- File List
- Globals

# 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: kern__descrip_8c-source.html 88 2016-01-12 00:11:29Z reddawg $
    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   /* First 5 Descriptors Are Reserved */
    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 /* HACK */
    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  END
    00158  ***/
    00159