home *** CD-ROM | disk | FTP | other *** search
/ Frostbyte's 1980s DOS Shareware Collection / floppyshareware.zip / floppyshareware / DOOG / CBASE09.ZIP / BLKIO10.ZIP / BLKIO.H < prev    next >
Text File  |  1989-08-30  |  6KB  |  149 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "blkio.h    1.1 - 89/07/03" */
  5.  
  6. /*man---------------------------------------------------------------------------
  7. NAME
  8.      blkio - block buffered input/output library
  9.  
  10. SYNOPSIS
  11.      #include <blkio.h>
  12.  
  13. DESCRIPTION
  14.      blkio is a buffered input/output library for structured files.  Because
  15.      structured files are primarily accessed randomly rather than
  16.      sequentially, they are better modeled as collections of blocks rather
  17.      than as streams of characters.  This library may be used with files
  18.      which fit the following criteria:
  19.  
  20.           1. A header of arbitrary (possibly zero) but fixed length
  21.              appears at the beginning of the file.
  22.           2. The data following the header is arranged in blocks
  23.              of uniform size.
  24.  
  25.      Files fitting this model are referred to in the documentation as block
  26.      files.
  27.  
  28.      A file to be accessed with the blkio library is declared to be a
  29.      pointer to a defined type BLKFILE.  The bopen function creates certain
  30.      descriptive data for the file and returns a pointer to designate it
  31.      in all further transactions.
  32.  
  33. SEE ALSO
  34.      bclose, bexit, bflpop, bflpush, bflush, bgetb, bgetbf, bgeth, bgethf,
  35.      bopen, bputb, bputbf, bputh, bputhf, bsetbuf, bsetvbuf, bsync, lockb.
  36.  
  37. ------------------------------------------------------------------------------*/
  38. #ifndef BLKIO_H        /* prevent multiple includes */
  39. #define BLKIO_H
  40.  
  41. #include <stddef.h>    /* replace with header containing size_t typedef */
  42.             /* e.g., <sys/types.h> */
  43. #include <stdio.h>
  44.  
  45. /* temporary ansi definitions and declarations */
  46. #ifndef FOPEN_MAX    /* these will be in ansi stdio.h */
  47. #define FOPEN_MAX    60
  48. #endif
  49. #ifndef FILENAME_MAX
  50. #define FILENAME_MAX    25
  51. #endif
  52. #ifndef offsetof    /* these will be in ansi stddef.h */
  53. #define offsetof(struct_t, member)    ((size_t)(char *)&((struct_t *)0)->member)
  54. #endif
  55. void *calloc();        /* these will be in ansi stdlib.h */
  56. void exit();
  57. void free();
  58. void *malloc();
  59. void *realloc();
  60. int memcmp();        /* these will be in ansi string.h */
  61. void *memcpy();
  62. void *memmove();
  63. void *memset();
  64. char *strstr();
  65.  
  66. /* blkio constants */
  67. #define BOPEN_MAX    FOPEN_MAX    /* max # block files open at once */
  68.  
  69. /* block file type definitions */
  70. typedef size_t    bpos_t;        /* block file position */
  71.  
  72. typedef union {            /* file desciptor type */
  73.     int ifd;        /* int file descriptor */
  74.     long lfd;        /* long int file descriptor */
  75. } fd_t;
  76.  
  77. typedef struct {        /* block structure */
  78.     bpos_t bn;        /* block number [1...] */
  79.     int flags;        /* block status flags */
  80.     size_t more;        /* link to more recently accessed block */
  81.     size_t less;        /* link to less recently accessed block */
  82. } block_t;
  83.  
  84. typedef struct {        /* block file control structure */
  85.     fd_t fd;        /* file descriptor for buffered file */
  86.     int flags;        /* buffer status flags */
  87.     size_t hdrsize;        /* size of file header */
  88.     size_t blksize;        /* size of blocks */
  89.     size_t bufcnt;        /* number blocks to buffer (0 if unbuffered) */
  90.     bpos_t endblk;        /* first block past end of file */
  91.     size_t most;        /* most recently accessed block [1..bufcnt] */
  92.     size_t least;        /* least recently accessed block [1..bufcnt] */
  93.     block_t *block_p;    /* doubly linked list of blocks */
  94.     void *blkbuf;        /* buffer storage for header and blocks */
  95. } BLKFILE;
  96. extern BLKFILE biob[BOPEN_MAX];    /* BLKFILE control struct table declaration */
  97.  
  98. /* block_t flag bits */
  99. #define BLKREAD          (01)    /* block can be read */
  100. #define BLKWRITE      (02)    /* block needs to be written to disk */
  101. #define BLKERR        (0100)    /* error has occurred on this block */
  102.  
  103. /* biob flag bits */
  104. #define BIOOPEN          (03)    /* open status bits */
  105. #define BIOREAD          (01)    /* block file is open for reading */
  106. #define BIOWRITE      (02)    /* block file is open for writing */
  107. #define BIOUSRBUF      (04)    /* user supplied buffer */
  108. #define BIOERR        (0100)    /* error has occurred on this block file */
  109.  
  110. /* function declarations */
  111. int        bclose(/* BLKFILE *bp */);
  112. void        bexit(/* int status */);
  113. int        bflpop(/* BLKFILE *bp, bpos_t *bn_p */);
  114. int        bflpush(/* BLKFILE *bp, bpos_t *bn_p */);
  115. int        bflush(/* BLKFILE *bp */);
  116. int        bgetb(/* BLKFILE *bp, bpos_t bn, void *buf */);
  117. int        bgetbf(/* BLKFILE *bp, bpos_t bn, size_t offset, void *buf, size_t bufsize */);
  118. int        bgeth(/* BLKFILE *bp, void *buf */);
  119. int        bgethf(/* BLKFILE *bp, size_t offset, void *buf, size_t bufsize */);
  120. BLKFILE *    bopen(/* char *filename, char *type, size_t hdrsize, size_t blksize, size_t bufcnt */);
  121. int        bputb(/* BLKFILE *bp, bpos_t bn, void *buf */);
  122. int        bputbf(/* BLKFILE *bp, bpos_t bn, size_t offset, void *buf, size_t bufsize */);
  123. int        bputh(/* BLKFILE *bp, void *buf */);
  124. int        bputhf(/* BLKFILE *bp, size_t offset, void *buf, size_t bufsize */);
  125. int        bsetbuf(/* BLKFILE *bp, void *buf */);
  126. int        bsetvbuf(/* BLKFILE *bp, void *buf, size_t blksize, size_t bufcnt */);
  127. int        bsync(/* BLKFILE *bp */);
  128. int        lockb(/* BLKFILE *bp, int l_type, bpos_t bn, size_t size */);
  129.  
  130. /* blkio lock types */
  131. #define B_UNLCK        (0)    /* unlock */
  132. #define B_RDLCK        (1)    /* read lock */
  133. #define B_WRLCK        (2)    /* write lock */
  134. #define B_RDLKW        (3)    /* read lock, wait */
  135. #define B_WRLKW        (4)    /* write lock, wait */
  136.  
  137. /* blkio error codes */
  138. #define BEOS        (0)    /* start of blkio error code domain */
  139. #define BEMFILE        (BEOS - 1)    /* too many block files open */
  140. #define BENOPEN        (BEOS - 2)    /* block file is not open */
  141. #define BENBUF        (BEOS - 3)    /* buffering is off */
  142. #define BEBUF        (BEOS - 4)    /* buffering is on */
  143. #define BEBOUND        (BEOS - 5)    /* block boundary error */
  144. #define BEEOF        (BEOS - 6)    /* past end of file */
  145. #define BENFL        (BEOS - 7)    /* no free list */
  146. #define BEPANIC        (BEOS - 10)    /* internal blkio error */
  147.  
  148. #endif    /* #ifndef BLKIO_H */
  149.