GLAST/LAT > DAQ and FSW > FSW > Doxygen Index > FBS / V0-2-0
Constituent: fbs_rtos     Tag: sun-gcc
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <netdb.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "PBI/Endianness.h"
#include "PBS/BSWP.ih"
#include "PBS/FFS.ih"
#include "PBS/INT.ih"
#include "ZLIB/zlib.h"
#include "MDB/MDB_pubdefs.h"
#include "FBS/FBS_msgs.h"
#include "FBS/FBS_pubrtos.h"
#include "FBS_mtx.ih"
#include "FBS_prvrtos.h"
Include dependency graph for FBS_open.c:
Data Structures | |
struct | _FILE_PrimaryHeader |
A description of the sacrosanct primary file header. More... | |
struct | _FILE_Stat |
Block of information associated with a file opened with FILE_open(). More... | |
Defines | |
#define | INT_FAKE_OK |
Allow unix to fake an interrupt lock. | |
#define | MKDIR(_a, _b) mkdir( _a, _b ) |
Gloss over differences in the unix and VxWorks mkdir calls. | |
#define | FILE_K_HDR_SIZ (9) |
Number of bits used to descibe header size. | |
#define | FILE_K_HDR_RSV (3) |
Number of bits used (reserved). | |
#define | FILE_K_HDR_CMP (1) |
Number of bits used to descibe header compression. | |
#define | FILE_K_HDR_VER (3) |
Number of bits used to describe header version. | |
#define | FILE_V_HDR_SIZ ( 0 ) |
Bit offset to header size field. | |
#define | FILE_V_HDR_RSV ( FILE_V_HDR_SIZ + FILE_K_HDR_SIZ ) |
Bit offset to (reserved) field. | |
#define | FILE_V_HDR_CMP ( FILE_V_HDR_RSV + FILE_K_HDR_RSV ) |
Bit offset to compression field. | |
#define | FILE_V_HDR_VER ( FILE_V_HDR_CMP + FILE_K_HDR_CMP ) |
Bit offset to version field. | |
#define | FILE_M_HDR_SIZ (((1 << FILE_K_HDR_SIZ ) - 1) << FILE_V_HDR_SIZ ) |
In place mask for the header size field. | |
#define | FILE_M_HDR_RSV (((1 << FILE_K_HDR_RSV ) - 1) << FILE_V_HDR_RSV ) |
In place mask for the (reserved) field. | |
#define | FILE_M_HDR_CMP (((1 << FILE_K_HDR_CMP ) - 1) << FILE_V_HDR_CMP ) |
In place mask for the compression field. | |
#define | FILE_M_HDR_VER (((1 << FILE_K_HDR_VER ) - 1) << FILE_V_HDR_VER ) |
In place mask for the version field. | |
#define | FILE_K_BITALLOC (2) |
Number of unsigned ints used in bit allocation scheme. | |
#define | FILE_L_TEMPNAME (256) |
Maximum length of a temporary filename. | |
#define | FILE_ACS_SIZE (2048) |
Size of buffer to use during adler32 checksum verification. | |
Typedefs | |
typedef _FILE_PrimaryHeader | FILE_PrimaryHeader |
Typedef for struct _FILE_PrimaryHeader. | |
typedef _FILE_Stat | FILE_Stat |
Typedef for struct _FILE_Stat. | |
Functions | |
static unsigned int | FILE_inflate (int in, int out, unsigned int bufSize) |
File inflater. | |
static int | FILE_findSlot (int fd) |
Find the slot describing fd. | |
static void * | FILE_inflateAlloc (void *opaque, unsigned int numItems, unsigned int size) |
Memory allocation callback for ZLIB. | |
static unsigned int | FILE_inflateError (int errCode, const char *func, const char *msg) |
This function translates ZLIB native error codes into MSG codes. | |
static void | FILE_inflateFree (void *opaque, void *address) |
Memory free callback for ZLIB. | |
static char * | FILE_tempname (int idx, char *buf, unsigned int len) |
Generate a temporary file name. | |
int | FILE_close (int fd) |
Close a FSW file (regular, headed/not-headed, compressed/not-compressed). | |
unsigned int | FILE_decodePrimary (unsigned char *buf, unsigned int len, unsigned int *ver, unsigned int *cmp, unsigned short *typ, unsigned int *key, unsigned int *fcs) |
Assuming buf points to a file header, decode it. | |
unsigned int | FILE_getCompression (int fd) |
Get the compression flag associated with the file descriptor. | |
unsigned int | FILE_getKey (int fd) |
Get the value of the key associated with the file descriptor. | |
int | FILE_getName (int fd, char *nam, unsigned int len) |
Get the original file name associated with the file descriptor. | |
unsigned int | FILE_getSize (int fd) |
Get the file header size associated with the file descriptor. | |
unsigned short | FILE_getType (int fd) |
Get the value of the type associated with the file descriptor. | |
unsigned int | FILE_getVersion (int fd) |
Get the file header version associated with the file descriptor. | |
int | FILE_open (const char *fil, int flg, mode_t mod) |
Open a FSW file (regular, headed/not-headed, compressed/not-compressed). | |
Variables | |
static FBS_mti | mti |
Instance of (storage for) mutex (only used in Unix). | |
static volatile FBS_mtx | mtx |
Mutex to enforce serial open/close/delete operations on a single file. | |
static unsigned int | bookbits [FILE_K_BITALLOC] |
unsigned ints used in a bit allocation scheme to indicate booked slots | |
static FILE_Stat | bookslot [FILE_K_BITALLOC<< 5] |
Slots in which to remember file descriptors for "delete-on-close". | |
char | dir [] = { "/tmp/d000/" } |
Directory prefix for a temporary inflation file. |
CVS $Id: FBS_open.c,v 1.4 2005/11/17 01:27:19 apw Exp $
D.Wood
|
Close a FSW file (regular, headed/not-headed, compressed/not-compressed).
|
|
Assuming buf points to a file header, decode it.
|
|
Find the slot describing fd.
|
|
Get the compression flag associated with the file descriptor.
If these conditions are not met, the guard value 0 is returned. Note that this is the compression bit from the original file open. If the original file is compressed, FILE_open() automatically runs a decompression step and points the caller to a decompressed version of the file. |
|
Get the value of the key associated with the file descriptor.
If these conditions are not met, the guard value 0xffffffff is returned. |
|
Get the original file name associated with the file descriptor.
If these conditions are not met, the guard value -1 is returned. Assuming the above conditions are met, this routine will always return a zero terminated string in nam, even if nam is not sufficiently long to accomodate the full name. To check for this case, the caller should compare the string length of nam against the true name length, which is returned by this function. |
|
Get the file header size associated with the file descriptor.
If these conditions are not met, the guard value 0 is returned. Note that the size returned is literally the number stored in the file header, and does not include the four bytes at the start of the header used to store the file header checksum. |
|
Get the value of the type associated with the file descriptor.
If these conditions are not met, the guard value 0xffff is returned. |
|
Get the file header version associated with the file descriptor.
If these conditions are not met, the guard value 0 is returned. |
|
File inflater.
|
|
Memory allocation callback for ZLIB.
|
|
This function translates ZLIB native error codes into MSG codes.
|
|
Memory free callback for ZLIB.
|
|
Open a FSW file (regular, headed/not-headed, compressed/not-compressed).
Flight software files appear in three different formats:
When FILE_open() is asked to open any of these formats, it will first inspect the file to classify it. The adler32 checksum in the header is very powerful here. Subsequent processing depends on the file format:
In keeping with the idea that FILE_open() is modeled on open(), the errno method is used to return extra information. One unusual feature of this is that errno can contain helpful information, even when the file open is successful. If the return value is not -1 (i.e. the open succeeded), errno can contain:
If the return value is -1 (i.e. the open failed), errno, in addition to any of the regular values that open() can return, can contain:
If you wish to use these values for additional checking, note that errno is a four byte word encoded as two two-byte units. The most significant unit is a module number and the lower unit is the "error" number. The additional error codes defined by FILE_open() are module 0x200 (to avoid collisions with unix and VxWorks error codes), and the error numbers obey MSG conventions, i.e. if the least significant bit is clear, the operation was a success. |
|
Generate a temporary file name.
/ram disk). The unix file name is a little more elaborate (it includes host name and process number) to try to avoid collisions. |