コード例 #1
0
        static int RawDiskBackup(ConsoleService c, string cmdName, string str)
        {
            ConsoleParam[] args =
            {
                new ConsoleParam("[diskName]", ConsoleService.Prompt, "Physical disk name: ",    ConsoleService.EvalNotEmpty, null),
                new ConsoleParam("dst",        ConsoleService.Prompt, "Destination file name: ", ConsoleService.EvalNotEmpty, null),
                new ConsoleParam("truncate"),
            };

            ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args);

            string diskName    = vl.DefaultParam.StrValue;
            string dstFileName = vl["dst"].StrValue;
            long   truncate    = vl["truncate"].StrValue._ToLong();

            if (truncate <= 0)
            {
                truncate = -1;
            }
            else
            {
                truncate = (truncate + 4095L) / 4096L * 4096L;
            }

            using (var rawFs = new LocalRawDiskFileSystem())
            {
                using (var disk = rawFs.Open($"/{diskName}"))
                {
                    using (var file = Lfs.Create(dstFileName, flags: FileFlags.AutoCreateDirectory))
                    {
                        using (var reporter = new ProgressReporter(new ProgressReporterSetting(ProgressReporterOutputs.Console, toStr3: true), null))
                        {
                            FileUtil.CopyBetweenFileBaseAsync(disk, file, truncateSize: truncate, param: new CopyFileParams(asyncCopy: true, bufferSize: 16 * 1024 * 1024), reporter: reporter)._GetResult();
                        }
                    }
                }
            }

            return(0);
        }