This file is indexed.

/usr/include/hdf/hfile.h is in libhdf4-dev 4.2r4-12build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * Copyright by the Board of Trustees of the University of Illinois.         *
 * All rights reserved.                                                      *
 *                                                                           *
 * This file is part of HDF.  The full HDF 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      *
 * http://hdfgroup.org/products/hdf4/doc/Copyright.html.  If you do not have *
 * access to either file, you may request a copy from help@hdfgroup.org.     *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/* $Id: hfile.h 5167 2009-01-26 01:55:18Z epourmal $ */

/*+ hfile.h
   *** Header for hfile.c, routines for low level data element I/O
   + */

#ifndef HFILE_H
#define HFILE_H

#include "tbbt.h"
#include "bitvect.h"
#include "atom.h"
#include "linklist.h"
#include "dynarray.h"

/* Magic cookie for HDF data files */
#define MAGICLEN 4  /* length */
#define HDFMAGIC "\016\003\023\001"     /* ^N^C^S^A */

/* sizes of elements in a file.  This is necessary because
   the size of variables need not be the same as in the file
   (cannot use sizeof) */
#define DD_SZ 12    /* 2+2+4+4 */
#define NDDS_SZ 2
#define OFFSET_SZ 4

/* invalid offset & length to indicate a partially defined element 
* written to the HDF file i.e. can handle the case where the the
* element is defined but not written out */
#define INVALID_OFFSET -1
#define INVALID_LENGTH -1


/* ----------------------------- Version Tags ----------------------------- */
/* Library version numbers */

#define LIBVER_MAJOR    4
#define LIBVER_MINOR    2 
#define LIBVER_RELEASE  4 
#define LIBVER_STRING   "HDF Version 4.2 Release 4, January 25, 2009"
#define LIBVSTR_LEN    80   /* length of version string  */
#define LIBVER_LEN  92      /* 4+4+4+80 = 92 */
/* end of version tags */

/* -------------------------- File I/O Functions -------------------------- */
/* FILELIB -- file library to use for file access: 1 stdio, 2 fcntl
   default to stdio library i.e. UNIX buffered I/O */

#ifndef FILELIB
#   define FILELIB UNIXBUFIO    /* UNIX buffered I/O is the default */
#endif /* FILELIB */

#if (FILELIB == UNIXBUFIO)
/* using C buffered file I/O routines to access files */
#include <stdio.h>
typedef FILE *hdf_file_t;
#ifdef VMS
/* For VMS, use "mbc=64" to improve performance     */
#   define HI_OPEN(p, a)       (((a) & DFACC_WRITE) ? \
                                fopen((p), "r+", "mbc=64") : \
                                fopen((p), "r", "mbc=64"))
#   define HI_CREATE(p)        (fopen((p), "w+", "mbc=64"))
#else  /*  !VMS  */
#if defined SUN && defined (__GNUC__)
#   define HI_OPEN(p, a)       (((a) & DFACC_WRITE) ? \
                                fopen((p), "r+") : fopen((p), "r"))
#   define HI_CREATE(p)        (fopen((p), "w+"))
#else /* !SUN w/ GNU CC */
#   define HI_OPEN(p, a)       (((a) & DFACC_WRITE) ? \
                                fopen((p), "rb+") : fopen((p), "rb"))
#   define HI_CREATE(p)        (fopen((p), "wb+"))
#endif /* !SUN w/ GNU CC */
#endif /* VMS */
#   define HI_READ(f, b, n)    (((size_t)(n) == (size_t)fread((b), 1, (size_t)(n), (f))) ? \
                                SUCCEED : FAIL)
#   define HI_WRITE(f, b, n)   (((size_t)(n) == (size_t)fwrite((b), 1, (size_t)(n), (f))) ? \
                                SUCCEED : FAIL)
#   define HI_CLOSE(f)   (((f = ((fclose(f)==0) ? NULL : f))==NULL) ? SUCCEED:FAIL)
#   define HI_FLUSH(f)   (fflush(f)==0 ? SUCCEED : FAIL)
#   define HI_SEEK(f,o)  (fseek((f), (long)(o), SEEK_SET)==0 ? SUCCEED : FAIL)
#   define HI_SEEK_CUR(f,o)  (fseek((f), (long)(o), SEEK_CUR)==0 ? SUCCEED : FAIL)
#   define HI_SEEKEND(f) (fseek((f), (long)0, SEEK_END)==0 ? SUCCEED : FAIL)
#   define HI_TELL(f)    (ftell(f))
#   define OPENERR(f)    ((f) == (FILE *)NULL)
#endif /* FILELIB == UNIXBUFIO */

#if (FILELIB == UNIXUNBUFIO)
/* using UNIX unbuffered file I/O routines to access files */
typedef int hdf_file_t;
#   define HI_OPEN(p, a)       (((a) & DFACC_WRITE) ? \
                                    open((p), O_RDWR) : open((p), O_RDONLY))
