These names come from ACPI, but the exact naming convention varies between hardware manufacturers. Try all of them and take the statistics from the first one that exists.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52831 Signed-off-by: Alex Henrie alexhenrie24@gmail.com --- v2: Remove the bitwise ORs that are now unnecessary because we're only looking at the first battery --- dlls/ntdll/unix/system.c | 61 +++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 20 deletions(-)
diff --git a/dlls/ntdll/unix/system.c b/dlls/ntdll/unix/system.c index 65c49b6ccd1..b51f2dddd6d 100644 --- a/dlls/ntdll/unix/system.c +++ b/dlls/ntdll/unix/system.c @@ -3425,10 +3425,14 @@ static ULONG mhz_from_cpuinfo(void) return cmz; }
-static const char * get_sys_str(const char *path, char *s) +static const char * get_sys_str(const char *dirname, const char *basename, char *s) { - FILE *f = fopen(path, "r"); + FILE *f; const char *ret = NULL; + char path[64]; + + sprintf(path, "%s/%s", dirname, basename); + f = fopen(path, "r");
if (f) { @@ -3438,40 +3442,57 @@ static const char * get_sys_str(const char *path, char *s) return ret; }
-static int get_sys_int(const char *path, int def) +static int get_sys_int(const char *dirname, const char *basename, int def) { char s[16]; - return get_sys_str(path, s) ? atoi(s) : def; + return get_sys_str(dirname, basename, s) ? atoi(s) : def; }
static NTSTATUS fill_battery_state( SYSTEM_BATTERY_STATE *bs ) { - char s[16], path[64]; - unsigned int i = 0; + static const char* ac_names[] = + { + "AC", + "ACAD", + "ADP0", + "ADP1", + NULL + }; + static const char* bat_names[] = + { + "BAT0", + "BAT1", + NULL + }; + char s[16], dirname[64]; + const char** name; LONG64 voltage; /* microvolts */
- bs->AcOnLine = get_sys_int("/sys/class/power_supply/AC/online", 1); - - for (;;) + bs->AcOnLine = TRUE; + for (name = ac_names; name; name++) { - sprintf(path, "/sys/class/power_supply/BAT%u/status", i); - if (!get_sys_str(path, s)) break; - bs->Charging |= (strcmp(s, "Charging\n") == 0); - bs->Discharging |= (strcmp(s, "Discharging\n") == 0); - bs->BatteryPresent = TRUE; - i++; + sprintf(dirname, "/sys/class/power_supply/%s", *name); + if (!get_sys_str(dirname, "online", s)) continue; + bs->AcOnLine = atoi(s); + break; }
- if (bs->BatteryPresent) + for (name = bat_names; name; name++) { - voltage = get_sys_int("/sys/class/power_supply/BAT0/voltage_now", 0); - bs->MaxCapacity = get_sys_int("/sys/class/power_supply/BAT0/charge_full", 0) * voltage / 1e9; - bs->RemainingCapacity = get_sys_int("/sys/class/power_supply/BAT0/charge_now", 0) * voltage / 1e9; - bs->Rate = -get_sys_int("/sys/class/power_supply/BAT0/current_now", 0) * voltage / 1e9; + sprintf(dirname, "/sys/class/power_supply/%s", *name); + if (!get_sys_str(dirname, "status", s)) continue; + bs->Charging = (strcmp(s, "Charging\n") == 0); + bs->Discharging = (strcmp(s, "Discharging\n") == 0); + bs->BatteryPresent = TRUE; + voltage = get_sys_int(dirname, "voltage_now", 0); + bs->MaxCapacity = get_sys_int(dirname, "charge_full", 0) * voltage / 1e9; + bs->RemainingCapacity = get_sys_int(dirname, "charge_now", 0) * voltage / 1e9; + bs->Rate = -get_sys_int(dirname, "current_now", 0) * voltage / 1e9; if (!bs->Charging && (LONG)bs->Rate < 0) bs->EstimatedTime = 3600 * bs->RemainingCapacity / -(LONG)bs->Rate; else bs->EstimatedTime = ~0u; + break; }
return STATUS_SUCCESS;
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=113166
Your paranoid android.
=== debian11 (32 bit report) ===
ntdll: info.c:1520: Test failed: expected success
=== debian11 (32 bit Chinese:China report) ===
ntdll: info.c:1520: Test failed: expected success
=== debian11 (32 bit WoW report) ===
ntdll: info.c:1520: Test failed: expected success
=== debian11 (64 bit WoW report) ===
ntdll: info.c:1520: Test failed: expected success
On Fri, Apr 22, 2022 at 2:20 AM Alex Henrie alexhenrie24@gmail.com wrote:
- static const char* ac_names[] =
- {
"AC",
"ACAD",
"ADP0",
"ADP1",
NULL
- };
- static const char* bat_names[] =
- {
"BAT0",
"BAT1",
NULL
- };
Sorry, I kind of jumped the gun on this. I looked through the Google search results more thoroughly this morning and discovered that AC0, AC1, and BAT are also common names.
If any of you would like to help, could you look in /sys/class/power_supply on your computer and let me know if your devices have other names that I missed?
-Alex
On Fri, Apr 22, 2022, 12:32 Alex Henrie alexhenrie24@gmail.com wrote:
On Fri, Apr 22, 2022 at 2:20 AM Alex Henrie alexhenrie24@gmail.com wrote:
- static const char* ac_names[] =
- {
"AC",
"ACAD",
"ADP0",
"ADP1",
NULL
- };
- static const char* bat_names[] =
- {
"BAT0",
"BAT1",
NULL
- };
Sorry, I kind of jumped the gun on this. I looked through the Google search results more thoroughly this morning and discovered that AC0, AC1, and BAT are also common names.
If any of you would like to help, could you look in /sys/class/power_supply on your computer and let me know if your devices have other names that I missed?
-Alex
This matches my amd64 hardware.
My armv7l chromebook reports the battery as: "sbs-20-000b" (alongside "gpio-charger") My aarch64 pinebook reports the battery as: "battery" (alongside "ac" and "usb")
On 4/24/22 13:30, Austin English wrote:
On Fri, Apr 22, 2022, 12:32 Alex Henrie alexhenrie24@gmail.com wrote:
On Fri, Apr 22, 2022 at 2:20 AM Alex Henrie alexhenrie24@gmail.com wrote:
- static const char* ac_names[] =
- {
"AC",
"ACAD",
"ADP0",
"ADP1",
NULL
- };
- static const char* bat_names[] =
- {
"BAT0",
"BAT1",
NULL
- };
Sorry, I kind of jumped the gun on this. I looked through the Google search results more thoroughly this morning and discovered that AC0, AC1, and BAT are also common names.
If any of you would like to help, could you look in /sys/class/power_supply on your computer and let me know if your devices have other names that I missed?
-Alex
This matches my amd64 hardware.
My armv7l chromebook reports the battery as: "sbs-20-000b" (alongside "gpio-charger") My aarch64 pinebook reports the battery as: "battery" (alongside "ac" and "usb")
On my system /sys/class/power_supply/*/type file contains either "Mains" for AC device, or "Battery" for BAT0.
I haven't checked kernel sources to see if it makes sense to rely on these values, hopefully it doesn't depend on the driver. If it's relatively stable, maybe we could look for type instead of the device name?
On 4/24/22 05:52, Nikolay Sivov wrote:
On 4/24/22 13:30, Austin English wrote:
On Fri, Apr 22, 2022, 12:32 Alex Henrie alexhenrie24@gmail.com wrote:
On Fri, Apr 22, 2022 at 2:20 AM Alex Henrie alexhenrie24@gmail.com wrote:
- static const char* ac_names[] =
- {
"AC",
"ACAD",
"ADP0",
"ADP1",
NULL
- };
- static const char* bat_names[] =
- {
"BAT0",
"BAT1",
NULL
- };
Sorry, I kind of jumped the gun on this. I looked through the Google search results more thoroughly this morning and discovered that AC0, AC1, and BAT are also common names.
If any of you would like to help, could you look in /sys/class/power_supply on your computer and let me know if your devices have other names that I missed?
-Alex
This matches my amd64 hardware.
My armv7l chromebook reports the battery as: "sbs-20-000b" (alongside "gpio-charger") My aarch64 pinebook reports the battery as: "battery" (alongside "ac" and "usb")
On my system /sys/class/power_supply/*/type file contains either "Mains" for AC device, or "Battery" for BAT0.
I haven't checked kernel sources to see if it makes sense to rely on these values, hopefully it doesn't depend on the driver. If it's relatively stable, maybe we could look for type instead of the device name?
It's part of the "testing" ABI, like everything else in power_supply [1], which apparently means that "the interface can be changed to add new features, but the current interface will not break by doing this, unless grave errors or security problems are found in them."
FWIW, there are other values there than just "Mains" and "Battery".
I also will note that my desktop has nothing in power_supply at all. I don't know if this is typical for desktops.
https://www.kernel.org/doc/html/latest/admin-guide/abi-testing.html#abi-sys-...
On Sun, Apr 24, 2022 at 4:31 AM Austin English austinenglish@gmail.com wrote:
This matches my amd64 hardware.
My armv7l chromebook reports the battery as: "sbs-20-000b" (alongside "gpio-charger") My aarch64 pinebook reports the battery as: "battery" (alongside "ac" and "usb")
Thanks! It sounds like we really ought to avoid hardcoding a list of names to look for here. I'll send a new patch that looks at /sys/class/power/*/type instead.
-Alex
On Sun, Apr 24, 2022 at 3:16 PM Alex Henrie alexhenrie24@gmail.com wrote:
On Sun, Apr 24, 2022 at 4:31 AM Austin English austinenglish@gmail.com wrote:
This matches my amd64 hardware.
My armv7l chromebook reports the battery as: "sbs-20-000b" (alongside "gpio-charger") My aarch64 pinebook reports the battery as: "battery" (alongside "ac" and "usb")
Thanks! It sounds like we really ought to avoid hardcoding a list of names to look for here. I'll send a new patch that looks at /sys/class/power/*/type instead.
I mean, /sys/class/power_supply/*/type.
-Alex