/* **********************************************************************
 * *                                                                    *
 * *                  Definitions for IRIS Archive                      *
 * *                                                                    *
 * **********************************************************************
 * File: iris/tape/archive_h.h
 *
 *       COPYRIGHT (c) 1989, 1993, 1996, 1998, 2000, 2003, 2004 BY
 *          SIGMET INCORPORATED, WESTFORD MASSACHUSETTS, U.S.A.
 *
 * THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
 * ONLY  IN  ACCORDANCE WITH  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
 * INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE  OR  ANY OTHER
 * COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
 * OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
 * TRANSFERED.
 */

#ifdef __cplusplus
extern "C" {
#endif

#define         BAD_UNIT       1
#define ARCHIVE_BAD_UNIT       (ARCHIVE_FACILITY + BAD_UNIT     )
#define         CANT_POS       2
#define ARCHIVE_CANT_POS       (ARCHIVE_FACILITY + CANT_POS     )
#define         FILE_DUPLICATE 3
#define ARCHIVE_FILE_DUPLICATE (ARCHIVE_FACILITY + FILE_DUPLICATE)
#define         FILE_NAMELONG  4
#define ARCHIVE_FILE_NAMELONG  (ARCHIVE_FACILITY + FILE_NAMELONG)
#define         FILE_NOTNATIVE 5
#define ARCHIVE_FILE_NOTNATIVE (ARCHIVE_FACILITY + FILE_NOTNATIVE)
#define         FILE_OPEN      6
#define ARCHIVE_FILE_OPEN      (ARCHIVE_FACILITY + FILE_OPEN    )
#define         FILE_PTYPE     7
#define ARCHIVE_FILE_PTYPE     (ARCHIVE_FACILITY + FILE_PTYPE    )
#define         FILE_SIZE      8
#define ARCHIVE_FILE_SIZE      (ARCHIVE_FACILITY + FILE_SIZE    )
#define         FILE_WRITE     9
#define ARCHIVE_FILE_WRITE     (ARCHIVE_FACILITY + FILE_WRITE   )
#define         FILE_WRONGDIR  10
#define ARCHIVE_FILE_WRONGDIR  (ARCHIVE_FACILITY + FILE_WRONGDIR)
#define         FORK_CLAIMED   11
#define ARCHIVE_FORK_CLAIMED   (ARCHIVE_FACILITY + FORK_CLAIMED )
#define         FORK_UNIT      12
#define ARCHIVE_FORK_UNIT      (ARCHIVE_FACILITY + FORK_UNIT    )
#define         INV_INVALID    13
#define ARCHIVE_INV_INVALID    (ARCHIVE_FACILITY + INV_INVALID  )
#define         INV_SITENUM    14
#define ARCHIVE_INV_SITENUM    (ARCHIVE_FACILITY + INV_SITENUM  )
#define         INV_SUBTYPE    15
#define ARCHIVE_INV_SUBTYPE    (ARCHIVE_FACILITY + INV_SUBTYPE  )
#define         LDA_ERROR      16
#define ARCHIVE_LDA_ERROR      (ARCHIVE_FACILITY + LDA_ERROR     )
#define         MEDIA_COUNT    17
#define ARCHIVE_MEDIA_COUNT    (ARCHIVE_FACILITY + MEDIA_COUNT  )
#define         MEDIA_FULL     18
#define ARCHIVE_MEDIA_FULL     (ARCHIVE_FACILITY + MEDIA_FULL   )
#define         MEDIA_MISSING  19
#define ARCHIVE_MEDIA_MISSING  (ARCHIVE_FACILITY + MEDIA_MISSING)
#define         MO_ERROR       20
#define ARCHIVE_MO_ERROR       (ARCHIVE_FACILITY + MO_ERROR     )
#define         MO_WPROT       21
#define ARCHIVE_MO_WPROT       (ARCHIVE_FACILITY + MO_WPROT     )
#define         NEWCMD         22
#define ARCHIVE_NEWCMD         (ARCHIVE_FACILITY + NEWCMD       )
#define         ON_ARCHIVE     23
#define ARCHIVE_ON_ARCHIVE     (ARCHIVE_FACILITY + ON_ARCHIVE   )
#define         NOT_A_MO       24
#define ARCHIVE_NOT_A_MO       (ARCHIVE_FACILITY + NOT_A_MO     )
#define         NOT_A_TAPE     25
#define ARCHIVE_NOT_A_TAPE     (ARCHIVE_FACILITY + NOT_A_TAPE   )
#define         RUEOF          26
#define ARCHIVE_RUEOF          (ARCHIVE_FACILITY + RUEOF        )
#define         RNEOF          27
#define ARCHIVE_RNEOF          (ARCHIVE_FACILITY + RNEOF        )
#define         TABORT_WRITE   28
#define ARCHIVE_TABORT_WRITE   (ARCHIVE_FACILITY + TABORT_WRITE )
#define         TAPELOST       29
#define ARCHIVE_TAPELOST       (ARCHIVE_FACILITY + TAPELOST     )
#define         TBAD_END       30
#define ARCHIVE_TBAD_END       (ARCHIVE_FACILITY + TBAD_END     )
#define         TPARITY        31
#define ARCHIVE_TPARITY        (ARCHIVE_FACILITY + TPARITY      )
#define         UNK_TAPEOP     32
#define ARCHIVE_UNK_TAPEOP     (ARCHIVE_FACILITY + UNK_TAPEOP   )

#ifndef MESSAGE_ONLY                      

/*
 * Shared variables:
 */
#ifdef SIGMET_HEADERS_H
#ifdef SIGMET_SETUP_H
#define TAPE_H_ARCHIVE 1
#endif  /* #ifdef SIGMET_SETUP_H */
#endif  /* #ifdef SIGMET_HEADERS_H */

#ifdef TAPE_H_ARCHIVE
struct archive_state
{
  volatile struct archive_inventory *ptinv;
  /* volatile struct archive_info      *ptape; */
  struct device_def device;    /* Device definition structure */
  SINT4 idevice;               /* Device number, origin 0 */
  UINT4 ievent_flag;           /* Event flag for the device */
  UINT1 itape_buf[TAPE_RECORD_LEN+2];
  SINT4 itfile;                /* Position on the tape */
  UINT2 leof;
  UINT2 leodata;
  UINT2 lalready_read_first;
  UINT4 ireclen;
  UINT4 icmd;                  /* Tape command sent from user */
};
#endif  /* #ifdef TAPE_H_ARCHIVE */

struct archive_init_options
{
  UINT1 lSetName;
  UINT1 lForceMoFormat;
  char sArchiveID[16];   /* Space padded */
};

/* Extra errno numbers added by IRIS */
#define E_IRIS_IMPORTVG (0x1001)

/* Tape control parameters in iop_a for itape_op_kernel()
 */
#define OP_READRECORD  (1)
#define OP_WRITERECORD (2)
#define OP_SKIPRECORD  (3)
#define OP_SKIPFILE    (4)
#define OP_REWIND      (5)
#define OP_REWOFFL     (6)
#define OP_WRITEOF     (7)
#define OP_PAKOPEN     (8)
#define OP_PAKCLOSE    (9)

/* Bits in iflags_a
 */
#define TFLG_BOT    (0x00000001)
#define TFLG_EOT    (0x00000002)
#define TFLG_EOF    (0x00000004)
#define TFLG_WENAB  (0x00000008)
#define TFLG_EODATA (0x00000010)

#define DVD_MAX_SIZE (4000)   //4000 MB = 4 GB
#define DVD_TEMP_DIR "DvdArchive"

MESSAGE itape_op_kernel  /* File: tape_ops.C */
  (UINT4 ichan_a, 
   UINT4 iop_a,
   void *ip1_a,
   UINT4 isize_a,     /* Desired size of read/write */
   UINT4 *iflags_a,
   UINT4 *ireclen_a ) ;  /* Actual size, chanel on open */

void archive_unmount( UINT2 ldvd_record_before_unmount_a ); /* File: tape.C */

#ifdef SIGMET_SETUP_H
struct device_def *init_args   /* File: init_ops.C */
( int iargc_a,
  char *sargv_a[],
  struct iris_setup *pISetup_a,
  struct license_setup *pLSetup_a,
  int itype_a,
  struct archive_init_options *pOptions_a );
#endif  /* #ifdef SIGMET_SETUP_H */

#ifdef SIGMET_OUTPUT_H
#ifdef SIGMET_SETUP_H
void init_header_record          /* File: init_ops.C */
(struct tape_header_record *phead_a,
 const struct archive_init_options *pOptions_a,
 const struct iris_setup *psite_a,
 const char sSitename_a[16] );  /* site name is space padded */
#endif  /* #ifdef SIGMET_SETUP_H */
#endif  /* #ifdef SIGMET_OUTPUT_H */


#ifdef SIGMET_OUTPUT_H
SINT4 insert_archive_at_pos       /* File: inventory.C */
(volatile struct archive_inventory *tinv_a,
 const struct one_tape_product *pfile_a,
 SINT4 index_a ); /* Origin 1 index */
#endif  /* #ifdef SIGMET_OUTPUT_H */

#ifdef TAPE_H_ARCHIVE
void inventory                   /* File: inventory.C */
(struct archive_state *pstate_a,
 const char *sdirectory_a );
void inventoryTempDvd                 /* File: inventory.C */
(struct archive_state *pstate_a,
 const char *sdirectory_a,
 const char *spath_temp_dvd_a );
#endif  /* #ifdef TAPE_H_ARCHIVE */

#ifdef TAPE_H_ARCHIVE
MESSAGE ipostape                 /* File: tape_pos.C */
(struct archive_state *pstate_a,
 SINT4 itfile_a );
#endif  /* #ifdef TAPE_H_ARCHIVE */

#ifdef TAPE_H_ARCHIVE
MESSAGE itape_op                 /* File: tape_pos.C */
(struct archive_state *pstate_a,
 UINT4 iop_a, void *ip1_a, SINT4 isize_a );
#endif  /* #ifdef TAPE_H_ARCHIVE */

#ifdef SIGMET_OUTPUT_H
UINT2  lcheck_iris_disk          /* File: mo_ops.C */
(const char *sDirectory_a,
 struct tape_header_record *phead_a ); /*Fills in tape header record, if found*/

UINT2  lcheck_iris_temp_dvd_disk       /* File: mo_ops.C */
(const char *sDirectory_a);
#endif  /* #ifdef SIGMET_OUTPUT_H */

#ifdef SIGMET_OUTPUT_H
#ifdef SIGMET_PRODUCT_H
void oap_from_product_hdr
(struct one_tape_product *parchive_a,
 const struct product_hdr *phdr_a,
 const char* sfile_name_a );
#endif  /* #ifdef SIGMET_PRODUCT_H */
#endif  /* #ifdef SIGMET_OUTPUT_H */


#ifdef SIGMET_OUTPUT_H
void read_tape_inven_file        /* File: inventory.C */
(const char *sdirectory_a,
 volatile const char sfile_a[12],
 volatile struct archive_inventory *ptape_a );
#endif  /* #ifdef SIGMET_OUTPUT_H */

#ifdef TAPE_H_ARCHIVE
void record_mode                 /* File: record_mode.C */
( struct archive_state *state_a );
#endif  /* #ifdef TAPE_H_ARCHIVE */

#ifdef TAPE_H_ARCHIVE
void retrieve_mode               /* File: retrieve_mode.C */
(struct archive_state *pstate_a);
#endif  /* #ifdef TAPE_H_ARCHIVE */

void set_tape_file               /* File: tape.C */
( UINT4 ifile_a );

void show_archive_action         /* File: tape.C */
(SINT4 imode_a,
 SINT4 iaction_a );

#ifdef SIGMET_SETUP_H
MESSAGE sig_lda_check            /* File: lda_ops.C */
(const struct device_def *pmo_a,
 UINT2 lverbose_a,
 volatile UINT2 *lwrite_a );
#endif  /* #ifdef SIGMET_SETUP_H */

#ifdef SIGMET_SETUP_H
MESSAGE sig_mo_check             /* File: mo_ops.C */
(const struct device_def *pmo_a,
 UINT2 lverbose_a,
 volatile UINT2 *lwrite_a );
#endif  /* #ifdef SIGMET_SETUP_H */

#ifdef SIGMET_SETUP_H
int sig_mo_mount                 /* File: mo_ops.C */
(const struct device_def *pmo_a,
 UINT2 lverbose_a,
 UINT2 lwrite_enable_a );
#endif  /* #ifdef SIGMET_SETUP_H */

#ifdef SIGMET_SETUP_H
int sig_mo_umount               /* File: mo_ops.C */
(const struct device_def *pmo_a,
 UINT2 lverbose_a );
#endif  /* #ifdef SIGMET_SETUP_H */

#ifdef SIGMET_SETUP_H
MESSAGE sig_dvd_check             /* File: dvd_ops.C */
(const struct device_def *pdvd_a,
 UINT2 lverbose_a,
 volatile UINT2 *lwrite_a );
#endif  /* #ifdef SIGMET_SETUP_H */

#ifdef SIGMET_SETUP_H
int sig_dvd_mount                 /* File: dvd_ops.C */
(const struct device_def *pdvd_a,
 UINT2 lverbose_a );
#endif  /* #ifdef SIGMET_SETUP_H */

#ifdef SIGMET_SETUP_H
int sig_dvd_umount                 /* File: dvd_ops.C */
(const struct device_def *pdvd_a,
 UINT2 lverbose_a );
#endif  /* #ifdef SIGMET_SETUP_H */

#ifdef SIGMET_SETUP_H
int sig_dvd_cleanup_and_umount              /* File: dvd_ops.C */
(const struct device_def *pdvd_a,
 UINT2 lverbose_a );
#endif  /* #ifdef SIGMET_SETUP_H */

#ifdef SIGMET_SETUP_H
int sig_dvd_record              /* File: dvd_ops.C */
(const struct device_def *pdvd_a,
 UINT2 lverbose_a );
#endif  /* #ifdef SIGMET_SETUP_H */

#ifdef SIGMET_SETUP_H
char *getTmpDvdDir(void);
char *getProdDir(void);
char *getProdRawDir(void);
#endif  /* #ifdef SIGMET_SETUP_H */

#ifdef TAPE_H_ARCHIVE
void write_inven_files           /* File: inventory.C */
(const char *sdirectory_a,
 struct archive_state *state_a );
#endif  /* #ifdef TAPE_H_ARCHIVE */

#endif  /* #ifndef MESSAGE_ONLY */

#ifdef __cplusplus
}
#endif
