source: rtems/cpukit/libfs/src/rfs/rtems-rfs-rtems-file.c @ a9fa9b7

4.104.115
Last change on this file since a9fa9b7 was a9fa9b7, checked in by Chris Johns <chrisj@…>, on 02/18/10 at 00:24:25

2010-02-18 Chris Johns <chrisj@…>

  • libfs/src/rfs/rtems-rfs-bitmaps.c, libfs/src/rfs/rtems-rfs-bitmaps.h, libfs/src/rfs/rtems-rfs-bitmaps-ut.c, libfs/src/rfs/rtems-rfs-block.c, libfs/src/rfs/rtems-rfs-block.h, libfs/src/rfs/rtems-rfs-block-pos.h, libfs/src/rfs/rtems-rfs-buffer-bdbuf.c, libfs/src/rfs/rtems-rfs-buffer.c, libfs/src/rfs/rtems-rfs-buffer-devio.c, libfs/src/rfs/rtems-rfs-buffer.h, libfs/src/rfs/rtems-rfs-data.h, libfs/src/rfs/rtems-rfs-dir.c, libfs/src/rfs/rtems-rfs-dir.h, libfs/src/rfs/rtems-rfs-dir-hash.c, libfs/src/rfs/rtems-rfs-dir-hash.h, libfs/src/rfs/rtems-rfs-file.c, libfs/src/rfs/rtems-rfs-file.h, libfs/src/rfs/rtems-rfs-file-system.c, libfs/src/rfs/rtems-rfs-file-system-fwd.h, libfs/src/rfs/rtems-rfs-file-system.h, libfs/src/rfs/rtems-rfs-format.c, libfs/src/rfs/rtems-rfs-format.h, libfs/src/rfs/rtems-rfs-group.c, libfs/src/rfs/rtems-rfs-group.h, libfs/src/rfs/rtems-rfs.h, libfs/src/rfs/rtems-rfs-inode.c, libfs/src/rfs/rtems-rfs-inode.h, libfs/src/rfs/rtems-rfs-link.c, libfs/src/rfs/rtems-rfs-link.h, libfs/src/rfs/rtems-rfs-mutex.c, libfs/src/rfs/rtems-rfs-mutex.h, libfs/src/rfs/rtems-rfs-rtems.c, libfs/src/rfs/rtems-rfs-rtems-dev.c, libfs/src/rfs/rtems-rfs-rtems-dir.c, libfs/src/rfs/rtems-rfs-rtems-file.c, libfs/src/rfs/rtems-rfs-rtems.h, libfs/src/rfs/rtems-rfs-rtems-utils.c, libfs/src/rfs/rtems-rfs-shell.c, libfs/src/rfs/rtems-rfs-shell.h, libfs/src/rfs/rtems-rfs-trace.c, libfs/src/rfs/rtems-rfs-trace.h: New.
  • Makefile.am, preinstall.am, libfs/Makefile.am, wrapup/Makefile.am: Updated with the RFS support.
  • libfs/README: Updated after 10 years.
  • libblock/src/flashdisk.c, libblock/src/nvdisk.c, libblock/src/ramdisk-driver.c: Updated to the new error reporting in libblock.
  • libmisc/shell/main_ls.c, libmisc/shell/print-ls.c: Fix printing the size in long mode.
  • libnetworking/nfs/bootp_subr.c, libnetworking/rtems/rtems_bootp.c, libnetworking/rtems/rtems_bsdnet_internal.h: Return the BOOTP/DHCP to the forever behaviour of 4.9 with the ability to call BOOTP and control the process if required.
  • Property mode set to 100644
