Skip to content

Commit 08bacea

Browse files
committed
fix: windows syscall error
1 parent 9ec17a4 commit 08bacea

File tree

3 files changed

+62
-20
lines changed

3 files changed

+62
-20
lines changed

blockdevice_unix.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
2+
// SPDX-License-Identifier: GPL-3.0-or-later
3+
//
4+
// This file is part of go-gameid.
5+
//
6+
// go-gameid is free software: you can redistribute it and/or modify
7+
// it under the terms of the GNU General Public License as published by
8+
// the Free Software Foundation, either version 3 of the License, or
9+
// (at your option) any later version.
10+
//
11+
// go-gameid is distributed in the hope that it will be useful,
12+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
// GNU General Public License for more details.
15+
//
16+
// You should have received a copy of the GNU General Public License
17+
// along with go-gameid. If not, see <https://www.gnu.org/licenses/>.
18+
19+
//go:build unix
20+
21+
package gameid
22+
23+
import (
24+
"os"
25+
"strings"
26+
"syscall"
27+
)
28+
29+
// isBlockDevice checks if the given path is a block device (e.g., /dev/sr0).
30+
func isBlockDevice(path string) bool {
31+
// On Unix, block devices are typically in /dev/
32+
if !strings.HasPrefix(path, "/dev/") {
33+
return false
34+
}
35+
info, err := os.Stat(path)
36+
if err != nil {
37+
return false
38+
}
39+
// Check if it's a block device using syscall
40+
stat, ok := info.Sys().(*syscall.Stat_t)
41+
if !ok {
42+
return false
43+
}
44+
// S_IFBLK = block device (0x6000 = 0o60000)
45+
return stat.Mode&syscall.S_IFMT == syscall.S_IFBLK
46+
}

blockdevice_windows.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) 2025 Niema Moshiri and The Zaparoo Project.
2+
// SPDX-License-Identifier: GPL-3.0-or-later
3+
4+
//go:build windows
5+
6+
package gameid
7+
8+
// isBlockDevice checks if the given path is a block device.
9+
// On Windows, block devices (like CD/DVD drives) are accessed differently,
10+
// typically via drive letters (e.g., D:\) rather than /dev/ paths.
11+
// This function returns false on Windows as the /dev/ path check doesn't apply.
12+
func isBlockDevice(_ string) bool {
13+
// Windows doesn't use /dev/ paths for block devices
14+
// Physical drives are accessed via \\.\PhysicalDriveN or drive letters
15+
return false
16+
}

gameid.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"fmt"
2626
"os"
2727
"strings"
28-
"syscall"
2928

3029
"github.com/ZaparooProject/go-gameid/identifier"
3130
)
@@ -261,25 +260,6 @@ func IsCartridgeBased(console Console) bool {
261260
return !IsDiscBased(console)
262261
}
263262

264-
// isBlockDevice checks if the given path is a block device (e.g., /dev/sr0).
265-
func isBlockDevice(path string) bool {
266-
// On Linux, block devices are typically in /dev/
267-
if !strings.HasPrefix(path, "/dev/") {
268-
return false
269-
}
270-
info, err := os.Stat(path)
271-
if err != nil {
272-
return false
273-
}
274-
// Check if it's a block device using syscall
275-
stat, ok := info.Sys().(*syscall.Stat_t)
276-
if !ok {
277-
return false
278-
}
279-
// S_IFBLK = block device (0x6000 = 0o60000)
280-
return stat.Mode&syscall.S_IFMT == syscall.S_IFBLK
281-
}
282-
283263
// identifyFromBlockDevice identifies a game from a physical disc (block device).
284264
//
285265
//nolint:revive // Line length acceptable for function signature with ignored parameter

0 commit comments

Comments
 (0)