1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Copyright by The HDF Group.                                               *
3  * Copyright by the Board of Trustees of the University of Illinois.         *
4  * All rights reserved.                                                      *
5  *                                                                           *
6  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
7  * terms governing use, modification, and redistribution, is contained in    *
8  * the COPYING file, which can be found at the root of the source code       *
9  * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
10  * If you do not have access to either file, you may request a copy from     *
11  * help@hdfgroup.org.                                                        *
12  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13 
14 /*
15  * Programmer: Quincey Koziol <koziol@ncsa.uiuc.edu>
16  *             Wednesday, July 9, 2003
17  *
18  * Purpose:     This file contains declarations which are visible
19  *              only within the H5HL package. Source files outside the
20  *              H5HL package should include H5HLprivate.h instead.
21  */
22 #ifndef H5HL_PACKAGE
23 #error "Do not include this file outside the H5HL package!"
24 #endif
25 
26 #ifndef _H5HLpkg_H
27 #define _H5HLpkg_H
28 
29 /* Get package's private header */
30 #include "H5HLprivate.h"
31 
32 /* Other private headers needed by this file */
33 #include "H5FLprivate.h"	/* Free lists                           */
34 
35 
36 /*****************************/
37 /* Package Private Variables */
38 /*****************************/
39 
40 /* The local heap prefix cache subclass */
41 H5_DLLVAR const H5AC_class_t H5AC_LHEAP_PRFX[1];
42 
43 /* The local heap data block cache subclass */
44 H5_DLLVAR const H5AC_class_t H5AC_LHEAP_DBLK[1];
45 
46 /* Declare extern the free list to manage the H5HL_free_t struct */
47 H5FL_EXTERN(H5HL_free_t);
48 
49 /* Declare extern the PQ free list to manage the heap chunk information */
50 H5FL_BLK_EXTERN(lheap_chunk);
51 
52 
53 /**************************/
54 /* Package Private Macros */
55 /**************************/
56 
57 #define H5HL_SIZEOF_HDR(F)						      \
58     H5HL_ALIGN(H5_SIZEOF_MAGIC +	/*heap signature		*/    \
59 	       1 +			/*version			*/    \
60 	       3 +			/*reserved			*/    \
61 	       H5F_SIZEOF_SIZE(F) +	/*data size			*/    \
62 	       H5F_SIZEOF_SIZE(F) +	/*free list head		*/    \
63 	       H5F_SIZEOF_ADDR(F))	/*data address			*/
64 
65 /* Value indicating end of free list on disk */
66 #define H5HL_FREE_NULL	1
67 
68 
69 /****************************/
70 /* Package Private Typedefs */
71 /****************************/
72 
73 typedef struct H5HL_free_t {
74     size_t		offset;		/*offset of free block		*/
75     size_t		size;		/*size of free block		*/
76     struct H5HL_free_t	*prev;		/*previous entry in free list	*/
77     struct H5HL_free_t	*next;		/*next entry in free list	*/
78 } H5HL_free_t;
79 
80 /* Forward declarations */
81 typedef struct H5HL_dblk_t H5HL_dblk_t;
82 typedef struct H5HL_prfx_t H5HL_prfx_t;
83 
84 struct H5HL_t {
85     /* General heap-management fields */
86     size_t                  rc;         /* Ref. count for prefix & data block using this struct */
87     size_t                  prots;      /* # of times the heap has been protected */
88     size_t                  sizeof_size; /* Size of file sizes */
89     size_t                  sizeof_addr; /* Size of file addresses */
90     hbool_t                 single_cache_obj;   /* Indicate if the heap is a single object in the cache */
91     H5HL_free_t		   *freelist;	/*the free list			*/
92 
93     /* Prefix-specific fields */
94     H5HL_prfx_t            *prfx;       /* The prefix object for the heap */
95     haddr_t                 prfx_addr;  /* address of heap prefix */
96     size_t                  prfx_size;  /* size of heap prefix */
97     hsize_t                 free_block; /* Address of first free block */
98 
99     /* Data block-specific fields */
100     H5HL_dblk_t            *dblk;       /* The data block object for the heap */
101     haddr_t		    dblk_addr;	/* address of data block	*/
102     size_t		    dblk_size;	/* size of heap data block on disk and in mem */
103     uint8_t		   *dblk_image;	/* The data block image */
104 };
105 
106 /* Struct for heap data block */
107 struct H5HL_dblk_t {
108     H5AC_info_t cache_info;    /* Information for H5AC cache functions, _must_ be */
109                                 /* first field in structure */
110     H5HL_t                 *heap;       /* Pointer to heap for data block */
111 };
112 
113 /* Struct for heap prefix */
114 struct H5HL_prfx_t {
115     H5AC_info_t cache_info;    /* Information for H5AC cache functions, _must_ be */
116                                 /* first field in structure */
117     H5HL_t                 *heap;       /* Pointer to heap for prefix */
118 };
119 
120 /* Callback information for loading local heap prefix from disk */
121 typedef struct H5HL_cache_prfx_ud_t {
122     /* Downwards */
123     size_t sizeof_size;                 /* Size of file sizes */
124     size_t sizeof_addr;                 /* Size of file addresses */
125     haddr_t prfx_addr;                  /* Address of prefix */
126     size_t sizeof_prfx;                 /* Size of heap prefix */
127 
128     /* Upwards */
129 } H5HL_cache_prfx_ud_t;
130 
131 /* Callback information for loading local heap data block from disk */
132 typedef struct H5HL_cache_dblk_ud_t {
133     /* Downwards */
134     H5HL_t *heap;                       /* Local heap */
135 
136     /* Upwards */
137     hbool_t loaded;                     /* Whether data block was loaded from file */
138 } H5HL_cache_dblk_ud_t;
139 
140 
141 /******************************/
142 /* Package Private Prototypes */
143 /******************************/
144 
145 /* Heap routines */
146 H5_DLL H5HL_t *H5HL_new(size_t sizeof_size, size_t sizeof_addr, size_t prfx_size);
147 H5_DLL herr_t H5HL_dest(H5HL_t *heap);
148 
149 /* Heap prefix routines */
150 H5_DLL H5HL_prfx_t *H5HL_prfx_new(H5HL_t *heap);
151 H5_DLL herr_t H5HL_prfx_dest(H5HL_prfx_t *prfx);
152 
153 /* Heap data block routines */
154 H5_DLL H5HL_dblk_t *H5HL_dblk_new(H5HL_t *heap);
155 H5_DLL herr_t H5HL_dblk_dest(H5HL_dblk_t *dblk);
156 
157 #endif /* _H5HLpkg_H */
158 
159