Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let logFileName = "vlog.txt"
- let hdd = @"\device\harddisk3\dr3"
- let linesOfFile (fileName : string) = [
- use sr = new StreamReader (fileName)
- while not sr.EndOfStream do yield sr.ReadLine ()
- ]
- let (|Match|_|) pattern input =
- let m = Regex.Match(input, pattern) in
- if m.Success then Some (List.tail [ for x in m.Groups -> x.Value ]) else None
- let shellExecute program arguments =
- let startInfo = new ProcessStartInfo ()
- startInfo.FileName <- program
- startInfo.Arguments <- arguments
- startInfo.UseShellExecute <- false
- startInfo.RedirectStandardOutput <- true
- let proc = new Process ()
- proc.EnableRaisingEvents <- true
- let output_seq = new List<string> ()
- proc.OutputDataReceived.AddHandler (fun sender args -> output_seq.Add args.Data)
- proc.StartInfo <- startInfo
- proc.Start () |> ignore
- proc.BeginOutputReadLine ()
- proc.WaitForExit()
- (proc.ExitCode, output_seq)
- let listToDict (list : 'a list) =
- let dict = new Dictionary<'a,int> ()
- list |> List.iter (fun key -> if dict.ContainsKey key then dict.[key] <- dict.[key] + 1 else dict.Add (key, 1))
- dict
- let getBlockOrNone = function
- | Match ".*Block ([0-9]+) Error.*" [block] -> Some(int64 block)
- | _ -> None
- let getClusterByBlock block = block
- let getFileNameByCluster hdd cluster =
- let (exitCode, output) = shellExecute "nfi" (hdd + " " + (string cluster))
- output.[10]
- let printFileNamesFromDict dict =
- for KeyValue(k, v) in dict do printfn "%s [%d bad blocks]" k v
- linesOfFile logFileName
- |> List.choose getBlockOrNone // (ref:getBlocks)
- |> List.map getClusterByBlock // (ref:getClusters)
- |> List.map (getFileNameByCluster hdd) // (ref:getFileNames)
- |> listToDict // (ref:unifyFileNames)
- |> printFileNamesFromDict // (ref:print)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement