MinOS

From FullFAT

Jump to: navigation, search
MinOS   Features    

MinOS is a commercial operating system (also by me). MinOS comes with a complete integration of FullFAT into the stdio library.

MinOS is not a complete OS, its really a well-organised framework that runs in usermode. It currently provides support for file I/O and Audio capabilities.

The real advantage of MinOS is that it improves the dependability of any system, due to its special low-cost HANDLE management system.

FullFAT comes with a complete demonstration of MinOS (an early development edition) providing a very simple demonstration of a complete integration of FullFAT as a file-system. Its also a great opportunity to show off MinOS as an OGG Vorbis player.

Below is an example of a system initialisation with MinOS.

#include <stdlib.h>
#include <minos.h>
#include <driver/win32_blockdev.h>
#include <driver/win32_stdio_streamdev.h>
#include <stdio.h>
 
#include "../../FFTerm/src/ffterm.h"
 
extern Fullfat_GetFSFunctions(void);
extern Strio_GetFSFunctions(void);
 
/*
        An information command!
*/
int info(int argc, char **argv) {
        printf("\n
MinOS Version 0.2A\n\n
(C) 2009 James Walmsley\n\n\n
MinOS (Minimum Operating System) is a platform-independent Operating system\n
It's designed especially for embedded systems, and has a unique HANDLE\n
type-checking system that improves the dependability of a system.\n
This is done at a small cost.\n\n");
        return 0;
}
/*
        A description and error code table for the command.
*/
const COMMAND_DESCRIPTION infoInfo[] =
{
        "Provides information about the installed MinOS Operating System.",             COMMAND_INFO,
        NULL
};
 
 
/*
        MinOS Main Initialisation and start of terminal.
*/
int main(int argc, char **argv) {
 
        ERROR   Err;                                    // An Error code Var.
        HANDLE  hDevice;                                // Handle for a device.
        HANDLE  hFS;                                    // Handle for a filesystem.
        HANDLE  hVolume;                                // Handle to a Volume.
        HANDLE  hPartition;                             // Handle to a Partition on a Volume.
        HANDLE  hConsole;                               // Console Handle
 
        char buffer[512];
        int i;
 
 
        /*
                Initialise the various components of MinOS. This will be integrated into a MinosStart() function.
        */
        Err = CreateDevMan();                   // Create the device manager!
        Err = CreateFSMan();                    // Create the File-system manager.
        Err = CreateVolMan();                   // Create the Volume and Partition manager.
 
 
        /*
                Register some File-systems. (2 are built-into MinOS, FullFAT and a Streaming IO file-system).
                More could be added if a developer wanted to make a driver, using the MinOS FS Driver model. (MFSDM)
        */
        Err = RegisterFilesystem("fullfat", (FN_FS_INFO)Fullfat_GetFSFunctions);        // Register fullfat
        Err = RegisterFilesystem("strio", (FN_FS_INFO)Strio_GetFSFunctions);            // Register streaming I/O
 
        /*
                Register some devices with MinOS.
                Currently the device manager supports Block and Stream devices.
        */
        // Register a Windows \\PHYSICALDRIVE as a block device. The number as the second parameter is the PHYSICALDRIVE number to register.
        Err = RegisterDevice("sda", (void *) 1, BLOCK_DEVICE, (FN_DEV_OPEN)Win32_BlockDevOpen, (FN_DEV_CLOSE)Win32_BlockDevClose, (FN_DEV_INFO)Win32_BlockDevInfo);
 
        // Register a Windows Console as a streaming I/O deivice. This uses the MinOS Win32 stdio stream device driver.
        Err = RegisterDevice("strio", NULL, STREAM_DEVICE, (FN_DEV_OPEN) Win32_stdio_streamdev_Open, (FN_DEV_CLOSE) Win32_stdio_streamdev_Close, Win32_stdio_streamdev_Info);
 
        /*
                Enumerate and Mount devices for File I/O.
        */
        hDevice = GetDeviceHandle("strio", &Err);       // Get a Handle to the streaming I/O device.
        Err = EnumerateVolume(hDevice, "strio");                        // Enumerate the streaming I/O device. (Creates volume & partition handles).
        hVolume = GetVolumeHandle("strio", NULL);       // Get a Handle to the strio device Volume.
 
        hFS = GetFilesystemHandle("strio", NULL);       // Get a Handle to the File-system that we want to mount the strio device with.
 
        /*
                Mount the Streaming I/O device.
        */
        for(i = 0; i < GetVolumePartitions(hVolume); i++) {     // We find the total number of partitions on the STRIO volume. (This should be 1).
                hPartition = GetPartitionHandle(hVolume, i, &Err);      // Get a handle to the partition.
                if(Err) {
                        printf("%s\n", GetErrorMessage(Err));   // If an error was encountered, print a useful message.
                }
                MountFilesystem(hFS, hPartition);                       // Mount the partition with the handle to the desired File-system.
        }
 
        /*
                Now that a streaming I/O device has been registered, we can open FILE handles to stdin and stdout, 
                allowing printf() to work.
        */
        stdin = fopen("strio0:\\", "r");
        stdout = fopen("strio0:\\", "w");
 
        /*
                Same procedure for mounting the other block (mass storage) device.
        */
 
        hDevice = GetDeviceHandle("sda", &Err);
        Err = EnumerateVolume(hDevice, "sda");
 
        /*
                We can use an API function to read the device RAW: (Reads in sector 0 of the registered device).
        */
        BlockDeviceRead(hDevice, 0, 1, buffer);
 
        hVolume = GetVolumeHandle("sda", &Err);
        hFS = GetFilesystemHandle("fullfat", &Err);
 
        for(i = 0; i < GetVolumePartitions(hVolume); i++) {     // We find the total number of partitions on the SDA volume. (This could be many).
                hPartition = GetPartitionHandle(hVolume, i, &Err);      // Get a handle to the partition.
                if(Err) {
                        printf("%s\n", GetErrorMessage(Err));   // If an error was encountered, print a useful message.
                }
                MountFilesystem(hFS, hPartition);                       // Mount the partition with the handle to the desired File-system.
        }
 
        // At this point we could use fopen() to open files on the device, e.g. sda0:\\test.txt or sda1:\\test.txt.
 
 
        // Now we're going to create the console and command terminal.  
        hConsole = CreateConsole("MinOS>", stdin, stdout, NULL);        // Create a Console.
 
        if(hConsole) {
                AddConsoleCommand(hConsole, "info", info, infoInfo);    // Add our info command with the command description.
                StartConsole(hConsole);                                                                 // Start the console. (Infinite loop until Console is terminated with the exit command).
        }
 
        return 0;
}


--James

Personal tools