summaryrefslogtreecommitdiffstats
path: root/src/H5FSprivate.h
blob: 2b840bdaf5b5f4e5e654dde195b099cdfc1ce381 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by the Board of Trustees of the University of Illinois.         *
 * All rights reserved.                                                      *
 *                                                                           *
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
 * terms governing use, modification, and redistribution, is contained in    *
 * the files COPYING and Copyright.html.  COPYING can be found at the root   *
 * of the source code distribution tree; Copyright.html can be found at the  *
 * root level of an installed copy of the electronic HDF5 document set and   *
 * is linked from the top-level documents page.  It can also be found at     *
 * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html.  If you do not have     *
 * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*-------------------------------------------------------------------------
 *
 * Created:		H5FSprivate.h
 *			May  2 2006
 *			Quincey Koziol <koziol@ncsa.uiuc.edu>
 *
 * Purpose:		Private header for library accessible file free space routines.
 *
 *-------------------------------------------------------------------------
 */

#ifndef _H5FSprivate_H
#define _H5FSprivate_H

/* Include package's public header */
#include "H5FSpublic.h"

/* Private headers needed by this file */
#include "H5Fprivate.h"		/* File access				*/
#include "H5FLprivate.h"	/* Free Lists                           */
#include "H5SLprivate.h"	/* Skip lists				*/

/**************************/
/* Library Private Macros */
/**************************/

/* Flags for H5FS_section_class_t 'flags' field */
#define H5FS_CLS_GHOST_OBJ      0x01    /* Objects in this class shouldn't be
                                         *      serialized to the file.
                                         */
#define H5FS_CLS_SEPAR_OBJ      0x02    /* Objects in this class shouldn't
                                         *      participate in merge operations
                                         */
#define H5FS_CLS_MERGE_SYM      0x04    /* Objects in this class only merge
                                         *      with other objects in this class
                                         */

/* Flags for H5FS_add() */
#define H5FS_ADD_DESERIALIZING  0x01    /* Free space is being deserialized
                                         */
#define H5FS_ADD_RETURNED_SPACE 0x02    /* Section was previously allocated
                                         *      and is being returned to the
                                         *      free space manager (usually
                                         *      as a result of freeing an
                                         *      object)
                                         */

/* Flags for deserialize callback  */
#define H5FS_DESERIALIZE_NO_ADD  0x01   /* Don't add section to free space
                                         *      manager after it's deserialized
                                         *      (its only here for it's side-
                                         *      effects).
                                         */


/****************************/
/* Library Private Typedefs */
/****************************/

/* Free space info (forward decl - defined in H5FSpkg.h) */
typedef struct H5FS_t H5FS_t;

/* Forward declaration free space section info */
typedef struct H5FS_section_info_t H5FS_section_info_t;

/* Free space section class info */
typedef struct H5FS_section_class_t {
    /* Class variables */
    const unsigned type;                /* Type of free space section */
    size_t serial_size;                 /* Size of serialized form of section */
    unsigned flags;                     /* Class flags */
    void *cls_private;                  /* Class private information */

    /* Class methods */
    herr_t (*init_cls)(struct H5FS_section_class_t *, void *);          /* Routine to initialize class-specific settings */
    herr_t (*term_cls)(struct H5FS_section_class_t *);                  /* Routine to terminate class-specific settings */

    /* Object methods */
    herr_t (*serialize)(const struct H5FS_section_class_t *, const H5FS_section_info_t *, uint8_t *);        /* Routine to serialize a "live" section into a buffer */
    H5FS_section_info_t *(*deserialize)(const struct H5FS_section_class_t *, hid_t dxpl_id, const uint8_t *, haddr_t, hsize_t, unsigned *);     /* Routine to deserialize a buffer into a "live" section */
    htri_t (*can_merge)(const H5FS_section_info_t *, const H5FS_section_info_t *, void *);  /* Routine to determine if two nodes are mergable */
    herr_t (*merge)(H5FS_section_info_t *, H5FS_section_info_t *, void *);      /* Routine to merge two nodes */
    htri_t (*can_shrink)(const H5FS_section_info_t *, void *);        /* Routine to determine if node can shrink container */
    herr_t (*shrink)(H5FS_section_info_t **, void *);   /* Routine to shrink container */
    herr_t (*free)(H5FS_section_info_t *);              /* Routine to free node */
    herr_t (*valid)(const struct H5FS_section_class_t *, const H5FS_section_info_t *);   /* Routine to check if a section is valid */
    herr_t (*debug)(const H5FS_section_info_t *, FILE *, int , int );   /* Routine to dump debugging information about a section */
} H5FS_section_class_t;

