source: rtems/c/src/exec/libfs/src/imfs/linearfile.c @ c873f40

4.104.114.84.95
Last change on this file since c873f40 was c873f40, checked in by Joel Sherrill <joel.sherrill@…>, on 04/08/02 at 18:28:59

2002-04-06 Ralf Corsepius <corsepiu@…>

  • src/imfs/imfs_getchild.c: include <string.h>.
  • src/imfs/imfs_gtkn.c: Include <string.h>.
  • src/imfs/ioman.c: Include <string.h>.
  • src/imfs/linearfile.c: Include <string.h>.
  • src/imfs/memfile.c: Include <string.h>.
  • Property mode set to 100644
File size: 2.3 KB
Line 
1/*
2 *  IMFS Linear File Handlers
3 *
4 *  This file contains the set of handlers used to process operations on
5 *  IMFS linear memory file nodes.  Linear memory files are contiguous
6 *  blocks of memory created from a TAR or other filesystem image.
7 *  The blocks are nonwriteable and nonresizeable.
8 *
9 *  COPYRIGHT (c) 1989-1999.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.OARcorp.com/rtems/license.html.
15 *
16 *  $Id$
17 */
18
19#if HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include <stdlib.h>
24#include <assert.h>
25#include <string.h>
26#include <errno.h>
27
28#include <rtems.h>
29#include <rtems/libio.h>
30#include "imfs.h"
31#include <rtems/libio_.h>
32#include <rtems/seterr.h>
33
34/*
35 * linearfile_read
36 *
37 *  This routine processes the read() system call.
38 */
39
40int linearfile_read(
41  rtems_libio_t *iop,
42  void          *buffer,
43  unsigned32     count
44)
45{
46  IMFS_jnode_t   *the_jnode;
47  unsigned char  *dest;
48  unsigned char  *file_ptr;
49  int            file_offset;
50
51
52  the_jnode = iop->file_info;
53
54  /*
55   *  Perform internal consistency checks
56   */
57
58  assert( the_jnode );
59  if ( !the_jnode )
60    rtems_set_errno_and_return_minus_one( EIO );
61
62  assert( the_jnode->type == IMFS_LINEAR_FILE );
63  if ( the_jnode->type != IMFS_LINEAR_FILE )
64    rtems_set_errno_and_return_minus_one( EIO );
65
66  /*
67   *  Error checks on arguments
68   */
69
70  dest = (unsigned char *)buffer;
71  assert( dest );
72  if ( !dest )
73    rtems_set_errno_and_return_minus_one( EINVAL );
74
75  /*
76   *  Perform a simple memory copy.
77   */
78
79  if (count == 0)
80     return(0);
81
82  the_jnode = iop->file_info;
83  file_ptr    = (unsigned char *)the_jnode->info.linearfile.direct;
84  file_offset = (unsigned long)iop->offset;
85
86  if (count > (the_jnode->info.linearfile.size - file_offset))
87     count = the_jnode->info.linearfile.size - file_offset;
88
89  memcpy(dest, &file_ptr[file_offset], count);
90
91  return(count);
92}
93
94
95/*
96 *  linearfile_lseek
97 *
98 *  This routine processes the lseek() system call.
99 */
100
101int linearfile_lseek(
102  rtems_libio_t   *iop,
103  off_t            offset,
104  int              whence
105)
106{
107  IMFS_jnode_t   *the_jnode;
108
109  the_jnode = iop->file_info;
110
111  if (iop->offset > the_jnode->info.linearfile.size)
112    iop->offset = the_jnode->info.linearfile.size;
113
114  return iop->offset;
115}
116
Note: See TracBrowser for help on using the repository browser.