Compare commits

...

183 Commits

Author SHA1 Message Date
Carter Li d0d9831d41 Merge pull request #686 from fastfetch-cli/dev
Release v2.6.0
2024-01-17 15:20:56 +08:00
李通洲 b3945e277c Global: review code 2024-01-17 15:06:52 +08:00
李通洲 9f77851176 JsonSchema: make it a valid json document 2024-01-17 14:08:31 +08:00
李通洲 963eaa5395 Release: v2.6.0 2024-01-17 14:02:07 +08:00
李通洲 07dfe57386 Doc: update changelog 2024-01-17 14:00:55 +08:00
Carter Li a3c0085e2b Sound: tidy 2024-01-17 13:31:34 +08:00
Carter Li c8f28e4c79 Sound (FreeBSD): don't use mixer.h
It's only supported in FreeBSD 14 and later
2024-01-17 10:22:56 +08:00
Carter Li 861eea5899 Sound (FreeBSD): new impl; drop pulseaudio dep 2024-01-16 17:40:41 +08:00
李通洲 1227799a38 Vulkan: print platformApi in JSON format 2024-01-15 18:14:40 +08:00
李通洲 35d1497053 Doc: update changelog 2024-01-15 15:48:39 +08:00
李通洲 ea3734f004 Locale (Windows): fix typo 2024-01-15 15:48:32 +08:00
李通洲 5d35dade60 DisplayServer (Windows): don't detect unknown display type as external 2024-01-15 15:22:33 +08:00
李通洲 0c844fc342 FFstrbuf: don't crash with ffStrbufInitStatic(&buf, NULL) 2024-01-15 15:22:33 +08:00
李通洲 c1ed0a4e91 Locale (Windows): print standard format 2024-01-15 15:22:33 +08:00
李通洲 e1af6fc0fe Locale: display only LC_MESSAGES if available, which is used by gettext 2024-01-15 14:27:29 +08:00
李通洲 c1d41a36bb CMake: fix build in macOS with -DENABLE_SYSTEM_YYJSON 2024-01-15 14:21:23 +08:00
李通洲 958bde228b Doc: fix typo 2024-01-15 13:30:18 +08:00
李通洲 6655c446ba Revert "Image: silence compiler warnings"
This reverts commit afa0a7dac8.
2024-01-15 13:15:43 +08:00
李通洲 43657e8fd6 Doc: update changelog 2024-01-15 11:29:29 +08:00
李通洲 38f216291e CMake: use system <yyjson.h> in fastfetch.c and flashfetch.c too
Fix #684
2024-01-15 11:22:42 +08:00
Carter Li 01de158bba Vulkan: print instance version if no vulkan drivers found 2024-01-15 10:33:55 +08:00
李通洲 5a34b8d01f Vulkan: error out if no results detected 2024-01-15 09:39:03 +08:00
李通洲 afa0a7dac8 Image: silence compiler warnings 2024-01-15 09:13:14 +08:00
李通洲 974ee2ab0d TerminalShell: fix wezterm name pretty printing 2024-01-14 17:26:54 +08:00
李通洲 ab1e3db665 Shell (Linux): detect ash version 2024-01-13 23:39:17 +08:00
李通洲 95b64622c4 Terminal (Linux): fix detection 2024-01-13 23:39:17 +08:00
李通洲 d3c7529c45 Processing (Windows): don't use CreateEventW 2024-01-13 13:38:53 +08:00
李通洲 89db425a03 Gamepad (Windows): use nonblocking read to get battery information 2024-01-13 13:33:29 +08:00
apocelipes 269ad36df5 refactor(TerminalShell): changing recursion into loops 2024-01-12 23:56:04 +08:00
李通洲 22cdb1247f TerminalShell: tidy; use case senstive string comparation where meaningful 2024-01-12 21:21:42 +08:00
李通洲 905ed76ddd TerminalShell: split terminal and shell detection code further 2024-01-12 20:58:45 +08:00
李通洲 6da57d64c3 TerminalShell: split terminal detection and shell detection 2024-01-12 16:44:19 +08:00
李通洲 37e0a7b03f stringUtils: tidy 2024-01-11 16:27:53 +08:00
李通洲 0c65cdc1f5 GPU (macOS): detect memory usage 2024-01-11 10:11:50 +08:00
李通洲 653e689f18 GPU (macOS): tidy 2024-01-11 09:55:13 +08:00
李通洲 a8aaf605b1 Doc: update changelog 2024-01-10 19:04:47 +08:00
李通洲 5f638a67ed Battery: rename manufacturerDate to manufactureDate 2024-01-10 19:03:58 +08:00
李通洲 0645f559af Monitor: detect serial number and manufacture date 2024-01-10 19:01:54 +08:00
李通洲 f5a57ab747 Doc: update changelog 2024-01-10 14:48:47 +08:00
李通洲 92e05f7e38 Chassis: don't print useless version 2024-01-10 14:44:14 +08:00
李通洲 8ba031b761 Brightness (FreeBSD): don't print empty () 2024-01-10 14:22:56 +08:00
李通洲 fdb68669f4 Battery (macOS): support manufacture date detection 2024-01-10 13:26:54 +08:00
李通洲 12155e029b Battery (Linux): support manufacture date detection 2024-01-09 23:08:19 +08:00
李通洲 7926b74917 Battery: detect manufacturer date 2024-01-09 22:58:32 +08:00
Carter Li 61af59fc00 Battery (Linux): fix temperature detection 2024-01-09 16:34:04 +08:00
李通洲 bc52613410 Gamepad: rename identifier to serial number 2024-01-09 15:53:42 +08:00
李通洲 f84bb1ebe2 Smbios: silence compiler warnings 2024-01-09 15:46:19 +08:00
李通洲 a160bc8de5 Gamepad (macOS): detect manufacturer 2024-01-09 15:28:03 +08:00
Carter Li cb599c6f2a Display (FreeBSD): support resolution detection in console 2024-01-08 16:03:07 +08:00
Carter Li 5693700c16 Bios (FreeBSD): fix boot type detection on some weird platforms 2024-01-08 16:02:52 +08:00
Carter Li e8c067ff3d Wifi (Linux): don't print invalid information 2024-01-08 11:32:39 +08:00
Carter Li 80cc4e3f4a Host (Linux): detect serial number for Asahi Linux 2024-01-08 11:19:35 +08:00
李通洲 8e78fadbeb Gamepad: don't provide device names of XBox compatible controllers 2024-01-08 10:38:40 +08:00
李通洲 1215eb06ca Gamepad (Windows): support battery detection of NS Pro 2024-01-07 19:07:15 +08:00
李通洲 2aa899d83c Gamepad (Linux): support battery level detection of NS Pro controller 2024-01-07 17:59:50 +08:00
李通洲 cf096eb101 Gamepad (Windows): detect serial number and battery (PS4 controller) 2024-01-06 23:43:35 +08:00
李通洲 5b4a26393d Gamepad (Linux): detect battery capacity 2024-01-06 20:40:20 +08:00
李通洲 2ba878cbab Monitor (Linux): fix detection with Nvidia drivers
NVIDIA DRM driver reports `enabled` to be `disabled`
2024-01-06 19:12:36 +08:00
李通洲 0af40ab6a3 Settings (FreeBSD): don't append trailing \0 2024-01-06 18:47:16 +08:00
李通洲 b9777bec77 Chassis: detect serial number 2024-01-06 18:35:10 +08:00
李通洲 8801921d02 Smbios: trim spaces 2024-01-06 18:33:57 +08:00
李通洲 c0c32456e8 Board: detect serial number 2024-01-06 18:12:51 +08:00
李通洲 640fa146c1 CPU (Windows): only use smbios to detect maximum speed
Because some virtual machines report invalid information
2024-01-06 18:00:59 +08:00
李通洲 de91429e1a CI: fix build 2024-01-06 17:11:39 +08:00
李通洲 1621484c96 CPU (Windows): don't report 30GHz in VMware 2024-01-06 17:11:26 +08:00
李通洲 d8297d296e CPU (Windows): use ThreadCount if GetLogicalProcessorInformationEx() fails 2024-01-06 17:11:26 +08:00
李通洲 48bb82c8fb Board (Windows): use SMBIOS result 2024-01-06 17:11:26 +08:00
李通洲 c1c7f7b93f Bios (Windows): use SMBIOS result 2024-01-06 17:11:26 +08:00
李通洲 1d35811253 Windows: make SMBIOS data a singleton 2024-01-06 17:11:26 +08:00
李通洲 fe0b43d92d CPU (Windows): detect the actual maximum frequency 2024-01-06 17:11:26 +08:00
李通洲 446fe907d2 Smbios: add comments, tidy 2024-01-06 17:11:26 +08:00
李通洲 d578f1006c Host / Chassis (Windows): remove options --*-use-wmi 2024-01-06 17:11:26 +08:00
李通洲 33f3199383 Host / Chassis (Windows): parse SMBIOS data directly 2024-01-06 17:11:25 +08:00
李通洲 21f3875c4f Host (Windows): detect serial number and UUID 2024-01-06 17:11:25 +08:00
李通洲 6bcd75835e Host: rename properties 2024-01-05 20:38:29 +08:00
李通洲 24cec76251 Host (Linux): detect serial number and uuid 2024-01-05 16:33:52 +08:00
李通洲 f8ac56691f Host (FreeBSD): detect serial number and uuid 2024-01-05 16:32:34 +08:00
李通洲 810112cb26 Host (macOS): detect serial number and uuid 2024-01-05 16:29:38 +08:00
李通洲 2340c2afd7 Board (macOS): print internal name instead of model indentifier
and actually detect the vendor
2024-01-05 16:24:43 +08:00
李通洲 b6c8649cbf macOS: improve IO service related code generally 2024-01-05 15:00:50 +08:00
李通洲 92a6b01133 Brightness (Apple): code optimise and fix mem leaks 2024-01-05 13:20:47 +08:00
李通洲 396112e8ea PowerAdapter: simplify implementation and support serial number detection 2024-01-05 11:01:32 +08:00
李通洲 5eacd0bb8e Battery (Apple): use less hard coded strings 2024-01-05 11:01:32 +08:00
李通洲 ea3ea196aa Battery (Linux): simplify temp detection 2024-01-05 11:01:32 +08:00
李通洲 0e6be69eb8 GPU (Linux): try detect GPU type 2024-01-04 18:50:38 +08:00
李通洲 d69e19377e Doc: update changelog 2024-01-04 16:31:41 +08:00
李通洲 f4f466d4ba Battery: print serial number 2024-01-04 16:21:19 +08:00
李通洲 10b2fe13bd Battery (Windows): detect serial number 2024-01-04 16:20:48 +08:00
李通洲 b5dc4f59f1 Battery (macOS): detect serial number 2024-01-04 16:04:34 +08:00
李通洲 7c0b743c61 Merge remote-tracking branch 'origin/master' into dev 2024-01-04 15:33:16 +08:00
李通洲 6bd909c89d Doc: update changelog 2024-01-04 15:27:31 +08:00
李通洲 1fef41241a Presets: fix formatation 2024-01-04 15:27:31 +08:00
Carter Li 5c75e271ef PowerAdapter (Linux): add support 2024-01-04 15:16:51 +08:00
Carter Li b6b1993f62 Battery (Linux): code refactor, support serial number detection 2024-01-04 15:16:51 +08:00
Carter Li cd0109c382 Battery (Linux): remove option --battery-dir
It was added in c5c3cecb93 but there was no comment or issues linked to indicate why it was necessary.

`/sys/class/power_supply` is standardized in <https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-power>. I don't I want to support non-standard platform unless proper reason is given
2024-01-04 14:18:33 +08:00
Carter Li 6698283430 GPU: fix vendor detection for asahi 2024-01-04 10:29:02 +08:00
李通洲 83ce3e4554 Wallpaper (macOS): support Sonoma 2024-01-03 10:15:56 +08:00
李通洲 ff0f91dc3c macOS: fix mem leaks 2024-01-03 10:12:48 +08:00
李通洲 ab028964bf GPU (WSL): add missing FF_USE_PROPRIETARY_GPU_DRIVER_API macro guards 2024-01-02 18:47:06 +08:00
李通洲 21353b8256 CMake (GPU): change ENABLE_NVIDIA_GPU to ENABLE_PROPRIETARY_GPU_DRIVER_API 2024-01-02 10:49:03 +08:00
Viorel 0a1de91a29 Add option for NVIDIA GPU support 2024-01-01 22:18:03 +08:00
Carter Li b80da99fac Merge pull request #677 from fastfetch-cli/dev
Release: v2.5.0
2024-01-01 11:52:51 +08:00
李通洲 a95a80aa93 README: remove invalid info 2024-01-01 10:50:04 +08:00
AlbydS 553338b2bc Add more Linux distributions to installation guide
I added Alpine Linux, NixOS and openSUSE to the installation guide.
2024-01-01 10:29:57 +08:00
李通洲 a56c092a78 Release: v2.5.0
Happy new year!
2023-12-31 18:44:32 +08:00
李通洲 3f553b3266 Doc: update changelog 2023-12-31 18:43:44 +08:00
Souma cae4b1c657 chore(terminalshell_linux.c): Ignore cwterm as well as figterm
Since CodeWhisperer overrides the terminal environment.
2023-12-31 18:19:04 +08:00
李通洲 bb489f9af3 Common: get rid of detection/internal.h 2023-12-30 18:13:54 +08:00
李通洲 275b53c6c0 Vulkan: don't print software renderers 2023-12-30 18:12:21 +08:00
李通洲 adae31304d Media (macOS): tidy 2023-12-30 14:21:52 +08:00
李通洲 db6d5d7fd6 Windows: get rid of InitOnceExecuteOnce 2023-12-30 14:19:25 +08:00
Carter Li bce96cf3f0 Doc: update changelog 2023-12-29 23:35:47 +08:00
Carter Li 0707902532 PhysicalDisk (Apple): trim strings 2023-12-29 23:33:16 +08:00
李通洲 ef1d102e05 GPU (Windows): clean up vendor name 2023-12-29 23:13:44 +08:00
李通洲 c1f511c8f2 GPU: detect supported platform graphic API version 2023-12-29 23:13:44 +08:00
李通洲 0284f6bfd1 Font: tidy 2023-12-28 15:42:07 +08:00
李通洲 6d50f1efdd Doc: update changelog 2023-12-28 15:12:20 +08:00
李通洲 4066c0d9e8 PhysicalDisk (Windows): improve stability 2023-12-28 14:50:39 +08:00
李通洲 150e9fc650 PhysicalDisk: prettify interconnect type 2023-12-28 13:47:21 +08:00
李通洲 36bce8fb0e PhysicalDisk (macOS): fix a possible segfault 2023-12-28 13:41:40 +08:00
Carter Li e5e70c1d92 PhysicalDisk (Linux): prettify interconnect type 2023-12-28 10:31:28 +08:00
Carter Li 12065bcfb0 PhysicalDisk (Linux): display nvme namespace id if needed 2023-12-28 10:28:21 +08:00
Carter Li 73a30da7bc Disk (FreeBSD): detect partition name 2023-12-27 16:26:58 +08:00
Carter Li 01fb491289 PhysicalDisk (FreeBSD): detect NVMe connect type 2023-12-27 15:32:17 +08:00
李通洲 6c4a4bfe13 Disk (macOS): support name detection of iso volumes 2023-12-27 14:15:50 +08:00
Carter Li 62647c3cb9 PhysicalDisk (FreeBSD): add comments 2023-12-27 11:14:15 +08:00
Carter Li 42694042f5 PhysicalDisk (FreeBSD): fix read-only type detection 2023-12-27 11:03:01 +08:00
李通洲 d5997b9f29 Doc: document --physicaldisk-temp 2023-12-27 10:16:33 +08:00
李通洲 969a67ed0f PhysicalDisk (macOS): detect temp 2023-12-27 10:00:29 +08:00
李通洲 54bd4346ec Temps (macOS): rename functions 2023-12-27 08:46:49 +08:00
李通洲 17d6f84850 Temps (macOS): update sensors of M2X 2023-12-27 08:45:02 +08:00
李通洲 0972eb6986 PhysicalDisk: detect temp 2023-12-26 19:57:24 +08:00
李通洲 0ee892f2de Disk (Linux): simplify impl of detecting partition removable 2023-12-26 18:58:05 +08:00
Carter Li b1f54ab7a2 Battery (Linux): fix temp detection for asahi 2023-12-26 16:44:13 +08:00
Carter Li 5a372882fa Battery (Linux): tidy 2023-12-26 16:44:13 +08:00
李通洲 16d34b6933 Doc: update changelog 2023-12-26 15:50:48 +08:00
李通洲 f319a80dc5 CPU (Linux): if we failed to detect the number of physical cores, assume all logical cores are physical 2023-12-26 13:40:41 +08:00
李通洲 60f5cc9079 CPU (Linux): don't print - 2023-12-26 13:34:58 +08:00
Carter Li dd3b3f22ba CPU (Linux): detect multi cpu models by lscpu
Supports asahi linux
2023-12-26 11:20:40 +08:00
Carter Li e672e40f8b GPU: detect devices by OpenGL
which works for asahi linux
2023-12-26 11:19:33 +08:00
李通洲 91089a7fe9 PhysicalDisk (Windows): init variables 2023-12-25 20:02:41 +08:00
李通洲 677f39420b PhysicalDisk: print product revision 2023-12-25 18:33:39 +08:00
李通洲 f2da8305c7 PhysicalDisk (Windows): detect revision 2023-12-25 18:22:04 +08:00
李通洲 060082885b PhysicalDisk: rename firmwareRev to revision 2023-12-25 18:21:23 +08:00
李通洲 3134a04b5c PhysicalDisk (Linux): don't append diskseq 2023-12-25 18:12:02 +08:00
李通洲 d3bcef61da PhysicalDisk (macOS): detect firmware revision 2023-12-25 16:40:59 +08:00
Carter Li b2cabd2af7 PhysicalDisk (Linux): detect firmware revision 2023-12-25 16:32:34 +08:00
Carter Li 5e85864ab0 PhysicalDisk (FreeBSD): detect read-only 2023-12-25 14:49:49 +08:00
李通洲 cb68dccd0e GPU (AMD): fix a silly bug 2023-12-25 14:47:12 +08:00
李通洲 3b6d5468da PhysicalDisk (macOS): detect read-only 2023-12-25 14:47:12 +08:00
李通洲 350388295d Doc: fix --help messages 2023-12-25 14:47:12 +08:00
apocelipes e7aa6c3757 fix(Battery): fix overflow and uninitializations of battery cycle counts 2023-12-25 06:45:47 +00:00
李通洲 c100e0dff7 PhysicalDisk (Windows): detect CDROMs; detect read-only 2023-12-24 23:27:57 +08:00
李通洲 02999ae4bf PhysicalDisk (Linux): detect readonly 2023-12-24 22:34:45 +08:00
李通洲 b5a01400e9 PhysicalDisk (Linux): detect more interconnect type 2023-12-24 22:31:36 +08:00
李通洲 ef8bd63075 PhysicalDisk (Linux): remove trailing spaces 2023-12-24 21:33:57 +08:00
李通洲 58e8403e16 Disk (Linux): be more careful to detect external type 2023-12-24 20:53:11 +08:00
李通洲 34b0bbac26 PhysicalDisk (Linux): be more careful to detect connection type 2023-12-24 20:52:05 +08:00
李通洲 97c6966939 Disk (Linux): detect subvolume first
Fix #674
2023-12-24 20:32:43 +08:00
李通洲 be38182ab2 Disk (WSL): fix Windows volume detection 2023-12-24 19:42:10 +08:00
李通洲 d2d4ee89d8 GPU (WSL): fix gpu temp detection for nvidia cards 2023-12-24 19:41:20 +08:00
apocelipes 113b1b8fc2 fix: fix trailing space 2023-12-23 02:55:14 +00:00
Carter Li cf98e6f5a1 Global: remove unexpected trailing line endings
Ref: https://github.com/fastfetch-cli/fastfetch/pull/671#issuecomment-1867777472
2023-12-23 00:19:50 +08:00
apocelipes e85a4b9ff5 refactor(IO): clean up ffAppendFDBuffer
for 2 reasons:

- Simplify the Code.
- ffAppendFDBuffer can't make assumptions about how the read data will
  be processed, so the trim calls are inappropriate.
