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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* 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://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*-------------------------------------------------------------------------
*
* Created: H5Glink.c
* Nov 13 2006
* Quincey Koziol <koziol@hdfgroup.org>
*
* Purpose: Functions for handling links in groups.
*
*-------------------------------------------------------------------------
*/
/****************/
/* Module Setup */
/****************/
#define H5G_PACKAGE /*suppress error about including H5Gpkg */
/***********/
/* Headers */
/***********/
#include "H5private.h" /* Generic Functions */
#include "H5Eprivate.h" /* Error handling */
#include "H5Gpkg.h" /* Groups */
#include "H5HLprivate.h" /* Local Heaps */
#include "H5Iprivate.h" /* IDs */
#include "H5Lprivate.h" /* Links */
#include "H5MMprivate.h" /* Memory management */
#include "H5Ppublic.h" /* Property Lists */
/****************/
/* Local Macros */
/****************/
/******************/
/* Local Typedefs */
/******************/
/********************/
/* Package Typedefs */
/********************/
/********************/
/* Local Prototypes */
/********************/
/*********************/
/* Package Variables */
/*********************/
/*****************************/
/* Library Private Variables */
/*****************************/
/*******************/
/* Local Variables */
/*******************/
/*-------------------------------------------------------------------------
* Function: H5G_link_cmp_name_inc
*
* Purpose: Callback routine for comparing two link names, in
* increasing alphabetic order
*
* Return: An integer less than, equal to, or greater than zero if the
* first argument is considered to be respectively less than,
* equal to, or greater than the second. If two members compare
* as equal, their order in the sorted array is undefined.
* (i.e. same as strcmp())
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* Sep 5 2005
*
*-------------------------------------------------------------------------
*/
int
H5G_link_cmp_name_inc(const void *lnk1, const void *lnk2)
{
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5G_link_cmp_name_inc)
FUNC_LEAVE_NOAPI(HDstrcmp(((const H5O_link_t *)lnk1)->name, ((const H5O_link_t *)lnk2)->name))
} /* end H5G_link_cmp_name_inc() */
/*-------------------------------------------------------------------------
* Function: H5G_link_cmp_name_dec
*
* Purpose: Callback routine for comparing two link names, in
* decreasing alphabetic order
*
* Return: An integer less than, equal to, or greater than zero if the
* second argument is considered to be respectively less than,
* equal to, or greater than the first. If two members compare
* as equal, their order in the sorted array is undefined.
* (i.e. opposite strcmp())
*
* Programmer: Quincey Koziol
* koziol@ncsa.uiuc.edu
* Sep 25 2006
*
*-------------------------------------------------------------------------
*/
int
H5G_link_cmp_name_dec(const void *lnk1, const void *lnk2)
{
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5G_link_cmp_name_dec)
FUNC_LEAVE_NOAPI(HDstrcmp(((const H5O_link_t *)lnk2)->name, ((const H5O_link_t *)lnk1)->name))
} /* end H5G_link_cmp_name_dec() */
/*-------------------------------------------------------------------------
* Function: H5G_link_cmp_corder_inc
*
* Purpose: Callback routine for comparing two link creation orders, in
* increasing order
*
* Return: An integer less than, equal to, or greater than zero if the
* first argument is considered to be respectively less than,
* equal to, or greater than the second. If two members compare
* as equal, their order in the sorted array is undefined.
*
* Programmer: Quincey Koziol
* koziol@hdfgroup.org
* Nov 6 2006
*
*-------------------------------------------------------------------------
*/
int
H5G_link_cmp_corder_inc(const void *lnk1, const void *lnk2)
{
int ret_value; /* Return value */
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5G_link_cmp_corder_inc)
if(((const H5O_link_t *)lnk1)->corder < ((const H5O_link_t *)lnk2)->corder)
ret_value = -1;
else if(((const H5O_link_t *)lnk1)->corder > ((const H5O_link_t *)lnk2)->corder)
ret_value = 1;
else
ret_value = 0;
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5G_link_cmp_corder_inc() */
/*-------------------------------------------------------------------------
* Function: H5G_link_cmp_corder_dec
*
* Purpose: Callback routine for comparing two link creation orders, in
* decreasing order
*
* Return: An integer less than, equal to, or greater than zero if the
* second argument is considered to be respectively less than,
* equal to, or greater than the first. If two members compare
* as equal, their order in the sorted array is undefined.
*
* Programmer: Quincey Koziol
* koziol@hdfgroup.org
* Nov 6 2006
*
*-------------------------------------------------------------------------
*/
int
H5G_link_cmp_corder_dec(const void *lnk1, const void *lnk2)
{
int ret_value; /* Return value */
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5G_link_cmp_corder_dec)
if(((const H5O_link_t *)lnk1)->corder < ((const H5O_link_t *)lnk2)->corder)
ret_value = 1;
else if(((const H5O_link_t *)lnk1)->corder > ((const H5O_link_t *)lnk2)->corder)
ret_value = -1;
else
ret_value = 0;
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5G_link_cmp_corder_dec() */
/*-------------------------------------------------------------------------
* Function: H5G_ent_to_link
*
* Purpose: Convert a symbol table entry to a link
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* koziol@hdfgroup.org
* Sep 16 2006
*
*-------------------------------------------------------------------------
*/
herr_t
H5G_ent_to_link(H5F_t *f, H5O_link_t *lnk, const H5HL_t *heap,
const H5G_entry_t *ent, const char *name)
{
FUNC_ENTER_NOAPI_NOFUNC(H5G_ent_to_link)
/* check arguments */
HDassert(f);
HDassert(lnk);
HDassert(heap);
HDassert(ent);
HDassert(name);
/* Set (default) common info for link */
lnk->cset = H5F_DEFAULT_CSET;
lnk->corder = 0;
lnk->corder_valid = FALSE; /* Creation order not valid for this link */
lnk->name = H5MM_xstrdup(name);
HDassert(lnk->name);
/* Object is a symbolic or hard link */
if(ent->type == H5G_CACHED_SLINK) {
const char *s; /* Pointer to link value */
s = (const char *)H5HL_offset_into(f, heap, ent->cache.slink.lval_offset);
HDassert(s);
/* Copy the link value */
lnk->u.soft.name = H5MM_xstrdup(s);
/* Set link type */
lnk->type = H5L_TYPE_SOFT;
} /* end if */
else {
/* Set address of object */
lnk->u.hard.addr = ent->header;
/* Set link type */
lnk->type = H5L_TYPE_HARD;
} /* end else */
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5G_ent_to_link() */
/*-------------------------------------------------------------------------
* Function: H5G_ent_to_info
*
* Purpose: Make link info for a symbol table entry
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* koziol@hdfgroup.org
* Nov 16 2006
*
*-------------------------------------------------------------------------
*/
herr_t
H5G_ent_to_info(H5F_t *f, H5L_info_t *info, const H5HL_t *heap,
const H5G_entry_t *ent)
{
FUNC_ENTER_NOAPI_NOFUNC(H5G_ent_to_info)
/* check arguments */
HDassert(f);
HDassert(info);
HDassert(heap);
HDassert(ent);
/* Set (default) common info for info */
info->cset = H5F_DEFAULT_CSET;
info->corder = 0;
info->corder_valid = FALSE; /* Creation order not valid for this link */
/* Object is a symbolic or hard link */
if(ent->type == H5G_CACHED_SLINK) {
const char *s; /* Pointer to link value */
s = (const char *)H5HL_offset_into(f, heap, ent->cache.slink.lval_offset);
HDassert(s);
/* Get the link value size */
info->u.val_size = HDstrlen(s) + 1;
/* Set link type */
info->type = H5L_TYPE_SOFT;
} /* end if */
else {
/* Set address of object */
info->u.address = ent->header;
/* Set link type */
info->type = H5L_TYPE_HARD;
} /* end else */
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5G_ent_to_info() */
/*-------------------------------------------------------------------------
* Function: H5G_link_to_info
*
* Purpose: Retrieve information from a link object
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* Tuesday, November 7 2006
*
*-------------------------------------------------------------------------
*/
herr_t
H5G_link_to_info(const H5O_link_t *lnk, H5L_info_t *info)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5G_link_to_info, FAIL)
/* Sanity check */
HDassert(lnk);
/* Get information from the link */
if(info) {
info->cset = lnk->cset;
info->corder = lnk->corder;
info->corder_valid = lnk->corder_valid;
info->type = lnk->type;
switch(lnk->type) {
case H5L_TYPE_HARD:
info->u.address = lnk->u.hard.addr;
break;
case H5L_TYPE_SOFT:
info->u.val_size = HDstrlen(lnk->u.soft.name) + 1; /*count the null terminator*/
break;
default:
{
const H5L_class_t *link_class; /* User-defined link class */
if(lnk->type < H5L_TYPE_UD_MIN || lnk->type > H5L_TYPE_MAX)
HGOTO_ERROR(H5E_LINK, H5E_BADTYPE, FAIL, "unknown link class")
/* User-defined link; call its query function to get the link udata size. */
/* Get the link class for this type of link. It's okay if the class
* isn't registered, though--we just can't give any more information
* about it
*/
link_class = H5L_find_class(lnk->type);
if(link_class != NULL && link_class->query_func != NULL) {
ssize_t cb_ret; /* Return value from UD callback */
/* Call the link's query routine to retrieve the user-defined link's value size */
/* (in case the query routine packs/unpacks the link value in some way that changes its size) */
if((cb_ret = (link_class->query_func)(lnk->name, lnk->u.ud.udata, lnk->u.ud.size, NULL, (size_t)0)) < 0)
HGOTO_ERROR(H5E_LINK, H5E_CALLBACK, FAIL, "query buffer size callback returned failure")
info->u.val_size = (size_t)cb_ret;
} /* end if */
else
info->u.val_size = 0;
} /* end case */
} /* end switch */
} /* end if */
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5G_link_to_info() */
/*-------------------------------------------------------------------------
* Function: H5G_link_to_loc
*
* Purpose: Build group location from group and link object
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* Monday, November 20 2006
*
*-------------------------------------------------------------------------
*/
herr_t
H5G_link_to_loc(const H5G_loc_t *grp_loc, const H5O_link_t *lnk,
H5G_loc_t *obj_loc)
{
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5G_link_to_loc, FAIL)
/* Sanity check */
HDassert(grp_loc);
HDassert(lnk);
HDassert(obj_loc);
/*
* Build location from the link
*/
/* Check for unknown library-internal link */
if(lnk->type > H5L_TYPE_BUILTIN_MAX && lnk->type < H5L_TYPE_UD_MIN)
HGOTO_ERROR(H5E_SYM, H5E_UNSUPPORTED, FAIL, "unknown link type")
/* Build object's group hier. location */
if(H5G_name_set(grp_loc->path, obj_loc->path, lnk->name) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTINIT, FAIL, "cannot set name")
/* Set the object location, if it's a hard link set the address also */
obj_loc->oloc->file = grp_loc->oloc->file;
obj_loc->oloc->holding_file = FALSE;
if(lnk->type == H5L_TYPE_HARD)
obj_loc->oloc->addr = lnk->u.hard.addr;
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5G_link_to_loc() */
/*-------------------------------------------------------------------------
* Function: H5G_link_copy_file
*
* Purpose: Copy a link and the object it points to from one file to
* another.
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* koziol@hdfgroup.org
* Sep 29 2006
*
*-------------------------------------------------------------------------
*/
herr_t
H5G_link_copy_file(H5F_t *dst_file, hid_t dxpl_id, const H5O_link_t *_src_lnk,
const H5O_loc_t *src_oloc, H5O_link_t *dst_lnk, H5O_copy_t *cpy_info)
{
H5O_link_t tmp_src_lnk; /* Temporary copy of src link, when needed */
const H5O_link_t *src_lnk = _src_lnk; /* Source link */
hbool_t dst_lnk_init = FALSE; /* Whether the destination link is initialized */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5G_link_copy_file, FAIL)
/* check arguments */
HDassert(dst_file);
HDassert(src_lnk);
HDassert(dst_lnk);
HDassert(cpy_info);
/* Expand soft link */
if(H5L_TYPE_SOFT == src_lnk->type && cpy_info->expand_soft_link) {
H5O_info_t oinfo; /* Information about object pointed to by soft link */
H5G_loc_t grp_loc; /* Group location holding soft link */
H5G_name_t grp_path; /* Path for group holding soft link */
/* Make a temporary copy, so that it will not change the info in the cache */
if(NULL == H5O_msg_copy(H5O_LINK_ID, src_lnk, &tmp_src_lnk))
HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, H5_ITER_ERROR, "unable to copy message")
/* Set up group location for soft link to start in */
H5G_name_reset(&grp_path);
grp_loc.path = &grp_path;
grp_loc.oloc = (H5O_loc_t *)src_oloc; /* Casting away const OK -QAK */
/* Check if the object pointed by the soft link exists in the source file */
if(H5G_loc_info(&grp_loc, tmp_src_lnk.u.soft.name, FALSE, &oinfo, H5P_DEFAULT, dxpl_id) >= 0) {
/* Convert soft link to hard link */
tmp_src_lnk.u.soft.name = (char *)H5MM_xfree(tmp_src_lnk.u.soft.name);
tmp_src_lnk.type = H5L_TYPE_HARD;
tmp_src_lnk.u.hard.addr = oinfo.addr;
src_lnk = &tmp_src_lnk;
} /* end if */
else {
/* Discard any errors from a dangling soft link */
H5E_clear_stack(NULL);
/* Release any information copied for temporary src link */
H5O_msg_reset(H5O_LINK_ID, &tmp_src_lnk);
} /* end else */
} /* end if */
/* Copy src link information to dst link information */
if(NULL == H5O_msg_copy(H5O_LINK_ID, src_lnk, dst_lnk))
HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, H5_ITER_ERROR, "unable to copy message")
dst_lnk_init = TRUE;
/* Check if object in source group is a hard link & copy it */
if(H5L_TYPE_HARD == src_lnk->type) {
H5O_loc_t new_dst_oloc; /* Copied object location in destination */
H5O_loc_t tmp_src_oloc; /* Temporary object location for source object */
/* Set up copied object location to fill in */
H5O_loc_reset(&new_dst_oloc);
new_dst_oloc.file = dst_file;
/* Build temporary object location for source */
H5O_loc_reset(&tmp_src_oloc);
tmp_src_oloc.file = src_oloc->file;
HDassert(H5F_addr_defined(src_lnk->u.hard.addr));
tmp_src_oloc.addr = src_lnk->u.hard.addr;
/* Copy the shared object from source to destination */
if(H5O_copy_header_map(&tmp_src_oloc, &new_dst_oloc, dxpl_id, cpy_info, TRUE) < 0)
HGOTO_ERROR(H5E_OHDR, H5E_CANTCOPY, H5_ITER_ERROR, "unable to copy object")
/* Copy new destination object's information for eventual insertion */
dst_lnk->u.hard.addr = new_dst_oloc.addr;
} /* end if */
done:
/* Check if we used a temporary src link */
if(src_lnk != _src_lnk) {
HDassert(src_lnk == &tmp_src_lnk);
H5O_msg_reset(H5O_LINK_ID, &tmp_src_lnk);
} /* end if */
if(ret_value < 0)
if(dst_lnk_init)
H5O_msg_reset(H5O_LINK_ID, dst_lnk);
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5G_link_copy_file() */
/*-------------------------------------------------------------------------
* Function: H5G_link_sort_table
*
* Purpose: Sort table containing a list of links for a group
*
* Return: Success: Non-negative
* Failure: Negative
*
* Programmer: Quincey Koziol
* Nov 20, 2006
*
*-------------------------------------------------------------------------
*/
herr_t
H5G_link_sort_table(H5G_link_table_t *ltable, H5_index_t idx_type,
H5_iter_order_t order)
{
FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5G_link_sort_table)
/* Sanity check */
HDassert(ltable);
/* Pick appropriate sorting routine */
if(idx_type == H5_INDEX_NAME) {
if(order == H5_ITER_INC)
HDqsort(ltable->lnks, ltable->nlinks, sizeof(H5O_link_t), H5G_link_cmp_name_inc);
else if(order == H5_ITER_DEC)
HDqsort(ltable->lnks, ltable->nlinks, sizeof(H5O_link_t), H5G_link_cmp_name_dec);
else
HDassert(order == H5_ITER_NATIVE);
} /* end if */
else {
HDassert(idx_type == H5_INDEX_CRT_ORDER);
if(order == H5_ITER_INC)
HDqsort(ltable->lnks, ltable->nlinks, sizeof(H5O_link_t), H5G_link_cmp_corder_inc);
else if(order == H5_ITER_DEC)
HDqsort(ltable->lnks, ltable->nlinks, sizeof(H5O_link_t), H5G_link_cmp_corder_dec);
else
HDassert(order == H5_ITER_NATIVE);
} /* end else */
FUNC_LEAVE_NOAPI(SUCCEED)
} /* end H5G_link_sort_table() */
/*-------------------------------------------------------------------------
* Function: H5G_link_iterate_table
*
* Purpose: Iterate over table containing a list of links for a group,
* making appropriate callbacks
*
* Return: Success: Non-negative
* Failure: Negative
*
* Programmer: Quincey Koziol
* Nov 20, 2006
*
*-------------------------------------------------------------------------
*/
herr_t
H5G_link_iterate_table(const H5G_link_table_t *ltable, hsize_t skip,
hsize_t *last_lnk, const H5G_lib_iterate_t op, void *op_data)
{
size_t u; /* Local index variable */
herr_t ret_value = H5_ITER_CONT; /* Return value */
FUNC_ENTER_NOAPI_NOERR(H5G_link_iterate_table, -)
/* Sanity check */
HDassert(ltable);
HDassert(op);
/* Skip over links, if requested */
if(last_lnk)
*last_lnk += skip;
/* Iterate over link messages */
H5_ASSIGN_OVERFLOW(/* To: */ u, /* From: */ skip, /* From: */ hsize_t, /* To: */ size_t)
for(; u < ltable->nlinks && !ret_value; u++) {
/* Make the callback */
ret_value = (op)(&(ltable->lnks[u]), op_data);
/* Increment the number of entries passed through */
if(last_lnk)
(*last_lnk)++;
} /* end for */
/* Check for callback failure and pass along return value */
if(ret_value < 0)
HERROR(H5E_SYM, H5E_CANTNEXT, "iteration operator failed");
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5G_link_iterate_table() */
/*-------------------------------------------------------------------------
* Function: H5G_link_release_table
*
* Purpose: Release table containing a list of links for a group
*
* Return: Success: Non-negative
* Failure: Negative
*
* Programmer: Quincey Koziol
* Sep 6, 2005
*
*-------------------------------------------------------------------------
*/
herr_t
H5G_link_release_table(H5G_link_table_t *ltable)
{
size_t u; /* Local index variable */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI_NOINIT(H5G_link_release_table)
/* Sanity check */
HDassert(ltable);
/* Release link info, if any */
if(ltable->nlinks > 0) {
/* Free link message information */
for(u = 0; u < ltable->nlinks; u++)
if(H5O_msg_reset(H5O_LINK_ID, &(ltable->lnks[u])) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTFREE, FAIL, "unable to release link message")
/* Free table of links */
H5MM_xfree(ltable->lnks);
} /* end if */
else
HDassert(ltable->lnks == NULL);
done:
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5G_link_release_table() */
/*-------------------------------------------------------------------------
* Function: H5G_link_name_replace
*
* Purpose: Determine the type of object referred to (for hard links) or
* the link type (for soft links and user-defined links).
*
* Return: Non-negative on success/Negative on failure
*
* Programmer: Quincey Koziol
* koziol@hdfgroup.org
* Nov 13 2006
*
*-------------------------------------------------------------------------
*/
herr_t
H5G_link_name_replace(H5F_t *file, hid_t dxpl_id, H5RS_str_t *grp_full_path_r,
const H5O_link_t *lnk)
{
H5RS_str_t *obj_path_r = NULL; /* Full path for link being removed */
herr_t ret_value = SUCCEED; /* Return value */
FUNC_ENTER_NOAPI(H5G_link_name_replace, FAIL)
/* check arguments */
HDassert(file);
/* Search the open IDs and replace names for unlinked object */
if(grp_full_path_r) {
obj_path_r = H5G_build_fullpath_refstr_str(grp_full_path_r, lnk->name);
if(H5G_name_replace(lnk, H5G_NAME_DELETE, file, obj_path_r, NULL, NULL, dxpl_id) < 0)
HGOTO_ERROR(H5E_SYM, H5E_CANTDELETE, FAIL, "unable to replace name")
} /* end if */
done:
if(obj_path_r)
H5RS_decr(obj_path_r);
FUNC_LEAVE_NOAPI(ret_value)
} /* end H5G_link_name_replace() */
|