OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [libfs/] [src/] [imfs/] [linearfile.c] - Blame information for rev 1026

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
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
 *  linearfile.c,v 1.4 2002/04/08 18:28:59 joel Exp
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
 
40
int 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
 
101
int 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
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.