winiso_unix.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //go:build linux
  15. // +build linux
  16. package isoutils
  17. import (
  18. "fmt"
  19. "github.com/Microsoft/go-winio/wim"
  20. "yunion.io/x/log"
  21. "yunion.io/x/pkg/util/imagetools"
  22. )
  23. // ========== 7. 保留Windows版本识别函数(适配新结构) ==========
  24. func DetectWindowsEdition(r *ISOFileReader) (*ISOInfo, error) {
  25. wimFile, err := r.GetFile("sources/install.wim")
  26. if err != nil {
  27. return nil, err
  28. }
  29. wim, err := wim.NewReader(wimFile.NewReader())
  30. if err != nil {
  31. return nil, err
  32. }
  33. result := &ISOInfo{}
  34. for _, image := range wim.Image {
  35. version := fmt.Sprintf("%d.%d.%d", image.Windows.Version.Major, image.Windows.Version.Minor, image.Windows.Version.Build)
  36. if image.Windows != nil {
  37. if image.Windows.Arch == 9 {
  38. result.Arch = "x86_64"
  39. } else if image.Windows.Arch == 12 {
  40. result.Arch = "arm64"
  41. } else if image.Windows.Arch == 0 {
  42. result.Arch = "x86"
  43. }
  44. result.Distro = imagetools.OS_DIST_WINDOWS
  45. result.Language = image.Windows.DefaultLanguage
  46. switch fmt.Sprintf("%d.%d", image.Windows.Version.Major, image.Windows.Version.Minor) {
  47. case "6.0":
  48. result.Version = "Windows Vista"
  49. case "6.1":
  50. result.Version = "Windows 7"
  51. case "6.2":
  52. result.Version = "Windows 8"
  53. case "6.3":
  54. result.Version = "Windows 8.1"
  55. case "10.0":
  56. if image.Windows.Version.Build >= 27500 {
  57. result.Version = "Windows 12"
  58. } else if image.Windows.Version.Build >= 22000 {
  59. result.Version = "Windows 11"
  60. } else {
  61. result.Version = "Windows 10"
  62. }
  63. }
  64. if image.Windows.ProductType == "ServerNT" {
  65. result.Distro = imagetools.OS_DIST_WINDOWS_SERVER
  66. switch fmt.Sprintf("%d.%d", image.Windows.Version.Major, image.Windows.Version.Minor) {
  67. case "6.0":
  68. result.Version = "Windows Server 2008"
  69. case "6.1":
  70. result.Version = "Windows Server 2008 R2"
  71. case "6.2":
  72. result.Version = "Windows Server 2012"
  73. case "6.3":
  74. result.Version = "Windows Server 2012 R2"
  75. case "10.0":
  76. if image.Windows.Version.Build >= 26040 {
  77. result.Version = "Windows Server 2025"
  78. } else if image.Windows.Version.Build >= 20348 {
  79. result.Version = "Windows Server 2022"
  80. } else if image.Windows.Version.Build >= 17763 {
  81. result.Version = "Windows Server 2019"
  82. } else if image.Windows.Version.Build >= 14393 {
  83. result.Version = "Windows Server 2016"
  84. }
  85. }
  86. }
  87. log.Debugf("识别到 %s 版本: %s -> %s", result.Distro, version, result.Version)
  88. break
  89. }
  90. }
  91. return result, nil
  92. }