Ugly Stool Rotating Header Image

In Search of rsync for Windows

I like almost everything about rsync.  The efficiency employed when transferring files, the mind-numbing command line options for just about every situation, the ability to work over a pipe, and network synchronization.  The biggest fail is the lack of native Windows support.  Syncing files is not solely relegated to UNIX, so anytime I have two directories to synchronize I shake my fists at the heavens,  “O rsync, rsync, wherefore art thou rsync!”

There are alternatives to rsync on Windows, and I use some of them with various levels of success.  I actually think the tools are fine, and work quite well.  The problem is me, I want to use these tools as if they were actually rsync, and they are not.

Sync Toy

Microsoft provides the free program SyncToy.  It can synchronize two directories, and works well.  It is not quite rsync because…

  1. Must define the directory pairs upfront through a UI.
  2. Leaves debris on the file system that contains records of the data moved between the two directories.
  3. The real power of this tool feels obscured by the UI. 

The latest version of SyncToy (2.1) greatly improves upon previous versions.  I setup jobs, and run them every now and again.


Robocopy is a command line utility to copy files.  It should be available in the default OS install, so if you have Windows it is there.  Robocopy supports mirroring two directories.

Create a backup up My Pictures – save all of the images (*.jpg fies) to my portable USB drive E:.

cmd> robocopy “My Pictures” E:\backup\pictures /MIR *.jpg

Create a backup up My Pictures to my NAS device.  Create a record so if the transfer if interrupted it can be automatically resumed.

cmd> robocopy “My Pictures” \\nas\backup\pictures /MIR /Z *.jpg

Robocopy has lots more options too.  One can do multi-threaded copy, bandwidth throttling, just create directory tree and file names (no data), etc.  Well worth a look for the CLI inclined.


Duplicati is a reimplementation of duplicity for Windows.  They are both great backup utilities, but not exactly what I want.  I mention them because Duplicati’s author created an rsync library for C#.  This library would be a great starting point for a Windows rsync implementation.

There are other rsync library available such as librsync, and  I like the idea of Duplicati’s because it is attached to an actively maintained and working application.  Start reading the source too see the implementation.

In the end it was me, not rsync.  I think the tooling on Windows is more than sufficient to do what I want – mirror two directories.  I leave the door open for experimentation.  I may write my own synchronization tool to bring a few more of the rsync-like abilites to Windows natively.  SyncToy is built upon a publicly available API, and Duplicati provides an OSS .NET rsync library too, so who knows.

Windows 2008 R2 with the WNA3100

I could not find anything when I searched the Web after installing this wireless USB device, so just in case someone else is…the device does work on Windows 2008 R2, but you must enable Wireless LAN.

Server Manager –> Features –> Add Features –> Wireless LAN.

My First JSON Document

I am writing my first JSON document (welcome to the party), and looked for tools to help me write it.  I want a tools to validate the document’s syntax, and tell me when I am doing the wrong thing.

I didn’t find a whole lot.  I settled on the Perl library JSON::XS, which comes with the command line tool json_xs for pretty printing and validation (kind of like xml_pp from XML::Twig) .  I used js2-mode for EMACS to write the document.

My biggest disappointment is that JSON makes trailing commas optional.  JSON parsers can optionally support or not support this construct.  This is wrong.  It requires more code to not add the comma, then it does to just add the comma all the time.  The trailing comma is supported to assist with the machine generation of code.  For shame JSON, for shame!

This syntax is not universally supported.

    "abc": 123,
    "def": 456,
    "ghi": 789,

Strip the trailing comma for better parser support.  In other words, this really is the standard format.

    "abc": 123,
    "def": 456,
    "ghi": 789

My First C++: CMake, GoogleTest, and GoogleMock

When starting a new project I always consider how to build the code, and how to test it.  I can puzzle through Make after a fashion, but I am not a fan.  If the project is only going to exist on Windows I stop at Visual Studio and MSBuild.  If the project is ever going to run on Windows and/or Linux then start with a build system that provides portability.

CMake can generate different project files based on the OS and user desire.  For example, on Windows you can generate Visual Studio projects files (2008, 2010, etc), or NMake makefiles.  Google started a project call GYP as an alternative to CMake specifically for Chromium.  (See GYP’s wiki for a GYP vs. CMake opinion.)

