Author: dquintana
Date: Sun Sep  6 18:10:59 2015
New Revision: 69064

URL: http://svn.reactos.org/svn/reactos?rev=69064&view=rev
Log:
[FATTEN]
* Improve crossplatformness.
* Turn back some indentations into tabs (temporarily).

Removed:
    trunk/reactos/tools/fatten/FAT.h
Modified:
    trunk/reactos/tools/fatten/fatfs/diskio.c
    trunk/reactos/tools/fatten/fatten.c

Removed: trunk/reactos/tools/fatten/FAT.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/fatten/FAT.h?rev=69063
==============================================================================
--- trunk/reactos/tools/fatten/FAT.h    [iso-8859-1] (original)
+++ trunk/reactos/tools/fatten/FAT.h    (removed)
@@ -1,42 +0,0 @@
-#ifndef _FAT_H_INCLUDED
-#define _FAT_H_INCLUDED
-
-typedef unsigned __int8  u8;
-typedef unsigned __int16 u16;
-typedef unsigned __int32 UInt32;
-typedef unsigned __int64 u64;
-typedef   signed __int8  s8;
-typedef   signed __int16 s16;
-typedef   signed __int32 s32;
-typedef   signed __int64 s64;
-
-#if 0
-struct Fat_Bootrecord {
-       u8  Jump[3];
-       u8  OEMID[8];
-       u8  BytesPerSector;
-       u8  SectorsPerCluster;          // 1
-       u16 ReservedSectors;            // 1
-       u8  FATs;
-       u16 RootEntries;
-       u16 Sectors16;
-       u8  MediaDescriptor;            // F0h = 1.44 MB, 3.5", 2-sided, 
18-sectors per track
-       u16 SectorsPerFAT;
-       u16 SectorsPerTrack;            // 18
-       u16 Heads;                                      
-       u32 HiddenSectors;
-       u32 Sectors32;
-       u8  PhysicalDriveNo; // 00h for floppy, 80h for HDD
-       u8  CurrentHead;
-       u8  NTSignature;                 //for WinNT: 28h or 29h
-       u32 SerialNumber;
-       u8  VolumeLabel[11];
-       u8  SystemID[8];
-       u8  BootCode[510 - 62];
-       u16 Signature; // 0xAA55
-};
-#endif
-
-extern char* imageFileName;
-
-#endif//_FAT_H_INCLUDED

Modified: trunk/reactos/tools/fatten/fatfs/diskio.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/fatten/fatfs/diskio.c?rev=69064&r1=69063&r2=69064&view=diff
==============================================================================
--- trunk/reactos/tools/fatten/fatfs/diskio.c   [iso-8859-1] (original)
+++ trunk/reactos/tools/fatten/fatfs/diskio.c   [iso-8859-1] Sun Sep  6 
18:10:59 2015
@@ -7,13 +7,14 @@
 /* storage control module to the FatFs module with a defined API.        */
 /*-----------------------------------------------------------------------*/
 #include "diskio.h"
-#include "../FAT.h"
 #include <stdio.h>
+
+extern char* imageFileName;
 
 /*-----------------------------------------------------------------------*/
 /* Correspondence between physical drive number and image file handles.  */
 
-HANDLE driveHandle[1] = {INVALID_HANDLE_VALUE};
+FILE* driveHandle[1] = {NULL};
 const int driveHandleCount = sizeof(driveHandle) / sizeof(FILE*);
 
 /*-----------------------------------------------------------------------*/
