Packages

otpbp

6.3.2
7.19.2 7.18.0 7.16.1 7.15.0 7.14.0 7.13.0 7.12.0 7.11.0 7.10.2 7.9.3 7.9.2 7.9.1 7.8.7 7.8.6 7.8.5 7.8.4 7.7.1 7.7.0 7.6.3 7.6.2 7.6.1 7.6.0 7.5.1 7.5.0 7.4.0 7.3.4 7.3.3 7.3.2 7.3.1 7.3.0 7.2.0 7.1.1 7.1.0 7.0.4 7.0.3 7.0.2 7.0.1 6.27.0 6.26.2 6.26.1 6.26.0 6.25.0 6.24.0 6.23.0 6.22.2 6.21.3 6.21.2 6.21.1 6.20.2 6.19.1 6.19.0 6.18.3 6.18.2 6.18.1 6.18.0 6.17.1 6.17.0 6.16.0 6.15.4 6.15.3 6.15.2 6.15.1 6.15.0 6.14.0 6.13.5 6.13.4 6.13.3 6.13.2 6.13.1 6.13.0 6.12.0 6.11.2 6.11.1 6.10.0 6.9.2 6.9.1 6.9.0 6.8.0 6.7.1 6.7.0 6.6.4 6.6.3 6.6.2 6.6.1 6.6.0 6.5.0 6.4.0 6.3.3 6.3.2 6.3.1 6.3.0 6.2.1 6.2.0 6.1.0 6.0.0 5.40.0 5.39.1 5.39.0 5.38.0 5.37.0 5.36.0 5.35.2 5.34.3 5.34.2 5.34.1 5.33.1 5.32.1 5.32.0 5.31.3 5.31.2 5.31.1 5.31.0 5.30.1 5.30.0 5.29.0 5.28.4 5.28.3 5.28.2 5.28.1 5.28.0 5.27.0 5.26.5 5.26.4 5.26.3 5.26.2 5.26.1 5.26.0 5.25.0 5.24.2 5.24.1 5.23.0 5.22.2 5.22.1 5.22.0 5.21.0 5.20.1 5.20.0 5.19.4 5.19.3 5.19.2 5.19.1 5.19.0 5.18.0 5.17.0 5.16.3 5.16.1 5.16.0 5.15.1 5.15.0 5.14.0 5.13.1 5.13.0 5.12.1 5.12.0 5.11.2 5.11.1 5.10.1 5.10.0 5.9.0 5.8.0 5.7.0 5.6.1 5.6.0 5.5.0 5.4.2 5.4.1 5.4.0 5.3.0 5.2.2 5.2.1 5.2.0 5.1.2 5.1.1 4.80.0 4.79.1 4.79.0 4.78.0 4.77.0 4.76.2 4.75.3 4.75.2 4.75.1 4.74.0 4.73.1 4.73.0 4.72.3 4.72.2 4.72.1 4.72.0 4.71.1 4.71.0 4.70.0 4.69.4 4.69.3 4.69.2 4.69.1 4.69.0 4.68.0 4.67.5 4.67.4 4.67.3 4.67.2 4.67.0 4.66.0 4.65.2 4.65.1 4.64.0 4.63.2 4.63.1 4.63.0 4.62.0 4.61.1 4.61.0 4.60.4 4.60.3 4.60.2 4.60.1 4.60.0 4.59.0 4.58.0 4.57.2 4.57.1 4.57.0 4.56.2 4.56.1 4.56.0 4.55.0 4.54.0 4.53.0 4.52.1 4.52.0 4.51.3 4.51.2 4.51.0 4.50.0 4.49.3 4.49.2

OTP backports

Current section

Files

Jump to
otpbp src otpbp_disksup.erl
Raw

src/otpbp_disksup.erl

