source: rtems/cpukit/libfs/src/imfs/linearfile.c @ f9d1afc

4.104.114.84.95
Last change on this file since f9d1afc was b2709481, checked in by Joel Sherrill <joel.sherrill@…>, on 01/04/02 at 18:30:58

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

  • src/imfs/imfs_eval.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • src/imfs/memfile.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • src/imfs/imfs_readlink.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • src/imfs/imfs_unlink.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • src/imfs/imfs_link.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • src/imfs/imfs_chown.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • src/imfs/ioman.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • src/imfs/imfs_mount.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • src/imfs/imfs_directory.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • src/imfs/imfs_stat.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • src/imfs/imfs_fchmod.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • src/imfs/imfs_symlink.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • src/imfs/imfs_mknod.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • src/imfs/linearfile.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • src/imfs/imfs_unmount.c: Include <rtems/seterr.h>. Apply rtems_set_errno_and_return_minus_one.
  • src/imfs/imfs.h: Apply rtems_set_errno_and_return_minus_one. Comment out increment_and_check_linkcounts.
  • 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 <errno.h>
26
27#include <rtems.h>
28#include <rtems/libio.h>
29#include "imfs.h"
30#include <rtems/libio_.h>
31#include <rtems/seterr.h>
32
33/*
34 * linearfile_read
35 *
36 *  This routine processes the read() system call.
37 */
38
39int linearfile_read(
40  rtems_libio_t *iop,
41  void          *buffer,
42  unsigned32     count
43)
44{
45  IMFS_jnode_t   *the_jnode;
46  unsigned char  *dest;
47  unsigned char  *file_ptr;
48  int            file_offset;
49
50
51  the_jnode = iop->file_info;
52
53  /*
54   *  Perform internal consistency checks
55   */
56
57  assert( the_jnode );
58  if ( !the_jnode )
59    rtems_set_errno_and_return_minus_one( EIO );
60
61  assert( the_jnode->type == IMFS_LINEAR_FILE );
62  if ( the_jnode->type != IMFS_LINEAR_FILE )
63    rtems_set_errno_and_return_minus_one( EIO );
64
65  /*
66   *  Error checks on arguments
67   */
68
69  dest = (unsigned char *)buffer;
70  assert( dest );
71  if ( !dest )
72    rtems_set_errno_and_return_minus_one( EINVAL );
73
74  /*
75   *  Perform a simple memory copy.
76   */
77
78  if (count == 0)
79     return(0);
80
81  the_jnode = iop->file_info;
82  file_ptr    = (unsigned char *)the_jnode->info.linearfile.direct;
83  file_offset = (unsigned long)iop->offset;
84
85  if (count > (the_jnode->info.linearfile.size - file_offset))
86     count = the_jnode->info.linearfile.size - file_offset;
87
88  memcpy(dest, &file_ptr[file_offset], count);
89
90  return(count);
91}
92
93
94/*
95 *  linearfile_lseek
96 *
97 *  This routine processes the lseek() system call.
98 */
99
100int linearfile_lseek(
101  rtems_libio_t   *iop,
102  off_t            offset,
103  int              whence
104)
105{
106  IMFS_jnode_t   *the_jnode;
107
108  the_jnode = iop->file_info;
109
110  if (iop->offset > the_jnode->info.linearfile.size)
111    iop->offset = the_jnode->info.linearfile.size;
112
113  return iop->offset;
114}
115
Note: See TracBrowser for help on using the repository browser.