ReactOS 0.4.15-dev-8109-gd7be748
finstext2.c File Reference
#include <stdio.h>
#include <string.h>
#include "finstext2.h"
#include "ext2.h"
#include <linux/hdreg.h>
#include <linux/ext3_fs.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
Include dependency graph for finstext2.c:

Go to the source code of this file.

Macros

#define MAJOR_VERSION   1
 
#define MINOR_VERSION   0
 

Functions

int main (int argc, char *argv[])
 

Variables

PEXT2_BOOTCODE Ext2BootCode = (PEXT2_BOOTCODE)ext2_data
 
struct ext3_super_block Ext2SuperBlock
 
struct hd_geometry Ext2DriveGeometry
 
unsigned char Ext2ExistingBootCode [1024]
 
char BlockDevice [260]
 
int BlockDeviceSpecified = 0
 
int BlockDeviceFileDescriptor
 

Macro Definition Documentation

◆ MAJOR_VERSION

#define MAJOR_VERSION   1

Definition at line 13 of file finstext2.c.

◆ MINOR_VERSION

#define MINOR_VERSION   0

Definition at line 14 of file finstext2.c.

Function Documentation

◆ main()

int main ( int argc  ,
char argv[] 
)

Definition at line 25 of file finstext2.c.

26{
27 int Index;
28 char ch;
29
30 // Verify that we got enough command line parameters
31 if (argc < 2)
32 {
33 printf("finstext2 block_device [-v]\n\n");
34 printf("block_device Specifies the ext2/3 volume to install to (i.e. /dev/hda1)\n");
35 printf("-v Displays the version\n\n");
36 }
37
38 // Parse the command line parameters
39 for (Index=1; Index<argc; Index++)
40 {
41 if (strcmp(argv[Index], "-v") == 0)
42 {
43 printf("FreeLoader Ext2/3 Installer v%d.%d\n", MAJOR_VERSION, MINOR_VERSION);
44 }
45 else
46 {
49 }
50 }
51
53 {
55
57 {
58 printf("Couldn't open block device %s\n", BlockDevice);
59 return 1;
60 }
61
63 {
65 printf("Couldn't read existing boot code from %s\n", BlockDevice);
66 return 1;
67 }
68
69 for (Index=0; Index<1024; Index++)
70 {
71 if (Ext2ExistingBootCode[Index] != 0x00)
72 {
73 printf("This EXT2/3 volume has existing boot code.\n");
74 printf("Do you want to overwrite it? [y/n] ");
75 scanf("%c", &ch);
76
77 if (ch == 'n' || ch == 'N')
78 {
80 printf("Cancelled.\n");
81 return 0;
82 }
83
84 break;
85 }
86 }
87
88 if (read(BlockDeviceFileDescriptor, &Ext2SuperBlock, (size_t)1024) != (ssize_t)1024)
89 {
91 printf("Couldn't read super block from %s\n", BlockDevice);
92 return 1;
93 }
94
95 if (Ext2SuperBlock.s_magic != EXT3_SUPER_MAGIC)
96 {
98 printf("Block device %s is not a EXT2/3 volume or has an invalid super block.\n", BlockDevice);
99 return 1;
100 }
101
102 if (ioctl(BlockDeviceFileDescriptor, HDIO_GETGEO, &Ext2DriveGeometry) != 0)
103 {
105 printf("Couldn't get drive geometry from block device %s\n", BlockDevice);
106 return 1;
107 }
108
109 printf("Heads: %d\n", Ext2DriveGeometry.heads);
110 printf("Sectors: %d\n", Ext2DriveGeometry.sectors);
111 printf("Cylinders: %d\n", Ext2DriveGeometry.cylinders);
112 printf("Start: %d\n", Ext2DriveGeometry.start);
113
114 Ext2BootCode->BootDrive = 0xff;
116 //Ext2BootCode->SectorsPerTrack = Ext2DriveGeometry.sectors;
117 //Ext2BootCode->NumberOfHeads = Ext2DriveGeometry.heads;
119 Ext2BootCode->Ext2BlockSizeInBytes = 1024 << Ext2SuperBlock.s_log_block_size;
123 Ext2BootCode->Ext2FirstDataBlock = Ext2SuperBlock.s_first_data_block;
124 Ext2BootCode->Ext2InodesPerGroup = Ext2SuperBlock.s_inodes_per_group;
126
128 {
130 printf("Couldn't write boot code on %s\n", BlockDevice);
131 return 1;
132 }
133
134 if (write(BlockDeviceFileDescriptor, Ext2BootCode, (size_t)1024) != (ssize_t)1024)
135 {
137 printf("Couldn't write boot code on %s\n", BlockDevice);
138 return 1;
139 }
140
142
143 printf("Boot code written successfully!\n");
144 }
145
146 return 0;
147}
static int argc
Definition: ServiceArgs.c:12
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
#define read
Definition: acwin.h:96
#define open
Definition: acwin.h:95
#define close
Definition: acwin.h:98
#define write
Definition: acwin.h:97
__kernel_off_t off_t
Definition: linux.h:201
int BlockDeviceFileDescriptor
Definition: finstext2.c:23
unsigned char Ext2ExistingBootCode[1024]
Definition: finstext2.c:19
#define MINOR_VERSION
Definition: finstext2.c:14
int BlockDeviceSpecified
Definition: finstext2.c:22
struct hd_geometry Ext2DriveGeometry
Definition: finstext2.c:18
PEXT2_BOOTCODE Ext2BootCode
Definition: finstext2.c:16
#define MAJOR_VERSION
Definition: finstext2.c:13
struct ext3_super_block Ext2SuperBlock
Definition: finstext2.c:17
char BlockDevice[260]
Definition: finstext2.c:21
#define printf
Definition: freeldr.h:97
#define O_RDWR
Definition: fcntl.h:36
_Check_return_ _CRTIMP int __cdecl scanf(_In_z_ _Scanf_format_string_ const char *_Format,...)
#define SEEK_SET
Definition: jmemansi.c:26
#define lseek
Definition: syshdrs.h:47
#define argv
Definition: mplay32.c:18
int ssize_t
Definition: rosdhcp.h:48
unsigned long Ext2InodesPerBlock
Definition: finstext2.h:22
unsigned long Ext2InodesPerGroup
Definition: finstext2.h:21
unsigned char BootDrive
Definition: finstext2.h:8
unsigned long Ext2PointersPerBlock
Definition: finstext2.h:18
unsigned long Ext2FirstDataBlock
Definition: finstext2.h:20
unsigned char BootPartition
Definition: finstext2.h:26
unsigned long Ext2BlockSizeInBytes
Definition: finstext2.h:17
unsigned long Ext2BlockSize
Definition: finstext2.h:16
unsigned long Ext2VolumeStartSector
Definition: finstext2.h:15
unsigned long Ext2GroupDescPerBlock
Definition: finstext2.h:19
_In_ WDFCOLLECTION _In_ ULONG Index
#define ioctl
Definition: wintirpc.h:60

Variable Documentation

◆ BlockDevice

◆ BlockDeviceFileDescriptor

int BlockDeviceFileDescriptor

Definition at line 23 of file finstext2.c.

Referenced by main().

◆ BlockDeviceSpecified

int BlockDeviceSpecified = 0

Definition at line 22 of file finstext2.c.

Referenced by main().

◆ Ext2BootCode

PEXT2_BOOTCODE Ext2BootCode = (PEXT2_BOOTCODE)ext2_data

Definition at line 16 of file finstext2.c.

Referenced by main().

◆ Ext2DriveGeometry

struct hd_geometry Ext2DriveGeometry

Definition at line 18 of file finstext2.c.

Referenced by main().

◆ Ext2ExistingBootCode

unsigned char Ext2ExistingBootCode[1024]

Definition at line 19 of file finstext2.c.

Referenced by main().

◆ Ext2SuperBlock

struct ext3_super_block Ext2SuperBlock

Definition at line 17 of file finstext2.c.

Referenced by main().