Example #1
0
        static void CreateOSOnDisk(DiskDriver disk)
        {
            // create the operating system on disk if not present

            disk.TurnOn();

            // try to mount the disk, format if needed first
            FileSystem filesystem = new SimpleFS();

            try
            {
                filesystem.Mount(disk, "/");
            }
            catch (Exception)
            {
                filesystem.Format(disk);
                filesystem.Mount(disk, "/");
            }

            Directory rootDir = filesystem.GetRootDirectory();

            // password file for security subsystem if not present
            if (filesystem.Find("/passwd") == null)
            {
                rootDir.CreateFile("passwd");
            }

            // user home directory and files if not present
            if (filesystem.Find("/home") == null)
            {
                rootDir.CreateDirectory("home");
            }

            // root user if not present
            SecuritySystem security = new SimpleSecurity(filesystem, "passwd");

            try
            {
                security.AddUser("root");
            }
            catch (Exception)
            {
            }

            disk.TurnOff();
        }