File size: 7.9 KB
Line 
1/*
2 *  COPYRIGHT (c) 2010 Chris Johns <chrisj@rtems.org>
3 *
4 *  The license and distribution terms for this file may be
5 *  found in the file LICENSE in this distribution or at
6 *  http://www.rtems.com/license/LICENSE.
7 *
8 *  $Id$
9 */
10/**
11 * @file
12 *
13 * @ingroup rtems-rfs
14 *
15 * RTEMS RFS File Handlers
16 *
17 * This file contains the set of handlers used to process operations on
18 * RFS file nodes.
19 */
20
21#include <rtems/rfs/rtems-rfs-file.h>
22#include "rtems-rfs-rtems.h"
23
24/**
25 * This routine processes the open() system call.  Note that there is nothing
26 * special to be done at open() time.
27 *
28 * @param iop
29 * @param pathname
30 * @param flag
31 * @param mode
32 * @return int
33 */
34
35static int
36rtems_rfs_rtems_file_open (rtems_libio_t* iop,
37                           const char*    pathname,
38                           uint32_t       flag,
39                           uint32_t       mode)
40{
41  rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (&iop->pathinfo);
42  rtems_rfs_ino          ino = rtems_rfs_rtems_get_iop_ino (iop);
43  rtems_rfs_file_handle* file;
44  uint32_t               flags;
45  int                    rc;
46
47  flags = 0;
48
49  if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_FILE_OPEN))
50    printf("rtems-rfs: file-open: path:%s ino:%ld flags:%04lx mode:%04lx\n",
51           pathname, ino, flags, mode);
52
53  rtems_rfs_rtems_lock (fs);
54 
55  rc = rtems_rfs_file_open (fs, ino, flags, &file);
56  if (rc > 0)
57  {
58    rtems_rfs_rtems_unlock (fs);
59    return rtems_rfs_rtems_error ("file-open: open", rc);
60  }
61
62  if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_FILE_OPEN))
63    printf("rtems-rfs: file-open: handle:%p\n", file);
64 
65  iop->file_info = file;
66 
67  rtems_rfs_rtems_unlock (fs);
68  return 0;
69}
70
71/**
72 * This routine processes the close() system call.  Note that there is nothing
73 * to flush at this point.
74 *
75 * @param iop
76 * @return int
77 */
78static int
79rtems_rfs_rtems_file_close (rtems_libio_t* iop)
80{
81  rtems_rfs_file_handle* file = iop->file_info;
82  rtems_rfs_file_system* fs = rtems_rfs_file_fs (file);
83  int                    rc;
84
85  if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_FILE_CLOSE))
86    printf("rtems-rfs: file-close: handle:%p\n", file);
87
88  rtems_rfs_rtems_lock (fs);
89 
90  rc = rtems_rfs_file_close (fs, file);
91  if (rc > 0)
92    rc = rtems_rfs_rtems_error ("file-close: file close", rc);
93 
94  rtems_rfs_rtems_unlock (fs);
95  return 0;
96}
97
98/**
99 * This routine processes the read() system call.
100 *
101 * @param iop
102 * @param buffer
103 * @param count
104 * @return int
105 */
106ssize_t
107rtems_rfs_rtems_file_read (rtems_libio_t* iop,
108                           void*          buffer,
109                           size_t         count)
110{
111  rtems_rfs_file_handle* file = iop->file_info;
112  rtems_rfs_pos          pos = iop->offset;
113  uint8_t*               data = buffer;
114  ssize_t                read = 0;
115  int                    rc;
116
117  if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_FILE_READ))
118    printf("rtems-rfs: file-read: handle:%p count:%ld\n", file, count);
119
120  rtems_rfs_rtems_lock (rtems_rfs_file_fs (file));
121
122  if (pos < rtems_rfs_file_size (file))
123  {
124    while (count)
125    {
126      size_t size;
127
128      rc = rtems_rfs_file_io_start (file, &size, true);
129      if (rc > 0)
130      {
131        read = rtems_rfs_rtems_error ("file-read: read: io-start", rc);
132        break;
133      }
134
135      if (size == 0)
136        break;
137   
138      if (size > count)
139        size = count;
140   
141      memcpy (data, rtems_rfs_file_data (file), size);
142
143      data  += size;
144      count -= size;
145      read  += size;
146
147      rc = rtems_rfs_file_io_end (file, size, true);
148      if (rc > 0)
149      {
150        read = rtems_rfs_rtems_error ("file-read: read: io-end", rc);
151        break;
152      }
153    }
154  }
155 
156  rtems_rfs_rtems_unlock (rtems_rfs_file_fs (file));
157 
158  return read;
159}
160
161/**
162 * This routine processes the write() system call.
163 *
164 * @param iop
165 * @param buffer
166 * @param count
167 * @return ssize_t
168 */
169ssize_t
170rtems_rfs_rtems_file_write (rtems_libio_t* iop,
171                            const void*    buffer,
172                            size_t         count)
173{
174  rtems_rfs_file_handle* file = iop->file_info;
175  rtems_rfs_pos          pos = iop->offset;
176  const uint8_t*         data = buffer;
177  ssize_t                write = 0;
178  int                    rc;
179
180  if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_FILE_WRITE))
181    printf("rtems-rfs: file-write: handle:%p count:%ld\n", file, count);
182
183  rtems_rfs_rtems_lock (rtems_rfs_file_fs (file));
184
185  /*
186   * If the iop position is past the physical end of the file we need to set the
187   * file size to the new length before writing.
188   */
189 
190  if (pos > rtems_rfs_file_size (file))
191  {
192    rc = rtems_rfs_file_set_size (file, pos);
193    if (rc)
194      return rtems_rfs_rtems_error ("file-write: write extend", rc);
195    rtems_rfs_file_set_bpos (file, pos);
196  }
197 
198  while (count)
199  {
200    size_t size = count;
201   
202    rc = rtems_rfs_file_io_start (file, &size, false);
203    if (rc)
204    {
205      write = rtems_rfs_rtems_error ("file-write: write open", rc);
206      break;
207    }
208   
209    if (size > count)
210      size = count;
211
212    memcpy (rtems_rfs_file_data (file), data, size);
213
214    data  += size;
215    count -= size;
216    write  += size;
217   
218    rc = rtems_rfs_file_io_end (file, size, false);
219    if (rc)
220    {
221      write = rtems_rfs_rtems_error ("file-write: write close", rc);
222      break;
223    }
224  }
225 
226  iop->size = rtems_rfs_file_size (file);
227 
228  rtems_rfs_rtems_unlock (rtems_rfs_file_fs (file));
229 
230  return write;
231}
232
233/**
234 * This routine processes the ioctl() system call.
235 *
236 * @note  No ioctl()'s are currently supported for RFS files.
237 *
238 * @param iop
239 * @param command
240 * @param buffer
241 */
242
243int
244rtems_rfs_rtems_file_ioctl (rtems_libio_t* iop, uint32_t command, void* buffer)
245{
246  return 0;
247}
248
249/**
250 * This routine processes the lseek() system call.
251 *
252 * @param iop
253 * @param offset
254 * @param whence
255 * @return rtems_off64_t
256 */
257rtems_off64_t
258rtems_rfs_rtems_file_lseek (rtems_libio_t* iop,
259                            rtems_off64_t  offset,
260                            int            whence)
261{
262  rtems_rfs_file_handle* file = iop->file_info;
263  rtems_rfs_pos          pos;
264  int                    rc;
265
266  if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_FILE_LSEEK))
267    printf("rtems-rfs: file-lseek: handle:%p offset:%Ld\n", file, offset);
268
269  pos = iop->offset;
270 
271  rtems_rfs_rtems_lock (rtems_rfs_file_fs (file));
272 
273  rc = rtems_rfs_file_seek (file, pos, &pos);
274  if (rc)
275  {
276    rtems_rfs_rtems_unlock (rtems_rfs_file_fs (file));
277    return rtems_rfs_rtems_error ("file_lseek: lseek", rc);
278  }
279 
280  rtems_rfs_rtems_unlock (rtems_rfs_file_fs (file));
281 
282  return iop->offset;
283}
284
285/**
286 * This routine processes the ftruncate() system call.
287 *
288 * @param iop
289 * @param length
290 * @return int
291 */
292int
293rtems_rfs_rtems_file_ftruncate (rtems_libio_t* iop,
294                                rtems_off64_t  length)
295{
296  rtems_rfs_file_handle* file = iop->file_info;
297  int                    rc;
298
299  if (rtems_rfs_rtems_trace (RTEMS_RFS_RTEMS_DEBUG_FILE_FTRUNC))
300    printf("rtems-rfs: file-ftrunc: handle:%p length:%Ld\n", file, length);
301 
302  rtems_rfs_rtems_lock (rtems_rfs_file_fs (file));
303
304  rc = rtems_rfs_file_set_size (file, length);
305  if (rc)
306    rc = rtems_rfs_rtems_error ("file_ftruncate: set size", rc);
307
308  iop->size = rtems_rfs_file_size (file);
309 
310  rtems_rfs_rtems_unlock (rtems_rfs_file_fs (file));
311
312  return rc;
313}
314
315/*
316 *  Set of operations handlers for operations on RFS files.
317 */
318
319const rtems_filesystem_file_handlers_r rtems_rfs_rtems_file_handlers = {
320  .open_h      = rtems_rfs_rtems_file_open,
321  .close_h     = rtems_rfs_rtems_file_close,
322  .read_h      = rtems_rfs_rtems_file_read,
323  .write_h     = rtems_rfs_rtems_file_write,
324  .ioctl_h     = rtems_rfs_rtems_file_ioctl,
325  .lseek_h     = rtems_rfs_rtems_file_lseek,
326  .fstat_h     = rtems_rfs_rtems_stat,
327  .fchmod_h    = rtems_rfs_rtems_fchmod,
328  .ftruncate_h = rtems_rfs_rtems_file_ftruncate,
329  .fpathconf_h = NULL,
330  .fsync_h     = rtems_rfs_rtems_fdatasync,
331  .fdatasync_h = rtems_rfs_rtems_fdatasync,
332  .fcntl_h     = rtems_rfs_rtems_fcntl,
333  .rmnod_h     = rtems_rfs_rtems_rmnod
334};
Note: See TracBrowser for help on using the repository browser.