From 43f7ab85737327c3f13ace230f8eba0cf0414441 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Mon, 25 May 2015 06:07:50 +0200
Subject: wineboot: Assign a drive serial number during prefix creation/update.

---
 programs/wineboot/wineboot.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/programs/wineboot/wineboot.c b/programs/wineboot/wineboot.c
index 4d70ea9..dbabfe4 100644
--- a/programs/wineboot/wineboot.c
+++ b/programs/wineboot/wineboot.c
@@ -81,6 +81,7 @@
 #include <shobjidl.h>
 #include <shlwapi.h>
 #include <shellapi.h>
+#include <ntsecapi.h>
 #include "resource.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(wineboot);
@@ -165,6 +166,36 @@ static DWORD set_reg_value( HKEY hkey, const WCHAR *name, const WCHAR *value )
     return RegSetValueExW( hkey, name, 0, REG_SZ, (const BYTE *)value, (strlenW(value) + 1) * sizeof(WCHAR) );
 }
 
+/* set a serial number for the disk containing windows */
+static void create_disk_serial_number(void)
+{
+    static const  WCHAR filename[] = {'\\','.','w','i','n','d','o','w','s','-','s','e','r','i','a','l',0};
+    DWORD serial, written;
+    WCHAR path[MAX_PATH];
+    char buffer[16];
+    HANDLE file;
+
+    if (GetSystemDirectoryW( path, sizeof(path)/sizeof(path[0]) ) && path[1] == ':')
+    {
+        path[2] = 0;
+        strcatW( path, filename );
+        if (!PathFileExistsW( path ) && RtlGenRandom( &serial, sizeof(serial) ))
+        {
+            WINE_TRACE( "Putting serial number of %08X into file %s\n", serial, wine_dbgstr_w(path) );
+            file = CreateFileW( path, GENERIC_WRITE, FILE_SHARE_READ, NULL,
+                                CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL );
+            if (file == INVALID_HANDLE_VALUE)
+                WINE_ERR( "wine: failed to create %s.\n", wine_dbgstr_w(path) );
+            else
+            {
+                sprintf( buffer, "%X\n", serial );
+                WriteFile( file, buffer, strlen(buffer), &written, NULL );
+                CloseHandle( file );
+            }
+        }
+    }
+}
+
 /* create the volatile hardware registry keys */
 static void create_hardware_registry_keys(void)
 {
@@ -1233,6 +1264,7 @@ int main( int argc, char *argv[] )
 
     ResetEvent( event );  /* in case this is a restart */
 
+    create_disk_serial_number();
     create_hardware_registry_keys();
     create_dynamic_registry_keys();
     create_environment_registry_keys();
-- 
2.4.0