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 >
Wrap
Text File
|
1989-08-30
|
6KB
|
149 lines
/* Copyright (c) 1989 Citadel */
/* All Rights Reserved */
/* #ident "blkio.h 1.1 - 89/07/03" */
/*man---------------------------------------------------------------------------
NAME
blkio - block buffered input/output library
SYNOPSIS
#include <blkio.h>
DESCRIPTION
blkio is a buffered input/output library for structured files. Because
structured files are primarily accessed randomly rather than
sequentially, they are better modeled as collections of blocks rather
than as streams of characters. This library may be used with files
which fit the following criteria:
1. A header of arbitrary (possibly zero) but fixed length
appears at the beginning of the file.
2. The data following the header is arranged in blocks
of uniform size.
Files fitting this model are referred to in the documentation as block
files.
A file to be accessed with the blkio library is declared to be a
pointer to a defined type BLKFILE. The bopen function creates certain
descriptive data for the file and returns a pointer to designate it
in all further transactions.
SEE ALSO
bclose, bexit, bflpop, bflpush, bflush, bgetb, bgetbf, bgeth, bgethf,
bopen, bputb, bputbf, bputh, bputhf, bsetbuf, bsetvbuf, bsync, lockb.
------------------------------------------------------------------------------*/
#ifndef BLKIO_H /* prevent multiple includes */
#define BLKIO_H
#include <stddef.h> /* replace with header containing size_t typedef */
/* e.g., <sys/types.h> */
#include <stdio.h>
/* temporary ansi definitions and declarations */
#ifndef FOPEN_MAX /* these will be in ansi stdio.h */
#define FOPEN_MAX 60
#endif
#ifndef FILENAME_MAX
#define FILENAME_MAX 25
#endif
#ifndef offsetof /* these will be in ansi stddef.h */
#define offsetof(struct_t, member) ((size_t)(char *)&((struct_t *)0)->member)
#endif
void *calloc(); /* these will be in ansi stdlib.h */
void exit();
void free();
void *malloc();
void *realloc();
int memcmp(); /* these will be in ansi string.h */
void *memcpy();
void *memmove();
void *memset();
char *strstr();
/* blkio constants */
#define BOPEN_MAX FOPEN_MAX /* max # block files open at once */
/* block file type definitions */
typedef size_t bpos_t; /* block file position */
typedef union { /* file desciptor type */
int ifd; /* int file descriptor */
long lfd; /* long int file descriptor */
} fd_t;
typedef struct { /* block structure */
bpos_t bn; /* block number [1...] */
int flags; /* block status flags */
size_t more; /* link to more recently accessed block */
size_t less; /* link to less recently accessed block */
} block_t;
typedef struct { /* block file control structure */
fd_t fd; /* file descriptor for buffered file */
int flags; /* buffer status flags */
size_t hdrsize; /* size of file header */
size_t blksize; /* size of blocks */
size_t bufcnt; /* number blocks to buffer (0 if unbuffered) */
bpos_t endblk; /* first block past end of file */
size_t most; /* most recently accessed block [1..bufcnt] */
size_t least; /* least recently accessed block [1..bufcnt] */
block_t *block_p; /* doubly linked list of blocks */
void *blkbuf; /* buffer storage for header and blocks */
} BLKFILE;
extern BLKFILE biob[BOPEN_MAX]; /* BLKFILE control struct table declaration */
/* block_t flag bits */
#define BLKREAD (01) /* block can be read */
#define BLKWRITE (02) /* block needs to be written to disk */
#define BLKERR (0100) /* error has occurred on this block */
/* biob flag bits */
#define BIOOPEN (03) /* open status bits */
#define BIOREAD (01) /* block file is open for reading */
#define BIOWRITE (02) /* block file is open for writing */
#define BIOUSRBUF (04) /* user supplied buffer */
#define BIOERR (0100) /* error has occurred on this block file */
/* function declarations */
int bclose(/* BLKFILE *bp */);
void bexit(/* int status */);
int bflpop(/* BLKFILE *bp, bpos_t *bn_p */);
int bflpush(/* BLKFILE *bp, bpos_t *bn_p */);
int bflush(/* BLKFILE *bp */);
int bgetb(/* BLKFILE *bp, bpos_t bn, void *buf */);
int bgetbf(/* BLKFILE *bp, bpos_t bn, size_t offset, void *buf, size_t bufsize */);
int bgeth(/* BLKFILE *bp, void *buf */);
int bgethf(/* BLKFILE *bp, size_t offset, void *buf, size_t bufsize */);
BLKFILE * bopen(/* char *filename, char *type, size_t hdrsize, size_t blksize, size_t bufcnt */);
int bputb(/* BLKFILE *bp, bpos_t bn, void *buf */);
int bputbf(/* BLKFILE *bp, bpos_t bn, size_t offset, void *buf, size_t bufsize */);
int bputh(/* BLKFILE *bp, void *buf */);
int bputhf(/* BLKFILE *bp, size_t offset, void *buf, size_t bufsize */);
int bsetbuf(/* BLKFILE *bp, void *buf */);
int bsetvbuf(/* BLKFILE *bp, void *buf, size_t blksize, size_t bufcnt */);
int bsync(/* BLKFILE *bp */);
int lockb(/* BLKFILE *bp, int l_type, bpos_t bn, size_t size */);
/* blkio lock types */
#define B_UNLCK (0) /* unlock */
#define B_RDLCK (1) /* read lock */
#define B_WRLCK (2) /* write lock */
#define B_RDLKW (3) /* read lock, wait */
#define B_WRLKW (4) /* write lock, wait */
/* blkio error codes */
#define BEOS (0) /* start of blkio error code domain */
#define BEMFILE (BEOS - 1) /* too many block files open */
#define BENOPEN (BEOS - 2) /* block file is not open */
#define BENBUF (BEOS - 3) /* buffering is off */
#define BEBUF (BEOS - 4) /* buffering is on */
#define BEBOUND (BEOS - 5) /* block boundary error */
#define BEEOF (BEOS - 6) /* past end of file */
#define BENFL (BEOS - 7) /* no free list */
#define BEPANIC (BEOS - 10) /* internal blkio error */
#endif /* #ifndef BLKIO_H */