2
0

isindexinfo.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
  24. /*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
  25. /*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
  26. /*%% (c) Copyright 1993, 1994 Novell, Inc. */
  27. /*%% $XConsortium: isindexinfo.c /main/3 1995/10/23 11:40:56 rswiston $ */
  28. /*
  29. * Copyright (c) 1988 by Sun Microsystems, Inc.
  30. */
  31. /*
  32. * isindexinfo.c
  33. *
  34. * Description:
  35. * Access file status information
  36. */
  37. #include "isam_impl.h"
  38. #include <sys/time.h>
  39. #define ZERO 0
  40. /*
  41. * err = isindexinfo(isfd, buffer, number)
  42. *
  43. * Return information about index.
  44. * Return information about the data file (if number == 0).
  45. *
  46. * (this function is overloaded).
  47. *
  48. * Errors:
  49. * EBADARG number is out of range
  50. * ENOTOPEN isfd is not ISAM file descriptor of open ISAM file
  51. */
  52. #define dibuf ((struct dictinfo *)buffer)
  53. int
  54. isindexinfo(int isfd, struct keydesc *buffer, int number)
  55. {
  56. Fab *fab;
  57. int ret;
  58. Fcb *fcb = NULL;
  59. /*
  60. * Get File Access Block.
  61. */
  62. if ((fab = _isfd_find(isfd)) == NULL) {
  63. _setiserrno2(ENOTOPEN, '9', '0');
  64. return (ISERROR);
  65. }
  66. /*
  67. * Call the Access Method or RPC client function, depending whether
  68. * the file is local or remote.
  69. */
  70. _isam_entryhook();
  71. /*
  72. * Get FCB corresponding to the isfhandle handle.
  73. */
  74. if ((fcb = _openfcb(&fab->isfhandle, &fab->errcode)) == NULL) {
  75. _isam_exithook();
  76. return (ISERROR);
  77. }
  78. /*
  79. * Update information in FCB from CNTL page on the disk
  80. */
  81. (void)_isfcb_cntlpg_r(fcb);
  82. /*
  83. * Validate number argument.
  84. */
  85. if (number < 0 || number > fcb->nkeys) {
  86. _amseterrcode(&fab->errcode, EBADARG);
  87. goto ERROR;
  88. }
  89. if (number == 0) {
  90. /*
  91. * Return dictinfo structure.
  92. */
  93. dibuf->di_nkeys = fcb->nkeys;
  94. dibuf->di_recsize = fcb->maxreclen;
  95. dibuf->di_idxsize = fcb->keys[0].k2_len;
  96. dibuf->di_nrecords = fcb->nrecords;
  97. /* Set msb of di_nkeys for variable length records. */
  98. if (fcb->varflag == TRUE)
  99. dibuf->di_nkeys |= DICTVARLENBIT;
  100. }
  101. else {
  102. /*
  103. * Return index information.
  104. */
  105. _iskey_itox(fcb->keys + number - 1, buffer);
  106. }
  107. _amseterrcode(&fab->errcode, ISOK);
  108. /* XXX This fixes a core dump that occurs when isindexinfo is
  109. * called on brand new tables
  110. _isdisk_commit();
  111. _isdisk_sync();
  112. _isdisk_inval();
  113. */
  114. _isam_exithook();
  115. ret = ISOK;
  116. goto CLEANUP;
  117. ERROR:
  118. /*
  119. * Restore FCB from CNTL page.
  120. */
  121. _isdisk_rollback();
  122. _isdisk_inval();
  123. _isam_exithook();
  124. ret = ISERROR;
  125. CLEANUP:
  126. if (ret == ISOK)
  127. isreclen = fab->minreclen; /* for variable length */
  128. _seterr_errcode(&fab->errcode);
  129. /*
  130. * This is a patch to conform with the VSX 3.0 test that checks
  131. * that k_leng == 2 and k_type == 1 for index 1 if the ISAM file
  132. * has no primary key. I suspect that these numbers are returned by
  133. * C-ISAM and the author of VSX tests diligently checks them even
  134. * though they have no meaning.
  135. */
  136. if (ret == ISOK && number == 1 && buffer->k_nparts == 0) {
  137. buffer->k_leng = 2;
  138. buffer->k_type = INTTYPE;
  139. }
  140. return (ret);
  141. }