H5Apkg.h

00001 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
00002  * Copyright by The HDF Group.                                               *
00003  * Copyright by the Board of Trustees of the University of Illinois.         *
00004  * All rights reserved.                                                      *
00005  *                                                                           *
00006  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
00007  * terms governing use, modification, and redistribution, is contained in    *
00008  * the files COPYING and Copyright.html.  COPYING can be found at the root   *
00009  * of the source code distribution tree; Copyright.html can be found at the  *
00010  * root level of an installed copy of the electronic HDF5 document set and   *
00011  * is linked from the top-level documents page.  It can also be found at     *
00012  * http://hdfgroup.org/HDF5/doc/Copyright.html.  If you do not have          *
00013  * access to either file, you may request a copy from help@hdfgroup.org.     *
00014  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
00015 
00016 /*
00017  * Programmer:  Quincey Koziol
00018  *              Monday, Apr 20
00019  *
00020  * Purpose:     This file contains declarations which are visible only within
00021  *              the H5A package.  Source files outside the H5A package should
00022  *              include H5Aprivate.h instead.
00023  */
00024 #ifndef H5A_PACKAGE
00025 #error "Do not include this file outside the H5A package!"
00026 #endif
00027 
00028 #ifndef _H5Apkg_H
00029 #define _H5Apkg_H
00030 
00031 /*
00032  * Define this to enable debugging.
00033  */
00034 #ifdef NDEBUG
00035 #  undef H5A_DEBUG
00036 #endif
00037 
00038 /* Get package's private header */
00039 #include "H5Aprivate.h"
00040 
00041 /* Other private headers needed by this file */
00042 #include "H5B2private.h"        /* v2 B-trees                           */
00043 #include "H5FLprivate.h"        /* Free Lists                           */
00044 #include "H5HFprivate.h"        /* Fractal heaps                        */
00045 #include "H5Oprivate.h"         /* Object headers                       */
00046 #include "H5Sprivate.h"         /* Dataspace                            */
00047 #include "H5Tprivate.h"         /* Datatype functions                   */
00048 
00049 
00050 /**************************/
00051 /* Package Private Macros */
00052 /**************************/
00053 
00054 /* This is the initial version, which does not have support for shared datatypes */
00055 #define H5O_ATTR_VERSION_1      1
00056 
00057 /* This version allows support for shared datatypes & dataspaces by adding a
00058  *      'flag' byte indicating when those components are shared.  This version
00059  *      also dropped the alignment on all the components.
00060  */
00061 #define H5O_ATTR_VERSION_2      2
00062 
00063 /* Add support for different character encodings of attribute names */
00064 #define H5O_ATTR_VERSION_3      3
00065 
00066 /* The latest version of the format.  Look through the 'encode', 'decode'
00067  *      and 'size' message callbacks for places to change when updating this.
00068  */
00069 #define H5O_ATTR_VERSION_LATEST H5O_ATTR_VERSION_3
00070 
00071 
00072 /****************************/
00073 /* Package Private Typedefs */
00074 /****************************/
00075 /* Define the shared attribute structure */
00076 typedef struct H5A_shared_t {
00077     unsigned    version;    /* Version to encode attribute with */
00078     hbool_t     initialized;/* Indicate whether the attribute has been modified */
00079 
00080     char        *name;      /* Attribute's name */
00081     H5T_cset_t  encoding;   /* Character encoding of attribute name */
00082 
00083     H5T_t       *dt;        /* Attribute's datatype */
00084     size_t      dt_size;    /* Size of datatype on disk */
00085 
00086     H5S_t       *ds;        /* Attribute's dataspace */
00087     size_t      ds_size;    /* Size of dataspace on disk */
00088 
00089     void        *data;      /* Attribute data (on a temporary basis) */
00090     size_t      data_size;  /* Size of data on disk */
00091     H5O_msg_crt_idx_t crt_idx;  /* Attribute's creation index in the object header */
00092     unsigned    nrefs;          /* Ref count for times this object is refered   */
00093 } H5A_shared_t;
00094 
00095 /* Define the main attribute structure */
00096 struct H5A_t {
00097     H5O_shared_t sh_loc;     /* Shared message info (must be first) */
00098     H5O_loc_t    oloc;       /* Object location for object attribute is on */
00099     hbool_t      obj_opened; /* Object header entry opened? */
00100     H5G_name_t   path;       /* Group hierarchy path */
00101     H5A_shared_t *shared;    /* Shared attribute information */
00102 };
00103 
00104 /* Typedefs for "dense" attribute storage */
00105 /* (fractal heap & v2 B-tree info) */
00106 
00107 /* Typedef for native 'name' field index records in the v2 B-tree */
00108 /* (Keep 'id' field first so generic record handling in callbacks works) */
00109 typedef struct H5A_dense_bt2_name_rec_t {
00110     H5O_fheap_id_t id;                  /* Heap ID for attribute */
00111     uint8_t flags;                      /* Object header message flags for attribute */
00112     H5O_msg_crt_idx_t corder;           /* 'creation order' field value */
00113     uint32_t hash;                      /* Hash of 'name' field value */
00114 } H5A_dense_bt2_name_rec_t;
00115 
00116 /* Typedef for native 'creation order' field index records in the v2 B-tree */
00117 /* (Keep 'id' field first so generic record handling in callbacks works) */
00118 typedef struct H5A_dense_bt2_corder_rec_t {
00119     H5O_fheap_id_t id;                  /* Heap ID for attribute */
00120     uint8_t flags;                      /* Object header message flags for attribute */
00121     H5O_msg_crt_idx_t corder;           /* 'creation order' field value */
00122 } H5A_dense_bt2_corder_rec_t;
00123 
00124 /* Define the 'found' callback function pointer for matching an attribute record in a v2 B-tree */
00125 typedef herr_t (*H5A_bt2_found_t)(const H5A_t *attr, hbool_t *took_ownership, void *op_data);
00126 
00127 /*
00128  * Common data exchange structure for dense attribute storage.  This structure
00129  * is passed through the v2 B-tree layer to the methods for the objects
00130  * to which the v2 B-tree points.
00131  */
00132 typedef struct H5A_bt2_ud_common_t {
00133     /* downward */
00134     H5F_t       *f;                     /* Pointer to file that fractal heap is in */
00135     hid_t       dxpl_id;                /* DXPL for operation                */
00136     H5HF_t      *fheap;                 /* Fractal heap handle               */
00137     H5HF_t      *shared_fheap;          /* Fractal heap handle for shared messages */
00138     const char  *name;                  /* Name of attribute to compare      */
00139     uint32_t    name_hash;              /* Hash of name of attribute to compare */
00140     uint8_t     flags;                  /* Flags for attribute storage location */
00141     H5O_msg_crt_idx_t corder;           /* Creation order value of attribute to compare */
00142     H5A_bt2_found_t found_op;           /* Callback when correct attribute is found */
00143     void        *found_op_data;         /* Callback data when correct attribute is found */
00144 } H5A_bt2_ud_common_t;
00145 
00146 /*
00147  * Data exchange structure for dense attribute storage.  This structure is
00148  * passed through the v2 B-tree layer when inserting attributes.
00149  */
00150 typedef struct H5A_bt2_ud_ins_t {
00151     /* downward */
00152     H5A_bt2_ud_common_t common;         /* Common info for B-tree user data (must be first) */
00153     H5O_fheap_id_t id;                  /* Heap ID of attribute to insert    */
00154 } H5A_bt2_ud_ins_t;
00155 
00156 /* Data structure to hold table of attributes for an object */
00157 typedef struct {
00158     size_t      nattrs;         /* # of attributes in table */
00159     H5A_t       **attrs;        /* Pointer to array of attribute pointers */
00160 } H5A_attr_table_t;
00161 
00162 /* Attribute iteration operator for internal library callbacks */
00163 typedef herr_t (*H5A_lib_iterate_t)(const H5A_t *attr, void *op_data);
00164 
00165 /* Describe kind of callback to make for each attribute */
00166 struct H5A_attr_iter_op_t {
00167     enum {
00168 #ifndef H5_NO_DEPRECATED_SYMBOLS
00169         H5A_ATTR_OP_APP,                /* Application callback */
00170 #endif /* H5_NO_DEPRECATED_SYMBOLS */
00171         H5A_ATTR_OP_APP2,               /* Revised application callback */
00172         H5A_ATTR_OP_LIB                 /* Library internal callback */
00173     } op_type;
00174     union {
00175 #ifndef H5_NO_DEPRECATED_SYMBOLS
00176         H5A_operator1_t app_op;         /* Application callback for each attribute */
00177 #endif /* H5_NO_DEPRECATED_SYMBOLS */
00178         H5A_operator2_t app_op2;        /* Revised application callback for each attribute */
00179         H5A_lib_iterate_t lib_op;       /* Library internal callback for each attribute */
00180     } u;
00181 };
00182 
00183 
00184 /*****************************/
00185 /* Package Private Variables */
00186 /*****************************/
00187 
00188 /* Declare extern the free list for H5A_t's */
00189 H5FL_EXTERN(H5A_t);
00190 
00191 /* Declare the external free lists for H5A_shared_t's */
00192 H5FL_EXTERN(H5A_shared_t);
00193 
00194 /* Declare extern a free list to manage blocks of type conversion data */
00195 H5FL_BLK_EXTERN(attr_buf);
00196 
00197 /* The v2 B-tree class for indexing 'name' field on attributes */
00198 H5_DLLVAR const H5B2_class_t H5A_BT2_NAME[1];
00199 
00200 /* The v2 B-tree class for indexing 'creation order' field on attributes */
00201 H5_DLLVAR const H5B2_class_t H5A_BT2_CORDER[1];
00202 
00203 
00204 /******************************/
00205 /* Package Private Prototypes */
00206 /******************************/
00207 
00208 /* Function prototypes for H5A package scope */
00209 H5_DLL herr_t H5A_init(void);
00210 H5_DLL hid_t H5A_create(const H5G_loc_t *loc, const char *name,
00211     const H5T_t *type, const H5S_t *space, hid_t acpl_id, hid_t dxpl_id);
00212 H5_DLL H5A_t * H5A_open_by_name(const H5G_loc_t *loc, const char *obj_name,
00213     const char *attr_name, hid_t lapl_id, hid_t dxpl_id);
00214 H5_DLL H5A_t *H5A_open_by_idx(const H5G_loc_t *loc, const char *obj_name,
00215     H5_index_t idx_type, H5_iter_order_t order, hsize_t n, hid_t lapl_id, hid_t dxpl_id);
00216 H5_DLL ssize_t H5A_get_name(H5A_t *attr, size_t buf_size, char *buf);
00217 H5_DLL H5A_t *H5A_copy(H5A_t *new_attr, const H5A_t *old_attr);
00218 H5_DLL herr_t H5A_get_info(const H5A_t *attr, H5A_info_t *ainfo);
00219 H5_DLL herr_t H5A_free(H5A_t *attr);
00220 H5_DLL herr_t H5A_close(H5A_t *attr);
00221 H5_DLL htri_t H5A_get_ainfo(H5F_t *f, hid_t dxpl_id, H5O_t *oh, H5O_ainfo_t *ainfo);
00222 H5_DLL herr_t H5A_set_version(const H5F_t *f, H5A_t *attr);
00223 
00224 /* Attribute "dense" storage routines */
00225 H5_DLL herr_t H5A_dense_create(H5F_t *f, hid_t dxpl_id, H5O_ainfo_t *ainfo);
00226 H5_DLL H5A_t *H5A_dense_open(H5F_t *f, hid_t dxpl_id, const H5O_ainfo_t *ainfo,
00227     const char *name);
00228 H5_DLL herr_t H5A_dense_insert(H5F_t *f, hid_t dxpl_id, const H5O_ainfo_t *ainfo,
00229     H5A_t *attr);
00230 H5_DLL herr_t H5A_dense_write(H5F_t *f, hid_t dxpl_id, const H5O_ainfo_t *ainfo,
00231     H5A_t *attr);
00232 H5_DLL herr_t H5A_dense_rename(H5F_t *f, hid_t dxpl_id, const H5O_ainfo_t *ainfo,
00233     const char *old_name, const char *new_name);
00234 H5_DLL herr_t H5A_dense_iterate(H5F_t *f, hid_t dxpl_id, hid_t loc_id,
00235     const H5O_ainfo_t *ainfo, H5_index_t idx_type, H5_iter_order_t order,
00236     hsize_t skip, hsize_t *last_attr, const H5A_attr_iter_op_t *attr_op,
00237     void *op_data);
00238 H5_DLL herr_t H5A_dense_remove(H5F_t *f, hid_t dxpl_id, const H5O_ainfo_t *ainfo,
00239     const char *name);
00240 H5_DLL herr_t H5A_dense_remove_by_idx(H5F_t *f, hid_t dxpl_id, const H5O_ainfo_t *ainfo,
00241     H5_index_t idx_type, H5_iter_order_t order, hsize_t n);
00242 H5_DLL htri_t H5A_dense_exists(H5F_t *f, hid_t dxpl_id, const H5O_ainfo_t *ainfo,
00243     const char *name);
00244 H5_DLL herr_t H5A_dense_delete(H5F_t *f, hid_t dxpl_id, H5O_ainfo_t *ainfo);
00245 
00246 
00247 /* Attribute table operations */
00248 H5_DLL herr_t H5A_compact_build_table(H5F_t *f, hid_t dxpl_id, H5O_t *oh,
00249     H5_index_t idx_type, H5_iter_order_t order, H5A_attr_table_t *atable);
00250 H5_DLL herr_t H5A_dense_build_table(H5F_t *f, hid_t dxpl_id,
00251     const H5O_ainfo_t *ainfo, H5_index_t idx_type, H5_iter_order_t order,
00252     H5A_attr_table_t *atable);
00253 H5_DLL herr_t H5A_attr_iterate_table(const H5A_attr_table_t *atable,
00254     hsize_t skip, hsize_t *last_attr, hid_t loc_id,
00255     const H5A_attr_iter_op_t *attr_op, void *op_data);
00256 H5_DLL herr_t H5A_attr_release_table(H5A_attr_table_t *atable);
00257 
00258 /* Attribute operations */
00259 H5_DLL herr_t H5O_attr_create(const H5O_loc_t *loc, hid_t dxpl_id, H5A_t *attr);
00260 H5_DLL H5A_t *H5O_attr_open_by_name(const H5O_loc_t *loc, const char *name,
00261     hid_t dxpl_id);
00262 H5_DLL H5A_t *H5O_attr_open_by_idx(const H5O_loc_t *loc, H5_index_t idx_type,
00263     H5_iter_order_t order, hsize_t n, hid_t dxpl_id);
00264 H5_DLL herr_t H5O_attr_update_shared(H5F_t *f, hid_t dxpl_id, H5O_t *oh,
00265         H5A_t *attr, H5O_shared_t *sh_mesg);
00266 H5_DLL herr_t H5O_attr_write(const H5O_loc_t *loc, hid_t dxpl_id,
00267     H5A_t *attr);
00268 H5_DLL herr_t H5O_attr_rename(const H5O_loc_t *loc, hid_t dxpl_id,
00269     const char *old_name, const char *new_name);
00270 H5_DLL herr_t H5O_attr_iterate(hid_t loc_id, hid_t dxpl_id, H5_index_t idx_type,
00271     H5_iter_order_t order, hsize_t skip, hsize_t *last_attr,
00272     const H5A_attr_iter_op_t *op, void *op_data);
00273 H5_DLL herr_t H5O_attr_remove(const H5O_loc_t *loc, const char *name,
00274     hid_t dxpl_id);
00275 H5_DLL herr_t H5O_attr_remove_by_idx(const H5O_loc_t *loc, H5_index_t idx_type,
00276     H5_iter_order_t order, hsize_t n, hid_t dxpl_id);
00277 H5_DLL htri_t H5O_attr_exists(const H5O_loc_t *loc, const char *name, hid_t dxpl_id);
00278 #ifndef H5_NO_DEPRECATED_SYMBOLS
00279 H5_DLL int H5O_attr_count(const H5O_loc_t *loc, hid_t dxpl_id);
00280 #endif /* H5_NO_DEPRECATED_SYMBOLS */
00281 H5_DLL H5A_t *H5A_attr_copy_file(const H5A_t *attr_src, H5F_t *file_dst, hbool_t *recompute_size,
00282     H5O_copy_t *cpy_info, hid_t dxpl_id);
00283 H5_DLL herr_t H5A_attr_post_copy_file(const H5O_loc_t *src_oloc, const H5A_t *mesg_src,
00284     H5O_loc_t *dst_oloc, const H5A_t *mesg_dst, hid_t dxpl_id, H5O_copy_t *cpy_info);
00285 H5_DLL herr_t H5A_dense_copy_file_all(H5F_t *file_src, H5O_ainfo_t *ainfo_src, H5F_t *file_dst, 
00286     const H5O_ainfo_t *ainfo_dst, hbool_t *recompute_size, H5O_copy_t *cpy_info, hid_t dxpl_id);
00287 H5_DLL herr_t H5A_dense_post_copy_file_all(const H5O_loc_t *src_oloc, const H5O_ainfo_t * ainfo_src,
00288     H5O_loc_t *dst_oloc, H5O_ainfo_t *ainfo_dst, hid_t dxpl_id, H5O_copy_t *cpy_info);
00289 
00290 
00291 /* Testing functions */
00292 #ifdef H5A_TESTING
00293 H5_DLL htri_t H5A_is_shared_test(hid_t aid);
00294 H5_DLL herr_t H5A_get_shared_rc_test(hid_t attr_id, hsize_t *ref_count);
00295 #endif /* H5A_TESTING */
00296 
00297 #endif /* _H5Apkg_H */
00298