#   define HI_CREATE(p)         (open((p), O_RDWR | O_CREAT | O_TRUNC, 0666))
#   define HI_CLOSE(f)          (((f = ((close(f)==0) ? NULL : f))==NULL) ? SUCCEED:FAIL)
#   define HI_FLUSH(f)          (SUCCEED)
#   define HI_READ(f, b, n)     (((n)==read((f), (char *)(b), (n))) ? SUCCEED : FAIL)
#   define HI_WRITE(f, b, n)    (((n)==write((f), (char *)(b), (n))) ? SUCCEED : FAIL)
#   define HI_SEEK(f, o)        (lseek((f), (off_t)(o), SEEK_SET)!=(-1) ? SUCCEED : FAIL)
#   define HI_SEEKEND(f)        (lseek((f), (off_t)0, SEEK_END)!=(-1) ? SUCCEED : FAIL)
#   define HI_TELL(f)           (lseek((f), (off_t)0, SEEK_CUR))
#   define OPENERR(f)           (f < 0)
#endif /* FILELIB == UNIXUNBUFIO */

#if (FILELIB == MACIO)
/* using special routines to redirect to Mac Toolkit I/O */
typedef short hdf_file_t;
#   define HI_OPEN(x,y)         mopen(x,y)
#   define HI_CREATE(name)      mopen(name, DFACC_CREATE)
#   define HI_CLOSE(x)          (((x = ((mclose(x)==0) ? NULL : x))==NULL) ? SUCCEED:FAIL)
#   define HI_FLUSH(a)          (SUCCEED)
#   define HI_READ(a,b,c)       mread(a, (char *) b, (int32) c)
#   define HI_WRITE(a,b,c)      mwrite(a, (char *) b, (int32) c)
#   define HI_SEEK(x,y)         mlseek(x, (int32 )y, 0)
#   define HI_SEEKEND(x)        mlseek(x, 0L, 2)
#   define HI_TELL(x)           mlseek(x,0L,1)
#   define DF_OPENERR(f)        ((f) == -1)
#   define OPENERR(f)           (f < 0)
#endif /* FILELIB == MACIO */

#ifdef NOT_USED     /* Deprecated routines, not supported any more */
#if (FILELIB == PCIO)
/* using special PC functions to enable reading/writing large chunks */
typedef FILE *hdf_file_t;
#   define HI_OPEN(p, a)       (((a) & DFACC_WRITE) ? \
                                fopen((p), "rb+") : fopen((p), "rb"))
#   define HI_CREATE(p)        (fopen((p), "wb+"))
/* Alias the HI_READ and HI_WRITE macros to functions which can handle */
/*  32-bits of data to read/write */
#   define HI_READ(f, b, n)    (((int32)(n) == HDfreadbig((b), (n), (f))) ? \
                                SUCCEED : FAIL)
#   define HI_WRITE(f, b, n)   (((int32)(n) == HDfwritebig((b), (n), (f))) ? \
                                SUCCEED : FAIL)
#   define HI_CLOSE(f)          (((f = ((fclose(f)==0) ? NULL : f))==NULL) ? SUCCEED:FAIL)
#   define HI_FLUSH(f)          (fflush(f)==0 ? SUCCEED : FAIL)
#   define HI_SEEK(f,o)  (fseek((f), (long)(o), SEEK_SET)==0 ? SUCCEED : FAIL)
#   define HI_SEEKEND(f) (fseek((f), (long)0, SEEK_END)==0 ? SUCCEED : FAIL)
#   define HI_TELL(f)           (ftell(f))
#   define OPENERR(f)           ((f) == (FILE *)NULL)
#endif /* FILELIB == PCIO */

#if (FILELIB == WINIO)
/* using special MS Windows functions to enable reading/writing large chunks */
typedef HFILE hdf_file_t;
#   define HI_OPEN(p, a)       (((a) & DFACC_WRITE) ? \
                                _lopen((p), READ_WRITE) : _lopen((p), READ))
#   define HI_CREATE(p)        (_lcreat((p), 0))
/* Alias the HI_READ and HI_WRITE macros to functions which can handle */
/*  32-bits of data to read/write */
#   define HI_READ(f, b, n)    (((int32)(n) == HDfreadbig((b), (n), (f))) ? \
                                SUCCEED : FAIL)
#   define HI_WRITE(f, b, n)   (((int32)(n) == HDfwritebig((b), (n), (f))) ? \
                                SUCCEED : FAIL)
#   define HI_CLOSE(f)          (((f = ((_lclose(f)==0) ? NULL : f))==NULL) ? SUCCEED:FAIL)
#   define HI_FLUSH(f)          (0)
#   define HI_SEEK(f, o)        (_llseek((f), (long)(o), SEEK_SET))
#   define HI_SEEKEND(f)        (_llseek((f), (long)0, SEEK_END))
#   define HI_TELL(f)           (_llseek((f),0l,SEEK_CUR))
#   define OPENERR(f)           ((f) == (HFILE)HFILE_ERROR)
#endif /* FILELIB == WINIO */

#if (FILELIB == WINNTIO)
/* using special Windows NT functions to enable reading/writing large chunks */
typedef HFILE hdf_file_t;
#   define HI_OPEN(p, a)       (((a) & DFACC_WRITE) ? \
                        _lopen((p), OF_READWRITE) : _lopen((p), OF_READ))
