public async Task <bool> TryAllocate(IPhone phone, ByteSize requiredSpace)
        {
            Log.Verbose("Shrinking Data partition...");

            var dataVolume = await phone.GetDataVolume();

            if (dataVolume == null)
            {
                return(false);
            }

            var phoneDisk = await phone.GetDeviceDisk();

            var data      = dataVolume.Size;
            var allocated = phoneDisk.AllocatedSize;
            var available = phoneDisk.AvailableSize;
            var newData   = data - (requiredSpace - available);



            Log.Verbose("Total size allocated: {Size}", allocated);
            Log.Verbose("Space available: {Size}", available);
            Log.Verbose("Space needed: {Size}", requiredSpace);
            Log.Verbose("'Data' size: {Size}", data);
            Log.Verbose("Calculated new size for the 'Data' partition: {Size}", newData);

            Log.Verbose("Resizing 'Data' to {Size}", newData);

            await dataVolume.Partition.Resize(newData);

            Log.Verbose("Resize operation completed successfully");

            return(await phone.IsThereEnoughSpace(requiredSpace));
        }
Ejemplo n.º 2
0
        private async Task PreparePhoneDiskForSafeRemoval()
        {
            Log.Information("# Preparing phone for safe removal");
            Log.Information("Please wait...");
            var disk = await phone.GetDeviceDisk();

            await disk.Refresh();
        }
Ejemplo n.º 3
0
        private async Task <WindowsVolumes> CreatePartitions()
        {
            Log.Verbose("Creating Windows partitions...");

            await(await phone.GetDeviceDisk()).CreateReservedPartition((ulong)ReservedPartitionSize.Bytes);

            var bootPartition = await(await phone.GetDeviceDisk()).CreatePartition((ulong)BootPartitionSize.Bytes);
            var bootVolume    = await bootPartition.GetVolume();

            await bootVolume.Mount();

            await bootVolume.Format(FileSystemFormat.Fat32, BootPartitionLabel);

            var windowsPartition = await(await phone.GetDeviceDisk()).CreatePartition(ulong.MaxValue);
            var winVolume        = await windowsPartition.GetVolume();

            await winVolume.Mount();

            await winVolume.Format(FileSystemFormat.Ntfs, WindowsPartitonLabel);

            Log.Verbose("Windows Partitions created successfully");

            return(new WindowsVolumes(await phone.GetBootVolume(), await phone.GetWindowsVolume()));
        }
Ejemplo n.º 4
0
        public async Task Clean(IPhone toClean)
        {
            Log.Information("Performing partition cleanup");

            disk = await toClean.GetDeviceDisk();

            dataPartition = await disk.GetPartitionByName(PartitionName.Data);

            await RemoveAnyPartitionsAfterData();
            await EnsureDataIsLastPartition();

            Log.Information("Cleanup done");

            await disk.Refresh();
        }
        public async Task Clean(IPhone toClean)
        {
            Log.Information("Performing cleanup of possible existing deployments");

            disk = await toClean.GetDeviceDisk();

            using (var context = await GptContextFactory.Create(disk.Number, FileAccess.ReadWrite))
            {
                context.RemoveExisting(PartitionName.System);
                context.RemoveExisting(PartitionName.Reserved);
                context.RemoveExisting(PartitionName.Windows);
            }

            Log.Information("Cleanup done");

            await disk.Refresh();
        }
Ejemplo n.º 6
0
        public async Task Execute()
        {
            var disk = await phone.GetDeviceDisk();

            var espPart = await disk.GetBootEfiEspPartition();

            if (espPart != null)
            {
                await espPart.SetGptType(PartitionType.Basic);
            }

            var bootVol = await phone.GetBootVolume();

            var finalPath = Path.Combine(bootVol.RootDir.Name, destination);
            await fileSystemOperations.Copy(origin, finalPath);

            await bootVol.Partition.SetGptType(PartitionType.Esp);
        }
        public async Task Clean(IPhone toClean)
        {
            Log.Information("Performing cleanup of possible existing deployments");

            disk = await toClean.GetDeviceDisk();

            using (var context = await GptContextFactory.Create(disk.Number, FileAccess.ReadWrite))
            {
                RemoveWellKnownPartitions(context);

                // This code is not there because it's considered unsafe. It's here just in case it's useful for a rare case.
                // RemovePartitionsAfterData(context);
            }

            Log.Information("Cleanup done");

            await disk.Refresh();
        }
Ejemplo n.º 8
0
        public async Task Clean(IPhone toClean)
        {
            Log.Information("Performing partition cleanup");

            disk = await toClean.GetDeviceDisk();

            dataPartition = await disk.GetPartition(PartitionName.Data);

            if (dataPartition == null)
            {
                Log.Verbose("Data partition not found. Skipping cleanup.");
                return;
            }

            await RemoveAnyPartitionsAfterData();
            await EnsureDataIsLastPartition();

            Log.Information("Cleanup done");

            await disk.Refresh();
        }