Changeset eb649786 in rtems


Ignore:
Timestamp:
Oct 8, 2009, 7:07:36 AM (10 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
4.10, 4.11, master
Children:
c1fc5d4
Parents:
cdf0be6
Message:

2009-10-08 Chris Johns <chrisj@…>

  • Makefile.am, preinstall.am: Added statvfs.h.
  • libcsupport/Makefile.am: Add statvfs.c.
  • libcsupport/include/sys/statvfs.h, libcsupport/src/statvfs.c: New.
  • libcsupport/include/rtems/libio.h: Add a file system handler for the statvfs call.
  • libfs/src/devfs/devfs_init.c, libfs/src/dosfs/msdos_init.c, libfs/src/imfs/imfs_init.c, libfs/src/nfsclient/src/nfs.c: Set the statvfs handler to NULL.
  • include/rtems/fs.h: Add a second node access field for the RFS file system to hold a directory offset while the existing field holds the inode number. This save a rescan of the directory when working with directories.
  • libblock/include/rtems/bdbuf.h: Added references and user fields to the buffer descriptor.
  • libblock/src/bdbuf.c: Added dynamic buffer support for different block sizes. Fixed a number of bugs.
  • libblock/src/blkdev.c: Release the disk device on an error.
  • libblock/src/diskdevs.c: Set the block size to the media block size during initialisation of the disk device.
  • libblock/src/flashdisk.c, libblock/src/nvdisk.c, libblock/src/ramdisk.c: Updated the drivers to handle variable block sizes.
  • libfs/src/dosfs/fat.c, libfs/src/dosfs/fat.h: Release any buffers when an error occurs. The FAT buffer layer hangs onto a single buffer while mounted. This should be fixed.
  • sapi/inline/rtems/chain.inl: Added rtems_chain_set_off_chain, rtems_chain_is_node_off_chain, and rtems_chain_previous.
  • score/inline/rtems/score/chain.inl: Added _Chain_Set_off_chain, and _Chain_Is_node_off_chain.
  • libmisc/shell/main_ln.c, libmisc/shell/main_mknod.c, libmisc/shell/mknod-pack_dev.c, libmisc/shell/mknod-pack_dev.h: New shell commands.
  • libmisc/Makefile.am, libmisc/shell/shellconfig.h: Added ln and mknod commands.
  • libmisc/shell/hexdump-display.c: Fixed the reopen bug which showed up as a free with a bad pointer.
  • libmisc/shell/main_mount.c: List the user adding file system when listing the available file systems to mount.
  • libmisc/shell/utils-cp.c: Remove the fixed static copy buffer and use a large dynamic buffer.
  • score/inline/rtems/score/address.inl, score/src/coremsgsubmit.c, score/src/objectallocate.c, score/src/objectfree.c: Remove warnings.
Location:
cpukit
Files:
6 added
30 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    rcdf0be6 reb649786  
     12009-10-08      Chris Johns <chrisj@rtems.org>
     2
     3        * Makefile.am, preinstall.am: Added statvfs.h.
     4        * libcsupport/Makefile.am: Add statvfs.c.
     5        * libcsupport/include/sys/statvfs.h, libcsupport/src/statvfs.c:
     6        New.
     7        * libcsupport/include/rtems/libio.h: Add a file system handler for
     8        the statvfs call.
     9        * libfs/src/devfs/devfs_init.c, libfs/src/dosfs/msdos_init.c,
     10        libfs/src/imfs/imfs_init.c, libfs/src/nfsclient/src/nfs.c: Set the
     11        statvfs handler to NULL.
     12        * include/rtems/fs.h: Add a second node access field for the RFS
     13        file system to hold a directory offset while the existing field
     14        holds the inode number. This save a rescan of the directory when
     15        working with directories.
     16        * libblock/include/rtems/bdbuf.h: Added references and user fields
     17        to the buffer descriptor.
     18        * libblock/src/bdbuf.c: Added dynamic buffer support for different
     19        block sizes. Fixed a number of bugs.
     20        * libblock/src/blkdev.c: Release the disk device on an error.
     21        * libblock/src/diskdevs.c: Set the block size to the media block
     22        size during initialisation of the disk device.
     23        * libblock/src/flashdisk.c, libblock/src/nvdisk.c,
     24        libblock/src/ramdisk.c: Updated the drivers to handle variable
     25        block sizes.
     26        * libfs/src/dosfs/fat.c, libfs/src/dosfs/fat.h: Release any
     27        buffers when an error occurs. The FAT buffer layer hangs onto a
     28        single buffer while mounted. This should be fixed.
     29        * sapi/inline/rtems/chain.inl: Added rtems_chain_set_off_chain,
     30        rtems_chain_is_node_off_chain, and rtems_chain_previous.
     31        * score/inline/rtems/score/chain.inl: Added _Chain_Set_off_chain,
     32        and _Chain_Is_node_off_chain.
     33        * libmisc/shell/main_ln.c, libmisc/shell/main_mknod.c,
     34        libmisc/shell/mknod-pack_dev.c, libmisc/shell/mknod-pack_dev.h:
     35        New shell commands.
     36        * libmisc/Makefile.am, libmisc/shell/shellconfig.h: Added ln and
     37        mknod commands.
     38        * libmisc/shell/hexdump-display.c: Fixed the reopen bug which
     39        showed up as a free with a bad pointer.
     40        * libmisc/shell/main_mount.c: List the user adding file system
     41        when listing the available file systems to mount.
     42        * libmisc/shell/utils-cp.c: Remove the fixed static copy buffer
     43        and use a large dynamic buffer.
     44        * score/inline/rtems/score/address.inl, score/src/coremsgsubmit.c,
     45        score/src/objectallocate.c, score/src/objectfree.c: Remove
     46        warnings.
     47
    1482009-10-06      Joel Sherrill <joel.sherrill@oarcorp.com>
    249
  • cpukit/Makefile.am

    rcdf0be6 reb649786  
    5656include_sys_HEADERS += libcsupport/include/sys/ioccom.h \
    5757    libcsupport/include/sys/filio.h libcsupport/include/sys/ioctl.h \
    58     libcsupport/include/sys/sockio.h libcsupport/include/sys/ttycom.h \
    59     libcsupport/include/sys/termios.h libcsupport/include/sys/utsname.h
     58    libcsupport/include/sys/statvfs.h libcsupport/include/sys/sockio.h \
     59    libcsupport/include/sys/ttycom.h libcsupport/include/sys/termios.h \
     60    libcsupport/include/sys/utsname.h
    6061
    6162include_sys_HEADERS += libnetworking/sys/uio.h
  • cpukit/include/rtems/fs.h

    rcdf0be6 reb649786  
    4747{
    4848   void                                    *node_access;
     49   void                                    *node_access_2;
    4950   const rtems_filesystem_file_handlers_r  *handlers;
    5051   const rtems_filesystem_operations_table *ops;
  • cpukit/libblock/include/rtems/bdbuf.h

    rcdf0be6 reb649786  
    191191
    192192  dev_t             dev;        /**< device number */
     193
    193194  rtems_blkdev_bnum block;      /**< block number on the device */
    194195
     
    205206  volatile uint32_t  hold_timer; /**< Timer to indicate how long a buffer
    206207                                  * has been held in the cache modified. */
     208
     209  int   references;              /**< Allow reference counting by owner. */
     210  void* user;                    /**< User data. */
    207211} rtems_bdbuf_buffer;
    208212
  • cpukit/libblock/src/bdbuf.c

    rcdf0be6 reb649786  
    3838#include <errno.h>
    3939#include <assert.h>
    40 
    41 #if RTEMS_BDBUF_TRACE
    4240#include <stdio.h>
    43 #endif
    4441
    4542#include "rtems/bdbuf.h"
     
    5653typedef struct rtems_bdbuf_swapout_transfer
    5754{
    58   rtems_chain_control   bds;       /**< The transfer list of BDs. */
    59   dev_t                 dev;       /**< The device the transfer is for. */
    60   rtems_blkdev_request* write_req; /**< The write request array. */
     55  rtems_chain_control   bds;         /**< The transfer list of BDs. */
     56  dev_t                 dev;         /**< The device the transfer is for. */
     57  rtems_blkdev_request* write_req;   /**< The write request array. */
     58  uint32_t              bufs_per_bd; /**< Number of buffers per bd. */
    6159} rtems_bdbuf_swapout_transfer;
    6260
     
    152150#define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAIT_2  RTEMS_BLKDEV_FATAL_ERROR(16)
    153151#define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAIT_3  RTEMS_BLKDEV_FATAL_ERROR(17)
    154 #define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAKE    RTEMS_BLKDEV_FATAL_ERROR(18)
    155 #define RTEMS_BLKDEV_FATAL_BDBUF_SO_WAKE       RTEMS_BLKDEV_FATAL_ERROR(19)
    156 #define RTEMS_BLKDEV_FATAL_BDBUF_SO_NOMEM      RTEMS_BLKDEV_FATAL_ERROR(20)
    157 #define RTEMS_BLKDEV_FATAL_BDBUF_SO_WK_CREATE  RTEMS_BLKDEV_FATAL_ERROR(21)
    158 #define RTEMS_BLKDEV_FATAL_BDBUF_SO_WK_START   RTEMS_BLKDEV_FATAL_ERROR(22)
    159 #define BLKDEV_FATAL_BDBUF_SWAPOUT_RE          RTEMS_BLKDEV_FATAL_ERROR(23)
    160 #define BLKDEV_FATAL_BDBUF_SWAPOUT_TS          RTEMS_BLKDEV_FATAL_ERROR(24)
     152#define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAIT_TO RTEMS_BLKDEV_FATAL_ERROR(18)
     153#define RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAKE    RTEMS_BLKDEV_FATAL_ERROR(19)
     154#define RTEMS_BLKDEV_FATAL_BDBUF_SO_WAKE       RTEMS_BLKDEV_FATAL_ERROR(20)
     155#define RTEMS_BLKDEV_FATAL_BDBUF_SO_NOMEM      RTEMS_BLKDEV_FATAL_ERROR(21)
     156#define RTEMS_BLKDEV_FATAL_BDBUF_SO_WK_CREATE  RTEMS_BLKDEV_FATAL_ERROR(22)
     157#define RTEMS_BLKDEV_FATAL_BDBUF_SO_WK_START   RTEMS_BLKDEV_FATAL_ERROR(23)
     158#define BLKDEV_FATAL_BDBUF_SWAPOUT_RE          RTEMS_BLKDEV_FATAL_ERROR(24)
     159#define BLKDEV_FATAL_BDBUF_SWAPOUT_TS          RTEMS_BLKDEV_FATAL_ERROR(25)
    161160
    162161/**
     
    194193   RTEMS_NO_INHERIT_PRIORITY | RTEMS_NO_PRIORITY_CEILING | RTEMS_LOCAL)
    195194
     195/**
     196 * Waiter timeout. Set to non-zero to find some info on a waiter that is
     197 * waiting too long.
     198 */
     199#define RTEMS_BDBUF_WAIT_TIMEOUT RTEMS_NO_TIMEOUT
     200#if !defined (RTEMS_BDBUF_WAIT_TIMEOUT)
     201#define RTEMS_BDBUF_WAIT_TIMEOUT \
     202  (TOD_MICROSECONDS_TO_TICKS (20000000))
     203#endif
     204
    196205/*
    197206 * The swap out task.
     
    204213static rtems_bdbuf_cache bdbuf_cache;
    205214
    206 /**
    207  * Print a message to the bdbuf trace output and flush it.
    208  *
    209  * @param format The format string. See printf for details.
    210  * @param ... The arguments for the format text.
    211  * @return int The number of bytes written to the output.
    212  */
    213215#if RTEMS_BDBUF_TRACE
     216/**
     217 * If true output the trace message.
     218 */
    214219bool rtems_bdbuf_tracer;
    215 static void
    216 rtems_bdbuf_printf (const char *format, ...)
    217 {
    218   va_list args;
    219   va_start (args, format);
    220   if (rtems_bdbuf_tracer)
    221   {
    222     fprintf (stdout, "bdbuf:");
    223     vfprintf (stdout, format, args);
    224     fflush (stdout);
    225   }
    226 }
     220
     221/**
     222 * Return the number of items on the list.
     223 *
     224 * @param list The chain control.
     225 * @return uint32_t The number of items on the list.
     226 */
     227uint32_t
     228rtems_bdbuf_list_count (rtems_chain_control* list)
     229{
     230  rtems_chain_node* node = rtems_chain_first (list);
     231  uint32_t          count = 0;
     232  while (!rtems_chain_is_tail (list, node))
     233  {
     234    count++;
     235    node = rtems_chain_next (node);
     236  }
     237  return count;
     238}
     239
     240/**
     241 * Show the usage for the bdbuf cache.
     242 */
     243void
     244rtems_bdbuf_show_usage (void)
     245{
     246  uint32_t group;
     247  uint32_t total = 0;
     248  uint32_t val;
     249  for (group = 0; group < bdbuf_cache.group_count; group++)
     250    total += bdbuf_cache.groups[group].users;
     251  printf ("bdbuf:group users=%lu", total);
     252  val = rtems_bdbuf_list_count (&bdbuf_cache.ready);
     253  printf (", ready=%lu", val);
     254  total = val;
     255  val = rtems_bdbuf_list_count (&bdbuf_cache.lru);
     256  printf (", lru=%lu", val);
     257  total += val;
     258  val = rtems_bdbuf_list_count (&bdbuf_cache.modified);
     259  printf (", mod=%lu", val);
     260  total += val;
     261  val = rtems_bdbuf_list_count (&bdbuf_cache.sync);
     262  printf (", sync=%lu", val);
     263  total += val;
     264  printf (", total=%lu\n", total);
     265}
     266
     267/**
     268 * Show the users for a group of a bd.
     269 *
     270 * @param where A label to show the context of output.
     271 * @param bd The bd to show the users of.
     272 */
     273void
     274rtems_bdbuf_show_users (const char* where, rtems_bdbuf_buffer* bd)
     275{
     276  const char* states[] =
     277    { "EM", "RA", "CH", "AC", "MD", "AM", "SY", "TR" };
     278  printf ("bdbuf:users: %15s: [%ld (%s)] %ld:%ld = %lu %s\n",
     279          where,
     280          bd->block, states[bd->state],
     281          bd->group - bdbuf_cache.groups,
     282          bd - bdbuf_cache.bds,
     283          bd->group->users,
     284          bd->group->users > 8 ? "<<<<<<<" : "");
     285}
     286#else
     287#define rtems_bdbuf_tracer (0)
     288#define rtems_bdbuf_show_usage()
     289#define rtems_bdbuf_show_users(_w, _b)
    227290#endif
    228291
     
    333396    p = q;
    334397  }
    335 
     398 
    336399  q->avl.left = q->avl.right = NULL;
    337400  q->avl.bal = 0;
     
    723786
    724787/**
     788 * Change the block number for the block size to the block number for the media
     789 * block size. We have to use 64bit maths. There is no short cut here.
     790 *
     791 * @param block The logical block number in the block size terms.
     792 * @param block_size The block size.
     793 * @param media_block_size The block size of the media.
     794 * @return rtems_blkdev_bnum The media block number.
     795 */
     796static rtems_blkdev_bnum
     797rtems_bdbuf_media_block (rtems_blkdev_bnum block,
     798                         size_t            block_size,
     799                         size_t            media_block_size)
     800{
     801  return (((uint64_t) block) * block_size) / media_block_size;
     802}
     803
     804/**
    725805 * Lock the mutex. A single task can nest calls.
    726806 *
     
    838918  rtems_bdbuf_unlock_cache ();
    839919
    840   sc = rtems_semaphore_obtain (*sema, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
     920  sc = rtems_semaphore_obtain (*sema, RTEMS_WAIT, RTEMS_BDBUF_WAIT_TIMEOUT);
     921
     922  if (sc == RTEMS_TIMEOUT)
     923    rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CACHE_WAIT_TO);
    841924 
    842925  if (sc != RTEMS_UNSATISFIED)
     
    9631046  size_t              bufs_per_bd;
    9641047
     1048  if (rtems_bdbuf_tracer)
     1049    printf ("bdbuf:realloc: %lu: %ld -> %ld\n",
     1050            group - bdbuf_cache.groups, group->bds_per_group,
     1051            new_bds_per_group);
     1052 
    9651053  bufs_per_bd = bdbuf_cache.max_bds_per_group / group->bds_per_group;
    9661054 
     
    9691057       b++, bd += bufs_per_bd)
    9701058  {
    971     if ((bd->state == RTEMS_BDBUF_STATE_MODIFIED) ||
    972         (bd->state == RTEMS_BDBUF_STATE_ACCESS) ||
    973         (bd->state == RTEMS_BDBUF_STATE_ACCESS_MODIFIED) ||
    974         (bd->state == RTEMS_BDBUF_STATE_SYNC) ||
    975         (bd->state == RTEMS_BDBUF_STATE_TRANSFER))
    976       rtems_fatal_error_occurred ((bd->state << 16) |
    977                                   RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_8);
    978    
    979     if ((bd->state == RTEMS_BDBUF_STATE_CACHED) ||
    980         (bd->state == RTEMS_BDBUF_STATE_READ_AHEAD))
    981     {
    982       if (rtems_bdbuf_avl_remove (&bdbuf_cache.tree, bd) != 0)
     1059    switch (bd->state)
     1060    {
     1061      case RTEMS_BDBUF_STATE_EMPTY:
     1062        break;
     1063      case RTEMS_BDBUF_STATE_CACHED:
     1064      case RTEMS_BDBUF_STATE_READ_AHEAD:
     1065        if (rtems_bdbuf_avl_remove (&bdbuf_cache.tree, bd) != 0)
     1066          rtems_fatal_error_occurred ((bd->state << 16) |
     1067                                      RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_1);
     1068        break;
     1069      default:
    9831070        rtems_fatal_error_occurred ((bd->state << 16) |
    984                                     RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_1);
     1071                                    RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_8);
    9851072    }
    9861073   
     
    10151102  {
    10161103    rtems_bdbuf_buffer* bd = (rtems_bdbuf_buffer*) node;
     1104
     1105    if (rtems_bdbuf_tracer)
     1106      printf ("bdbuf:next-bd: %lu (%ld:%ld) %ld -> %ld\n",
     1107              bd - bdbuf_cache.bds,
     1108              bd->group - bdbuf_cache.groups, bd->group->users,
     1109              bd->group->bds_per_group, bds_per_group);
    10171110
    10181111    /*
     
    10581151  rtems_status_code   sc;
    10591152
    1060 #if RTEMS_BDBUF_TRACE
    1061   rtems_bdbuf_printf ("init\n");
    1062 #endif
     1153  if (rtems_bdbuf_tracer)
     1154    printf ("bdbuf:init\n");
    10631155
    10641156  /*
     
    11681260 
    11691261  /*
     1262   * Compute the various number of elements in the cache.
     1263   */
     1264  bdbuf_cache.buffer_min_count =
     1265    bdbuf_config.size / bdbuf_config.buffer_min;
     1266  bdbuf_cache.max_bds_per_group =
     1267    bdbuf_config.buffer_max / bdbuf_config.buffer_min;
     1268  bdbuf_cache.group_count =
     1269    bdbuf_cache.buffer_min_count / bdbuf_cache.max_bds_per_group;
     1270
     1271  /*
    11701272   * Allocate the memory for the buffer descriptors.
    11711273   */
    11721274  bdbuf_cache.bds = calloc (sizeof (rtems_bdbuf_buffer),
    1173                             bdbuf_config.size / bdbuf_config.buffer_min);
     1275                            bdbuf_cache.buffer_min_count);
    11741276  if (!bdbuf_cache.bds)
    11751277  {
     
    11821284    return RTEMS_NO_MEMORY;
    11831285  }
    1184 
    1185   /*
    1186    * Compute the various number of elements in the cache.
    1187    */
    1188   bdbuf_cache.buffer_min_count =
    1189     bdbuf_config.size / bdbuf_config.buffer_min;
    1190   bdbuf_cache.max_bds_per_group =
    1191     bdbuf_config.buffer_max / bdbuf_config.buffer_min;
    1192   bdbuf_cache.group_count =
    1193     bdbuf_cache.buffer_min_count / bdbuf_cache.max_bds_per_group;
    11941286
    11951287  /*
     
    12141306   * aligned. It is possible to free the memory allocated by rtems_memalign()
    12151307   * with free(). Return 0 if allocated.
     1308   *
     1309   * The memory allocate allows a
    12161310   */
    12171311  if (rtems_memalign ((void **) &bdbuf_cache.buffers,
     
    12481342    bd->waiters    = 0;
    12491343    bd->hold_timer = 0;
     1344    bd->references = 0;
     1345    bd->user       = NULL;
    12501346   
    12511347    rtems_chain_append (&bdbuf_cache.ready, &bd->link);
     
    14451541        {
    14461542          /*
    1447            * Remove the buffer from the AVL tree.
     1543           * Remove the buffer from the AVL tree if the state says it is in the
     1544           * cache or a read ahead buffer. The buffer could be in the empty
     1545           * state as a result of reallocations.
    14481546           */
    1449           if (rtems_bdbuf_avl_remove (&bdbuf_cache.tree, bd) != 0)
    1450             rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_2);
     1547          switch (bd->state)
     1548          {
     1549            case RTEMS_BDBUF_STATE_CACHED:
     1550            case RTEMS_BDBUF_STATE_READ_AHEAD:
     1551              if (rtems_bdbuf_avl_remove (&bdbuf_cache.tree, bd) != 0)
     1552                rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_2);
     1553              break;
     1554            default:
     1555              break;
     1556          }
    14511557        }
    14521558        else
     
    15231629      if (bd->group->bds_per_group != bds_per_group)
    15241630      {
     1631        /*
     1632         * Remove the buffer from the AVL tree.
     1633         */
     1634        if (rtems_bdbuf_avl_remove (&bdbuf_cache.tree, bd) != 0)
     1635          rtems_fatal_error_occurred (RTEMS_BLKDEV_FATAL_BDBUF_CONSISTENCY_2);
    15251636        bd->state = RTEMS_BDBUF_STATE_EMPTY;
    15261637        rtems_chain_extract (&bd->link);
     
    15341645  /*
    15351646   * If the buffer is for read ahead and it exists in the AVL cache or is being
    1536    * accessed or being transfered then return NULL.
     1647   * accessed or being transfered then return NULL stopping further read ahead
     1648   * requests.
    15371649   */
    15381650  if (read_ahead)
     
    15571669      case RTEMS_BDBUF_STATE_ACCESS_MODIFIED:
    15581670        bd->waiters++;
    1559         rtems_bdbuf_wait (&bdbuf_cache.access,
    1560                           &bdbuf_cache.access_waiters);
     1671        rtems_bdbuf_wait (&bdbuf_cache.access, &bdbuf_cache.access_waiters);
    15611672        bd->waiters--;
    15621673        break;
     
    15651676      case RTEMS_BDBUF_STATE_TRANSFER:
    15661677        bd->waiters++;
    1567         rtems_bdbuf_wait (&bdbuf_cache.transfer,
    1568                           &bdbuf_cache.transfer_waiters);
     1678        rtems_bdbuf_wait (&bdbuf_cache.transfer, &bdbuf_cache.transfer_waiters);
    15691679        bd->waiters--;
    15701680        break;
     
    15901700  rtems_disk_device*  dd;
    15911701  rtems_bdbuf_buffer* bd;
     1702  rtems_blkdev_bnum   media_block;
    15921703  size_t              bds_per_group;
    15931704
     
    16021713    return RTEMS_INVALID_ID;
    16031714
    1604   if (block >= dd->size)
    1605   {
    1606     rtems_disk_release (dd);
    1607     return RTEMS_INVALID_ADDRESS;
     1715  /*
     1716   * Compute the media block number. Drivers work with media block number not
     1717   * the block number a BD may have as this depends on the block size set by
     1718   * the user.
     1719   */
     1720  media_block = rtems_bdbuf_media_block (block,
     1721                                         dd->block_size,
     1722                                         dd->media_block_size);
     1723  if (media_block >= dd->size)
     1724  {
     1725    rtems_disk_release(dd);
     1726    return RTEMS_INVALID_NUMBER;
    16081727  }
    16091728
     
    16141733    return RTEMS_INVALID_NUMBER;
    16151734  }
    1616  
     1735
     1736  media_block += dd->start;
     1737
    16171738  rtems_bdbuf_lock_cache ();
    16181739
    1619 #if RTEMS_BDBUF_TRACE
    1620   /* Print the block index relative to the physical disk */
    1621   rtems_bdbuf_printf ("get: %d (dev = %08x)\n", block + dd->start, device);
    1622 #endif
    1623 
    1624   bd = rtems_bdbuf_get_buffer (dd, bds_per_group, block + dd->start, false);
    1625 
     1740  /*
     1741   * Print the block index relative to the physical disk.
     1742   */
     1743  if (rtems_bdbuf_tracer)
     1744    printf ("bdbuf:get: %lu (%lu) (dev = %08x)\n",
     1745            media_block, block, (unsigned int) device);
     1746
     1747  bd = rtems_bdbuf_get_buffer (dd, bds_per_group, media_block, false);
     1748
     1749  /*
     1750   * This could be considered a bug in the caller because you should not be
     1751   * getting an already modified buffer but user may have modified a byte in a
     1752   * block then decided to seek the start and write the whole block and the
     1753   * file system will have no record of this so just gets the block to fill.
     1754   */
    16261755  if (bd->state == RTEMS_BDBUF_STATE_MODIFIED)
    16271756    bd->state = RTEMS_BDBUF_STATE_ACCESS_MODIFIED;
    16281757  else
     1758  {
    16291759    bd->state = RTEMS_BDBUF_STATE_ACCESS;
    1630 
    1631   /*
    1632    * Indicate a buffer in this group is being used.
    1633    */
    1634   bd->group->users++;
    1635  
     1760    /*
     1761     * Indicate a buffer in this group is being used.
     1762     */
     1763    bd->group->users++;
     1764  }
     1765 
     1766  if (rtems_bdbuf_tracer)
     1767  {
     1768    rtems_bdbuf_show_users ("get", bd);
     1769    rtems_bdbuf_show_usage ();
     1770  }
     1771
    16361772  rtems_bdbuf_unlock_cache ();
    16371773
     
    16741810  rtems_blkdev_request* req;
    16751811  size_t                bds_per_group;
     1812  rtems_blkdev_bnum     media_block;
     1813  rtems_blkdev_bnum     media_block_count;
    16761814 
    16771815  if (!bdbuf_cache.initialised)
     
    16941832    return RTEMS_INVALID_ID;
    16951833 
    1696   if (block >= dd->size) {
     1834  /*
     1835   * Compute the media block number. Drivers work with media block number not
     1836   * the block number a BD may have as this depends on the block size set by
     1837   * the user.
     1838   */
     1839  media_block = rtems_bdbuf_media_block (block,
     1840                                         dd->block_size,
     1841                                         dd->media_block_size);
     1842  if (media_block >= dd->size)
     1843  {
    16971844    rtems_disk_release(dd);
    16981845    return RTEMS_INVALID_NUMBER;
     
    17061853  }
    17071854 
    1708 #if RTEMS_BDBUF_TRACE
    1709   /* Print the block index relative to the physical disk */
    1710   rtems_bdbuf_printf ("read: %d (dev = %08x)\n", block + dd->start, device);
    1711 #endif
    1712 
    1713   req->bufnum = 0;
     1855  /*
     1856   * Print the block index relative to the physical disk and the user block
     1857   * number
     1858   */
     1859  if (rtems_bdbuf_tracer)
     1860    printf ("bdbuf:read: %lu (%lu) (dev = %08x)\n",
     1861            media_block + dd->start, block, (unsigned int) device);
    17141862
    17151863  /*
     
    17201868   * Limit the blocks read by the size of the disk.
    17211869   */
    1722   if ((rtems_bdbuf_configuration.max_read_ahead_blocks + block) < dd->size)
     1870  if ((rtems_bdbuf_configuration.max_read_ahead_blocks + media_block) < dd->size)
    17231871    read_ahead_count = rtems_bdbuf_configuration.max_read_ahead_blocks;
    17241872  else
    1725     read_ahead_count = dd->size - block;
     1873    read_ahead_count = dd->size - media_block;
     1874
     1875  media_block_count = dd->block_size / dd->media_block_size;
     1876 
     1877  req->bufnum = 0;
    17261878
    17271879  rtems_bdbuf_lock_cache ();
     
    17371889     * caller.
    17381890     */
    1739     bd = rtems_bdbuf_get_buffer (dd, bds_per_group,
    1740                                  block + dd->start + req->bufnum,
     1891    bd = rtems_bdbuf_get_buffer (dd, bds_per_group, media_block + dd->start,
    17411892                                 req->bufnum == 0 ? false : true);
    17421893
     
    17621913     */
    17631914    bd->group->users++;
     1915
     1916    if (rtems_bdbuf_tracer)
     1917      rtems_bdbuf_show_users ("reading", bd);
    17641918   
    17651919    /*
     
    17721926     */
    17731927    req->bufs[req->bufnum].user   = bd;
    1774     req->bufs[req->bufnum].block  = bd->block;
     1928    req->bufs[req->bufnum].block  = media_block + dd->start;
    17751929    req->bufs[req->bufnum].length = dd->block_size;
    17761930    req->bufs[req->bufnum].buffer = bd->buffer;
    17771931    req->bufnum++;
     1932
     1933    /*
     1934     * Move the media block count by the number of media blocks in the
     1935     * disk device's set block size.
     1936     */
     1937    media_block += media_block_count;
    17781938  }
    17791939
     
    17981958    int             result;
    17991959    uint32_t        b;
     1960    bool            wake_transfer;
    18001961
    18011962    /*
     
    18381999    }
    18392000
     2001    wake_transfer = false;
     2002   
    18402003    rtems_bdbuf_lock_cache ();
    18412004
     
    18432006    {
    18442007      bd = req->bufs[b].user;
    1845       bd->error = req->error;
     2008      if (!bd->error)
     2009        bd->error = req->error;
    18462010      bd->state = RTEMS_BDBUF_STATE_READ_AHEAD;
    18472011      bd->group->users--;
     2012
     2013      if (rtems_bdbuf_tracer)
     2014        rtems_bdbuf_show_users ("read-ahead", bd);
     2015
    18482016      rtems_chain_prepend (&bdbuf_cache.ready, &bd->link);
    18492017
    18502018      /*
    1851        * If there is an error remove the BD from the AVL tree as it does is
    1852        * invalid, then wake any threads that may be waiting. A thread may have
    1853        * been waiting for this block and assumed it was in the tree.
     2019       * If there is an error remove the BD from the AVL tree as it is invalid,
     2020       * then wake any threads that may be waiting. A thread may have been
     2021       * waiting for this block and assumed it was in the tree.
    18542022       */
    18552023      if (bd->error)
     
    18612029
    18622030      if (bd->waiters)
    1863         rtems_bdbuf_wake (bdbuf_cache.access, &bdbuf_cache.access_waiters);
    1864       else
    1865       {
    1866         if (rtems_chain_has_only_one_node (&bdbuf_cache.ready))
    1867           rtems_bdbuf_wake (bdbuf_cache.waiting, &bdbuf_cache.wait_waiters);
    1868       }
    1869     }
    1870 
     2031        wake_transfer = true;
     2032    }
     2033
     2034    if (wake_transfer)
     2035      rtems_bdbuf_wake (bdbuf_cache.transfer, &bdbuf_cache.transfer_waiters);
     2036    else
     2037      rtems_bdbuf_wake (bdbuf_cache.waiting, &bdbuf_cache.wait_waiters);
     2038   
    18712039    bd = req->bufs[0].user;
    18722040
    18732041    /*
    1874      * One less user. We do this here then increment again so the case of the
    1875      * buffer in the the cache and no read leaves the user counts at the
    1876      * correct level.
     2042     * One less user for the BD we return. The loop above is only for the read
     2043     * head buffers. We do this here then increment again so the case of the
     2044     * buffer in the cache or modified and no read leaves the user counts at
     2045     * the correct level.
    18772046     */
    18782047    bd->group->users--;
     2048
     2049    if (rtems_bdbuf_tracer)
     2050      rtems_bdbuf_show_users ("read-done", bd);
    18792051  }
    18802052
     
    18932065  }
    18942066
     2067  if (rtems_bdbuf_tracer)
     2068  {
     2069    rtems_bdbuf_show_users ("read", bd);
     2070    rtems_bdbuf_show_usage ();
     2071  }
     2072 
    18952073  rtems_bdbuf_unlock_cache ();
    18962074  rtems_disk_release (dd);
     
    19122090  rtems_bdbuf_lock_cache ();
    19132091
    1914 #if RTEMS_BDBUF_TRACE
    1915   rtems_bdbuf_printf ("release: %d\n", bd->block);
    1916 #endif
     2092  if (rtems_bdbuf_tracer)
     2093    printf ("bdbuf:release: %lu\n", bd->block);
    19172094 
    19182095  if (bd->state == RTEMS_BDBUF_STATE_ACCESS_MODIFIED)
     
    19222099  else
    19232100  {
    1924     /*
    1925      * If this is a read ahead buffer place the ready queue. Buffers are taken
    1926      * from here first. If we prepend then get from the queue the buffers
    1927      * furthermost from the read buffer will be used.
    1928      */
    1929     if (bd->state == RTEMS_BDBUF_STATE_READ_AHEAD)
    1930       rtems_chain_prepend (&bdbuf_cache.ready, &bd->link);
    1931     else
    1932     {
    1933       bd->state = RTEMS_BDBUF_STATE_CACHED;
    1934       rtems_chain_append (&bdbuf_cache.lru, &bd->link);
    1935     }
     2101    bd->state = RTEMS_BDBUF_STATE_CACHED;
     2102    rtems_chain_append (&bdbuf_cache.lru, &bd->link);
    19362103
    19372104    /*
     
    19412108  }
    19422109 
     2110  if (rtems_bdbuf_tracer)
     2111    rtems_bdbuf_show_users ("release", bd);
     2112 
    19432113  /*
    19442114   * If there are threads waiting to access the buffer wake them. Wake any
    1945    * waiters if this is the first buffer to placed back onto the queue.
     2115   * waiters if this buffer is placed back onto the LRU queue.
    19462116   */
    19472117  if (bd->waiters)
    19482118    rtems_bdbuf_wake (bdbuf_cache.access, &bdbuf_cache.access_waiters);
    19492119  else
    1950   {
    1951     if (bd->state == RTEMS_BDBUF_STATE_READ_AHEAD)
    1952     {
    1953       if (rtems_chain_has_only_one_node (&bdbuf_cache.ready))
    1954         rtems_bdbuf_wake (bdbuf_cache.waiting, &bdbuf_cache.wait_waiters);
    1955     }
    1956     else
    1957     {
    1958       if (rtems_chain_has_only_one_node (&bdbuf_cache.lru))
    1959         rtems_bdbuf_wake (bdbuf_cache.waiting, &bdbuf_cache.wait_waiters);
    1960     }
    1961   }
     2120    rtems_bdbuf_wake (bdbuf_cache.waiting, &bdbuf_cache.wait_waiters);
     2121 
     2122  if (rtems_bdbuf_tracer)
     2123    rtems_bdbuf_show_usage ();
    19622124 
    19632125  rtems_bdbuf_unlock_cache ();
     
    19772139  rtems_bdbuf_lock_cache ();
    19782140
    1979 #if RTEMS_BDBUF_TRACE
    1980   rtems_bdbuf_printf ("release modified: %d\n", bd->block);
    1981 #endif
     2141  if (rtems_bdbuf_tracer)
     2142    printf ("bdbuf:release modified: %lu\n", bd->block);
    19822143
    19832144  bd->hold_timer = rtems_bdbuf_configuration.swap_block_hold;
     2145 
     2146  if (rtems_bdbuf_tracer)
     2147    rtems_bdbuf_show_users ("release-modified", bd);
    19842148 
    19852149  rtems_bdbuf_append_modified (bd);
     
    19882152    rtems_bdbuf_wake (bdbuf_cache.access, &bdbuf_cache.access_waiters);
    19892153 
     2154  if (rtems_bdbuf_tracer)
     2155    rtems_bdbuf_show_usage ();
     2156 
    19902157  rtems_bdbuf_unlock_cache ();
    19912158
     
    19982165  bool available;
    19992166
    2000 #if RTEMS_BDBUF_TRACE
    2001   rtems_bdbuf_printf ("sync: %d\n", bd->block);
    2002 #endif
     2167  if (rtems_bdbuf_tracer)
     2168    printf ("bdbuf:sync: %lu\n", bd->block);
    20032169 
    20042170  if (!bdbuf_cache.initialised)
     
    20322198      case RTEMS_BDBUF_STATE_TRANSFER:
    20332199        bd->waiters++;
    2034         rtems_bdbuf_wait (&bdbuf_cache.transfer,
    2035                           &bdbuf_cache.transfer_waiters);
     2200        rtems_bdbuf_wait (&bdbuf_cache.transfer, &bdbuf_cache.transfer_waiters);
    20362201        bd->waiters--;
    20372202        break;
     
    20542219  rtems_event_set     out;
    20552220
    2056 #if RTEMS_BDBUF_TRACE
    2057   rtems_bdbuf_printf ("syncdev: %08x\n", dev);
    2058 #endif
     2221  if (rtems_bdbuf_tracer)
     2222    printf ("bdbuf:syncdev: %08x\n", (unsigned int) dev);
    20592223
    20602224  if (!bdbuf_cache.initialised)
     
    21062270/**
    21072271 * Call back handler called by the low level driver when the transfer has
    2108  * completed. This function may be invoked from interrupt handler.
     2272 * completed. This function may be invoked from interrupt handlers.
    21092273 *
    21102274 * @param arg Arbitrary argument specified in block device request
     
    21352299rtems_bdbuf_swapout_write (rtems_bdbuf_swapout_transfer* transfer)
    21362300{
    2137   rtems_disk_device*  dd;
    2138  
    2139 #if RTEMS_BDBUF_TRACE
    2140   rtems_bdbuf_printf ("swapout transfer: %08x\n", transfer->dev);
    2141 #endif
     2301  rtems_disk_device* dd;
     2302 
     2303  if (rtems_bdbuf_tracer)
     2304    printf ("bdbuf:swapout transfer: %08x\n", (unsigned int) transfer->dev);
    21422305
    21432306  /*
     
    21582321       */
    21592322      uint32_t last_block = 0;
     2323
     2324      /*
     2325       * Number of buffers per bd. This is used to detect the next
     2326       * block.
     2327       */
     2328      uint32_t bufs_per_bd = dd->block_size / bdbuf_config.buffer_min;
    21602329     
    21612330      /*
     
    21862355         */
    21872356       
    2188 #if RTEMS_BDBUF_TRACE
    2189         rtems_bdbuf_printf ("swapout write: bd:%d, bufnum:%d mode:%s\n",
    2190                             bd->block, transfer->write_req->bufnum,
    2191                             dd->phys_dev->capabilities &
    2192                             RTEMS_BLKDEV_CAP_MULTISECTOR_CONT ? "MULIT" : "SCAT");
    2193 #endif
    2194 
     2357        if (rtems_bdbuf_tracer)
     2358          printf ("bdbuf:swapout write: bd:%lu, bufnum:%lu mode:%s\n",
     2359                  bd->block, transfer->write_req->bufnum,
     2360                  dd->phys_dev->capabilities &
     2361                  RTEMS_BLKDEV_CAP_MULTISECTOR_CONT ? "MULIT" : "SCAT");
     2362       
    21952363        if ((dd->phys_dev->capabilities & RTEMS_BLKDEV_CAP_MULTISECTOR_CONT) &&
    21962364            transfer->write_req->bufnum &&
    2197             (bd->block != (last_block + 1)))
     2365            (bd->block != (last_block + bufs_per_bd)))
    21982366        {
    21992367          rtems_chain_prepend (&transfer->bds, &bd->link);
     
    22262394          uint32_t b;
    22272395
    2228 #if RTEMS_BDBUF_TRACE
    2229           rtems_bdbuf_printf ("swapout write: writing bufnum:%d\n",
    2230                               transfer->write_req->bufnum);
    2231 #endif
     2396          if (rtems_bdbuf_tracer)
     2397            printf ("bdbuf:swapout write: writing bufnum:%lu\n",
     2398                    transfer->write_req->bufnum);
     2399
    22322400          /*
    22332401           * Perform the transfer. No cache locks, no preemption, only the disk
     
    22802448               */
    22812449              bd->group->users--;
    2282              
     2450
     2451              if (rtems_bdbuf_tracer)
     2452                rtems_bdbuf_show_users ("write", bd);
     2453
    22832454              rtems_chain_append (&bdbuf_cache.lru, &bd->link);
    22842455             
     
    22862457                rtems_bdbuf_wake (bdbuf_cache.transfer, &bdbuf_cache.transfer_waiters);
    22872458              else
    2288               {
    2289                 if (rtems_chain_has_only_one_node (&bdbuf_cache.lru))
    2290                   rtems_bdbuf_wake (bdbuf_cache.waiting, &bdbuf_cache.wait_waiters);
    2291               }
     2459                rtems_bdbuf_wake (bdbuf_cache.waiting, &bdbuf_cache.wait_waiters);
    22922460            }
    22932461          }
    2294              
     2462
     2463          if (rtems_bdbuf_tracer)
     2464            rtems_bdbuf_show_usage ();
     2465
    22952466          rtems_bdbuf_unlock_cache ();
    22962467
     
    24522623   * If a sync is active do not use a worker because the current code does not
    24532624   * cleaning up after. We need to know the buffers have been written when
    2454    * syncing to release sync lock and currently worker threads do not return to
    2455    * here. We do not know the worker is the last in a sequence of sync writes
    2456    * until after we have it running so we do not know to tell it to release the
    2457    * lock. The simplest solution is to get the main swap out task perform all
    2458    * sync operations.
     2625   * syncing to the release sync lock and currently worker threads do not
     2626   * return to here. We do not know the worker is the last in a sequence of
     2627   * sync writes until after we have it running so we do not know to tell it to
     2628   * release the lock. The simplest solution is to get the main swap out task
     2629   * perform all sync operations.
    24592630   */
    24602631  if (bdbuf_cache.sync_active)
  • cpukit/libblock/src/blkdev.c

    rcdf0be6 reb649786  
    264264    rtems_disk_device *dd;
    265265    size_t            *arg_size = argp;
     266    int                rc = 0;
    266267
    267268    dd = rtems_disk_obtain(dev);
     
    292293        default:
    293294            errno = EINVAL;
    294             return -1;
     295            rc = -1;
    295296            break;
    296297    }
     
    298299    rtems_disk_release(dd);
    299300
    300     return 0;
    301 }
     301    return rc;
     302}
  • cpukit/libblock/src/diskdevs.c

    rcdf0be6 reb649786  
    315315  dd->start = start;
    316316  dd->size = size;
    317   dd->block_size = pdd->block_size;
     317  dd->block_size = dd->media_block_size = pdd->block_size;
    318318  dd->ioctl = pdd->ioctl;
    319319
  • cpukit/libblock/src/flashdisk.c

    rcdf0be6 reb649786  
    20542054{
    20552055  rtems_blkdev_sg_buffer* sg = req->bufs;
    2056   uint32_t                b;
     2056  uint32_t                buf;
    20572057  int                     ret = 0;
    20582058
    2059   for (b = 0; b < req->bufnum; b++, sg++)
    2060   {
    2061     uint32_t length = sg->length;
    2062  
    2063     if (sg->length != fd->block_size)
    2064     {
    2065       rtems_fdisk_error ("fdisk-read: length is not the block size: "\
    2066                          "bd:%d fd:%d", sg->length, fd->block_size);
    2067 
    2068       if (length > fd->block_size)
    2069         length = fd->block_size;
    2070     }
    2071 
    2072     ret = rtems_fdisk_read_block (fd, sg->block, sg->buffer);
    2073 
    2074     if (ret)
    2075       break;
     2059  for (buf = 0; (ret == 0) && (buf < req->bufnum); buf++, sg++)
     2060  {
     2061    uint8_t* data;
     2062    uint32_t fb;
     2063    uint32_t b;
     2064    fb = sg->length / fd->block_size;
     2065    data = sg->buffer;
     2066    for (b = 0; b < fb; b++, data += fd->block_size)
     2067    {
     2068      ret = rtems_fdisk_read_block (fd, sg->block + b, data);
     2069      if (ret)
     2070        break;
     2071    }
    20762072  }
    20772073
     
    20942090{
    20952091  rtems_blkdev_sg_buffer* sg = req->bufs;
    2096   uint32_t                b;
     2092  uint32_t                buf;
    20972093  int                     ret = 0;
    20982094
    2099   for (b = 0; b < req->bufnum; b++, sg++)
    2100   {
    2101     if (sg->length != fd->block_size)
    2102     {
    2103       rtems_fdisk_error ("fdisk-write: length is not the block size: " \
    2104                          "bd:%d fd:%d", sg->length, fd->block_size);
    2105     }
    2106 
    2107     ret = rtems_fdisk_write_block (fd, sg->block, sg->buffer);
    2108 
    2109     if (ret)
    2110       break;
     2095  for (buf = 0; (ret == 0) && (buf < req->bufnum); buf++, sg++)
     2096  {
     2097    uint8_t* data;
     2098    uint32_t fb;
     2099    uint32_t b;
     2100    fb = sg->length / fd->block_size;
     2101    data = sg->buffer;
     2102    for (b = 0; b < fb; b++, data += fd->block_size)
     2103    {
     2104      ret = rtems_fdisk_write_block (fd, sg->block + b, data);
     2105      if (ret)
     2106        break;
     2107    }
    21112108  }
    21122109
     
    23582355  else
    23592356  {
     2357    errno = 0;
    23602358    switch (req)
    23612359    {
     
    24112409
    24122410      default:
    2413         return rtems_blkdev_ioctl (dev, req, argp);
     2411        rtems_blkdev_ioctl (dev, req, argp);
    24142412        break;
    24152413    }
  • cpukit/libblock/src/nvdisk.c

    rcdf0be6 reb649786  
    574574{
    575575  rtems_blkdev_sg_buffer* sg = req->bufs;
    576   uint32_t                b;
    577   int32_t                 remains;
     576  uint32_t                bufs;
    578577  int                     ret = 0;
    579578
     
    582581#endif
    583582
    584   remains = req->bufnum * nvd->block_size;
    585  
    586   for (b = 0; b < req->bufnum; b++, sg++)
    587   {
    588     uint32_t length = sg->length;
    589 
    590     if (remains <= 0)
    591       rtems_nvdisk_error ("nvdisk-read: remains size <= 0");
    592      
    593     if (sg->length != nvd->block_size)
     583  for (bufs = 0; (ret == 0) && (bufs < req->bufnum); bufs++, sg++)
     584  {
     585    uint8_t* data;
     586    uint32_t nvb;
     587    uint32_t b;
     588    nvb = sg->length / nvd->block_size;
     589    data = sg->buffer;
     590    for (b = 0; b < nvb; b++, data += nvd->block_size)
    594591    {
    595       rtems_nvdisk_error ("nvdisk-read: length is not the block size: "\
    596                          "bd:%d nvd:%d", sg->length, nvd->block_size);
    597 
    598       if (length > nvd->block_size)
    599         length = nvd->block_size;
     592      ret = rtems_nvdisk_read_block (nvd, sg->block + b, data);
     593      if (ret)
     594        break;
    600595    }
    601 
    602     ret = rtems_nvdisk_read_block (nvd, sg->block, sg->buffer);
    603 
    604     if (ret)
    605       break;
    606 
    607     remains -= length;
    608596  }
    609597
     
    626614{
    627615  rtems_blkdev_sg_buffer* sg = req->bufs;
    628   uint32_t                b;
     616  uint32_t                bufs;
    629617  int                     ret = 0;
    630618
     
    633621#endif
    634622
    635   for (b = 0; b < req->bufnum; b++, sg++)
    636   {
    637     if (sg->length != nvd->block_size)
     623  for (bufs = 0; (ret == 0) && (bufs < req->bufnum); bufs++, sg++)
     624  {
     625    uint8_t* data;
     626    uint32_t nvb;
     627    uint32_t b;
     628    nvb = sg->length / nvd->block_size;
     629    data = sg->buffer;
     630    for (b = 0; b < nvb; b++, data += nvd->block_size)
    638631    {
    639       rtems_nvdisk_error ("nvdisk-write: length is not the block size: " \
    640                          "bd:%d nvd:%d", sg->length, nvd->block_size);
     632      ret = rtems_nvdisk_write_block (nvd, sg->block + b, data);
     633      if (ret)
     634        break;
    641635    }
    642 
    643     ret = rtems_nvdisk_write_block (nvd, sg->block, sg->buffer);
    644 
    645     if (ret)
    646       break;
    647636  }
    648637
     
    717706  else
    718707  {
     708    errno = 0;
    719709    switch (req)
    720710    {
     
    745735       
    746736      default:
    747         return rtems_blkdev_ioctl (dev, req, argp);
     737        rtems_blkdev_ioctl (dev, req, argp);
    748738        break;
    749739    }
  • cpukit/libblock/src/ramdisk.c

    rcdf0be6 reb649786  
    4242/* Internal RAM disk descriptor */
    4343struct ramdisk {
    44   uint32_t block_size; /* RAM disk block size */
     44  uint32_t block_size; /* RAM disk block size, the media size */
    4545  rtems_blkdev_bnum block_num; /* Number of blocks on this RAM disk */
    4646  void *area; /* RAM disk memory area */
     
    9595ramdisk_read(struct ramdisk *rd, rtems_blkdev_request *req)
    9696{
    97     char *from;
     97    uint8_t *from = rd->area;
    9898    uint32_t   i;
    9999    rtems_blkdev_sg_buffer *sg;
    100     uint32_t   remains;
    101 
    102 #if RTEMS_RAMDISK_TRACE
    103     rtems_ramdisk_printf (rd, "ramdisk read: start=%d, blocks=%d remains=%d",
    104                           req->bufs[0].block, req->bufnum,
    105                           rd->block_size * req->count);
    106 #endif
    107 
    108     remains = rd->block_size * req->bufnum;
    109     sg = req->bufs;
    110     for (i = 0; (remains > 0) && (i < req->bufnum); i++, sg++)
    111     {
    112         uint32_t count = sg->length;
    113         from = ((char *)rd->area + (sg->block * rd->block_size));
    114         if (count > remains)
    115             count = remains;
    116         memcpy(sg->buffer, from, count);
    117         remains -= count;
    118         from += count;
     100
     101#if RTEMS_RAMDISK_TRACE
     102    rtems_ramdisk_printf (rd, "ramdisk read: start=%d, blocks=%d",
     103                          req->bufs[0].block, req->bufnum);
     104#endif
     105
     106    for (i = 0, sg = req->bufs; i < req->bufnum; i++, sg++)
     107    {
     108#if RTEMS_RAMDISK_TRACE
     109        rtems_ramdisk_printf (rd, "ramdisk read: buf=%d block=%d length=%d off=%d addr=%p",
     110                              i, sg->block, sg->length, sg->block * rd->block_size,
     111                              from + (sg->block * rd->block_size));
     112#endif
     113        memcpy(sg->buffer, from + (sg->block * rd->block_size), sg->length);
    119114    }
    120115    req->req_done(req->done_arg, RTEMS_SUCCESSFUL, 0);
     
    136131ramdisk_write(struct ramdisk *rd, rtems_blkdev_request *req)
    137132{
    138     char *to;
     133    uint8_t *to = rd->area;
    139134    uint32_t   i;
    140135    rtems_blkdev_sg_buffer *sg;
    141     uint32_t   remains;
    142 
    143 #if RTEMS_RAMDISK_TRACE
    144     rtems_ramdisk_printf (rd, "ramdisk write: start=%d, blocks=%d remains=%d",
    145                           req->bufs[0].block, req->bufnum,
    146                           rd->block_size * req->bufnum);
    147 #endif
    148     remains = rd->block_size * req->bufnum;
    149     sg = req->bufs;
    150     for (i = 0; (remains > 0) && (i < req->bufnum); i++, sg++)
    151     {
    152         uint32_t count = sg->length;
    153         to = ((char *)rd->area + (sg->block * rd->block_size));
    154         if (count > remains)
    155             count = remains;
    156         memcpy(to, sg->buffer, count);
    157         remains -= count;
    158         to += count;
     136
     137#if RTEMS_RAMDISK_TRACE
     138    rtems_ramdisk_printf (rd, "ramdisk write: start=%d, blocks=%d",
     139                          req->bufs[0].block, req->bufnum);
     140#endif
     141    for (i = 0, sg = req->bufs; i < req->bufnum; i++, sg++)
     142    {
     143#if RTEMS_RAMDISK_TRACE
     144        rtems_ramdisk_printf (rd, "ramdisk write: buf=%d block=%d length=%d off=%d addr=%p",
     145                              i, sg->block, sg->length, sg->block * rd->block_size,
     146                              to + (sg->block * rd->block_size));
     147#endif
     148        memcpy(to + (sg->block * rd->block_size), sg->buffer, sg->length);
    159149    }
    160150    req->req_done(req->done_arg, RTEMS_SUCCESSFUL, 0);
  • cpukit/libcsupport/Makefile.am

    rcdf0be6 reb649786  
    6363    src/fcntl.c src/fpathconf.c src/getdents.c src/fsync.c src/fdatasync.c \
    6464    src/pipe.c src/dup.c src/dup2.c src/symlink.c src/readlink.c src/creat.c \
    65     src/chroot.c src/sync.c src/_rename_r.c
     65    src/chroot.c src/sync.c src/_rename_r.c src/statvfs.c
    6666
    6767## Until sys/uio.h is moved to libcsupport, we have to have networking
  • cpukit/libcsupport/include/rtems/libio.h

    rcdf0be6 reb649786  
    2929#include <sys/stat.h>
    3030#include <sys/ioctl.h>
     31#include <sys/statvfs.h>
    3132
    3233/*
     
    249250 char                              *buf,     /* OUT */
    250251 size_t                            bufsize
     252);
     253
     254typedef int (*rtems_filesystem_statvfs_t)(
     255 rtems_filesystem_location_info_t  *loc,     /* IN  */
     256 struct statvfs                    *buf      /* OUT */
    251257);
    252258
     
    275281    rtems_filesystem_symlink_t       symlink_h;
    276282    rtems_filesystem_readlink_t      readlink_h;
     283    rtems_filesystem_statvfs_t       statvfs_h;
    277284};
    278285
  • cpukit/libfs/src/devfs/devfs_init.c

    rcdf0be6 reb649786  
    2929    NULL,
    3030    devFS_initialize,
     31    NULL,
    3132    NULL,
    3233    NULL,
  • cpukit/libfs/src/dosfs/fat.c

    rcdf0be6 reb649786  
    265265}
    266266
     267/* _fat_block_release --
     268 *     This function works around the hack that hold a bdbuf and does
     269 *     not release it.
     270 *
     271 * PARAMETERS:
     272 *     mt_entry - mount table entry
     273 *
     274 * RETURNS:
     275 *     0 on success, or -1 if error occured and errno set appropriately
     276 */
     277int
     278_fat_block_release(
     279    rtems_filesystem_mount_table_entry_t *mt_entry)
     280{
     281    fat_fs_info_t *fs_info = mt_entry->fs_info;
     282    return fat_buf_release(fs_info);
     283}
     284   
    267285/* fat_cluster_read --
    268286 *     wrapper for reading a whole cluster at once
     
    505523                FAT_FSINFO_LEAD_SIGNATURE_VALUE)
    506524            {
     525                _fat_block_release(mt_entry);
    507526                rtems_disk_release(vol->dd);
    508527                rtems_set_errno_and_return_minus_one( EINVAL );
     
    514533                if ( ret < 0 )
    515534                {
     535                    _fat_block_release(mt_entry);
    516536                    rtems_disk_release(vol->dd);
    517537                    return -1;
     
    524544                if ( rc != RC_OK )
    525545                {
     546                    _fat_block_release(mt_entry);
    526547                    rtems_disk_release(vol->dd);
    527548                    return rc;
     
    538559        vol->next_cl = 0xFFFFFFFF;
    539560    }
     561
     562    _fat_block_release(mt_entry);
     563
    540564    vol->afat_loc = vol->fat_loc + vol->fat_length * vol->afat;
    541565
  • cpukit/libfs/src/dosfs/fat.h

    rcdf0be6 reb649786  
    465465                 const void                           *buff);
    466466
     467int
     468_fat_block_release(rtems_filesystem_mount_table_entry_t *mt_entry);
     469
    467470ssize_t
    468471fat_cluster_read(rtems_filesystem_mount_table_entry_t *mt_entry,
  • cpukit/libfs/src/dosfs/msdos_init.c

    rcdf0be6 reb649786  
    3939    NULL,
    4040    NULL,
     41    NULL,
    4142    NULL
    4243};
  • cpukit/libfs/src/imfs/imfs_init.c

    rcdf0be6 reb649786  
    5050  IMFS_evaluate_link,
    5151  IMFS_symlink,
    52   IMFS_readlink
     52  IMFS_readlink,
     53  NULL
    5354};
    5455
  • cpukit/libfs/src/nfsclient/src/nfs.c

    rcdf0be6 reb649786  
    24572457                nfs_symlink,            /* OPTIONAL; may be NULL */
    24582458                nfs_readlink,           /* OPTIONAL; may be NULL */
     2459                NULL                            /* OPTIONAL; may be NULL */
    24592460};
    24602461
  • cpukit/libmisc/Makefile.am

    rcdf0be6 reb649786  
    7474    shell/main_cp.c shell/main_cpuuse.c shell/main_date.c shell/main_dir.c \
    7575    shell/main_echo.c shell/main_exit.c shell/main_halt.c shell/main_help.c \
    76     shell/main_id.c shell/main_logoff.c shell/main_ls.c \
     76    shell/main_id.c shell/main_logoff.c shell/main_ln.c shell/main_ls.c \
    7777    shell/main_mallocinfo.c shell/main_mdump.c shell/main_medit.c \
    7878    shell/main_mfill.c shell/main_mkdir.c shell/main_mount.c \
     
    9696    shell/main_hexdump.c shell/hexdump-conv.c shell/hexdump-display.c \
    9797    shell/hexdump-odsyntax.c shell/hexdump-parse.c shell/hexsyntax.c \
    98     shell/main_time.c
     98    shell/main_time.c shell/main_mknod.c
    9999
    100100if LIBNETWORKING
  • cpukit/libmisc/shell/hexdump-display.c

    rcdf0be6 reb649786  
    366366          err(exit_jump, 1, "file name allocation");
    367367        }
     368        memset (hdstdin, 0, sizeof(FILE));
    368369      }
    369                         if (!(hdstdin = fopen(*_argv, "r"))) {
     370                        if (!(hdstdin = freopen(*_argv, "r", hdstdin))) {
    370371                                warn("%s", *_argv);
    371372                                exitval = 1;
     
    400401                if (fstat(fileno(hdstdin), &sb))
    401402                        err(exit_jump, 1, "%s", fname);
    402                 if (S_ISREG(sb.st_mode) && skip >= sb.st_size) {
     403    /* can seek block devices on RTEMS */
     404                if (0 && S_ISREG(sb.st_mode) && skip >= sb.st_size) {
    403405                        address += sb.st_size;
    404406                        skip -= sb.st_size;
    405407                        return;
    406408                }
    407         }
    408         if (S_ISREG(sb.st_mode)) {
    409                 if (fseeko(hdstdin, skip, SEEK_SET))
    410                         err(exit_jump, 1, "%s", fname);
    411                 address += skip;
    412                 skip = 0;
    413         } else {
    414                 for (cnt = 0; cnt < skip; ++cnt)
    415                         if (getchar() == EOF)
    416                                 break;
    417                 address += cnt;
    418                 skip -= cnt;
    419         }
    420 }
     409                if (1 || S_ISREG(sb.st_mode)) {
     410                        if (fseeko(hdstdin, skip, SEEK_SET))
     411                                err(exit_jump, 1, "%s", fname);
     412                        address += skip;
     413                        skip = 0;
     414                } else {
     415                        for (cnt = 0; cnt < skip; ++cnt)
     416                                if (getchar() == EOF)
     417                                        break;
     418                        address += cnt;
     419                        skip -= cnt;
     420                }
     421        }
     422}
  • cpukit/libmisc/shell/main_mount.c

    rcdf0be6 reb649786  
    129129          if (*a)
    130130            fprintf (stderr, "%s ", (*a)->name);
     131        if (!rtems_chain_is_empty(&filesystems)) {
     132          rtems_chain_node* node = filesystems.first;
     133          while (!rtems_chain_is_tail (&filesystems, node)) {
     134            rtems_shell_filesystems_t* f = (rtems_shell_filesystems_t*)node;
     135            fprintf (stderr, "%s ", f->name);
     136            node = node->next;
     137          }
     138        }
    131139        fprintf (stderr, "\n");
    132140        return 1;
  • cpukit/libmisc/shell/shellconfig.h

    rcdf0be6 reb649786  
    5151extern rtems_shell_cmd_t rtems_shell_MV_Command;
    5252extern rtems_shell_cmd_t rtems_shell_RM_Command;
     53extern rtems_shell_cmd_t rtems_shell_LN_Command;
     54extern rtems_shell_cmd_t rtems_shell_MKNOD_Command;
    5355extern rtems_shell_cmd_t rtems_shell_UMASK_Command;
    5456extern rtems_shell_cmd_t rtems_shell_MOUNT_Command;
     
    286288        defined(CONFIGURE_SHELL_COMMAND_RM)
    287289      &rtems_shell_RM_Command,
     290    #endif
     291    #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
     292         !defined(CONFIGURE_SHELL_NO_COMMAND_LN)) || \
     293        defined(CONFIGURE_SHELL_COMMAND_LN)
     294      &rtems_shell_LN_Command,
     295    #endif
     296    #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
     297         !defined(CONFIGURE_SHELL_NO_COMMAND_MKNOD)) || \
     298        defined(CONFIGURE_SHELL_COMMAND_MKNOD)
     299      &rtems_shell_MKNOD_Command,
    288300    #endif
    289301    #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \
  • cpukit/libmisc/shell/utils-cp.c

    rcdf0be6 reb649786  
    7070#define cp_pct(x, y)    ((y == 0) ? 0 : (int)(100.0 * (x) / (y)))
    7171
    72 /* original was MAXBSIZE which results in 64K on the stack */
    73 #define MAX_READ 1024
    74 
    7572int
    7673set_utimes(const char *file, struct stat *fs)
     
    9188copy_file(rtems_shell_cp_globals* cp_globals __attribute__((unused)), FTSENT *entp, int dne)
    9289{
    93         static char buf[MAX_READ];
     90#define MAX_READ max_read
     91  int max_read;
     92        char* buf;
    9493        struct stat *fs;
    9594        ssize_t wcount;
     
    102101#endif
    103102
     103        fs = entp->fts_statp;
     104
     105  max_read = fs->st_blksize;
     106  if (max_read < (8 * 1024))
     107    max_read = 8 * 1024;
     108  buf = malloc (max_read);
     109  if (!buf)
     110  {
     111                warn("no memory");
     112    return (1);
     113  }
     114
    104115        if ((from_fd = open(entp->fts_path, O_RDONLY, 0)) == -1) {
    105116                warn("%s", entp->fts_path);
    106                 return (1);
    107         }
    108 
    109         fs = entp->fts_statp;
     117    (void)free(buf);
     118                return (1);
     119        }
    110120
    111121        /*
     
    123133                                printf("%s not overwritten\n", to.p_path);
    124134                        (void)close(from_fd);
     135      (void)free(buf);
    125136                        return (0);
    126137                } else if (iflag) {
     
    132143                        if (checkch != 'y' && checkch != 'Y') {
    133144                                (void)close(from_fd);
     145        (void)free(buf);
    134146                                (void)fprintf(stderr, "not overwritten\n");
    135147                                return (1);
     
    158170                warn("%s", to.p_path);
    159171                (void)close(from_fd);
     172    (void)free(buf);
    160173                return (1);
    161174        }
     
    262275                }
    263276        }
     277  (void)free(buf);
    264278        return (rval);
    265279}
  • cpukit/preinstall.am

    rcdf0be6 reb649786  
    7373PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/ioctl.h
    7474
     75$(PROJECT_INCLUDE)/sys/statvfs.h: libcsupport/include/sys/statvfs.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
     76        $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/statvfs.h
     77PREINSTALL_FILES += $(PROJECT_INCLUDE)/sys/statvfs.h
     78
    7579$(PROJECT_INCLUDE)/sys/sockio.h: libcsupport/include/sys/sockio.h $(PROJECT_INCLUDE)/sys/$(dirstamp)
    7680        $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/sys/sockio.h
  • cpukit/sapi/inline/rtems/chain.inl

    rcdf0be6 reb649786  
    7575
    7676/**
     77 *  @brief Set off chain
     78 *
     79 *  This function sets the next and previous fields of the @a node to NULL
     80 *  indicating the @a node is not part of a chain.
     81 *
     82 *  @param[in] node the node set to off chain.
     83 */
     84RTEMS_INLINE_ROUTINE void rtems_chain_set_off_chain(
     85  rtems_chain_node *node
     86)
     87{
     88  _Chain_Set_off_chain( node );
     89}
     90
     91/**
     92 *  @brief Is the Node off Chain
     93 *
     94 *  This function returns true if the @a node is not on a chain. A @a node is
     95 *  off chain if the next and previous fields are set to NULL.
     96 *
     97 *  @param[in] node is the node off chain.
     98 *
     99 *  @return This function returns true if the @a node is off chain.
     100 */
     101RTEMS_INLINE_ROUTINE bool rtems_chain_is_node_off_chain(
     102  const rtems_chain_node *node
     103)
     104{
     105  return _Chain_Is_node_off_chain( node );
     106}
     107
     108/**
    77109 *  @brief Is the Chain Node Pointer NULL
    78110 *
     
    170202{
    171203  return _Chain_Next( the_node );
     204}
     205
     206/**
     207 *  @brief Return pointer the previous node from this node
     208 *
     209 *  This function returns a pointer to the previous node on this chain.
     210 *
     211 *  @param[in] the_node is the node to be operated upon.
     212 *
     213 *  @return This method returns the previous node on the chain.
     214 */
     215RTEMS_INLINE_ROUTINE rtems_chain_node *rtems_chain_previous(
     216  rtems_chain_node *the_node
     217)
     218{
     219  return _Chain_Previous( the_node );
    172220}
    173221
  • cpukit/score/inline/rtems/score/address.inl

    rcdf0be6 reb649786  
    4343RTEMS_INLINE_ROUTINE void *_Addresses_Add_offset (
    4444  const void *base,
    45   intptr_t    offset
     45  uintptr_t   offset
    4646)
    4747{
    48   return (void *)((intptr_t)base + offset);
     48  return (void *)((uintptr_t)base + offset);
    4949}
    5050
     
    6363RTEMS_INLINE_ROUTINE void *_Addresses_Subtract_offset (
    6464  const void *base,
    65   intptr_t    offset
     65  uintptr_t   offset
    6666)
    6767{
    68   return (void *)((intptr_t)base - offset);
     68  return (void *)((uintptr_t)base - offset);
    6969}
    7070
  • cpukit/score/inline/rtems/score/chain.inl

    rcdf0be6 reb649786  
    3232 *  @{
    3333 */
     34
     35/** @brief Set off chain
     36 *
     37 *  This function sets the next and previous fields of the @a node to NULL
     38 *  indicating the @a node is not part of a chain.
     39 *
     40 *  @param[in] node the node set to off chain.
     41 */
     42RTEMS_INLINE_ROUTINE void _Chain_Set_off_chain(
     43  Chain_Node *node
     44)
     45{
     46  node->next = node->previous = NULL;
     47}
     48
     49/** @brief Is the Node off Chain
     50 *
     51 *  This function returns true if the @a node is not on a chain. A @a node is
     52 *  off chain if the next and previous fields are set to NULL.
     53 *
     54 *  @param[in] node is the node off chain.
     55 *
     56 *  @return This function returns true if the @a node is off chain.
     57 */
     58RTEMS_INLINE_ROUTINE bool _Chain_Is_node_off_chain(
     59  const Chain_Node *node
     60)
     61{
     62  return (node->next == NULL) && (node->previous == NULL);
     63}
    3464
    3565/** @brief Are Two Nodes Equal
  • cpukit/score/src/coremsgsubmit.c

    rcdf0be6 reb649786  
    8989      );
    9090      *(size_t *) the_thread->Wait.return_argument = size;
    91       the_thread->Wait.count = submit_type;
     91      the_thread->Wait.count = (uint32_t) submit_type;
    9292
    9393      #if defined(RTEMS_MULTIPROCESSING)
  • cpukit/score/src/objectallocate.c

    rcdf0be6 reb649786  
    7474      uint32_t   block;
    7575
    76       block = _Objects_Get_index( the_object->id ) -
     76      block = (uint32_t) _Objects_Get_index( the_object->id ) -
    7777              _Objects_Get_index( information->minimum_id );
    7878      block /= information->allocation_size;
  • cpukit/score/src/objectfree.c

    rcdf0be6 reb649786  
    5151    uint32_t    block;
    5252
    53     block =
    54       _Objects_Get_index( the_object->id ) - _Objects_Get_index( information->minimum_id );
     53    block = (uint32_t) (_Objects_Get_index( the_object->id ) -
     54                        _Objects_Get_index( information->minimum_id ));
    5555    block /= information->allocation_size;
    5656
Note: See TracChangeset for help on using the changeset viewer.