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

NTSTATUS NTAPI Ext2Format ( IN PUNICODE_STRING  DriveRoot,
IN FMIFS_MEDIA_FLAG  MediaFlag,
IN PUNICODE_STRING  Label,
IN BOOLEAN  QuickFormat,
IN ULONG  ClusterSize,
IN PFMIFSCALLBACK  Callback 
)

Definition at line 806 of file Mke2fs.c.

Referenced by NATIVE_CreateFileSystemList().

{
    BOOLEAN    bRet = FALSE;
    NTSTATUS   Status = STATUS_UNSUCCESSFUL;
    /* Super Block: 1024 bytes long */
    EXT2_SUPER_BLOCK Ext2Sb;
    /* File Sys Structure */
    EXT2_FILESYS     FileSys;
    ULONG Percent;
    ULONG rsv;
    ULONG blocks;
    ULONG start;
    ULONG ret_blk;


    if (Callback != NULL)
    {
        Callback(PROGRESS, 0, (PVOID)&Percent);
    }


    RtlZeroMemory(&Ext2Sb, sizeof(EXT2_SUPER_BLOCK));
    RtlZeroMemory(&FileSys, sizeof(EXT2_FILESYS));
    FileSys.ext2_sb = &Ext2Sb;


    if (!NT_SUCCESS(Ext2OpenDevice(&FileSys, DriveRoot)))
    {
        DPRINT1("Mke2fs: Volume %wZ does not exist, ...\n", DriveRoot);
        goto clean_up;
    }


    if (!NT_SUCCESS(Ext2GetMediaInfo(&FileSys)))
    {
        DPRINT1("Mke2fs: Can't get media information\n");
        goto clean_up;
    }

    set_fs_defaults(NULL, &Ext2Sb, ClusterSize, &inode_ratio);

    Ext2Sb.s_blocks_count = FileSys.PartInfo.PartitionLength.QuadPart /
                            EXT2_BLOCK_SIZE(&Ext2Sb);


    /*
     * Calculate number of inodes based on the inode ratio
     */
    Ext2Sb.s_inodes_count =
        (ULONG)(((LONGLONG) Ext2Sb.s_blocks_count * EXT2_BLOCK_SIZE(&Ext2Sb)) / inode_ratio);

    /*
     * Calculate number of blocks to reserve
     */
    Ext2Sb.s_r_blocks_count = (Ext2Sb.s_blocks_count * 5) / 100;


    Status = Ext2LockVolume(&FileSys);
    if (NT_SUCCESS(Status))
    {
        bLocked = TRUE;
    }


    // Initialize 
    if (!ext2_initialize_sb(&FileSys))
    {
        DPRINT1("Mke2fs: error...\n");
        goto clean_up;
    }


    zap_sector(&FileSys, 2, 6);

    /*
     * Generate a UUID for it...
     */
    {
        __u8  uuid[16];
        uuid_generate(&uuid[0]);
        memcpy(&Ext2Sb.s_uuid[0], &uuid[0], 16);
    }

    /*
     * Add "jitter" to the superblock's check interval so that we
     * don't check all the filesystems at the same time.  We use a
     * kludgy hack of using the UUID to derive a random jitter value.
     */
    {
        ULONG i, val;

        for (i = 0, val = 0 ; i < sizeof(Ext2Sb.s_uuid); i++)
            val += Ext2Sb.s_uuid[i];

        Ext2Sb.s_max_mnt_count += val % EXT2_DFL_MAX_MNT_COUNT;
    }

    /*
     * Set the volume label...
     */
    if (Label)
    {
        ANSI_STRING ansi_label;
        ansi_label.MaximumLength = sizeof(Ext2Sb.s_volume_name);
        ansi_label.Length = 0;
        ansi_label.Buffer = Ext2Sb.s_volume_name;
        RtlUnicodeStringToAnsiString(&ansi_label, Label, FALSE);
    }

    ext2_print_super(&Ext2Sb);

    bRet = ext2_allocate_tables(&FileSys);

    if (!bRet)
    {
        goto clean_up;
    }

    /* rsv must be a power of two (64kB is MD RAID sb alignment) */
    rsv = 65536 / FileSys.blocksize;
    blocks = Ext2Sb.s_blocks_count;

#ifdef ZAP_BOOTBLOCK
    DPRINT1("Mke2fs: zeroing volume boot record\n");
    zap_sector(&FileSys, 0, 2);
#endif

    /*
     * Wipe out any old MD RAID (or other) metadata at the end
     * of the device.  This will also verify that the device is
     * as large as we think.  Be careful with very small devices.
     */

    start = (blocks & ~(rsv - 1));
    if (start > rsv)
        start -= rsv;

    if (start > 0)
        bRet = zero_blocks(&FileSys, start, blocks - start, &ret_blk, NULL);

    if (!bRet)
    {
        DPRINT1("Mke2fs: zeroing block %lu at end of filesystem", ret_blk);
        goto clean_up;
    }

    write_inode_tables(&FileSys);

    create_root_dir(&FileSys);
    create_lost_and_found(&FileSys);

    ext2_reserve_inodes(&FileSys);

    create_bad_block_inode(&FileSys, NULL);

    DPRINT("Mke2fs: Writing superblocks and filesystem accounting information ... \n");

    if (!QuickFormat)
    {
        DPRINT1("Mke2fs: Slow format not supported yet\n");
    }

    if (!ext2_flush(&FileSys))
    {
        bRet = false;
        DPRINT1("Mke2fs: Warning, had trouble writing out superblocks.\n");
        goto clean_up;
    }

    DPRINT("Mke2fs: Writing superblocks and filesystem accounting information done!\n");

    bRet = true;
    Status = STATUS_SUCCESS;

clean_up:

    // Clean up ...
    ext2_free_group_desc(&FileSys);

    ext2_free_block_bitmap(&FileSys);
    ext2_free_inode_bitmap(&FileSys);

    if (!bRet)
    {
        Ext2DisMountVolume(&FileSys);
    }
    else
    {
        if(bLocked)
        {
            Ext2UnLockVolume(&FileSys);
        }
    }

    Ext2CloseDevice(&FileSys);

    if (Callback != NULL)
    {
        Callback(DONE, 0, (PVOID)&bRet);
    }

    return Status;
}

Generated on Wed May 23 2012 05:54:16 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.