@@ -26,12 +27,12 @@
 {
        if(pdrv == 0) // only one drive (image file) supported atm.
        {
-               if(driveHandle[0]!=INVALID_HANDLE_VALUE)
+               if(driveHandle[0]!=NULL)
                        return 0;
 
-               driveHandle[0]=CreateFile(imageFileName, GENERIC_READ | 
GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL /* | 
FILE_FLAG_RANDOM_ACCESS */, NULL);
+               driveHandle[0]=fopen(imageFileName, "r+b");
 
-               if(driveHandle[0]!=INVALID_HANDLE_VALUE)
+               if(driveHandle[0]!=NULL)
                        return 0;
        }
        return STA_NOINIT;
@@ -49,7 +50,7 @@
 {
        if(pdrv < driveHandleCount)
        {
-               if(driveHandle[pdrv] != INVALID_HANDLE_VALUE)
+               if(driveHandle[pdrv] != NULL)
                        return 0;
        }
        return STA_NOINIT;
@@ -72,15 +73,14 @@
 
        if(pdrv < driveHandleCount)
        {
-               if(driveHandle[pdrv] != INVALID_HANDLE_VALUE)
+               if(driveHandle[pdrv] != NULL)
                {
-                       if(SetFilePointer(driveHandle[pdrv], sector * 512, 
NULL, SEEK_SET) == INVALID_SET_FILE_POINTER)
+                       if(fseek(driveHandle[pdrv], sector * 512, SEEK_SET))
                                return RES_ERROR;
 
-                       if(!ReadFile(driveHandle[pdrv], buff, 512 * count, 
&result, NULL))
-                               return RES_ERROR;
+                       result = fread(buff, 512, count, driveHandle[pdrv]);
 
-                       if(result == (512 * count))
+                       if(result == count)
                                return RES_OK;
 
                        return RES_ERROR;
@@ -108,18 +108,18 @@
 
        if(pdrv < driveHandleCount)
        {
-               if(driveHandle[pdrv] != INVALID_HANDLE_VALUE)
+               if(driveHandle[pdrv] != NULL)
                {
-                       if(SetFilePointer(driveHandle[pdrv], sector * 512, 
NULL, SEEK_SET) == INVALID_SET_FILE_POINTER)
+                       if(fseek(driveHandle[pdrv], sector * 512, SEEK_SET))
                                return RES_ERROR;
 
-                       if(!WriteFile(driveHandle[pdrv], buff, 512 * count, 
&result, NULL))
+                       result = fwrite(buff, 512, count, driveHandle[pdrv]);
                                return RES_ERROR;
 
-                       if(result == (512 * count))
-                               return RES_OK;
+                       if(result != (512 * count))
+                               return RES_ERROR;
 
-                       return RES_ERROR;
+                       return RES_OK;
                }
        }
 
@@ -141,11 +141,12 @@
 {
        if(pdrv < driveHandleCount)
        {
-               if(driveHandle[pdrv] != INVALID_HANDLE_VALUE)
+               if(driveHandle[pdrv] != NULL)
                {
                        switch(cmd)
                        {
                        case CTRL_SYNC:
+                               fflush(driveHandle[pdrv]);
                                return RES_OK;
                        case GET_SECTOR_SIZE:
                                *(DWORD*)buff = 512;
@@ -154,15 +155,32 @@
                                *(DWORD*)buff = 512;
                                return RES_OK;
                        case GET_SECTOR_COUNT:
-                               {
-                                       *(DWORD*)buff = 
GetFileSize(driveHandle[pdrv], NULL) / 512;
-                               }
+                               fseek(driveHandle[pdrv], 0, SEEK_END);
+                               *(DWORD*)buff = ftell(driveHandle[pdrv]) / 512;
                                return RES_OK;
                        case SET_SECTOR_COUNT:
+                       {
+                               int count = *(DWORD*)buff;
+                               long size;
+                               
+                               fseek(driveHandle[pdrv], 0, SEEK_END);
+                               size = ftell(driveHandle[pdrv]) / 512;
+                               
+                               if(size < count)
                                {
-                                       SetFilePointer(driveHandle[pdrv], 
(*(DWORD*)buff)*512, NULL, SEEK_SET);
-                                       SetEndOfFile(driveHandle[pdrv]);
+                                       if(fseek(driveHandle[pdrv], count * 512 
- 1, SEEK_SET))
+                                           return RES_ERROR;   
+
+                                       fwrite(buff, 1, 1, driveHandle[pdrv]);
+
+                                       return RES_OK;
                                }
+                               else
+                               {
+                                   // SHRINKING NOT IMPLEMENTED
+                                   return RES_OK;
+                               }
+                       }
                        }
                }
        }

Modified: trunk/reactos/tools/fatten/fatten.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/fatten/fatten.c?rev=69064&r1=69063&r2=69064&view=diff
==============================================================================
--- trunk/reactos/tools/fatten/fatten.c [iso-8859-1] (original)
+++ trunk/reactos/tools/fatten/fatten.c [iso-8859-1] Sun Sep  6 18:10:59 2015
@@ -7,8 +7,7 @@
  */
 #include <stdio.h>
 #include <string.h>
-#include <windows.h>
-#include "FAT.h"
+#include <time.h>
 #include "fatfs/ff.h"
 #include "fatfs/diskio.h"
 
@@ -16,7 +15,7 @@
 
 FATFS g_Filesystem;
 
-BOOL isMounted;
+int isMounted = 0;
 
 // tool needed by fatfs
 DWORD get_fattime()
@@ -24,9 +23,11 @@
        /* 31-25: Year(0-127 org.1980), 24-21: Month(1-12), 20-16: Day(1-31) */
        /* 15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2) */
 
-       SYSTEMTIME stm;
-
-       GetLocalTime(&stm);
+       time_t rawtime;
+       struct tm * timeinfo;
+
+       time (&rawtime);
+       timeinfo = localtime (&rawtime);
 
        union FatTime {
                struct {
@@ -40,12 +41,12 @@
                DWORD whole;
        } myTime = {
                {
-                       stm.wSecond / 2,
-                       stm.wMinute,
-                       stm.wHour,
-                       stm.wDay,
-                       stm.wMonth,
-                       stm.wYear - 1980,
+                       timeinfo->tm_sec / 2,
+                       timeinfo->tm_min,
+                       timeinfo->tm_hour,
+                       timeinfo->tm_mday,
+                       timeinfo->tm_mon,
+                       timeinfo->tm_year - 1980,
                }
        };
 
@@ -58,34 +59,34 @@
 }
 
 #define NEED_PARAMS(_min_,_max_) \
-    do {\
-        if(nargs<_min_) { printf("Too few args for command %s.\n",argv[-1]); 
goto print_help; } \
-        if(nargs>_max_) { printf("Too many args for command %s.\n",argv[-1]); 
goto print_help; } \
-    } while(0)
+       do {\
+               if(nargs<_min_) { printf("Too few args for command 
%s.\n",argv[-1]); goto print_help; } \
+               if(nargs>_max_) { printf("Too many args for command 
%s.\n",argv[-1]); goto print_help; } \
+       } while(0)
 
 BOOL need_mount()
-{   
-    if(isMounted)
-        return FR_OK;
-    
-    int r = f_mount(&g_Filesystem, "0:", 0);
+{
+       if(isMounted)
+               return FR_OK;
+
+       int r = f_mount(&g_Filesystem, "0:", 0);
        if(r)
-        return r;
-    
-    isMounted = TRUE;
-    return FR_OK;
+               return r;
+
+       isMounted = 1;
+       return FR_OK;
 }
 
 #define NEED_MOUNT() \
-    do { ret = need_mount(); if(ret) \
-    {\
-        printf("Error: could not mount image file '%s' (%d). \n", 
imageFileName, ret); \
-        goto print_help; \
-    } } while(0)
+       do { ret = need_mount(); if(ret) \
+       {\
+               printf("Error: could not mount image file '%s' (%d). \n", 
imageFileName, ret); \
+               goto print_help; \
+       } } while(0)
 
 int main(int oargc, char* oargv[])
 {
-    int ret;
+       int ret;
        int    argc = oargc-1;
        char** argv = oargv+1;
 
@@ -135,10 +136,10 @@
                if(strcmp(parg,"format")==0)
                {
                        // NOTE: The fs driver detects which FAT format fits 
best based on size
-            
+
                        NEED_PARAMS(1,1);
 
-            NEED_MOUNT();
+                       NEED_MOUNT();
 
                        // Arg 1: number of sectors
                        int sectors = atoi(argv[0]);
@@ -150,13 +151,13 @@
                        }
 
                        disk_ioctl(0, SET_SECTOR_COUNT, &sectors);
-               
-            ret = f_mkfs("0:", 1, 4096);
+
+                       ret = f_mkfs("0:", 1, 4096);
                        if (ret)
-            {
-                printf("ERROR: Formatting drive: %d.\n", ret);
-                goto print_help;
-            }
+                       {
+                               printf("ERROR: Formatting drive: %d.\n", ret);
+                               goto print_help;
+                       }
                }
                else if(strcmp(parg,"boot")==0)
                {
@@ -168,8 +169,8 @@
                else if(strcmp(parg,"add")==0)
                {
                        NEED_PARAMS(2,2);
-            
-            NEED_MOUNT();
+
+                       NEED_MOUNT();
 
                        // Arg 1: external file to add
                        // Arg 2: virtual filename
@@ -204,8 +205,8 @@
                {
                        NEED_PARAMS(2,2);
 
-            NEED_MOUNT();
-            
+                       NEED_MOUNT();
+
                        // Arg 1: virtual file to extract
                        // Arg 2: external filename
 
@@ -239,8 +240,7 @@
                {
                        NEED_PARAMS(2,2);
 
-            NEED_MOUNT();
-            
+                       NEED_MOUNT();
                        // Arg 1: src path & filename
                        // Arg 2: new path & filename
 
@@ -249,10 +249,9 @@
                }
                else if(strcmp(parg,"copy")==0)
                {
-                       NEED_PARAMS(2,2);
-
-            NEED_MOUNT();
-            
+                       NEED_PARAMS(2,2)
+
+                       NEED_MOUNT();
                        // Arg 1: src path & filename
                        // Arg 2: new path & filename
 
@@ -286,8 +285,7 @@
                {
                        NEED_PARAMS(1,1);
 
-            NEED_MOUNT();
-            
+                       NEED_MOUNT();
                        // Arg 1: folder path
                        f_mkdir(argv[1]);
                }
@@ -295,8 +293,7 @@
                {
                        NEED_PARAMS(1,1);
 
-            NEED_MOUNT();
-            
+                       NEED_MOUNT();
                        // Arg 1: file/folder path (cannot delete non-empty 
folders)
                        f_unlink(argv[1]);
                }


Reply via email to