2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
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: isfileio.c /main/3 1995/10/23 11:39:26 rswiston $ */
29 static char sccsid[] = "@(#)isfileio.c 1.3 89/07/17 Copyr 1988 Sun Micro";
32 * Copyright (c) 1988 by Sun Microsystems, Inc.
39 * I/O operations on UNIX files associated with FCB
42 #include "isam_impl.h"
44 static int _getoffset();
45 static Blkno _getblkno();
49 * _cp_tofile(fcb, unixfd, data, pos, len)
51 * Copy data to a file associated with FCB (unixfd distinguishes among
52 * .rec, .ind., and .var file). The data are copied from buffer data to
53 * the file at offset pos. The number of bytes to copy is in len.
57 _cp_tofile(fcb, unixfd, data, pos, len)
64 int offset; /* Offset within a page */
70 * Data may span multiple blocks.
73 blkno = _getblkno(pos);
74 offset = _getoffset(pos);
75 nbytes = (len < ISPAGESIZE - offset) ? len : ISPAGESIZE - offset;
77 bufhdr = _isdisk_fix(fcb, unixfd, blkno, ISFIXWRITE);
78 memcpy( bufhdr->isb_buffer + offset,data, nbytes);
79 _isdisk_unfix(bufhdr);
88 * _cp_fromfile(fcb, unixfd, data, pos, len)
90 * Copy data from a file associated with FCB (unixfd distinguishes among
91 * .rec, .ind., and .var file). The data are copied to buffer data from
92 * the file at offset pos. The number of bytes to copy is in len.
96 _cp_fromfile(fcb, unixfd, data, pos, len)
103 int offset; /* Offset within a page */
109 * Data may span multiple blocks.
112 blkno = _getblkno(pos);
113 offset = _getoffset(pos);
114 nbytes = (len < ISPAGESIZE - offset) ? len : ISPAGESIZE - offset;
116 bufhdr = _isdisk_fix(fcb, unixfd, blkno, ISFIXREAD);
117 memcpy( data,bufhdr->isb_buffer + offset, nbytes);
118 _isdisk_unfix(bufhdr);
127 * extend_file(fcb, unixfd, oldsize)
129 * Extend UNIX file by one block.
133 _extend_file(fcb, unixfd, oldsize)
139 char buf[ISPAGESIZE];
142 * We must write something to the buffer, or we will get
143 * segmentation fault when using mapped I/O.
145 _isseekpg(unixfd, oldsize);
146 _iswritepg(unixfd, buf);
148 bufhdr = _isdisk_fix(fcb, unixfd, oldsize, ISFIXNOREAD);
149 _isdisk_unfix(bufhdr);
151 return (oldsize + 1);
155 * off = _getoffset(pos)
157 * Calculate offset relative to the beginning of page
164 return ((int)(pos % ISPAGESIZE));
168 * blkno = _getblkno(pos)
170 * Calculate block number of the block containing position pos.
177 return ((int)(pos / ISPAGESIZE));