isdelcurr.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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: isdelcurr.c /main/3 1995/10/23 11:37:32 rswiston $ */
  28. /*
  29. * Copyright (c) 1988 by Sun Microsystems, Inc.
  30. */
  31. /*
  32. * isdelcurr.c
  33. *
  34. * Description:
  35. * Delete current record from ISAM file.
  36. */
  37. #include "isam_impl.h"
  38. #include <sys/time.h>
  39. static int _amdelcurr();
  40. /*
  41. * err = isdelcurr(isfd, record)
  42. *
  43. * Isdelcurr() modifies the current record in ISAM file.
  44. * All indexes of the ISAM file are updated.
  45. *
  46. * Current record position is not changed.
  47. * isrecnum is set to to the deleted record.
  48. *
  49. * Returns 0 if successful, or -1 of any error.
  50. *
  51. * Errors:
  52. * ELOCKED The record or file has been locked by another process.
  53. * ENOTOPEN isfd does not correspond to an open ISAM file, or the
  54. * ISAM file was not opened with ISINOUT mode.
  55. * ENOCURR Record with record number recnum does not exist, or it
  56. * was deleted by another process.
  57. */
  58. int
  59. isdelcurr(int isfd)
  60. {
  61. int _am_delcurr();
  62. Fab *fab;
  63. int ret;
  64. int recnum;
  65. /*
  66. * Get File Access Block.
  67. */
  68. if ((fab = _isfd_find(isfd)) == NULL) {
  69. _setiserrno2(ENOTOPEN, '9', '0');
  70. return (ISERROR);
  71. }
  72. /*
  73. * Check that the open mode was ISINOUT.
  74. */
  75. if (fab->openmode != OM_INOUT) {
  76. _setiserrno2(ENOTOPEN, '9', '0');
  77. return (ISERROR);
  78. }
  79. if ((ret = _amdelcurr(&fab->isfhandle, &fab->curpos,
  80. &recnum, &fab->errcode)) == ISOK) {
  81. isrecnum = recnum; /* Set isrecnum */
  82. }
  83. _seterr_errcode(&fab->errcode);
  84. return (ret); /* Successful write */
  85. }
  86. /*
  87. * _amdelcurr(isfhandle, curpos, recnum, errcode)
  88. *
  89. * _amdelcurr() deletes a record from ISAM file.
  90. *
  91. * Input params:
  92. * isfhandle Handle of ISAM file
  93. * curpos Curent record position
  94. *
  95. * Output params:
  96. * recnum record number of the deleted record
  97. * errcode error status of the operation
  98. *
  99. */
  100. static int
  101. _amdelcurr(Bytearray *isfhandle, Bytearray *curpos, Recno *recnum,
  102. struct errcode *errcode)
  103. {
  104. Fcb *fcb = NULL;
  105. Crp *crp;
  106. char recbuf[ISMAXRECLEN];
  107. int reclen;
  108. int (*rec_read)();
  109. int (*rec_delete)();
  110. _isam_entryhook();
  111. /*
  112. * Get FCB corresponding to the isfhandle handle.
  113. */
  114. if ((fcb = _openfcb(isfhandle, errcode)) == NULL) {
  115. _isam_exithook();
  116. return (ISERROR);
  117. }
  118. rec_read = (fcb->varflag?_vlrec_read:_flrec_read);
  119. rec_delete = (fcb->varflag?_vlrec_delete:_flrec_delete);
  120. /*
  121. * Get info from current record position structure.
  122. */
  123. crp = (Crp *) curpos->data;
  124. if (crp->flag != CRP_ON) {
  125. _amseterrcode(errcode, ENOCURR);
  126. goto ERROR;
  127. }
  128. /*
  129. * Update information in FCB from CNTL page on the disk
  130. */
  131. (void)_isfcb_cntlpg_r2(fcb);
  132. /*
  133. * We must read the record first to be able to delete keys.
  134. */
  135. if (rec_read(fcb, recbuf, crp->recno, &reclen) != ISOK) {
  136. _amseterrcode(errcode, ENOCURR);
  137. goto ERROR;
  138. }
  139. if (rec_delete(fcb, crp->recno) != ISOK) {
  140. _amseterrcode(errcode, ENOCURR);
  141. goto ERROR;
  142. }
  143. *recnum = crp->recno;
  144. fcb->nrecords--;
  145. /*
  146. * Delete associated entries from all indexes.
  147. */
  148. _delkeys(fcb, recbuf, crp->recno);
  149. _amseterrcode(errcode, ISOK);
  150. _issignals_mask();
  151. _isdisk_commit();
  152. _isdisk_sync();
  153. _isdisk_inval();
  154. /*
  155. * Update CNTL Page from the FCB.
  156. */
  157. (void)_isfcb_cntlpg_w2(fcb);
  158. _issignals_unmask();
  159. _isam_exithook();
  160. return (ISOK);
  161. ERROR:
  162. _isdisk_rollback();
  163. _isdisk_inval();
  164. /*
  165. * Restore FCB from CNTL page.
  166. */
  167. if (fcb) (void)_isfcb_cntlpg_r2(fcb);
  168. _isam_exithook();
  169. return (ISERROR);
  170. }