#   define HI_CREATE(p)        (_lcreat((p), 0))
#   define HI_READ(f, b, n)    (((int32)(n) == _hread((f), (b), (n))) ? \
                                SUCCEED : FAIL)
#   define HI_WRITE(f, b, n)   (((int32)(n) == _hwrite((f), (b), (n))) ? \
                                SUCCEED : FAIL)
#   define HI_CLOSE(f)         (((f = ((_lclose(f)==0) ? NULL : f))==NULL) ? SUCCEED:FAIL)
#   define HI_FLUSH(f) (0)
#   define HI_SEEK(f, o)       (_llseek((f), (long)(o), 0))
#   define HI_SEEKEND(f) (_llseek((f), (long)0, 2))
#   define HI_TELL(f)  (_llseek((f),0l,1))
#   define OPENERR(f)  ((f) == (HFILE)HFILE_ERROR)
#endif /* FILELIB == WINNTIO */
#endif /* NOT_USED */

#if (FILELIB == PAGEBUFIO)
#include "fmpio.h"
/* using page buffered file I/O routines to access files */
typedef MPFILE *hdf_file_t;
#   define HI_OPEN(p, a)        (MPopen((p), (a)))
#   define HI_CREATE(p)         (MPopen((p), DFACC_CREATE))
#   define HI_CLOSE(f)          (((f = ((MPclose(f)==0) ? NULL : f))==NULL) ? SUCCEED:FAIL)
#   define HI_FLUSH(f)          (MPflush(f))
#   define HI_READ(f, b, n)     (MPread((f), (char *)(b), (n)))
#   define HI_WRITE(f, b, n)    (MPwrite((f), (char *)(b), (n)))
#   define HI_SEEK(f, o)        (MPseek((f), (off_t)(o), SEEK_SET))
#   define HI_SEEKEND(f)        (MPseek((f), (off_t)0, SEEK_END))
#   define HI_TELL(f)           (MPseek((f), (off_t)0, SEEK_CUR))
#   define OPENERR(f)           ((f) == (MPFILE *)NULL)
#endif /* FILELIB == PAGEBUFIO */

/* ----------------------- Internal Data Structures ----------------------- */
/* The internal structure used to keep track of the files opened: an
   array of filerec_t structures, each has a linked list of ddblock_t.
   Each ddblock_t struct points to an array of dd_t structs. 

   File Header(4 bytes)
   ===================
   <--- 32 bits ----->
   ------------------
   |HDF magic number |
   ------------------

   HDF magic number - 0x0e031301 (Hexadecimal)

   Data Descriptor(DD - 12 bytes)
   ==============================
   <-  16 bits -> <- 16 bits -> <- 32 bits -> <- 32 bits ->
   --------------------------------------------------------
   |    Tag      | reference   |  Offset     |  Length    |
   |             | number      |             |            |
   --------------------------------------------------------
        \____________/
               V
        tag/ref (unique data indentifier in file)
   
   Tag  -- identifies the type of data, 16 bit unsigned integer whose
           value ranges from 1 - 65535. Tags are assigned by NCSA.
           The HDF tag space is divided as follows based on the 2 highest bits:

              00: NCSA reserved ordinary tags
              01: NCSA reserved special tags(i.e. regular tags made into 
                                                  linked-block, external, 
                                                  compressed or chunked.)
              10, 11: User tags.

           Current tag assingments are:
           00001 - 32767  - reserved for NCSA use
                            00001 - 16383 - NCSA regular tags
                            16384 - 32767 - NCSA special tags
           32768 - 64999  - user definable
           65000 - 65535  - reserved for expansion of format

   Refererence number - 16 bit unsigned integer whose assignment is not
          gauranteed to be consecutive. Provides a way to distinguish 
          elements with the same tag in the file.

   Offset - Specifies the byte offset of the data element from the 
            beginning of the file - 32 bit unsigned integer

   Length - Indicates the byte length of the data element
            32 bit unsigned integer

   Data Descriptor Header(DDH - 6 bytes)
   ====================================
   <-  16 bits -> <- 32 bits ->
   -----------------------------
   | Block Size  | Next Block  |
   -----------------------------

   Block Size - Indicates the number of DD's in the DD Block,
                16 bit unsigned integer value
   Next Block - Gives the offset of the next DD Block. The last DD Block has
                a ZERO(0) in the "Next Block" field in the DDH.
                32 bit unsigned integer value

   Data Descriptor Block(DDB - variable size)
   ==========================================
   <- DD Header -> <--------------- DD's --------------------->
   --------------------------------------------------------...-
   |Block | Next  | DD | DD | DD | DD | DD | DD | DD | DD |...|
   |Size  | Block |    |    |    |    |    |    |    |    |   |
   --------------------------------------------------------...-
   <-------------------------- DD Block ---------------------->

   Note: default number of DD's in a DD Block is 16

   HDF file layout
   =============================
   (one example)
   ---------------------------------------------------------------------
   | FH | DD Block | Data | DD Block | Data | DD Block | Data | .....
   ---------------------------------------------------------------------
 
*/

