source: box/trunk/docs/api-notes/windows_porting.txt @ 2478

Revision 2478, 6.6 KB checked in by chris, 3 years ago (diff)

Rearrangement of api-notes directory.

  • Property svn:eol-style set to native
Line 
1TITLE Notes on porting the backup client to Windows
2
3It should be relatively easy to port the backup client (bbackupd) to Windows. However, the server relies on unlink() behaviour of the UNIX filesystem which is different on the Windows platform, so it will not be so easy to port.
4
5An installation of perl is required to build the system. The ActiveState port is the easiest to install.
6
7
8SUBTITLE Build environment
9
10The build environment generation script, makebuildenv.pl, uses perl to scan all the files and generate makefiles. It's rather orientated towards UNIX systems with gcc.
11
12Probably the easiest way to handle this is to detect the Windows platform, set up a few variables appropriately (in BoxPlatform.pm) and then post-process the generated Makefiles to mould them into something more handy for the MS Windows compiler and toolchain.
13
14The script itself is a bit messy. It was fine at first, but then the multi-platform thing got in the way. I do intend to rewrite it at some point in the future.
15
16Make sure your new version defines PLATFORM_WIN32 on the compile line.
17
18All files #include "Box.h" as the first include file. Use this for pre-compiled headers. Edit BoxPlatform.h to include the Windows headers required, and include a PLATFORM_WIN32 section. The easiest start will be to leave this blank, apart from typedefs for the basic types and any "not supported" #defines you can find.
19
20Boring bits of the code, such as exceptions and protocol definitions, are autogenerated using perl scripts. This code should be portable without modification.
21
22I have tried to avoid the things I know won't work with the MS compiler, so hopefully the code will be fairly clean. However, it might be a little easier to use the MinGW compiler [ http://www.mingw.org/ ] just to be consistent with the UNIX version. But I hope this won't be necessary.
23
24You'll need the latest version of OpenSSL. This was slightly difficult to get to compile last time I tried -- especially if you're determined to use the optimised assembler version. The main difficulty was getting a version which would link properly with the options used in my project, the default libraries selected got in the way.
25
26
27SUBTITLE Porting as UNIX emulation
28
29Since the daemon uses so few UNIX system calls and with a limited set of options, it seems to make sense to port it by writing emulations of these functions. It's probably nicest to create a lib/win32 directory, and populate this with header files corresponding to the UNIX header files used. These just contain inline functions which map the UNIX calls to Win32 calls.
30
31File/socket handles may have to be translated. -1 is used as a failure return value and by the code internally to mark an invalid socket handle. (0 is a valid socket handle)
32
33Of course, some bits of code aren't relevant, so will just be #ifdefed out, or replaced. But this should be minimal. (Only perhaps the small bit relating to filesystem structure -- there aren't really mount points as such.)
34
35
36SUBTITLE File tracking
37
38The daemon uses the inode number of a file to keep track of files and directories, so when they're renamed they can be moved efficiently on the store. Some unique (per filesystem) number will have to be found and used instead.
39
40It uses the Berkeley DB to store these on disc. It's likely another storage system will need to be used. (It just has to map the file's unique number into to a 8 byte struct.)
41
42There is a in-memory implementation for platforms which don't support Berkeley DB, but this isn't so good when the daemon has to be restarted as all the tracking is lost. But it's an easy start.
43
44
45SUBTITLE Expected filesystem behaviour
46
47File and directories have (at least) two modification times, for contents and attributes.
48
49For files, the contents modification time must change when the contents change, and the attributes time when the attributes change (and may change when the contents change too.)
50
51For directories, the contents modification time must change when files or directories are deleted or added. If it changes any more frequently than this, then the client will be slightly less efficient -- it will download the store's directory listing whenever this time changes. The attributes modification time is less important, as the actual attributes are compared and only uploaded if different.
52
53
54SUBTITLE Attributes
55
56Attributes means file modification times, flags, and filesystem permissions.
57
58The BackupClientFileAttribute class will need to be extended. Allocate another "attribute type" for the Win32 attributes, and then serialise it in a compatible way -- put your new attribute type in the header, and then a serialised network byte order structure in the rest. The different size of block is handled for you, and the server never looks inside.
59
60Add code so that under UNIX, Win32 attributes are ignored, and UNIX attributes under Win32.
61
62It's probably not necessary to worry too much about these for the first version. Not many people seem to use these attributes anyway.
63
64
65SUBTITLE Times
66
67The system uses it's own 64 bit time type -- see BoxTime.h. Everything is translated to this from the various different system time types, and calculated and stored internally in this form.
68
69
70SUBTITLE Daemon as a Service
71
72The client is derived from the Daemon class, which implements a daemon. The interface is simple, and it shouldn't be hard to write a compatible class which implements a Windows Service instead.
73
74Or cheat and run it as a Win32 application.
75
76Note that the daemon expects to be able to read every file it wants, and will abort a scan and upload run if it gets an error. The daemon must therefore be run with sufficient privileges. It runs as root under UNIX.
77
78
79SUBTITLE Command Socket
80
81The backup daemon accepts commands from bbackupctl through a UNIX domain socket. When a connection is made, the user ID of the connecting process is checked to see if it's the same user ID as the daemon is running under.
82
83This may not have any exact analogue under Win32, so another communications scheme may have to be devised.
84
85This is only actually necessary if the client is to be run in snapshot mode. It can be safely left unimplemented if snapshot mode is not required, or the prompts for it to sync with the server are implemented some other way.
86
87
88SUBTITLE NTFS streams
89
90If you want to back up NTFS streams, then a generic solution should probably be defined, so that the Mac OS X resource forks can be backed up with the same mechanism.
91
92
93SUBTITLE Source code
94
95I work on a slightly different version of the source files. A make distribution script adds the license header and removes private sections of code. This means submitted diffs need a slight bit of translation.
96
97
98
99
100
Note: See TracBrowser for help on using the repository browser.