Changeset 796967c in rtems for testsuites/samples/fileio/init.c


Ignore:
Timestamp:
Feb 28, 2012, 4:19:49 PM (8 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
3ee7b84
Parents:
1024561
git-author:
Sebastian Huber <sebastian.huber@…> (02/28/12 16:19:49)
git-committer:
Sebastian Huber <sebastian.huber@…> (03/13/12 11:24:18)
Message:

libblock: Change bdbuf API

The functions

o rtems_bdbuf_get(),
o rtems_bdbuf_read(),
o rtems_bdbuf_syncdev(), and
o rtems_bdbuf_purge_dev(),

use now the disk device instead of the device identifier. This makes
bdbuf independent of rtems_disk_obtain() and rtems_disk_release(). It
is the responsiblity of the file system to obtain the disk device. This
also reduces the overhead to get a buffer.

The key for the AVL tree uses now the disk device instead of the device
identifier. The pointer is interpreted as an unsigned integer. This
reduces the memory overhead and makes the comparison operation a bit
faster.

Removed function rtems_bdbuf_purge_major(). This function was too
destructive and could have unpredictable side effects.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • testsuites/samples/fileio/init.c

    r1024561 r796967c  
    326326
    327327static int
    328 disk_test_set_block_size (dev_t dev, size_t size)
    329 {
    330   rtems_disk_device* dd;
    331   int                rc;
    332  
    333   dd = rtems_disk_obtain (dev);
    334   if (!dd)
    335   {
    336     printf ("error: cannot obtain disk\n");
    337     return 1;
    338   }
    339  
    340   rc = dd->ioctl (dd, RTEMS_BLKIO_SETBLKSIZE, &size);
    341 
    342   rtems_disk_release (dd);
    343 
    344   return rc;
     328disk_test_set_block_size (rtems_disk_device *dd, size_t size)
     329{
     330  return dd->ioctl (dd, RTEMS_BLKIO_SETBLKSIZE, &size);
    345331}
    346332
     
    354340  rtems_bdbuf_buffer* bd;
    355341  rtems_status_code   sc;
    356  
    357   if (disk_test_set_block_size (dev, size) < 0)
     342  int                 rv = 0;
     343  rtems_disk_device* dd;
     344 
     345  dd = rtems_disk_obtain (dev);
     346  if (!dd)
     347  {
     348    printf ("error: cannot obtain disk\n");
     349    rv = 1;
     350  }
     351 
     352  if (rv == 0 && disk_test_set_block_size (dd, size) < 0)
    358353  {
    359354    printf ("error: set block size failed: %s\n", strerror (errno));
    360     return 1;
    361   }
    362 
    363   for (block = start; block < (start + count); block++)
    364   {
    365     sc = rtems_bdbuf_read (dev, block, &bd);
    366     if (sc != RTEMS_SUCCESSFUL)
     355    rv = 1;
     356  }
     357
     358  for (block = start; rv == 0 && block < (start + count); block++)
     359  {
     360    sc = rtems_bdbuf_read (dd, block, &bd);
     361    if (sc == RTEMS_SUCCESSFUL)
     362    {
     363      ip = (uint32_t*) bd->buffer;
     364      for (i = 0; i < (size / sizeof (uint32_t)); i++, ip++, value++)
     365        *ip = (size << 16) | value;
     366
     367      sc = rtems_bdbuf_release_modified (bd);
     368      if (sc != RTEMS_SUCCESSFUL)
     369      {
     370        printf ("error: release block %d bd failed: %s\n",
     371                block, rtems_status_text (sc));
     372        rv = 1;
     373      }
     374    }
     375    else
    367376    {
    368377      printf ("error: get block %d bd failed: %s\n",
    369378              block, rtems_status_text (sc));
    370       return 1;
    371     }
    372 
    373     ip = (uint32_t*) bd->buffer;
    374     for (i = 0; i < (size / sizeof (uint32_t)); i++, ip++, value++)
    375       *ip = (size << 16) | value;
    376 
    377     sc = rtems_bdbuf_release_modified (bd);
    378     if (sc != RTEMS_SUCCESSFUL)
    379     {
    380       printf ("error: release block %d bd failed: %s\n",
    381               block, rtems_status_text (sc));
    382       return 1;
    383     }
    384   }
    385 
    386   return 0;
     379      rv = 1;
     380    }
     381  }
     382
     383  rtems_disk_release (dd);
     384
     385  return rv;
    387386}
    388387
Note: See TracChangeset for help on using the changeset viewer.