/* record of each data decsriptor */
typedef struct dd_t
  {
      uint16      tag;          /* Tag number of element i.e. type of data */
      uint16      ref;          /* Reference number of element */
      int32       length;       /* length of data element */
      int32       offset;       /* byte offset of data element from */
      struct ddblock_t *blk;    /* Pointer to the block this dd is in */
  }                             /* beginning of file */
dd_t;

/* version tags */
typedef struct version_t
  {
      uint32      majorv;       /* major version number */
      uint32      minorv;       /* minor version number */
      uint32      release;      /* release number */
      char        string[LIBVSTR_LEN + 1];  /* optional text description, len 80+1 */
      int16       modified;     /* indicates file was modified */
  }
version_t;

/* record of a block of data descriptors, mirrors structure of a HDF file.  */
typedef struct ddblock_t
  {
      uintn       dirty;        /* boolean: should this DD block be flushed? */
      int32       myoffset;     /* offset of this DD block in the file */
      int16       ndds;         /* number of dd's in this block */
      int32       nextoffset;   /* offset to the next ddblock in the file */
      struct filerec_t *frec;   /* Pointer to the filerec this block is in */
      struct ddblock_t *next;   /* pointer to the next ddblock in memory */
      struct ddblock_t *prev;   /* Pointer to previous ddblock. */
      struct dd_t *ddlist;      /* pointer to array of dd's */
  }
ddblock_t;

/* Tag tree node structure */
typedef struct tag_info_str
  {
      uint16 tag;       /* tag value for this node */
      /* Needs to be first in this structure */
      bv_ptr b;         /* bit-vector to keep track of which refs are used */
      dynarr_p d;       /* dynarray of the refs for this tag */
  }tag_info;

/* For determining what the last file operation was */
typedef enum
  {
      H4_OP_UNKNOWN = 0,   /* Don't know what the last operation was (after fopen frex) */
      H4_OP_SEEK,          /* Last operation was a seek */
      H4_OP_WRITE,         /* Last operation was a write */
      H4_OP_READ           /* Last operation was a read */
  }
fileop_t;

/* File record structure */
typedef struct filerec_t
  {
      char       *path;         /* name of file */
      hdf_file_t  file;         /* either file descriptor or pointer */
      uint16      maxref;       /* highest ref in this file */
      intn        access;       /* access mode */
      intn        refcount;     /* reference count / times opened */
      intn        attach;       /* number of access elts attached */
      intn        version_set;  /* version tag stuff */
      version_t   version;      /* file version info */

      /* Seek caching info */
      int32      f_cur_off;    /* Current location in the file */
      fileop_t    last_op;      /* the last file operation performed */

      /* DD block caching info */
      intn        cache;        /* boolean: whether caching is on */
      intn        dirty;        /* boolean: if dd list needs to be flushed */
      int32      f_end_off;    /* offset of the end of the file */

      /* DD list pointers */
      struct ddblock_t *ddhead; /* head of ddblock list */
      struct ddblock_t *ddlast; /* end of ddblock list */

      /* NULL DD pointers (for fast lookup of DFTAG_NULL) */
      struct ddblock_t *ddnull; /* location of last ddblock with a DFTAG_NULL */
      int32       ddnull_idx;   /* offset of the last location with DFTAG_NULL */

      /* tag tree for file */
      TBBT_TREE *tag_tree;      /* TBBT of the tags in the file */

      /* annotation stuff for file */
      intn       an_num[4];   /* Holds number of annotations found of each type */
      TBBT_TREE *an_tree[4];  /* tbbt trees for each type of annotation in file 
                               * i.e. file/data labels and descriptions.
                               * This is done for faster searching of annotations
                               * of a particular type. */
  }
filerec_t;

/* bits for filerec_t 'dirty' flag */
#define DDLIST_DIRTY   0x01     /* mark whether to flush dirty DD blocks */
#define FILE_END_DIRTY 0x02     /* indicate that the file needs to be extended */

/* Each access element is associated with a tag/ref to keep track of
   the dd it is pointing at.  To facilitate searching for next dd's,
   instead of pointing directly to the dd, we point to the ddblock and
   index into the ddlist of that ddblock. */
typedef struct accrec_t
  {
      /* Flags for this access record */
      intn        appendable;   /* whether appends to the data are allowed */
      intn        special;      /* special element ? */
      intn        new_elem;     /* is a new element (i.e. no length set yet) */
      int32       block_size;   /* size of the blocks for linked-block element*/
      int32       num_blocks;   /* number blocks in the linked-block element */
      uint32      access;       /* access codes */
      uintn       access_type;  /* I/O access type: serial/parallel/... */
      int32       file_id;      /* id of attached file */
      atom_t      ddid;         /* DD id for the DD attached to */
      int32       posn;         /* seek position with respect to start of element */
      void *       special_info; /* special element info? */
      struct funclist_t *special_func;  /* ptr to special function? */
      struct accrec_t *next;    /* for free-list linking */
  }
