home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / gnu / ixemul-39.47-env-bin.lha / include / sys / file.h < prev    next >
C/C++ Source or Header  |  1994-07-08  |  5KB  |  139 lines

  1. /*
  2.  *  This file is part of ixemul.library for the Amiga.
  3.  *  Copyright (C) 1991, 1992  Markus M. Wild
  4.  *  Portions Copyright (C) 1994 Rafael W. Luebbert
  5.  *
  6.  *  This library is free software; you can redistribute it and/or
  7.  *  modify it under the terms of the GNU Library General Public
  8.  *  License as published by the Free Software Foundation; either
  9.  *  version 2 of the License, or (at your option) any later version.
  10.  *
  11.  *  This library is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  *  Library General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU Library General Public
  17.  *  License along with this library; if not, write to the Free
  18.  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21. #ifndef _SYS_FILE_H
  22. #define _SYS_FILE_H
  23.  
  24. #include <sys/types.h>
  25. #include <sys/fcntl.h>
  26. #include <sys/unistd.h>
  27.  
  28. #ifdef _INTERNAL_FILE
  29. #include <sys/stat.h>
  30. #include <libraries/dosextens.h>
  31.  
  32. /* this is the incore representation of a DTYPE_MEM file */
  33. struct mem_file {
  34.   int   mf_offset;
  35.   void *mf_buffer;
  36. };
  37.  
  38. /* this `glue' makes a tty a subtype of a plain file. Ie f->f_fh will work
  39.    for plain files as well as ttys. */
  40. struct tty_glue {
  41.   struct FileHandle *fh;
  42.   struct tty *tty;    /* internal data of tty.c */
  43. };
  44.  
  45. /* this will hold basic information about a file, but contrairy to
  46.  * Unix, it will also hold its name */
  47.  
  48. struct file {
  49.   char *f_name;         /* the name as used with open() */
  50.   int f_stb_dirty,   /* gets == 1, if changes have been made to 'stb' */
  51.       f_type,         /* can be a file or some amiga..devices */
  52.       f_flags,         /* see fcntl.h */
  53.       f_count,         /* open-count, normally 1, higher after dup() */
  54.       (*f_write)(),    /* functions to perform write,read,etc on this fd */
  55.       (*f_read)(),
  56.       (*f_ioctl)(),
  57.       (*f_select)(),
  58.       (*f_close)();
  59.   union {
  60.     struct FileHandle *fh; /* this is a CPTR to the allocated
  61.                 * FileHandle */
  62.     struct mem_file mf;       /* current data for incore files */
  63.     struct socket *so;       /* points to socket when DTYPE_SOCKET */
  64.     struct tmp_pipe *tp;   /* temporary until sockets are here ;-) */
  65.     struct tty_glue tg;
  66.   } f__fh;
  67. #define f_fh  f__fh.fh
  68. #define f_mf  f__fh.mf
  69. #define f_so  f__fh.so
  70. #define f_tp  f__fh.tp
  71. #define f_tty f__fh.tg.tty
  72.   /* WARNING: if you change this struct, take care, that f_sp starts at
  73.    * long (!) alignment in the struct. The file-table will be allocated
  74.    * by AllocMem(), thus by itself it will have DOS-compatible alignment,
  75.    * if you don't follow this, you'll get some nice gurus.. */
  76.   struct StandardPacket f_sp; /* all IO is done thru the Packet-Interface,
  77.                    * not the higher-level DOS-functions */
  78.   char *f_async_buf;
  79.   int   f_async_len;
  80.   struct stat f_stb; /* file-params at open-time, or after changes to fd */
  81.   int    f_sync_flags;    /* for process synchronization */
  82. };
  83.  
  84.  
  85. #define FSFB_LOCKED    (0)
  86. #define FSFF_LOCKED    (1<<0)    /* means the fh is in use */
  87. #define FSFB_WANTLOCK    (1)
  88. #define FSFF_WANTLOCK    (1<<1)    /* means a process is sleeping on fh to get free */
  89.  
  90. #endif /* _INTERNAL_FILE_H */
  91.  
  92.  
  93. #if 0 /* now in <sys/fcntl.h> */
  94. #include <fcntl.h>
  95.  
  96. /*
  97.  * flags - see also fcntl.h
  98.  */
  99. #define    FOPEN        (-1)
  100. #define    FREAD        00001        /* descriptor read/receive'able */
  101. #define    FWRITE        00002        /* descriptor write/send'able */
  102. #define FINDIR        00010        /* result of a dup() call */
  103. #define FEXTOPEN        00020        /* someone else opened this fd for
  104.                      * us, so we shouldn't close it */
  105. #define FTTYRAW        00040        /* did we send a RAW-packet ?? */
  106. #define FUNLINK        00200        /* unlink file after close */
  107.  
  108. /* bits to save after open */
  109. #define    FMASK        (FREAD|FWRITE|FAPPEND|FSYNC|FASYNC|FNBIO|FINDIR)
  110. #define    FCNTLCANT    (FREAD|FWRITE|FINDIR|FEXTOPEN)
  111. #endif
  112.  
  113. #if 0  /* now in sys/fcntl.h sys/unistd.h */
  114. /*
  115.  * Access call.
  116.  */
  117. #define    F_OK        0    /* does file exist */
  118. #define    X_OK        1    /* is it executable by caller */
  119. #define    W_OK        2    /* writable by caller */
  120. #define    R_OK        4    /* readable by caller */
  121.  
  122. /*
  123.  * Lseek call.
  124.  */
  125. #define    L_SET        0    /* absolute offset */
  126. #define    L_INCR        1    /* relative to current offset */
  127. #define    L_XTND        2    /* relative to end of file */
  128. #endif
  129.  
  130. #define DTYPE_FILE    1    /* 'file' is really a file */
  131. #define DTYPE_PIPE    2    /* it's an incore pipe */
  132. #define DTYPE_MEM    3    /* a RDONLY file completely buffered in memory */
  133. #define DTYPE_TASK_FILE    4    /* is a 'file', but used by a task, not a process !*/
  134. #define DTYPE_SOCKET    5    /* socket (to be implemented real soon now ;-)) */
  135. #define DTYPE_TTY    6    /* amigados file, with special access functions */
  136. /* more to follow.. */
  137.  
  138. #endif /* _SYS_FILE_H */
  139.