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

ff_format.c
Go to the documentation of this file.
00001 /*****************************************************************************
00002  *  FullFAT - High Performance, Thread-Safe Embedded FAT File-System         *
00003  *  Copyright (C) 2009  James Walmsley (james@worm.me.uk)                    *
00004  *                                                                           *
00005  *  This program is free software: you can redistribute it and/or modify     *
00006  *  it under the terms of the GNU General Public License as published by     *
00007  *  the Free Software Foundation, either version 3 of the License, or        *
00008  *  (at your option) any later version.                                      *
00009  *                                                                           *
00010  *  This program is distributed in the hope that it will be useful,          *
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00013  *  GNU General Public License for more details.                             *
00014  *                                                                           *
00015  *  You should have received a copy of the GNU General Public License        *
00016  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.    *
00017  *                                                                           *
00018  *  IMPORTANT NOTICE:                                                        *
00019  *  =================                                                        *
00020  *  Alternative Licensing is available directly from the Copyright holder,   *
00021  *  (James Walmsley). For more information consult LICENSING.TXT to obtain   *
00022  *  a Commercial license.                                                    *
00023  *                                                                           *
00024  *  See RESTRICTIONS.TXT for extra restrictions on the use of FullFAT.       *
00025  *                                                                           *
00026  *  Removing the above notice is illegal and will invalidate this license.   *
00027  *****************************************************************************
00028  *  See http://worm.me.uk/fullfat for more information.                      *
00029  *  Or  http://fullfat.googlecode.com/ for latest releases and the wiki.     *
00030  *****************************************************************************/
00031 
00045 #include "ff_format.h"
00046 #include "ff_types.h"
00047 #include "ff_ioman.h"
00048 #include "ff_fatdef.h"
00049 
00050 static FF_T_SINT8 FF_PartitionCount (FF_T_UINT8 *pBuffer)
00051 {
00052     FF_T_SINT8 count = 0;
00053     FF_T_SINT8 part;
00054     // Check PBR or MBR signature
00055     if (FF_getChar(pBuffer, FF_FAT_MBR_SIGNATURE) != 0x55 &&
00056         FF_getChar(pBuffer, FF_FAT_MBR_SIGNATURE) != 0xAA ) {
00057         // No MBR, but is it a PBR ?
00058         if (FF_getChar(pBuffer, 0) == 0xEB &&          // PBR Byte 0
00059             FF_getChar(pBuffer, 2) == 0x90 &&          // PBR Byte 2
00060             (FF_getChar(pBuffer, 21) & 0xF0) == 0xF0) {// PBR Byte 21 : Media byte
00061             return 1;   // No MBR but PBR exist then only one partition
00062         }
00063         return 0;   // No MBR and no PBR then no partition found
00064     }
00065     for (part = 0; part < 4; part++)  {
00066         FF_T_UINT8 active = FF_getChar(pBuffer, FF_FAT_PTBL + FF_FAT_PTBL_ACTIVE + (16 * part));
00067         FF_T_UINT8 part_id = FF_getChar(pBuffer, FF_FAT_PTBL + FF_FAT_PTBL_ID + (16 * part));
00068         // The first sector must be a MBR, then check the partition entry in the MBR
00069         if (active != 0x80 && (active != 0 || part_id == 0)) {
00070             break;
00071         }
00072         count++;
00073     }
00074     return count;
00075 }
00076 
00077 FF_ERROR FF_FormatPartition(FF_IOMAN *pIoman, FF_T_UINT32 ulPartitionNumber, FF_T_UINT32 ulClusterSize) {
00078     
00079     FF_BUFFER *pBuffer;
00080     FF_T_UINT8  ucPartitionType;
00081     FF_T_SINT8  scPartitionCount;
00082 
00083     FF_T_UINT32 /*ulPartitionBeginLBA, ulPartitionLength,*/ ulPnum;
00084 
00085     FF_ERROR    Error = FF_ERR_NONE;
00086 
00087     ulClusterSize = 0;
00088 
00089     // Get Partition Metrics, and pass on to FF_Format() function
00090 
00091     pBuffer = FF_GetBuffer(pIoman, 0, FF_MODE_READ);
00092     {
00093         if(!pBuffer) {
00094             return FF_ERR_DEVICE_DRIVER_FAILED;
00095         }
00096 
00097         scPartitionCount = FF_PartitionCount(pBuffer->pBuffer);
00098 
00099         ucPartitionType = FF_getChar(pBuffer->pBuffer, FF_FAT_PTBL + FF_FAT_PTBL_ID);
00100 
00101         if(ucPartitionType == 0xEE) {
00102             // Handle Extended Partitions
00103             ulPnum = 0;         
00104         } else {
00105             if(ulPartitionNumber > (FF_T_UINT32) scPartitionCount) {
00106                 FF_ReleaseBuffer(pIoman, pBuffer);
00107                 return FF_ERR_IOMAN_INVALID_PARTITION_NUM;
00108             }
00109             ulPnum = ulPartitionNumber;
00110         }
00111 
00112     }
00113     FF_ReleaseBuffer(pIoman, pBuffer);
00114 
00115 
00116 
00117     return Error;
00118     
00119 }
00120 
00121 FF_ERROR FF_Format(FF_IOMAN *pIoman, FF_T_UINT32 ulStartLBA, FF_T_UINT32 ulEndLBA, FF_T_UINT32 ulClusterSize) {
00122     FF_T_UINT32 ulTotalSectors;
00123     FF_T_UINT32 ulTotalClusters;
00124 
00125     ulTotalSectors  = ulEndLBA - ulStartLBA;
00126     ulTotalClusters = ulTotalSectors / (ulClusterSize / pIoman->BlkSize);
00127 
00128 
00129     return -1;
00130 
00131 
00132 }

Generated on Sat May 26 2012 04:33:00 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.