ReactOS  0.4.14-dev-854-gb9426a3
vfdfat.c File Reference
#include <windows.h>
#include "vfdtypes.h"
#include "vfdio.h"
#include "vfdlib.h"
#include "vfdver.h"
Include dependency graph for vfdfat.c:

Go to the source code of this file.

Classes

struct  _DOS_BPB
 
struct  _EXBPB
 
struct  _DOS_PBR
 

Macros

#define WIN32_LEAN_AND_MEAN
 
#define FAT_DIR_ENTRY_SIZE   32
 
#define VFD_JUMP_CODE   "\xeb\x3c\x90"
 
#define VFD_OEM_NAME   "VFD" VFD_DRIVER_VERSION_STR " "
 
#define VFD_VOLUME_LABEL   "NO NAME "
 
#define VFD_FILESYSTEM   "FAT12 "
 

Typedefs

typedef struct _DOS_BPB DOS_BPB
 
typedef struct _DOS_BPBPDOS_BPB
 
typedef struct _EXBPB EXBPB
 
typedef struct _EXBPBPEXBPB
 
typedef struct _DOS_PBR DOS_PBR
 
typedef struct _DOS_PBRPDOS_PBR
 

Functions

static const DOS_BPBSelectDosBpb (USHORT nSectors)
 
DWORD FormatBufferFat (PUCHAR pBuffer, ULONG nSectors)
 

Macro Definition Documentation

◆ FAT_DIR_ENTRY_SIZE

#define FAT_DIR_ENTRY_SIZE   32

Definition at line 71 of file vfdfat.c.

◆ VFD_FILESYSTEM

#define VFD_FILESYSTEM   "FAT12 "

Definition at line 78 of file vfdfat.c.

◆ VFD_JUMP_CODE

#define VFD_JUMP_CODE   "\xeb\x3c\x90"

Definition at line 75 of file vfdfat.c.

◆ VFD_OEM_NAME

#define VFD_OEM_NAME   "VFD" VFD_DRIVER_VERSION_STR " "

Definition at line 76 of file vfdfat.c.

◆ VFD_VOLUME_LABEL

#define VFD_VOLUME_LABEL   "NO NAME "

Definition at line 77 of file vfdfat.c.

◆ WIN32_LEAN_AND_MEAN

#define WIN32_LEAN_AND_MEAN

Definition at line 15 of file vfdfat.c.

Typedef Documentation

◆ DOS_BPB

◆ DOS_PBR

◆ EXBPB

typedef struct _EXBPB EXBPB

◆ PDOS_BPB

◆ PDOS_PBR

◆ PEXBPB

typedef struct _EXBPB * PEXBPB

Function Documentation

◆ FormatBufferFat()

DWORD FormatBufferFat ( PUCHAR  pBuffer,
ULONG  nSectors 
)

Definition at line 116 of file vfdfat.c.

