{"record":{"id":"a1393696aaac640b","repo":"EllanJiang/GameFramework","slug":"max-file-count-can-not-larger-than-max-block-count","errorCode":null,"errorMessage":"Max file count can not larger than max block count.","messagePattern":"Max file count can not larger than max block count\\.","errorType":"validation","errorClass":"GameFrameworkException","httpStatus":null,"severity":"error","filePath":"GameFramework/FileSystem/FileSystem.cs","lineNumber":153,"sourceCode":"        /// <param name=\"stream\">要创建的文件系统的文件系统流。</param>\n        /// <param name=\"maxFileCount\">要创建的文件系统的最大文件数量。</param>\n        /// <param name=\"maxBlockCount\">要创建的文件系统的最大块数据数量。</param>\n        /// <returns>创建的文件系统。</returns>\n        public static FileSystem Create(string fullPath, FileSystemAccess access, FileSystemStream stream, int maxFileCount, int maxBlockCount)\n        {\n            if (maxFileCount <= 0)\n            {\n                throw new GameFrameworkException(\"Max file count is invalid.\");\n            }\n\n            if (maxBlockCount <= 0)\n            {\n                throw new GameFrameworkException(\"Max block count is invalid.\");\n            }\n\n            if (maxFileCount > maxBlockCount)\n            {\n                throw new GameFrameworkException(\"Max file count can not larger than max block count.\");\n            }\n\n            FileSystem fileSystem = new FileSystem(fullPath, access, stream);\n            fileSystem.m_HeaderData = new HeaderData(maxFileCount, maxBlockCount);\n            CalcOffsets(fileSystem);\n            Utility.Marshal.StructureToBytes(fileSystem.m_HeaderData, HeaderDataSize, s_CachedBytes);\n\n            try\n            {\n                stream.Write(s_CachedBytes, 0, HeaderDataSize);\n                stream.SetLength(fileSystem.m_FileDataOffset);\n                return fileSystem;\n            }\n            catch\n            {\n                fileSystem.Shutdown();\n                return null;\n            }","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/EllanJiang/GameFramework/blob/d0c010b05167c58e92350449d04864a91ca13fd2/GameFramework/FileSystem/FileSystem.cs#L135-L171","documentation":"Each file entry consumes at least one block, so the filesystem cannot support more files than blocks. FileSystem.Create enforces maxFileCount <= maxBlockCount and throws when this invariant is violated.","triggerScenarios":"Calling FileSystem.Create with maxFileCount > maxBlockCount — e.g. Create(path, access, stream, 100, 50).","commonSituations":"Independent config values for files and blocks tuned separately without a cross-check; users lowering block count to save space without realizing each file needs a block; reordered arguments putting the block count in the file count slot.","solutions":["Set maxBlockCount >= maxFileCount when calling Create","Add a cross-field validation to your settings loader that clamps or rejects file count > block count","If fewer blocks are desired, reduce maxFileCount proportionally — one block per file is the minimum","Re-check parameter order in the Create call"],"exampleFix":"// before\nvar fs = FileSystem.Create(path, access, stream, maxFileCount: 100, maxBlockCount: 50);\n// after\nint maxBlockCount = Math.Max(50, 100); // blocks >= files\nvar fs = FileSystem.Create(path, access, stream, 100, maxBlockCount);","handlingStrategy":"validation","validationCode":"if (maxFileCount > maxBlockCount) throw new ArgumentException(\"maxBlockCount must be >= maxFileCount\");\nFileSystem.Create(fullPath, access, stream, maxFileCount, maxBlockCount);","typeGuard":"bool AreValidCapacities(int files, int blocks) => files > 0 && blocks > 0 && blocks >= files;","tryCatchPattern":"try { var fs = FileSystem.Create(path, access, stream, fc, bc); }\ncatch (GameFrameworkException ex) when (ex.Message.Contains(\"can not larger than max block count\")) { Log.Error($\"files={fc} blocks={bc}: each file needs at least one block\"); }","preventionTips":["Cross-validate file and block counts together in settings loaders","Clamp maxBlockCount = Math.Max(maxBlockCount, maxFileCount)","Document in config that every file consumes at least one block"],"tags":["gameframework","filesystem","conflicting-options"],"backgroundTag":"conflicting-config-options","analyzedSha":"d0c010b05167c58e92350449d04864a91ca13fd2","analyzedAt":"2026-09-15T13:37:15.352Z","contentChangedAt":"2026-09-15T13:37:15.352Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}