Changeset 0aea082 in rtems
- Timestamp:
- Jul 30, 2010, 10:36:32 PM (11 years ago)
- Branches:
- 4.11, 5, master
- Children:
- cc43b364
- Parents:
- 3bae3f2
- Location:
- cpukit
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
cpukit/ChangeLog
r3bae3f2 r0aea082 1 2010-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 1 9 2010-07-30 Gedare Bloom <giddyup44@yahoo.com> 2 10 -
cpukit/libcsupport/src/fstat.c
r3bae3f2 r0aea082 33 33 * Check to see if we were passed a valid pointer. 34 34 */ 35 36 35 if ( !sbuf ) 37 36 rtems_set_errno_and_return_minus_one( EFAULT ); … … 40 39 * Now process the stat() request. 41 40 */ 42 43 41 iop = rtems_libio_iop( fd ); 44 42 rtems_libio_check_fd( fd ); -
cpukit/libcsupport/src/rmdir.c
r3bae3f2 r0aea082 75 75 * Verify you can remove this node as a directory. 76 76 */ 77 if ( (*loc.ops->node_type_h)( &loc ) != RTEMS_FILESYSTEM_DIRECTORY ){77 if ( (*loc.ops->node_type_h)( &loc ) != RTEMS_FILESYSTEM_DIRECTORY ) { 78 78 rtems_filesystem_freenode( &loc ); 79 79 if ( free_parentloc ) -
cpukit/libfs/src/imfs/imfs.h
r3bae3f2 r0aea082 561 561 ); 562 562 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 563 574 #ifdef __cplusplus 564 575 } -
cpukit/libfs/src/imfs/imfs_creat.c
r3bae3f2 r0aea082 18 18 #endif 19 19 20 #if defined(RTEMS_DEBUG)21 #include <assert.h>22 #endif23 20 #include <stdlib.h> 24 21 #include <string.h> … … 102 99 103 100 default: 104 #if defined(RTEMS_DEBUG) 105 assert(0); 106 #endif 101 IMFS_assert(0); 107 102 break; 108 103 } … … 111 106 * This node MUST have a parent, so put it in that directory list. 112 107 */ 113 114 108 node->Parent = parent; 115 109 node->st_ino = ++fs_info->ino_count; -
cpukit/libfs/src/imfs/imfs_debug.c
r3bae3f2 r0aea082 16 16 #endif 17 17 18 #if defined(RTEMS_DEBUG)19 #include <assert.h>20 #endif21 18 #include <string.h> 22 19 #include <fcntl.h> … … 37 34 * This routine prints the contents of the specified jnode. 38 35 */ 39 40 36 void IMFS_print_jnode( 41 37 IMFS_jnode_t *the_jnode 42 38 ) 43 39 { 44 #if defined(RTEMS_DEBUG) 45 assert( the_jnode ); 46 #endif 40 IMFS_assert( the_jnode ); 47 41 48 42 fprintf(stdout, "%s", the_jnode->name ); … … 105 99 * the subdirectory. 106 100 */ 107 108 101 void IMFS_dump_directory( 109 102 IMFS_jnode_t *the_directory, … … 116 109 int i; 117 110 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 ); 123 114 124 115 the_chain = &the_directory->info.directory.Entries; … … 153 144 fprintf(stdout, "/\n" ); 154 145 IMFS_dump_directory( rtems_filesystem_root.node_access, 0 ); 155 fprintf(stdout, "*************** End of Dump***************\n" );146 fprintf(stdout, "*************** End of Dump ***************\n" ); 156 147 } 157 148 … … 163 154 * 164 155 */ 165 166 156 int IMFS_memfile_maximum_size( void ) 167 157 { -
cpukit/libfs/src/imfs/imfs_getchild.c
r3bae3f2 r0aea082 18 18 #endif 19 19 20 #if defined(RTEMS_DEBUG)21 #include <assert.h>22 #endif23 20 #include <errno.h> 24 21 #include <string.h> … … 41 38 * the IMFS code. 42 39 */ 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 ); 53 42 54 43 /* -
cpukit/libfs/src/imfs/memfile.c
r3bae3f2 r0aea082 32 32 #include <rtems/seterr.h> 33 33 34 #if defined(RTEMS_DEBUG)35 #include <assert.h>36 #endif37 38 34 #define MEMFILE_STATIC 39 35 … … 41 37 * Prototypes of private routines 42 38 */ 43 44 39 MEMFILE_STATIC int IMFS_memfile_extend( 45 40 IMFS_jnode_t *the_jnode, … … 89 84 * nothing special to be done at open() time. 90 85 */ 91 92 86 int memfile_open( 93 87 rtems_libio_t *iop, … … 131 125 * nothing to flush or memory to free at this point. 132 126 */ 133 134 127 int memfile_close( 135 128 rtems_libio_t *iop … … 153 146 * This routine processes the read() system call. 154 147 */ 155 156 148 ssize_t memfile_read( 157 149 rtems_libio_t *iop, … … 172 164 * This routine processes the write() system call. 173 165 */ 174 175 166 ssize_t memfile_write( 176 167 rtems_libio_t *iop, … … 197 188 * NOTE: No ioctl()'s are supported for in-memory files. 198 189 */ 199 200 190 int memfile_ioctl( 201 191 rtems_libio_t *iop, … … 216 206 * This routine processes the lseek() system call. 217 207 */ 218 219 208 rtems_off64_t memfile_lseek( 220 209 rtems_libio_t *iop, … … 251 240 * This routine processes the ftruncate() system call. 252 241 */ 253 254 242 int memfile_ftruncate( 255 243 rtems_libio_t *iop, … … 275 263 * future use and just set the length. 276 264 */ 277 278 265 the_jnode->info.file.size = length; 279 266 iop->size = the_jnode->info.file.size; … … 291 278 * extend the file. 292 279 */ 293 294 280 MEMFILE_STATIC int IMFS_memfile_extend( 295 281 IMFS_jnode_t *the_jnode, … … 304 290 * Perform internal consistency checks 305 291 */ 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 */ 317 298 if ( new_length >= IMFS_MEMFILE_MAXIMUM_SIZE ) 318 299 rtems_set_errno_and_return_minus_one( EINVAL ); 319 300 301 /* 302 * Verify new file size is actually larger than current size 303 */ 320 304 if ( new_length <= the_jnode->info.file.size ) 321 305 return 0; … … 324 308 * Calculate the number of range of blocks to allocate 325 309 */ 326 327 310 new_blocks = new_length / IMFS_MEMFILE_BYTES_PER_BLOCK; 328 311 old_blocks = the_jnode->info.file.size / IMFS_MEMFILE_BYTES_PER_BLOCK; … … 331 314 * Now allocate each of those blocks. 332 315 */ 333 334 316 for ( block=old_blocks ; block<=new_blocks ; block++ ) { 335 317 if ( IMFS_memfile_addblock( the_jnode, block ) ) { 336 318 for ( ; block>=old_blocks ; block-- ) { 337 319 IMFS_memfile_remove_block( the_jnode, block ); 338 320 } 339 321 rtems_set_errno_and_return_minus_one( ENOSPC ); … … 344 326 * Set the new length of the file. 345 327 */ 346 347 328 the_jnode->info.file.size = new_length; 348 329 return 0; … … 354 335 * This routine adds a single block to the specified in-memory file. 355 336 */ 356 357 337 MEMFILE_STATIC int IMFS_memfile_addblock( 358 338 IMFS_jnode_t *the_jnode, … … 363 343 block_p *block_entry_ptr; 364 344 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 */ 375 351 block_entry_ptr = IMFS_memfile_get_block_pointer( the_jnode, block, 1 ); 376 352 if ( *block_entry_ptr ) 377 353 return 0; 378 354 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 */ 384 358 memory = memfile_alloc_block(); 385 359 if ( !memory ) 386 360 return 1; 361 387 362 *block_entry_ptr = memory; 388 389 363 return 0; 390 364 } … … 400 374 * dangerous and the results unpredictable. 401 375 */ 402 403 376 MEMFILE_STATIC int IMFS_memfile_remove_block( 404 377 IMFS_jnode_t *the_jnode, … … 410 383 411 384 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 ); 420 390 421 391 return 1; … … 428 398 * blocks in one of the indirection tables. 429 399 */ 430 431 400 void memfile_free_blocks_in_table( 432 401 block_p **block_table, … … 440 409 * Perform internal consistency checks 441 410 */ 442 443 #if defined(RTEMS_DEBUG) 444 assert( block_table ); 445 #endif 446 if ( !block_table ) 447 return; 411 IMFS_assert( block_table ); 448 412 449 413 /* 450 414 * Now go through all the slots in the table and free the memory. 451 415 */ 452 453 416 b = *block_table; 454 417 … … 464 427 * free the block table itself. 465 428 */ 466 467 429 memfile_free_block( *block_table ); 468 430 *block_table = 0; … … 487 449 * is better to stick to simple, easy to understand algorithms. 488 450 */ 489 490 451 int IMFS_memfile_remove( 491 452 IMFS_jnode_t *the_jnode … … 501 462 * Perform internal consistency checks 502 463 */ 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 ); 513 466 514 467 /* … … 516 469 * memfile_free_blocks_in_table to greatly speed this up. 517 470 */ 518 519 471 to_free = IMFS_MEMFILE_BLOCK_SLOTS; 520 472 … … 525 477 * + triply indirect 526 478 */ 527 528 479 info = &the_jnode->info.file; 529 480 … … 533 484 534 485 if ( info->doubly_indirect ) { 535 536 486 for ( i=0 ; i<IMFS_MEMFILE_BLOCK_SLOTS ; i++ ) { 537 487 if ( info->doubly_indirect[i] ) { … … 575 525 * read). 576 526 */ 577 578 527 MEMFILE_STATIC ssize_t IMFS_memfile_read( 579 528 IMFS_jnode_t *the_jnode, … … 597 546 * Perform internal consistency checks 598 547 */ 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 || 603 550 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 ); 627 552 628 553 /* … … 630 555 * than block files). 631 556 */ 557 my_length = length; 558 632 559 if (the_jnode->type == IMFS_LINEAR_FILE) { 633 560 unsigned char *file_ptr; … … 649 576 * in memory file, then shorten the length to read. 650 577 */ 651 652 578 last_byte = start + length; 653 579 if ( last_byte > the_jnode->info.file.size ) … … 666 592 * Phase 1: possibly the last part of one block 667 593 */ 668 669 594 start_offset = start % IMFS_MEMFILE_BYTES_PER_BLOCK; 670 595 block = start / IMFS_MEMFILE_BYTES_PER_BLOCK; … … 686 611 * Phase 2: all of zero of more blocks 687 612 */ 688 689 613 to_copy = IMFS_MEMFILE_BYTES_PER_BLOCK; 690 614 while ( my_length >= IMFS_MEMFILE_BYTES_PER_BLOCK ) { … … 702 626 * Phase 3: possibly the first part of one block 703 627 */ 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 ); 708 629 709 630 if ( my_length ) { … … 726 647 * file pointed to by the_jnode. The file is extended as needed. 727 648 */ 728 729 649 MEMFILE_STATIC ssize_t IMFS_memfile_write( 730 650 IMFS_jnode_t *the_jnode, … … 749 669 * Perform internal consistency checks 750 670 */ 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 ); 774 674 775 675 my_length = length; 776 if ( !my_length )777 rtems_set_errno_and_return_minus_one( EINVAL );778 779 676 /* 780 677 * If the last byte we are supposed to write is past the end of this … … 782 679 */ 783 680 784 last_byte = start + length;681 last_byte = start + my_length; 785 682 if ( last_byte > the_jnode->info.file.size ) { 786 683 status = IMFS_memfile_extend( the_jnode, last_byte ); … … 801 698 * Phase 1: possibly the last part of one block 802 699 */ 803 804 700 start_offset = start % IMFS_MEMFILE_BYTES_PER_BLOCK; 805 701 block = start / IMFS_MEMFILE_BYTES_PER_BLOCK; … … 851 747 * Phase 3: possibly the first part of one block 852 748 */ 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 ); 857 750 858 751 to_copy = my_length; … … 881 774 * TRUE, then the block is allocated. Otherwise, it is an error. 882 775 */ 883 884 776 #if 0 885 777 block_p *IMFS_memfile_get_block_pointer_DEBUG( … … 923 815 * Perform internal consistency checks 924 816 */ 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 ); 935 819 936 820 info = &the_jnode->info.file; 937 938 821 my_block = block; 939 822 … … 941 824 * Is the block number in the simple indirect portion? 942 825 */ 943 944 826 if ( my_block <= LAST_INDIRECT ) { 945 827 p = info->indirect; … … 967 849 968 850 if ( my_block <= LAST_DOUBLY_INDIRECT ) { 969 #if 0970 fprintf(stdout, "(d %d) ", block );971 fflush(stdout);972 #endif973 974 851 my_block -= FIRST_DOUBLY_INDIRECT; 975 852 … … 1005 882 return 0; 1006 883 1007 #if 01008 fprintf(stdout, "(d %d %d %d %d %p %p) ", block, my_block, doubly,1009 singly, p, &p[singly] );1010 fflush(stdout);1011 #endif1012 884 return (block_p *)&p[ singly ]; 1013 885 } 1014 886 1015 #if 01016 fprintf(stdout, "(t %d) ", block );1017 fflush(stdout);1018 #endif1019 887 /* 1020 888 * Is the block number in the triply indirect portion? 1021 889 */ 1022 1023 890 if ( my_block <= LAST_TRIPLY_INDIRECT ) { 1024 891 my_block -= FIRST_TRIPLY_INDIRECT; … … 1060 927 return 0; 1061 928 1062 #if 01063 fprintf(stdout, "(t %d %d %d %d %d) ", block, my_block, triply, doubly, singly );1064 fflush(stdout);1065 #endif1066 929 p1 = (block_p *) p[ triply ]; 1067 930 if ( !p1 ) … … 1078 941 * This means the requested block number is out of range. 1079 942 */ 1080 1081 943 return 0; 1082 944 } … … 1087 949 * Allocate a block for an in-memory file. 1088 950 */ 1089 1090 951 int memfile_blocks_allocated = 0; 1091 952 … … 1106 967 * Free a block from an in-memory file. 1107 968 */ 1108 1109 969 void memfile_free_block( 1110 970 void *memory 1111 971 ) 1112 972 { 1113 #if 01114 fprintf(stdout, "(d %p) ", memory );1115 fflush(stdout);1116 #endif1117 973 free(memory); 1118 974 memfile_blocks_allocated--;
Note: See TracChangeset
for help on using the changeset viewer.