source: rtems/cpukit/libfs/src/rfs/rtems-rfs-rtems-dir.c @ 9b4422a2

4.115
Last change on this file since 9b4422a2 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 4.6 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/**
9 * @file
10 *
11 * @ingroup rtems-rfs
12 *
13 * RTEMS RFS Directory Access Routines
14 */
15
16#if HAVE_CONFIG_H
17#include "config.h"
18#endif
19
20#include <inttypes.h>
21
22#include <sys/types.h>
23#include <sys/stat.h>
24#include <fcntl.h>
25#include <stdlib.h>
26#include <stdio.h>
27#include <unistd.h>
28
29#include <rtems/rfs/rtems-rfs-dir.h>
30#include <rtems/rfs/rtems-rfs-link.h>
31#include "rtems-rfs-rtems.h"
32
33/**
34 * This rountine will verify that the node being opened as a directory is in
35 * fact a directory node. If it is then the offset into the directory will be
36 * set to 0 to position to the first directory entry.
37 */
38static int
39rtems_rfs_rtems_dir_open (rtems_libio_t* iop,
40                          const char*    pathname,
41                          int            oflag,
42                          mode_t         mode)
43{
44  rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (&iop->pathinfo);
45  rtems_rfs_ino          ino = rtems_rfs_rtems_get_iop_ino (iop);
46  rtems_rfs_inode_handle inode;
47  int                    rc;
48
49  rtems_rfs_rtems_lock (fs);
50
51  rc = rtems_rfs_inode_open (fs, ino, &inode, true);
52  if (rc)
53  {
54    rtems_rfs_rtems_unlock (fs);
55    return rtems_rfs_rtems_error ("dir_open: opening inode", rc);
56  }
57
58  if (!RTEMS_RFS_S_ISDIR (rtems_rfs_inode_get_mode (&inode)))
59  {
60    rtems_rfs_inode_close (fs, &inode);
61    rtems_rfs_rtems_unlock (fs);
62    return rtems_rfs_rtems_error ("dir_open: not dir", ENOTDIR);
63  }
64
65  iop->offset = 0;
66
67  rtems_rfs_inode_close (fs, &inode);
68  rtems_rfs_rtems_unlock (fs);
69  return 0;
70}
71
72/**
73 * This routine will be called by the generic close routine to cleanup any
74 * resources that have been allocated for the management of the file
75 *
76 * @param iop
77 * @retval 0 Always no error.
78 */
79static int
80rtems_rfs_rtems_dir_close (rtems_libio_t* iop)
81{
82  /*
83   * The RFS does not hold any resources. Nothing to do.
84   */
85  return 0;
86}
87
88/**
89 * This routine will read the next directory entry based on the directory
90 * offset. The offset should be equal to -n- time the size of an individual
91 * dirent structure. If n is not an integer multiple of the sizeof a dirent
92 * structure, an integer division will be performed to determine directory
93 * entry that will be returned in the buffer. Count should reflect -m- times
94 * the sizeof dirent bytes to be placed in the buffer.  If there are not -m-
95 * dirent elements from the current directory position to the end of the
96 * exisiting file, the remaining entries will be placed in the buffer and the
97 * returned value will be equal to -m actual- times the size of a directory
98 * entry.
99 */
100static ssize_t
101rtems_rfs_rtems_dir_read (rtems_libio_t* iop,
102                          void*          buffer,
103                          size_t         count)
104{
105  rtems_rfs_file_system* fs = rtems_rfs_rtems_pathloc_dev (&iop->pathinfo);
106  rtems_rfs_ino          ino = rtems_rfs_rtems_get_iop_ino (iop);
107  rtems_rfs_inode_handle inode;
108  struct dirent*         dirent;
109  ssize_t                bytes_transferred;
110  int                    d;
111  int                    rc;
112
113  count  = count / sizeof (struct dirent);
114  dirent = buffer;
115
116  rtems_rfs_rtems_lock (fs);
117
118  rc = rtems_rfs_inode_open (fs, ino, &inode, true);
119  if (rc)
120  {
121    rtems_rfs_rtems_unlock (fs);
122    return rtems_rfs_rtems_error ("dir_read: read inode", rc);
123  }
124
125  bytes_transferred = 0;
126
127  for (d = 0; d < count; d++, dirent++)
128  {
129    size_t size;
130    rc = rtems_rfs_dir_read (fs, &inode, iop->offset, dirent, &size);
131    if (rc == ENOENT)
132    {
133      rc = 0;
134      break;
135    }
136    if (rc > 0)
137    {
138      bytes_transferred = rtems_rfs_rtems_error ("dir_read: dir read", rc);
139      break;
140    }
141    iop->offset += size;
142    bytes_transferred += sizeof (struct dirent);
143  }
144
145  rtems_rfs_inode_close (fs, &inode);
146  rtems_rfs_rtems_unlock (fs);
147
148  return bytes_transferred;
149}
150
151/*
152 *  Set of operations handlers for operations on directories.
153 */
154
155const rtems_filesystem_file_handlers_r rtems_rfs_rtems_dir_handlers = {
156  .open_h      = rtems_rfs_rtems_dir_open,
157  .close_h     = rtems_rfs_rtems_dir_close,
158  .read_h      = rtems_rfs_rtems_dir_read,
159  .write_h     = rtems_filesystem_default_write,
160  .ioctl_h     = rtems_filesystem_default_ioctl,
161  .lseek_h     = rtems_filesystem_default_lseek_directory,
162  .fstat_h     = rtems_rfs_rtems_fstat,
163  .ftruncate_h = rtems_filesystem_default_ftruncate_directory,
164  .fsync_h     = rtems_filesystem_default_fsync_or_fdatasync,
165  .fdatasync_h = rtems_rfs_rtems_fdatasync,
166  .fcntl_h     = rtems_filesystem_default_fcntl
167};
Note: See TracBrowser for help on using the repository browser.