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 libraries 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 * Copyright (c) 1988 by Sun Microsystems, Inc.
36 * I/O operations on UNIX files associated with FCB
39 #include "isam_impl.h"
41 static int _getoffset();
42 static Blkno _getblkno();
46 * _cp_tofile(fcb, unixfd, data, pos, len)
48 * Copy data to a file associated with FCB (unixfd distinguishes among
49 * .rec, .ind., and .var file). The data are copied from buffer data to
50 * the file at offset pos. The number of bytes to copy is in len.
54 _cp_tofile(Fcb *fcb, int unixfd, char *data, long pos, int len)
56 int offset; /* Offset within a page */
62 * Data may span multiple blocks.
65 blkno = _getblkno(pos);
66 offset = _getoffset(pos);
67 nbytes = (len < ISPAGESIZE - offset) ? len : ISPAGESIZE - offset;
69 bufhdr = _isdisk_fix(fcb, unixfd, blkno, ISFIXWRITE);
70 memcpy( bufhdr->isb_buffer + offset,data, nbytes);
71 _isdisk_unfix(bufhdr);
80 * _cp_fromfile(fcb, unixfd, data, pos, len)
82 * Copy data from a file associated with FCB (unixfd distinguishes among
83 * .rec, .ind., and .var file). The data are copied to buffer data from
84 * the file at offset pos. The number of bytes to copy is in len.
88 _cp_fromfile(Fcb *fcb, int unixfd, char *data, long pos, int len)
90 int offset; /* Offset within a page */
96 * Data may span multiple blocks.
99 blkno = _getblkno(pos);
100 offset = _getoffset(pos);
101 nbytes = (len < ISPAGESIZE - offset) ? len : ISPAGESIZE - offset;
103 bufhdr = _isdisk_fix(fcb, unixfd, blkno, ISFIXREAD);
104 memcpy( data,bufhdr->isb_buffer + offset, nbytes);
105 _isdisk_unfix(bufhdr);
114 * extend_file(fcb, unixfd, oldsize)
116 * Extend UNIX file by one block.
120 _extend_file(Fcb *fcb, int unixfd, Blkno oldsize)
123 char buf[ISPAGESIZE];
126 * We must write something to the buffer, or we will get
127 * segmentation fault when using mapped I/O.
129 _isseekpg(unixfd, oldsize);
130 _iswritepg(unixfd, buf);
132 bufhdr = _isdisk_fix(fcb, unixfd, oldsize, ISFIXNOREAD);
133 _isdisk_unfix(bufhdr);
135 return (oldsize + 1);
139 * off = _getoffset(pos)
141 * Calculate offset relative to the beginning of page
147 return ((int)(pos % ISPAGESIZE));
151 * blkno = _getblkno(pos)
153 * Calculate block number of the block containing position pos.
159 return ((int)(pos / ISPAGESIZE));