home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.2 (Developer) / NS_dev_3.2.iso / NextDeveloper / Headers / bsd / sys / file.h < prev    next >
Text File  |  1993-10-19  |  4KB  |  144 lines

  1. /* 
  2.  * Mach Operating System
  3.  * Copyright (c) 1987 Carnegie-Mellon University
  4.  * All rights reserved.  The CMU software License Agreement specifies
  5.  * the terms and conditions for use and redistribution.
  6.  */
  7. /*
  8.  * HISTORY
  9.  *  7-Jan-93  Mac Gillon (mgillon) at NeXT
  10.  *     Integrated POSIX support
  11.  *
  12.  * 11-Aug-87  Peter King (king) at NeXT
  13.  *    SUN_VFS: Added f_cred pointer to user's credentials
  14.  *         Moved fcntl and open flag defines to fcntl.h
  15.  *
  16.  * 25-Jan-86  Avadis Tevanian (avie) at Carnegie-Mellon University
  17.  *    Upgraded to 4.3.
  18.  */
  19.  
  20. /*
  21.  * Copyright (c) 1982, 1986 Regents of the University of California.
  22.  * All rights reserved.  The Berkeley software License Agreement
  23.  * specifies the terms and conditions for redistribution.
  24.  *
  25.  *    @(#)file.h    7.1 (Berkeley) 6/4/86
  26.  */
  27.  
  28. /* @(#)file.h    2.1 88/05/18 4.0NFSSRC SMI;    from UCB 7.1 06/04/86    */
  29. #import <sys/fcntl.h>
  30.  
  31. #ifdef    KERNEL_FILE
  32. #define    KERNEL
  33. #endif    KERNEL_FILE
  34. #ifdef KERNEL
  35. #import <kernserv/queue.h>
  36.  
  37. /*
  38.  * Descriptor table entry.
  39.  * One for each kernel object.
  40.  */
  41. struct    file {
  42.     queue_chain_t    links;    /* links for list of all files */
  43.     int    f_flag;        /* see below */
  44.     short    f_type;        /* descriptor type */
  45.     short    f_count;    /* reference count */
  46.     short    f_msgcount;    /* references from message queue */
  47.     struct    fileops {
  48.         int    (*fo_rw)();
  49.         int    (*fo_ioctl)();
  50.         int    (*fo_select)();
  51.         int    (*fo_close)();
  52.     } *f_ops;
  53.     caddr_t    f_data;     /* ptr to file specific struct ([iv]node/socket) */
  54.     off_t    f_offset;
  55. /*VFS*/    struct    ucred *f_cred;    /* credentials of user who opened file */
  56. };
  57.  
  58. queue_head_t    file_list;
  59. struct    file *getf();
  60. struct    file *falloc();
  61. #endif
  62.  
  63. /*
  64.  * flags- also for fcntl call. (VFS: see also fcntl.h)
  65.  */
  66. #define    FOPEN        (-1)
  67. #define    FREAD        00001        /* descriptor read/receive'able */
  68. #define    FWRITE        00002        /* descriptor write/send'able */
  69. #define    FMARK        00020        /* mark during gc() */
  70. #define    FDEFER        00040        /* defer for next gc pass */
  71. #define    FSHLOCK        00200        /* shared lock present */
  72. #define    FEXLOCK        00400        /* exclusive lock present */
  73.  
  74. #if POSIX_KERN
  75. /*
  76.  * POSIX behavior: When read() or write() is called on a pipe and the pipe is
  77.  *                 supposed to block and the O_NONBLOCK flag is set, then
  78.  *                 the function will return -1 and set errno to EAGAIN.  
  79.  *                 On the NeXT, errno is set to EWOULDBLOCK.
  80.  *
  81.  * Since pipes on the NeXT are implemented using sockets, we need to
  82.  * differentiate between sockets and pipes.  The following constant is
  83.  * used internally for such purpose.
  84.  */
  85. #define    FPOSIX_PIPE    020000
  86. #endif    /* POSIX_KERN */
  87.  
  88. /* bits to save after open */
  89. #define    FMASK        00113
  90. #if POSIX_KERN
  91. #define    FCNTLCANT    (FREAD|FWRITE|FMARK|FDEFER|FSHLOCK|FEXLOCK|FPOSIX_PIPE)
  92. #else
  93. #define    FCNTLCANT    (FREAD|FWRITE|FMARK|FDEFER|FSHLOCK|FEXLOCK)
  94. #endif    /* POSIX_KERN */
  95.  
  96. /*
  97.  * User calls
  98.  */
  99.  
  100.  
  101. /*
  102.  * Flock call.
  103.  */
  104. #define    LOCK_SH        1    /* shared lock */
  105. #define    LOCK_EX        2    /* exclusive lock */
  106. #define    LOCK_NB        4    /* don't block when locking */
  107. #define    LOCK_UN        8    /* unlock */
  108.  
  109. /*
  110.  * Lseek call.
  111.  */
  112. #define    L_SET        0    /* absolute offset */
  113. #define    L_INCR        1    /* relative to current offset */
  114. #define    L_XTND        2    /* relative to end of file */
  115.  
  116. #ifdef KERNEL
  117. #if    NeXT
  118.  
  119. #define FPINPROGRESS 0xffff0000
  120.  
  121. #define    GETF(fp, fd) { \
  122.     if ((unsigned)(fd) >= u.u_ofile_cnt || ((fp) = u.u_ofile[fd]) == NULL || \
  123.         (fp == (struct file *)FPINPROGRESS)) { \
  124.         u.u_error = EBADF; \
  125.         return; \
  126.     } \
  127. }
  128. #else    NeXT
  129. #define    GETF(fp, fd) { \
  130.     if ((unsigned)(fd) >= NOFILE || ((fp) = u.u_ofile[fd]) == NULL) { \
  131.         u.u_error = EBADF; \
  132.         return; \
  133.     } \
  134. }
  135. #endif    NeXT
  136. #define    DTYPE_VNODE    1    /* file */
  137. #define    DTYPE_SOCKET    2    /* communications endpoint */
  138. #endif
  139. #ifdef    KERNEL_FILE
  140. #undef    KERNEL
  141. #endif    KERNEL_FILE
  142.  
  143.  
  144.