diff options
-rw-r--r-- | src/H5Apublic.h | 1 | ||||
-rw-r--r-- | src/H5D.c | 440 | ||||
-rw-r--r-- | src/H5Dprivate.h | 35 | ||||
-rw-r--r-- | src/H5M.c | 19 |
4 files changed, 208 insertions, 287 deletions
diff --git a/src/H5Apublic.h b/src/H5Apublic.h index 115153c..3823b28 100644 --- a/src/H5Apublic.h +++ b/src/H5Apublic.h @@ -32,7 +32,6 @@ typedef enum { H5_DATASPACE, /* Group ID for Dataspace objects */ H5_DATASET, /* Group ID for Dataset objects */ H5_DIRECTORY, /* Group ID for Directory objects */ - H5_OID, /* Group ID for OID objects */ MAXGROUP /* Highest group in group_t (Invalid as true group) */ } group_t; @@ -34,13 +34,14 @@ static char RcsId[] = "@(#)$Revision$"; #include <H5private.h> /* Generic Functions */ #include <H5Aprivate.h> /* Atoms */ -#include <H5Mprivate.h> /* Meta-Object API */ #include <H5Dprivate.h> /* Dataset functions */ #include <H5Eprivate.h> /* Error handling */ -#include <H5Mprivate.h> /* Meta data */ #include <H5Gprivate.h> /* Group headers */ -#include <H5Oprivate.h> /* Object headers */ +#include <H5Mprivate.h> /* Meta data */ #include <H5MFprivate.h> /* File space allocation header */ +#include <H5MMprivate.h> /* Memory management */ +#include <H5Mprivate.h> /* Meta-Object API */ +#include <H5Oprivate.h> /* Object headers */ #define PABLO_MASK H5D_mask @@ -68,7 +69,6 @@ static herr_t H5D_init_interface(void) FUNC_ENTER (H5D_init_interface, NULL, FAIL); /* Initialize the atom group for the file IDs */ - ret_value=H5Ainit_group(H5_OID,H5A_OID_HASHSIZE,0); ret_value=H5Ainit_group(H5_DATASET,H5A_DATASETID_HASHSIZE,H5D_RESERVED_ATOMS); FUNC_LEAVE(ret_value); @@ -87,37 +87,42 @@ static herr_t H5D_init_interface(void) RETURNS Returns ID (atom) on success, FAIL on failure DESCRIPTION - This function actually creates the dataset object. + This function actually creates the dataset object, but it cannot be + accessed by name until it is stored in the file. --------------------------------------------------------------------------*/ hatom_t H5D_create(hatom_t owner_id, hobjtype_t type, const char *name) { - H5D_dataset_t *new_dset; /* new dataset object to create */ + H5D_t *new_dset; /* new dataset object to create */ hatom_t ret_value = SUCCEED; + hdf5_file_t *file = NULL; FUNC_ENTER(H5D_create, H5D_init_interface, FAIL); /* Clear errors and check args and all the boring stuff. */ H5ECLEAR; + /* Convert atom arguments to pointers */ + if(H5Aatom_group(owner_id)!=H5_FILE) + HGOTO_ERROR(H5E_ATOM, H5E_BADTYPE, FAIL); + file = H5Aatom_object (owner_id); + /* Allocate space for the new dataset */ - if((new_dset=HDmalloc(sizeof(H5D_dataset_t)))==NULL) + if((new_dset=HDcalloc(1, sizeof(H5D_t)))==NULL) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL); /* Initialize the dataset object */ - if(H5Aatom_group(owner_id)!=H5_FILE) - HGOTO_ERROR(H5E_ATOM, H5E_BADTYPE, FAIL); - new_dset->file=H5Aatom_object(owner_id); - if((new_dset->name=HDmalloc(sizeof(H5O_name_t)))==NULL) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL); - new_dset->name->s=HDstrdup(name); /* make a copy of the dataset name */ - new_dset->modified=BTRUE; /* Yep, we're new... */ - new_dset->type=NULL; - new_dset->dim=NULL; - new_dset->header=(-1); /* don't know where we are... */ - new_dset->data=(-1); /* don't know where we should put the data, either... */ + new_dset->file = file; + new_dset->name = H5MM_xstrdup (name); + new_dset->cwd = file->root_sym; + new_dset->ent.header = -1; /* Not on disk yet */ + new_dset->ent.type = H5G_NOTHING_CACHED; + new_dset->type=NULL; /* No type yet */ + new_dset->dim=NULL; /* No dimensions yet */ + new_dset->data_addr = -1; /* No data yet */ + new_dset->modified=BTRUE; /* Yep, we're new */ /* Register the new datatype and get an ID for it */ - if((ret_value=H5Aregister_atom(H5_DATASET, (const VOIDP)new_dset))==FAIL) + if((ret_value=H5Aregister_atom(H5_DATASET, (const VOIDP)new_dset))<0) HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL); done: @@ -133,82 +138,14 @@ done: /*-------------------------------------------------------------------------- NAME - H5D_access - PURPOSE - Start access to an existing HDF5 dataset object - USAGE - hatom_t H5D_access(oid) - hatom_t oid; IN: Atom for OID of dataset - RETURNS - Returns ID (atom) on success, FAIL on failure - DESCRIPTION - This function initiates access to a dataset object. ---------------------------------------------------------------------------*/ -hatom_t H5D_access(hatom_t oid) -{ - H5D_dataset_t *dset; /* dataset object to access */ - H5D_oid_t *ohdr; /* OID for reference to dataset */ - H5O_std_store_t store; /* standard storage info */ - hatom_t ret_value = SUCCEED; - - FUNC_ENTER(H5D_access, H5D_init_interface, FAIL); - - /* Clear errors and check args and all the boring stuff. */ - H5ECLEAR; - - /* Go get the OID for the dataset */ - if((ohdr=H5Aatom_object(oid))==NULL) - HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL); - - /* Allocate space for the dataset */ - if((dset=HDmalloc(sizeof(H5D_dataset_t)))==NULL) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL); - - /* Pull information about the dataset out of the file */ - dset->file=H5Aatom_object(ohdr->fid); /* Get the pointer to the file for the dataset */ - /* Get the dataset's name */ - if((dset->name=H5O_read(dset->file,ohdr->ohdr,&ohdr->ent,H5O_NAME,0,NULL))==NULL) - HGOTO_ERROR(H5E_OHDR, H5E_NOTFOUND, FAIL); - dset->modified=BFALSE; /* nothing changed yet */ - /* Get the dataset's type (currently only atomic types) */ - if((dset->type=H5O_read(dset->file,ohdr->ohdr,&ohdr->ent,H5O_SIM_DTYPE,0,NULL))==NULL) - HGOTO_ERROR(H5E_OHDR, H5E_NOTFOUND, FAIL); - /* Get the dataset's dimensionality (currently only simple dataspaces) */ - if((dset->dim=HDmalloc(sizeof(H5P_dim_t)))==NULL) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL); - dset->dim->type=H5P_TYPE_SIMPLE; /* for now... */ - if((dset->dim->s=H5O_read(dset->file,ohdr->ohdr,&ohdr->ent,H5O_SIM_DIM,0,NULL))==NULL) - HGOTO_ERROR(H5E_OHDR, H5E_NOTFOUND, FAIL); - dset->header=ohdr->ohdr; /* keep the object header location for later */ - /* Get the dataset's data offset (currently only standard storage) */ - if(NULL==H5O_read(dset->file,ohdr->ohdr,&ohdr->ent,H5O_STD_STORE,0,&store)) - HGOTO_ERROR(H5E_OHDR, H5E_NOTFOUND, FAIL); - dset->data=store.off; - - /* Register the new datatype and get an ID for it */ - if((ret_value=H5Aregister_atom(H5_DATASET, (const VOIDP)dset))==FAIL) - HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL); - -done: - if(ret_value == FAIL) - { /* Error condition cleanup */ - - } /* end if */ - - /* Normal function cleanup */ - - FUNC_LEAVE(ret_value); -} /* end H5D_access() */ - -/*-------------------------------------------------------------------------- - NAME H5D_find_name PURPOSE Get the OID for accessing an existing HDF5 dataset object USAGE hoid_t H5D_find_name(grp_id, type, name) hatom_t grp_id; IN: Atom for directory to search for dataset - hobjtype_t type; IN: Type of object to search for (dataset in this case) + hobjtype_t type; IN: Type of object to search for (dataset in + this case) const char *name; IN: Name of the object to search for RETURNS Returns ID (atom) on success, FAIL on failure @@ -218,41 +155,73 @@ done: hatom_t H5D_find_name(hatom_t grp_id, hobjtype_t type, const char *name) { hdf5_file_t *file; /* Pointer to the file-store of this object */ - H5D_oid_t *ohdr; /* OID for reference to dataset */ + H5D_t *dset = NULL; /* The dataset */ hatom_t ret_value = SUCCEED; + H5O_std_store_t store; FUNC_ENTER(H5D_find_name, H5D_init_interface, FAIL); /* Clear errors and check args and all the boring stuff. */ H5ECLEAR; - /* Allocate space for the dataset */ - if((ohdr=HDmalloc(sizeof(H5D_oid_t)))==NULL) - HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL); - - /* Get directory symbols, etc... */ + /* Convert atom arguments to pointers */ if(H5Aatom_group(grp_id)!=H5_FILE) HGOTO_ERROR(H5E_ATOM, H5E_BADTYPE, FAIL); file=H5Aatom_object(grp_id); + + /* Allocate space for the dataset */ + if(NULL==(dset=HDcalloc(1, sizeof(H5D_t)))) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL); + + /* Initialize file, directory, name fields */ + dset->modified = FALSE; + dset->file = file; + dset->name = H5MM_xstrdup (name); /* WARNING! WARNING! WARNING! */ /* The following line explicitly uses the root symbol as the current working directory. This should be changed to something more appropriate and is only hacked in here to get the prototype working. -QAK */ /* WARNING! WARNING! WARNING! */ - if(H5G_find(file,file->root_sym,&(ohdr->dir),name,&(ohdr->ent))==FAIL) + dset->cwd = file->root_sym; + + /* Get the dataset's symbol table entry */ + if (H5G_find (dset->file, dset->cwd, NULL, dset->name, &(dset->ent))<0) HGOTO_ERROR(H5E_DATASET, H5E_NOTFOUND, FAIL); - ohdr->fid=grp_id; - ohdr->ohdr=ohdr->ent.header; + + /* Get the dataset's type (currently only atomic types) */ + if (NULL==(dset->type=H5O_read (dset->file, dset->ent.header, &(dset->ent), + H5O_SIM_DTYPE, 0, NULL))) + HGOTO_ERROR(H5E_OHDR, H5E_NOTFOUND, FAIL); + /* Get the dataset's dimensionality (currently only simple dataspaces) */ + if((dset->dim=HDmalloc(sizeof(H5P_dim_t)))==NULL) + HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL); + dset->dim->type=H5P_TYPE_SIMPLE; /* for now... */ + if (NULL==(dset->dim->s=H5O_read (dset->file, dset->ent.header, + &(dset->ent), H5O_SIM_DIM, 0, NULL))) + HGOTO_ERROR(H5E_OHDR, H5E_NOTFOUND, FAIL); + + /* Get the dataset's data offset (currently only standard storage) */ + if (NULL==H5O_read (dset->file, dset->ent.header ,&(dset->ent), + H5O_STD_STORE, 0, &store)) + HGOTO_ERROR(H5E_OHDR, H5E_NOTFOUND, FAIL); + dset->data_addr=store.off; + /* Register the new OID and get an ID for it */ - if((ret_value=H5Aregister_atom(H5_OID, (const VOIDP)ohdr))==FAIL) + if((ret_value=H5Aregister_atom(H5_DATASET, (const VOIDP)dset))==FAIL) HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL); done: if(ret_value == FAIL) { /* Error condition cleanup */ - + if (dset) { + dset->name = H5MM_xfree (dset->name); +#ifdef LATER + /* We might need to free the `type' and `dim' fields also... */ +#endif + H5MM_xfree (dset); + } } /* end if */ /* Normal function cleanup */ @@ -277,8 +246,8 @@ done: --------------------------------------------------------------------------*/ herr_t H5Dset_info(hatom_t oid, hatom_t tid, hatom_t did) { - H5D_dataset_t *dataset; /* dataset object to modify */ - herr_t ret_value = SUCCEED; + H5D_t *dataset = NULL; /* dataset object to modify */ + herr_t ret_value = SUCCEED; FUNC_ENTER(H5Dset_info, H5D_init_interface, FAIL); @@ -293,7 +262,7 @@ herr_t H5Dset_info(hatom_t oid, hatom_t tid, hatom_t did) if((dataset=H5Aatom_object(oid))==NULL) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL); /* Check that the datatype & dataspace haven't already been initialized */ - if(dataset->type!=0 || dataset->dim!=0) + if(dataset->type || dataset->dim) HGOTO_ERROR(H5E_FUNC, H5E_ALREADYINIT, FAIL); dataset->type=H5Aatom_object(tid); @@ -330,7 +299,7 @@ done: --------------------------------------------------------------------------*/ herr_t H5Dget_info(hatom_t oid, hatom_t *tid, hatom_t *sid) { - H5D_dataset_t *dataset; /* dataset object to query */ + H5D_t *dataset; /* dataset object to query */ herr_t ret_value = SUCCEED; FUNC_ENTER(H5Dget_info, H5D_init_interface, FAIL); @@ -345,13 +314,13 @@ herr_t H5Dget_info(hatom_t oid, hatom_t *tid, hatom_t *sid) /* Get the object */ if((dataset=H5Aatom_object(oid))==NULL) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL); - /* Check that the datatype & dataspace haven't already been initialized */ + /* Check that the datatype & dataspace have already been initialized */ if(dataset->type==NULL || dataset->dim==NULL) HGOTO_ERROR(H5E_DATASET, H5E_UNINITIALIZED, FAIL); - if((*tid=H5Aregister_atom(H5_DATATYPE, (const VOIDP)dataset->type))==FAIL) + if((*tid=H5Aregister_atom(H5_DATATYPE, (const VOIDP)(dataset->type)))<0) HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL); - if((*sid=H5Aregister_atom(H5_DATASPACE, (const VOIDP)dataset->dim))==FAIL) + if((*sid=H5Aregister_atom(H5_DATASPACE, (const VOIDP)(dataset->dim)))<0) HGOTO_ERROR(H5E_ATOM, H5E_CANTREGISTER, FAIL); done: @@ -378,7 +347,7 @@ done: RETURNS SUCCEED/FAIL DESCRIPTION - This function reads dataset object data to the file. The dataspace + This function reads dataset object data from the file. The dataspace ID determines the slice/hyper-slab/portion of the dataset to write. H5P_SCALAR is a special value which indicates that the entire dataset is to be written out. (For datasets which have a scalar dataspace for the @@ -386,7 +355,7 @@ done: --------------------------------------------------------------------------*/ herr_t H5Dread(hatom_t oid, hatom_t did, VOIDP buf) { - H5D_dataset_t *dataset; /* dataset object to do I/O on */ + H5D_t *dataset; /* dataset object to do I/O on */ void *readbuf; /* pointer to buffer to write out */ uintn free_buf=0; /* if temporary conversion buffer needs to be free'd */ uintn toread; /* number of bytes to read in */ @@ -408,7 +377,7 @@ herr_t H5Dread(hatom_t oid, hatom_t did, VOIDP buf) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL); /* Check that the datatype & dataspace have already been initialized */ - if(dataset->type==NULL || dataset->dim==NULL || dataset->data==(-1)) + if(dataset->type==NULL || dataset->dim==NULL || dataset->data_addr<0) HGOTO_ERROR(H5E_FUNC, H5E_UNINITIALIZED, FAIL); /* Compute the number of bytes to read */ @@ -429,8 +398,8 @@ herr_t H5Dread(hatom_t oid, hatom_t did, VOIDP buf) readbuf=buf; - /* Write the data out to disk */ - if(H5F_block_read(dataset->file,dataset->data,toread,readbuf)==FAIL) + /* Read data from disk */ + if(H5F_block_read(dataset->file,dataset->data_addr,toread,readbuf)==FAIL) HGOTO_ERROR(H5E_IO, H5E_READERROR, FAIL); if(free_buf!=0) @@ -470,7 +439,7 @@ done: --------------------------------------------------------------------------*/ herr_t H5Dwrite(hatom_t oid, hatom_t did, VOIDP buf) { - H5D_dataset_t *dataset; /* dataset object to do I/O on */ + H5D_t *dataset; /* dataset object to do I/O on */ uintn towrite; /* number of bytes to write out */ void *writebuf; /* pointer to buffer to write out */ uintn free_buf=0; /* if temporary conversion buffer needs to be free'd */ @@ -491,7 +460,7 @@ herr_t H5Dwrite(hatom_t oid, hatom_t did, VOIDP buf) if((dataset=H5Aatom_object(oid))==NULL) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL); - /* Check that the datatype & dataspace haven't already been initialized */ + /* Check that the datatype & dataspace have already been initialized */ if(dataset->type==NULL || dataset->dim==NULL) HGOTO_ERROR(H5E_FUNC, H5E_UNINITIALIZED, FAIL); @@ -502,9 +471,11 @@ herr_t H5Dwrite(hatom_t oid, hatom_t did, VOIDP buf) HGOTO_ERROR(H5E_INTERNAL, H5E_UNSUPPORTED, FAIL); /* Check if we have space for the dataset yet */ - if(dataset->data==(-1)) - if((dataset->data=H5MF_alloc(dataset->file,towrite))==FAIL) + if(dataset->data_addr<0) { + if((dataset->data_addr=H5MF_alloc(dataset->file,towrite))<0) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, FAIL); + dataset->modified = TRUE; + } /* Check memory to disk datatype conversions, etc. */ /* This is totally hacked up code, but I'm in a hurry. ;-/ -QAK */ @@ -519,7 +490,7 @@ herr_t H5Dwrite(hatom_t oid, hatom_t did, VOIDP buf) writebuf=buf; /* Write the data out to disk */ - if(H5F_block_write(dataset->file,dataset->data,towrite,writebuf)==FAIL) + if(H5F_block_write(dataset->file,dataset->data_addr,towrite,writebuf)<0) HGOTO_ERROR(H5E_IO, H5E_WRITEERROR, FAIL); done: @@ -553,9 +524,11 @@ done: --------------------------------------------------------------------------*/ herr_t H5D_flush(hatom_t oid) { - H5D_dataset_t *dataset; /* dataset object to release */ - herr_t ret_value = SUCCEED; - H5G_entry_t d_sym; + H5D_t *dataset; /* dataset object to release */ + herr_t ret_value = SUCCEED; + intn mesg_sequence = 0; /*message sequence number */ + hbool_t new_dataset; /*is this a new dataset on disk?*/ + hbool_t entry_changed = FALSE; /*did symbol table entry change?*/ FUNC_ENTER(H5D_flush, H5D_init_interface, FAIL); @@ -566,125 +539,96 @@ herr_t H5D_flush(hatom_t oid) if((dataset=H5Aatom_object(oid))==NULL) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL); - /* Check if we have information to flush to the file... */ if (dataset->modified) { - if (dataset->header<=0) { - /* - * Create the object header. - */ - if ((dataset->header = H5O_new (dataset->file, 0, H5D_MINHDR_SIZE))<0) { - HGOTO_ERROR (H5E_SYM, H5E_CANTINIT, FAIL); /*can't create header*/ - } - - /* - * Start creating the symbol table entry. Inserting messages - * into the header may cache things in this entry. - */ - d_sym.header = dataset->header; - d_sym.type = H5G_NOTHING_CACHED; - - /* - * Write the necessary messages to the header. - */ - /* Write the dataset's name */ - if(dataset->name!=NULL) - { - if(H5O_modify(dataset->file,dataset->header,&d_sym,NULL,H5O_NAME,H5O_NEW_MESG,dataset->name)==FAIL) - HGOTO_ERROR (H5E_INTERNAL, H5E_CANTCREATE, FAIL); - } /* end if */ - /* Check if this dataset has an "atomic" datatype */ - if(BTRUE==H5T_is_atomic(dataset->type)) - { - if(H5O_modify(dataset->file,dataset->header,&d_sym,NULL,H5O_SIM_DTYPE,H5O_NEW_MESG,dataset->type)==FAIL) - HGOTO_ERROR (H5E_INTERNAL, H5E_CANTCREATE, FAIL); - } /* end if */ - else - { /* if it's not an atomic datatype, fail for right now */ - HGOTO_ERROR (H5E_INTERNAL, H5E_UNSUPPORTED, FAIL); - } /* end else */ - /* Check if this dataset has "simple" dimensionality */ - if(BTRUE==H5P_is_simple(dataset->dim)) - { - if(H5O_modify(dataset->file,dataset->header,&d_sym,NULL,H5O_SIM_DIM,H5O_NEW_MESG,dataset->dim->s)==FAIL) - HGOTO_ERROR (H5E_INTERNAL, H5E_CANTCREATE, FAIL); - } /* end if */ - else - { /* if it's not an atomic datatype, fail for right now */ - HGOTO_ERROR (H5E_INTERNAL, H5E_UNSUPPORTED, FAIL); - } /* end else */ - /* Write the dataset's storage information */ - if(dataset->data>0) - { - H5O_std_store_t store; /* standard storage info */ - - store.len=H5T_size(dataset->type,BTRUE)*H5P_nelem(dataset->dim); - store.off=dataset->data; - if(H5O_modify(dataset->file,dataset->header,&d_sym,NULL,H5O_STD_STORE,H5O_NEW_MESG,&store)==FAIL) - HGOTO_ERROR (H5E_INTERNAL, H5E_CANTCREATE, FAIL); - } /* end if */ - - /* - * Give the object header a name so others can access it. - */ -#if 1 /* SEE_BELOW */ - d_sym.type = H5G_NOTHING_CACHED; -#endif - - /* - * Give the object header a name so others can access it. - */ - if (H5G_insert (dataset->file, dataset->file->root_sym, NULL, dataset->name->s, - &d_sym)<0) { - HGOTO_ERROR (H5E_SYM, H5E_CANTINIT, FAIL); /*can't name header*/ - } - - - } else { - /* - * Update existing header messages if necessary. If updating the - * header messages changes the symbol table entry because new - * info is cached, then we must re-insert the symbol entry into - * the directory. - */ - hbool_t entry_changed = FALSE; - -/*------------------------------------------------------------------------- - * Quincey, you can get rid of this statement if either of the - * following are true: You don't change any messages or the - * changed messages aren't cached in the symbol table entry. - *------------------------------------------------------------------------- - */ - if (H5G_find (dataset->file, dataset->file->root_sym, NULL, dataset->name->s, &d_sym)<0) { - HGOTO_ERROR (H5E_SYM, H5E_CANTINIT, FAIL); - } - - /* - * Change any messaages that need to be updated. - */ - -#if 0 - H5O_modify (dataset->file, d_sym.header, &d_sym, &entry_changed, - H5O_WHATEVER, 0, &the_message); - H5O_modify (dataset->file, d_sym.header, &d_sym, &entry_changed, - H5O_WHATEVER, 0, &the_message); - H5O_modify (dataset->file, d_sym.header, &d_sym, &entry_changed, - H5O_WHATEVER, 0, &the_message); -#endif - -/*------------------------------------------------------------------------- - * Quincey, you can get rid of this `if' statement and the - * H5G_modify() call subject to the same constraints as above. - *------------------------------------------------------------------------- - */ - if (entry_changed) { - /* - * Make sure the symbol table entry as modified by the - * changing of messages gets back to the file. - */ - H5G_modify (dataset->file, dataset->file->root_sym, NULL, dataset->name->s, &d_sym); - } - } - dataset->modified = FALSE; + /* + * A new dataset is one which doesn't exist on disk yet. + */ + new_dataset = (dataset->ent.header < 0); + + + /* + * If the dataset is new then create an object header for it. Set the + * message sequence numbers to H5O_NEW_MESSAGE so we create new + * messages instead of trying to modify existing messages. + */ + if (new_dataset) { + dataset->ent.type = H5G_NOTHING_CACHED; + if ((dataset->ent.header = H5O_new (dataset->file, 0, + H5D_MINHDR_SIZE))<0) { + /* Can't create header. */ + HGOTO_ERROR (H5E_SYM, H5E_CANTINIT, FAIL); + } + mesg_sequence = H5O_NEW_MESG; + } + + + /* + * Create or update messages for this dataset. Begin with the + * type information. + */ + if (H5T_is_atomic (dataset->type)) { + if (H5O_modify (dataset->file, dataset->ent.header, + &(dataset->ent), &entry_changed, H5O_SIM_DTYPE, + mesg_sequence, dataset->type)<0) { + /* Can't create/update type message */ + HGOTO_ERROR (H5E_INTERNAL, H5E_CANTCREATE, FAIL); + } + } else { + /* Not an atomic datatype */ + HGOTO_ERROR (H5E_INTERNAL, H5E_UNSUPPORTED, FAIL); + } + + /* + * Write the dimensionality information. + */ + if (H5P_is_simple (dataset->dim)) { + if (H5O_modify (dataset->file, dataset->ent.header, + &(dataset->ent), &entry_changed, H5O_SIM_DIM, + mesg_sequence, dataset->dim->s)<0) { + /* Can't create/update dimensionality message */ + HGOTO_ERROR (H5E_INTERNAL, H5E_CANTCREATE, FAIL); + } + } else { + /* Not an atomic datatype */ + HGOTO_ERROR (H5E_INTERNAL, H5E_UNSUPPORTED, FAIL); + } + + /* + * Write the dataset's storage information. + */ + if (dataset->data_addr>=0) { + H5O_std_store_t store; /* standard storage info */ + + store.len = H5T_size (dataset->type, BTRUE) * + H5P_nelem (dataset->dim); + store.off = dataset->data_addr; + if (H5O_modify (dataset->file, dataset->ent.header, + &(dataset->ent), &entry_changed, H5O_STD_STORE, + mesg_sequence, &store)<0) { + /* Can't create/modify storage information */ + HGOTO_ERROR (H5E_INTERNAL, H5E_CANTCREATE, FAIL); + } + } + + /* + * If this is a new dataset then we must give it a name so others can + * access it. + */ + if (new_dataset) { + assert (dataset->name); + if (H5G_insert (dataset->file, dataset->cwd, NULL, + dataset->name, &(dataset->ent))<0) { + /* Can't name dataset */ + HGOTO_ERROR (H5E_SYM, H5E_CANTINIT, FAIL); + } + } else if (entry_changed) { + if (H5G_modify (dataset->file, dataset->cwd, NULL, + dataset->name, &(dataset->ent))<0) { + /* Can't update symbol table entry */ + HGOTO_ERROR (H5E_SYM, H5E_CANTINIT, FAIL); + } + } + dataset->modified = FALSE; /*it's clean now*/ } done: @@ -713,8 +657,8 @@ done: --------------------------------------------------------------------------*/ herr_t H5D_release(hatom_t oid) { - H5D_dataset_t *dataset; /* dataset object to release */ - herr_t ret_value = SUCCEED; + H5D_t *dataset; /* dataset object to release */ + herr_t ret_value = SUCCEED; FUNC_ENTER(H5D_release, H5D_init_interface, FAIL); @@ -726,16 +670,14 @@ herr_t H5D_release(hatom_t oid) HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL); /* Check if we have information to flush to the file... */ - if(dataset->modified==BTRUE) - H5D_flush(oid); - + if(dataset->modified && H5D_flush(oid)<0) { + /* Can't flush dataset */ + HGOTO_ERROR (H5E_OHDR, H5E_CANTFLUSH, FAIL); + } + /* release the memory used for the dataset */ - if(dataset->name!=NULL) - { - HDfree(dataset->name->s); - HDfree(dataset->name); - } /* end if */ - HDfree(dataset); + dataset->name = H5MM_xfree (dataset->name); + H5MM_xfree (dataset); /* Delete the dataset from the atom group */ if(H5Aatom_object(oid)==NULL) diff --git a/src/H5Dprivate.h b/src/H5Dprivate.h index beb982e..f0a08a2 100644 --- a/src/H5Dprivate.h +++ b/src/H5Dprivate.h @@ -28,24 +28,21 @@ #include <H5Pprivate.h> /* for the H5P_sdim_t type */ #include <H5Oprivate.h> /* Object Headers */ -/* Define a struct to carry all the information required to look up an object header */ -typedef struct { - hatom_t fid; /* File Id for object */ - haddr_t ohdr; /* Offset of the object header */ - H5G_entry_t dir; /* directory entry for the directory the object is located in */ - H5G_entry_t ent; /* directory entry for the object itself */ - } H5D_oid_t; - -typedef struct { - hdf5_file_t *file; /* Pointer to the file-store of this object */ - H5O_name_t *name; /* Name of dataset */ - hbool_t modified; /* Whether the dataset has been modified from version on disk */ - h5_datatype_t *type; /* Pointer to datatype of the dataset */ - H5P_dim_t *dim; /* Pointer to dimensionality of the dataset */ - haddr_t header; /* offset of the object header for this dataset */ - haddr_t data; /* offset of the data in the file */ - } H5D_dataset_t; - +/* + * A dataset is the following struct. It can exist in memory without + * existing in a file. + */ +typedef struct H5D_t { + hdf5_file_t *file; /* File store for this object */ + char *name; /* Name of dataset, relative or absolute */ + H5G_entry_t *cwd; /* Directory for relative name lookup */ + H5G_entry_t ent; /* Cached object header stuff */ + h5_datatype_t *type; /* Datatype of this dataset */ + H5P_dim_t *dim; /* Dimensionality of this dataset */ + haddr_t data_addr; /* Data storage address */ + hbool_t modified; /* Is memory out of data wrt file? */ +} H5D_t; + #define H5D_RESERVED_ATOMS 0 /* Set the minimum object header size to create objects with */ @@ -53,7 +50,7 @@ typedef struct { /*-----------------_-- Local function prototypes ----------------------------*/ hatom_t H5D_create(hatom_t owner_id, hobjtype_t type, const char *name); -hatom_t H5D_access(hatom_t oid); +hatom_t H5D_access_by_name (hatom_t owner_id, const char *name); hatom_t H5D_find_name(hatom_t owner_id, hobjtype_t type, const char *name); herr_t H5D_flush(hatom_t oid); herr_t H5D_release(hatom_t oid); @@ -115,7 +115,7 @@ static meta_func_t meta_func_arr[]={ { /* Dataset object meta-functions (defined in H5D.c) */ H5_DATASET, /* Dataset Type ID */ H5D_create, /* Dataset Create */ - H5D_access, /* Dataset Access */ + NULL, /* Dataset Access */ NULL, /* Dataset Copy */ H5D_find_name, /* Dataset FindName */ NULL, /* Dataset NameLen */ @@ -129,23 +129,6 @@ static meta_func_t meta_func_arr[]={ NULL, /* Dataset GetFile */ H5D_release /* Dataset Release */ }, - { /* Dataset object meta-functions (defined in H5D.c) */ - H5_OID, /* OID Type ID */ - NULL, /* OID Create */ - H5D_access, /* OID Access (calls dataset access routine) */ - NULL, /* OID Copy */ - NULL, /* OID FindName */ - NULL, /* OID NameLen */ - NULL, /* OID GetName */ - NULL, /* OID SetName */ - NULL, /* OID Search */ - NULL, /* OID Index */ - NULL, /* OID Flush */ - NULL, /* OID Delete */ - NULL, /* OID GetParent */ - NULL, /* OID GetFile */ - NULL /* OID Release */ - } }; /*------------------_-- Local function prototypes ----------------------------*/ |