2023-12-22 11:49:57 +00:00
FilippoULIVO b7935aa238 Update README.md 2023-12-22 11:06:00 +00:00
李通洲 a13520c5ff 3rdparty: remove unused types in amd_ags and make it complies in C
Ref: https://github.com/GPUOpen-LibrariesAndSDKs/AGS_SDK/issues/48
2023-12-21 19:20:35 +08:00
李通洲 dfb0eecf86 3rdparty: add amd_ags 2023-12-21 18:52:38 +08:00
李通洲 c5695542b2 CI: generate sha256sum for source tarballs
Ref: https://github.com/ncipollo/release-action/issues/400
2023-12-21 10:31:25 +08:00
李通洲 a1d81b4964 fastfetch: fix compiler warnings 2023-12-21 09:52:20 +08:00
李通洲 72ed11ec9e 3rdparty: oops 2023-12-20 22:23:02 +08:00
李通洲 1c5179d3b0 GPU (Intel): actually detect real time clock frequency 2023-12-20 22:19:15 +08:00
李通洲 adc506d2b3 GPU: fix clock frequency detection and overall tidy 2023-12-20 19:13:00 +08:00
apocelipes b2236cc046 refactor(TerminalFont): use ffSearchUserConfigFile 2023-12-20 10:28:51 +00:00
apocelipes 3040bc38cb refactor(WMTheme): use ffSearchUserConfigFile 2023-12-20 10:28:51 +00:00
apocelipes b9368ac20d feature(IO): support searching user's config file from configDirs 2023-12-20 10:28:51 +00:00
Carter Li a4f5a9af03 Brightness (Linux): show meaningfull name on asahi 2023-12-20 16:44:30 +08:00
李通洲 f8be6322df GPU: rename use-nvml to driver-specific
Because we are supporting drivers other than NVML
2023-12-20 15:32:55 +08:00
李通洲 4a1bbb6a03 GPU: huge improvement of driver specific detection code 2023-12-20 14:45:27 +08:00
李通洲 961e9a6a5f GPU (Windows): detection with intel driver (WIP) 2023-12-20 00:49:56 +08:00
李通洲 2f4b210f33 CI: generate sha256sum 2023-12-19 18:48:38 +08:00
李通洲 456a58c8f5 fastfetch: default preset names to .jsonc
Fix #666
2023-12-19 18:48:38 +08:00
李通洲 b8b15c5170 Wifi (macOS): support most auth types 2023-12-19 18:48:38 +08:00
apocelipes 61485cb133 refactor(WMTheme): clean up detectOpenbox
Simplify the code and implement stricter checking of xml contents.
2023-12-19 08:31:57 +00:00
168 changed files with 12298 additions and 2145 deletions
+35 -10
View File
@@ -132,7 +132,7 @@ jobs:
run: echo "ffversion=$(./fastfetch --version-raw)" >> $GITHUB_OUTPUT
- name: upload artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: fastfetch-linux
path: ./fastfetch-*.*
@@ -188,7 +188,7 @@ jobs:
run: ctest
- name: upload artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: fastfetch-macos
path: ./fastfetch-*.*
@@ -204,7 +204,7 @@ jobs:
uses: actions/checkout@v4
- name: run VM
uses: cross-platform-actions/action@v0.21.1
uses: cross-platform-actions/action@master
with:
operating_system: freebsd
version: '13.2'
@@ -222,7 +222,7 @@ jobs:
ctest
- name: upload artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: fastfetch-freebsd
path: ./fastfetch-*.*
@@ -284,7 +284,7 @@ jobs:
run: 7z a -t7z -mx9 -bd -y fastfetch-$(./fastfetch --version-raw)-Win64.7z *.dll fastfetch.exe flashfetch.exe presets
- name: upload artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: fastfetch-win64
path: ./fastfetch-*-Win64.*
@@ -351,7 +351,7 @@ jobs:
run: 7z a -t7z -mx9 -bd -y fastfetch-$(./fastfetch --version-raw)-Win32.7z *.dll fastfetch.exe flashfetch.exe presets
- name: upload artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: fastfetch-win32
path: ./fastfetch-*-Win32.*
@@ -369,15 +369,16 @@ jobs:
permissions:
contents: write
steps:
- name: download artifacts
uses: actions/download-artifact@v3
- name: get latest release version
id: get_version_release
uses: pozetroninc/github-action-get-latest-release@master
with:
repository: ${{ github.repository }}
- name: download artifacts
if: needs.linux.outputs.ffversion != steps.get_version_release.outputs.release
uses: actions/download-artifact@v4
- name: create release
if: needs.linux.outputs.ffversion != steps.get_version_release.outputs.release
uses: ncipollo/release-action@v1
@@ -385,4 +386,28 @@ jobs:
tag: ${{ needs.linux.outputs.ffversion }}
commit: ${{ github.sha }}
artifactErrorsFailBuild: true
artifacts: fastfetch-linux/*,fastfetch-macos/*,fastfetch-freebsd/*,fastfetch-win64/*,fastfetch-win32/*
artifacts: fastfetch-*/fastfetch-*
body: "Please refer to [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/${{ needs.linux.outputs.ffversion }}/CHANGELOG.md) for details."
- name: download source tarballs
if: needs.linux.outputs.ffversion != steps.get_version_release.outputs.release
run: |
for i in 1 2 3 4 5; do curl -L --remote-name-all --output-dir fastfetch-source --create-dirs https://github.com/${{ github.repository }}/archive/refs/tags/${{ needs.linux.outputs.ffversion }}.{tar.gz,zip} && break || sleep 5; done
ls fastfetch-*/*
- name: generate release notes
if: needs.linux.outputs.ffversion != steps.get_version_release.outputs.release
run: |
echo "Please refer to [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/${{ needs.linux.outputs.ffversion }}/CHANGELOG.md) for details." > fastfetch-release-notes.md
echo -e "\n---\n\n<details><summary>SHA256SUMs</summary><br>\n\n\`\`\`" >> fastfetch-release-notes.md
sha256sum fastfetch-*/* >> fastfetch-release-notes.md
echo -e "\`\`\`\n</details>" >> fastfetch-release-notes.md
- name: update release body
if: needs.linux.outputs.ffversion != steps.get_version_release.outputs.release
uses: ncipollo/release-action@v1
with:
tag: ${{ needs.linux.outputs.ffversion }}
commit: ${{ github.sha }}
bodyFile: fastfetch-release-notes.md
allowUpdates: true
+51
View File
@@ -1,3 +1,54 @@
# 2.6.0
Changes:
* Remove support of option `--battery-dir`. We detect a lot of things in `/sys/class/*` and only module `Battery` supports specifying a custom directory for some reason, which is weird.
* Remove `--chassis-use-wmi` which is no longer used.
Features:
* Add `ENABLE_PROPRIETARY_GPU_DRIVER_API` cmake option to disable using of proprietary GPU driver APIs (GPU)
* Support wallpaper detection for macOS Sonoma (Wallpaper, macOS)
* Support power adapter detection for Asahi Linux (PowerAdapter, Linux)
* Support battery serial number and manufacturer date detection (Battery)
* Support host serial number and UUID detection (Host)
* Support battery level detection for gamepads where possible (Gamepad)
* Support maximum CPU clock detection. Previously base clock was printed (CPU, Windows)
* Support manufacture date and serial number detection for physical monitors (Monitor)
* Support ash (default shell of BusyBox) version detection (Shell, Linux)
* Sound module in FreeBSD now uses native `ioctl`s. Pulseaudio dependency is no longer used.
* Locale module in Windows now prints the same format as in Linux and other posix systems.
Bugfixes:
* Fix overall memory leaks (macOS)
* Remove trailing `\0` in JSON results (FreeBSD)
* Fix physical monitor detection with Nvidia drivers (Monitor, Linux)
* Don't print llvmpipe in vulkan module (Vulkan)
* Fix system yyjson usage in `fastfetch.c`. Previously embedded `3rdparty/yyjson/yyjson.h` was used in `fastfetch.c` even if `ENABLE_SYSTEM_YYJSON` was set (CMake)
* Fix locale module printing unexpected results in specific environments (Locale)
* Fix battery temperature detection in Windows. Note only smart batteries report temperatures but few laptops uses smart battery (Battery, Windows)
* Print device name if no backlight name is available, so we don't print empty parentheses (Brightness, FreeBSD)
# 2.5.0
Changes:
* `--gpu-use-nvml` has been renamed to `--gpu-driver-specific` due to using of `IGCL` and `AGS`
* We now detect external partitions more conservatively in Linux. USB partitions will not be detected as external always ( eg. The Linux kernel itself is installed in a USB drive )
Features:
* Support more authentication type detection for macOS Sonoma (Wifi, macOS)
* Default preset names to `.jsonc`. For example, `fastfetch -c all` will load `presets/all.jsonc` (#666)
* Use Intel Graphics Control Library (IGCL) to detect more GPU information. Windows only (GPU, Windows)
* Improve support of Asahi Linux (Brightness / CPU / GPU / Disk, Linux)
* Support more properties of physical disks (PhysicalDisk)
* Support SSD temperature detection with `--physicaldisk-temp` (PhysicalDisk)
* Support partition label detection (Disk, FreeBSD)
* Support platform specific graphic API version detection (GPU, macOS / Windows)
Bugfixes:
* Fix Windows partition detection for WSL2 (Linux, Disk)
* Fix Btrfs subvolumes being detected as external partitions some times (Linux, Disk)
* Fix battery cycle counts in some places (Battery)
* Fix CodeWhisperer compatibility (#676, Terminal, macOS)
# 2.4.0
**We are deprecating flags based config files (will be removed in v3.0.0). We suggest you migrate to json based config files.** One may use `-c /path/to/config.conf --gen-config` to migrate existing flag based config files.
+46 -18
View File
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs & project homepage url
project(fastfetch
VERSION 2.4.0
VERSION 2.6.0
LANGUAGES C
DESCRIPTION "Fast neofetch-like system information tool"
HOMEPAGE_URL "https://github.com/fastfetch-cli/fastfetch"
@@ -66,7 +66,7 @@ cmake_dependent_option(ENABLE_OSMESA "Enable osmesa" ON "LINUX OR BSD" OFF)
cmake_dependent_option(ENABLE_OPENCL "Enable opencl" ON "LINUX OR BSD OR WIN32" OFF)
cmake_dependent_option(ENABLE_LIBNM "Enable libnm" ON "LINUX" OFF)
cmake_dependent_option(ENABLE_FREETYPE "Enable freetype" ON "ANDROID" OFF)
cmake_dependent_option(ENABLE_PULSE "Enable pulse" ON "LINUX OR BSD" OFF)
cmake_dependent_option(ENABLE_PULSE "Enable pulse" ON "LINUX" OFF)
cmake_dependent_option(ENABLE_DDCUTIL "Enable ddcutil" ON "LINUX" OFF)
cmake_dependent_option(ENABLE_DIRECTX_HEADERS "Enable DirectX headers for WSL" ON "LINUX" OFF)
cmake_dependent_option(ENABLE_THREADS "Enable multithreading" ON "Threads_FOUND" OFF)
@@ -74,6 +74,7 @@ cmake_dependent_option(ENABLE_PCI_MEMORY "Enable detecting GPU memory size with
option(ENABLE_SYSTEM_YYJSON "Use system provided (instead of fastfetch embedded) yyjson library" OFF)
option(ENABLE_ASAN "Build fastfetch with ASAN (address sanitizer)" OFF)
option(ENABLE_PROPRIETARY_GPU_DRIVER_API "Enable proprietary GPU driver API (NVML, IGCL and AGS)" ON)
option(BUILD_TESTS "Build tests" OFF) # Also create test executables
option(SET_TWEAK "Add tweak to project version" ON) # This is set to off by github actions for release builds
@@ -109,12 +110,8 @@ endif()
if(WIN32)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--tsaware -Wl,--build-id -Wl,--subsystem,console:6.1,--major-os-version,6,--minor-os-version,1")
endif()
# Used for dlopen finding dylibs installed by homebrew
# `/opt/homebrew/lib` is not on in dlopen search path by default
if(APPLE AND DEFINED ENV{HOMEBREW_PREFIX})
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,$ENV{HOMEBREW_PREFIX}/lib")
elseif(APPLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fobjc-arc")
endif()
set(FASTFETCH_FLAGS_DEBUG "-fno-omit-frame-pointer")
@@ -290,7 +287,6 @@ set(LIBFASTFETCH_SRC
src/detection/displayserver/displayserver.c
src/detection/font/font.c
src/detection/gpu/gpu.c
src/detection/locale/locale.c
src/detection/media/media.c
src/detection/netio/netio.c
src/detection/opencl/opencl.c
@@ -374,7 +370,6 @@ set(LIBFASTFETCH_SRC
src/util/FFlist.c
src/util/FFstrbuf.c
src/util/platform/FFPlatform.c
src/util/stringUtils.c
src/util/smbiosHelper.c
)
@@ -405,12 +400,12 @@ if(LINUX)
src/detection/displayserver/linux/xlib.c
src/detection/font/font_linux.c
src/detection/gpu/gpu_linux.c
src/detection/gpu/gpu_nvidia.c
src/detection/gtk_qt/gtk.c
src/detection/host/host_linux.c
src/detection/icons/icons_linux.c
src/detection/libc/libc_linux.c
src/detection/lm/lm_linux.c
src/detection/locale/locale_linux.c
src/detection/localip/localip_linux.c
src/detection/gamepad/gamepad_linux.c
src/detection/media/media_linux.c
@@ -420,7 +415,7 @@ if(LINUX)
src/detection/opengl/opengl_linux.c
src/detection/os/os_linux.c
src/detection/packages/packages_linux.c
src/detection/poweradapter/poweradapter_nosupport.c
src/detection/poweradapter/poweradapter_linux.c
src/detection/processes/processes_linux.c
src/detection/gtk_qt/qt.c
src/detection/sound/sound_linux.c
@@ -464,6 +459,7 @@ elseif(ANDROID)
src/detection/icons/icons_nosupport.c
src/detection/libc/libc_android.c
src/detection/lm/lm_nosupport.c
src/detection/locale/locale_linux.c
src/detection/localip/localip_linux.c
src/detection/gamepad/gamepad_nosupport.c
src/detection/media/media_nosupport.c
@@ -519,12 +515,12 @@ elseif(BSD)
src/detection/displayserver/linux/xlib.c
src/detection/font/font_linux.c
src/detection/gpu/gpu_linux.c
src/detection/gpu/gpu_nvidia.c
src/detection/gtk_qt/gtk.c
src/detection/host/host_bsd.c
src/detection/lm/lm_linux.c
src/detection/icons/icons_linux.c
src/detection/libc/libc_bsd.c
src/detection/locale/locale_linux.c
src/detection/localip/localip_linux.c
src/detection/gamepad/gamepad_bsd.c
src/detection/media/media_linux.c
@@ -537,7 +533,7 @@ elseif(BSD)
src/detection/poweradapter/poweradapter_nosupport.c
src/detection/processes/processes_bsd.c
src/detection/gtk_qt/qt.c
src/detection/sound/sound_linux.c
src/detection/sound/sound_bsd.c
src/detection/swap/swap_bsd.c
src/detection/temps/temps_bsd.c
src/detection/terminalfont/terminalfont_linux.c
@@ -575,10 +571,12 @@ elseif(APPLE)
src/detection/displayserver/displayserver_apple.c
src/detection/font/font_apple.m
src/detection/gpu/gpu_apple.c
src/detection/gpu/gpu_apple.m
src/detection/host/host_apple.c
src/detection/lm/lm_nosupport.c
src/detection/icons/icons_nosupport.c
src/detection/libc/libc_apple.c
src/detection/locale/locale_linux.c
src/detection/localip/localip_linux.c
src/detection/gamepad/gamepad_apple.c
src/detection/media/media_apple.m
@@ -599,7 +597,7 @@ elseif(APPLE)
src/detection/theme/theme_nosupport.c
src/detection/uptime/uptime_bsd.c
src/detection/users/users_linux.c
src/detection/wallpaper/wallpaper_apple.c
src/detection/wallpaper/wallpaper_apple.m
src/detection/wifi/wifi_apple.m
src/detection/wm/wm_apple.c
src/detection/de/de_nosupport.c
@@ -619,7 +617,7 @@ elseif(WIN32)
src/detection/bluetooth/bluetooth_windows.c
src/detection/board/board_windows.c
src/detection/brightness/brightness_windows.cpp
src/detection/chassis/chassis_windows.cpp
src/detection/chassis/chassis_windows.c
src/detection/cpu/cpu_windows.c
src/detection/cpuusage/cpuusage_windows.c
src/detection/cursor/cursor_windows.c
@@ -629,11 +627,11 @@ elseif(WIN32)
src/detection/displayserver/displayserver_windows.c
src/detection/font/font_windows.c
src/detection/gpu/gpu_windows.c
src/detection/gpu/gpu_nvidia.c
src/detection/host/host_windows.c
src/detection/icons/icons_windows.c
src/detection/libc/libc_windows.cpp
src/detection/lm/lm_nosupport.c
src/detection/locale/locale_windows.c
src/detection/localip/localip_windows.c
src/detection/gamepad/gamepad_windows.c
src/detection/media/media_nosupport.c
@@ -673,6 +671,17 @@ if(ENABLE_DIRECTX_HEADERS)
list(APPEND LIBFASTFETCH_SRC src/detection/gpu/gpu_wsl.cpp)
endif()
if(ENABLE_PROPRIETARY_GPU_DRIVER_API AND (LINUX OR BSD OR WIN32))
message(STATUS "Enabling proprietary GPU driver API")
if(LINUX OR BSD OR WIN32)
list(APPEND LIBFASTFETCH_SRC src/detection/gpu/gpu_nvidia.c)
endif()
if(WIN32)
list(APPEND LIBFASTFETCH_SRC src/detection/gpu/gpu_intel.c)
list(APPEND LIBFASTFETCH_SRC src/detection/gpu/gpu_amd.c)
endif()
endif()
include(CheckFunctionExists)
check_function_exists(wcwidth HAVE_WCWIDTH)
if(NOT HAVE_WCWIDTH)
@@ -696,9 +705,20 @@ add_library(libfastfetch OBJECT
${LIBFASTFETCH_SRC}
)
if(ENABLE_PROPRIETARY_GPU_DRIVER_API AND (LINUX OR BSD OR WIN32))
target_compile_definitions(libfastfetch PRIVATE FF_USE_PROPRIETARY_GPU_DRIVER_API)
endif()
if(yyjson_FOUND)
target_compile_definitions(libfastfetch PRIVATE FF_USE_SYSTEM_YYJSON)
target_link_libraries(libfastfetch PRIVATE yyjson)
target_link_libraries(libfastfetch PRIVATE yyjson::yyjson)
# `target_link_libraries(yyjson::yyjson)` sets rpath implicitly
else()
# Used for dlopen finding dylibs installed by homebrew
# `/opt/homebrew/lib` is not on in dlopen search path by default
if(APPLE AND DEFINED ENV{HOMEBREW_PREFIX})
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,$ENV{HOMEBREW_PREFIX}/lib")
endif()
endif()
if(LINUX AND EXISTS "/lib/ld-musl-${CMAKE_HOST_SYSTEM_PROCESSOR}.so.1")
@@ -903,6 +923,7 @@ elseif(APPLE)
PRIVATE "-framework CoreWLAN"
PRIVATE "-framework IOBluetooth"
PRIVATE "-framework IOKit"
PRIVATE "-framework Metal"
PRIVATE "-framework OpenGL"
PRIVATE "-framework OpenCL"
PRIVATE "-framework SystemConfiguration"
@@ -989,6 +1010,13 @@ set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "")
set_target_properties(fastfetch PROPERTIES LINKER_LANGUAGE C)
set_target_properties(flashfetch PROPERTIES LINKER_LANGUAGE C)
if(yyjson_FOUND)
target_compile_definitions(fastfetch PRIVATE FF_USE_SYSTEM_YYJSON)
target_link_libraries(fastfetch PRIVATE yyjson::yyjson)
target_compile_definitions(flashfetch PRIVATE FF_USE_SYSTEM_YYJSON)
target_link_libraries(flashfetch PRIVATE yyjson::yyjson)
endif()
if(WIN32)
set(TARGET_NAME fastfetch)
target_sources(fastfetch
+5 -1
View File
@@ -27,10 +27,14 @@ There are [screenshots on different platforms](https://github.com/fastfetch-cli/
### Linux
* Debian / Ubuntu: Download `fastfetch-<version>-Linux.deb` from [Github release page](https://github.com/fastfetch-cli/fastfetch/releases/latest) and `sudo apt install fastfetch-<version>-Linux.deb`
* Debian / Ubuntu: Download `fastfetch-<version>-Linux.deb` from [Github release page](https://github.com/fastfetch-cli/fastfetch/releases/latest) and `dpkg -i fastfetch-<version>-Linux.deb`
* Arch Linux: `sudo pacman -S fastfetch`
* Fedora: `sudo dnf install fastfetch`
* Gentoo: `sudo emerge --ask app-misc/fastfetch`
* NixOS: `sudo nix-shell -p fastfetch`
* openSUSE: `sudo zypper install fastfetch`
Replace sudo with doas depending on what you use.
[See also if fastfetch has been packaged for your favorite Linux distro](#Packaging)
-1
View File
@@ -384,7 +384,6 @@ __fastfetch_completion()
"--lib-pulse"
"--lib-ddcutil"
"--lib-nm"
"--battery-dir"
)
local FF_OPTIONS_LOGO=(
+7 -11
View File
@@ -804,10 +804,6 @@
"const": "battery",
"description": "Print battery capacity, status, etc"
},
"dir": {
"description": "The directory where the battery folders are. Standard: `/sys/class/power_supply/`. Linux only",
"type": "string"
},
"useSetupApi": {
"description": "Set if `SetupAPI` should be used on Windows to detect battery info, which supports multi batteries, but slower. Windows only",
"type": "boolean",
@@ -883,11 +879,6 @@
"const": "chassis",
"description": "Print chassis type (desktop, laptop, etc)"
},
"useWmi": {
"description": "Set if WMI query should be used on Windows, which detects more information but slower",
"type": "boolean",
"default": false
},
"key": {
"$ref": "#/$defs/key"
},
@@ -1191,8 +1182,8 @@
"type": "boolean",
"default": false
},
"useNvml": {
"description": "Use nvml (NVIDIA Management Library) to detect more detailed GPU information (memory usage, CUDA core count, etc)",
"driverSpecific": {
"description": "Use driver specific method to detect more detailed GPU information (memory usage, core count, etc)",
"type": "boolean",
"default": false
},
@@ -1381,6 +1372,11 @@
"description": "Show disks with given name prefix only",
"type": "string"
},
"temp": {
"description": "Detect and display SSD temperature if supported",
"type": "boolean",
"default": false
},
"key": {
"$ref": "#/$defs/key"
},
+383
View File
@@ -0,0 +1,383 @@
//
// Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
/// \file
/// \mainpage
/// AGS Library Overview
/// --------------------
/// This document provides an overview of the AGS (AMD GPU Services) library. The AGS library provides software developers with the ability to query
/// AMD GPU software and hardware state information that is not normally available through standard operating systems or graphic APIs.
///
/// The latest version of the API is publicly hosted here: https://github.com/GPUOpen-LibrariesAndSDKs/AGS_SDK/.
/// It is also worth checking http://gpuopen.com/gaming-product/amd-gpu-services-ags-library/ for any updates and articles on AGS.
/// \internal
/// Online documentation is publicly hosted here: http://gpuopen-librariesandsdks.github.io/ags/
/// \endinternal
///
/// ---------------------------------------
/// What's new in AGS 6.2 since version 6.1
/// ---------------------------------------
/// AGS 6.2 includes the following updates:
/// * Shader clock intrinsics
/// * Minor improvements and fixes
///
/// ---------------------------------------
/// What's new in AGS 6.1 since version 6.0
/// ---------------------------------------
/// AGS 6.1 includes the following updates:
/// * RDNA3 detection
///
/// ---------------------------------------
/// What's new in AGS 6.0 since version 5.4.2
/// ---------------------------------------
/// AGS 6.0 includes the following updates:
/// * DX12 ray tracing hit token for RDNA2 hardware.
/// * Shader intrinsic that exposes ReadLaneAt in DX12.
/// * Shader intrinsics that expose explicit float conversions in DX12.
/// * Refactored and revised API to minimize user error.
/// * Added agsGetVersionNumber.
/// * Detection for external GPUs.
/// * Detection of RDNA2 architecture.
/// * Grouped the more established intrinsics together into per year support.
/// * Function pointer typedefs for the API
///
/// ---------------------------------------
/// What's new in AGS 5.4.2 since version 5.4.1
/// ---------------------------------------
/// AGS 5.4.2 includes the following updates:
/// * sharedMemoryInBytes has been reinstated.
/// * Clock speed returned for APUs.
///
/// ---------------------------------------
/// What's new in AGS 5.4.1 since version 5.4.0
/// ---------------------------------------
/// AGS 5.4.1 includes the following updates:
/// * AsicFamily_Count to help with code maintenance.
/// * Visual Studio 2019 support.
/// * x86 support
/// * BaseInstance and BaseVertex intrinsics along with corresponding caps bits.
/// * GetWaveSize intrinsic along with corresponding caps bits.
///
/// ---------------------------------------
/// What's new in AGS 5.4 since version 5.3
/// ---------------------------------------
/// AGS 5.4 includes the following updates:
/// * A more detailed description of the GPU architecture, now including RDNA GPUs.
/// * Radeon 7 core and memory speeds returned.
/// * Draw index and Atomic U64 intrinsics for both DX11 and DX12.
///
/// ---------------------------------------
/// What's new in AGS 5.3 since version 5.2
/// ---------------------------------------
/// AGS 5.3 includes the following updates:
/// * DX11 deferred context support for Multi Draw Indirect and UAV Overlap extensions.
/// * A Radeon Software Version helper to determine whether the installed driver meets your game's minimum driver version requirements.
/// * Freesync HDR Gamma 2.2 mode which uses a 1010102 swapchain and can be considered as an alternative to using the 64 bit swapchain required for Freesync HDR scRGB.
///
/// Using the AGS library
/// ---------------------
/// It is recommended to take a look at the source code for the samples that come with the AGS SDK:
/// * AGSSample
/// * CrossfireSample
/// * EyefinitySample
/// The AGSSample application is the simplest of the three examples and demonstrates the code required to initialize AGS and use it to query the GPU and Eyefinity state.
/// The CrossfireSample application demonstrates the use of the new API to transfer resources on GPUs in Crossfire mode. Lastly, the EyefinitySample application provides a more
/// extensive example of Eyefinity setup than the basic example provided in AGSSample.
/// There are other samples on Github that demonstrate the DirectX shader extensions, such as the Barycentrics11 and Barycentrics12 samples.
///
/// To add AGS support to an existing project, follow these steps:
/// * Link your project against the correct import library. Choose from either the 32 bit or 64 bit version.
/// * Copy the AGS dll into the same directory as your game executable.
/// * Include the amd_ags.h header file from your source code.
/// * Include the AGS hlsl files if you are using the shader intrinsics.
/// * Declare a pointer to an AGSContext and make this available for all subsequent calls to AGS.
/// * On game initialization, call \ref agsInitialize passing in the address of the context. On success, this function will return a valid context pointer.
///
/// Don't forget to cleanup AGS by calling \ref agsDeInitialize when the app exits, after the device has been destroyed.
#ifndef AMD_AGS_H
#define AMD_AGS_H
#define AMD_AGS_VERSION_MAJOR 6 ///< AGS major version
#define AMD_AGS_VERSION_MINOR 2 ///< AGS minor version
#define AMD_AGS_VERSION_PATCH 0 ///< AGS patch version
#ifdef __cplusplus
extern "C" {
#endif
/// \defgroup Defines AGS defines
/// @{
#if defined (AGS_GCC)
#define AMD_AGS_API
#else
#define AMD_AGS_API __declspec(dllexport) ///< AGS exported functions
#endif
#define AGS_MAKE_VERSION( major, minor, patch ) ( ( major << 22 ) | ( minor << 12 ) | patch ) ///< Macro to create the app and engine versions for the fields in \ref AGSDX12ExtensionParams and \ref AGSDX11ExtensionParams and the Radeon Software Version
#define AGS_UNSPECIFIED_VERSION 0xFFFFAD00 ///< Use this to specify no version
#define AGS_CURRENT_VERSION AGS_MAKE_VERSION( AMD_AGS_VERSION_MAJOR, AMD_AGS_VERSION_MINOR, AMD_AGS_VERSION_PATCH ) ///< Macro to return the current AGS version as defined by the AGS header file
/// @}
/// \defgroup enums General enumerations
/// @{
/// The return codes
typedef enum AGSReturnCode
{
AGS_SUCCESS, ///< Successful function call
AGS_FAILURE, ///< Failed to complete call for some unspecified reason
AGS_INVALID_ARGS, ///< Invalid arguments into the function
AGS_OUT_OF_MEMORY, ///< Out of memory when allocating space internally
AGS_MISSING_D3D_DLL, ///< Returned when a D3D dll fails to load
AGS_LEGACY_DRIVER, ///< Returned if a feature is not present in the installed driver
AGS_NO_AMD_DRIVER_INSTALLED, ///< Returned if the AMD GPU driver does not appear to be installed
AGS_EXTENSION_NOT_SUPPORTED, ///< Returned if the driver does not support the requested driver extension
AGS_ADL_FAILURE, ///< Failure in ADL (the AMD Display Library)
AGS_DX_FAILURE, ///< Failure from DirectX runtime
AGS_D3DDEVICE_NOT_CREATED ///< Failure due to not creating the D3D device successfully via AGS.
} AGSReturnCode;
/// @}
typedef struct AGSContext AGSContext; ///< All function calls in AGS require a pointer to a context. This is generated via \ref agsInitialize
/// The rectangle struct used by AGS.
typedef struct AGSRect
{
int offsetX; ///< Offset on X axis
int offsetY; ///< Offset on Y axis
int width; ///< Width of rectangle
int height; ///< Height of rectangle
} AGSRect;
/// The display info struct used to describe a display enumerated by AGS
typedef struct AGSDisplayInfo
{
char name[ 256 ]; ///< The name of the display
char displayDeviceName[ 32 ]; ///< The display device name, i.e. DISPLAY_DEVICE::DeviceName
unsigned int isPrimaryDisplay : 1; ///< Whether this display is marked as the primary display
unsigned int HDR10 : 1; ///< HDR10 is supported on this display
unsigned int dolbyVision : 1; ///< Dolby Vision is supported on this display
unsigned int freesync : 1; ///< Freesync is supported on this display
unsigned int freesyncHDR : 1; ///< Freesync HDR is supported on this display
unsigned int eyefinityInGroup : 1; ///< The display is part of the Eyefinity group
unsigned int eyefinityPreferredDisplay : 1; ///< The display is the preferred display in the Eyefinity group for displaying the UI
unsigned int eyefinityInPortraitMode : 1; ///< The display is in the Eyefinity group but in portrait mode
unsigned int reservedPadding : 24; ///< Reserved for future use
int maxResolutionX; ///< The maximum supported resolution of the unrotated display
int maxResolutionY; ///< The maximum supported resolution of the unrotated display
float maxRefreshRate; ///< The maximum supported refresh rate of the display
AGSRect currentResolution; ///< The current resolution and position in the desktop, ignoring Eyefinity bezel compensation
AGSRect visibleResolution; ///< The visible resolution and position. When Eyefinity bezel compensation is enabled this will
///< be the sub region in the Eyefinity single large surface (SLS)
float currentRefreshRate; ///< The current refresh rate
int eyefinityGridCoordX; ///< The X coordinate in the Eyefinity grid. -1 if not in an Eyefinity group
int eyefinityGridCoordY; ///< The Y coordinate in the Eyefinity grid. -1 if not in an Eyefinity group
double chromaticityRedX; ///< Red display primary X coord
double chromaticityRedY; ///< Red display primary Y coord
double chromaticityGreenX; ///< Green display primary X coord
double chromaticityGreenY; ///< Green display primary Y coord
double chromaticityBlueX; ///< Blue display primary X coord
double chromaticityBlueY; ///< Blue display primary Y coord
double chromaticityWhitePointX; ///< White point X coord
double chromaticityWhitePointY; ///< White point Y coord
double screenDiffuseReflectance; ///< Percentage expressed between 0 - 1
double screenSpecularReflectance; ///< Percentage expressed between 0 - 1
double minLuminance; ///< The minimum luminance of the display in nits
double maxLuminance; ///< The maximum luminance of the display in nits
double avgLuminance; ///< The average luminance of the display in nits
int logicalDisplayIndex; ///< The internally used index of this display
int adlAdapterIndex; ///< The internally used ADL adapter index
int reserved; ///< reserved field
} AGSDisplayInfo;
/// The ASIC family
typedef enum AsicFamily
{
AsicFamily_Unknown, ///< Unknown architecture, potentially from another IHV. Check \ref AGSDeviceInfo::vendorId
AsicFamily_PreGCN, ///< Pre GCN architecture.
AsicFamily_GCN1, ///< AMD GCN 1 architecture: Oland, Cape Verde, Pitcairn & Tahiti.
AsicFamily_GCN2, ///< AMD GCN 2 architecture: Hawaii & Bonaire. This also includes APUs Kaveri and Carrizo.
AsicFamily_GCN3, ///< AMD GCN 3 architecture: Tonga & Fiji.
AsicFamily_GCN4, ///< AMD GCN 4 architecture: Polaris.
AsicFamily_Vega, ///< AMD Vega architecture, including Raven Ridge (ie AMD Ryzen CPU + AMD Vega GPU).
AsicFamily_RDNA, ///< AMD RDNA architecture
AsicFamily_RDNA2, ///< AMD RDNA2 architecture
AsicFamily_RDNA3, ///< AMD RDNA3 architecture
AsicFamily_Count ///< Number of enumerated ASIC families
} AsicFamily;
/// The device info struct used to describe a physical GPU enumerated by AGS
typedef struct AGSDeviceInfo
{
const char* adapterString; ///< The adapter name string
AsicFamily asicFamily; ///< Set to Unknown if not AMD hardware
unsigned int isAPU : 1; ///< Whether this device is an APU
unsigned int isPrimaryDevice : 1; ///< Whether this device is marked as the primary device
unsigned int isExternal :1; ///< Whether this device is a detachable, external device
unsigned int reservedPadding : 29; ///< Reserved for future use
int vendorId; ///< The vendor id
int deviceId; ///< The device id
int revisionId; ///< The revision id
int numCUs; ///< Number of compute units
int numWGPs; ///< Number of RDNA Work Group Processors. Only valid if ASIC is RDNA onwards.
int numROPs; ///< Number of ROPs
int coreClock; ///< Core clock speed at 100% power in MHz
int memoryClock; ///< Memory clock speed at 100% power in MHz
int memoryBandwidth; ///< Memory bandwidth in MB/s
float teraFlops; ///< Teraflops of GPU. Zero if not GCN onwards. Calculated from iCoreClock * iNumCUs * 64 Pixels/clk * 2 instructions/MAD
unsigned long long localMemoryInBytes; ///< The size of local memory in bytes. 0 for non AMD hardware.
unsigned long long sharedMemoryInBytes; ///< The size of system memory available to the GPU in bytes. It is important to factor this into your VRAM budget for APUs
///< as the reported local memory will only be a small fraction of the total memory available to the GPU.
int numDisplays; ///< The number of active displays found to be attached to this adapter.
AGSDisplayInfo* displays; ///< List of displays allocated by AGS to be numDisplays in length.
int eyefinityEnabled; ///< Indicates if Eyefinity is active
int eyefinityGridWidth; ///< Contains width of the multi-monitor grid that makes up the Eyefinity Single Large Surface.
int eyefinityGridHeight; ///< Contains height of the multi-monitor grid that makes up the Eyefinity Single Large Surface.
int eyefinityResolutionX; ///< Contains width in pixels of the multi-monitor Single Large Surface.
int eyefinityResolutionY; ///< Contains height in pixels of the multi-monitor Single Large Surface.
int eyefinityBezelCompensated; ///< Indicates if bezel compensation is used for the current SLS display area. 1 if enabled, and 0 if disabled.
int adlAdapterIndex; ///< Internally used index into the ADL list of adapters
int reserved; ///< reserved field
} AGSDeviceInfo;
/// \defgroup general General API functions
/// API for initialization, cleanup, HDR display modes and Crossfire GPU count
/// @{
typedef void* (__stdcall *AGS_ALLOC_CALLBACK)( size_t allocationSize ); ///< AGS user defined allocation prototype
typedef void (__stdcall *AGS_FREE_CALLBACK)( void* allocationPtr ); ///< AGS user defined free prototype
/// The configuration options that can be passed in to \ref agsInitialize
typedef struct AGSConfiguration
{
AGS_ALLOC_CALLBACK allocCallback; ///< Optional memory allocation callback. If not supplied, malloc() is used
AGS_FREE_CALLBACK freeCallback; ///< Optional memory freeing callback. If not supplied, free() is used
} AGSConfiguration;
/// The top level GPU information returned from \ref agsInitialize
typedef struct AGSGPUInfo
{
const char* driverVersion; ///< The AMD driver package version
const char* radeonSoftwareVersion; ///< The Radeon Software Version
int numDevices; ///< Number of GPUs in the system
AGSDeviceInfo* devices; ///< List of GPUs in the system
} AGSGPUInfo;
/// The struct to specify the display settings to the driver.
typedef struct AGSDisplaySettings AGSDisplaySettings;
/// The result returned from \ref agsCheckDriverVersion
typedef enum AGSDriverVersionResult
{
AGS_SOFTWAREVERSIONCHECK_OK, ///< The reported Radeon Software Version is newer or the same as the required version
AGS_SOFTWAREVERSIONCHECK_OLDER, ///< The reported Radeon Software Version is older than the required version
AGS_SOFTWAREVERSIONCHECK_UNDEFINED ///< The check could not determine as result. This could be because it is a private or custom driver or just invalid arguments.
} AGSDriverVersionResult;
///
/// Helper function to check the installed software version against the required software version.
///
/// \param [in] radeonSoftwareVersionReported The Radeon Software Version returned from \ref AGSGPUInfo::radeonSoftwareVersion.
/// \param [in] radeonSoftwareVersionRequired The Radeon Software Version to check against. This is specificed using \ref AGS_MAKE_VERSION.
/// \return The result of the check.
///
AMD_AGS_API AGSDriverVersionResult agsCheckDriverVersion( const char* radeonSoftwareVersionReported, unsigned int radeonSoftwareVersionRequired );
///
/// Function to return the AGS version number.
///
/// \return The version number made using AGS_MAKE_VERSION( AMD_AGS_VERSION_MAJOR, AMD_AGS_VERSION_MINOR, AMD_AGS_VERSION_PATCH ).
///
AMD_AGS_API int agsGetVersionNumber();
///
/// Function used to initialize the AGS library.
/// agsVersion must be specified as AGS_CURRENT_VERSION or the call will return \ref AGS_INVALID_ARGS.
/// Must be called prior to any of the subsequent AGS API calls.
/// Must be called prior to ID3D11Device or ID3D12Device creation.
/// \note The caller of this function should handle the possibility of the call failing in the cases below. One option is to do a vendor id check and only call \ref agsInitialize if there is an AMD GPU present.
/// \note This function will fail with \ref AGS_NO_AMD_DRIVER_INSTALLED if there is no AMD driver found on the system.
/// \note This function will fail with \ref AGS_LEGACY_DRIVER in Catalyst versions before 12.20.
///
/// \param [in] agsVersion The API version specified using the \ref AGS_CURRENT_VERSION macro. If this does not match the version in the binary this initialization call will fail.
/// \param [in] config Optional pointer to a AGSConfiguration struct to override the default library configuration.
/// \param [out] context Address of a pointer to a context. This function allocates a context on the heap which is then required for all subsequent API calls.
/// \param [out] gpuInfo Optional pointer to a AGSGPUInfo struct which will get filled in for all the GPUs in the system.
///
AMD_AGS_API AGSReturnCode agsInitialize( int agsVersion, const AGSConfiguration* config, AGSContext** context, AGSGPUInfo* gpuInfo );
///
/// Function used to clean up the AGS library.
///
/// \param [in] context Pointer to a context. This function will deallocate the context from the heap.
///
AMD_AGS_API AGSReturnCode agsDeInitialize( AGSContext* context );
///
/// Function used to set a specific display into HDR mode
/// \note Setting all of the values apart from color space and transfer function to zero will cause the display to use defaults.
/// \note Call this function after each mode change (switch to fullscreen, any change in swapchain etc).
/// \note HDR10 PQ mode requires a 1010102 swapchain.
/// \note HDR10 scRGB mode requires an FP16 swapchain.
/// \note Freesync HDR scRGB mode requires an FP16 swapchain.
/// \note Freesync HDR Gamma 2.2 mode requires a 1010102 swapchain.
/// \note Dolby Vision requires a 8888 UNORM swapchain.
///
/// \param [in] context Pointer to a context. This is generated by \ref agsInitialize
/// \param [in] deviceIndex The index of the device listed in \ref AGSGPUInfo::devices.
/// \param [in] displayIndex The index of the display listed in \ref AGSDeviceInfo::displays.
/// \param [in] settings Pointer to the display settings to use.
///
AMD_AGS_API AGSReturnCode agsSetDisplayMode( AGSContext* context, int deviceIndex, int displayIndex, const AGSDisplaySettings* settings );
/// @}
/// @}
#ifdef __cplusplus
} // extern "C"
#endif
#endif // AMD_AGS_H
+7
View File
@@ -0,0 +1,7 @@
{
"home": "https://github.com/GPUOpen-LibrariesAndSDKs/AGS_SDK",
"license": "MIT (embeded in source)",
"version": "AGS v6.2.0",
"author": "Advanced Micro Devices, Inc",
"modified": "CarterLi"
}
+27
View File
@@ -0,0 +1,27 @@
Intel Software License Agreement
10.07.21
Use and Redistribution. You may use and redistribute Intels Control API software and the header files for the Intel® Graphics Control Library (collectively, the “Software”), solely for use on Intel platforms, provided the following conditions are met:
* Redistributions must reproduce the above copyright notice and the following terms of use in the Software and in the documentation and/or other materials provided with the distribution.
* Neither the name of Intel nor the names of its suppliers may be used to endorse or promote products derived from this Software without specific prior written permission.
* No reverse engineering, decompilation, or disassembly of Software provided to you in binary form is permitted.
Third Party Software. The Software may contain Third Party Software. “Third Party Software” is third party software, open source software or other Intel software listed in the “third-party-software.txt” or other similarly named text file that is included with the Software. Third Party Software, even if included with the distribution of the Software, may be governed by separate license terms, including without limitation, third party license terms, open source software notices and terms, and/or other Intel software license terms. These separate license terms solely govern your use of the Third Party Software.
Ownership. Title to the Software and all copies remain with Intel or its suppliers.
DISCLAIMER. THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT ARE DISCLAIMED. THIS SOFTWARE IS NOT INTENDED FOR USE IN SYSTEMS OR APPLICATIONS WHERE FAILURE OF THE SOFTWARE MAY CAUSE PERSONAL INJURY OR DEATH AND YOU AGREE THAT YOU ARE FULLY RESPONSIBLE FOR ANY CLAIMS, COSTS, DAMAGES, EXPENSES, AND ATTORNEYS FEES ARISING OUT OF ANY SUCH USE, EVEN IF ANY CLAIM ALLEGES THAT INTEL WAS NEGLIGENT REGARDING THE DESIGN OR MANUFACTURE OF THE SOFTWARE.
LIMITATION OF LIABILITY; INDEMNITY. IN NO EVENT WILL INTEL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. YOU AGREE TO INDEMNIFY, DEFEND, AND HOLD INTEL HARMLESS AGAINST ANY CLAIMS, DAMAGES, AND EXPENSES RESULTING FROM YOUR USE OR UNAUTHORIZED USE OF THE SOFTWARE.
No support. Intel may make changes to the Software, at any time without notice, and is not obligated to support, update or provide training for the Software.
Termination. Your right to use the Software is terminated immediately in the event of your breach of this agreement.
Feedback. Should you provide Intel with comments, modifications, corrections, enhancements or other input (“Feedback”) related to the Software Intel will be free to use, disclose, reproduce, license or otherwise distribute or exploit the Feedback in its sole discretion without any obligations or restrictions of any kind, including without limitation, intellectual property rights or licensing obligations.
Compliance with laws. You agree to comply with all applicable laws and regulations governing your use, transfer, import or export (or prohibition thereof) of the Software.
Governing law. All disputes will be governed by the laws of the United States of America and the State of Delaware without reference to conflict of law principles and subject to the exclusive jurisdiction of the state or federal courts sitting in the State of Delaware, and each party agrees that it submits to the personal jurisdiction and venue of those courts and waives any objections. The United Nations Convention on Contracts for the International Sale of Goods (1980) is specifically excluded and will not apply to the Software.
Severability. The parties intend that if a court holds that any provision of this agreement is invalid or unenforceable under applicable law, the court will modify the provision to the minimum extent necessary to make it valid and enforceable or sever and delete the provision from this agreement. Any change to or deletion of a provision of this agreement under this Section will not affect the validity or enforceability of the remainder of this agreement, which will continue in full force and effect.
+7649
View File
File diff suppressed because it is too large Load Diff
+6
View File
@@ -0,0 +1,6 @@
{
"home": "https://github.com/intel/drivers.gpu.control-library",
"license": "./LICENSE",
"version": "e1776b7be2ceead1296204371447b27860d25a66",
"author": "Intel Corporation"
}
+18 -7
View File
@@ -12,6 +12,22 @@ void ffFontInit(FFfont* font)
ffListInit(&font->styles, sizeof(FFstrbuf));
}
static void strbufAppendNSExcludingC(FFstrbuf* strbuf, uint32_t length, const char* value, char exclude)
{
if(value == NULL || length == 0)
return;
ffStrbufEnsureFree(strbuf, length);
for(uint32_t i = 0; i < length; i++)
{
if(value[i] != exclude)
strbuf->chars[strbuf->length++] = value[i];
}
strbuf->chars[strbuf->length] = '\0';
}
static void fontInitPretty(FFfont* font)
{
ffStrbufAppend(&font->pretty, &font->name);
@@ -155,7 +171,7 @@ static void fontPangoParseWord(const char** data, FFfont* font, FFstrbuf* altern
ffStrbufInit(alternativeBuffer);
}
ffStrbufAppendNSExludingC(alternativeBuffer, wordLength, wordStart, '-');
strbufAppendNSExcludingC(alternativeBuffer, wordLength, wordStart, '-');
if(
strncasecmp(wordStart, "Ultra ", 6) == 0 ||
@@ -171,7 +187,7 @@ static void fontPangoParseWord(const char** data, FFfont* font, FFstrbuf* altern
if(alternativeBuffer != NULL)
{
ffStrbufAppendNSExludingC(alternativeBuffer, wordLength, wordStart, '-');
strbufAppendNSExcludingC(alternativeBuffer, wordLength, wordStart, '-');
return;
}
@@ -200,11 +216,6 @@ void ffFontInitValues(FFfont* font, const char* name, const char* size)
fontInitPretty(font);
}
void ffFontInitCopy(FFfont* font, const char* name)
{
ffFontInitValues(font, name, NULL);
}
void ffFontInitWithSpace(FFfont* font, const char* rawName)
{
const char* pspace = strrchr(rawName, ' ');
+5 -1
View File
@@ -14,7 +14,11 @@ typedef struct FFfont
void ffFontInit(FFfont* font);
void ffFontInitQt(FFfont* font, const char* data);
void ffFontInitPango(FFfont* font, const char* data);
void ffFontInitCopy(FFfont* font, const char* name);
void ffFontInitValues(FFfont* font, const char* name, const char* size);
void ffFontInitWithSpace(FFfont* font, const char* rawName);
void ffFontDestroy(FFfont* font);
static inline void ffFontInitCopy(FFfont* font, const char* name)
{
ffFontInitValues(font, name, NULL);
}
+9
View File
@@ -244,6 +244,15 @@ void ffListFeatures(void)
#ifdef FF_HAVE_DIRECTX_HEADERS
"Directx Headers\n"
#endif
#ifdef FF_USE_PROPRIETARY_GPU_DRIVER_API
"Proprietary GPU driver API\n"
#endif
#ifdef FF_USE_SYSTEM_YYJSON
"System yyjson\n"
#endif
#ifdef FF_USE_PCI_MEMORY
"PCI memory\n"
#endif
""
, stdout);
}
+17 -1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "util/FFstrbuf.h"
#include "util/FFlist.h"
#ifdef _WIN32
#include <fileapi.h>
@@ -104,7 +105,7 @@ static inline bool ffPathExists(const char* path, FFPathType pathType)
unsigned int mode = fileStat.st_mode & S_IFMT;
if(pathType & FF_PATHTYPE_FILE && mode == S_IFREG)
if(pathType & FF_PATHTYPE_FILE && mode != S_IFDIR)
return true;
if(pathType & FF_PATHTYPE_DIRECTORY && mode == S_IFDIR)
@@ -185,3 +186,18 @@ static inline bool wrapClosedir(HANDLE* pdir)
}
#endif
#define FF_AUTO_CLOSE_DIR __attribute__((__cleanup__(wrapClosedir)))
static inline bool ffSearchUserConfigFile(const FFlist* configDirs, const char* fileSubpath, FFstrbuf* result)
{
// configDirs is a list of FFstrbufs include the trailing slash
FF_LIST_FOR_EACH(FFstrbuf, dir, *configDirs)
{
ffStrbufClear(result);
ffStrbufAppend(result, dir);
ffStrbufAppendS(result, fileSubpath);
if (ffPathExists(result->chars, FF_PATHTYPE_FILE))
return true;
}
return false;
}
+29 -29
View File
@@ -47,46 +47,46 @@ bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data)
return write(fd, data, dataSize) > 0;
}
static inline void readWithLength(int fd, FFstrbuf* buffer, uint32_t length)
{
ffStrbufEnsureFixedLengthFree(buffer, length);
ssize_t bytesRead = 0;
while(
length > 0 && (bytesRead = read(fd, buffer->chars + buffer->length, length)) > 0
) {
buffer->length += (uint32_t) bytesRead;
length -= (uint32_t) bytesRead;
}
}
static inline void readUntilEOF(int fd, FFstrbuf* buffer)
{
ffStrbufEnsureFree(buffer, 31);
uint32_t available = ffStrbufGetFree(buffer);
ssize_t bytesRead = 0;
while(
(bytesRead = read(fd, buffer->chars + buffer->length, available)) > 0
) {
buffer->length += (uint32_t) bytesRead;
if((uint32_t) bytesRead == available)
ffStrbufEnsureFree(buffer, buffer->allocated - 1); // Doubles capacity every round. -1 for the null byte.
available = ffStrbufGetFree(buffer);
}
}
bool ffAppendFDBuffer(int fd, FFstrbuf* buffer)
{
ssize_t bytesRead = 0;
struct stat fileInfo;
if(fstat(fd, &fileInfo) != 0)
return false;
if (fileInfo.st_size > 0)
{
// optimize for files has a fixed length,
// file can be very large, only keep necessary memory to save time and resources.
ffStrbufEnsureFixedLengthFree(buffer, (uint32_t)fileInfo.st_size);
}
readWithLength(fd, buffer, (uint32_t)fileInfo.st_size);
else
ffStrbufEnsureFree(buffer, 31);
uint32_t free = ffStrbufGetFree(buffer);
// procfs file's st_size is always zero
// choose a signed int type so that can store a native number
ssize_t remain = fileInfo.st_size;
while(
(bytesRead = read(fd, buffer->chars + buffer->length, free)) > 0
) {
buffer->length += (uint32_t) bytesRead;
// if remain > 0, it means there is some data left in the file.
// if remain == 0, it means reading has completed, no need to grow up the buffer.
// if remain < 0, we are reading a file from procfs/sysfs and its st_size is zero,
// we cannot detect how many data remains in the file, we only can call ffStrbufEnsureFree and read again.
remain -= bytesRead;
if((uint32_t) bytesRead == free && remain != 0)
ffStrbufEnsureFree(buffer, buffer->allocated - 1); // Doubles capacity every round. -1 for the null byte.
free = ffStrbufGetFree(buffer);
}
readUntilEOF(fd, buffer);
buffer->chars[buffer->length] = '\0';
ffStrbufTrimRight(buffer, '\n');
ffStrbufTrimRight(buffer, ' ');
return buffer->length > 0;
}
+33 -26
View File
@@ -35,43 +35,50 @@ bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data)
return !!WriteFile(handle, data, (DWORD)dataSize, &written, NULL);
}
static inline void readWithLength(HANDLE handle, FFstrbuf* buffer, uint32_t length)
{
ffStrbufEnsureFixedLengthFree(buffer, length);
DWORD bytesRead = 0;
while(
length > 0 &&
ReadFile(handle, buffer->chars + buffer->length, length, &bytesRead, NULL) != FALSE &&
bytesRead > 0
) {
buffer->length += (uint32_t) bytesRead;
length -= (uint32_t) bytesRead;
}
}
static inline void readUntilEOF(HANDLE handle, FFstrbuf* buffer)
{
ffStrbufEnsureFree(buffer, 31);
uint32_t available = ffStrbufGetFree(buffer);
DWORD bytesRead = 0;
while(
ReadFile(handle, buffer->chars + buffer->length, available, &bytesRead, NULL) != FALSE &&
bytesRead > 0
) {
buffer->length += (uint32_t) bytesRead;
if((uint32_t) bytesRead == available)
ffStrbufEnsureFree(buffer, buffer->allocated - 1); // Doubles capacity every round. -1 for the null byte.
available = ffStrbufGetFree(buffer);
}
}
bool ffAppendFDBuffer(HANDLE handle, FFstrbuf* buffer)
{
DWORD bytesRead = 0;
LARGE_INTEGER fileSize;
if(!GetFileSizeEx(handle, &fileSize))
fileSize.QuadPart = 0;
if (fileSize.QuadPart > 0)
{
// optimize for files has a fixed length,
// file can be very large, only keep necessary memory to save time and resources.
ffStrbufEnsureFixedLengthFree(buffer, (uint32_t)fileSize.QuadPart);
}
readWithLength(handle, buffer, (uint32_t)fileSize.QuadPart);
else
ffStrbufEnsureFree(buffer, 31);
uint32_t free = ffStrbufGetFree(buffer);
ssize_t remain = fileSize.QuadPart;
bool success;
while(
(success = !!ReadFile(handle, buffer->chars + buffer->length, free, &bytesRead, NULL)) &&
bytesRead > 0
) {
buffer->length += (uint32_t) bytesRead;
remain -= (ssize_t)bytesRead;
if((uint32_t) bytesRead == free && remain != 0)
ffStrbufEnsureFree(buffer, buffer->allocated - 1); // Doubles capacity every round. -1 for the null byte.
free = ffStrbufGetFree(buffer);
}
readUntilEOF(handle, buffer);
buffer->chars[buffer->length] = '\0';
ffStrbufTrimRight(buffer, '\n');
ffStrbufTrimRight(buffer, ' ');
return success;
return buffer->length > 0;
}
ssize_t ffReadFileData(const char* fileName, size_t dataSize, void* data)
+24 -21
View File
@@ -7,22 +7,18 @@
static LPFN_CONNECTEX ConnectEx;
static BOOL WINAPI initWsaData(PINIT_ONCE once, PVOID param, PVOID* context)
static const char* initWsaData(WSADATA* wsaData)
{
(void)once;
(void)param;
static WSADATA wsaData;
*context = &wsaData;
if(WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
return FALSE;
if(WSAStartup(MAKEWORD(2, 2), wsaData) != 0)
return "WSAStartup() failed";
if(LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2)
return FALSE;
if(LOBYTE(wsaData->wVersion) != 2 || HIBYTE(wsaData->wVersion) != 2)
return "Invalid wsaData version found";
//Dummy socket needed for WSAIoctl
SOCKET sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(sockfd == INVALID_SOCKET)
return FALSE;
return "socket(AF_INET, SOCK_STREAM) failed";
DWORD dwBytes;
GUID guid = WSAID_CONNECTEX;
@@ -30,28 +26,35 @@ static BOOL WINAPI initWsaData(PINIT_ONCE once, PVOID param, PVOID* context)
&guid, sizeof(guid),
&ConnectEx, sizeof(ConnectEx),
&dwBytes, NULL, NULL) != 0)
return FALSE;
return "WSAIoctl(sockfd, SIO_GET_EXTENSION_FUNCTION_POINTER) failed";
return closesocket(sockfd) == 0;
closesocket(sockfd);
return NULL;
}
bool ffNetworkingSendHttpRequest(FFNetworkingState* state, const char* host, const char* path, const char* headers)
{
static INIT_ONCE once = INIT_ONCE_STATIC_INIT;
WSADATA* pData;
if(!InitOnceExecuteOnce(&once, initWsaData, NULL, (LPVOID*) &pData))
static WSADATA wsaData;
if (wsaData.wVersion == 0)
{
if (initWsaData(&wsaData) != NULL)
{
wsaData.wVersion = (WORD) -1;
return false;
}
}
else if (wsaData.wVersion == (WORD) -1)
return false;
memset(state, 0, sizeof(*state));
struct addrinfo hints = {
.ai_family = AF_INET,
.ai_socktype = SOCK_STREAM,
};
struct addrinfo* addr;
if(getaddrinfo(host, "80", &hints, &addr) != 0)
if(getaddrinfo(host, "80", &(struct addrinfo) {
.ai_family = AF_INET,
.ai_socktype = SOCK_STREAM,
}, &addr) != 0)
return false;
state->sockfd = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
+3 -4
View File
@@ -83,8 +83,7 @@ const char* ffProcessAppendOutput(FFstrbuf* buffer, char* const argv[], bool use
char str[FF_PIPE_BUFSIZ];
DWORD nRead = 0;
FF_AUTO_CLOSE_FD HANDLE hEvent = CreateEventW(NULL, FALSE, FALSE, NULL);
OVERLAPPED overlapped = { .hEvent = hEvent };
OVERLAPPED overlapped = { };
// ReadFile always completes synchronously if the pipe is not created with FILE_FLAG_OVERLAPPED
do
{
@@ -93,11 +92,11 @@ const char* ffProcessAppendOutput(FFstrbuf* buffer, char* const argv[], bool use
switch (GetLastError())
{
case ERROR_IO_PENDING:
if (!timeout || WaitForSingleObject(hEvent, (DWORD) timeout) != WAIT_OBJECT_0)
if (!timeout || WaitForSingleObject(hChildPipeRead, (DWORD) timeout) != WAIT_OBJECT_0)
{
CancelIo(hChildPipeRead);
TerminateProcess(hProcess, 1);
return "WaitForSingleObject(hEvent) failed or timeout";
return "WaitForSingleObject(hChildPipeRead) failed or timeout";
}
if (!GetOverlappedResult(hChildPipeRead, &overlapped, &nRead, FALSE))
+2 -3
View File
@@ -411,9 +411,8 @@ bool ffSettingsGetFreeBSDKenv(const char* propName, FFstrbuf* result)
//https://wiki.ghostbsd.org/index.php/Kenv
ffStrbufEnsureFree(result, KENV_MVALLEN);
int len = kenv(KENV_GET, propName, result->chars + result->length, KENV_MVALLEN);
if (len <= 0) return false;
result->length += (uint32_t) len;
result->chars[result->length] = '\0';
if (len <= 1) return false; // number of bytes copied, including NUL terminator
result->length += (uint32_t) len - 1;
return true;
}
#endif
+13 -23
View File
@@ -82,7 +82,7 @@
}
}
],
"pseudo": [
"General": [
{
"long": "thread",
"desc": "Use separate threads to send HTTP requests",
@@ -842,16 +842,6 @@
"default": "default"
}
},
{
"long": "chassis-use-wmi",
"desc": "Set if WMI query should be used on Windows",
"remark": "WMI query detects more information but is slower. Windows only",
"arg": {
"type": "bool",
"optional": true,
"default": false
}
},
{
"long": "separator-string",
"desc": "Set the string printed by the separator module",
@@ -954,6 +944,15 @@
"type": "str"
}
},
{
"long": "physicaldisk-temp",
"desc": "Detect and display SSD temperature if supported",
"arg": {
"type": "bool",
"optional": true,
"default": false
}
},
{
"long": "bluetooth-show-disconnected",
"desc": "Set if disconnected bluetooth devices should be printed",
@@ -1017,15 +1016,6 @@
"default": "main"
}
},
{
"long": "battery-dir",
"desc": "The directory where the battery folders are",
"remark": "Linux only",
"arg": {
"type": "path",
"default": "/sys/class/power_supply/"
}
},
{
"long": "battery-use-setup-api",
"desc": "Set if \"SetupAPI\" should be used on Windows to detect battery info",
@@ -1082,9 +1072,9 @@
}
},
{
"long": "gpu-use-nvml",
"desc": "Use nvml (NVIDIA Management Library) to detect more detailed GPU information",
"remark": "Detects memory usage, CUDA core count, etc. Requires NVIDIA proprietary driver installed",
"long": "gpu-driver-specific",
"desc": "Use driver specific method to detect more detailed GPU information (memory usage, core count, etc)",
"remark": "Correctly NVML (NVIDIA) and IGCL (Intel, Windows only) are supported. Both require the latest proprietary driver to be installed",
"arg": {
"type": "bool",
"optional": true,
+3 -1
View File
@@ -7,10 +7,12 @@
typedef struct FFBatteryResult
{
FFstrbuf manufacturer;
FFstrbuf manufactureDate;
FFstrbuf modelName;
FFstrbuf technology;
double capacity;
FFstrbuf status;
FFstrbuf serial;
double capacity;
double temperature;
uint32_t cycleCount;
} FFBatteryResult;
+2
View File
@@ -40,6 +40,7 @@ static const char* parseTermuxApi(FFBatteryOptions* options, FFlist* results)
ffStrbufInit(&battery->modelName);
ffStrbufInit(&battery->status);
ffStrbufInit(&battery->technology);
ffStrbufInit(&battery->manufactureDate);
battery->capacity = yyjson_get_num(yyjson_obj_get(root, "percentage"));
ffStrbufAppendS(&battery->status, yyjson_get_str(yyjson_obj_get(root, "status")));
@@ -71,6 +72,7 @@ static const char* parseDumpsys(FFBatteryOptions* options, FFlist* results)
FFBatteryResult* battery = ffListAdd(results);
battery->temperature = FF_BATTERY_TEMP_UNSET;
battery->cycleCount = 0;
ffStrbufInit(&battery->manufacturer);
ffStrbufInit(&battery->modelName);
ffStrbufInit(&battery->status);
+36 -27
View File
@@ -4,49 +4,46 @@
#include "detection/temps/temps_apple.h"
#include <IOKit/IOKitLib.h>
#include <IOKit/pwr_mgt/IOPM.h>
const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results)
{
io_iterator_t iterator;
if(IOServiceGetMatchingServices(MACH_PORT_NULL, IOServiceMatching("AppleSmartBattery"), &iterator) != kIOReturnSuccess)
FF_IOOBJECT_AUTO_RELEASE io_iterator_t iterator = IO_OBJECT_NULL;
if (IOServiceGetMatchingServices(MACH_PORT_NULL, IOServiceMatching("AppleSmartBattery"), &iterator) != kIOReturnSuccess)
return "IOServiceGetMatchingServices() failed";
io_registry_entry_t registryEntry;
while((registryEntry = IOIteratorNext(iterator)) != 0)
while ((registryEntry = IOIteratorNext(iterator)) != IO_OBJECT_NULL)
{
FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t entryBattery = registryEntry;
FF_CFTYPE_AUTO_RELEASE CFMutableDictionaryRef properties = NULL;
if(IORegistryEntryCreateCFProperties(registryEntry, &properties, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess)
{
IOObjectRelease(registryEntry);
if (IORegistryEntryCreateCFProperties(entryBattery, &properties, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess)
continue;
}
bool boolValue;
const char* error;
FFBatteryResult* battery = ffListAdd(results);
battery->temperature = FF_BATTERY_TEMP_UNSET;
ffStrbufInit(&battery->manufacturer);
ffStrbufInit(&battery->modelName);
ffStrbufInit(&battery->serial);
ffStrbufInit(&battery->technology);
ffStrbufInit(&battery->status);
ffStrbufInit(&battery->manufactureDate);
battery->capacity = 0.0/0.0;
int currentCapacity, maxCapacity;
if ((error = ffCfDictGetInt(properties, CFSTR("MaxCapacity"), &maxCapacity)))
return error;
if (maxCapacity <= 0)
return "Querying MaxCapacity failed";
if (ffCfDictGetInt(properties, CFSTR(kIOPMPSMaxCapacityKey), &maxCapacity) != NULL || maxCapacity <= 0)
continue;
if ((error = ffCfDictGetInt(properties, CFSTR("CurrentCapacity"), &currentCapacity)))
return error;
if(currentCapacity <= 0)
return "Querying CurrentCapacity failed";
if (ffCfDictGetInt(properties, CFSTR(kIOPMPSCurrentCapacityKey), &currentCapacity) != NULL || currentCapacity <= 0)
continue;
battery->capacity = currentCapacity * 100.0 / maxCapacity;
ffCfDictGetString(properties, CFSTR("DeviceName"), &battery->modelName);
ffCfDictGetString(properties, CFSTR(kIOPMDeviceNameKey), &battery->modelName);
ffCfDictGetString(properties, CFSTR(kIOPMPSSerialKey), &battery->serial);
if (!ffCfDictGetBool(properties, CFSTR("built-in"), &boolValue) && boolValue)
{
@@ -56,32 +53,44 @@ const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results)
ffStrbufAppendS(&battery->modelName, "Built-in");
}
ffCfDictGetInt(properties, CFSTR("CycleCount"), (int32_t*) &battery->cycleCount);
int32_t cycleCount = 0;
ffCfDictGetInt(properties, CFSTR(kIOPMPSCycleCountKey), &cycleCount);
battery->cycleCount = cycleCount < 0 ? 0 : (uint32_t) cycleCount;
if (!ffCfDictGetBool(properties, CFSTR("ExternalConnected"), &boolValue) && boolValue)
if (!ffCfDictGetBool(properties, CFSTR(kIOPMPSExternalConnectedKey), &boolValue) && boolValue)
ffStrbufAppendS(&battery->status, "AC connected, ");
else
ffStrbufAppendS(&battery->status, "Discharging, ");
if (!ffCfDictGetBool(properties, CFSTR("IsCharging"), &boolValue) && boolValue)
if (!ffCfDictGetBool(properties, CFSTR(kIOPMPSIsChargingKey), &boolValue) && boolValue)
ffStrbufAppendS(&battery->status, "Charging, ");
if (!ffCfDictGetBool(properties, CFSTR("AtCriticalLevel"), &boolValue) && boolValue)
if (!ffCfDictGetBool(properties, CFSTR(kIOPMPSAtCriticalLevelKey), &boolValue) && boolValue)
ffStrbufAppendS(&battery->status, "Critical, ");
ffStrbufTrimRight(&battery->status, ' ');
ffStrbufTrimRight(&battery->status, ',');
CFDictionaryRef batteryData;
if (ffCfDictGetDict(properties, CFSTR("BatteryData"), &batteryData) == NULL)
{
char manufactureDate[sizeof(uint64_t)];
if (ffCfDictGetInt64(batteryData, CFSTR(kIOPMPSManufactureDateKey), (int64_t*) manufactureDate) == NULL)
{
// https://github.com/AsahiLinux/linux/blob/b5c05cbffb0488c7618106926d522cc3b43d93d5/drivers/power/supply/macsmc_power.c#L410-L419
int year = (manufactureDate[0] - '0') * 10 + (manufactureDate[1] - '0') + 2000 - 8;
int month = (manufactureDate[2] - '0') * 10 + (manufactureDate[3] - '0');
int day = (manufactureDate[4] - '0') * 10 + (manufactureDate[3] - '5');
ffStrbufSetF(&battery->manufactureDate, "%.4d-%.2d-%.2d", year, month, day);
}
}
if (options->temp)
{
int64_t temp;
if (!ffCfDictGetInt64(properties, CFSTR("Temperature"), &temp))
if (!ffCfDictGetInt64(properties, CFSTR(kIOPMPSBatteryTemperatureKey), &temp))
battery->temperature = (double) temp / 10 - 273.15;
else
ffDetectCoreTemps(FF_TEMP_BATTERY, &battery->temperature);
ffDetectSmcTemps(FF_TEMP_BATTERY, &battery->temperature);
}
IOObjectRelease(registryEntry);
}
IOObjectRelease(iterator);
return NULL;
}
+2
View File
@@ -39,6 +39,8 @@ const char* ffDetectBattery(FF_MAYBE_UNUSED FFBatteryOptions* options, FFlist* r
ffStrbufInit(&battery->modelName);
ffStrbufInit(&battery->status);
ffStrbufInit(&battery->technology);
ffStrbufInit(&battery->serial);
ffStrbufInit(&battery->manufactureDate);
battery->capacity = battio.battinfo.cap;
if(battio.battinfo.state == ACPI_BATT_STAT_INVALID)
+74 -44
View File
@@ -9,103 +9,133 @@ static void parseBattery(FFstrbuf* dir, const char* id, FFBatteryOptions* option
{
uint32_t dirLength = dir->length;
FF_STRBUF_AUTO_DESTROY testBatteryBuffer = ffStrbufCreate();
FF_STRBUF_AUTO_DESTROY tmpBuffer = ffStrbufCreate();
//type must exist and be "Battery"
ffStrbufAppendS(dir, "/type");
ffReadFileBuffer(dir->chars, &testBatteryBuffer);
if (ffReadFileBuffer(dir->chars, &tmpBuffer))
ffStrbufTrimRightSpace(&tmpBuffer);
ffStrbufSubstrBefore(dir, dirLength);
if(ffStrbufIgnCaseCompS(&testBatteryBuffer, "Battery") != 0)
if(!ffStrbufIgnCaseEqualS(&tmpBuffer, "Battery"))
return;
//scope may not exist or must not be "Device"
ffStrbufAppendS(dir, "/scope");
ffReadFileBuffer(dir->chars, &testBatteryBuffer);
if (ffReadFileBuffer(dir->chars, &tmpBuffer))
ffStrbufTrimRightSpace(&tmpBuffer);
ffStrbufSubstrBefore(dir, dirLength);
if(ffStrbufIgnCaseCompS(&testBatteryBuffer, "Device") == 0)
if(ffStrbufIgnCaseEqualS(&tmpBuffer, "Device"))
return;
FFBatteryResult* result = ffListAdd(results);
//capacity must exist and be not empty
ffStrbufAppendS(dir, "/capacity");
bool available = ffReadFileBuffer(dir->chars, &testBatteryBuffer);
bool available = ffReadFileBuffer(dir->chars, &tmpBuffer);
ffStrbufSubstrBefore(dir, dirLength);
if(available)
result->capacity = ffStrbufToDouble(&testBatteryBuffer);
if(!available)
{
result->capacity = 0.0/0.0;
--results->length;
if (!available)
return;
}
FFBatteryResult* result = ffListAdd(results);
result->capacity = ffStrbufToDouble(&tmpBuffer);
//At this point, we have a battery. Try to get as much values as possible.
ffStrbufInit(&result->manufacturer);
ffStrbufAppendS(dir, "/manufacturer");
ffReadFileBuffer(dir->chars, &result->manufacturer);
if (ffReadFileBuffer(dir->chars, &result->manufacturer))
ffStrbufTrimRightSpace(&result->manufacturer);
else if (ffStrEquals(id, "macsmc-battery")) // asahi
ffStrbufSetStatic(&result->manufacturer, "Apple Inc.");
ffStrbufSubstrBefore(dir, dirLength);
ffStrbufInit(&result->modelName);
ffStrbufAppendS(dir, "/model_name");
ffReadFileBuffer(dir->chars, &result->modelName);
if (ffReadFileBuffer(dir->chars, &result->modelName))
ffStrbufTrimRightSpace(&result->modelName);
ffStrbufSubstrBefore(dir, dirLength);
ffStrbufInit(&result->technology);
ffStrbufAppendS(dir, "/technology");
ffReadFileBuffer(dir->chars, &result->technology);
if (ffReadFileBuffer(dir->chars, &result->technology))
ffStrbufTrimRightSpace(&result->technology);
ffStrbufSubstrBefore(dir, dirLength);
ffStrbufInit(&result->status);
ffStrbufAppendS(dir, "/status");
ffReadFileBuffer(dir->chars, &result->status);
if (ffReadFileBuffer(dir->chars, &result->status))
ffStrbufTrimRightSpace(&result->status);
ffStrbufSubstrBefore(dir, dirLength);
ffStrbufInit(&result->serial);
ffStrbufAppendS(dir, "/serial_number");
if (ffReadFileBuffer(dir->chars, &result->serial))
ffStrbufTrimRightSpace(&result->serial);
ffStrbufSubstrBefore(dir, dirLength);
ffStrbufAppendS(dir, "/cycle_count");
ffReadFileBuffer(dir->chars, &testBatteryBuffer);
available = ffReadFileBuffer(dir->chars, &tmpBuffer);
ffStrbufSubstrBefore(dir, dirLength);
if(dir->length)
result->cycleCount = (uint32_t) ffStrbufToUInt(&testBatteryBuffer, 0);
if (available)
{
int64_t cycleCount = ffStrbufToSInt(&tmpBuffer, 0);
result->cycleCount = cycleCount < 0 || cycleCount > UINT32_MAX ? 0 : (uint32_t) cycleCount;
}
ffStrbufInit(&result->manufactureDate);
ffStrbufAppendS(dir, "/manufacture_year");
available = ffReadFileBuffer(dir->chars, &tmpBuffer);
ffStrbufSubstrBefore(dir, dirLength);
if (available)
{
int year = (int) ffStrbufToSInt(&tmpBuffer, 0);
if (year > 0)
{
ffStrbufAppendS(dir, "/manufacture_month");
available = ffReadFileBuffer(dir->chars, &tmpBuffer);
ffStrbufSubstrBefore(dir, dirLength);
if (available)
{
int month = (int) ffStrbufToSInt(&tmpBuffer, 0);
if (month > 0)
{
ffStrbufAppendS(dir, "/manufacture_day");
available = ffReadFileBuffer(dir->chars, &tmpBuffer);
ffStrbufSubstrBefore(dir, dirLength);
if (available)
{
int day = (int) ffStrbufToSInt(&tmpBuffer, 0);
if (day > 0)
{
ffStrbufSetF(&result->manufactureDate, "%.4d-%.2d-%.2d", year, month, day);
}
}
}
}
}
}
result->temperature = FF_BATTERY_TEMP_UNSET;
if (options->temp)
{
const FFlist* tempsResult = ffDetectTemps();
FF_LIST_FOR_EACH(FFTempValue, value, *tempsResult)
{
if (ffStrbufEqualS(&value->name, id))
{
result->temperature = value->value;
break;
}
}
ffStrbufAppendS(dir, "/temp");
if (ffReadFileBuffer(dir->chars, &tmpBuffer))
result->temperature = ffStrbufToDouble(&tmpBuffer) / 10;
ffStrbufSubstrBefore(dir, dirLength);
}
}
const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results)
{
FF_STRBUF_AUTO_DESTROY baseDir = ffStrbufCreateA(64);
if(options->dir.length > 0)
{
ffStrbufAppend(&baseDir, &options->dir);
ffStrbufEnsureEndsWithC(&baseDir, '/');
}
else
{
ffStrbufAppendS(&baseDir, "/sys/class/power_supply/");
}
ffStrbufAppendS(&baseDir, "/sys/class/power_supply/");
uint32_t baseDirLength = baseDir.length;
FF_AUTO_CLOSE_DIR DIR* dirp = opendir(baseDir.chars);
if(dirp == NULL)
return "opendir(batteryDir) == NULL";
return "opendir(\"/sys/class/power_supply/\") == NULL";
struct dirent* entry;
while((entry = readdir(dirp)) != NULL)
@@ -119,7 +149,7 @@ const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results)
}
if(results->length == 0)
return "batteryDir doesn't contain any battery folder";
return "\"/sys/class/power_supply/\" doesn't contain any battery folder";
return NULL;
}
+109 -10
View File
@@ -1,6 +1,7 @@
#include "battery.h"
#include "util/windows/unicode.h"
#include "util/mallocHelper.h"
#include "util/smbiosHelper.h"
#undef WIN32_LEAN_AND_MEAN
#include <windows.h>
@@ -75,19 +76,19 @@ static const char* detectWithSetupApi(FFBatteryOptions* options, FFlist* results
FFBatteryResult* battery = (FFBatteryResult*)ffListAdd(results);
if(memcmp(bi.Chemistry, "PbAc", 4) == 0)
ffStrbufInitS(&battery->technology, "Lead Acid");
ffStrbufInitStatic(&battery->technology, "Lead Acid");
else if(memcmp(bi.Chemistry, "LION", 4) == 0 || memcmp(bi.Chemistry, "Li-I", 4) == 0)
ffStrbufInitS(&battery->technology, "Lithium Ion");
ffStrbufInitStatic(&battery->technology, "Lithium Ion");
else if(memcmp(bi.Chemistry, "NiCd", 4) == 0)
ffStrbufInitS(&battery->technology, "Nickel Cadmium");
ffStrbufInitStatic(&battery->technology, "Nickel Cadmium");
else if(memcmp(bi.Chemistry, "NiMH", 4) == 0)
ffStrbufInitS(&battery->technology, "Nickel Metal Hydride");
ffStrbufInitStatic(&battery->technology, "Nickel Metal Hydride");
else if(memcmp(bi.Chemistry, "NiZn", 4) == 0)
ffStrbufInitS(&battery->technology, "Nickel Zinc");
ffStrbufInitStatic(&battery->technology, "Nickel Zinc");
else if(memcmp(bi.Chemistry, "RAM\0", 4) == 0)
ffStrbufInitS(&battery->technology, "Rechargeable Alkaline-Manganese");
ffStrbufInitStatic(&battery->technology, "Rechargeable Alkaline-Manganese");
else
ffStrbufInitS(&battery->technology, "Unknown");
ffStrbufInitStatic(&battery->technology, "Unknown");
{
ffStrbufInit(&battery->modelName);
@@ -105,6 +106,22 @@ static const char* detectWithSetupApi(FFBatteryOptions* options, FFlist* results
ffStrbufSetWS(&battery->manufacturer, name);
}
{
ffStrbufInit(&battery->manufactureDate);
bqi.InformationLevel = BatteryManufactureDate;
BATTERY_MANUFACTURE_DATE date;
if(DeviceIoControl(hBattery, IOCTL_BATTERY_QUERY_INFORMATION, &bqi, sizeof(bqi), &date, sizeof(date), &dwOut, NULL))
ffStrbufSetF(&battery->manufactureDate, "%.4d-%.2d-%.2d", date.Year + 1900, date.Month, date.Day);
}
{
ffStrbufInit(&battery->serial);
bqi.InformationLevel = BatterySerialNumber;
wchar_t name[64];
if(DeviceIoControl(hBattery, IOCTL_BATTERY_QUERY_INFORMATION, &bqi, sizeof(bqi), name, sizeof(name), &dwOut, NULL))
ffStrbufSetWS(&battery->serial, name);
}
battery->cycleCount = bi.CycleCount;
battery->temperature = 0.0/0.0;
@@ -113,7 +130,7 @@ static const char* detectWithSetupApi(FFBatteryOptions* options, FFlist* results
bqi.InformationLevel = BatteryTemperature;
ULONG temp;
if(DeviceIoControl(hBattery, IOCTL_BATTERY_QUERY_INFORMATION, &bqi, sizeof(bqi), &temp, sizeof(temp), &dwOut, NULL))
battery->temperature = temp;
battery->temperature = temp / 10.0 - 273.15;
}
{
@@ -140,6 +157,83 @@ static const char* detectWithSetupApi(FFBatteryOptions* options, FFlist* results
return NULL;
}
typedef struct FFSmbiosPortableBattery
{
FFSmbiosHeader Header;
// 2.1+
uint8_t Location; // string
uint8_t Manufacturer; // string
uint8_t ManufactureDate; // string
uint8_t SerialNumber; // string
uint8_t DeviceName; // string
uint8_t DeviceChemistry; // enum
uint16_t DesignCapacity; // varies
uint16_t DesignVoltage; // varies
uint8_t SbdsVersionNumber; // string
uint8_t MaximumErrorInBatteryData; // varies
// 2.2+
uint16_t SbdsSerialNumber; // varies
uint16_t SbdsManufactureDate; // varies
uint8_t SbdsDeviceChemistry; // string
uint8_t DesignCapacityMultiplier; // varies
uint16_t OEMSpecific; // varies
} FFSmbiosPortableBattery;
const char* detectBySmbios(FFBatteryResult* battery)
{
const FFSmbiosPortableBattery* data = (const FFSmbiosPortableBattery*) (*ffGetSmbiosHeaderTable())[FF_SMBIOS_TYPE_PORTABLE_BATTERY];
if (!data)
return "Portable battery section is not found in SMBIOS data";
const char* strings = (const char*) data + data->Header.Length;
ffStrbufSetStatic(&battery->modelName, ffSmbiosLocateString(strings, data->DeviceName));
ffCleanUpSmbiosValue(&battery->modelName);
ffStrbufSetStatic(&battery->manufacturer, ffSmbiosLocateString(strings, data->Manufacturer));
ffCleanUpSmbiosValue(&battery->manufacturer);
if (data->ManufactureDate)
{
ffStrbufSetStatic(&battery->manufactureDate, ffSmbiosLocateString(strings, data->ManufactureDate));
ffCleanUpSmbiosValue(&battery->manufactureDate);
}
else if (data->Header.Length > offsetof(FFSmbiosPortableBattery, SbdsManufactureDate))
{
uint16_t day = data->SbdsManufactureDate & 0b11111;
uint16_t month = (data->SbdsManufactureDate >> 5) & 0b1111;
uint16_t year = (data->SbdsManufactureDate >> 9) + 1800;
ffStrbufSetF(&battery->manufactureDate, "%.4d-%.2d-%.2d", year, month, day);
}
switch (data->DeviceChemistry)
{
case 0x01: ffStrbufSetStatic(&battery->technology, "Other"); break;
case 0x02: ffStrbufSetStatic(&battery->technology, "Unknown"); break;
case 0x03: ffStrbufSetStatic(&battery->technology, "Lead Acid"); break;
case 0x04: ffStrbufSetStatic(&battery->technology, "Nickel Cadmium"); break;
case 0x05: ffStrbufSetStatic(&battery->technology, "Nickel metal hydride"); break;
case 0x06: ffStrbufSetStatic(&battery->technology, "Lithium-ion"); break;
case 0x07: ffStrbufSetStatic(&battery->technology, "Zinc air"); break;
case 0x08: ffStrbufSetStatic(&battery->technology, "Lithium Polymer"); break;
}
if (data->SerialNumber)
{
ffStrbufSetStatic(&battery->serial, ffSmbiosLocateString(strings, data->SerialNumber));
ffCleanUpSmbiosValue(&battery->serial);
}
else if (data->Header.Length > offsetof(FFSmbiosPortableBattery, SbdsSerialNumber))
{
ffStrbufSetF(&battery->serial, "%4X", data->SbdsSerialNumber);
}
return NULL;
}
static const char* detectWithNtApi(FF_MAYBE_UNUSED FFBatteryOptions* options, FFlist* results)
{
SYSTEM_BATTERY_STATE info;
@@ -148,9 +242,11 @@ static const char* detectWithNtApi(FF_MAYBE_UNUSED FFBatteryOptions* options, FF
FFBatteryResult* battery = (FFBatteryResult*)ffListAdd(results);
ffStrbufInit(&battery->modelName);
ffStrbufInit(&battery->manufacturer);
ffStrbufInit(&battery->manufactureDate);
ffStrbufInit(&battery->technology);
ffStrbufInit(&battery->status);
battery->temperature = 0.0/0.0;
ffStrbufInit(&battery->serial);
battery->temperature = FF_BATTERY_TEMP_UNSET;
battery->cycleCount = 0;
battery->capacity = info.RemainingCapacity * 100.0 / info.MaxCapacity;
@@ -162,6 +258,9 @@ static const char* detectWithNtApi(FF_MAYBE_UNUSED FFBatteryOptions* options, FF
}
else if(info.Discharging)
ffStrbufAppendS(&battery->status, "Discharging");
detectBySmbios(battery);
return NULL;
}
return "NtPowerInformation(SystemBatteryState) failed";
@@ -169,7 +268,7 @@ static const char* detectWithNtApi(FF_MAYBE_UNUSED FFBatteryOptions* options, FF
const char* ffDetectBattery(FFBatteryOptions* options, FFlist* results)
{
return true
return options->useSetupApi
? detectWithSetupApi(options, results)
: detectWithNtApi(options, results);
}
+14
View File
@@ -2,6 +2,7 @@
#include "common/settings.h"
#include "common/sysctl.h"
#include "common/io/io.h"
#include "util/smbiosHelper.h"
const char* ffDetectBios(FFBiosResult* result)
@@ -15,5 +16,18 @@ const char* ffDetectBios(FFBiosResult* result)
ffSettingsGetFreeBSDKenv("smbios.bios.version", &result->version);
ffCleanUpSmbiosValue(&result->version);
ffSysctlGetString("machdep.bootmethod", &result->type);
if (result->type.length == 0)
{
if (ffSettingsGetFreeBSDKenv("loader.efi", &result->type))
ffStrbufSetStatic(&result->type, ffStrbufEqualS(&result->type, "1") ? "UEFI" : "BIOS");
else
{
ffStrbufSetStatic(&result->type,
ffPathExists("/dev/efi" /*efidev*/, FF_PATHTYPE_FILE) ||
ffPathExists("/boot/efi/efi" /*efi partition*/, FF_PATHTYPE_DIRECTORY)
? "UEFI" : "BIOS");
}
}
return NULL;
}
+5 -18
View File
@@ -4,25 +4,12 @@
#include <stdlib.h>
static void getSmbiosValue(const char* devicesPath, const char* classPath, FFstrbuf* buffer)
const char* ffDetectBios(FFBiosResult* bios)
{
ffReadFileBuffer(devicesPath, buffer);
if(ffIsSmbiosValueSet(buffer))
return;
ffReadFileBuffer(classPath, buffer);
if(ffIsSmbiosValueSet(buffer))
return;
ffStrbufClear(buffer);
}
const char* ffDetectBios(FFBiosResult* bios)
{
getSmbiosValue("/sys/devices/virtual/dmi/id/bios_date", "/sys/class/dmi/id/bios_date", &bios->date);
getSmbiosValue("/sys/devices/virtual/dmi/id/bios_release", "/sys/class/dmi/id/bios_release", &bios->release);
getSmbiosValue("/sys/devices/virtual/dmi/id/bios_vendor", "/sys/class/dmi/id/bios_vendor", &bios->vendor);
getSmbiosValue("/sys/devices/virtual/dmi/id/bios_version", "/sys/class/dmi/id/bios_version", &bios->version);
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/bios_date", "/sys/class/dmi/id/bios_date", &bios->date);
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/bios_release", "/sys/class/dmi/id/bios_release", &bios->release);
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/bios_vendor", "/sys/class/dmi/id/bios_vendor", &bios->vendor);
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/bios_version", "/sys/class/dmi/id/bios_version", &bios->version);
if (ffPathExists("/sys/firmware/efi", FF_PATHTYPE_DIRECTORY) || ffPathExists("/sys/firmware/acpi/tables/UEFI", FF_PATHTYPE_FILE))
ffStrbufSetStatic(&bios->type, "UEFI");
else
+32 -14
View File
@@ -1,5 +1,4 @@
#include "bios.h"
#include "util/windows/registry.h"
#include "util/smbiosHelper.h"
#include <ntstatus.h>
@@ -26,27 +25,46 @@ typedef struct _SYSTEM_BOOT_ENVIRONMENT_INFORMATION
};
} SYSTEM_BOOT_ENVIRONMENT_INFORMATION;
typedef struct FFSmbiosBios
{
FFSmbiosHeader Header;
uint8_t Vendor; // string
uint8_t BiosVersion; // string
uint16_t BiosStartingAddressSegment; // varies
uint8_t BiosReleaseDate; // string
uint8_t BiosRomSize; // string
uint32_t BiosCharacteristics; // bit field
// 2.4+
uint8_t BiosCharacteristicsExtensionBytes[2]; // bit field
uint8_t SystemBiosMajorRelease; // varies
uint8_t SystemBiosMinorRelease; // varies
uint8_t EmbeddedControllerFirmwareMajorRelease; // varies
uint8_t EmbeddedControllerFirmwareMinorRelease; // varies
// 3.1+
uint16_t ExtendedBiosRomSize; // bit field
} FFSmbiosBios;
const char* ffDetectBios(FFBiosResult* bios)
{
FF_HKEY_AUTO_DESTROY hKey = NULL;
if(!ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\BIOS", &hKey, NULL))
return "ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L\"HARDWARE\\DESCRIPTION\\System\\BIOS\", &hKey, NULL) failed";
const FFSmbiosBios* data = (const FFSmbiosBios*) (*ffGetSmbiosHeaderTable())[FF_SMBIOS_TYPE_BIOS];
if (!data)
return "BIOS section is not found in SMBIOS data";
if(!ffRegReadStrbuf(hKey, L"BIOSVersion", &bios->version, NULL))
return "\"HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\BIOS\\BIOSVersion\" doesn't exist";
const char* strings = (const char*) data + data->Header.Length;
ffStrbufSetStatic(&bios->version, ffSmbiosLocateString(strings, data->BiosVersion));
ffCleanUpSmbiosValue(&bios->version);
ffRegReadStrbuf(hKey, L"BIOSVendor", &bios->vendor, NULL);
ffStrbufSetStatic(&bios->vendor, ffSmbiosLocateString(strings, data->Vendor));
ffCleanUpSmbiosValue(&bios->vendor);
ffRegReadStrbuf(hKey, L"BIOSReleaseDate", &bios->date, NULL);
ffStrbufSetStatic(&bios->date, ffSmbiosLocateString(strings, data->BiosReleaseDate));
ffCleanUpSmbiosValue(&bios->date);
uint32_t major, minor;
if(
ffRegReadUint(hKey, L"BiosMajorRelease", &major, NULL) &&
ffRegReadUint(hKey, L"BiosMinorRelease", &minor, NULL)
)
ffStrbufAppendF(&bios->release, "%u.%u", (unsigned)major, (unsigned)minor);
if (data->Header.Length > offsetof(FFSmbiosBios, SystemBiosMajorRelease))
ffStrbufSetF(&bios->release, "%u.%u", data->SystemBiosMajorRelease, data->SystemBiosMinorRelease);
// Same as GetFirmwareType, but support (?) Windows 7
// https://ntdoc.m417z.com/system_information_class
+1
View File
@@ -7,6 +7,7 @@ typedef struct FFBoardResult
FFstrbuf name;
FFstrbuf vendor;
FFstrbuf version;
FFstrbuf serial;
} FFBoardResult;
const char* ffDetectBoard(FFBoardResult* board);
+12 -4
View File
@@ -1,13 +1,21 @@
#include "board.h"
#include "common/sysctl.h"
#include "util/apple/cf_helpers.h"
const char* ffDetectBoard(FFBoardResult* result)
{
const char* error = ffSysctlGetString("hw.model", &result->name);
if (error)
return error;
FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t service = IOServiceGetMatchingService(MACH_PORT_NULL, IOServiceMatching("IOPlatformExpertDevice"));
if (!service)
return "No IOPlatformExpertDevice found";
io_name_t name;
if (IORegistryEntryGetName(service, name) == kIOReturnSuccess)
ffStrbufSetS(&result->name, name);
FF_CFTYPE_AUTO_RELEASE CFTypeRef manufacturer = IORegistryEntryCreateCFProperty(service, CFSTR("manufacturer"), kCFAllocatorDefault, kNilOptions);
if (manufacturer)
ffCfStrGetString(manufacturer, &result->vendor);
ffStrbufSetStatic(&result->vendor, "Apple");
return NULL;
}
+2
View File
@@ -6,6 +6,8 @@ const char* ffDetectBoard(FFBoardResult* result)
{
ffSettingsGetFreeBSDKenv("smbios.planar.product", &result->name);
ffCleanUpSmbiosValue(&result->name);
ffSettingsGetFreeBSDKenv("smbios.planar.serial", &result->serial);
ffCleanUpSmbiosValue(&result->serial);
ffSettingsGetFreeBSDKenv("smbios.planar.maker", &result->vendor);
ffCleanUpSmbiosValue(&result->vendor);
ffSettingsGetFreeBSDKenv("smbios.planar.version", &result->version);
+4 -16
View File
@@ -4,23 +4,11 @@
#include <stdlib.h>
static void getSmbiosValue(const char* devicesPath, const char* classPath, FFstrbuf* buffer)
{
ffReadFileBuffer(devicesPath, buffer);
if(ffIsSmbiosValueSet(buffer))
return;
ffReadFileBuffer(classPath, buffer);
if(ffIsSmbiosValueSet(buffer))
return;
ffStrbufClear(buffer);
}
const char* ffDetectBoard(FFBoardResult* board)
{
getSmbiosValue("/sys/devices/virtual/dmi/id/board_name", "/sys/class/dmi/id/board_name", &board->name);
getSmbiosValue("/sys/devices/virtual/dmi/id/board_vendor", "/sys/class/dmi/id/board_vendor", &board->vendor);
getSmbiosValue("/sys/devices/virtual/dmi/id/board_version", "/sys/class/dmi/id/board_version", &board->version);
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/board_name", "/sys/class/dmi/id/board_name", &board->name);
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/board_serial", "/sys/class/dmi/id/board_serial", &board->serial);
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/board_vendor", "/sys/class/dmi/id/board_vendor", &board->vendor);
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/board_version", "/sys/class/dmi/id/board_version", &board->version);
return NULL;
}
+26 -9
View File
@@ -1,21 +1,38 @@
#include "board.h"
#include "util/windows/registry.h"
#include "util/smbiosHelper.h"
typedef struct FFSmbiosBaseboard
{
FFSmbiosHeader Header;
uint8_t Manufacturer; // string
uint8_t Product; // string
uint8_t Version; // string
uint8_t SerialNumber; // string
uint8_t AssetTag; // string
uint8_t FeatureFlags; // bit field
uint8_t LocationInChassis; // string
uint16_t ChassisHandle; // varies
uint8_t BoardType; // enum
uint8_t NumberOfContainedObjectHandle; // varies
uint16_t ContainedObjectHandle[]; // varies
} FFSmbiosBaseboard;
const char* ffDetectBoard(FFBoardResult* board)
{
FF_HKEY_AUTO_DESTROY hKey = NULL;
const FFSmbiosBaseboard* data = (const FFSmbiosBaseboard*) (*ffGetSmbiosHeaderTable())[FF_SMBIOS_TYPE_BASEBOARD_INFO];
if (!data)
return "Baseboard information section is not found in SMBIOS data";
if(!ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\BIOS", &hKey, NULL))
return "ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L\"HARDWARE\\DESCRIPTION\\System\\BIOS\") failed";
if(!ffRegReadStrbuf(hKey, L"BaseBoardProduct", &board->name, NULL))
return "ffRegReadStrbuf(hKey, L\"BaseBoardProduct\") failed";
const char* strings = (const char*) data + data->Header.Length;
ffStrbufSetStatic(&board->name, ffSmbiosLocateString(strings, data->Product));
ffCleanUpSmbiosValue(&board->name);
ffRegReadStrbuf(hKey, L"BaseBoardManufacturer", &board->vendor, NULL);
ffStrbufSetStatic(&board->serial, ffSmbiosLocateString(strings, data->SerialNumber));
ffCleanUpSmbiosValue(&board->serial);
ffStrbufSetStatic(&board->vendor, ffSmbiosLocateString(strings, data->Manufacturer));
ffCleanUpSmbiosValue(&board->vendor);
ffRegReadStrbuf(hKey, L"BaseBoardVersion", &board->version, NULL);
ffStrbufSetStatic(&board->version, ffSmbiosLocateString(strings, data->Version));
ffCleanUpSmbiosValue(&board->version);
return NULL;
+22 -22
View File
@@ -57,35 +57,35 @@ static const char* detectWithDdcci(FF_MAYBE_UNUSED const FFDisplayServerResult*
if (!IOAVServiceCreate || !IOAVServiceReadI2C)
return "IOAVService is not available";
io_iterator_t iterator;
if(IOServiceGetMatchingServices(MACH_PORT_NULL, IOServiceMatching("DCPAVServiceProxy"), &iterator) != kIOReturnSuccess)
FF_IOOBJECT_AUTO_RELEASE io_iterator_t iterator = IO_OBJECT_NULL;
if (IOServiceGetMatchingServices(MACH_PORT_NULL, IOServiceMatching("DCPAVServiceProxy"), &iterator) != kIOReturnSuccess)
return "IOServiceGetMatchingServices() failed";
FF_STRBUF_AUTO_DESTROY location = ffStrbufCreate();
io_registry_entry_t registryEntry;
while((registryEntry = IOIteratorNext(iterator)) != 0)
while ((registryEntry = IOIteratorNext(iterator)) != IO_OBJECT_NULL)
{
CFMutableDictionaryRef properties;
if(IORegistryEntryCreateCFProperties(registryEntry, &properties, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess)
FF_CFTYPE_AUTO_RELEASE IOAVServiceRef service = NULL;
{
IOObjectRelease(registryEntry);
continue;
FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t entryAv = registryEntry;
FF_CFTYPE_AUTO_RELEASE CFBooleanRef IOAVServiceUserInterfaceSupported = IORegistryEntryCreateCFProperty(entryAv, CFSTR("IOAVServiceUserInterfaceSupported"), kCFAllocatorDefault, kNilOptions);
if (IOAVServiceUserInterfaceSupported && !CFBooleanGetValue(IOAVServiceUserInterfaceSupported))
{
// IOAVServiceCreateWithService won't work
continue;
}
FF_CFTYPE_AUTO_RELEASE CFStringRef location = IORegistryEntryCreateCFProperty(entryAv, CFSTR("Location"), kCFAllocatorDefault, kNilOptions);
if (location && CFStringCompare(location, CFSTR("Embedded"), 0) == 0)
{
// Builtin display should be handled by DisplayServices
continue;
}
service = IOAVServiceCreateWithService(kCFAllocatorDefault, (io_service_t) registryEntry);
if (!service) continue;
}
ffStrbufClear(&location);
if(ffCfDictGetString(properties, CFSTR("Location"), &location) || ffStrbufEqualS(&location, "Embedded"))
{
// Builtin display should be handled by DisplayServices
IOObjectRelease(registryEntry);
continue;
}
FF_CFTYPE_AUTO_RELEASE IOAVServiceRef service = IOAVServiceCreateWithService(kCFAllocatorDefault, (io_service_t) registryEntry);
IOObjectRelease(registryEntry);
if (!service) continue;
{
uint8_t i2cIn[4] = { 0x82, 0x01, 0x10 /* luminance */ };
i2cIn[3] = 0x6e ^ i2cIn[0] ^ i2cIn[1] ^ i2cIn[2];
@@ -36,6 +36,8 @@ const char* ffDetectBrightness(FF_MAYBE_UNUSED FFBrightnessOptions* options, FFl
struct backlight_info info;
if(ioctl(blfd, BACKLIGHTGETINFO, &info) < 0)
ffStrbufAppendS(&brightness->name, info.name);
else
ffStrbufAppendS(&brightness->name, path + strlen("/dev/backlight/"));
}
return NULL;
}
+2 -2
View File
@@ -58,9 +58,9 @@ static const char* detectWithBacklight(FFlist* result)
{
ffStrbufSubstrBeforeLastC(&brightness->name, '/'); // remove "/edid"
ffStrbufSubstrAfterLastC(&brightness->name, '/'); // try getting DRM connector name
if(ffStrbufStartsWithS(&brightness->name, "0000:"))
if(isdigit(brightness->name.chars[0]))
{
// PCI address, give up
// PCI address or some unknown path, give up
ffStrbufSetS(&brightness->name, entry->d_name);
}
else
+2 -2
View File
@@ -2,9 +2,9 @@
const char* ffChassisTypeToString(uint32_t type)
{
// https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.2.0.pdf
// https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.7.0.pdf
// 7.4.1 System Enclosure or Chassis Types
switch (type)
switch (type & 0b01111111)
{
case 0x01: return "Other";
case 0x02: return "Unknown";
+2 -1
View File
@@ -5,9 +5,10 @@
typedef struct FFChassisResult
{
FFstrbuf type;
FFstrbuf serial;
FFstrbuf vendor;
FFstrbuf version;
} FFChassisResult;
const char* ffDetectChassis(FFChassisResult* result, FFChassisOptions* options);
const char* ffDetectChassis(FFChassisResult* result);
const char* ffChassisTypeToString(uint32_t type);
+3 -1
View File
@@ -2,13 +2,15 @@
#include "common/settings.h"
#include "util/smbiosHelper.h"
const char* ffDetectChassis(FFChassisResult* result, FF_MAYBE_UNUSED FFChassisOptions* options)
const char* ffDetectChassis(FFChassisResult* result)
{
// Unlike other platforms, `smbios.chassis.type` return display string directly on my machine
ffSettingsGetFreeBSDKenv("smbios.chassis.type", &result->type);
ffCleanUpSmbiosValue(&result->type);
ffSettingsGetFreeBSDKenv("smbios.chassis.maker", &result->vendor);
ffCleanUpSmbiosValue(&result->vendor);
ffSettingsGetFreeBSDKenv("smbios.chassis.serial", &result->serial);
ffCleanUpSmbiosValue(&result->serial);
ffSettingsGetFreeBSDKenv("smbios.chassis.version", &result->version);
ffCleanUpSmbiosValue(&result->version);
return NULL;
+5 -17
View File
@@ -4,24 +4,12 @@
#include <stdlib.h>
static void getSmbiosValue(const char* devicesPath, const char* classPath, FFstrbuf* buffer)
const char* ffDetectChassis(FFChassisResult* result)
{
ffReadFileBuffer(devicesPath, buffer);
if(ffIsSmbiosValueSet(buffer))
return;
ffReadFileBuffer(classPath, buffer);
if(ffIsSmbiosValueSet(buffer))
return;
ffStrbufClear(buffer);
}
const char* ffDetectChassis(FFChassisResult* result, FF_MAYBE_UNUSED FFChassisOptions* options)
{
getSmbiosValue("/sys/devices/virtual/dmi/id/chassis_type", "/sys/class/dmi/id/chassis_type", &result->type);
getSmbiosValue("/sys/devices/virtual/dmi/id/chassis_vendor", "/sys/class/dmi/id/chassis_vendor", &result->vendor);
getSmbiosValue("/sys/devices/virtual/dmi/id/chassis_version", "/sys/class/dmi/id/chassis_version", &result->version);
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/chassis_type", "/sys/class/dmi/id/chassis_type", &result->type);
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/chassis_serial", "/sys/class/dmi/id/chassis_serial", &result->serial);
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/chassis_vendor", "/sys/class/dmi/id/chassis_vendor", &result->vendor);
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/chassis_version", "/sys/class/dmi/id/chassis_version", &result->version);
if(result->type.length)
{
+1 -1
View File
@@ -1,6 +1,6 @@
#include "chassis.h"
const char* ffDetectChassis(FF_MAYBE_UNUSED FFChassisResult* result, FF_MAYBE_UNUSED FFChassisOptions* options)
const char* ffDetectChassis(FF_MAYBE_UNUSED FFChassisResult* result)
{
return "Not supported on this platform";
}
+47
View File
@@ -0,0 +1,47 @@
#include "chassis.h"
#include "util/smbiosHelper.h"
// 7.4
typedef struct FFSmbiosSystemEnclosure
{
FFSmbiosHeader Header;
uint8_t Manufacturer; // string
uint8_t Type; // varies
uint8_t Version; // string
uint8_t SerialNumber; // string
uint8_t AssetTagNumber; // string
// 2.1+
uint8_t BootupState; // enum
uint8_t PowerSupplyState; // enum
uint8_t ThermalState; // enum
uint8_t SecurityStatus; // enum
// 2.3+
uint32_t OEMDefined; // varies
uint8_t Height; // varies
uint8_t NumberOfPowerCords; // varies
uint8_t ContainedElementCount; // varies
uint8_t ContainedRecordLength; // varies
uint8_t ContainedElements[]; // varies
} FFSmbiosSystemEnclosure;
const char* ffDetectChassis(FFChassisResult* result)
{
const FFSmbiosSystemEnclosure* data = (const FFSmbiosSystemEnclosure*) (*ffGetSmbiosHeaderTable())[FF_SMBIOS_TYPE_SYSTEM_ENCLOSURE];
if (!data)
return "System enclosure is not found in SMBIOS data";
const char* strings = (const char*) data + data->Header.Length;
ffStrbufSetStatic(&result->vendor, ffSmbiosLocateString(strings, data->Manufacturer));
ffCleanUpSmbiosValue(&result->vendor);
ffStrbufSetStatic(&result->serial, ffSmbiosLocateString(strings, data->SerialNumber));
ffCleanUpSmbiosValue(&result->serial);
ffStrbufSetStatic(&result->version, ffSmbiosLocateString(strings, data->Version));
ffCleanUpSmbiosValue(&result->version);
ffStrbufSetStatic(&result->type, ffChassisTypeToString(data->Type));
return NULL;
}
-73
View File
@@ -1,73 +0,0 @@
extern "C" {
#include "chassis.h"
#include "util/windows/registry.h"
#include "util/smbiosHelper.h"
}
#include "util/windows/unicode.hpp"
#include "util/windows/wmi.hpp"
static const char* detectWithRegistry(FFChassisResult* result)
{
FF_HKEY_AUTO_DESTROY hKey = NULL;
if(!ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\BIOS", &hKey, NULL)) // SMBIOS
return "ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L\"HARDWARE\\DESCRIPTION\\System\\BIOS\", &hKey, NULL) failed";
uint32_t type = 0;
if(!ffRegReadUint(hKey, L"EnclosureType", &type, NULL))
return "\"HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\BIOS\\EnclosureType\" doesn't exist";
const char* typeStr = ffChassisTypeToString(type);
if(!typeStr)
return "Unknown chassis type";
ffStrbufAppendS(&result->type, typeStr);
return NULL;
}
FF_MAYBE_UNUSED static const char* detectWithWmi(FFChassisResult* result)
{
FFWmiQuery query(L"SELECT Version, ChassisTypes, Manufacturer FROM Win32_SystemEnclosure");
if (!query)
return "Query WMI service failed";
if (FFWmiRecord record = query.next())
{
if (auto vtProp = record.get(L"ChassisTypes"))
{
auto [arr, len] = vtProp.get<std::pair<const int32_t*, uint32_t>>();
if(len == 0)
return "ChassisTypes contain no data";
for (uint32_t i = 0; i < len; ++i)
{
if (i > 0)
ffStrbufAppendS(&result->type, ", ");
ffStrbufAppendS(&result->type, ffChassisTypeToString((uint32_t) arr[i]));
}
}
else
return "Get ChassisTypes failed";
if (auto vtProp = record.get(L"Version"))
{
ffStrbufSetWSV(&result->version, vtProp.get<std::wstring_view>());
ffCleanUpSmbiosValue(&result->version);
}
if (auto vtProp = record.get(L"Manufacturer"))
{
ffStrbufSetWSV(&result->vendor, vtProp.get<std::wstring_view>());
ffCleanUpSmbiosValue(&result->vendor);
}
return NULL;
}
return "No WMI result returned";
}
extern "C"
const char* ffDetectChassis(FFChassisResult* result, FFChassisOptions* options)
{
if (options->useWmi)
return detectWithWmi(result);
return detectWithRegistry(result);
}
-1
View File
@@ -1,5 +1,4 @@
#include "cpu.h"
#include "detection/internal.h"
const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu);
+2 -2
View File
@@ -13,8 +13,8 @@ typedef struct FFCPUResult
uint16_t coresLogical;
uint16_t coresOnline;
double frequencyMin;
double frequencyMax;
double frequencyMin; // GHz
double frequencyMax; // GHz
double temperature;
} FFCPUResult;
+27 -37
View File
@@ -1,6 +1,7 @@
#include "cpu.h"
#include "common/sysctl.h"
#include "detection/temps/temps_apple.h"
#include "util/stringUtils.h"
static double detectCpuTemp(const FFstrbuf* cpuName)
{
@@ -11,14 +12,14 @@ static double detectCpuTemp(const FFstrbuf* cpuName)
{
switch (strtol(cpuName->chars + strlen("Apple M"), NULL, 10))
{
case 1: error = ffDetectCoreTemps(FF_TEMP_CPU_M1X, &result); break;
case 2: error = ffDetectCoreTemps(FF_TEMP_CPU_M2X, &result); break;
case 3: error = ffDetectCoreTemps(FF_TEMP_CPU_M3X, &result); break;
case 1: error = ffDetectSmcTemps(FF_TEMP_CPU_M1X, &result); break;
case 2: error = ffDetectSmcTemps(FF_TEMP_CPU_M2X, &result); break;
case 3: error = ffDetectSmcTemps(FF_TEMP_CPU_M3X, &result); break;
default: error = "Unsupported Apple Silicon CPU";
}
}
else // PPC?
error = ffDetectCoreTemps(FF_TEMP_CPU_X64, &result);
error = ffDetectSmcTemps(FF_TEMP_CPU_X64, &result);
if(error)
return FF_CPU_TEMP_UNSET;
@@ -35,44 +36,33 @@ static const char* detectFrequency(FFCPUResult* cpu)
{
// https://github.com/giampaolo/psutil/pull/2222/files
io_iterator_t iterator;
if(IOServiceGetMatchingServices(MACH_PORT_NULL, IOServiceMatching("AppleARMIODevice"), &iterator) != kIOReturnSuccess)
FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t entryDevice = IOServiceGetMatchingService(MACH_PORT_NULL, IOServiceNameMatching("pmgr"));
if (!entryDevice)
return "IOServiceGetMatchingServices() failed";
io_registry_entry_t registryEntry;
while((registryEntry = IOIteratorNext(iterator)) != 0)
if (!IOObjectConformsTo(entryDevice, "AppleARMIODevice"))
return "\"pmgr\" should conform to \"AppleARMIODevice\"";
FF_CFTYPE_AUTO_RELEASE CFMutableDictionaryRef properties = NULL;
if (IORegistryEntryCreateCFProperties(entryDevice, &properties, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess)
return "IORegistryEntryCreateCFProperties() failed";
uint32_t pMin, eMin, aMax, pCoreLength;
if (ffCfDictGetData(properties, CFSTR("voltage-states5-sram"), 0, 4, (uint8_t*) &pMin, &pCoreLength) != NULL) // pCore
return "\"voltage-states5-sram\" in \"pmgr\" is not found";
if (ffCfDictGetData(properties, CFSTR("voltage-states1-sram"), 0, 4, (uint8_t*) &eMin, NULL) != NULL) // eCore
return "\"voltage-states1-sram\" in \"pmgr\" is not found";
cpu->frequencyMin = (pMin < eMin ? pMin : eMin) / (1000.0 * 1000 * 1000);
if (pCoreLength >= 8)
{
CFMutableDictionaryRef properties;
if(IORegistryEntryCreateCFProperties(registryEntry, &properties, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess)
{
IOObjectRelease(registryEntry);
continue;
}
io_name_t name;
if (IORegistryEntryGetName(registryEntry, name) != KERN_SUCCESS)
continue;
if (strcmp(name, "pmgr") != 0)
continue;
uint32_t pMin, eMin, aMax, pCoreLength;
ffCfDictGetData(properties, CFSTR("voltage-states5-sram"), 0, 4, (uint8_t*) &pMin, &pCoreLength); // pCore
ffCfDictGetData(properties, CFSTR("voltage-states1-sram"), 0, 4, (uint8_t*) &eMin, NULL); // eCore
cpu->frequencyMin = (pMin < eMin ? pMin : eMin) / (1000.0 * 1000 * 1000);
if (pCoreLength >= 8)
{
ffCfDictGetData(properties, CFSTR("voltage-states5-sram"), pCoreLength - 8, 4, (uint8_t*) &aMax, NULL);
cpu->frequencyMax = aMax / (1000.0 * 1000 * 1000);
}
else
cpu->frequencyMax = 0.0;
CFRelease(properties);
IOObjectRelease(registryEntry);
ffCfDictGetData(properties, CFSTR("voltage-states5-sram"), pCoreLength - 8, 4, (uint8_t*) &aMax, NULL);
cpu->frequencyMax = aMax / (1000.0 * 1000 * 1000);
}
else
cpu->frequencyMax = 0.0;
IOObjectRelease(iterator);
return NULL;
}
#else
+54 -7
View File
@@ -8,6 +8,7 @@
#include <sys/sysinfo.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#ifdef __ANDROID__
#include "common/settings.h"
@@ -132,10 +133,9 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
const char* error = parseCpuInfo(cpu, &physicalCoresBuffer, &cpuMHz, &cpuIsa, &cpuUarch);
if (error) return error;
cpu->coresPhysical = (uint16_t) ffStrbufToUInt(&physicalCoresBuffer, 1);
cpu->coresLogical = (uint16_t) get_nprocs_conf();
cpu->coresOnline = (uint16_t) get_nprocs();
cpu->coresPhysical = (uint16_t) ffStrbufToUInt(&physicalCoresBuffer, cpu->coresLogical);
#define BP "/sys/devices/system/cpu/cpufreq/policy0/"
if(ffPathExists(BP, FF_PATHTYPE_DIRECTORY))
@@ -167,17 +167,64 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
detectAndroid(cpu);
#endif
#ifdef __linux__
if (cpu->name.length == 0)
{
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
if (!ffProcessAppendStdOut(&buffer, (char *const[]) { "lscpu", NULL }))
if (ffProcessAppendStdOut(&buffer, (char *const[]) { "lscpu", NULL }) == NULL)
{
ffParsePropLines(buffer.chars, "Model name:", &cpu->name);
if (ffStrbufEqualS(&cpu->name, "-")) ffStrbufClear(&cpu->name);
char* pstart = buffer.chars;
if (cpu->vendor.length == 0)
{
pstart = strstr(pstart, "Vendor ID:");
if (pstart)
{
pstart += strlen("Vendor ID:");
while (isspace(*pstart)) ++pstart;
if (*pstart)
{
char* pend = strchr(pstart, '\n');
if (pend != NULL)
ffStrbufAppendNS(&cpu->vendor, (uint32_t) (pend - pstart), pstart);
else
{
ffStrbufAppendS(&cpu->vendor, pstart);
}
pstart = pend + 1;
}
}
}
while ((pstart = strstr(pstart, "Model name:")))
{
pstart += strlen("Model name:");
while (isspace(*pstart)) ++pstart;
if (*pstart == '\0')
break;
if (cpu->name.length > 0)
ffStrbufAppendS(&cpu->name, " + ");
if (*pstart == '-')
{
ffStrbufAppendS(&cpu->name, "Unknown");
++pstart;
continue;
}
char* pend = strchr(pstart, '\n');
if (pend != NULL)
ffStrbufAppendNS(&cpu->name, (uint32_t) (pend - pstart), pstart);
else
{
ffStrbufAppendS(&cpu->name, pstart);
break;
}
pstart = pend + 1;
}
}
}
#endif
return NULL;
}
+85 -2
View File
@@ -2,8 +2,81 @@
#include "detection/temps/temps_windows.h"
#include "util/windows/registry.h"
#include "util/mallocHelper.h"
#include "util/smbiosHelper.h"
const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
// 7.5
typedef struct FFSmbiosProcessorInfo
{
FFSmbiosHeader Header;
uint8_t SocketDesignation; // string
uint8_t ProcessorType; // enum
uint8_t ProcessorFamily; // enum
uint8_t ProcessorManufacturer; // string
uint64_t ProcessorID; // varies
uint8_t ProcessorVersion; // string
uint8_t Voltage; // varies
uint16_t ExternalClock; // varies
uint16_t MaxSpeed; // varies
uint16_t CurrentSpeed; // varies
uint8_t Status; // varies
uint8_t ProcessorUpgrade; // enum
// 2.1+
uint16_t L1CacheHandle; // varies
uint16_t L2CacheHandle; // varies
uint16_t L3CacheHandle; // varies
// 2.3+
uint8_t SerialNumber; // string
uint8_t AssertTag; // string
uint8_t PartNumber; // string
// 2.5+
uint8_t CoreCount; // varies
uint8_t CoreEnabled; // varies
uint8_t ThreadCount; // varies
uint16_t ProcessorCharacteristics; // bit field
// 2.6+
uint16_t ProcessorFamily2; // enum
// 3.0+
uint16_t CoreCount2; // varies
uint16_t CoreEnabled2; // varies
uint16_t ThreadCount2; // varies
// 3.6+
uint16_t ThreadEnabled; // varies
} FFSmbiosProcessorInfo;
static const char* detectMaxSpeedBySmbios(FFCPUResult* cpu)
{
const FFSmbiosProcessorInfo* data = (const FFSmbiosProcessorInfo*) (*ffGetSmbiosHeaderTable())[FF_SMBIOS_TYPE_PROCESSOR_INFO];
if (!data)
return "Processor information is not found in SMBIOS data";
while (data->ProcessorType != 0x03 /*Central Processor*/ || (data->Status & 0b00000111) != 1 /*Enabled*/)
{
data = (const FFSmbiosProcessorInfo*) ffSmbiosNextEntry(&data->Header);
if (data->Header.Type != FF_SMBIOS_TYPE_PROCESSOR_INFO)
return "No active CPU is found in SMBIOS data";
}
double speed;
if (data->MaxSpeed > 0 && data->MaxSpeed < 30000) // VMware reports weird values
speed = data->MaxSpeed / 1000.0;
else
speed = data->CurrentSpeed / 1000.0;
if (cpu->frequencyMax < speed)
cpu->frequencyMax = speed;
return NULL;
}
static const char* detectByOS(FFCPUResult* cpu)
{
{
DWORD length = 0;
@@ -42,14 +115,24 @@ const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
{
uint32_t mhz;
if(ffRegReadUint(hKey, L"~MHz", &mhz, NULL))
cpu->frequencyMax = mhz / 1000.0;
cpu->frequencyMin = cpu->frequencyMax = mhz / 1000.0;
}
ffRegReadStrbuf(hKey, L"ProcessorNameString", &cpu->name, NULL);
ffRegReadStrbuf(hKey, L"VendorIdentifier", &cpu->vendor, NULL);
return NULL;
}
const char* ffDetectCPUImpl(const FFCPUOptions* options, FFCPUResult* cpu)
{
const char* error = detectByOS(cpu);
if (error)
return error;
if(options->temp)
ffDetectSmbiosTemp(&cpu->temperature, NULL);
detectMaxSpeedBySmbios(cpu);
return NULL;
}
+45 -6
View File
@@ -5,6 +5,43 @@
#include <sys/mount.h>
#ifdef __FreeBSD__
#include <libgeom.h>
static const char* detectFsLabel(struct statfs* fs, FFDisk* disk)
{
if (!ffStrStartsWith(fs->f_mntfromname, "/dev/"))
return "Only block devices are supported";
// Detect volume label in geom tree
static struct gmesh geomTree;
static struct gclass* cLabels;
if (!cLabels)
{
if (geomTree.lg_ident)
return "Previous geom_gettree() failed";
if (geom_gettree(&geomTree) < 0)
{
geomTree.lg_ident = (void*)(intptr_t)-1;
return "geom_gettree() failed";
}
for (cLabels = geomTree.lg_class.lh_first; !ffStrEquals(cLabels->lg_name, "LABEL"); cLabels = cLabels->lg_class.le_next);
if (!cLabels)
return "Class LABEL is not found";
}
for (struct ggeom* label = cLabels->lg_geom.lh_first; label; label = label->lg_geom.le_next)
{
struct gprovider* provider = label->lg_provider.lh_first;
if (!provider || !ffStrEquals(label->lg_name, fs->f_mntfromname + strlen("/dev/"))) continue;
const char* str = strchr(provider->lg_name, '/');
ffStrbufSetS(&disk->name, str ? str + 1 : provider->lg_name);
}
return NULL;
}
static void detectFsInfo(struct statfs* fs, FFDisk* disk)
{
if(ffStrbufEqualS(&disk->filesystem, "zfs"))
@@ -19,6 +56,8 @@ static void detectFsInfo(struct statfs* fs, FFDisk* disk)
disk->type = FF_DISK_VOLUME_TYPE_EXTERNAL_BIT;
else
disk->type = FF_DISK_VOLUME_TYPE_REGULAR_BIT;
detectFsLabel(fs, disk);
}
#elif __APPLE__
#include "util/apple/cf_helpers.h"
@@ -26,10 +65,10 @@ static void detectFsInfo(struct statfs* fs, FFDisk* disk)
#include <sys/attr.h>
#include <unistd.h>
struct VolAttrBuf {
struct CmnAttrBuf {
uint32_t length;
attrreference_t volNameRef;
char volNameSpace[MAXPATHLEN];
attrreference_t nameRef;
char nameSpace[NAME_MAX * 3 + 1];
} __attribute__((aligned(4), packed));
void detectFsInfo(struct statfs* fs, FFDisk* disk)
@@ -41,12 +80,12 @@ void detectFsInfo(struct statfs* fs, FFDisk* disk)
else
disk->type = FF_DISK_VOLUME_TYPE_REGULAR_BIT;
struct VolAttrBuf attrBuf;
struct CmnAttrBuf attrBuf;
if (getattrlist(disk->mountpoint.chars, &(struct attrlist) {
.bitmapcount = ATTR_BIT_MAP_COUNT,
.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME,
.commonattr = ATTR_CMN_NAME,
}, &attrBuf, sizeof(attrBuf), 0) == 0)
ffStrbufInitNS(&disk->name, attrBuf.volNameRef.attr_length - 1 /* excluding '\0' */, attrBuf.volNameSpace);
ffStrbufInitNS(&disk->name, attrBuf.nameRef.attr_length - 1 /* excluding '\0' */, attrBuf.nameSpace);
}
#endif
+15 -24
View File
@@ -26,8 +26,11 @@ static bool isPhysicalDevice(const struct mntent* device)
if(ffStrEquals(device->mnt_dir, "/"))
return true;
if(ffStrEquals(device->mnt_fsname, "none"))
return false;
//DrvFs is a filesystem plugin to WSL that was designed to support interop between WSL and the Windows filesystem.
if(ffStrEquals(device->mnt_fsname, "drvfs"))
if(ffStrEquals(device->mnt_type, "9p"))
return true;
//ZFS pool
@@ -189,41 +192,29 @@ static bool isSubvolume(const FFlist* disks, FFDisk* currentDisk)
static bool isRemovable(FFDisk* currentDisk)
{
FF_STRBUF_AUTO_DESTROY basePath = ffStrbufCreateS("/sys/block/");
FF_AUTO_CLOSE_DIR DIR* dir = opendir(basePath.chars);
if(dir == NULL)
if (!ffStrbufStartsWithS(&currentDisk->mountFrom, "/dev/"))
return false;
uint32_t index = ffStrbufLastIndexC(&currentDisk->mountFrom, '/');
const char* partitionName = index == currentDisk->mountFrom.length ? NULL : currentDisk->mountFrom.chars + index + 1;
if (!partitionName || !*partitionName) return false;
char sysBlockPartition[64];
snprintf(sysBlockPartition, sizeof(sysBlockPartition), "/sys/class/block/%s", currentDisk->mountFrom.chars + strlen("/dev/"));
struct dirent* entry;
while((entry = readdir(dir)) != NULL)
{
if(entry->d_name[0] == '.')
continue;
char sysBlockVolume[PATH_MAX]; // /sys/devices/pci0000:00/0000:00:14.0/usb4/4-3/4-3:1.0/host0/target0:0:0/0:0:0:0/block/sda/sda1
if (realpath(sysBlockPartition, sysBlockVolume) == NULL)
return false;
strcpy(strrchr(sysBlockVolume, '/') + 1, "removable");
if (!ffStrStartsWith(partitionName, entry->d_name)) continue;
// /sys/block/sdx/device/delete
ffStrbufAppendS(&basePath, entry->d_name);
ffStrbufAppendS(&basePath, "/device/delete");
return ffPathExists(basePath.chars, FF_PATHTYPE_FILE);
}
return false;
char removableChar = '0';
return ffReadFileData(sysBlockVolume, 1, &removableChar) > 0 && removableChar == '1';
}
static void detectType(const FFlist* disks, FFDisk* currentDisk)
{
if(ffStrbufStartsWithS(&currentDisk->mountpoint, "/boot") || ffStrbufStartsWithS(&currentDisk->mountpoint, "/efi"))
currentDisk->type = FF_DISK_VOLUME_TYPE_HIDDEN_BIT;
else if(isRemovable(currentDisk))
currentDisk->type = FF_DISK_VOLUME_TYPE_EXTERNAL_BIT;
else if(isSubvolume(disks, currentDisk))
currentDisk->type = FF_DISK_VOLUME_TYPE_SUBVOLUME_BIT;
else if(isRemovable(currentDisk))
currentDisk->type = FF_DISK_VOLUME_TYPE_EXTERNAL_BIT;
else
currentDisk->type = FF_DISK_VOLUME_TYPE_REGULAR_BIT;
}
+2 -10
View File
@@ -8,22 +8,14 @@
#include <IOKit/storage/IOStorageDeviceCharacteristics.h>
#include <IOKit/storage/IOStorageProtocolCharacteristics.h>
static inline void wrapIoObjectRelease(io_service_t* service)
{
assert(service);
if (*service)
IOObjectRelease(*service);
}
#define FF_IOOBJECT_AUTO_RELEASE __attribute__((__cleanup__(wrapIoObjectRelease)))
const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
{
FF_IOOBJECT_AUTO_RELEASE io_iterator_t iterator = 0;
if(IOServiceGetMatchingServices(MACH_PORT_NULL, IOServiceMatching(kIOMediaClass), &iterator) != KERN_SUCCESS)
if (IOServiceGetMatchingServices(MACH_PORT_NULL, IOServiceMatching(kIOMediaClass), &iterator) != KERN_SUCCESS)
return "IOServiceGetMatchingServices() failed";
io_registry_entry_t registryEntry;
while((registryEntry = IOIteratorNext(iterator)) != 0)
while ((registryEntry = IOIteratorNext(iterator)) != IO_OBJECT_NULL)
{
FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t entryPartition = registryEntry;
+25 -4
View File
@@ -41,16 +41,37 @@ const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
{
snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/device/vendor", devName);
ffAppendFileBuffer(pathSysBlock, &device->name);
if (device->name.length > 0)
ffStrbufAppendC(&device->name, ' ');
if (ffAppendFileBuffer(pathSysBlock, &device->name))
{
ffStrbufTrimRightSpace(&device->name);
if (device->name.length > 0)
ffStrbufAppendC(&device->name, ' ');
}
snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/device/model", devName);
ffAppendFileBuffer(pathSysBlock, &device->name);
ffStrbufTrim(&device->name, ' ');
ffStrbufTrimRightSpace(&device->name);
if (device->name.length == 0)
ffStrbufSetS(&device->name, devName);
else if (ffStrStartsWith(devName, "nvme"))
{
int devid, nsid;
if (sscanf(devName, "nvme%dn%d", &devid, &nsid) == 2)
{
bool multiNs = nsid > 1;
if (!multiNs)
{
snprintf(pathSysBlock, PATH_MAX, "/sys/block/%s/device/nvme%dn2", devName, devid);
multiNs = ffPathExists(pathSysBlock, FF_PATHTYPE_DIRECTORY);
}
if (multiNs)
{
// In Asahi Linux, there are multiple namespaces for the same NVMe drive.
ffStrbufAppendF(&device->name, " - %d", nsid);
}
}
}
if (options->namePrefix.length && !ffStrbufStartsWith(&device->name, &options->namePrefix))
{
+86 -65
View File
@@ -5,78 +5,99 @@
#include <windows.h>
#include <winioctl.h>
static bool detectPhysicalDisk(const wchar_t* szDevice, FFlist* result, FFDiskIOOptions* options)
{
FF_AUTO_CLOSE_FD HANDLE hDevice = CreateFileW(szDevice, FILE_READ_ATTRIBUTES, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if (hDevice == INVALID_HANDLE_VALUE)
return false;
DWORD retSize;
char sddBuffer[4096];
if(!DeviceIoControl(
hDevice,
IOCTL_STORAGE_QUERY_PROPERTY,
&(STORAGE_PROPERTY_QUERY) {
.PropertyId = StorageDeviceProperty,
.QueryType = PropertyStandardQuery,
},
sizeof(STORAGE_PROPERTY_QUERY),
&sddBuffer,
sizeof(sddBuffer),
&retSize,
NULL
) || retSize == 0)
return true;
FFDiskIOResult* device = (FFDiskIOResult*) ffListAdd(result);
STORAGE_DEVICE_DESCRIPTOR* sdd = (STORAGE_DEVICE_DESCRIPTOR*) sddBuffer;
ffStrbufInit(&device->name);
if (sdd->VendorIdOffset != 0)
{
ffStrbufSetS(&device->name, (const char*) sddBuffer + sdd->VendorIdOffset);
ffStrbufTrim(&device->name, ' ');
}
if (sdd->ProductIdOffset != 0)
{
if (device->name.length)
ffStrbufAppendC(&device->name, ' ');
ffStrbufAppendS(&device->name, (const char*) sddBuffer + sdd->ProductIdOffset);
ffStrbufTrimRight(&device->name, ' ');
}
if (!device->name.length)
ffStrbufSetWS(&device->name, szDevice);
if (options->namePrefix.length && !ffStrbufStartsWith(&device->name, &options->namePrefix))
{
ffStrbufDestroy(&device->name);
result->length--;
return true;
}
ffStrbufInitWS(&device->devPath, szDevice);
DISK_PERFORMANCE dp = {};
if (DeviceIoControl(hDevice, IOCTL_DISK_PERFORMANCE, NULL, 0, &dp, sizeof(dp), &retSize, NULL))
{
device->bytesRead = (uint64_t) dp.BytesRead.QuadPart;
device->readCount = (uint64_t) dp.ReadCount;
device->bytesWritten = (uint64_t) dp.BytesWritten.QuadPart;
device->writeCount = (uint64_t) dp.WriteCount;
}
else
{
ffStrbufDestroy(&device->name);
result->length--;
}
return true;
}
const char* ffDiskIOGetIoCounters(FFlist* result, FFDiskIOOptions* options)
{
wchar_t szDevice[32] = L"\\\\.\\PhysicalDrive";
wchar_t* pNum = szDevice + strlen("\\\\.\\PhysicalDrive");
for (uint32_t idev = 0; ; ++idev)
{
_ultow(idev, pNum, 10);
FF_AUTO_CLOSE_FD HANDLE hDevice = CreateFileW(szDevice, FILE_READ_ATTRIBUTES, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if (hDevice == INVALID_HANDLE_VALUE)
break;
DWORD retSize;
char sddBuffer[4096];
if(!DeviceIoControl(
hDevice,
IOCTL_STORAGE_QUERY_PROPERTY,
&(STORAGE_PROPERTY_QUERY) {
.PropertyId = StorageDeviceProperty,
.QueryType = PropertyStandardQuery,
},
sizeof(STORAGE_PROPERTY_QUERY),
&sddBuffer,
sizeof(sddBuffer),
&retSize,
NULL
) || retSize == 0)
continue;
FFDiskIOResult* device = (FFDiskIOResult*) ffListAdd(result);
STORAGE_DEVICE_DESCRIPTOR* sdd = (STORAGE_DEVICE_DESCRIPTOR*) sddBuffer;
ffStrbufInit(&device->name);
if (sdd->VendorIdOffset != 0)
wchar_t szPhysicalDrive[32] = L"\\\\.\\PhysicalDrive";
wchar_t* pNum = szPhysicalDrive + strlen("\\\\.\\PhysicalDrive");
for (uint32_t idev = 0; ; ++idev)
{
ffStrbufSetS(&device->name, (const char*) sddBuffer + sdd->VendorIdOffset);
ffStrbufTrim(&device->name, ' ');
_ultow(idev, pNum, 10);
if (!detectPhysicalDisk(szPhysicalDrive, result, options))
break;
}
if (sdd->ProductIdOffset != 0)
}
{
wchar_t szCdrom[32] = L"\\\\.\\CDROM";
wchar_t* pNum = szCdrom + strlen("\\\\.\\CDROM");
for (uint32_t idev = 0; ; ++idev)
{
if (device->name.length)
ffStrbufAppendC(&device->name, ' ');
_ultow(idev, pNum, 10);
ffStrbufAppendS(&device->name, (const char*) sddBuffer + sdd->ProductIdOffset);
ffStrbufTrimRight(&device->name, ' ');
}
if (!device->name.length)
ffStrbufAppendF(&device->name, "PhysicalDrive%u", (unsigned) idev);
if (options->namePrefix.length && !ffStrbufStartsWith(&device->name, &options->namePrefix))
{
ffStrbufDestroy(&device->name);
result->length--;
continue;
}
ffStrbufInitWS(&device->devPath, szDevice);
DISK_PERFORMANCE dp = {};
if (DeviceIoControl(hDevice, IOCTL_DISK_PERFORMANCE, NULL, 0, &dp, sizeof(dp), &retSize, NULL))
{
device->bytesRead = (uint64_t) dp.BytesRead.QuadPart;
device->readCount = (uint64_t) dp.ReadCount;
device->bytesWritten = (uint64_t) dp.BytesWritten.QuadPart;
device->writeCount = (uint64_t) dp.WriteCount;
}
else
{
ffStrbufDestroy(&device->name);
result->length--;
continue;
if (!detectPhysicalDisk(szCdrom, result, options))
break;
}
}
+11 -3
View File
@@ -1,5 +1,4 @@
#include "displayserver.h"
#include "detection/internal.h"
bool ffdsAppendDisplay(
FFDisplayServerResult* result,
@@ -36,7 +35,16 @@ void ffConnectDisplayServerImpl(FFDisplayServerResult* ds);
const FFDisplayServerResult* ffConnectDisplayServer()
{
FF_DETECTION_INTERNAL_GUARD(FFDisplayServerResult,
static FFDisplayServerResult result;
if (result.displays.elementSize == 0)
{
ffStrbufInit(&result.wmProcessName);
ffStrbufInit(&result.wmPrettyName);
ffStrbufInit(&result.wmProtocolName);
ffStrbufInit(&result.deProcessName);
ffStrbufInit(&result.dePrettyName);
ffListInit(&result.displays, sizeof(FFDisplayResult));
ffConnectDisplayServerImpl(&result);
);
}
return &result;
}
@@ -102,12 +102,8 @@ static bool detectWithGetprop(FFDisplayServerResult* ds)
void ffConnectDisplayServerImpl(FFDisplayServerResult* ds)
{
ffStrbufInitStatic(&ds->wmProcessName, "WindowManager");
ffStrbufInitStatic(&ds->wmPrettyName, "Window Manager");
ffStrbufInit(&ds->wmProtocolName);
ffStrbufInit(&ds->deProcessName);
ffStrbufInit(&ds->dePrettyName);
ffListInitA(&ds->displays, sizeof(FFDisplayResult), 0);
ffStrbufSetStatic(&ds->wmProcessName, "WindowManager");
ffStrbufSetStatic(&ds->wmPrettyName, "Window Manager");
if (!detectWithGetprop(ds))
detectWithDumpsys(ds);
@@ -73,20 +73,11 @@ void ffConnectDisplayServerImpl(FFDisplayServerResult* ds)
FF_CFTYPE_AUTO_RELEASE CFMachPortRef port = CGWindowServerCreateServerPort();
if (port)
{
ffStrbufInitStatic(&ds->wmProcessName, "WindowServer");
ffStrbufInitStatic(&ds->wmPrettyName, "Quartz Compositor");
}
else
{
ffStrbufInit(&ds->wmProcessName);
ffStrbufInit(&ds->wmPrettyName);
ffStrbufSetStatic(&ds->wmProcessName, "WindowServer");
ffStrbufSetStatic(&ds->wmPrettyName, "Quartz Compositor");
}
}
ffStrbufInit(&ds->wmProtocolName);
ffStrbufSetStatic(&ds->dePrettyName, "Aqua");
ffStrbufInit(&ds->deProcessName);
ffStrbufInitStatic(&ds->dePrettyName, "Aqua");
ffListInitA(&ds->displays, sizeof(FFDisplayResult), 4);
detectDisplays(ds);
}
@@ -13,10 +13,10 @@ typedef struct FFMonitorInfo
} FFMonitorInfo;
static CALLBACK BOOL MonitorEnumProc(
HMONITOR hMonitor,
FF_MAYBE_UNUSED HDC hdc,
FF_MAYBE_UNUSED LPRECT lpRect,
LPARAM lParam
HMONITOR hMonitor,
FF_MAYBE_UNUSED HDC hdc,
FF_MAYBE_UNUSED LPRECT lpRect,
LPARAM lParam
)
{
FFlist* monitors = (FFlist*) lParam;
@@ -129,8 +129,9 @@ static void detectDisplays(FFDisplayServerResult* ds)
(uint32_t) (monitorInfo->info.rcMonitor.bottom - monitorInfo->info.rcMonitor.top),
rotation,
&name,
path->targetInfo.outputTechnology == DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INTERNAL ||
path->targetInfo.outputTechnology == DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EMBEDDED ||
path->targetInfo.outputTechnology == DISPLAYCONFIG_OUTPUT_TECHNOLOGY_OTHER ? FF_DISPLAY_TYPE_UNKNOWN :
path->targetInfo.outputTechnology == DISPLAYCONFIG_OUTPUT_TECHNOLOGY_INTERNAL ||
path->targetInfo.outputTechnology == DISPLAYCONFIG_OUTPUT_TECHNOLOGY_DISPLAYPORT_EMBEDDED ||
path->targetInfo.outputTechnology == DISPLAYCONFIG_OUTPUT_TECHNOLOGY_UDI_EMBEDDED
? FF_DISPLAY_TYPE_BUILTIN : FF_DISPLAY_TYPE_EXTERNAL,
!!(monitorInfo->info.dwFlags & MONITORINFOF_PRIMARY),
@@ -145,20 +146,16 @@ void ffConnectDisplayServerImpl(FFDisplayServerResult* ds)
BOOL enabled;
if(SUCCEEDED(DwmIsCompositionEnabled(&enabled)) && enabled)
{
ffStrbufInitStatic(&ds->wmProcessName, "dwm.exe");
ffStrbufInitStatic(&ds->wmPrettyName, "Desktop Window Manager");
ffStrbufSetStatic(&ds->wmProcessName, "dwm.exe");
ffStrbufSetStatic(&ds->wmPrettyName, "Desktop Window Manager");
}
else
{
// `explorer.exe` only provides a subset of WM functions, as well as the taskbar and desktop icons.
// While a window itself is drawn by kernel (GDI). Killing `explorer.exe` won't affect how windows are displayed generally.
ffStrbufInitStatic(&ds->wmProcessName, "explorer.exe");
ffStrbufInitStatic(&ds->wmPrettyName, "Internal");
ffStrbufSetStatic(&ds->wmProcessName, "explorer.exe");
ffStrbufSetStatic(&ds->wmPrettyName, "Internal");
}
ffStrbufInit(&ds->wmProtocolName);
ffStrbufInit(&ds->deProcessName);
ffStrbufInit(&ds->dePrettyName);
ffListInit(&ds->displays, sizeof(FFDisplayResult));
detectDisplays(ds);
@@ -1,15 +1,11 @@
#include "displayserver_linux.h"
#include "common/io/io.h"
#ifdef __FreeBSD__
#include "common/settings.h"
#endif
void ffConnectDisplayServerImpl(FFDisplayServerResult* ds)
{
ffStrbufInit(&ds->wmProcessName);
ffStrbufInit(&ds->wmPrettyName);
ffStrbufInit(&ds->wmProtocolName);
ffStrbufInit(&ds->deProcessName);
ffStrbufInit(&ds->dePrettyName);
ffListInitA(&ds->displays, sizeof(FFDisplayResult), 4);
if (instance.config.general.dsForceDrm == FF_DS_FORCE_DRM_TYPE_FALSE)
{
//We try wayland as our preferred display server, as it supports the most features.
@@ -38,6 +34,26 @@ void ffConnectDisplayServerImpl(FFDisplayServerResult* ds)
if(ds->displays.length == 0)
ffdsConnectDrm(ds);
#ifdef __FreeBSD__
if(ds->displays.length == 0)
{
FF_STRBUF_AUTO_DESTROY buf = ffStrbufCreate();
if (ffSettingsGetFreeBSDKenv("screen.width", &buf))
{
uint32_t width = (uint32_t) ffStrbufToUInt(&buf, 0);
if (width)
{
ffStrbufClear(&buf);
if (ffSettingsGetFreeBSDKenv("screen.height", &buf))
{
uint32_t height = (uint32_t) ffStrbufToUInt(&buf, 0);
ffdsAppendDisplay(ds, width, height, 0, 0, 0, 0, NULL, FF_DISPLAY_TYPE_UNKNOWN, false, 0);
}
}
}
}
#endif
//This fills in missing information about WM / DE by using env vars and iterating processes
ffdsDetectWMDE(ds);
}
@@ -50,6 +50,7 @@ static void waylandDetectWM(int fd, FFDisplayServerResult* result)
FF_STRBUF_AUTO_DESTROY procPath = ffStrbufCreate();
ffStrbufAppendF(&procPath, "/proc/%d/cmdline", ucred.pid); //We check the cmdline for the process name, because it is not trimmed.
ffReadFileBuffer(procPath.chars, &result->wmProcessName);
ffStrbufTrimRightSpace(&result->wmProcessName);
ffStrbufSubstrBeforeFirstC(&result->wmProcessName, '\0'); //Trim the arguments
ffStrbufSubstrAfterLastC(&result->wmProcessName, '/'); //Trim the path
}
+1
View File
@@ -326,6 +326,7 @@ static const char* getFromProcesses(FFDisplayServerResult* result)
//We check the cmdline for the process name, because it is not trimmed.
ffStrbufAppendS(&procPath, "/cmdline");
ffReadFileBuffer(procPath.chars, &processName);
ffStrbufTrimRightSpace(&processName);
ffStrbufSubstrBeforeFirstC(&processName, '\0'); //Trim the arguments
ffStrbufSubstrAfterLastC(&processName, '/');
-1
View File
@@ -1,5 +1,4 @@
#include "font.h"
#include "detection/internal.h"
const char* ffDetectFontImpl(FFFontResult* font);
+2 -1
View File
@@ -4,8 +4,9 @@
typedef struct FFGamepadDevice
{
FFstrbuf identifier;
FFstrbuf serial;
FFstrbuf name;
uint8_t battery; // 0-100%
} FFGamepadDevice;
const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */);
+39 -15
View File
@@ -1,18 +1,34 @@
#include "gamepad.h"
#include "util/apple/cf_helpers.h"
#include "util/mallocHelper.h"
#include <IOKit/IOKitLib.h>
#include <IOKit/hid/IOHIDLib.h>
static void enumSet(const void* value, void *context)
static void enumSet(IOHIDDeviceRef value, FFlist* results)
{
CFStringRef product = IOHIDDeviceGetProperty((IOHIDDeviceRef) value, CFSTR(kIOHIDProductKey));
CFStringRef serialNumber = IOHIDDeviceGetProperty((IOHIDDeviceRef) value, CFSTR(kIOHIDSerialNumberKey));
FFGamepadDevice* device = (FFGamepadDevice*) ffListAdd((FFlist*) context);
ffStrbufInit(&device->identifier);
ffCfStrGetString(serialNumber, &device->identifier);
FFGamepadDevice* device = (FFGamepadDevice*) ffListAdd(results);
ffStrbufInit(&device->serial);
ffStrbufInit(&device->name);
ffCfStrGetString(product, &device->name);
device->battery = 0;
CFStringRef manufacturer = IOHIDDeviceGetProperty(value, CFSTR(kIOHIDManufacturerKey));
ffCfStrGetString(manufacturer, &device->name);
CFStringRef product = IOHIDDeviceGetProperty(value, CFSTR(kIOHIDProductKey));
if (device->name.length)
{
ffCfStrGetString(product, &device->serial);
ffStrbufAppendC(&device->name, ' ');
ffStrbufAppend(&device->name, &device->serial);
}
else
{
ffCfStrGetString(product, &device->name);
}
CFStringRef serialNumber = IOHIDDeviceGetProperty(value, CFSTR(kIOHIDSerialNumberKey));
ffCfStrGetString(serialNumber, &device->serial);
}
const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
@@ -21,21 +37,29 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
if (IOHIDManagerOpen(manager, kIOHIDOptionsTypeNone) != kIOReturnSuccess)
return "IOHIDManagerOpen() failed";
CFNumberRef FF_CFTYPE_AUTO_RELEASE genericDesktop = ffCfCreateInt(kHIDPage_GenericDesktop);
CFNumberRef FF_CFTYPE_AUTO_RELEASE gamePad = ffCfCreateInt(kHIDUsage_GD_GamePad);
CFDictionaryRef FF_CFTYPE_AUTO_RELEASE matching = CFDictionaryCreate(kCFAllocatorDefault, (const void **)(CFStringRef[]){
CFDictionaryRef FF_CFTYPE_AUTO_RELEASE matching1 = CFDictionaryCreate(kCFAllocatorDefault, (const void **)(CFStringRef[]){
CFSTR(kIOHIDDeviceUsagePageKey),
CFSTR(kIOHIDDeviceUsageKey)
}, (const void **)(CFNumberRef[]){
genericDesktop,
gamePad
ffCfCreateInt(kHIDPage_GenericDesktop),
ffCfCreateInt(kHIDUsage_GD_Joystick)
}, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
IOHIDManagerSetDeviceMatching(manager, matching);
CFDictionaryRef FF_CFTYPE_AUTO_RELEASE matching2 = CFDictionaryCreate(kCFAllocatorDefault, (const void **)(CFStringRef[]){
CFSTR(kIOHIDDeviceUsagePageKey),
CFSTR(kIOHIDDeviceUsageKey)
}, (const void **)(CFNumberRef[]){
ffCfCreateInt(kHIDPage_GenericDesktop),
ffCfCreateInt(kHIDUsage_GD_GamePad)
}, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFArrayRef FF_CFTYPE_AUTO_RELEASE matchings = CFArrayCreate(kCFAllocatorDefault, (const void **)(CFTypeRef[]){
matching1, matching2
}, 2, &kCFTypeArrayCallBacks);
IOHIDManagerSetDeviceMatchingMultiple(manager, matchings);
CFSetRef FF_CFTYPE_AUTO_RELEASE set = IOHIDManagerCopyDevices(manager);
if (set)
CFSetApplyFunction(set, &enumSet, devices);
IOHIDManagerClose(manager, 0);
CFSetApplyFunction(set, (CFSetApplierFunction) &enumSet, devices);
IOHIDManagerClose(manager, kIOHIDOptionsTypeNone);
return NULL;
}
+2 -1
View File
@@ -42,8 +42,9 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
if (ioctl(fd, USB_GET_DEVICEINFO, &di) != -1)
{
FFGamepadDevice* device = (FFGamepadDevice*) ffListAdd(devices);
ffStrbufInitS(&device->identifier, di.udi_serial);
ffStrbufInitS(&device->serial, di.udi_serial);
ffStrbufInitF(&device->name, "%s %s", di.udi_vendor, di.udi_product);
device->battery = 0;
}
}
}
+62 -12
View File
@@ -5,38 +5,88 @@
#include <dirent.h>
#include <ctype.h>
static void detectGamepad(FFlist* devices, FFstrbuf* name, FFstrbuf* path)
{
uint32_t baseLen = path->length;
FFGamepadDevice* device = (FFGamepadDevice*) ffListAdd(devices);
ffStrbufInit(&device->serial);
ffStrbufInitMove(&device->name, name);
device->battery = 0;
ffStrbufAppendS(path, "uniq");
if (ffAppendFileBuffer(path->chars, &device->serial))
ffStrbufTrimRightSpace(&device->serial);
ffStrbufSubstrBefore(path, baseLen);
ffStrbufAppendS(path, "device/power_supply/"); // /sys/class/input/jsX/device/device/power_supply
FF_AUTO_CLOSE_DIR DIR* dirp = opendir(path->chars);
if (dirp)
{
struct dirent* entry;
while ((entry = readdir(dirp)) != NULL)
{
if (entry->d_name[0] == '.' || (entry->d_type != DT_DIR && entry->d_type != DT_UNKNOWN))
continue;
ffStrbufAppendS(path, entry->d_name);
ffStrbufAppendS(path, "/capacity"); // /sys/class/input/jsX/device/device/power_supply/XXX/capacity
char capacity[32];
ssize_t nRead = ffReadFileData(path->chars, sizeof(capacity) - 1, capacity);
if (nRead > 0) // Tested with a PS4 controller
{
capacity[nRead] = '\0';
device->battery = (uint8_t) strtoul(capacity, NULL, 10);
break;
}
ffStrbufAppendS(path, "_level");
nRead = ffReadFileData(path->chars, sizeof(capacity) - 1, capacity);
if (nRead > 0) // Tested with a NS Pro controller
{
// https://github.com/torvalds/linux/blob/52b1853b080a082ec3749c3a9577f6c71b1d4a90/drivers/power/supply/power_supply_sysfs.c#L124
switch (capacity[0])
{
case 'C': device->battery = 1; break; // Critical
case 'L': device->battery = 25; break; // Low
case 'N': device->battery = 50; break; // Normal
case 'H': device->battery = 75; break; // High
case 'F': device->battery = 100; break; // Full
}
}
}
}
}
const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
{
DIR* dirp = opendir("/sys/class/input/");
if(dirp == NULL)
FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/sys/class/input/");
if (dirp == NULL)
return "opendir(\"/sys/class/input/\") == NULL";
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateS("/sys/class/input/");
uint32_t baseLen = path.length;
struct dirent* entry;
while((entry = readdir(dirp)) != NULL)
while ((entry = readdir(dirp)) != NULL)
{
if(!ffStrStartsWith(entry->d_name, "js"))
if (!ffStrStartsWith(entry->d_name, "js"))
continue;
if(!isdigit(entry->d_name[2]))
if (!isdigit(entry->d_name[2]))
continue;
ffStrbufAppendS(&path, entry->d_name);
ffStrbufAppendS(&path, "/device/name");
if (ffPathExists(path.chars, FF_PATHTYPE_FILE))
FF_STRBUF_AUTO_DESTROY name = ffStrbufCreate();
if (ffAppendFileBuffer(path.chars, &name))
{
FFGamepadDevice* device = (FFGamepadDevice*) ffListAdd(devices);
ffStrbufInitS(&device->identifier, entry->d_name);
ffStrbufInit(&device->name);
ffAppendFileBuffer(path.chars, &device->name);
ffStrbufTrimRightSpace(&name);
ffStrbufSubstrBefore(&path, path.length - 4);
detectGamepad(devices, &name, &path);
}
ffStrbufSubstrBefore(&path, baseLen);
}
closedir(dirp);
return NULL;
}
+90 -37
View File
@@ -3,10 +3,11 @@
#include "util/mallocHelper.h"
#include "util/windows/unicode.h"
#include <winternl.h>
#include <windows.h>
#include <hidsdi.h>
static const char* detectKnownGamepad(uint32_t vendorId, uint32_t productId)
static const char* detectKnownDeviceName(uint32_t vendorId, uint32_t productId)
{
switch (vendorId)
{
@@ -30,38 +31,14 @@ static const char* detectKnownGamepad(uint32_t vendorId, uint32_t productId)
{
switch (productId)
{
case 0x0268: return "Sony Playstation 3 Controller";
case 0x0268: return "Sony DualShock 3 / Six Axis";
case 0x05C4: return "Sony DualShock 4 Gen1";
case 0x09CC: return "Sony DualShock 4 Gen2";
case 0x0BA0: return "Sony PS4 Controller USB receiver";
case 0x0BA0: return "Sony DualShock 4 USB receiver";
case 0x0CE6: return "Sony DualSense";
default: return NULL;
}
}
// Microsoft
case 0x045E:
{
switch (productId)
{
case 0x02E0: return "Microsoft X-Box One S pad (Wireless)";
case 0x02FD: return "Microsoft X-Box One S pad (Wireless, 2016 FW)";
case 0x0B05: return "Microsoft X-Box One Elite Series 2 pad (Wireless)";
case 0x0B13: return "Microsoft X-Box Series X (Wireless)";
case 0x028E: return "Microsoft XBox 360";
case 0x028F: return "Microsoft XBox 360 v2";
case 0x02A1: return "Microsoft XBox 360";
case 0x0291: return "Microsoft XBox 360 USB receiver";
case 0x02A0: return "Microsoft XBox 360 Big Button IR";
case 0x02DD: return "Microsoft XBox One";
case 0xB326: return "Microsoft XBox One Firmware 2015";
case 0x02E3: return "Microsoft XBox One Elite";
case 0x02FF: return "Microsoft XBox One Elite";
case 0x02EA: return "Microsoft XBox One S";
case 0x0DF2: return "Sony DualSense Edge";
default: return NULL;
}
@@ -83,6 +60,7 @@ static const char* detectKnownGamepad(uint32_t vendorId, uint32_t productId)
}
}
case 0x045E: // Microsoft Xbox compatible controllers should be handled by Windows without problems
default: return NULL;
}
}
@@ -98,7 +76,8 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
if ((nDevices = GetRawInputDeviceList(pRawInputDeviceList, &nDevices, sizeof(RAWINPUTDEVICELIST))) == (UINT) -1)
return "GetRawInputDeviceList(pRawInputDeviceList) failed";
for (UINT i = 0; i < nDevices; ++i) {
for (UINT i = 0; i < nDevices; ++i)
{
if (pRawInputDeviceList[i].dwType != 2) continue;
HANDLE hDevice = pRawInputDeviceList[i].hDevice;
@@ -117,20 +96,94 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
continue;
FFGamepadDevice* device = (FFGamepadDevice*) ffListAdd(devices);
ffStrbufInitWS(&device->identifier, devName);
ffStrbufInit(&device->serial);
ffStrbufInit(&device->name);
device->battery = 0;
const char* knownGamepad = detectKnownGamepad(rdi.hid.dwVendorId, rdi.hid.dwProductId);
const char* knownGamepad = detectKnownDeviceName(rdi.hid.dwVendorId, rdi.hid.dwProductId);
if (knownGamepad)
ffStrbufSetS(&device->name, knownGamepad);
else
HANDLE FF_AUTO_CLOSE_FD hHidFile = CreateFileW(devName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
if (!hHidFile)
{
if (!knownGamepad)
ffStrbufSetF(&device->name, "Unknown gamepad %04X-%04X", (unsigned) rdi.hid.dwVendorId, (unsigned) rdi.hid.dwProductId);
continue;
}
if (!knownGamepad)
{
wchar_t displayName[126];
HANDLE FF_AUTO_CLOSE_FD hHidFile = CreateFileW(devName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if (hHidFile && HidD_GetProductString(hHidFile, displayName, sizeof(wchar_t) * 126))
ffStrbufSetWS(&device->name, displayName);
else
ffStrbufSetF(&device->name, "Unknown gamepad %4X-%4X", (unsigned) rdi.hid.dwVendorId, (unsigned) rdi.hid.dwProductId);
if (HidD_GetProductString(hHidFile, displayName, sizeof(displayName)))
{
wchar_t manufacturer[126];
if (HidD_GetManufacturerString(hHidFile, manufacturer, sizeof(manufacturer)))
{
ffStrbufSetWS(&device->name, manufacturer);
FF_STRBUF_AUTO_DESTROY displayNameStr = ffStrbufCreateWS(displayName);
ffStrbufAppendC(&device->name, ' ');
ffStrbufAppend(&device->name, &displayNameStr);
}
else
{
ffStrbufSetWS(&device->name, displayName);
}
}
}
PHIDP_PREPARSED_DATA preparsedData = NULL;
if (HidD_GetPreparsedData(hHidFile, &preparsedData))
{
HIDP_CAPS caps;
NTSTATUS capsResult = HidP_GetCaps(preparsedData, &caps);
HidD_FreePreparsedData(preparsedData);
if (!NT_SUCCESS(capsResult))
continue;
wchar_t serialNumber[127] = L"";
if (HidD_GetSerialNumberString(hHidFile, serialNumber, sizeof(serialNumber)))
ffStrbufSetWS(&device->serial, serialNumber);
if (
(rdi.hid.dwVendorId == 0x054C && (
rdi.hid.dwProductId == 0x05C4 || // PS4 Gen1
rdi.hid.dwProductId == 0x09CC // PS4 Gen2
)) ||
(rdi.hid.dwVendorId == 0x057E && (
rdi.hid.dwProductId == 0x2009 // NS Pro
))
)
{
// Controller must be connected by other programs
FF_AUTO_FREE uint8_t* reportBuffer = malloc(caps.InputReportByteLength);
OVERLAPPED overlapped = { };
DWORD nBytes;
if (ReadFile(hHidFile, reportBuffer, caps.InputReportByteLength, &nBytes, &overlapped) ||
(WaitForSingleObject(hHidFile, FF_IO_TERM_RESP_WAIT_MS) == WAIT_OBJECT_0 && GetOverlappedResult(hHidFile, &overlapped, &nBytes, FALSE)))
{
if (rdi.hid.dwVendorId == 0x054C)
{
if (nBytes > 31)
{
uint8_t batteryInfo = reportBuffer[caps.InputReportByteLength == 64 /*USB?*/ ? 30 : 32];
device->battery = (uint8_t) ((batteryInfo & 0x0f) * 100 / (batteryInfo & 0x10 /*charging?*/ ? 11 /*BATTERY_MAX_USB*/ : 8 /*BATTERY_MAX*/));
if (device->battery > 100) device->battery = 100;
}
}
else
{
if (nBytes > 3 && reportBuffer[0] == 0x30)
{
uint8_t batteryInfo = reportBuffer[2];
device->battery = (uint8_t) (((batteryInfo & 0xE0) >> 4) * 100 / 8);
if (device->battery == 0) device->battery = 1;
else if (device->battery > 100) device->battery = 100;
}
}
}
else
CancelIo(hHidFile);
}
}
}
+58 -6
View File
@@ -1,6 +1,6 @@
#include "gpu.h"
#include "detection/internal.h"
#include "detection/vulkan/vulkan.h"
#include "detection/opengl/opengl.h"
const char* FF_GPU_VENDOR_NAME_APPLE = "Apple";
const char* FF_GPU_VENDOR_NAME_AMD = "AMD";
@@ -46,17 +46,69 @@ const char* ffGetGPUVendorString(unsigned vendorId)
return NULL;
}
const char* detectByOpenGL(FFlist* gpus)
{
FFOpenGLResult result;
ffStrbufInit(&result.version);
ffStrbufInit(&result.renderer);
ffStrbufInit(&result.vendor);
ffStrbufInit(&result.slv);
const char* error = ffDetectOpenGL(&instance.config.modules.openGL, &result);
if (!error)
{
FFGPUResult* gpu = (FFGPUResult*) ffListAdd(gpus);
gpu->type = FF_GPU_TYPE_UNKNOWN;
ffStrbufInitMove(&gpu->vendor, &result.vendor);
ffStrbufInitMove(&gpu->name, &result.renderer);
ffStrbufInit(&gpu->driver);
ffStrbufInitF(&gpu->platformApi, "OpenGL %s", result.version.chars);
gpu->temperature = FF_GPU_TEMP_UNSET;
gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;
gpu->frequency = FF_GPU_FREQUENCY_UNSET;
gpu->dedicated = gpu->shared = (FFGPUMemory){0, 0};
gpu->deviceId = 0;
if (ffStrbufIgnCaseEqualS(&gpu->vendor, "Mesa"))
ffStrbufClear(&gpu->vendor);
if (!gpu->vendor.length)
{
if (ffStrbufContainS(&gpu->name, "Apple"))
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_APPLE);
else if (ffStrbufContainS(&gpu->name, "Intel"))
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_INTEL);
else if (ffStrbufContainS(&gpu->name, "AMD") || ffStrbufContainS(&gpu->name, "ATI"))
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_AMD);
else if (ffStrbufContainS(&gpu->name, "NVIDIA"))
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_NVIDIA);
}
if (ffStrbufEqualS(&gpu->vendor, FF_GPU_VENDOR_NAME_APPLE))
gpu->type = FF_GPU_TYPE_INTEGRATED;
}
ffStrbufDestroy(&result.version);
ffStrbufDestroy(&result.renderer);
ffStrbufDestroy(&result.vendor);
ffStrbufDestroy(&result.slv);
return error;
}
const char* ffDetectGPU(const FFGPUOptions* options, FFlist* result)
{
if (!options->forceVulkan)
{
const char* error = ffDetectGPUImpl(options, result);
if (!error) return NULL;
if (!error && result->length > 0) return NULL;
}
FFVulkanResult* vulkan = ffDetectVulkan();
if (vulkan->error) return "GPU detection failed";
ffListDestroy(result);
ffListInitMove(result, &vulkan->gpus);
if (!vulkan->error && vulkan->gpus.length > 0)
{
ffListDestroy(result);
ffListInitMove(result, &vulkan->gpus);
return NULL;
}
if (detectByOpenGL(result) == NULL)
return NULL;
return NULL;
return "GPU detection failed";
}
+5 -2
View File
@@ -5,6 +5,7 @@
#define FF_GPU_TEMP_UNSET (0/0.0)
#define FF_GPU_CORE_COUNT_UNSET -1
#define FF_GPU_VMEM_SIZE_UNSET ((uint64_t)-1)
#define FF_GPU_FREQUENCY_UNSET (0/0.0)
extern const char* FF_GPU_VENDOR_NAME_APPLE;
extern const char* FF_GPU_VENDOR_NAME_AMD;
@@ -28,11 +29,13 @@ typedef struct FFGPUResult
FFstrbuf vendor;
FFstrbuf name;
FFstrbuf driver;
FFstrbuf platformApi;
double temperature;
int coreCount;
int32_t coreCount;
double frequency; // Real time clock frequency in GHz
FFGPUMemory dedicated;
FFGPUMemory shared;
uint32_t vulkanDeviceId; // Only used for vulkan
uint64_t deviceId; // Used internally, may be uninitialized
} FFGPUResult;
const char* ffDetectGPU(const FFGPUOptions* options, FFlist* result);
+67
View File
@@ -0,0 +1,67 @@
#include "gpu_driver_specific.h"
// Everything detected in this file is static.
// The real time monitoring requires ADLX, whose interface is much more complicated than AGS
// Whoever has AMD graphic cards interested in this may contribute
// * ADLX (AMD Device Library eXtra): https://github.com/GPUOpen-LibrariesAndSDKs/ADLX
#include "3rdparty/ags/amd_ags.h"
#include "common/library.h"
#include "util/mallocHelper.h"
const char* ffDetectAmdGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResult result, const char* soName)
{
static bool inited = false;
static AGSGPUInfo gpuInfo;
if (!inited)
{
inited = true;
FF_LIBRARY_LOAD(libags, NULL, "dlopen amd_ags failed", soName , 1);
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libags, agsInitialize)
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libags, agsDeInitialize)
struct AGSContext* apiHandle;
if (ffagsInitialize(AGS_CURRENT_VERSION, NULL, &apiHandle, &gpuInfo) != AGS_SUCCESS)
return "loading ags library failed";
ffagsDeInitialize(apiHandle);
}
if (gpuInfo.numDevices == 0)
return "loading ags library failed or no AMD gpus found";
AGSDeviceInfo* device = NULL;
for (int iDev = 0; iDev < gpuInfo.numDevices; iDev++)
{
if (cond->type & FF_GPU_DRIVER_CONDITION_TYPE_DEVICE_ID)
{
if (
cond->pciDeviceId.deviceId == (uint32_t) gpuInfo.devices[iDev].deviceId &&
cond->pciDeviceId.vendorId == (uint32_t) gpuInfo.devices[iDev].vendorId &&
cond->pciDeviceId.revId == (uint32_t) gpuInfo.devices[iDev].revisionId)
{
device = &gpuInfo.devices[iDev];
break;
}
}
}
if (!device)
return "Device not found";
if (result.coreCount)
*result.coreCount = (uint32_t) device->numCUs;
if (result.memory)
{
result.memory->total = device->localMemoryInBytes;
result.memory->used = FF_GPU_VMEM_SIZE_UNSET;
}
if (result.frequency)
*result.frequency = device->coreClock / 1000.; // Maximum frequency
return NULL;
}
+15 -10
View File
@@ -6,6 +6,8 @@
#include <IOKit/graphics/IOGraphicsLib.h>
const char* ffGpuDetectMetal(FFlist* gpus);
static double detectGpuTemp(const FFstrbuf* gpuName)
{
double result = 0;
@@ -15,18 +17,18 @@ static double detectGpuTemp(const FFstrbuf* gpuName)
{
switch (strtol(gpuName->chars + strlen("Apple M"), NULL, 10))
{
case 1: error = ffDetectCoreTemps(FF_TEMP_GPU_M1X, &result); break;
case 2: error = ffDetectCoreTemps(FF_TEMP_GPU_M2X, &result); break;
case 3: error = ffDetectCoreTemps(FF_TEMP_GPU_M3X, &result); break;
case 1: error = ffDetectSmcTemps(FF_TEMP_GPU_M1X, &result); break;
case 2: error = ffDetectSmcTemps(FF_TEMP_GPU_M2X, &result); break;
case 3: error = ffDetectSmcTemps(FF_TEMP_GPU_M3X, &result); break;
default: error = "Unsupported Apple Silicon GPU";
}
}
else if (ffStrbufStartsWithS(gpuName, "Intel"))
error = ffDetectCoreTemps(FF_TEMP_GPU_INTEL, &result);
error = ffDetectSmcTemps(FF_TEMP_GPU_INTEL, &result);
else if (ffStrbufStartsWithS(gpuName, "Radeon") || ffStrbufStartsWithS(gpuName, "AMD"))
error = ffDetectCoreTemps(FF_TEMP_GPU_AMD, &result);
error = ffDetectSmcTemps(FF_TEMP_GPU_AMD, &result);
else
error = ffDetectCoreTemps(FF_TEMP_GPU_UNKNOWN, &result);
error = ffDetectSmcTemps(FF_TEMP_GPU_UNKNOWN, &result);
if (error)
return FF_GPU_TEMP_UNSET;
@@ -36,12 +38,12 @@ static double detectGpuTemp(const FFstrbuf* gpuName)
const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus)
{
io_iterator_t iterator;
if(IOServiceGetMatchingServices(MACH_PORT_NULL, IOServiceMatching(kIOAcceleratorClassName), &iterator) != kIOReturnSuccess)
FF_IOOBJECT_AUTO_RELEASE io_iterator_t iterator = IO_OBJECT_NULL;
if (IOServiceGetMatchingServices(MACH_PORT_NULL, IOServiceMatching(kIOAcceleratorClassName), &iterator) != kIOReturnSuccess)
return "IOServiceGetMatchingServices() failed";
io_registry_entry_t registryEntry;
while((registryEntry = IOIteratorNext(iterator)) != 0)
while ((registryEntry = IOIteratorNext(iterator)) != IO_OBJECT_NULL)
{
CFMutableDictionaryRef properties;
if(IORegistryEntryCreateCFProperties(registryEntry, &properties, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess)
@@ -54,6 +56,9 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus)
gpu->dedicated.total = gpu->dedicated.used = gpu->shared.total = gpu->shared.used = FF_GPU_VMEM_SIZE_UNSET;
gpu->type = FF_GPU_TYPE_UNKNOWN;
gpu->frequency = FF_GPU_FREQUENCY_UNSET;
IORegistryEntryGetRegistryEntryID(registryEntry, &gpu->deviceId);
ffStrbufInitStatic(&gpu->platformApi, "Metal");
ffStrbufInit(&gpu->driver); // Ok for both Apple and Intel
ffCfDictGetString(properties, CFSTR("CFBundleIdentifier"), &gpu->driver);
@@ -101,6 +106,6 @@ const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus)
IOObjectRelease(registryEntry);
}
IOObjectRelease(iterator);
ffGpuDetectMetal(gpus);
return NULL;
}
+51
View File
@@ -0,0 +1,51 @@
#include "gpu.h"
#import <Metal/MTLDevice.h>
#ifndef MAC_OS_VERSION_13_0
#define MTLGPUFamilyMetal3 ((MTLGPUFamily) 5001)
#endif
const char* ffGpuDetectMetal(FFlist* gpus)
{
if (@available(macOS 10.15, *))
{
for (id<MTLDevice> device in MTLCopyAllDevices())
{
FFGPUResult* gpu = NULL;
FF_LIST_FOR_EACH(FFGPUResult, x, *gpus)
{
if (x->deviceId == device.registryID)
{
gpu = x;
break;
}
}
if (!gpu) continue;
if ([device supportsFamily:MTLGPUFamilyMetal3])
ffStrbufSetStatic(&gpu->platformApi, "Metal 3");
else if ([device supportsFamily:MTLGPUFamilyCommon3])
ffStrbufSetStatic(&gpu->platformApi, "Metal Common 3");
else if ([device supportsFamily:MTLGPUFamilyCommon2])
ffStrbufSetStatic(&gpu->platformApi, "Metal Common 2");
else if ([device supportsFamily:MTLGPUFamilyCommon1])
ffStrbufSetStatic(&gpu->platformApi, "Metal Common 1");
if (gpu->type == device.hasUnifiedMemory)
{
gpu->type = FF_GPU_TYPE_INTEGRATED;
gpu->shared.total = device.recommendedMaxWorkingSetSize;
gpu->shared.used = device.currentAllocatedSize;
}
else
{
gpu->type = FF_GPU_TYPE_DISCRETE;
gpu->dedicated.total = device.recommendedMaxWorkingSetSize;
gpu->dedicated.used = device.currentAllocatedSize;
}
}
return NULL;
}
return "Metal API is not supported by this macOS version";
}
+49
View File
@@ -0,0 +1,49 @@
#pragma once
#include "gpu.h"
typedef enum FFGpuDriverConditionType
{
FF_GPU_DRIVER_CONDITION_TYPE_BUS_ID = 1 << 0,
FF_GPU_DRIVER_CONDITION_TYPE_DEVICE_ID = 1 << 1,
FF_GPU_DRIVER_CONDITION_TYPE_LUID = 1 << 2,
} FFGpuDriverConditionType;
typedef struct FFGpuDriverPciBusId
{
uint32_t domain;
uint32_t bus;
uint32_t device;
uint32_t func;
} FFGpuDriverPciBusId;
typedef struct FFGpuDriverPciDeviceId
{
uint32_t deviceId;
uint32_t vendorId;
uint32_t subSystemId;
uint32_t revId;
} FFGpuDriverPciDeviceId;
// Use pciBusId if not NULL; use pciDeviceId otherwise
typedef struct FFGpuDriverCondition
{
FFGpuDriverConditionType type;
FFGpuDriverPciBusId pciBusId;
FFGpuDriverPciDeviceId pciDeviceId;
uint64_t luid;
} FFGpuDriverCondition;
// detect x if not NULL
typedef struct FFGpuDriverResult
{
double* temp;
FFGPUMemory* memory;
uint32_t* coreCount;
FFGPUType* type;
double* frequency;
} FFGpuDriverResult;
const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResult result, const char* soName);
const char* ffDetectIntelGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResult result, const char* soName);
const char* ffDetectAmdGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResult result, const char* soName);
+200
View File
@@ -0,0 +1,200 @@
#include "gpu_driver_specific.h"
#include "3rdparty/igcl/igcl_api.h"
#include "common/library.h"
#include "util/mallocHelper.h"
struct FFIgclData {
FF_LIBRARY_SYMBOL(ctlClose)
FF_LIBRARY_SYMBOL(ctlEnumerateDevices)
FF_LIBRARY_SYMBOL(ctlGetDeviceProperties)
FF_LIBRARY_SYMBOL(ctlEnumTemperatureSensors)
FF_LIBRARY_SYMBOL(ctlTemperatureGetState)
FF_LIBRARY_SYMBOL(ctlEnumMemoryModules)
FF_LIBRARY_SYMBOL(ctlMemoryGetState)
FF_LIBRARY_SYMBOL(ctlEnumFrequencyDomains)
FF_LIBRARY_SYMBOL(ctlFrequencyGetState)
bool inited;
ctl_api_handle_t apiHandle;
} igclData;
static void shutdownIgcl()
{
if (igclData.apiHandle)
{
igclData.ffctlClose(igclData.apiHandle);
igclData.apiHandle = NULL;
}
}
const char* ffDetectIntelGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResult result, const char* soName)
{
if (!igclData.inited)
{
igclData.inited = true;
FF_LIBRARY_LOAD(libigcl, NULL, "dlopen igcl (ControlLib) failed", soName , 1);
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libigcl, ctlInit)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libigcl, igclData, ctlClose)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libigcl, igclData, ctlEnumerateDevices)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libigcl, igclData, ctlGetDeviceProperties)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libigcl, igclData, ctlEnumTemperatureSensors)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libigcl, igclData, ctlTemperatureGetState)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libigcl, igclData, ctlEnumMemoryModules)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libigcl, igclData, ctlMemoryGetState)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libigcl, igclData, ctlEnumFrequencyDomains)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libigcl, igclData, ctlFrequencyGetState)
if (ffctlInit(&(ctl_init_args_t) {
.AppVersion = CTL_MAKE_VERSION(CTL_IMPL_MAJOR_VERSION, CTL_IMPL_MINOR_VERSION),
.flags = CTL_INIT_FLAG_USE_LEVEL_ZERO,
.Size = sizeof(ctl_init_args_t),
.Version = 0,
}, &igclData.apiHandle) != CTL_RESULT_SUCCESS)
return "loading igcl library failed";
atexit(shutdownIgcl);
libigcl = NULL; // don't close igcl
}
if (!igclData.apiHandle)
return "loading igcl library failed";
uint32_t deviceCount = 0;
if (igclData.ffctlEnumerateDevices(igclData.apiHandle, &deviceCount, NULL))
return "ctlEnumerateDevices(NULL) failed";
if (deviceCount == 0)
return "No Intel graphics adapter found";
FF_AUTO_FREE ctl_device_adapter_handle_t* devices = malloc(deviceCount * sizeof(*devices));
if (igclData.ffctlEnumerateDevices(igclData.apiHandle, &deviceCount, devices))
return "ctlEnumerateDevices(devices) failed";
ctl_device_adapter_handle_t device = NULL;
uint64_t /* LUID */ deviceId = 0;
ctl_device_adapter_properties_t properties = {
.Size = sizeof(properties),
.pDeviceID = &deviceId,
.device_id_size = sizeof(deviceId),
.Version = 2,
};
for (uint32_t iDev = 0; iDev < deviceCount; iDev++)
{
if (igclData.ffctlGetDeviceProperties(devices[iDev], &properties) != CTL_RESULT_SUCCESS)
continue;
if (properties.device_type != CTL_DEVICE_TYPE_GRAPHICS)
continue;
if (cond->type & FF_GPU_DRIVER_CONDITION_TYPE_LUID)
{
if (cond->luid == deviceId)
{
device = devices[iDev];
break;
}
}
else if (cond->type & FF_GPU_DRIVER_CONDITION_TYPE_BUS_ID)
{
if (cond->pciBusId.bus == properties.adapter_bdf.bus &&
cond->pciBusId.device == properties.adapter_bdf.device &&
cond->pciBusId.func == properties.adapter_bdf.function)
{
device = devices[iDev];
break;
}
}
else if (cond->type & FF_GPU_DRIVER_CONDITION_TYPE_DEVICE_ID)
{
if (
cond->pciDeviceId.deviceId == properties.pci_device_id &&
cond->pciDeviceId.vendorId == properties.pci_vendor_id &&
cond->pciDeviceId.subSystemId == (uint32_t) ((properties.pci_subsys_id << 16u) | properties.pci_subsys_vendor_id) &&
cond->pciDeviceId.revId == properties.rev_id)
{
device = devices[iDev];
break;
}
}
}
if (!device)
return "Device not found";
if (result.coreCount)
*result.coreCount = properties.num_slices * properties.num_sub_slices_per_slice * properties.num_eus_per_sub_slice;
if (result.memory)
{
ctl_mem_handle_t memoryModules[16];
uint32_t memoryCount = sizeof(memoryModules) / sizeof(memoryModules[0]);
if (igclData.ffctlEnumMemoryModules(device, &memoryCount, memoryModules) == CTL_RESULT_SUCCESS && memoryCount > 0)
{
result.memory->used = 0;
result.memory->total = 0;
for (uint32_t iMem = 0; iMem < memoryCount; iMem++)
{
ctl_mem_state_t memoryState = {
.Size = sizeof(ctl_mem_state_t),
.Version = 0,
};
if (igclData.ffctlMemoryGetState(memoryModules[iMem], &memoryState) == CTL_RESULT_SUCCESS)
{
result.memory->total += memoryState.size;
result.memory->used += memoryState.size - memoryState.free;
}
}
}
}
if (result.type)
{
*result.type = properties.graphics_adapter_properties & CTL_ADAPTER_PROPERTIES_FLAG_INTEGRATED
? FF_GPU_TYPE_INTEGRATED : FF_GPU_TYPE_DISCRETE;
}
if (result.temp)
{
ctl_temp_handle_t sensors[16];
uint32_t sensorCount = sizeof(sensors) / sizeof(sensors[0]);
if (igclData.ffctlEnumTemperatureSensors(device, &sensorCount, sensors) == CTL_RESULT_SUCCESS && sensorCount > 0)
{
double sumValue = 0;
uint32_t availableCount = 0;
for (uint32_t iSensor = 0; iSensor < sensorCount; iSensor++)
{
double value;
if (igclData.ffctlTemperatureGetState(sensors[iSensor], &value) == CTL_RESULT_SUCCESS)
{
sumValue += value;
availableCount++;
}
}
*result.temp = sumValue / availableCount;
}
}
if (result.frequency)
{
ctl_freq_handle_t freqs[16];
uint32_t freqCount = sizeof(freqs) / sizeof(freqs[0]);
if (igclData.ffctlEnumFrequencyDomains(device, &freqCount, freqs) == CTL_RESULT_SUCCESS && freqCount > 0)
{
double sumValue = 0;
uint32_t availableCount = 0;
for (uint32_t iFreq = 0; iFreq < freqCount; iFreq++)
{
ctl_freq_state_t state = { .Size = sizeof(state), .Version = 0 };
if (igclData.ffctlFrequencyGetState(freqs[iFreq], &state) == CTL_RESULT_SUCCESS)
{
sumValue += state.actual;
availableCount++;
}
}
*result.frequency = (sumValue / availableCount) / 1000.;
}
}
return NULL;
}
+29 -12
View File
@@ -1,7 +1,10 @@
#include "detection/gpu/gpu.h"
#include "detection/gpu/gpu_nvidia.h"
#include "detection/vulkan/vulkan.h"
#ifdef FF_USE_PROPRIETARY_GPU_DRIVER_API
#include "detection/gpu/gpu_driver_specific.h"
#endif
#ifdef FF_HAVE_LIBPCI
#include "common/io/io.h"
#include "common/library.h"
@@ -46,12 +49,14 @@ static void pciDetectVendorName(FFGPUResult* gpu, PCIData* pci, struct pci_dev*
pci->ffpci_lookup_name(pci->access, gpu->vendor.chars, (int) gpu->vendor.allocated, PCI_LOOKUP_VENDOR, device->vendor_id);
ffStrbufRecalculateLength(&gpu->vendor);
if(ffStrbufContainS(&gpu->vendor, "AMD") || ffStrbufContainS(&gpu->vendor, "ATI"))
if(ffStrbufContainIgnCaseS(&gpu->vendor, "AMD") || ffStrbufContainS(&gpu->vendor, "ATI"))
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_AMD);
else if(ffStrbufContainS(&gpu->vendor, "Intel"))
else if(ffStrbufContainIgnCaseS(&gpu->vendor, "Intel"))
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_INTEL);
else if(ffStrbufContainS(&gpu->vendor, "NVIDIA"))
else if(ffStrbufContainIgnCaseS(&gpu->vendor, "NVIDIA"))
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_NVIDIA);
else if(ffStrbufContainIgnCaseS(&gpu->vendor, "Apple"))
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_APPLE);
}
static void drmDetectDeviceName(FFGPUResult* gpu, PCIData* pci, struct pci_dev* device)
@@ -133,7 +138,7 @@ static void pciDetectDriverName(FFGPUResult* gpu, PCIData* pci, struct pci_dev*
ffStrbufAppendC(&gpu->driver, ' ');
ffStrbufAppendS(&path, "/module/version");
ffAppendFileBuffer(path.chars, &gpu->driver);
ffStrbufTrimRight(&gpu->driver, ' ');
ffStrbufTrimRightSpace(&gpu->driver);
}
FF_MAYBE_UNUSED static void pciDetectTemp(FFGPUResult* gpu, struct pci_dev* device)
@@ -219,6 +224,8 @@ static void pciHandleDevice(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
FFGPUResult* gpu = ffListAdd(results);
ffStrbufInit(&gpu->platformApi);
ffStrbufInit(&gpu->vendor);
pciDetectVendorName(gpu, pci, device);
@@ -239,21 +246,31 @@ static void pciHandleDevice(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;
gpu->temperature = FF_GPU_TEMP_UNSET;
gpu->frequency = FF_GPU_FREQUENCY_UNSET;
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA && (options->temp || options->useNvml))
#ifdef FF_USE_PROPRIETARY_GPU_DRIVER_API
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA && (options->temp || options->driverSpecific))
{
char pciDeviceId[32];
snprintf(pciDeviceId, sizeof(pciDeviceId) - 1, "%04x:%02x:%02x.%d", device->domain, device->bus, device->dev, device->func);
ffDetectNvidiaGpuInfo((FFGpuNvidiaCondition) { .pciBusId = pciDeviceId }, (FFGpuNvidiaResult) {
ffDetectNvidiaGpuInfo(&(FFGpuDriverCondition) {
.type = FF_GPU_DRIVER_CONDITION_TYPE_BUS_ID,
.pciBusId = {
.domain = (uint32_t) device->domain,
.bus = device->bus,
.device = device->dev,
.func = device->func,
},
}, (FFGpuDriverResult) {
.temp = options->temp ? &gpu->temperature : NULL,
.memory = options->useNvml ? &gpu->dedicated : NULL,
.coreCount = options->useNvml ? (uint32_t*) &gpu->coreCount : NULL,
.memory = options->driverSpecific ? &gpu->dedicated : NULL,
.coreCount = options->driverSpecific ? (uint32_t*) &gpu->coreCount : NULL,
.type = &gpu->type,
.frequency = &gpu->frequency,
}, "libnvidia-ml.so");
if (gpu->dedicated.total != FF_GPU_VMEM_SIZE_UNSET)
gpu->type = gpu->dedicated.total > (uint64_t)1024 * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED;
}
#endif // FF_USE_PROPRIETARY_GPU_DRIVER_API
#ifdef __linux__
if(options->temp && gpu->temperature != gpu->temperature)
+39 -6
View File
@@ -1,4 +1,4 @@
#include "gpu_nvidia.h"
#include "gpu_driver_specific.h"
#include "3rdparty/nvml/nvml.h"
#include "common/library.h"
@@ -11,11 +11,13 @@ struct FFNvmlData {
FF_LIBRARY_SYMBOL(nvmlDeviceGetTemperature)
FF_LIBRARY_SYMBOL(nvmlDeviceGetMemoryInfo_v2)
FF_LIBRARY_SYMBOL(nvmlDeviceGetNumGpuCores)
FF_LIBRARY_SYMBOL(nvmlDeviceGetClockInfo)
FF_LIBRARY_SYMBOL(nvmlDeviceGetBrand)
bool inited;
} nvmlData;
const char* ffDetectNvidiaGpuInfo(FFGpuNvidiaCondition cond, FFGpuNvidiaResult result, const char* soName)
const char* ffDetectNvidiaGpuInfo(const FFGpuDriverCondition* cond, FFGpuDriverResult result, const char* soName)
{
if (!nvmlData.inited)
{
@@ -30,6 +32,8 @@ const char* ffDetectNvidiaGpuInfo(FFGpuNvidiaCondition cond, FFGpuNvidiaResult r
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetTemperature)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetMemoryInfo_v2)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetNumGpuCores)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetClockInfo)
FF_LIBRARY_LOAD_SYMBOL_VAR_MESSAGE(libnvml, nvmlData, nvmlDeviceGetBrand)
if (ffnvmlInit_v2() != NVML_SUCCESS)
{
@@ -44,13 +48,16 @@ const char* ffDetectNvidiaGpuInfo(FFGpuNvidiaCondition cond, FFGpuNvidiaResult r
return "loading nvml library failed";
nvmlDevice_t device = NULL;
if (cond.pciBusId)
if (cond->type & FF_GPU_DRIVER_CONDITION_TYPE_BUS_ID)
{
nvmlReturn_t ret = nvmlData.ffnvmlDeviceGetHandleByPciBusId_v2(cond.pciBusId, &device);
char pciBusIdStr[32];
snprintf(pciBusIdStr, sizeof(pciBusIdStr) - 1, "%04x:%02x:%02x.%d", cond->pciBusId.domain, cond->pciBusId.bus, cond->pciBusId.device, cond->pciBusId.func);
nvmlReturn_t ret = nvmlData.ffnvmlDeviceGetHandleByPciBusId_v2(pciBusIdStr, &device);
if (ret != NVML_SUCCESS)
return "nvmlDeviceGetHandleByPciBusId_v2() failed";
}
else
else if (cond->type & FF_GPU_DRIVER_CONDITION_TYPE_DEVICE_ID)
{
uint32_t count;
if (nvmlData.ffnvmlDeviceGetCount_v2(&count) != NVML_SUCCESS)
@@ -65,7 +72,8 @@ const char* ffDetectNvidiaGpuInfo(FFGpuNvidiaCondition cond, FFGpuNvidiaResult r
if (nvmlData.ffnvmlDeviceGetPciInfo_v3(device, &pciInfo) != NVML_SUCCESS)
continue;
if (pciInfo.pciDeviceId != cond.pciDeviceId || pciInfo.pciSubSystemId != cond.pciSubSystemId)
if (pciInfo.pciDeviceId != ((cond->pciDeviceId.deviceId << 16u) | cond->pciDeviceId.vendorId) ||
pciInfo.pciSubSystemId != cond->pciDeviceId.subSystemId)
continue;
break;
@@ -73,6 +81,24 @@ const char* ffDetectNvidiaGpuInfo(FFGpuNvidiaCondition cond, FFGpuNvidiaResult r
if (!device) return "Device not found";
}
nvmlBrandType_t brand;
if (nvmlData.ffnvmlDeviceGetBrand(device, &brand) == NVML_SUCCESS)
{
switch (brand)
{
case NVML_BRAND_NVIDIA_RTX:
case NVML_BRAND_QUADRO_RTX:
case NVML_BRAND_GEFORCE:
case NVML_BRAND_TITAN:
case NVML_BRAND_TESLA:
case NVML_BRAND_QUADRO:
*result.type = FF_GPU_TYPE_DISCRETE;
break;
default:
break;
}
}
if (result.temp)
{
uint32_t value;
@@ -93,5 +119,12 @@ const char* ffDetectNvidiaGpuInfo(FFGpuNvidiaCondition cond, FFGpuNvidiaResult r
if (result.coreCount)
nvmlData.ffnvmlDeviceGetNumGpuCores(device, result.coreCount);
if (result.frequency)
{
uint32_t clockMHz;
if (nvmlData.ffnvmlDeviceGetClockInfo(device, NVML_CLOCK_GRAPHICS, &clockMHz) == NVML_SUCCESS)
*result.frequency = clockMHz / 1000.;
}
return NULL;
}
-23
View File
@@ -1,23 +0,0 @@
#pragma once
#include "gpu.h"
// Use pciBusId if not NULL; use pciDeviceId and pciSubSystemId otherwise
typedef struct FFGpuNvidiaCondition
{
// "domain:bus:device.function"
const char* pciBusId;
// (deviceId << 16) | vendorId
uint32_t pciDeviceId;
uint32_t pciSubSystemId;
} FFGpuNvidiaCondition;
// detect x if not NULL
typedef struct FFGpuNvidiaResult
{
double* temp;
FFGPUMemory* memory;
uint32_t* coreCount;
} FFGpuNvidiaResult;
const char* ffDetectNvidiaGpuInfo(FFGpuNvidiaCondition cond, FFGpuNvidiaResult result, const char* soName);
+98 -25
View File
@@ -1,8 +1,11 @@
#include "gpu.h"
#include "detection/gpu/gpu_nvidia.h"
#include "util/windows/unicode.h"
#include "util/windows/registry.h"
#ifdef FF_USE_PROPRIETARY_GPU_DRIVER_API
#include "detection/gpu/gpu_driver_specific.h"
#endif
#include <inttypes.h>
static int isGpuNameEqual(const FFGPUResult* gpu, const FFstrbuf* name)
@@ -10,6 +13,43 @@ static int isGpuNameEqual(const FFGPUResult* gpu, const FFstrbuf* name)
return ffStrbufEqual(&gpu->name, name);
}
#ifdef FF_USE_PROPRIETARY_GPU_DRIVER_API
static inline bool getDriverSpecificDetectionFn(const char* vendor, __typeof__(&ffDetectNvidiaGpuInfo)* pDetectFn, const char** pDllName)
{
if (vendor == FF_GPU_VENDOR_NAME_NVIDIA)
{
*pDetectFn = ffDetectNvidiaGpuInfo;
*pDllName = "nvml.dll";
}
else if (vendor == FF_GPU_VENDOR_NAME_INTEL)
{
*pDetectFn = ffDetectIntelGpuInfo;
#ifdef _WIN64
*pDllName = "ControlLib.dll";
#else
*pDllName = "ControlLib32.dll";
#endif
}
else if (vendor == FF_GPU_VENDOR_NAME_AMD)
{
*pDetectFn = ffDetectAmdGpuInfo;
#ifdef _WIN64
*pDllName = "amd_ags_x64.dll";
#else
*pDllName = "amd_ags_x86.dll";
#endif
}
else
{
*pDetectFn = NULL;
*pDllName = NULL;
return false;
}
return true;
}
#endif // FF_USE_PROPRIETARY_GPU_DRIVER_API
const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist* gpus)
{
DISPLAY_DEVICEW displayDevice = { .cb = sizeof(displayDevice) };
@@ -35,14 +75,22 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
if (ffListContains(gpus, &gpuName, (void*) isGpuNameEqual)) continue;
}
// See: https://download.nvidia.com/XFree86/Linux-x86_64/545.23.06/README/supportedchips.html
// displayDevice.DeviceID = MatchingDeviceId "PCI\\VEN_10DE&DEV_2782&SUBSYS_513417AA&REV_A1"
uint32_t vendorId = 0, deviceId = 0, subSystemId = 0, revId = 0;
swscanf(displayDevice.DeviceID, L"PCI\\VEN_%x&DEV_%x&SUBSYS_%x&REV_%x", &vendorId, &deviceId, &subSystemId, &revId);
FFGPUResult* gpu = (FFGPUResult*)ffListAdd(gpus);
ffStrbufInit(&gpu->vendor);
ffStrbufInitStatic(&gpu->vendor, ffGetGPUVendorString(vendorId));
ffStrbufInitWS(&gpu->name, displayDevice.DeviceString);
ffStrbufInit(&gpu->driver);
ffStrbufInitStatic(&gpu->platformApi, "Direct3D");
gpu->temperature = FF_GPU_TEMP_UNSET;
gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;
gpu->type = FF_GPU_TYPE_UNKNOWN;
gpu->dedicated.total = gpu->dedicated.used = gpu->shared.total = gpu->shared.used = FF_GPU_VMEM_SIZE_UNSET;
gpu->deviceId = 0;
gpu->frequency = FF_GPU_FREQUENCY_UNSET;
if (deviceKeyLength == 100 && displayDevice.DeviceKey[deviceKeyPrefixLength - 1] == '{')
{
@@ -51,14 +99,6 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
if (!ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, regControlVideoKey, &hKey, NULL)) continue;
ffRegReadStrbuf(hKey, L"DriverVersion", &gpu->driver, NULL);
ffRegReadStrbuf(hKey, L"ProviderName", &gpu->vendor, NULL);
if(ffStrbufContainS(&gpu->vendor, "AMD") || ffStrbufContainS(&gpu->vendor, "ATI"))
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_AMD);
else if(ffStrbufContainS(&gpu->vendor, "Intel"))
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_INTEL);
else if(ffStrbufContainS(&gpu->vendor, "NVIDIA"))
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_NVIDIA);
wmemcpy(regDirectxKey + regDirectxKeyPrefixLength, displayDevice.DeviceKey + deviceKeyPrefixLength, strlen("00000000-0000-0000-0000-000000000000}"));
FF_HKEY_AUTO_DESTROY hDirectxKey = NULL;
@@ -75,6 +115,14 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
gpu->dedicated.total = dedicatedVideoMemory + dedicatedSystemMemory;
gpu->shared.total = sharedSystemMemory;
}
ffRegReadUint64(hDirectxKey, L"AdapterLuid", &gpu->deviceId, NULL);
uint32_t featureLevel = 0;
if(ffRegReadUint(hDirectxKey, L"MaxD3D12FeatureLevel", &featureLevel, NULL) && featureLevel)
ffStrbufSetF(&gpu->platformApi, "Direct3D 12.%u", (featureLevel & 0x0F00) >> 8);
else if(ffRegReadUint(hDirectxKey, L"MaxD3D11FeatureLevel", &featureLevel, NULL) && featureLevel)
ffStrbufSetF(&gpu->platformApi, "Direct3D 11.%u", (featureLevel & 0x0F00) >> 8);
}
else if (!ffRegReadUint64(hKey, L"HardwareInformation.qwMemorySize", &gpu->dedicated.total, NULL))
{
@@ -83,25 +131,50 @@ const char* ffDetectGPUImpl(FF_MAYBE_UNUSED const FFGPUOptions* options, FFlist*
gpu->dedicated.total = vmem;
gpu->type = gpu->dedicated.total > 1024 * 1024 * 1024 ? FF_GPU_TYPE_DISCRETE : FF_GPU_TYPE_INTEGRATED;
}
}
if (gpu->vendor.chars == FF_GPU_VENDOR_NAME_NVIDIA && (options->temp || options->useNvml))
{
uint32_t vendorId, deviceId, subSystemId;
// See: https://download.nvidia.com/XFree86/Linux-x86_64/545.23.06/README/supportedchips.html
// displayDevice.DeviceID = MatchingDeviceId "PCI\\VEN_10DE&DEV_2782&SUBSYS_513417AA&REV_A1"
if (swscanf(displayDevice.DeviceID, L"PCI\\VEN_%x&DEV_%x&SUBSYS_%x", &vendorId, &deviceId, &subSystemId) == 3)
if (gpu->vendor.length == 0)
{
ffDetectNvidiaGpuInfo((FFGpuNvidiaCondition) {
.pciDeviceId = (deviceId << 16) | vendorId,
.pciSubSystemId = subSystemId,
}, (FFGpuNvidiaResult) {
.temp = options->temp ? &gpu->temperature : NULL,
.memory = options->useNvml ? &gpu->dedicated : NULL,
.coreCount = options->useNvml ? (uint32_t*) &gpu->coreCount : NULL,
}, "nvml.dll");
ffRegReadStrbuf(hKey, L"ProviderName", &gpu->vendor, NULL);
if (ffStrbufContainS(&gpu->vendor, "Intel"))
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_INTEL);
else if (ffStrbufContainS(&gpu->vendor, "NVIDIA"))
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_NVIDIA);
else if (ffStrbufContainS(&gpu->vendor, "AMD") || ffStrbufContainS(&gpu->vendor, "ATI"))
ffStrbufSetStatic(&gpu->vendor, FF_GPU_VENDOR_NAME_AMD);
}
}
#ifdef FF_USE_PROPRIETARY_GPU_DRIVER_API
__typeof__(&ffDetectNvidiaGpuInfo) detectFn;
const char* dllName;
if (getDriverSpecificDetectionFn(gpu->vendor.chars, &detectFn, &dllName) && (options->temp || options->driverSpecific))
{
if (vendorId && deviceId && subSystemId && revId)
{
detectFn(
&(FFGpuDriverCondition) {
.type = FF_GPU_DRIVER_CONDITION_TYPE_DEVICE_ID | FF_GPU_DRIVER_CONDITION_TYPE_LUID,
.pciDeviceId = {
.deviceId = deviceId,
.vendorId = vendorId,
.subSystemId = subSystemId,
.revId = revId,
},
.luid = gpu->deviceId,
},
(FFGpuDriverResult) {
.temp = options->temp ? &gpu->temperature : NULL,
.memory = options->driverSpecific ? &gpu->dedicated : NULL,
.coreCount = options->driverSpecific ? (uint32_t*) &gpu->coreCount : NULL,
.type = &gpu->type,
.frequency = &gpu->frequency,
},
dllName
);
}
}
#endif // FF_USE_PROPRIETARY_GPU_DRIVER_API
}
return NULL;
+21 -9
View File
@@ -4,7 +4,7 @@
extern "C" {
#include "common/library.h"
#include "detection/gpu/gpu.h"
#include "detection/gpu/gpu_nvidia.h"
#include "detection/gpu/gpu_driver_specific.h"
}
#include <wsl/winadapter.h>
@@ -14,6 +14,8 @@ extern "C" {
#include <utility>
#include <cinttypes>
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
template <typename Fn>
struct on_scope_exit {
on_scope_exit(Fn &&fn): _fn(std::move(fn)) {}
@@ -65,6 +67,7 @@ const char* ffGPUDetectByDirectX(FF_MAYBE_UNUSED const FFGPUOptions* options, FF
ffStrbufInitS(&gpu->name, desc);
gpu->coreCount = FF_GPU_CORE_COUNT_UNSET;
gpu->temperature = FF_GPU_TEMP_UNSET;
gpu->frequency = FF_GPU_FREQUENCY_UNSET;
ffStrbufInit(&gpu->driver);
uint64_t value = 0;
@@ -95,18 +98,27 @@ const char* ffGPUDetectByDirectX(FF_MAYBE_UNUSED const FFGPUOptions* options, FF
const char* vendorStr = ffGetGPUVendorString((unsigned) hardwareId.vendorID);
ffStrbufSetStatic(&gpu->vendor, vendorStr);
if (vendorStr == FF_GPU_VENDOR_NAME_NVIDIA && options->useNvml)
#ifdef FF_USE_PROPRIETARY_GPU_DRIVER_API
if (vendorStr == FF_GPU_VENDOR_NAME_NVIDIA && (options->driverSpecific || options->temp))
{
ffDetectNvidiaGpuInfo((FFGpuNvidiaCondition) {
.pciBusId = nullptr,
.pciDeviceId = (hardwareId.deviceID << 16) | hardwareId.vendorID,
.pciSubSystemId = hardwareId.subSysID
}, (FFGpuNvidiaResult) {
FFGpuDriverCondition cond = {
.type = FF_GPU_DRIVER_CONDITION_TYPE_DEVICE_ID,
.pciDeviceId = {
.deviceId = hardwareId.deviceID,
.vendorId = hardwareId.vendorID,
.subSystemId = hardwareId.subSysID,
.revId = hardwareId.revision,
},
};
ffDetectNvidiaGpuInfo(&cond, (FFGpuDriverResult) {
.temp = options->temp ? &gpu->temperature : NULL,
.memory = options->useNvml ? &gpu->dedicated : NULL,
.coreCount = options->useNvml ? (uint32_t*) &gpu->coreCount : NULL,
.memory = options->driverSpecific ? &gpu->dedicated : NULL,
.coreCount = options->driverSpecific ? (uint32_t*) &gpu->coreCount : NULL,
.type = &gpu->type,
.frequency = &gpu->frequency,
}, "/usr/lib/wsl/lib/libnvidia-ml.so");
}
#endif
}
}
+7 -5
View File
@@ -4,11 +4,13 @@
typedef struct FFHostResult
{
FFstrbuf productFamily;
FFstrbuf productName;
FFstrbuf productVersion;
FFstrbuf productSku;
FFstrbuf sysVendor;
FFstrbuf family;
FFstrbuf name;
FFstrbuf version;
FFstrbuf sku;
FFstrbuf serial;
FFstrbuf uuid;
FFstrbuf vendor;
} FFHostResult;
const char* ffDetectHost(FFHostResult* host);
+17 -17
View File
@@ -5,32 +5,32 @@
const char* ffDetectHost(FFHostResult* host)
{
// http://newandroidbook.com/ddb/
ffSettingsGetAndroidProperty("ro.product.device", &host->productFamily);
ffSettingsGetAndroidProperty("ro.product.device", &host->family);
ffSettingsGetAndroidProperty("ro.product.marketname", &host->productName)
|| ffSettingsGetAndroidProperty("ro.vendor.product.display", &host->productName)
|| ffSettingsGetAndroidProperty("ro.config.devicename", &host->productName)
|| ffSettingsGetAndroidProperty("ro.config.marketing_name", &host->productName)
|| ffSettingsGetAndroidProperty("ro.product.vendor.model", &host->productName)
|| ffSettingsGetAndroidProperty("ro.product.oppo_model", &host->productName)
|| ffSettingsGetAndroidProperty("ro.oppo.market.name", &host->productName)
|| ffSettingsGetAndroidProperty("ro.product.brand", &host->productName);
ffSettingsGetAndroidProperty("ro.product.marketname", &host->name)
|| ffSettingsGetAndroidProperty("ro.vendor.product.display", &host->name)
|| ffSettingsGetAndroidProperty("ro.config.devicename", &host->name)
|| ffSettingsGetAndroidProperty("ro.config.marketing_name", &host->name)
|| ffSettingsGetAndroidProperty("ro.product.vendor.model", &host->name)
|| ffSettingsGetAndroidProperty("ro.product.oppo_model", &host->name)
|| ffSettingsGetAndroidProperty("ro.oppo.market.name", &host->name)
|| ffSettingsGetAndroidProperty("ro.product.brand", &host->name);
if (ffSettingsGetAndroidProperty("ro.product.model", &host->productVersion))
if (ffSettingsGetAndroidProperty("ro.product.model", &host->version))
{
if (ffStrbufStartsWithIgnCase(&host->productVersion, &host->productName))
if (ffStrbufStartsWithIgnCase(&host->version, &host->name))
{
ffStrbufSubstrAfter(&host->productVersion, host->productName.length);
ffStrbufTrimLeft(&host->productVersion, ' ');
ffStrbufSubstrAfter(&host->version, host->name.length);
ffStrbufTrimLeft(&host->version, ' ');
}
}
ffSettingsGetAndroidProperty("ro.product.manufacturer", &host->sysVendor);
ffSettingsGetAndroidProperty("ro.product.manufacturer", &host->vendor);
if(host->sysVendor.length && !ffStrbufStartsWithIgnCase(&host->productName, &host->sysVendor))
if(host->vendor.length && !ffStrbufStartsWithIgnCase(&host->name, &host->vendor))
{
ffStrbufPrependS(&host->productName, " ");
ffStrbufPrepend(&host->productName, &host->sysVendor);
ffStrbufPrependS(&host->name, " ");
ffStrbufPrepend(&host->name, &host->vendor);
}
return NULL;
+33 -25
View File
@@ -169,40 +169,48 @@ static const char* getProductNameWithHwModel(const FFstrbuf* hwModel)
const char* getProductNameWithIokit(FFstrbuf* result)
{
io_iterator_t iterator;
if(IOServiceGetMatchingServices(MACH_PORT_NULL, IOServiceNameMatching("product"), &iterator) != kIOReturnSuccess)
return "IOServiceGetMatchingServices() failed";
FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t registryEntry = IOServiceGetMatchingService(MACH_PORT_NULL, IOServiceNameMatching("product"));
if (!registryEntry)
return "IOServiceGetMatchingService() failed";
io_registry_entry_t registryEntry;
while((registryEntry = IOIteratorNext(iterator)) != 0)
{
FF_CFTYPE_AUTO_RELEASE CFMutableDictionaryRef properties = NULL;
if(IORegistryEntryCreateCFProperties(registryEntry, &properties, kCFAllocatorDefault, kNilOptions) != kIOReturnSuccess)
{
IOObjectRelease(registryEntry);
continue;
}
FF_CFTYPE_AUTO_RELEASE CFStringRef productName = IORegistryEntryCreateCFProperty(registryEntry, CFSTR("product-name"), kCFAllocatorDefault, kNilOptions);
if (!productName)
return "IORegistryEntryCreateCFProperty() failed";
if (ffCfDictGetString(properties, CFSTR("product-name"), result))
break;
}
return ffCfStrGetString(productName, result);
}
const char* getOthersByIokit(FFHostResult* host)
{
FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t registryEntry = IOServiceGetMatchingService(MACH_PORT_NULL, IOServiceMatching("IOPlatformExpertDevice"));
if (!registryEntry)
return "IOServiceGetMatchingService() failed";
FF_CFTYPE_AUTO_RELEASE CFStringRef serialNumber = IORegistryEntryCreateCFProperty(registryEntry, CFSTR(kIOPlatformSerialNumberKey), kCFAllocatorDefault, kNilOptions);
if (serialNumber)
ffCfStrGetString(serialNumber, &host->serial);
FF_CFTYPE_AUTO_RELEASE CFStringRef uuid = IORegistryEntryCreateCFProperty(registryEntry, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, kNilOptions);
if (uuid)
ffCfStrGetString(uuid, &host->uuid);
FF_CFTYPE_AUTO_RELEASE CFStringRef manufacturer = IORegistryEntryCreateCFProperty(registryEntry, CFSTR("manufacturer"), kCFAllocatorDefault, kNilOptions);
if (manufacturer)
ffCfStrGetString(manufacturer, &host->vendor);
IOObjectRelease(registryEntry);
return NULL;
}
const char* ffDetectHost(FFHostResult* host)
{
ffStrbufSetStatic(&host->sysVendor, "Apple");
const char* error = ffSysctlGetString("hw.model", &host->productFamily);
const char* error = ffSysctlGetString("hw.model", &host->family);
if (error) return error;
ffStrbufSetStatic(&host->productName, getProductNameWithHwModel(&host->productFamily));
if (host->productName.length == 0)
getProductNameWithIokit(&host->productName);
if (host->productName.length == 0)
ffStrbufSet(&host->productName, &host->productFamily);
ffStrbufSetStatic(&host->name, getProductNameWithHwModel(&host->family));
if (host->name.length == 0)
getProductNameWithIokit(&host->name);
if (host->name.length == 0)
ffStrbufSet(&host->name, &host->family);
getOthersByIokit(host);
return NULL;
}
+14 -10
View File
@@ -4,16 +4,20 @@
const char* ffDetectHost(FFHostResult* host)
{
ffSettingsGetFreeBSDKenv("smbios.system.product", &host->productName);
ffCleanUpSmbiosValue(&host->productName);
ffSettingsGetFreeBSDKenv("smbios.system.family", &host->productFamily);
ffCleanUpSmbiosValue(&host->productFamily);
ffSettingsGetFreeBSDKenv("smbios.system.version", &host->productVersion);
ffCleanUpSmbiosValue(&host->productVersion);
ffSettingsGetFreeBSDKenv("smbios.system.sku", &host->productSku);
ffCleanUpSmbiosValue(&host->productSku);
ffSettingsGetFreeBSDKenv("smbios.system.maker", &host->sysVendor);
ffCleanUpSmbiosValue(&host->sysVendor);
ffSettingsGetFreeBSDKenv("smbios.system.product", &host->name);
ffCleanUpSmbiosValue(&host->name);
ffSettingsGetFreeBSDKenv("smbios.system.family", &host->family);
ffCleanUpSmbiosValue(&host->family);
ffSettingsGetFreeBSDKenv("smbios.system.version", &host->version);
ffCleanUpSmbiosValue(&host->version);
ffSettingsGetFreeBSDKenv("smbios.system.sku", &host->sku);
ffCleanUpSmbiosValue(&host->sku);
ffSettingsGetFreeBSDKenv("smbios.system.serial", &host->serial);
ffCleanUpSmbiosValue(&host->serial);
ffSettingsGetFreeBSDKenv("smbios.system.uuid", &host->uuid);
ffCleanUpSmbiosValue(&host->uuid);
ffSettingsGetFreeBSDKenv("smbios.system.maker", &host->vendor);
ffCleanUpSmbiosValue(&host->vendor);
return NULL;
}
+54 -39
View File
@@ -5,63 +5,78 @@
#include <stdlib.h>
static void getSmbiosValue(const char* devicesPath, const char* classPath, FFstrbuf* buffer)
{
ffReadFileBuffer(devicesPath, buffer);
if(ffIsSmbiosValueSet(buffer))
return;
ffReadFileBuffer(classPath, buffer);
if(ffIsSmbiosValueSet(buffer))
return;
ffStrbufClear(buffer);
}
static void getHostProductName(FFstrbuf* name)
{
getSmbiosValue("/sys/devices/virtual/dmi/id/product_name", "/sys/class/dmi/id/product_name", name);
if(name->length > 0)
return;
if (ffReadFileBuffer("/sys/firmware/devicetree/base/model", name))
{
ffStrbufTrimRightSpace(name);
ffStrbufTrimRight(name, '\0');
if(ffIsSmbiosValueSet(name))
return;
}
ffReadFileBuffer("/sys/firmware/devicetree/base/model", name);
if(ffIsSmbiosValueSet(name))
return;
if (ffReadFileBuffer("/sys/firmware/devicetree/base/banner-name", name))
{
ffStrbufTrimRightSpace(name);
ffStrbufTrimRight(name, '\0');
if(ffIsSmbiosValueSet(name))
return;
}
ffReadFileBuffer("/sys/firmware/devicetree/base/banner-name", name);
if(ffIsSmbiosValueSet(name))
return;
//does a clear before the read
ffReadFileBuffer("/tmp/sysinfo/model", name);
if(ffIsSmbiosValueSet(name))
return;
if (ffReadFileBuffer("/tmp/sysinfo/model", name))
{
ffStrbufTrimRightSpace(name);
ffStrbufTrimRight(name, '\0');
if(ffIsSmbiosValueSet(name))
return;
}
ffStrbufClear(name);
}
static void getHostSerialNumber(FFstrbuf* serial)
{
if (ffReadFileBuffer("/sys/firmware/devicetree/base/serial-number", serial))
{
ffStrbufTrimRightSpace(serial);
ffStrbufTrimRight(serial, '\0');
if(ffIsSmbiosValueSet(serial))
return;
}
ffStrbufClear(serial);
}
const char* ffDetectHost(FFHostResult* host)
{
getSmbiosValue("/sys/devices/virtual/dmi/id/product_family", "/sys/class/dmi/id/product_family", &host->productFamily);
getHostProductName(&host->productName);
getSmbiosValue("/sys/devices/virtual/dmi/id/product_version", "/sys/class/dmi/id/product_version", &host->productVersion);
getSmbiosValue("/sys/devices/virtual/dmi/id/product_sku", "/sys/class/dmi/id/product_sku", &host->productSku);
getSmbiosValue("/sys/devices/virtual/dmi/id/sys_vendor", "/sys/class/dmi/id/sys_vendor", &host->sysVendor);
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/product_family", "/sys/class/dmi/id/product_family", &host->family);
if (!ffGetSmbiosValue("/sys/devices/virtual/dmi/id/product_name", "/sys/class/dmi/id/product_name", &host->name))
getHostProductName(&host->name);
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/product_version", "/sys/class/dmi/id/product_version", &host->version);
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/product_sku", "/sys/class/dmi/id/product_sku", &host->sku);
if (!ffGetSmbiosValue("/sys/devices/virtual/dmi/id/product_serial", "/sys/class/dmi/id/product_serial", &host->serial))
getHostSerialNumber(&host->serial);
ffGetSmbiosValue("/sys/devices/virtual/dmi/id/product_uuid", "/sys/class/dmi/id/product_uuid", &host->uuid);
if (!ffGetSmbiosValue("/sys/devices/virtual/dmi/id/sys_vendor", "/sys/class/dmi/id/sys_vendor", &host->vendor))
{
if (ffStrbufStartsWithS(&host->name, "Apple "))
ffStrbufSetStatic(&host->vendor, "Apple Inc.");
}
//KVM/Qemu virtual machine
if(ffStrbufStartsWithS(&host->productName, "Standard PC"))
ffStrbufPrependS(&host->productName, "KVM/QEMU ");
if(ffStrbufStartsWithS(&host->name, "Standard PC"))
ffStrbufPrependS(&host->name, "KVM/QEMU ");
if(host->productFamily.length == 0 && host->productName.length == 0)
if(host->family.length == 0 && host->name.length == 0)
{
const char* wslDistroName = getenv("WSL_DISTRO_NAME");
//On WSL, the real host can't be detected. Instead use WSL as host.
if(wslDistroName != NULL || getenv("WSL_DISTRO") != NULL || getenv("WSL_INTEROP") != NULL)
{
ffStrbufAppendS(&host->productName, "Windows Subsystem for Linux");
ffStrbufAppendS(&host->name, "Windows Subsystem for Linux");
if (wslDistroName)
ffStrbufAppendF(&host->productName, " - %s", wslDistroName);
ffStrbufAppendS(&host->productFamily, "WSL");
ffStrbufAppendF(&host->name, " - %s", wslDistroName);
ffStrbufAppendS(&host->family, "WSL");
FF_STRBUF_AUTO_DESTROY wslVer = ffStrbufCreate(); //Wide characters
if(!ffProcessAppendStdOut(&wslVer, (char* const[]){
@@ -74,7 +89,7 @@ const char* ffDetectHost(FFHostResult* host)
ffStrbufSubstrAfterLastC(&wslVer, ' ');
for(uint32_t i = 0; i < wslVer.length; ++i) {
if(wslVer.chars[i]) //don't append \0
ffStrbufAppendC(&host->productVersion, wslVer.chars[i]);
ffStrbufAppendC(&host->version, wslVer.chars[i]);
}
}
}
+59 -14
View File
@@ -1,24 +1,69 @@
#include "host.h"
#include "util/windows/registry.h"
#include "util/smbiosHelper.h"
typedef struct FFSmbiosSystemInfo
{
FFSmbiosHeader Header;
uint8_t Manufacturer; // string
uint8_t ProductName; // string
uint8_t Version; // string
uint8_t SerialNumber; // string
// 2.1+
struct {
uint32_t TimeLow;
uint16_t TimeMid;
uint16_t TimeHighAndVersion;
uint8_t ClockSeqHiAndReserved;
uint8_t ClockSeqLow;
uint8_t Node[6];
} UUID; // varies
uint8_t WakeUpType; // enum
// 2.4+
uint8_t SKUNumber; // string
uint8_t Family; // string
} FFSmbiosSystemInfo;
const char* ffDetectHost(FFHostResult* host)
{
FF_HKEY_AUTO_DESTROY hKey = NULL;
const FFSmbiosSystemInfo* data = (const FFSmbiosSystemInfo*) (*ffGetSmbiosHeaderTable())[FF_SMBIOS_TYPE_SYSTEM_INFO];
if (!data)
return "System information is not found in SMBIOS data";
if(!ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\BIOS", &hKey, NULL))
return "ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L\"HARDWARE\\DESCRIPTION\\System\\BIOS\", &hKey, NULL) failed";
const char* strings = (const char*) data + data->Header.Length;
ffRegReadStrbuf(hKey, L"SystemProductName", &host->productName, NULL);
ffCleanUpSmbiosValue(&host->productName);
ffRegReadStrbuf(hKey, L"SystemFamily", &host->productFamily, NULL);
ffCleanUpSmbiosValue(&host->productFamily);
ffRegReadStrbuf(hKey, L"SystemVersion", &host->productVersion, NULL);
ffCleanUpSmbiosValue(&host->productVersion);
ffRegReadStrbuf(hKey, L"SystemSKU", &host->productSku, NULL);
ffCleanUpSmbiosValue(&host->productSku);
ffRegReadStrbuf(hKey, L"SystemManufacturer", &host->sysVendor, NULL);
ffCleanUpSmbiosValue(&host->sysVendor);
ffStrbufSetStatic(&host->vendor, ffSmbiosLocateString(strings, data->Manufacturer));
ffCleanUpSmbiosValue(&host->vendor);
ffStrbufSetStatic(&host->name, ffSmbiosLocateString(strings, data->ProductName));
ffCleanUpSmbiosValue(&host->name);
ffStrbufSetStatic(&host->version, ffSmbiosLocateString(strings, data->Version));
ffCleanUpSmbiosValue(&host->version);
ffStrbufSetStatic(&host->serial, ffSmbiosLocateString(strings, data->SerialNumber));
ffCleanUpSmbiosValue(&host->serial);
static_assert(offsetof(FFSmbiosSystemInfo, UUID) == 0x08, "FFSmbiosSystemInfo.UUID offset is wrong");
if (data->Header.Length > offsetof(FFSmbiosSystemInfo, UUID))
{
ffStrbufSetF(&host->uuid, "%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
data->UUID.TimeLow, data->UUID.TimeMid, data->UUID.TimeHighAndVersion,
data->UUID.ClockSeqHiAndReserved, data->UUID.ClockSeqLow,
data->UUID.Node[0], data->UUID.Node[1], data->UUID.Node[2], data->UUID.Node[3], data->UUID.Node[4], data->UUID.Node[5]);
}
static_assert(offsetof(FFSmbiosSystemInfo, SKUNumber) == 0x19, "FFSmbiosSystemInfo.SKUNumber offset is wrong");
if (data->Header.Length > offsetof(FFSmbiosSystemInfo, SKUNumber))
{
ffStrbufSetStatic(&host->sku, ffSmbiosLocateString(strings, data->SKUNumber));
ffCleanUpSmbiosValue(&host->sku);
}
if (data->Header.Length > offsetof(FFSmbiosSystemInfo, Family))
{
ffStrbufSetStatic(&host->family, ffSmbiosLocateString(strings, data->Family));
ffCleanUpSmbiosValue(&host->family);
}
return NULL;
}
-12
View File
@@ -1,12 +0,0 @@
#pragma once
#include "common/thread.h"
#define FF_DETECTION_INTERNAL_GUARD(ResultType, ...) \
static ResultType result; \
static bool init = false; \
if(init) \
return &result; \
init = true; \
__VA_ARGS__; \
return &result;
@@ -21,14 +21,14 @@ static void getLocaleFromEnv(FFstrbuf* locale)
static void getLocaleFromStdFn(FFstrbuf* locale)
{
ffStrbufAppendS(locale, setlocale(LC_ALL, NULL));
#ifdef LC_MESSAGES
ffStrbufAppendS(locale, setlocale(LC_MESSAGES, NULL));
if(locale->length > 0)
return;
ffStrbufAppendS(locale, setlocale(LC_MESSAGES, NULL));
#endif
ffStrbufAppendS(locale, setlocale(LC_ALL, NULL));
}
void ffDetectLocale(FFstrbuf* result)
+18
View File
@@ -0,0 +1,18 @@
#include "detection/locale/locale.h"
#include "util/windows/unicode.h"
#include <windows.h>
#include <locale.h>
void ffDetectLocale(FFstrbuf* result)
{
wchar_t name[LOCALE_NAME_MAX_LENGTH];
int size = GetUserDefaultLocaleName(name, LOCALE_NAME_MAX_LENGTH);
if (size > 1) // including '\0'
{
ffStrbufSetNWS(result, (uint32_t)size - 1, name);
ffStrbufAppendS(result, ".UTF-8"); // set explicitly in `ffInitInstance`
}
else
ffStrbufSetS(result, setlocale(LC_ALL, NULL));
}
+7 -4
View File
@@ -1,11 +1,13 @@
#include "media.h"
#include "detection/internal.h"
void ffDetectMediaImpl(FFMediaResult* media);
const FFMediaResult* ffDetectMedia(void)
{
FF_DETECTION_INTERNAL_GUARD(FFMediaResult,
static FFMediaResult result;
if (result.error.chars == NULL)
{
ffStrbufInit(&result.error);
ffStrbufInit(&result.playerId);
ffStrbufInit(&result.player);
@@ -14,10 +16,11 @@ const FFMediaResult* ffDetectMedia(void)
ffStrbufInit(&result.album);
ffStrbufInit(&result.url);
ffStrbufInit(&result.status);
ffDetectMediaImpl(&result);
if(result.song.length == 0 && result.error.length == 0)
ffStrbufAppendS(&result.error, "No media found");
);
}
return &result;
}
-1
View File
@@ -79,7 +79,6 @@ static const char* getMedia(FFMediaResult* result)
void ffDetectMediaImpl(FFMediaResult* media)
{
FF_UNUSED(instance)
const char* error = getMedia(media);
ffStrbufAppendS(&media->error, error);
}
-2
View File
@@ -1,6 +1,5 @@
#include "fastfetch.h"
#include "detection/media/media.h"
#include "common/thread.h"
#include "util/stringUtils.h"
#include <string.h>
@@ -11,7 +10,6 @@
#ifdef FF_HAVE_DBUS
#include "common/dbus.h"
#include "common/library.h"
#include "common/parsing.h"
static bool getBusProperties(FFDBusData* data, const char* busName, FFMediaResult* result)
{
+3
View File
@@ -8,6 +8,9 @@ typedef struct FFMonitorResult
uint32_t physicalWidth; // in mm
uint32_t physicalHeight; // in mm
bool hdrCompatible;
uint16_t manufactureYear;
uint16_t manufactureWeek;
uint32_t serial;
} FFMonitorResult;
const char* ffDetectMonitor(FFlist* results);
+13 -1
View File
@@ -40,9 +40,13 @@ const char* ffDetectMonitor(FFlist* results)
CFDictionaryRef FF_CFTYPE_AUTO_RELEASE displayInfo = CoreDisplay_DisplayCreateInfoDictionary((CGDirectDisplayID) display->id);
if(!displayInfo) continue;
bool isVirtual = false;
if (ffCfDictGetBool(displayInfo, CFSTR("kCGDisplayIsVirtualDevice"), &isVirtual) == NULL && isVirtual)
continue;
uint8_t edidData[128] = {};
uint32_t edidLength = 0;
if (false || !ffCfDictGetData(displayInfo, CFSTR("IODisplayEDID"), 0, sizeof(edidData), edidData, &edidLength))
if (ffCfDictGetData(displayInfo, CFSTR("IODisplayEDID"), 0, sizeof(edidData), edidData, &edidLength) == NULL)
{
uint32_t width, height;
ffEdidGetPhysicalResolution(edidData, &width, &height);
@@ -75,6 +79,14 @@ const char* ffDetectMonitor(FFlist* results)
monitor->physicalHeight = (uint32_t) (size.height + 0.5);
monitor->hdrCompatible = CFDictionaryContainsKey(displayInfo, CFSTR("ReferencePeakHDRLuminance")) ||
detectHdrSupportWithNSScreen(display);
int64_t serial, year, week;
if (ffCfDictGetInt64(displayInfo, CFSTR("DisplaySerialNumber"), &serial) == NULL)
monitor->serial = (uint32_t) (uint64_t) serial;
if (ffCfDictGetInt64(displayInfo, CFSTR("DisplayYearManufacture"), &year) == NULL)
monitor->manufactureYear = (uint16_t) year;
if (ffCfDictGetInt64(displayInfo, CFSTR("DisplayWeekManufacture"), &week) == NULL)
monitor->manufactureWeek = (uint16_t) week;
}
return NULL;
+5 -4
View File
@@ -29,10 +29,10 @@ const char* ffDetectMonitor(FFlist* results)
ffStrbufAppendS(&drmDir, entry->d_name);
uint32_t drmDirWithDnameLength = drmDir.length;
ffStrbufAppendS(&drmDir, "/enabled");
char enabled = 'd'; // disabled
ffReadFileData(drmDir.chars, sizeof(enabled), &enabled);
if (enabled != 'e') // enabled
ffStrbufAppendS(&drmDir, "/status");
char status = 'd'; // disconnected
ffReadFileData(drmDir.chars, sizeof(status), &status);
if (status != 'c') // connected
{
ffStrbufSubstrBefore(&drmDir, drmDirLength);
continue;
@@ -59,6 +59,7 @@ const char* ffDetectMonitor(FFlist* results)
ffStrbufInit(&display->name);
ffEdidGetName(edidData, &display->name);
ffEdidGetPhysicalSize(edidData, &display->physicalWidth, &display->physicalHeight);
ffEdidGetSerialAndManufactureDate(edidData, &display->serial, &display->manufactureYear, &display->manufactureWeek);
display->hdrCompatible = ffEdidGetHdrCompatible(edidData, (uint32_t) edidLength);
}
+1
View File
@@ -44,6 +44,7 @@ const char* ffDetectMonitor(FFlist* results)
FFMonitorResult* display = (FFMonitorResult*) ffListAdd(results);
display->width = width;
display->height = height;
ffEdidGetSerialAndManufactureDate(edidData, &display->serial, &display->manufactureYear, &display->manufactureWeek);
display->hdrCompatible = ffEdidGetHdrCompatible(edidData, edidLength); // Doesn't work. edidLength is always 128
ffStrbufInit(&display->name);
ffEdidGetName(edidData, &display->name);
+1 -1
View File
@@ -9,7 +9,7 @@
static void getData(FFstrbuf* buffer, const char* ifName, bool isDefaultRoute, FFstrbuf* path, FFlist* result)
{
ffStrbufSetF(path, "/sys/class/net/%s/operstate", ifName);
if(!ffReadFileBuffer(path->chars, buffer) || !ffStrbufEqualS(buffer, "up"))
if(!ffReadFileBuffer(path->chars, buffer) || !ffStrbufEqualS(buffer, "up\n"))
return;
FFNetIOResult* counters = (FFNetIOResult*) ffListAdd(result);
+16 -4
View File
@@ -1,11 +1,23 @@
#include "os.h"
#include "detection/internal.h"
void ffDetectOSImpl(FFOSResult* os);
const FFOSResult* ffDetectOS(void)
{
FF_DETECTION_INTERNAL_GUARD(FFOSResult,
ffDetectOSImpl(&result)
);
static FFOSResult result;
if (result.name.chars == NULL)
{
ffStrbufInit(&result.name);
ffStrbufInit(&result.prettyName);
ffStrbufInit(&result.id);
ffStrbufInit(&result.version);
ffStrbufInit(&result.versionID);
ffStrbufInit(&result.codename);
ffStrbufInit(&result.buildID);
ffStrbufInit(&result.idLike);
ffStrbufInit(&result.variant);
ffStrbufInit(&result.variantID);
ffDetectOSImpl(&result);
}
return &result;
}
+3 -11
View File
@@ -3,25 +3,17 @@
void ffDetectOSImpl(FFOSResult* os)
{
ffStrbufInitStatic(&os->name, "Android");
ffStrbufSetStatic(&os->name, "Android");
ffStrbufInitStatic(&os->prettyName, "Android");
ffStrbufSetStatic(&os->prettyName, "Android");
ffStrbufInitStatic(&os->id, "android");
ffStrbufSetStatic(&os->id, "android");
ffStrbufInit(&os->version);
ffSettingsGetAndroidProperty("ro.build.version.release", &os->version);
ffStrbufInit(&os->versionID);
ffSettingsGetAndroidProperty("ro.build.version.release", &os->versionID);
ffStrbufInit(&os->codename);
ffSettingsGetAndroidProperty("ro.build.version.codename", &os->codename);
ffStrbufInit(&os->buildID);
ffSettingsGetAndroidProperty("ro.build.id", &os->buildID);
ffStrbufInit(&os->idLike);
ffStrbufInit(&os->variant);
ffStrbufInit(&os->variantID);
}
+4 -19
View File
@@ -1,6 +1,8 @@
#include "os.h"
#include "common/io/io.h"
#include "common/sysctl.h"
#include "util/stringUtils.h"
#include "util/mallocHelper.h"
#include <stdlib.h>
#include <string.h>
@@ -72,11 +74,11 @@ static bool detectOSCodeName(FFOSResult* os)
static void parseOSXSoftwareLicense(FFOSResult* os)
{
FILE* rtf = fopen("/System/Library/CoreServices/Setup Assistant.app/Contents/Resources/en.lproj/OSXSoftwareLicense.rtf", "r");
FF_AUTO_CLOSE_FILE FILE* rtf = fopen("/System/Library/CoreServices/Setup Assistant.app/Contents/Resources/en.lproj/OSXSoftwareLicense.rtf", "r");
if(rtf == NULL)
return;
char* line = NULL;
FF_AUTO_FREE char* line = NULL;
size_t len = 0;
const char* searchStr = "\\f0\\b SOFTWARE LICENSE AGREEMENT FOR macOS ";
while(getline(&line, &len, rtf) != EOF)
@@ -89,27 +91,10 @@ static void parseOSXSoftwareLicense(FFOSResult* os)
break;
}
}
if(line != NULL)
free(line);
fclose(rtf);
}
void ffDetectOSImpl(FFOSResult* os)
{
ffStrbufInit(&os->name);
ffStrbufInit(&os->version);
ffStrbufInit(&os->buildID);
ffStrbufInit(&os->id);
ffStrbufInit(&os->prettyName);
ffStrbufInit(&os->versionID);
ffStrbufInit(&os->codename);
ffStrbufInit(&os->idLike);
ffStrbufInit(&os->variant);
ffStrbufInit(&os->variantID);
parseSystemVersion(os);
if(ffStrbufStartsWithIgnCaseS(&os->name, "MacOS"))

Some files were not shown because too many files have changed in this diff Show More