accrec_t;

#ifdef HFILE_MASTER
/* Pointer to the access record node free list */
static accrec_t *accrec_free_list=NULL;
#endif /* HFILE_MASTER */

/* this type is returned to applications programs or other special
   interfaces when they need to know information about a given
   special element.  This is all information that would not be returned
   via Hinquire().  This should probably be a union of structures. */
typedef struct sp_info_block_t
  {
      int16       key;          /* type of special element this is */

      /* external elements */
      int32       offset;       /* offset in the file */
      char       *path;         /* file name - should not be freed by user */

      /* linked blocks */
      int32       first_len;    /* length of first block */
      int32       block_len;    /* length of standard block */
      int32       nblocks;      /* number of blocks per chunk */

      /* compressed elements */
      int32       comp_type;    /* compression type */
      int32       model_type;   /* model type */
      int32       comp_size;    /* size of compressed information */

      /* variable-length linked blocks */
      int32       min_block;    /* the minimum block size */

    /* Chunked elements */
      int32       chunk_size;   /* logical size of chunks */
      int32       ndims;        /* number of dimensions */
      int32       *cdims;       /* array of chunk lengths for each dimension */

      /* Buffered elements */
      int32       buf_aid;      /* AID of element buffered */
  }
sp_info_block_t;

/* a function table record for accessing special data elements.
   special data elements of a key could be accessed through the list
   of functions in array pointed to by tab. */
typedef struct funclist_t
  {
      int32       (*stread) (accrec_t * rec);
      int32       (*stwrite) (accrec_t * rec);
      int32       (*seek) (accrec_t * access_rec, int32 offset, intn origin);
      int32       (*inquire) (accrec_t * access_rec, int32 *pfile_id,
                                 uint16 *ptag, uint16 *pref, int32 *plength,
                               int32 *poffset, int32 *pposn, int16 *paccess,
                                     int16 *pspecial);
      int32       (*read) (accrec_t * access_rec, int32 length, void * data);
      int32       (*write) (accrec_t * access_rec, int32 length, const void * data);
      intn        (*endaccess) (accrec_t * access_rec);
      int32       (*info) (accrec_t * access_rec, sp_info_block_t * info);
      int32       (*reset) (accrec_t * access_rec, sp_info_block_t * info);
  }
funclist_t;

typedef struct functab_t
  {
      int16       key;          /* the key for this type of special elt */
      funclist_t *tab;          /* table of accessing functions */
  }
functab_t;

/* ---------------------- ID Types and Manipulation ----------------------- */
/* each id, what ever the type, will be represented with a 32-bit word,
   the most-significant 16 bits is a number unique for type.  The less-
   significant 16 bits is an id unique to each type; in this, we use the
   internal slot number. */

#define FIDTYPE   1
#define AIDTYPE   2
#define GROUPTYPE 3
#define SDSTYPE   4
#define DIMTYPE   5
#define CDFTYPE   6
#define VGIDTYPE  8     /* also defined in vg.h for Vgroups */
#define VSIDTYPE  9     /* also defined in vg.h for Vsets */
#define BITTYPE   10    /* For bit-accesses */
#define GRIDTYPE  11    /* for GR access */
#define RIIDTYPE  12    /* for RI access */

#define BADFREC(r)  ((r)==NULL || (r)->refcount==0)

/* --------------------------- Special Elements --------------------------- */
/* The HDF tag space is divided as follows based on the 2 highest bits:
   00: NCSA reserved ordinary tags
   01: NCSA reserved special tags(e.g. linked-block, external, compressed,..)
   10, 11: User tags.

   It is relatively cheap to operate with special tags within the NCSA
   reserved tags range. For users to specify special tags and their
   corresponding ordinary tag, the pair has to be added to the
   special_table in hfile.c and SPECIAL_TABLE must be defined. */

#ifdef SPECIAL_TABLE
#define BASETAG(t)      (HDbase_tag(t))
#define SPECIALTAG(t)   (HDis_special_tag(t))
#define MKSPECIALTAG(t) (HDmake_special_tag(t))
#else
/* This macro converts a (potentially) special tag into a normal tag */
#define BASETAG(t)      (uint16)((~(t) & 0x8000) ? ((t) & ~0x4000) : (t))
/* This macro checks if a tag is special */
#define SPECIALTAG(t)   (uint16)((~(t) & 0x8000) && ((t) & 0x4000))
/* This macro (potentially) converts a regular tag into a special tag */
#define MKSPECIALTAG(t) (uint16)((~(t) & 0x8000) ? ((t) | 0x4000) : DFTAG_NULL)
#endif /*SPECIAL_TABLE */

/* -------------------------- H-Layer Prototypes -------------------------- */
/*
   ** Functions to get information of special elt from other access records.
   **   defined in hfile.c
   ** These should really be HD... routines, but they are only used within
   **   the H-layer...
 */