/* State of section ("live" or "serialized") */
typedef enum H5FS_section_state_t {
    H5FS_SECT_LIVE,             /* Section has "live" memory references */
    H5FS_SECT_SERIALIZED        /* Section is in "serialized" form */
} H5FS_section_state_t;

/* Free space section info */
struct H5FS_section_info_t {
    haddr_t     addr;                   /* Address of free space section in the address space */
    hsize_t     size;                   /* Size of free space section */
    unsigned    type;                   /* Type of free space section (i.e. class) */
    H5FS_section_state_t state;         /* Whether the section is in "serialized" or "live" form */
};

/* Free space client IDs for identifying user of free space */
typedef enum H5FS_client_t {
    H5FS_CLIENT_FHEAP_ID = 0,	/* Free space is used by fractal heap */
    H5FS_NUM_CLIENT_ID          /* Number of free space client IDs (must be last)   */
} H5FS_client_t;

/* Free space creation parameters */
typedef struct H5FS_create_t {
    H5FS_client_t client;               /* Client's ID */
    unsigned shrink_percent;            /* Percent of "normal" serialized size to shrink serialized space at */
    unsigned expand_percent;            /* Percent of "normal" serialized size to expand serialized space at */
    unsigned max_sect_addr;             /* Size of address space free sections are within (log2 of actual value) */
    hsize_t max_sect_size;              /* Maximum size of section to track */
} H5FS_create_t;

/* Typedef for iteration operations */
typedef herr_t (*H5FS_operator_t)(const H5FS_section_info_t *sect,
        void *operator_data/*in,out*/);


/*****************************/
/* Library-private Variables */
/*****************************/

/* Declare a free list to manage the H5FS_section_class_t sequence information */
H5FL_SEQ_EXTERN(H5FS_section_class_t);


/***************************************/
/* Library-private Function Prototypes */
/***************************************/
H5_DLL H5FS_t *H5FS_create(H5F_t *f, hid_t dxpl_id, haddr_t *fs_addr,
    const H5FS_create_t *fs_create, size_t nclasses,
    const H5FS_section_class_t *classes[], void *cls_init_udata);
H5_DLL H5FS_t *H5FS_open(H5F_t *f, hid_t dxpl_id, haddr_t fs_addr,
    size_t nclasses, const H5FS_section_class_t *classes[], void *cls_init_udata);
H5_DLL herr_t H5FS_add(H5F_t *f, hid_t dxpl_id, H5FS_t *fspace,
    H5FS_section_info_t *node, unsigned flags, void *op_data);
H5_DLL herr_t H5FS_remove(H5F_t *f, hid_t dxpl_id, H5FS_t *fspace,
    H5FS_section_info_t *node);
H5_DLL htri_t H5FS_find(H5F_t *f, hid_t dxpl_id, H5FS_t *fspace,
    hsize_t request, H5FS_section_info_t **node);
H5_DLL herr_t H5FS_iterate(H5F_t *f, hid_t dxpl_id, H5FS_t *fspace, H5FS_operator_t op, void *op_data);
H5_DLL herr_t H5FS_get_sect_count(const H5FS_t *fspace, hsize_t *nsects);
H5_DLL herr_t H5FS_sect_change_class(H5FS_t *fspace, H5FS_section_info_t *sect,
    unsigned new_class);
H5_DLL herr_t H5FS_flush(H5F_t *f, hid_t dxpl_id, unsigned flags);
H5_DLL herr_t H5FS_delete(H5F_t *f, hid_t dxpl_id, haddr_t fs_addr);
H5_DLL herr_t H5FS_close(H5F_t *f, hid_t dxpl_id, H5FS_t *fspace);

/* Debugging routines for dumping file structures */
H5_DLL herr_t H5FS_sect_debug(const H5FS_t *fspace, const H5FS_section_info_t *sect,
    FILE *stream, int indent, int fwidth);

H5_DLL herr_t H5FS_debug_test(const H5FS_t *fspace);
#endif /* _H5FSprivate_H */