1c202f43995f74f188c093250302bce3a71a5c35
[openafs.git] / src / bubasics / butm.p.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afs/auth.h>
11 #include <afs/bubasics.h>
12
13 struct blockMark {
14     int count;                  /* actual number of bytes valid in the block */
15     afs_int32 magic;
16     afs_int32 spare1;
17     afs_int32 spare2;
18     afs_int32 spare3;
19     afs_int32 spare4;
20 };
21
22 /* The size of a tapeblock is 16KB: contains header info and data */
23 #define BUTM_BLOCKSIZE 16384
24 #define BUTM_HDRSIZE   ((5*sizeof(afs_int32)) + sizeof(int))    /* sizeof blockMark */
25 #define BUTM_BLKSIZE   (BUTM_BLOCKSIZE - BUTM_HDRSIZE)
26
27 struct butm_tapeLabel;
28
29 struct butm_tapeInfo {
30     afs_int32 structVersion;
31     struct {
32         afs_int32(*mount) (struct butm_tapeInfo *, char *);
33         afs_int32(*dismount) (struct butm_tapeInfo *);
34         afs_int32(*create) (struct butm_tapeInfo *, struct butm_tapeLabel *,
35                             afs_int32);
36         afs_int32(*readLabel) (struct butm_tapeInfo *, 
37                                struct butm_tapeLabel *,
38                                afs_int32);
39         afs_int32(*seek) (struct butm_tapeInfo *, afs_int32);
40         afs_int32(*seekEODump) (struct butm_tapeInfo *, afs_int32);
41         afs_int32(*readFileBegin) (struct butm_tapeInfo *);
42         afs_int32(*readFileData) (struct butm_tapeInfo *, char *, int len, 
43                                   int *);
44         afs_int32(*readFileEnd) (struct butm_tapeInfo *);
45         afs_int32(*writeFileBegin) (struct butm_tapeInfo *);
46         afs_int32(*writeFileData) (struct butm_tapeInfo *, char *, afs_int32,
47                                    afs_int32);
48         afs_int32(*writeFileEnd) (struct butm_tapeInfo *);
49         afs_int32(*writeEOT) (struct butm_tapeInfo *);
50         afs_int32(*setSize) (struct butm_tapeInfo *, afs_uint32);
51         afs_int32(*getSize) (struct butm_tapeInfo *, afs_uint32);
52     } ops;
53     char name[BU_MAXTAPELEN];
54     afs_int32 position;         /* current position of tape */
55     afs_uint32 posCount;        /* position in bytes of the tape */
56
57     /* the next three fields are used for modeling tape usage */
58     afs_uint32 nBytes;          /* number of bytes   written */
59     afs_uint32 kBytes;          /* number of Kbytes  written */
60     afs_int32 nRecords;         /* number of records written */
61     afs_int32 nFiles;           /* number of files   written */
62
63     /* These fields provide the coefficients for the above variables */
64     afs_int32 recordSize;       /* bytes per record */
65     afs_uint32 tapeSize;        /* length of tape */
66     afs_int32 coefBytes;        /* length multiplier for bytes */
67     afs_int32 coefRecords;      /*   ditto  records */
68     afs_int32 coefFiles;        /*   ditto  files */
69     int simultaneousTapes;      /* number of tapes mounted simultaneously */
70     int status;                 /* status of tape */
71     int flags;                  /* e.g. read-only, sequential */
72     char *tcRock;               /* for random tape coordinator storage */
73     char *tmRock;               /* for random tape module storage */
74     afs_int32 sizeflags;        /* What the units of tape size are. */
75
76     afs_int32 debug;            /* print debugging info */
77     afs_int32 error;            /* Error code from butm module */
78     afs_int32 spare[8];
79 };
80
81 struct tapeConfig {
82     char device[256];
83     afs_uint32 capacity;
84     afs_int32 fileMarkSize;     /* size of file marks, in bytes */
85     afs_int32 portOffset;
86 };
87
88 /* returns answer in bytes */
89 #define butm_remainingSpace(i) (1024*((i)->tapeSize - (1024*(i)->kBytes*(i)->coefBytes + (i)->Bytes*(i)->coefBytes )))
90
91 /* returns answer in kbytes */
92 #define butm_remainingKSpace(i) ((i)->tapeSize - ((i)->kBytes*(i)->coefBytes ))
93
94 #define BUTM_STATUS_OFFLINE (1<<0)      /* tape not mounted */
95 #define BUTM_STATUS_TAPEERROR (1<<1)    /* tape error encountered */
96 #define BUTM_STATUS_WRITEERROR (1<<2)   /* tape error during write */
97 #define BUTM_STATUS_READERROR (1<<3)    /* tape error during read */
98 #define BUTM_STATUS_SEEKERROR (1<<4)    /* tape error during positioning */
99 #define BUTM_STATUS_EOF (1<<5)  /* tape at EOF */
100 #define BUTM_STATUS_EOD (1<<6)  /* end of tape reached */
101
102 #define BUTM_FLAGS_READONLY (1<<0)      /* tape mounted read-only */
103 #define BUTM_FLAGS_SEQUENTIAL (1<<1)    /* tape is sequential access: sort positions */
104
105 struct butm_tapeLabel {
106     afs_int32 structVersion;    /* structure version number */
107     Date creationTime;          /* when tape was first labeled */
108     Date expirationDate;        /* when tape can be relabelled */
109     char AFSName[BU_MAXTAPELEN];        /* AFS assigned tape name */
110     struct ktc_principal creator;       /* person creating tape */
111     char cell[BU_MAXCELLLEN];   /* cell which owns tape. */
112     afs_uint32 dumpid;          /* which dump on this tape  */
113     afs_int32 useCount;         /* # times written */
114     afs_int32 spare[8];
115     char comment[96];
116     char pName[BU_MAXTAPELEN];  /* permanent user assigned tape name */
117     afs_uint32 size;
118     char dumpPath[BU_MAX_DUMP_PATH];    /* dump schedule path name */
119 };
120
121 #define TNAME(labelptr) \
122    ( strcmp((labelptr)->pName,"") ? (labelptr)->pName : \
123      ( strcmp((labelptr)->AFSName,"") ? (labelptr)->AFSName : "<NULL>" ) )
124
125 #define TAPENAME(tapename, name, dbDumpId) \
126    if (!strcmp("", name)) \
127      sprintf(tapename, "<NULL>"); \
128    else if (dbDumpId == 0) \
129      sprintf(tapename, "%s", name); \
130    else \
131      sprintf(tapename, "%s (%u)", name, dbDumpId);
132
133 #define LABELNAME(tapename, labelptr) \
134    TAPENAME(tapename, TNAME(labelptr), (labelptr)->dumpid)
135
136 /* now the procedure macros */
137 #define butm_Mount(i,t) (*((i)->ops.mount))(i,t)
138 #define butm_Dismount(i) (*((i)->ops.dismount))(i)
139 #define butm_Create(i,l,r) (*((i)->ops.create))(i,l,r)
140 #define butm_ReadLabel(i,l,r) (*((i)->ops.readLabel))(i,l,r)
141 #define butm_Seek(i,p) (*((i)->ops.seek))(i,p)
142 #define butm_SeekEODump(i,p) (*((i)->ops.seekEODump))(i,p)
143 #define butm_ReadFileBegin(i) (*((i)->ops.readFileBegin))(i)
144 #define butm_ReadFileData(i,d,l,n) (*((i)->ops.readFileData))(i,d,l,n)
145 #define butm_ReadFileEnd(i) (*((i)->ops.readFileEnd))(i)
146 #define butm_WriteFileBegin(i) (*((i)->ops.writeFileBegin))(i)
147 #define butm_WriteFileData(i,d,b,l) (*((i)->ops.writeFileData))(i,d,b,l)
148 #define butm_WriteFileEnd(i) (*((i)->ops.writeFileEnd))(i)
149 #define butm_WriteEOT(i) (*((i)->ops.writeEOT))(i)
150 #define butm_SetSize(i,s) (*((i)->ops.setSize))(i,s)
151 #define butm_GetSize(i,s) (*((i)->ops.getSize))(i,s)