#if defined c_plusplus || defined __cplusplus
extern      "C"
{
#endif                          /* c_plusplus || __cplusplus */

    HDFLIBAPI accrec_t *HIget_access_rec
                (void);

    HDFLIBAPI void HIrelease_accrec_node(accrec_t *acc);

    HDFLIBAPI void * HIgetspinfo
                (accrec_t * access_rec);

    HDFLIBAPI intn HPcompare_filerec_path
                (const void * obj, const void * key);

    HDFLIBAPI intn HPcompare_accrec_tagref
                (const void * rec1, const void * rec2);

    HDFLIBAPI int32 HPgetdiskblock
                (filerec_t * file_rec, int32 block_size, intn moveto);

    HDFLIBAPI intn HPfreediskblock
                (filerec_t * file_rec, int32 block_offset, int32 block_size);

    HDFLIBAPI intn HPisfile_in_use
                (const char *path);

    HDFLIBAPI int32 HDcheck_empty
                (int32 file_id, uint16 tag, uint16 ref, intn *emptySDS);

    HDFLIBAPI int32 HDget_special_info
                (int32 access_id, sp_info_block_t * info_block);

    HDFLIBAPI int32 HDset_special_info
                (int32 access_id, sp_info_block_t * info_block);

    HDFLIBAPI intn HP_read
                (filerec_t *file_rec,void * buf,int32 bytes);

    HDFLIBAPI intn HPseek
                (filerec_t *file_rec,int32 offset);

    HDFLIBAPI intn HP_write
                (filerec_t *file_rec,const void * buf,int32 bytes);

    HDFLIBAPI intn tagcompare
                (void * k1, void * k2, intn cmparg);

    HDFLIBAPI VOID tagdestroynode
                (void * n);

/*
   ** from hblocks.c
 */
    HDFLIBAPI int32 HLPstread
                (accrec_t * access_rec);

    HDFLIBAPI int32 HLPstwrite
                (accrec_t * access_rec);

    HDFLIBAPI int32 HLPseek
                (accrec_t * access_rec, int32 offset, int origin);

    HDFLIBAPI int32 HLPread
                (accrec_t * access_rec, int32 length, void * data);

    HDFLIBAPI int32 HLPwrite
                (accrec_t * access_rec, int32 length, const void * data);

    HDFLIBAPI int32 HLPinquire
                (accrec_t * access_rec, int32 *pfile_id, uint16 *ptag, uint16 *pref,
               int32 *plength, int32 *poffset, int32 *pposn, int16 *paccess,
                 int16 *pspecial);

    HDFLIBAPI intn HLPendaccess
                (accrec_t * access_rec);

    HDFLIBAPI int32 HLPcloseAID
                (accrec_t * access_rec);

    HDFLIBAPI int32 HLPinfo
                (accrec_t * access_rec, sp_info_block_t * info_block);

/*
   ** from hextelt.c
 */
    HDFLIBAPI int32 HXPstread
                (accrec_t * rec);

    HDFLIBAPI int32 HXPstwrite
                (accrec_t * rec);

    HDFLIBAPI int32 HXPseek
                (accrec_t * access_rec, int32 offset, int origin);

    HDFLIBAPI int32 HXPread
                (accrec_t * access_rec, int32 length, void * data);

    HDFLIBAPI int32 HXPwrite
                (accrec_t * access_rec, int32 length, const void * data);

    HDFLIBAPI int32 HXPinquire
                (accrec_t * access_rec, int32 *pfile_id, uint16 *ptag, uint16 *pref,
               int32 *plength, int32 *poffset, int32 *pposn, int16 *paccess,
                 int16 *pspecial);

    HDFLIBAPI intn HXPendaccess
                (accrec_t * access_rec);

    HDFLIBAPI int32 HXPcloseAID
                (accrec_t * access_rec);

    HDFLIBAPI int32 HXPinfo
                (accrec_t * access_rec, sp_info_block_t * info_block);

    HDFLIBAPI int32 HXPreset
                (accrec_t * access_rec, sp_info_block_t * info_block);

    HDFLIBAPI intn HXPsetaccesstype
                (accrec_t * access_rec);

    HDFLIBAPI intn HXPshutdown
                (void);

/*
   ** from hcomp.c
 */

    HDFLIBAPI int32 HCPstread
                (accrec_t * rec);

    HDFLIBAPI int32 HCPstwrite
                (accrec_t * rec);

    HDFLIBAPI int32 HCPseek
                (accrec_t * access_rec, int32 offset, int origin);

    HDFLIBAPI int32 HCPinquire
                (accrec_t * access_rec, int32 *pfile_id, uint16 *ptag, uint16 *pref,
               int32 *plength, int32 *poffset, int32 *pposn, int16 *paccess,
                 int16 *pspecial);

    HDFLIBAPI int32 HCPread
                (accrec_t * access_rec, int32 length, void * data);

    HDFLIBAPI int32 HCPwrite
                (accrec_t * access_rec, int32 length, const void * data);

    HDFLIBAPI intn HCPendaccess
                (accrec_t * access_rec);

    HDFLIBAPI int32 HCPcloseAID
                (accrec_t * access_rec);

    HDFLIBAPI int32 HCPinfo
                (accrec_t * access_rec, sp_info_block_t * info_block);

    HDFLIBAPI int32 get_comp_len
	        (accrec_t* access_rec);

/*
   ** from hchunks.c - should be the same as found in 'hchunks.h'
 */
#include "hchunks.h"

#if defined (MAC) || defined (macintosh) || defined (SYMANTEC_C)
    HDFLIBAPI hdf_file_t mopen
                (char *filename, intn access);

    HDFLIBAPI int32 mclose
                (hdf_file_t rn);

    HDFLIBAPI int32 mlseek
                (hdf_file_t rn, int32 n, intn m);

    HDFLIBAPI int32 mread
                (hdf_file_t rn, char *buf, int32 n);

    HDFLIBAPI int32 mwrite
                (hdf_file_t rn, char *buf, int32 n);
    HDFLIBAPI intn mstat
                (char *path);

#endif  /* macintosh */

/*
   ** from hbuffer.c
 */

    HDFLIBAPI int32 HBPstread
                (accrec_t * rec);

    HDFLIBAPI int32 HBPstwrite
                (accrec_t * rec);

    HDFLIBAPI int32 HBPseek
                (accrec_t * access_rec, int32 offset, int origin);

    HDFLIBAPI int32 HBPinquire
                (accrec_t * access_rec, int32 *pfile_id, uint16 *ptag, uint16 *pref,
               int32 *plength, int32 *poffset, int32 *pposn, int16 *paccess,
                 int16 *pspecial);

    HDFLIBAPI int32 HBPread
                (accrec_t * access_rec, int32 length, void * data);

    HDFLIBAPI int32 HBPwrite
                (accrec_t * access_rec, int32 length, const void * data);

    HDFLIBAPI intn HBPendaccess
                (accrec_t * access_rec);

    HDFLIBAPI int32 HBPcloseAID
                (accrec_t * access_rec);

    HDFLIBAPI int32 HBPinfo
                (accrec_t * access_rec, sp_info_block_t * info_block);

/*
   ** from hcompri.c
 */

    HDFLIBAPI int32 HRPstread
                (accrec_t * rec);

    HDFLIBAPI int32 HRPstwrite
                (accrec_t * rec);

    HDFLIBAPI int32 HRPseek
                (accrec_t * access_rec, int32 offset, int origin);

    HDFLIBAPI int32 HRPinquire
                (accrec_t * access_rec, int32 *pfile_id, uint16 *ptag, uint16 *pref,
               int32 *plength, int32 *poffset, int32 *pposn, int16 *paccess,
                 int16 *pspecial);

    HDFLIBAPI int32 HRPread
                (accrec_t * access_rec, int32 length, void * data);

    HDFLIBAPI int32 HRPwrite
                (accrec_t * access_rec, int32 length, const void * data);

    HDFLIBAPI intn HRPendaccess
                (accrec_t * access_rec);

    HDFLIBAPI int32 HRPcloseAID
                (accrec_t * access_rec);

    HDFLIBAPI int32 HRPinfo
                (accrec_t * access_rec, sp_info_block_t * info_block);

/*
   ** from hfiledd.c
 */
/******************************************************************************
 NAME
     HTPstart - Initialize the DD list in memory

 DESCRIPTION
    Reads the DD blocks from disk and creates the in-memory structures for
    handling them.  This routine should only be called once for a given
    file and HTPend should be called when finished with the DD list (i.e.
    when the file is being closed).

 RETURNS
    Returns SUCCEED if successful and FAIL otherwise

*******************************************************************************/
intn HTPstart(filerec_t *file_rec       /* IN:  File record to store info in */
);

/******************************************************************************
 NAME
     HTPinit - Create a new DD list in memory

 DESCRIPTION
    Creates a new DD list in memory for a newly created file.  This routine
    should only be called once for a given file and HTPend should be called
    when finished with the DD list (i.e.  when the file is being closed).

 RETURNS
    Returns SUCCEED if successful and FAIL otherwise

*******************************************************************************/
intn HTPinit(filerec_t *file_rec,       /* IN: File record to store info in */
    int16 ndds                          /* IN: # of DDs to store in each block */
);

/******************************************************************************
 NAME
     HTPsync - Flush the DD list in memory

 DESCRIPTION
    Syncronizes the in-memory copy of the DD list with the copy on disk by
    writing out the DD blocks which have changed to disk.
    
 RETURNS
    Returns SUCCEED if successful and FAIL otherwise

*******************************************************************************/
intn HTPsync(filerec_t *file_rec       /* IN:  File record to store info in */
);

/******************************************************************************
 NAME
     HTPend - Terminate the DD list in memory

 DESCRIPTION
    Terminates access to the DD list in memory, writing the DD blocks out to
    the disk (if they've changed).  After this routine is called, no further
    access to tag/refs (or essentially any other HDF objects) can be performed
    on the file.

 RETURNS
    Returns SUCCEED if successful and FAIL otherwise

*******************************************************************************/
intn HTPend(filerec_t *file_rec       /* IN:  File record to store info in */
); 

/******************************************************************************
 NAME
     HTPcreate - Create (and attach to) a tag/ref pair

 DESCRIPTION
    Creates a new tag/ref pair in memory and inserts the tag/ref pair into the
    DD list to be written out to disk.  This routine returns a DD id which can
    be used in the other tag/ref routines to modify the DD.

 RETURNS
    Returns DD id if successful and FAIL otherwise

*******************************************************************************/
atom_t HTPcreate(filerec_t *file_rec,   /* IN: File record to store info in */
    uint16 tag,                         /* IN: Tag to create */
    uint16 ref                          /* IN: ref to create */
);

/******************************************************************************
 NAME
     HTPselect - Attach to an existing tag/ref pair

 DESCRIPTION
    Attaches to an existing tag/ref pair.  This routine returns a DD id which
    can be used in the other tag/ref routines to modify the DD.

 RETURNS
    Returns DD id if successful and FAIL otherwise

*******************************************************************************/
atom_t HTPselect(filerec_t *file_rec,   /* IN: File record to store info in */
    uint16 tag,                         /* IN: Tag to select */
    uint16 ref                          /* IN: ref to select */
);

/******************************************************************************
 NAME
     HTPendaccess - End access to an existing tag/ref pair

 DESCRIPTION
    Ends access to an existing tag/ref pair.  Any further access to the tag/ref
    pair may result in incorrect information being recorded about the DD in
    memory or on disk.

 RETURNS
    Returns SUCCEED if successful and FAIL otherwise

*******************************************************************************/
intn HTPendaccess(atom_t ddid           /* IN: DD id to end access to */
);

/******************************************************************************
 NAME
     HTPdelete - Delete an existing tag/ref pair

 DESCRIPTION
    Deletes a tag/ref from the file.  Also ends access to the tag/ref pair.
    Any further access to the tag/ref pair may result in incorrect information
    being recorded about the DD in memory or on disk.

 RETURNS
    Returns SUCCEED if successful and FAIL otherwise

*******************************************************************************/
intn HTPdelete(atom_t ddid              /* IN: DD id to delete */
);

/******************************************************************************
 NAME
     HTPupdate - Change the offset or length of an existing tag/ref pair

 DESCRIPTION
    Updates a tag/ref in the file, allowing the length and/or offset to be
    modified. Note: "INVALID_OFFSET" & "INVALID_LENGTH" are used to indicate
    that the length or offset (respectively) is unchanged.

 RETURNS
    Returns SUCCEED if successful and FAIL otherwise

*******************************************************************************/
intn HTPupdate(atom_t ddid,             /* IN: DD id to update */
    int32 new_off,                      /* IN: new offset for DD */
    int32 new_len                       /* IN: new length for DD */
);

/******************************************************************************
 NAME
     HTPinquire - Get the DD information for a DD (i.e. tag/ref/offset/length)

 DESCRIPTION
    Get the DD information for a DD id from the DD block.  Passing NULL for
    any parameter does not try to update that parameter.

 RETURNS
    Returns SUCCEED if successful and FAIL otherwise

*******************************************************************************/
intn HTPinquire(atom_t ddid,            /* IN: DD id to inquire about */
    uint16 *tag,                        /* IN: tag of DD */
    uint16 *ref,                        /* IN: ref of DD */
    int32 *off,                         /* IN: offset of DD */
    int32 *len                          /* IN: length of DD */
);

/******************************************************************************
 NAME
     HTPis_special - Check if a DD id is associated with a special tag

 DESCRIPTION
    Checks if the tag for the DD id is a special tag.

 RETURNS
    Returns TRUE(1)/FALSE(0) if successful and FAIL otherwise

*******************************************************************************/
intn HTPis_special(atom_t ddid             /* IN: DD id to inquire about */
);

/******************************************************************************
 NAME
    HTPdump_dds -- Dump out the dd information for a file

 DESCRIPTION
    Prints out all the information (that you could _ever_ want to know) about
    the dd blocks and dd list for a file.

 RETURNS
    returns SUCCEED (0) if successful and FAIL (-1) if failed.

*******************************************************************************/
intn HTPdump_dds(int32 file_id,     /* IN: file ID of HDF file to dump info for */
    FILE *fout                      /* IN: file stream to output to */
);

#if defined c_plusplus || defined __cplusplus
}
#endif                          /* c_plusplus || __cplusplus */

/* #define DISKBLOCK_DEBUG */
#ifdef DISKBLOCK_DEBUG

#ifndef HFILE_MASTER
extern
#endif /* HFILE_MASTER */
const uint8 diskblock_header[4]
#ifdef HFILE_MASTER
={0xde, 0xad, 0xbe, 0xef}
#endif /* HFILE_MASTER */
;

#ifndef HFILE_MASTER
extern
#endif /* HFILE_MASTER */
const uint8 diskblock_tail[4]
#ifdef HFILE_MASTER
={0xfe, 0xeb, 0xda, 0xed}
#endif /* HFILE_MASTER */
;
#define DISKBLOCK_HSIZE sizeof(diskblock_header)
#define DISKBLOCK_TSIZE sizeof(diskblock_tail)

#endif /* DISKBLOCK_DEBUG */

#endif                          /* HFILE_H */