ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

ULONG NTAPI Ext2CreateFile ( PtrExt2IrpContext  PtrIrpContext,
PtrExt2VCB  PtrVCB,
PUNICODE_STRING  PtrName,
PtrExt2FCB  PtrParentFCB,
ULONG  Type 
)

Definition at line 1437 of file create.c.

Referenced by Ext2CommonCreate().

{
    EXT2_INODE  Inode, ParentInode;

    ULONG       NewInodeNo = 0;
    BOOLEAN     FCBAcquired = FALSE;

    ULONG       LogicalBlockSize = 0;

    try
    {
        

        //  0. Verify if the creation is possible,,,
        if( Type != EXT2_FT_DIR && Type != EXT2_FT_REG_FILE )
        {
            //
            //  Can create only a directory or a regular file...
            //
            return 0;
        }
        
        //  1. Allocate an i-node...
        
        NewInodeNo = Ext2AllocInode( PtrIrpContext, PtrVCB, PtrParentFCB->INodeNo );
        
        //  NewInodeNo = 12;

        if( !NewInodeNo )
        {
            return 0;
        }
        
        //  2. Acquire the Parent FCB Exclusively...
        if( !ExAcquireResourceExclusiveLite(&( PtrParentFCB->NTRequiredFCB.MainResource ), TRUE) )
        {
            Ext2DeallocInode( PtrIrpContext, PtrVCB, NewInodeNo );
            try_return( NewInodeNo = 0);
        }
        FCBAcquired = TRUE;

        //  3. Make an entry in the parent Directory...     
        ASSERT( PtrParentFCB->DcbFcb.Dcb.PtrDirFileObject );
        
        Ext2MakeNewDirectoryEntry(
            PtrIrpContext,
            PtrParentFCB, 
            PtrParentFCB->DcbFcb.Dcb.PtrDirFileObject, 
            PtrName, Type, NewInodeNo );
    
        
        //  4. Initialize an inode entry and  write it to disk...
        LogicalBlockSize = EXT2_MIN_BLOCK_SIZE << PtrVCB->LogBlockSize;

        {
            //  To be deleted
            Ext2ReadInode( PtrVCB, NewInodeNo, &Inode );
        }

        RtlZeroMemory( &Inode, sizeof( EXT2_INODE ) );
        if( Type == EXT2_FT_DIR )
        {
            Inode.i_mode = 0x41ff;

            //  In addition to the usual link, 
            //  there will be an additional link in the directory itself - the '.' entry
            Inode.i_links_count = 2;

            //  Incrementing the link count for the parent as well...
            Ext2ReadInode( PtrVCB, PtrParentFCB->INodeNo, &ParentInode );
            ParentInode.i_links_count++;
            Ext2WriteInode( PtrIrpContext, PtrVCB, PtrParentFCB->INodeNo, &ParentInode );

        }
        else
        {
            Inode.i_mode = 0x81ff;
            Inode.i_links_count = 1;
        }


        {
            //
            //  Setting the time fields in the inode...
            //
            ULONG Time;
            Time = Ext2GetCurrentTime();
            Inode.i_ctime = Time;
            Inode.i_atime = Time;
            Inode.i_mtime = Time;
            Inode.i_dtime = 0;          //  Deleted time;
        }

        Ext2WriteInode( PtrIrpContext, PtrVCB, NewInodeNo, &Inode );

        try_exit:   NOTHING;
    }
    finally 
    {
        if( FCBAcquired )
        {
            Ext2ReleaseResource( &(PtrParentFCB->NTRequiredFCB.MainResource) );
        }
    }

    return NewInodeNo ;
}

Generated on Sun May 27 2012 04:41:20 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.