Changeset 656 for trunk/kernel/fs/vfs.c
- Timestamp:
- Dec 6, 2019, 12:07:51 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/fs/vfs.c
r651 r656 235 235 236 236 #if DEBUG_VFS_INODE_CREATE 237 char name[CONFIG_VFS_MAX_NAME_LENGTH];238 237 uint32_t cycle = (uint32_t)hal_get_cycles(); 239 238 thread_t * this = CURRENT_THREAD; 240 vfs_inode_get_name( *inode_xp , name );241 239 if( DEBUG_VFS_INODE_CREATE < cycle ) 242 printk("\n[%s] thread[%x,%x] created <%s> / inode [%x,%x]/ cycle %d\n",243 __FUNCTION__, this->process->pid, this->trdid, name,local_cxy, inode, cycle );240 printk("\n[%s] thread[%x,%x] created inode (%x,%x) / cycle %d\n", 241 __FUNCTION__, this->process->pid, this->trdid, local_cxy, inode, cycle ); 244 242 #endif 245 243 … … 513 511 uint32_t cycle = (uint32_t)hal_get_cycles(); 514 512 if( DEBUG_VFS_DENTRY_CREATE < cycle ) 515 printk("\n[%s] thread[%x,%x] created <%s> / dentry [%x,%x]/ cycle %d\n",513 printk("\n[%s] thread[%x,%x] created dentry <%s> : (%x,%x) / cycle %d\n", 516 514 __FUNCTION__, this->process->pid, this->trdid, name, local_cxy, dentry, cycle ); 517 515 #endif … … 777 775 } // end vfs_open() 778 776 779 ////////////////////////////////////// 780 int vfs_user_move( bool_t to_buffer, 781 xptr_t file_xp, 782 void * buffer, 783 uint32_t size ) 784 { 785 cxy_t file_cxy; // remote file descriptor cluster 786 vfs_file_t * file_ptr; // remote file descriptor local pointer 787 vfs_inode_type_t inode_type; 788 uint32_t file_offset; // current offset in file 789 mapper_t * mapper; 777 /////////////////////////////////////////// 778 uint32_t vfs_user_move( bool_t to_buffer, 779 xptr_t file_xp, 780 void * buffer, 781 uint32_t count ) 782 { 783 cxy_t file_cxy; // remote file descriptor cluster 784 vfs_file_t * file_ptr; // remote file descriptor local pointer 785 mapper_t * mapper; // local pointer on file mapper 786 vfs_inode_t * inode; // local pointer on file inode 787 vfs_inode_type_t type; // inode type 788 uint32_t offset; // current offset in file 789 uint32_t size; // current file size 790 uint32_t nbytes; // number of bytes actually transfered 790 791 error_t error; 791 792 … … 797 798 file_ptr = GET_PTR( file_xp ); 798 799 799 // get inode type from remote file descriptor 800 inode_type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) ); 800 // get various infos from remote file descriptor 801 type = hal_remote_l32( XPTR( file_cxy , &file_ptr->type ) ); 802 offset = hal_remote_l32( XPTR( file_cxy , &file_ptr->offset ) ); 803 mapper = hal_remote_lpt( XPTR( file_cxy , &file_ptr->mapper ) ); 804 inode = hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) ); 805 size = hal_remote_l32( XPTR( file_cxy , &inode->size ) ); 801 806 802 807 // check inode type 803 assert( (inode_type == INODE_TYPE_FILE), "bad inode type" ); 804 805 // get mapper pointer and file offset from file descriptor 806 file_offset = hal_remote_l32( XPTR( file_cxy , &file_ptr->offset ) ); 807 mapper = hal_remote_lpt( XPTR( file_cxy , &file_ptr->mapper ) ); 808 assert( (type == INODE_TYPE_FILE), "bad inode type" ); 808 809 809 810 #if DEBUG_VFS_USER_MOVE … … 811 812 uint32_t cycle = (uint32_t)hal_get_cycles(); 812 813 thread_t * this = CURRENT_THREAD; 813 vfs_inode_t * inode = hal_remote_lpt( XPTR( file_cxy , &file_ptr->inode ) );814 814 vfs_inode_get_name( XPTR( file_cxy , inode ) , name ); 815 815 if( cycle > DEBUG_VFS_USER_MOVE ) … … 817 817 if( to_buffer ) 818 818 printk("\n[%s] thread[%x,%x] enter / %d bytes / map(%s) -> buf(%x) / offset %d / cycle %d\n", 819 __FUNCTION__ , this->process->pid, this->trdid, size, name, buffer, file_offset, cycle );819 __FUNCTION__ , this->process->pid, this->trdid, count, name, buffer, offset, cycle ); 820 820 else 821 821 printk("\n[%s] thread[%x,%x] enter / %d bytes / buf(%x) -> map(%s) / offset %d / cycle %d\n", 822 __FUNCTION__ , this->process->pid, this->trdid, size, buffer, name, file_offset, cycle );822 __FUNCTION__ , this->process->pid, this->trdid, count, buffer, name, offset, cycle ); 823 823 } 824 824 #endif 825 825 826 // move data between mapper and buffer 827 error = mapper_move_user( XPTR( file_cxy , mapper ), 828 to_buffer, 829 file_offset, 830 buffer, 831 size ); 826 if( to_buffer ) // => compute the number of bytes to move and make the move 827 { 828 // compute number of bytes to move 829 if ( size <= offset ) nbytes = 0; 830 else if( size < offset + count ) nbytes = size - offset; 831 else nbytes = count; 832 833 // move data from mapper to buffer when required 834 if( nbytes > 0 ) 835 { 836 error = mapper_move_user( XPTR( file_cxy , mapper ), 837 to_buffer, 838 offset, 839 buffer, 840 nbytes ); 841 } 842 else 843 { 844 error = 0; 845 } 846 } 847 else // to mapper => make the move and update the file size if required 848 { 849 nbytes = count; 850 851 // move data from buffer to mapper 852 error = mapper_move_user( XPTR( file_cxy , mapper ), 853 to_buffer, 854 offset, 855 buffer, 856 count ); 857 858 // update file size in inode if required 859 if( offset + count > size ) 860 { 861 vfs_inode_update_size( XPTR( file_cxy , inode ) , offset + count ); 862 } 863 } 864 832 865 if( error ) 833 866 { … … 837 870 838 871 // update file offset in file descriptor 839 hal_remote_atomic_add( XPTR( file_cxy , &file_ptr->offset ) , size);872 hal_remote_atomic_add( XPTR( file_cxy , &file_ptr->offset ) , nbytes ); 840 873 841 874 #if DEBUG_VFS_USER_MOVE … … 844 877 { 845 878 if( to_buffer ) 846 printk("\n[%s] thread[%x,%x] exit / cycle %d\n",847 __FUNCTION__ , this->process->pid, cycle);879 printk("\n[%s] thread[%x,%x] exit / %d bytes moved from mapper to buffer\n", 880 __FUNCTION__ , this->process->pid, nbytes ); 848 881 else 849 printk("\n[%s] thread[%x,%x] exit / cycle %d\n",850 __FUNCTION__ , this->process->pid, cycle);882 printk("\n[%s] thread[%x,%x] exit / %d bytes moved from buffer to mapper / size %d\n", 883 __FUNCTION__ , this->process->pid, nbytes, hal_remote_l32(XPTR(file_cxy,&inode->size)) ); 851 884 } 852 885 #endif 853 886 854 return size;887 return nbytes; 855 888 856 889 } // end vfs_user_move() … … 2483 2516 #endif 2484 2517 2518 #if ( DEBUG_VFS_LOOKUP & 1 ) 2519 if( DEBUG_VFS_LOOKUP < cycle ) 2520 vfs_display( root_xp ); 2521 #endif 2522 2485 2523 // compute lookup flags 2486 2524 create = (lookup_mode & VFS_LOOKUP_CREATE) == VFS_LOOKUP_CREATE; … … 2527 2565 #endif 2528 2566 2529 // search the child dentry matching name in parent inode 2567 // search the child dentry matching name in parent inode XHTAB 2530 2568 found = vfs_get_child( parent_xp, 2531 2569 name, … … 2593 2631 #if (DEBUG_VFS_LOOKUP & 1) 2594 2632 if( DEBUG_VFS_LOOKUP < cycle ) 2595 printk("\n[%s] thread[%x,%x] created missing inode for<%s> in cluster %x\n",2633 printk("\n[%s] thread[%x,%x] created missing inode <%s> in cluster %x\n", 2596 2634 __FUNCTION__, process->pid, this->trdid, name, child_cxy ); 2597 2635 #endif … … 2771 2809 { 2772 2810 error_t error; 2773 uint32_t cluster ;2811 uint32_t cluster_id; 2774 2812 uint32_t child_type; 2775 2813 uint32_t child_size; … … 2798 2836 vfs_inode_t * child_ptr = GET_PTR( child_xp ); 2799 2837 2800 // 1. allocate one free cluster in file system to child inode,2838 // 1. allocate one free cluster_id in file system to child inode, 2801 2839 // and update the File Allocation Table in both the FAT mapper and IOC device. 2802 2840 // It depends on the child inode FS type. … … 2804 2842 2805 2843 error = vfs_fs_cluster_alloc( ctx->type, 2806 &cluster );2844 &cluster_id ); 2807 2845 if ( error ) 2808 2846 { 2809 printk("\n[ERROR] in %s : cannot find a free VFS cluster \n",2847 printk("\n[ERROR] in %s : cannot find a free VFS cluster_id\n", 2810 2848 __FUNCTION__ ); 2811 2849 return -1; … … 2814 2852 #if( DEBUG_VFS_NEW_DENTRY_INIT & 1) 2815 2853 if( DEBUG_VFS_NEW_DENTRY_INIT < cycle ) 2816 printk("\n[%s] thread[%x,%x] allocated FS cluster %x to <%s>\n",2817 __FUNCTION__ , this->process->pid, this->trdid, cluster , child_name );2854 printk("\n[%s] thread[%x,%x] allocated FS cluster_id %x to <%s>\n", 2855 __FUNCTION__ , this->process->pid, this->trdid, cluster_id, child_name ); 2818 2856 #endif 2819 2857 2820 2858 // 2. update the child inode descriptor size and extend 2821 2859 child_type = hal_remote_l32( XPTR( child_cxy , &child_ptr->type ) ); 2822 child_size = (child_type == INODE_TYPE_DIR) ? 4096 :0;2860 child_size = 0; 2823 2861 2824 2862 hal_remote_s32( XPTR( child_cxy , &child_ptr->size ) , child_size ); 2825 hal_remote_spt( XPTR( child_cxy , &child_ptr->extend ) , (void*)(intptr_t)cluster );2863 hal_remote_spt( XPTR( child_cxy , &child_ptr->extend ) , (void*)(intptr_t)cluster_id ); 2826 2864 2827 2865 // 3. update the parent inode mapper, and … … 3285 3323 #if(DEBUG_VFS_ADD_CHILD & 1) 3286 3324 if( DEBUG_VFS_ADD_CHILD < cycle ) 3287 printk("\n[%s] thread[%x,%x] / dentry <%s> created(%x,%x)\n",3325 printk("\n[%s] thread[%x,%x] created dentry <%s> : (%x,%x)\n", 3288 3326 __FUNCTION__, this->process->pid, this->trdid, name, parent_cxy, new_dentry_ptr ); 3289 3327 #endif … … 3332 3370 #if(DEBUG_VFS_ADD_CHILD & 1) 3333 3371 if( DEBUG_VFS_ADD_CHILD < cycle ) 3334 printk("\n[%s] thread[%x,%x] / inode <%s> created(%x,%x)\n",3372 printk("\n[%s] thread[%x,%x] created inode <%s> : (%x,%x)\n", 3335 3373 __FUNCTION__ , this->process->pid, this->trdid, name , child_cxy, new_inode_ptr ); 3336 3374 #endif … … 3345 3383 #if(DEBUG_VFS_ADD_CHILD & 1) 3346 3384 if( DEBUG_VFS_ADD_CHILD < cycle ) 3347 printk("\n[%s] thread[%x,%x] link dentry(%x,%x) to child inode(%x,%x)\n",3385 printk("\n[%s] thread[%x,%x] linked dentry(%x,%x) to child inode(%x,%x)\n", 3348 3386 __FUNCTION__, this->process->pid, this->trdid, 3349 3387 parent_cxy, new_dentry_ptr, child_cxy, new_inode_ptr ); … … 3357 3395 #if(DEBUG_VFS_ADD_CHILD & 1) 3358 3396 if( DEBUG_VFS_ADD_CHILD < cycle ) 3359 printk("\n[%s] thread[%x,%x] link dentry(%x,%x) to parent inode(%x,%x)\n",3397 printk("\n[%s] thread[%x,%x] linked dentry(%x,%x) to parent inode(%x,%x)\n", 3360 3398 __FUNCTION__, this->process->pid, this->trdid, 3361 3399 parent_cxy, new_dentry_ptr, parent_cxy, parent_inode_ptr ); … … 3814 3852 return error; 3815 3853 3816 } // end vfs_fs_ alloc_cluster()3854 } // end vfs_fs_cluster_alloc() 3817 3855 3818 3856 ////////////////////////////////////////////////
Note: See TracChangeset
for help on using the changeset viewer.