2 this creates a save2dsk.bin hibernation file for phoenix netbios
3 laptops. I tested it on my IBM Thinkpad T20 but it should work on
6 Copyright 2002 Andrew Tridgell <tridge@samba.org>
7 released under the GNU General Public License version 2 or later
11 This program was inspired by lphdisk which was written by Patrick
12 Ashmore and Alex Stewart. The main difference is that tphdisk
13 doesn't muck about with partition tables, which makes it easy to use
14 it for either a hibernation partition or a save2dsk.bin file.
21 typedef unsigned short u16;
27 static void x_write(int fd, void *data, size_t size)
29 if (write(fd, data, size) != (ssize_t)size) {
30 fprintf(stderr,"Write failed!\n");
36 the main function. The 'size' is in sectors (512 byte units)
38 this writes a save2dsk.bin file to the given file descriptor
40 static void write_phdisk(int fd, u32 size)
42 unsigned char sector[512];
46 memset(sector, 0, 512);
48 /* form the header - this is x86 byte order dependent, but who
49 has a non-intel lapptop with a phoenix notebios? */
50 strcpy(sector, "TimO");
52 *(u32 *)§or[16] = size;
53 for (checksum=0, i=8;i<512;i+=2) {
54 checksum += *(u16 *)(§or[i]);
56 *(u16 *)§or[6] = ~checksum;
58 /* write two copies of the header */
59 x_write(fd, sector, 512);
60 x_write(fd, sector, 512);
62 /* rest is filled with 0x50 */
63 memset(sector, 0x50, 512);
65 for (i=2;i<size;i++) {
66 x_write(fd, sector, 512);
71 int main(int argc, char *argv[])
77 Usage: tphdisk <size in MB>
79 written by Andrew Tridgell <tridge@samba.org>
82 This program writes a 'save2dsk.bin' hibernation file to stdout. To
83 use it you should do something like this:
85 1) create a type 16 (Hidden FAT16) partition on your laptop
86 2) format the partition with 'mkdosfs'
87 3) mount the partition as VFAT
88 4) create the 'save2dsk.bin' file on the partition using something like
89 tphdisk 280 > save2dsk.bin
92 The only parameter is the size in megabytes of the save file. This
93 needs to be at least as big as your main memory + video memory, but you
94 can make it larger if you want to.
99 size = atoi(argv[1]) * 1024 * 2;
101 write_phdisk(1, size);