119 {
120  const DOS_BPB *bpb; // BIOS Parameter Block
121  PDOS_PBR pbr; // Partition Boot Record
122  PUCHAR fat; // File Allocation Table
123  USHORT idx;
124 
125  VFDTRACE(0,
126  ("[VFD] VfdFormatImage - IN\n"));
127 
128  //
129  // Select DOS BPB parameters from media size
130  //
131  bpb = SelectDosBpb((USHORT)nSectors);
132 
133  if (!bpb) {
134  VFDTRACE(0,
135  ("[VFD] Unsupported media size %lu\n",
136  nSectors));
138  }
139 
140  //
141  // Initialize the whole area with the fill data
142  //
144  VFD_SECTOR_TO_BYTE(nSectors),
146 
147  //
148  // Make up the FAT boot record
149  //
151 
152  pbr = (PDOS_PBR)pBuffer;
153 
154  CopyMemory(pbr->jump, VFD_JUMP_CODE, sizeof(pbr->jump));
155  CopyMemory(pbr->oemid, VFD_OEM_NAME, sizeof(pbr->oemid));
156  CopyMemory(&pbr->bpb, bpb, sizeof(pbr->bpb));
157 
158  // Make up the extended BPB
159 
160  pbr->exbpb.BootSignature = 0x29;
161 
162  // use the tick count as the volume serial number
164 
166  VFD_VOLUME_LABEL, sizeof(pbr->exbpb.VolumeLabel));
167 
169  VFD_FILESYSTEM, sizeof(pbr->exbpb.FileSystemType));
170 
171  // Set the boot record signature
172 
173  *(pBuffer + VFD_BYTES_PER_SECTOR - 2) = 0x55;
174  *(pBuffer + VFD_BYTES_PER_SECTOR - 1) = 0xaa;
175 
176  //
177  // Clear FAT areas
178  //
180 
181  ZeroMemory(
182  fat,
184 
185  //
186  // Make up FAT entries for the root directory
187  //
188  for (idx = 0; idx < bpb->NumberOfFATs; idx++) {
189  *fat = bpb->MediaDescriptor;
190  *(fat + 1) = 0xff;
191  *(fat + 2) = 0xff;
192 
194  }
195 
196  //
197  // Clear root directory entries
198  //
200 
201  VFDTRACE(0,
202  ("[VFD] VfdFormatImage - OUT\n"));
203 
204  return ERROR_SUCCESS;
205 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
CHAR oemid[8]
Definition: vfdfat.c:63
USHORT SectorsPerFAT
Definition: vfdfat.c:36
#define ERROR_SUCCESS
Definition: deptool.c:10
UCHAR NumberOfFATs
Definition: vfdfat.c:32
#define VFD_BYTES_PER_SECTOR
Definition: vfdio.h:40
unsigned char * PUCHAR
Definition: retypes.h:3
DOS_BPB bpb
Definition: vfdfat.c:64
#define VFD_SECTOR_TO_BYTE(s)
Definition: vfdio.h:45
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:455
#define ZeroMemory
Definition: winbase.h:1642
#define VFD_VOLUME_LABEL
Definition: vfdfat.c:77
CHAR VolumeLabel[11]
Definition: vfdfat.c:53
#define VFD_FILESYSTEM
Definition: vfdfat.c:78
unsigned int idx
Definition: utils.c:41
PVOID pBuffer
#define FAT_DIR_ENTRY_SIZE
Definition: vfdfat.c:71
#define VFD_FORMAT_FILL_DATA
Definition: vfdio.h:51
#define CopyMemory
Definition: winbase.h:1640
#define VFD_JUMP_CODE
Definition: vfdfat.c:75
#define FillMemory(BUF, SIZ, MASK)
Definition: strucsup.c:31
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
USHORT RootEntries
Definition: vfdfat.c:33
EXBPB exbpb
Definition: vfdfat.c:65
UCHAR BootSignature
Definition: vfdfat.c:51
#define VFD_OEM_NAME
Definition: vfdfat.c:76
CHAR FileSystemType[8]
Definition: vfdfat.c:54
ULONG VolumeSerialNumber
Definition: vfdfat.c:52
struct _DOS_PBR * PDOS_PBR
UCHAR MediaDescriptor
Definition: vfdfat.c:35
unsigned short USHORT
Definition: pedump.c:61
UCHAR jump[3]
Definition: vfdfat.c:62
USHORT ReservedSectors
Definition: vfdfat.c:31
static const DOS_BPB * SelectDosBpb(USHORT nSectors)
Definition: vfdfat.c:83
static unsigned char * fat
Definition: mkdosfs.c:542

Referenced by VfdCreateImageFile(), VfdFormatMedia(), and VfdOpenImage().

◆ SelectDosBpb()

static const DOS_BPB* SelectDosBpb ( USHORT  nSectors)
static

Definition at line 83 of file vfdfat.c.

85 {
86  static const DOS_BPB bpb_tbl[] = {
87  // b/s s/c r fat root sec desc s/f s/t h
88  {VFD_BYTES_PER_SECTOR, 2, 1, 2, 112, 320, 0xFE, 1, 8, 1, 0, 0}, // 160KB 5.25"
89  {VFD_BYTES_PER_SECTOR, 2, 1, 2, 112, 360, 0xFC, 1, 9, 1, 0, 0}, // 180KB 5.25"
90  {VFD_BYTES_PER_SECTOR, 2, 1, 2, 112, 640, 0xFF, 1, 8, 2, 0, 0}, // 320KB 5.25"
91  {VFD_BYTES_PER_SECTOR, 2, 1, 2, 112, 720, 0xFD, 2, 9, 2, 0, 0}, // 360KB 5.25"
92  {VFD_BYTES_PER_SECTOR, 2, 1, 2, 112, 1280, 0xFB, 2, 8, 2, 0, 0}, // 640KB 5.25" / 3.5"
93  {VFD_BYTES_PER_SECTOR, 2, 1, 2, 112, 1440, 0xF9, 3, 9, 2, 0, 0}, // 720KB 5.25" / 3.5"
94  {VFD_BYTES_PER_SECTOR, 2, 1, 2, 112, 1640, 0xF9, 3, 10, 2, 0, 0}, // 820KB 3.5"
95  {VFD_BYTES_PER_SECTOR, 1, 1, 2, 224, 2400, 0xF9, 7, 15, 2, 0, 0}, // 1.20MB 5.25" / 3.5"
96  {VFD_BYTES_PER_SECTOR, 1, 1, 2, 224, 2880, 0xF0, 9, 18, 2, 0, 0}, // 1.44MB 3.5"
97  {VFD_BYTES_PER_SECTOR, 1, 1, 2, 224, 3360, 0xF0, 10, 21, 2, 0, 0}, // 1.68MB 3.5"
98  {VFD_BYTES_PER_SECTOR, 1, 1, 2, 224, 3444, 0xF0, 10, 21, 2, 0, 0}, // 1.72MB 3.5"
99  {VFD_BYTES_PER_SECTOR, 2, 1, 2, 240, 5760, 0xF0, 9, 36, 2, 0, 0}, // 2.88MB 3.5"
100  };
101 
102  int i;
103 
104  for (i = 0; i < sizeof(bpb_tbl) / sizeof(bpb_tbl[0]); i++) {
105  if (nSectors == bpb_tbl[i].SmallSectors) {
106  return &bpb_tbl[i];
107  }
108  }
109 
110  return NULL;
111 }
#define VFD_BYTES_PER_SECTOR
Definition: vfdio.h:40
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416

Referenced by FormatBufferFat().