1 /*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
2 /*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
3 /*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
4 /*%% (c) Copyright 1993, 1994 Novell, Inc. */
5 /*%% $XConsortium: isindfreel.c /main/3 1995/10/23 11:41:03 rswiston $ */
7 static char sccsid[] = "@(#)isindfreel.c 1.3 89/07/17 Copyr 1988 Sun Micro";
11 * Copyright (c) 1988 by Sun Microsystems, Inc.
18 * Free list maintenance functions
21 #include "isam_impl.h"
23 extern Bufhdr *_isdisk_fix();
26 * blkno = _isfreel_alloc()
28 * Allocate a new index page.
32 _isindfreel_alloc(fcb)
40 if (fcb->indfreelist == FREELIST_NOPAGE) {
43 * We must write something to the buffer, or we will get
44 * segmentation fault when using mapped I/O.
46 fcb->indsize = _extend_file(fcb, fcb->indfd, fcb->indsize);
48 return (fcb->indsize - 1);
51 pbhdr = _isdisk_fix(fcb, fcb->indfd, fcb->indfreelist, ISFIXWRITE);
52 p = pbhdr->isb_buffer;
54 npointers = ldshort(p + FL_NPOINTERS_OFF);
57 blkno = ldblkno(p + FL_POINTERS_OFF + npointers * BLKNOSIZE);
59 stshort((short)npointers, p + FL_NPOINTERS_OFF);
61 return (ldblkno(p + FL_POINTERS_OFF + npointers * BLKNOSIZE));
64 blkno = fcb->indfreelist;
65 fcb->indfreelist = ldblkno(p + FL_NEXT_OFF);
78 _isindfreel_free(fcb, blkno)
86 if (fcb->indfreelist != FREELIST_NOPAGE) {
87 pbhdr = _isdisk_fix(fcb, fcb->indfd, fcb->indfreelist, ISFIXWRITE);
88 p = pbhdr->isb_buffer;
90 npointers = ldshort(p + FL_NPOINTERS_OFF);
92 if (npointers < FL_MAXNPOINTERS) {
93 stblkno(blkno, p + FL_POINTERS_OFF + npointers * BLKNOSIZE);
95 stshort((short)npointers, p + FL_NPOINTERS_OFF);
102 pbhdr = _isdisk_fix(fcb, fcb->indfd, blkno, ISFIXWRITE);
103 p = pbhdr->isb_buffer;
105 /* Mark page to indicate that it is in the free list. */
106 stshort((short)PT_FREELIST, p + FL_TYPE_OFF);
108 stshort((short)0, p + FL_NPOINTERS_OFF);
109 stblkno(fcb->indfreelist, p + FL_NEXT_OFF);
111 fcb->indfreelist = blkno;