1 /*  $Id: cnfs-private.h 10397 2020-11-12 20:22:51Z iulius $
2 **
3 **  CNFS disk/file mode header file.
4 */
5 
6 #ifndef	CNFS_PRIVATE_H
7 #define CNFS_PRIVATE_H 1
8 
9 #include <sys/types.h>
10 #if HAVE_UNISTD_H
11 # include <unistd.h>
12 #endif
13 
14 #define _PATH_CYCBUFFCONFIG	"cycbuff.conf"
15 
16 /* Page boundary on which to mmap() the CNFS article usage header.  Should be
17    a multiple of the pagesize for all the architectures you expect might need
18    access to your CNFS buffer.  If you don't expect to share your buffer
19    across several platforms, you can use 'pagesize' here. */
20 #define	CNFS_HDR_PAGESIZE       16384
21 
22 #define	CNFS_MAGICV1	"Cycbuff"	/* CNFSMASIZ bytes */
23 #define	CNFS_MAGICV2	"CBuf1"		/* CNFSMASIZ bytes */
24 #define	CNFS_MAGICV3	"CBuf3"		/* CNFSMASIZ bytes */
25 #define	CNFS_MAGICV4	"CBuf4"		/* CNFSMASIZ bytes */
26 #define	CNFS_DFL_BLOCKSIZE	4096	/* Unit block size we'll work with */
27 #define	CNFS_MAX_BLOCKSIZE	16384	/* Max unit block size */
28 
29 /* Amount of data stored at beginning of CYCBUFF before the bitfield */
30 #define	CNFS_BEFOREBITF		512	/* Rounded up to CNFS_HDR_PAGESIZE */
31 
32 struct metacycbuff;		/* Definition comes below */
33 
34 #define	CNFSMAXCYCBUFFNAME	8
35 #define	CNFSMASIZ	8
36 #define	CNFSNASIZ	16	/* Effective size is 9, not 16 */
37 #define	CNFSPASIZ	64
38 #define	CNFSLASIZ	16	/* Match length of ASCII hex off_t
39 				   representation */
40 
41 typedef struct _CYCBUFF {
42   char		name[CNFSNASIZ];/* Symbolic name */
43   char		path[CNFSPASIZ];/* Path to file */
44   off_t         len;		/* Length of writable area, in bytes */
45   off_t         free;		/* Offset (relative to byte 0 of file) to first
46 				   freely available byte */
47   time_t	updated;	/* Time of last update to header */
48   int		fd;		/* file descriptor for this cycbuff */
49   uint32_t	cyclenum;	/* Number of current cycle, 0 = invalid */
50   int		magicver;	/* Magic version number */
51   void *	bitfield;	/* Bitfield for article in use */
52   off_t         minartoffset;	/* The minimum offset allowed for article
53 				   storage */
54   bool		needflush;	/* true if CYCBUFFEXTERN is needed to be
55 				   flushed */
56   int		blksz;		/* Blocksize */
57   struct _CYCBUFF	*next;
58   bool		currentbuff;	/* true if this cycbuff is currently used */
59   char		metaname[CNFSNASIZ];/* Symbolic name of meta */
60   int		order;		/* Order in meta, start from 1 not 0 */
61 } CYCBUFF;
62 
63 /*
64 ** A structure suitable for thwapping onto disk in a quasi-portable way.
65 ** We assume that sizeof(CYCBUFFEXTERN) < CNFS_BLOCKSIZE.
66 */
67 typedef struct {
68     char	magic[CNFSMASIZ];
69     char	name[CNFSNASIZ];
70     char	path[CNFSPASIZ];
71     char	lena[CNFSLASIZ];	/* ASCII version of len */
72     char	freea[CNFSLASIZ];	/* ASCII version of free */
73     char	updateda[CNFSLASIZ];	/* ASCII version of updated */
74     char	cyclenuma[CNFSLASIZ];	/* ASCII version of cyclenum */
75     char	metaname[CNFSNASIZ];
76     char	orderinmeta[CNFSLASIZ];
77     char	currentbuff[CNFSMASIZ];
78     char	blksza[CNFSLASIZ];	/* ASCII version of blksz */
79 } CYCBUFFEXTERN;
80 
81 #define METACYCBUFF_UPDATE	25
82 #define REFRESH_INTERVAL	30
83 
84 typedef enum {INTERLEAVE, SEQUENTIAL} METAMODE;
85 
86 typedef struct metacycbuff {
87   char		*name;		/* Symbolic name of the pool */
88   int		count;		/* Number of files/devs in this pool */
89   CYCBUFF	**members;	/* Member cycbuffs */
90   int		memb_next;	/* Index to next member to write onto */
91   unsigned long	write_count;	/* Number of writes since last header flush */
92   struct metacycbuff	*next;
93   METAMODE	metamode;
94 } METACYCBUFF;
95 
96 typedef struct _CNFSEXPIRERULES {
97   STORAGECLASS		class;
98   METACYCBUFF		*dest;
99   struct _CNFSEXPIRERULES	*next;
100 } CNFSEXPIRERULES;
101 
102 typedef struct {
103   long		size;		/* Size of the article */
104   time_t	arrived;	/* This is the time when article arrived */
105   STORAGECLASS	class;		/* storage class */
106 } CNFSARTHEADER;
107 
108 /* uncomment below for old cnfs spool */
109 /* #ifdef OLD_CNFS */
110 typedef struct {
111   long      zottf;      /* This should always be 0x01234*/
112   long      size;       /* Size of the article */
113   char      m_id[64];   /* We'll only store up to 63 bytes of the
114 	                       Message-ID, that should be good enough */
115 } oldCNFSARTHEADER;
116 
117 #endif /* !CNFS_PRIVATE_H */
118