{"record":{"id":"c9a53e96b5af75e0","repo":"microsoft/FASTER","slug":"error-creating-log-file-for-segmentfilename-error-error-0x","errorCode":null,"errorMessage":"Error creating log file for {segmentFileName}, error: {error} 0x({Native32.MakeHRFromErrorCode(error)})","messagePattern":"Error creating log file for (.+?), error: (.+?) 0x\\((.+?)\\)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"cs/src/core/Device/LocalStorageDevice.cs","lineNumber":433,"sourceCode":"                // FILE_SHARE_DELETE allows multiple FASTER instances to share a single log directory and each can specify deleteOnClose.\n                // This will allow the files to persist until all handles across all instances have been closed.\n                fileShare |= Native32.FILE_SHARE_DELETE;\n            }\n\n            string segmentFileName = GetSegmentFilename(fileName, segmentId, omitSegmentId);\n            var logHandle = Native32.CreateFileW(\n                segmentFileName,\n                fileAccess, fileShare,\n                IntPtr.Zero, fileCreation,\n                fileFlags, IntPtr.Zero);\n\n            if (logHandle.IsInvalid)\n            {\n                var error = Marshal.GetLastWin32Error();\n                var message = $\"Error creating log file for {segmentFileName}, error: {error} 0x({Native32.MakeHRFromErrorCode(error)})\";\n                if (error == Native32.ERROR_PATH_NOT_FOUND)\n                    message += $\" (Path not found; name length = {segmentFileName.Length}, MAX_PATH = {Native32.WIN32_MAX_PATH}\";\n                throw new IOException(message);\n            }\n\n            if (preallocateFile && segmentSize != -1)\n                SetFileSize(fileName, logHandle, segmentSize);\n\n            if (ioCompletionPort != IntPtr.Zero)\n            {\n                ThreadPool.GetMaxThreads(out int workerThreads, out _);\n                Native32.CreateIoCompletionPort(logHandle, ioCompletionPort, (UIntPtr)(long)logHandle.DangerousGetHandle(), (uint)(workerThreads + NumCompletionThreads));\n            }\n            else\n            {\n                try\n                {\n                    ThreadPool.BindHandle(logHandle);\n                }\n                catch (Exception e)\n                {","sourceCodeStart":415,"sourceCodeEnd":451,"githubUrl":"https://github.com/microsoft/FASTER/blob/321d872eabda6a0345c8bd76419f89723ed864ae/cs/src/core/Device/LocalStorageDevice.cs#L415-L451","documentation":"CreateHandle opens a segment file with CreateFile; if the returned handle is invalid, it builds a message with the Win32 error code and its HRESULT form and throws IOException. A PATH_NOT_FOUND error appends the filename length and MAX_PATH for diagnosis.","triggerScenarios":"Opening/creating a segment file where the directory does not exist (ERROR_PATH_NOT_FOUND), access is denied, path is too long, the disk is unavailable, or the path is malformed.","commonSituations":"Checkpoint/log directory not created before initializing the device; network drive unavailable; permissions issues under service accounts; path length overflow on Windows.","solutions":["Create the target directory (Directory.CreateDirectory) before initializing the device.","If the message says 'Path not found', compare name length against MAX_PATH and shorten the path.","Check ACLs / run the process under an account with write access to the segment directory.","Verify the drive/volume is mounted and the path uses valid characters."],"exampleFix":"// before\nvar device = new LocalStorageDevice(@\"D:\\faster\\hlog\\seg-0\", ...); // D:\\faster\\hlog does not exist\n// after\nDirectory.CreateDirectory(@\"D:\\faster\\hlog\");\nvar device = new LocalStorageDevice(@\"D:\\faster\\hlog\\seg-0\", ...);","handlingStrategy":"validation","validationCode":"Directory.CreateDirectory(Path.GetDirectoryName(fullSegmentPath));\nif (fullSegmentPath.Length > 260) throw new ArgumentException(\"Path exceeds MAX_PATH\");","typeGuard":null,"tryCatchPattern":"try { device.Initialize(...); } catch (IOException e) when (e.Message.Contains(\"Error creating log file\")) { log.LogError(e, \"Cannot create segment file; check directory and ACLs\"); }","preventionTips":["Always create the checkpoint/log directory before device initialization.","Run the service under an account with write access to the segment directory.","Verify network drives are mounted before startup."],"tags":["io","windows","file-create","storage-device","filesystem"],"backgroundTag":"file-open-failed","analyzedSha":"321d872eabda6a0345c8bd76419f89723ed864ae","analyzedAt":"2026-09-15T22:18:00.693Z","contentChangedAt":"2026-09-15T22:18:00.693Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}