-module(otpbp_disksup).
-compile({parse_transform, otpbp_pt}).
-ifndef(HAVE_disksup__parse_df_2).
% OTP 21.0
-export([parse_df/2]).
-endif.
-ifndef(HAVE_disksup__get_disk_info_0).
% OTP 26.0
-export([get_disk_info/0]).
-endif.
-ifndef(HAVE_disksup__get_disk_info_1).
% OTP 26.0
-export([get_disk_info/1]).
-endif.
-ifndef(HAVE_disksup__get_disk_info_0).
-ifdef(HAVE_disksup__get_disk_info_1).
-import(disksup, [get_disk_info/1]).
-endif.
-ifdef(HAVE_disksup__parse_df_2).
-import(disksup, [parse_df/2]).
-endif.
-endif.
-ifndef(HAVE_disksup__get_disk_info_0).
get_disk_info() -> get_disk_info("").
-endif.
-ifndef(HAVE_disksup__get_disk_info_1).
get_disk_info(Path) ->
case get_disk_info(Path, os:type()) of
[] -> [{Path, 0, 0, 0}];
DiskInfo -> DiskInfo
end.
get_disk_info("", {win32, _}) -> disk_info_win32(os_mon_sysinfo:get_disk_info());
get_disk_info(DriveRoot, {win32, _}) -> disk_info_win32(os_mon_sysinfo:get_disk_info(DriveRoot));
get_disk_info(Path, {unix, OS})
when OS =:= linux; OS =:= freebsd; OS =:= openbsd; OS =:= netbsd;
OS =:= solaris; OS =:= dragonfly; OS =:= sunos4; OS =:= posix ->
disk_info_solaris(skip_to_eol(run_df(Path, OS)));
get_disk_info(Path, {unix, darwin}) -> disk_info_susv3(skip_to_eol(run_df(Path, darwin)));
get_disk_info(Path, {unix, irix}) -> disk_info_irix(skip_to_eol(run_df(Path, irix))).
run_df(Path, solaris) -> my_cmd("/usr/bin/df -lk " ++ Path);
run_df(Path, irix) -> my_cmd("/usr/sbin/df -lk " ++ Path);
run_df(Path, linux) -> my_cmd(find_cmd("df", "/bin") ++ " -lk -x squashfs " ++ Path);
run_df(Path, posix) -> my_cmd("df -k -P " ++ Path);
run_df(Path, dragonfly) -> my_cmd("/bin/df -k -t ufs,hammer " ++ Path);
run_df(Path, netbsd) -> my_cmd("/bin/df -k -t ffs " ++ Path);
run_df(Path, sunos4) -> my_cmd("df " ++ Path);
run_df(Path, darwin) -> my_cmd("/bin/df -i -k -t ufs,hfs,apfs " ++ Path);
run_df(Path, OS) when OS =:= freebsd; OS =:= openbsd -> my_cmd("/bin/df -k -l " ++ Path).
my_cmd(Cmd) ->
Port = open_port({spawn, Cmd}, [stream, {env, [{"LANG0", "C"}]}]),
receive
{Port, {data, N}} -> N;
{'EXIT', Port, Reason} -> exit({port_died, Reason})
end.
find_cmd(Cmd) -> os:find_executable(Cmd).
find_cmd(Cmd, Path) ->
%% try to find it at the specific location
case os:find_executable(Cmd, Path) of
false -> find_cmd(Cmd);
Found -> Found
end.
disk_info_win32([]) -> [];
disk_info_win32([H|T]) ->
case io_lib:fread("~s~s~d~d~d", H) of
{ok, [Drive, "DRIVE_FIXED", BAvail, BTot, _TotFree], _RestStr} ->
[{Drive,
BTot div 1024,
BAvail div 1024,
trunc(math:ceil(100 * ((BTot - BAvail) / BTot)))}|disk_info_win32(T)];
{ok, _, _RestStr} -> disk_info_win32(T);
_Other -> []
end.
disk_info_solaris(Str) when Str =:= ""; Str =:= "\n" -> [];
disk_info_solaris(Str) ->
case parse_df(Str, posix) of
{ok, {KiBTotal, KiBAvailable, Capacity, MntOn}, RestStr} ->
[{MntOn, KiBTotal, KiBAvailable, Capacity}|disk_info_solaris(RestStr)];
_Other -> disk_info_solaris(skip_to_eol(Str))
end.
disk_info_irix(Str) when Str =:= ""; Str =:= "\n" -> [];
disk_info_irix(Str) ->
case io_lib:fread("~s~s~d~d~d~d~s", Str) of
{ok, [_FS, _FSType, KiBAvailable, Capacity, _Avail, KiBTotal, MntOn], RestStr} ->
[{MntOn, KiBTotal, KiBAvailable, Capacity}|disk_info_irix(RestStr)];
_Other -> disk_info_irix(skip_to_eol(Str))
end.
disk_info_susv3(Str) when Str =:= ""; Str =:= "\n" -> [];
disk_info_susv3(Str) ->
case parse_df(Str, susv3) of
{ok, {KiBTotal, KiBAvailable, Capacity, MntOn}, RestStr} ->
[{MntOn, KiBTotal, KiBAvailable, Capacity}|disk_info_susv3(RestStr)];
_Other -> disk_info_susv3(skip_to_eol(Str))
end.
skip_to_eol([$\n|T]) -> T;
skip_to_eol([_|T]) -> skip_to_eol(T);
skip_to_eol([]) -> [].
-endif.
-ifndef(HAVE_disksup__parse_df_2).
parse_df(Input0, Flavor) ->
{KiBTotalStr, Input2} = parse_df_take_word(parse_df_skip_word(Input0)),
{KiBAvailableStr, Input4} = parse_df_take_word(parse_df_skip_word(Input2)),
{CapacityStr, Input5} = parse_df_take_word_percent(Input4),
{MountPath, Input7} = lists:splitwith(fun(C) -> C =/= $\r andalso C =/= $\n end,
if
Flavor =:= posix -> Input5;
Flavor =:= susv3 ->
{_, Input5c} = parse_df_take_word_percent(parse_df_skip_word(parse_df_skip_word(Input5))),
Input5c
end),
Remaining = lists:dropwhile(fun(X) -> parse_df_is_eol(X) end, Input7),
try {list_to_integer(KiBTotalStr), list_to_integer(KiBAvailableStr), list_to_integer(CapacityStr)} of
{KiBTotal, KiBAvailable, Capacity} -> {ok, {KiBTotal, KiBAvailable, Capacity, MountPath}, Remaining}
catch
error:badarg -> {error, parse_df}
end.
parse_df_is_eol(C) -> C =:= $\r orelse C =:= $\n.
parse_df_is_not_space(C) -> C =/= $\s andalso C =/= $%.
parse_df_take_word_percent(Input) ->
case lists:splitwith(fun parse_df_is_not_space/1, Input) of
{Word, [$%|Remaining]} -> {Word, Remaining};
Result -> Result
end.
parse_df_skip_word(Input) ->
lists:dropwhile(fun(C) -> C =:= $\s end, lists:dropwhile(fun parse_df_is_not_space/1, Input)).
parse_df_take_word(Input) ->
{Word, Remaining} = lists:splitwith(fun parse_df_is_not_space/1, Input),
{Word, lists:dropwhile(fun(C) -> C =:= $\s end, Remaining)}.
-endif.