Beispiel #1
0
        public static IFileSystem CreateNewVolume([NotNull] string fileName, ulong volumeSize, [NotNull] IFileSystem destination)
        {
            Validate.ArgumentNotNull(fileName, "fileName");
            Validate.ArgumentNotNull(destination, "destination");

            var file = destination.CreateFile(fileName);
            file.SetFileSize(volumeSize); // preliminary allocation. mounting system will increase this size slightly.

            if (destination is PhysicalFileSystem)
            {
                var stream = new VirtualStream(file);
                var diskAccess = new DirectDiskAccess(stream);
                var vfs = new VirtualFileSystem(diskAccess, volumeSize);
                file.SetFileSize(vfs.RealVolumeSize);
                return vfs;
            }
            else
            {
                // for virtual files mounting file system directly.
                // this allows parallel access from any thread, not restricted by writer lock in creating thread.
                var destVfs = (VirtualFileSystem)destination;
                file.Close();
                var diskAccess = destVfs.MountDisk(fileName);
                var vfs = new VirtualFileSystem(diskAccess, volumeSize);
                diskAccess.SetFileSize(vfs.RealVolumeSize);
                return vfs;
            }
        }
Beispiel #2
0
        public static IFileSystem MountVirtual([NotNull] string fileName, [NotNull] IFileSystem source)
        {
            Validate.ArgumentNotNull(fileName, "fileName");
            Validate.ArgumentNotNull(source, "source");

            if (source is PhysicalFileSystem)
            {
                var file = source.OpenFile(fileName, true);
                var stream = new VirtualStream(file);
                var diskAccess = new DirectDiskAccess(stream);
                return new VirtualFileSystem(diskAccess);
            }

            var vfs = (VirtualFileSystem)source;
            var access = vfs.MountDisk(fileName);
            return new VirtualFileSystem(access);
        }