Changeset 0aea082 in rtems


Ignore:
Timestamp:
Jul 30, 2010, 10:36:32 PM (9 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.11, master
Children:
cc43b364
Parents:
3bae3f2
Message:

2010-07-30 Joel Sherrill <joel.sherrill@…>

  • libcsupport/src/fstat.c, libcsupport/src/rmdir.c, libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_creat.c, libfs/src/imfs/imfs_debug.c, libfs/src/imfs/imfs_getchild.c, libfs/src/imfs/memfile.c: Add IMFS_assert. Clean up and remove all checks which are redundant with system call layer. Formatting.
Location:
cpukit
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    r3bae3f2 r0aea082  
     12010-07-30      Joel Sherrill <joel.sherrill@oarcorp.com>
     2
     3        * libcsupport/src/fstat.c, libcsupport/src/rmdir.c,
     4        libfs/src/imfs/imfs.h, libfs/src/imfs/imfs_creat.c,
     5        libfs/src/imfs/imfs_debug.c, libfs/src/imfs/imfs_getchild.c,
     6        libfs/src/imfs/memfile.c: Add IMFS_assert. Clean up and remove all
     7        checks which are redundant with system call layer. Formatting.
     8
    192010-07-30      Gedare Bloom <giddyup44@yahoo.com>
    210
  • cpukit/libcsupport/src/fstat.c

    r3bae3f2 r0aea082  
    3333   *  Check to see if we were passed a valid pointer.
    3434   */
    35 
    3635  if ( !sbuf )
    3736    rtems_set_errno_and_return_minus_one( EFAULT );
     
    4039   *  Now process the stat() request.
    4140   */
    42 
    4341  iop = rtems_libio_iop( fd );
    4442  rtems_libio_check_fd( fd );
  • cpukit/libcsupport/src/rmdir.c

    r3bae3f2 r0aea082  
    7575   * Verify you can remove this node as a directory.
    7676   */
    77   if (  (*loc.ops->node_type_h)( &loc ) != RTEMS_FILESYSTEM_DIRECTORY ){
     77  if ( (*loc.ops->node_type_h)( &loc ) != RTEMS_FILESYSTEM_DIRECTORY ) {
    7878    rtems_filesystem_freenode( &loc );
    7979    if ( free_parentloc )
  • cpukit/libfs/src/imfs/imfs.h

    r3bae3f2 r0aea082  
    561561);
    562562
     563/*
     564 *  Turn on IMFS assertions when RTEMS_DEBUG is defined.
     565 */
     566#ifdef RTEMS_DEBUG
     567  #include <assert.h>
     568
     569  #define IMFS_assert(_x) assert(_X)
     570#else
     571  #define IMFS_assert(_x)
     572#endif
     573
    563574#ifdef __cplusplus
    564575}
  • cpukit/libfs/src/imfs/imfs_creat.c

    r3bae3f2 r0aea082  
    1818#endif
    1919
    20 #if defined(RTEMS_DEBUG)
    21   #include <assert.h>
    22 #endif
    2320#include <stdlib.h>
    2421#include <string.h>
     
    10299
    103100    default:
    104       #if defined(RTEMS_DEBUG)
    105         assert(0);
    106       #endif
     101      IMFS_assert(0);
    107102      break;
    108103  }
     
    111106   *  This node MUST have a parent, so put it in that directory list.
    112107   */
    113 
    114108  node->Parent = parent;
    115109  node->st_ino = ++fs_info->ino_count;
  • cpukit/libfs/src/imfs/imfs_debug.c

    r3bae3f2 r0aea082  
    1616#endif
    1717
    18 #if defined(RTEMS_DEBUG)
    19   #include <assert.h>
    20 #endif
    2118#include <string.h>
    2219#include <fcntl.h>
     
    3734 *  This routine prints the contents of the specified jnode.
    3835 */
    39 
    4036void IMFS_print_jnode(
    4137  IMFS_jnode_t *the_jnode
    4238)
    4339{
    44   #if defined(RTEMS_DEBUG)
    45     assert( the_jnode );
    46   #endif
     40  IMFS_assert( the_jnode );
    4741
    4842  fprintf(stdout, "%s", the_jnode->name );
     
    10599 *  the subdirectory.
    106100 */
    107 
    108101void IMFS_dump_directory(
    109102  IMFS_jnode_t  *the_directory,
     
    116109  int                   i;
    117110
    118   #if defined(RTEMS_DEBUG)
    119     assert( the_directory );
    120     assert( level >= 0 );
    121     assert( the_directory->type == IMFS_DIRECTORY );
    122   #endif
     111  IMFS_assert( the_directory );
     112  IMFS_assert( level >= 0 );
     113  IMFS_assert( the_directory->type == IMFS_DIRECTORY );
    123114
    124115  the_chain = &the_directory->info.directory.Entries;
     
    153144  fprintf(stdout, "/\n" );
    154145  IMFS_dump_directory( rtems_filesystem_root.node_access, 0 );
    155   fprintf(stdout, "***************       End of Dump        ***************\n" );
     146  fprintf(stdout, "***************      End of Dump       ***************\n" );
    156147}
    157148
     
    163154 *
    164155 */
    165 
    166156int IMFS_memfile_maximum_size( void )
    167157{
  • cpukit/libfs/src/imfs/imfs_getchild.c

    r3bae3f2 r0aea082  
    1818#endif
    1919
    20 #if defined(RTEMS_DEBUG)
    21   #include <assert.h>
    22 #endif
    2320#include <errno.h>
    2421#include <string.h>
     
    4138   *  the IMFS code.
    4239   */
    43 
    44   #if defined(RTEMS_DEBUG)
    45     assert( directory );
    46     assert( name );
    47   #endif
    48   if ( !name )
    49     return 0;
    50 
    51   if ( !directory )
    52     return 0;
     40  IMFS_assert( directory );
     41  IMFS_assert( name );
    5342
    5443  /*
  • cpukit/libfs/src/imfs/memfile.c

    r3bae3f2 r0aea082  
    3232#include <rtems/seterr.h>
    3333
    34 #if defined(RTEMS_DEBUG)
    35   #include <assert.h>
    36 #endif
    37 
    3834#define MEMFILE_STATIC
    3935
     
    4137 *  Prototypes of private routines
    4238 */
    43 
    4439MEMFILE_STATIC int IMFS_memfile_extend(
    4540   IMFS_jnode_t  *the_jnode,
     
    8984 *  nothing special to be done at open() time.
    9085 */
    91 
    9286int memfile_open(
    9387  rtems_libio_t *iop,
     
    131125 *  nothing to flush or memory to free at this point.
    132126 */
    133 
    134127int memfile_close(
    135128  rtems_libio_t *iop
     
    153146 *  This routine processes the read() system call.
    154147 */
    155 
    156148ssize_t memfile_read(
    157149  rtems_libio_t *iop,
     
    172164 *  This routine processes the write() system call.
    173165 */
    174 
    175166ssize_t memfile_write(
    176167  rtems_libio_t *iop,
     
    197188 *  NOTE:  No ioctl()'s are supported for in-memory files.
    198189 */
    199 
    200190int memfile_ioctl(
    201191  rtems_libio_t *iop,
     
    216206 *  This routine processes the lseek() system call.
    217207 */
    218 
    219208rtems_off64_t memfile_lseek(
    220209  rtems_libio_t   *iop,
     
    251240 *  This routine processes the ftruncate() system call.
    252241 */
    253 
    254242int memfile_ftruncate(
    255243  rtems_libio_t        *iop,
     
    275263   *  future use and just set the length.
    276264   */
    277 
    278265  the_jnode->info.file.size = length;
    279266  iop->size = the_jnode->info.file.size;
     
    291278 *  extend the file.
    292279 */
    293 
    294280MEMFILE_STATIC int IMFS_memfile_extend(
    295281   IMFS_jnode_t  *the_jnode,
     
    304290   *  Perform internal consistency checks
    305291   */
    306 
    307   #if defined(RTEMS_DEBUG)
    308     assert( the_jnode );
    309     assert( the_jnode->type == IMFS_MEMORY_FILE );
    310   #endif
    311   if ( !the_jnode )
    312     rtems_set_errno_and_return_minus_one( EIO );
    313 
    314   if ( the_jnode->type != IMFS_MEMORY_FILE )
    315     rtems_set_errno_and_return_minus_one( EIO );
    316 
     292  IMFS_assert( the_jnode );
     293    IMFS_assert( the_jnode->type == IMFS_MEMORY_FILE );
     294
     295  /*
     296   *  Verify new file size is supported
     297   */
    317298  if ( new_length >= IMFS_MEMFILE_MAXIMUM_SIZE )
    318299    rtems_set_errno_and_return_minus_one( EINVAL );
    319300
     301  /*
     302   *  Verify new file size is actually larger than current size
     303   */
    320304  if ( new_length <= the_jnode->info.file.size )
    321305    return 0;
     
    324308   *  Calculate the number of range of blocks to allocate
    325309   */
    326 
    327310  new_blocks = new_length / IMFS_MEMFILE_BYTES_PER_BLOCK;
    328311  old_blocks = the_jnode->info.file.size / IMFS_MEMFILE_BYTES_PER_BLOCK;
     
    331314   *  Now allocate each of those blocks.
    332315   */
    333 
    334316  for ( block=old_blocks ; block<=new_blocks ; block++ ) {
    335317    if ( IMFS_memfile_addblock( the_jnode, block ) ) {
    336318       for ( ; block>=old_blocks ; block-- ) {
    337           IMFS_memfile_remove_block( the_jnode, block );
     319         IMFS_memfile_remove_block( the_jnode, block );
    338320       }
    339321       rtems_set_errno_and_return_minus_one( ENOSPC );
     
    344326   *  Set the new length of the file.
    345327   */
    346 
    347328  the_jnode->info.file.size = new_length;
    348329  return 0;
     
    354335 *  This routine adds a single block to the specified in-memory file.
    355336 */
    356 
    357337MEMFILE_STATIC int IMFS_memfile_addblock(
    358338   IMFS_jnode_t  *the_jnode,
     
    363343  block_p *block_entry_ptr;
    364344
    365   #if defined(RTEMS_DEBUG)
    366     assert( the_jnode );
    367     assert( the_jnode->type == IMFS_MEMORY_FILE );
    368   #endif
    369   if ( !the_jnode )
    370     rtems_set_errno_and_return_minus_one( EIO );
    371 
    372   if ( the_jnode->type != IMFS_MEMORY_FILE )
    373     rtems_set_errno_and_return_minus_one( EIO );
    374 
     345  IMFS_assert( the_jnode );
     346  IMFS_assert( the_jnode->type == IMFS_MEMORY_FILE );
     347
     348  /*
     349   * Obtain the pointer for the specified block number
     350   */
    375351  block_entry_ptr = IMFS_memfile_get_block_pointer( the_jnode, block, 1 );
    376352  if ( *block_entry_ptr )
    377353    return 0;
    378354
    379 #if 0
    380   fprintf(stdout, "%d %p", block, block_entry_ptr );
    381     fflush(stdout);
    382 #endif
    383 
     355  /*
     356   *  There is no memory for this block number so allocate it.
     357   */
    384358  memory = memfile_alloc_block();
    385359  if ( !memory )
    386360    return 1;
     361
    387362  *block_entry_ptr = memory;
    388 
    389363  return 0;
    390364}
     
    400374 *         dangerous and the results unpredictable.
    401375 */
    402 
    403376MEMFILE_STATIC int IMFS_memfile_remove_block(
    404377   IMFS_jnode_t  *the_jnode,
     
    410383
    411384  block_ptr = IMFS_memfile_get_block_pointer( the_jnode, block, 0 );
    412   #if defined(RTEMS_DEBUG)
    413     assert( block_ptr );
    414   #endif
    415   if ( block_ptr ) {
    416     ptr = *block_ptr;
    417     *block_ptr = 0;
    418     memfile_free_block( ptr );
    419   }
     385  IMFS_assert( block_ptr );
     386
     387  ptr = *block_ptr;
     388  *block_ptr = 0;
     389  memfile_free_block( ptr );
    420390
    421391  return 1;
     
    428398 *  blocks in one of the indirection tables.
    429399 */
    430 
    431400void memfile_free_blocks_in_table(
    432401  block_p **block_table,
     
    440409   *  Perform internal consistency checks
    441410   */
    442 
    443   #if defined(RTEMS_DEBUG)
    444     assert( block_table );
    445   #endif
    446   if ( !block_table )
    447     return;
     411  IMFS_assert( block_table );
    448412
    449413  /*
    450414   *  Now go through all the slots in the table and free the memory.
    451415   */
    452 
    453416  b = *block_table;
    454417
     
    464427   *  free the block table itself.
    465428   */
    466 
    467429  memfile_free_block( *block_table );
    468430  *block_table = 0;
     
    487449 *         is better to stick to simple, easy to understand algorithms.
    488450 */
    489 
    490451int IMFS_memfile_remove(
    491452 IMFS_jnode_t  *the_jnode
     
    501462   *  Perform internal consistency checks
    502463   */
    503 
    504   #if defined(RTEMS_DEBUG)
    505     assert( the_jnode );
    506     assert( the_jnode->type == IMFS_MEMORY_FILE );
    507   #endif
    508   if ( !the_jnode )
    509     rtems_set_errno_and_return_minus_one( EIO );
    510 
    511   if ( the_jnode->type != IMFS_MEMORY_FILE )
    512     rtems_set_errno_and_return_minus_one( EIO );
     464  IMFS_assert( the_jnode );
     465  IMFS_assert( the_jnode->type == IMFS_MEMORY_FILE );
    513466
    514467  /*
     
    516469   *  memfile_free_blocks_in_table to greatly speed this up.
    517470   */
    518 
    519471  to_free = IMFS_MEMFILE_BLOCK_SLOTS;
    520472
     
    525477   *    + triply indirect
    526478   */
    527 
    528479  info = &the_jnode->info.file;
    529480
     
    533484
    534485  if ( info->doubly_indirect ) {
    535 
    536486    for ( i=0 ; i<IMFS_MEMFILE_BLOCK_SLOTS ; i++ ) {
    537487      if ( info->doubly_indirect[i] ) {
     
    575525 *  read).
    576526 */
    577 
    578527MEMFILE_STATIC ssize_t IMFS_memfile_read(
    579528   IMFS_jnode_t    *the_jnode,
     
    597546   *  Perform internal consistency checks
    598547   */
    599 
    600   #if defined(RTEMS_DEBUG)
    601     assert( the_jnode );
    602     assert( the_jnode->type == IMFS_MEMORY_FILE ||
     548  IMFS_assert( the_jnode );
     549  IMFS_assert( the_jnode->type == IMFS_MEMORY_FILE ||
    603550       the_jnode->type != IMFS_LINEAR_FILE );
    604     assert( dest );
    605   #endif
    606   if ( !the_jnode )
    607     rtems_set_errno_and_return_minus_one( EIO );
    608 
    609   if ( the_jnode->type != IMFS_MEMORY_FILE &&
    610        the_jnode->type != IMFS_LINEAR_FILE )
    611     rtems_set_errno_and_return_minus_one( EIO );
    612 
    613   /*
    614    *  Error checks on arguments
    615    */
    616 
    617   if ( !dest )
    618     rtems_set_errno_and_return_minus_one( EINVAL );
    619 
    620   /*
    621    *  If there is nothing to read, then quick exit.
    622    */
    623 
    624   my_length = length;
    625   if ( !my_length )
    626     rtems_set_errno_and_return_minus_one( EINVAL );
     551  IMFS_assert( dest );
    627552
    628553  /*
     
    630555   *  than block files).
    631556   */
     557  my_length = length;
     558
    632559  if (the_jnode->type == IMFS_LINEAR_FILE) {
    633560    unsigned char  *file_ptr;
     
    649576   *  in memory file, then shorten the length to read.
    650577   */
    651 
    652578  last_byte = start + length;
    653579  if ( last_byte > the_jnode->info.file.size )
     
    666592   *  Phase 1: possibly the last part of one block
    667593   */
    668 
    669594  start_offset = start % IMFS_MEMFILE_BYTES_PER_BLOCK;
    670595  block = start / IMFS_MEMFILE_BYTES_PER_BLOCK;
     
    686611   *  Phase 2: all of zero of more blocks
    687612   */
    688 
    689613  to_copy = IMFS_MEMFILE_BYTES_PER_BLOCK;
    690614  while ( my_length >= IMFS_MEMFILE_BYTES_PER_BLOCK ) {
     
    702626   *  Phase 3: possibly the first part of one block
    703627   */
    704 
    705   #if defined(RTEMS_DEBUG)
    706     assert( my_length < IMFS_MEMFILE_BYTES_PER_BLOCK );
    707   #endif
     628  IMFS_assert( my_length < IMFS_MEMFILE_BYTES_PER_BLOCK );
    708629
    709630  if ( my_length ) {
     
    726647 *  file pointed to by the_jnode.  The file is extended as needed.
    727648 */
    728 
    729649MEMFILE_STATIC ssize_t IMFS_memfile_write(
    730650   IMFS_jnode_t          *the_jnode,
     
    749669   *  Perform internal consistency checks
    750670   */
    751 
    752   #if defined(RTEMS_DEBUG)
    753     assert( source );
    754     assert( the_jnode );
    755     assert( the_jnode->type == IMFS_MEMORY_FILE );
    756   #endif
    757   if ( !the_jnode )
    758     rtems_set_errno_and_return_minus_one( EIO );
    759 
    760   if ( the_jnode->type != IMFS_MEMORY_FILE )
    761     rtems_set_errno_and_return_minus_one( EIO );
    762 
    763   /*
    764    *  Error check arguments
    765    */
    766 
    767   if ( !source )
    768     rtems_set_errno_and_return_minus_one( EINVAL );
    769 
    770 
    771   /*
    772    *  If there is nothing to write, then quick exit.
    773    */
     671  IMFS_assert( source );
     672  IMFS_assert( the_jnode );
     673  IMFS_assert( the_jnode->type == IMFS_MEMORY_FILE );
    774674
    775675  my_length = length;
    776   if ( !my_length )
    777     rtems_set_errno_and_return_minus_one( EINVAL );
    778 
    779676  /*
    780677   *  If the last byte we are supposed to write is past the end of this
     
    782679   */
    783680
    784   last_byte = start + length;
     681  last_byte = start + my_length;
    785682  if ( last_byte > the_jnode->info.file.size ) {
    786683    status = IMFS_memfile_extend( the_jnode, last_byte );
     
    801698   *  Phase 1: possibly the last part of one block
    802699   */
    803 
    804700  start_offset = start % IMFS_MEMFILE_BYTES_PER_BLOCK;
    805701  block = start / IMFS_MEMFILE_BYTES_PER_BLOCK;
     
    851747   *  Phase 3: possibly the first part of one block
    852748   */
    853 
    854   #if defined(RTEMS_DEBUG)
    855     assert( my_length < IMFS_MEMFILE_BYTES_PER_BLOCK );
    856   #endif
     749  IMFS_assert( my_length < IMFS_MEMFILE_BYTES_PER_BLOCK );
    857750
    858751  to_copy = my_length;
     
    881774 *  TRUE, then the block is allocated.  Otherwise, it is an error.
    882775 */
    883 
    884776#if 0
    885777block_p *IMFS_memfile_get_block_pointer_DEBUG(
     
    923815   *  Perform internal consistency checks
    924816   */
    925 
    926   #if defined(RTEMS_DEBUG)
    927     assert( the_jnode );
    928     assert( the_jnode->type == IMFS_MEMORY_FILE );
    929   #endif
    930   if ( !the_jnode )
    931     return NULL;
    932 
    933   if ( the_jnode->type != IMFS_MEMORY_FILE )
    934     return NULL;
     817  IMFS_assert( the_jnode );
     818  IMFS_assert( the_jnode->type == IMFS_MEMORY_FILE );
    935819
    936820  info = &the_jnode->info.file;
    937 
    938821  my_block = block;
    939822
     
    941824   *  Is the block number in the simple indirect portion?
    942825   */
    943 
    944826  if ( my_block <= LAST_INDIRECT ) {
    945827    p = info->indirect;
     
    967849
    968850  if ( my_block <= LAST_DOUBLY_INDIRECT ) {
    969 #if 0
    970 fprintf(stdout, "(d %d) ", block );
    971 fflush(stdout);
    972 #endif
    973 
    974851    my_block -= FIRST_DOUBLY_INDIRECT;
    975852
     
    1005882      return 0;
    1006883
    1007 #if 0
    1008 fprintf(stdout, "(d %d %d %d %d %p %p) ", block, my_block, doubly,
    1009                                        singly, p, &p[singly] );
    1010 fflush(stdout);
    1011 #endif
    1012884    return (block_p *)&p[ singly ];
    1013885  }
    1014886
    1015 #if 0
    1016 fprintf(stdout, "(t %d) ", block );
    1017 fflush(stdout);
    1018 #endif
    1019887  /*
    1020888   *  Is the block number in the triply indirect portion?
    1021889   */
    1022 
    1023890  if ( my_block <= LAST_TRIPLY_INDIRECT ) {
    1024891    my_block -= FIRST_TRIPLY_INDIRECT;
     
    1060927      return 0;
    1061928
    1062 #if 0
    1063 fprintf(stdout, "(t %d %d %d %d %d) ", block, my_block, triply, doubly, singly );
    1064 fflush(stdout);
    1065 #endif
    1066929    p1 = (block_p *) p[ triply ];
    1067930    if ( !p1 )
     
    1078941   *  This means the requested block number is out of range.
    1079942   */
    1080 
    1081943  return 0;
    1082944}
     
    1087949 *  Allocate a block for an in-memory file.
    1088950 */
    1089 
    1090951int memfile_blocks_allocated = 0;
    1091952
     
    1106967 *  Free a block from an in-memory file.
    1107968 */
    1108 
    1109969void memfile_free_block(
    1110970  void *memory
    1111971)
    1112972{
    1113 #if 0
    1114 fprintf(stdout, "(d %p) ", memory );
    1115 fflush(stdout);
    1116 #endif
    1117973  free(memory);
    1118974  memfile_blocks_allocated--;
Note: See TracChangeset for help on using the changeset viewer.