With testing I am very familiar with the frameworks available on .NET and Java, but not for C++.  When I recently started a new C++ project to solve those ubiquitous block letter games on smartphones I wanted to know how I was going to test it.  After consulting the oracle I decided upon GoogleTest and GoogleMock.

It was a wee pain to figure out how to get everything to work together because I was (and still am) a CMake neophyte. 

Step 1: Create a program that needs to be tested.  I created a simple example (minus most of the implementation) that extracts links from an HTML document.

Step 2: Files

http_fetch.h defines a class that issues an HTTP GET of the specified URI and returns the contents of said URI as a string.

#ifndef __HTTP_FETCH_H__
#define __HTTP_FETCH_H__
#include <string>
class HttpFetch {
    virtual ~HttpFetch() {}
    virtual std::string GetUriAsString(const std::string& uri) const {
        // TODO(cboumenot): implement
        return std::string();
#endif // __HTTP_FETCH_H__

html_parser.h defines a class that parses the specified URI, and extracts all of the links found in the fetched HTML document.  It uses HttpFetch to get the data.

#ifndef __HTML_PARSER_H__
#define __HTML_PARSER_H__
#include <string>
#include <vector>
#include "http_fetch.h"
class HtmlParser {
    HtmlParser(const HttpFetch &http) :
        _http(http) {}
    std::vector<std::string> GetAllLinks(const std::string& uri) const {
        // TODO(cboumenot): implement
        return std::vector<std::string>();
    HttpFetch _http;
#endif // __HTML_PARSER_H__

I wrote a test for the HtmlParser using GoogleMock and GoogleTest.  I use mocking to inject data into HtmlParser and assert its responses.  Just like .NET/Java mocking goodness.

#include <string>
#include <vector>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "http_fetch.h"
#include "html_parser.h"
using ::testing::Return;
class HttpFetchMock : public HttpFetch {
    MOCK_CONST_METHOD1(GetUriAsString, std::string(const std::string& uri));
TEST(HtmlParser, OneLink) {
    char *html = "<html>"
    "<a href='/index.html'>index.html</a>"
    HttpFetchMock mock;
    HtmlParser parser(mock);
    EXPECT_CALL(mock, GetUriAsString(""))
    std::vector<std::string> links = parser.GetAllLinks("");
    EXPECT_EQ(1, links.size());
    EXPECT_STREQ("", links[0].c_str());
TEST(HtmlParser, NoData) {
    char *html = "";
    HttpFetchMock mock;
    HtmlParser parser(mock);
    EXPECT_CALL(mock, GetUriAsString(""))
    std::vector<std::string> links = parser.GetAllLinks("");
    EXPECT_EQ(0, links.size());

A mock is defined by deriving from HttpFetch.  All mocked methods are made public (yes, C++ allows this).  Methods are defined using GoogleMock macros.  The GoogleMock documentation is great, and has loads of information.  Everything I remember doing with NMock/EasyMock I have accomplished with GoogleMock.  I would even venture that one can do more with GoogleMock.

A test is defined with the TEST macro, and are written as one would expect.  Expectations are made on the mock before any methods on the mock are called.  Assertions are made using the EXPECT_* macros.

Building these codes starts with creating a CMake build file called CMakeLists.txt.

## CMakeLists.txt
option(foo_build_tests "Build all of foo's unit tests." OFF)
cmake_minimum_required(VERSION 2.6.2)
add_executable(foo ${foo_SOURCES})
if (foo_build_tests)
    add_test(html-tests html_parser_test)

This recipe starts of by defining a build option called foo_build_tests.  When CMake is invoked by default it will not build the tests because this option defaults to OFF.  This can easily by changed by flipping this switch when CMake is invoked.

$ cmake –Dfoo_build_tests .

By default CMake will generated makefiles, so the only thing necessary to build the code is to run make.  Of the many nice things CMake does it also adds a dependency on the CMakeLists.txt file.  If this file is out of date with respect to the Makefile, the Makefile will be re-auto-generated.  There is no need to keep invoking cmake after every change to CMakeLists.txt.

$ make

The recipes sets the project name using the project() function.  It also specifies a minimum CMake version.  If one is not defined CMake will complain, and 2.6.2 is the current default for GoogleTest.

The recipe hard-codes include and link directories (/usr/local/{include,lib})because this is where I installed GoogleMock and GoogleTest.  (A better approach would have been to use the find_package() function.)

The main project executable is defined by the add_executable() function and the list of sources that make it up (.h and .cc).

The test, html_parser_test, is defined in a much more complicated manner.  The test is only one .cc file (that does not define a main()), and the appropriate header files.  But, this test requires the GoogleMock and GoogleTest libraries as well as the dependencies of these libraries of which there is only pthread.  The dependencies of an executable can be built up, and do not have to be defined all at once.  Use the function target_link_libraries() to make the invdividual dependencies much more explicit  (or not, your call).  A better approach to defining the test would be to write a CMake function or macro that handled automatically adding the dependencies.  See the GoogleTest source code for such an example.

Finally, the function enable_testing(), and add_test() tell CMake to generate a target called test, that can be invoked easily from the command line.

$ make test

Viola!  A sample prototype for new C++ projects.

wmic vs. dmidecode

I use a machine’s SM BIOS UUID to track it, and I get this information by using either wmic or dmidecode depending the OS currently running.  The problem is that these tools never agree on what the UUID is.  One always has to transform (swizzle) the value of one of the programs to make them agree.

For example, my VM reports the following UUID depending upon the tool that read it.

cmd> wmic PATH Win32_ComputerSystemProduct GET UUID
$ dmidecode --string system-uuid

Notice how the first 16 bytes (three fields) are transformed between the two.  Which one is the incorrect UUID, or rather which output do you always transform before using.  (Note: the definition of incorrect may not be correct.)  I never bothered to figure out why the difference existed.

I was reading the dmidecode source code, and came across the following comment which solved the mystery.

 * As of version 2.6 of the SMBIOS specification, the first 3
 * fields of the UUID are supposed to be encoded on little-endian.
 * The specification says that this is the defacto standard,
 * however I've seen systems following RFC 4122 instead and use
 * network byte order, so I am reluctant to apply the byte-swapping
 * for older versions.

I can now sleep better at night.

How to Create a WinPE ISO

Download the Windows Automated Installation Kit, or WAIK (pronounced “wake”) from Microsoft.  WAIK’s are versioned by the OS they are based on.  For example, there is WAIK for Vista/Server 2008, and another for WAIK for Windows 7/Server 2008 R2.  (WAIK for Windows 7/Server 2008 R2 SP1 was recently released.)

After installing WAIK execute the following instructions to build a WinPE x86 (32-bit) ISO image.  (You need to run as an administrator to execute some of these commands.)  WinPE is a stripped down Windows 7 OS and only supports the architecture it is built against.  For example, the amd64 (64-bit) does not support running 32-bit binaries even though the full OS does.  If the application you want to run is strictly 64-bit use amd64, likewise if it is a 32-bit application use x86.  (ia64 support is available too.).

cd "\Program Files\Windows AIK\Tools\PETools"
copype.cmd x86 c:\windowspe-x86
cd "\Program Files\Windows AIK\Tools\Servicing"
dism /Mount-Wim /WimFile:c:\windowspe-x86\winpe.wim /Index:1 /MountDir:c:\windowspe-x86\mount
copy ..\x86\imagex.exe c:\windowspe-x86\mount\Windows\System32\
dism /Add-Package /PackagePath:..\PETools\x86\WinPE_FPs\ /image:c:\windowspe-x86\mount
dism /Add-Package /PackagePath:..\PETools\x86\WinPE_FPs\ /image:c:\windowspe-x86\mount
dism /Unmount-Wim /Commit /MountDir:c:\windowspe-x86\mount
copy c:\windowspe-x86\winpe.wim c:\windowspe-x86\ISO\sources\boot.wim
..\x86\oscdimg.exe -n -bc:\windowspe-x86\ c:\windowspe-x86\ISO c:\windowspe-x86\windowspe-x86.iso

This is a basic WinPE with two packages added via the dism command.  The package installs code to run WSH scripts – think VBscript and JScript.  The package supports the execution of the WMI commands.  WMI is useful for interrogating the system’s resource from the command line.  Documentation for other WinPE packages is available at MSDN.

Step 6 copies the imagex.exe executable into the WinPE because it is not installed by default.  ImageX is used to copy disk/OS images from an existing machine, and for applying disk/OS images.  (Not sure why the default image does not include ImageX as it is the OS deployment tool.)

Device drivers can be installed into a WinPE image using the dism command.  For example, if the drivers have been unzip’ed into c:\drivers, the following command would install all drivers found into the WinPE mount point.  (The WinPE image must still be mounted, step 5, for this command to work.)  WAIK for Windows 7 includes the drivers for Hyper-V, such as the synthetic NIC.

dism /Add-Driver /Driver:c:\drivers /Recurse /ForceUnsigned /image:c:\windowspe-x86\mount

Installing other programs into WinPE is as simple as copying the binaries into the mounted WinPE image.  The program must be compiled for the target architecture (32 vs. 64).  The deployment process can be scripted using VBscript or JScript, but I think ruby is more expressive.  Download the ruby-1.9.1p378 binary for windows, and extract the contents into the mount point.  Rebuild the CD using oscdimg, and viola!


If you want to start a program when WinPE boot, simply start it from the startnet.cmd file located in \Windows\System32.

I would also recommend adding the UnxUtils because they are small and you get useful command line utilities (find and grep) in a limited WinPE environment.

It is interesting that WAIK includes an ISO creation tool – oscdimg.exe.  Unfortunately, the license is rather strict.

C:\Program Files\Windows AIK\Tools\Servicing>..\x86\oscdimg.exe ISO -help

OSCDIMG 2.55 CD-ROM and DVD-ROM Premastering Utility

Copyright (C) Microsoft, 1993-2007. All rights reserved.

Licensed only for producing Microsoft authorized content.


This is a post of me meandering through the Syslinux source code, there isn’t a real point.

Syslinux is most closely associated with Linux, but it actually supports the booting of other OS’s.  It can boot over the network (PXE), CD-ROM, and various file systems.

I am working on a project that utilizes Syslinux; the project must read and write Syslinux boot configuration files.  I need to understand the available options, and what they mean.  The best place to start is with the Syslinux documentation, and the relevant code.  (The real impetus for this project is to learn Scala.)

I was reading the parsing source code that I found in com32/menu/readconfig.c, but I could not find the code that configured the serial console.  The documentation has this to say about serial port configuration.

For the SERIAL directive to be guaranteed to work properly, it
should be the first directive in the configuration file.

Despite this statement, I could not find any code to parse the serial directive, so I started to ack.  I found the method __syslinux_get_serial_console_info(void), which seemed like a good start.  The prototype had an attribute that did not make sense to me – __constructor__.

void __constructor __syslinux_get_serial_console_info(void)
    static com32sys_t reg;
    memset(&reg, 0, sizeof reg);
    reg.eax.w[0] = 0x000b;
    __intcall(0x22, &reg, &reg);
    __syslinux_serial_console_info.iobase = reg.edx.w[0];
    __syslinux_serial_console_info.divisor = reg.ecx.w[0];
    __syslinux_serial_console_info.flowctl = reg.ebx.w[0];

I asked the oracle, and found out that this is a GCC-ism, that guarantees the function is invoked before main().  But, wait, there is even more coolness going on.  What about com32sys_ and intcall!

I went back to the oracle, and asked about interrupt 0x22.  I found out that it is typically reserved for DOS methods, so I assumed that Syslinux was hooking the interrupt to provide system calls.

After some more acking I found out the intcall function’s methods are the following. 

  1. interrupt handler to invoke
  2. register values to pass to the invoked system call; call executed is determined by the value in EAX.
  3. register results of the invoked system call

The actual system calls are setup in  The assembly code calls into C code to do the heavy lifting.  Comboot is an API to extend Syslinux, and there are several projects that take advantage of it.

Back to the code…

Scala, SBT, and IntelliJ

I started a personal project to learn Scala, and I had zero idea where to start – how do I build Hello World and then continue to scale it.  I know how to do it with make/gcc, ant/Eclipse, and VisualStudio.  From reading various Scala projects on github and it was clear that people where using some combination of sbt, maven, and IntelliJ.

I know nothing about Maven, but at first blush it is intimidating – I am sure it is my lack of knowledge.  I punted on maven.  sbt appears (stress on appears) simple, and it is written in and developers configure it by writing Scala.

The IntelliJ pick is more of an experiment to see how it compares to Eclipse.  I know not everyone thinks you should change editors.

There may be better ways to combine sbt and IntelliJ, but this one is fairly easy.  I assume sbt is already installed.

Step 1 – SBT

Create a directory to hold your project, and then create an empty project by invoking sbt.

$ mkdir test
$ cd test
$ sbt
Project does not exist, create new project? (y/N/s) y
Name: example
Organizatoin: org.example
Version [1.0]:
Scala version [2.8.1]:
sbt version [0.7.5]:
> exit

Note: SBT uses Scala version 2.7.7, but builds your project with Scala 2.8.1.

Step 2 – Build

Create a .scala file to control the building of your project, and to specify your project’s dependencies.

$ mkdir project\build
$ notepad project\build\project.scala

This file includes example dependencies for Squeryl.

import sbt._
class Project(info: ProjectInfo) extends DefaultProject(info)
      with IdeaProject {
  val mysql = "mysql" % "mysql-connector-java" % "5.1.15"
  val squeryl = "org.squeryl" % "squeryl_2.8.1" % "0.9.4-RC6"
  override def libraryDependencies = Set(
  ) ++ super.libraryDependencies

Step 3 – Plugin

Add the IntelliJ plugin to SBT.

$ mkdir project\plugins
$ notepad project\plugins\plugins.scala

Create the plugins.scala file, and add the appropriate reference.

import sbt._
class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
    val sbtIdeaRepo  = "sbt-idea-repo" at ""
    val sbtIdea = "com.github.mpeltonen" % "sbt-idea-plugin" % "0.4.0"

Step 4 – Build

Create a Hello World application to build, and put it in src/main/scala/.

object Program {
    def main(args: Array[String]): Unit = {
        println("Hello World")

Launch sbt, and fetch the dependencies. Execute the idea command to create an IntelliJ project.

$ sbt update
$ sbt idea
$ sbt run

Once the files have been created simply open the project using IntelliJ.  sbt can be executed from within IntelliJ using the idea-sbt-plugin


We switched from SVN to TFS at work a little over a year ago, and it was for the better for the most part.  There are some things that annoy me, but that’s also true when comparing SVN to hg or git.


  • TFS is very fast compared to SVN.  No need to wait for svn status, as TFS is explicitly told the files checked out for edit.
  • TFS allows the checked out edits to be temporarily put aside, and then brought back.  This is similar to git stash – TFS calls them shelvesets.
  • TFS allows an individual developer to easily create private builds.  Point TFS at a shelveset, and wait for the build output to show up.
  • The API is very easy to use.  Creating custom tooling around TFS is dead-simple.
  • All-in-one solution (good and bad) for source control, bugs, and build.


  • The world is moving towards offline distributed development, and TFS is decidedly not.  Checking a file out for edit requires connectivity with the TFS server.
  • TFS requires a lot of horsepower to run.  Our configuration involves three machines: SQL Server, SharePoint, and the App Server.
  • The omnibox has won!  I’ll tell you what I want and you figure out how to parse and retrieve the data.  Do not force me to create a query to find a bug, it’s ridiculous.
  • [minor] There are some annoying parts of the UI, such as not being able to sort a table by a specific column. 

I am not really sure how to phrase when TFS is better than SVN or not.  It sounds trite to say for Enterprise because I do not believe that to be true.  How about, if you are on the MS platform, and you want an all-in-one solution TFS is a good answer.  VS integration, source control, and the build server all work in concert with one another very well.  The bug management support is complete, albeit baroque.

Multiple WLAN’s with DD-WRT

I made a failed attempt to replace DD-WRT with OpenWRT, but unfortunately the wireless NIC’s are not supported.  When I returned to DD-WRT I decided to update to the latest recommended 24 preSP2 Build 14896 (04/23/10), and add support for multiple wireless LAN’s.  One LAN is dedicated to the devices I do not control or trust (TiVo, Wii, etc.), and the other is dedicated to my machines.

I followed the instructions on the DD-WRT wiki, and it worked great!  Per the instructions I used the Command Method to configure dnsmasq.

Page optimized by WP Minify WordPress Plugin