<commit_before># openbsd-lib.pl
# Mount table functions for openbsd

$uname_release = `uname -r`;

# Return information about a filesystem, in the form:
#  directory, device, type, options, fsck_order, mount_at_boot
# If a field is unused or ignored, a - appears instead of the value.
# Swap-filesystems (devices or files mounted for VM) have a type of 'swap',
# and 'swap' in the directory field
sub list_mounts
{
local(@rv, @p, @o, $_, $i, $j); $i = 0;

# Get /etc/fstab mounts
open(FSTAB, $config{'fstab_file'});
while(<FSTAB>) {
	local(@o, $at_boot);
	chop; s/#.*$//g;
	if (!/\S/) { next; }
	@p = split(/\s+/, $_);
	if ($p[2] eq "proc" || $p[2] eq "procfs") { $p[2] = $p[0] = "proc"; }
	if ($p[2] eq "swap") { $p[1] = "swap"; }
	$rv[$i] = [ $p[1], $p[0], $p[2] ];
	$rv[$i]->[5] = "yes";
	@o = split(/,/ , $p[3] eq "defaults" ? "" : $p[3]);
	if (($j = &indexof("noauto", @o)) >= 0) {
		# filesytem is not mounted at boot
		splice(@o, $j, 1);
		$rv[$i]->[5] = "no";
		}
	$rv[$i]->[3] = (@o ? join(',' , @o) : "-");
	$rv[$i]->[4] = (@p >= 5 ? $p[5] : 0);
	$i++;
	}
close(FSTAB);
return @rv;
}


# create_mount(directory, device, type, options, fsck_order, mount_at_boot)
# Add a new entry to the fstab file, old or new automounter file
sub create_mount
{
local(@mlist, @amd, $_); local($opts);

# Adding a normal mount to the fstab file
&open_tempfile(FSTAB, ">> $config{'fstab_file'}");
&print_tempfile(FSTAB, "$_[1]  $_[0]  $_[2]");
$opts = $_[3] eq "-" ? "" : $_[3];
if ($_[5] eq "no") {
	$opts = join(',' , (split(/,/ , $opts) , "noauto"));
	}
if ($opts eq "") { &print_tempfile(FSTAB, "  defaults"); }
else { &print_tempfile(FSTAB, "  $opts"); }
&print_tempfile(FSTAB, "  0  ");
&print_tempfile(FSTAB, $_[4] eq "-" ? "0\n" : "$_[4]\n");
&close_tempfile(FSTAB);
}


# change_mount(num, directory, device, type, options, fsck_order, mount_at_boot)
# Change an existing permanent mount
sub change_mount
{
local($i, @fstab, $line, $opts, $j, @amd);
$i = 0;

# Update fstab file
open(FSTAB, $config{fstab_file});
@fstab = <FSTAB>;
close(FSTAB);
&open_tempfile(FSTAB, "> $config{fstab_file}");
foreach (@fstab) {
	chop; ($line = $_) =~ s/#.*$//g;
	if ($line =~ /\S/ && $i++ == $_[0]) {
		# Found the line to replace
		&print_tempfile(FSTAB, "$_[2]  $_[1]  $_[3]");
		$opts = $_[4] eq "-" ? "" : $_[4];
		if ($_[6] eq "no") {
			$opts = join(',' , (split(/,/ , $opts) , "noauto"));
			}
		if ($opts eq "") { &print_tempfile(FSTAB, "  defaults"); }
		else { &print_tempfile(FSTAB, "  $opts"); }
		&print_tempfile(FSTAB, "  0  ");
		&print_tempfile(FSTAB, $_[5] eq "-" ? "0\n" : "$_[5]\n");
		}
	else {
		&print_tempfile(FSTAB, $_,"\n");
		}
	}
&close_tempfile(FSTAB);
}


# delete_mount(index)
# Delete an existing permanent mount
sub delete_mount
{
local($i, @fstab, $line, $opts, $j, @amd);
$i = 0;

# Update fstab file
open(FSTAB, $config{fstab_file});
@fstab = <FSTAB>;
close(FSTAB);
&open_tempfile(FSTAB, "> $config{fstab_file}");
foreach (@fstab) {
	chop; ($line = $_) =~ s/#.*$//g;
	if ($line !~ /\S/ || $i++ != $_[0]) {
		# Don't delete this line
		&print_tempfile(FSTAB, $_,"\n");
		}
	}
&close_tempfile(FSTAB);
}


# list_mounted()
# Return a list of all the currently mounted filesystems and swap files.
# The list is in the form:
#  directory device type options
# Under OpenBSD, there seems to be no way to get additional mount options
# used by filesystems like NFS etc. Even getting the full details of mounted
# filesystems requires C code! So we have to call a specially-written external
# program to get the mount list
sub list_mounted
{
# get the list of mounted filesystems
local(@rv, $_);
local $cmd = $uname_release =~ /^4\./ ? "openbsd-mounts-4" :
	     $uname_release =~ /^3\./ ? "openbsd-mounts-3" :
					"openbsd-mounts-2";
&compile_program($cmd, '.*86');
&open_execute_command(CMD, "$module_config_directory/$cmd", 1, 1);
while(<CMD>) {
	local @p = split(/\t/, $_);
	if ($p[2] eq "procfs" || $p[1] eq "procfs") { $p[1] = $p[2] = "proc"; }
	push(@rv, \@p);
	}
close(CMD);

# add output from swapinfo
&open_execute_command(SWAP, "swapinfo", 1, 1);
while(<SWAP>) {
	if (/^(\/\S+)\s+\d+\s+\d+/) {<commit_msg>Compile correct openbsd mounts command<commit_after># openbsd-lib.pl
# Mount table functions for openbsd

$uname_release = `uname -r`;

# Return information about a filesystem, in the form:
#  directory, device, type, options, fsck_order, mount_at_boot
# If a field is unused or ignored, a - appears instead of the value.
# Swap-filesystems (devices or files mounted for VM) have a type of 'swap',
# and 'swap' in the directory field
sub list_mounts
{
local(@rv, @p, @o, $_, $i, $j); $i = 0;

# Get /etc/fstab mounts
open(FSTAB, $config{'fstab_file'});
while(<FSTAB>) {
	local(@o, $at_boot);
	chop; s/#.*$//g;
	if (!/\S/) { next; }
	@p = split(/\s+/, $_);
	if ($p[2] eq "proc" || $p[2] eq "procfs") { $p[2] = $p[0] = "proc"; }
	if ($p[2] eq "swap") { $p[1] = "swap"; }
	$rv[$i] = [ $p[1], $p[0], $p[2] ];
	$rv[$i]->[5] = "yes";
	@o = split(/,/ , $p[3] eq "defaults" ? "" : $p[3]);
	if (($j = &indexof("noauto", @o)) >= 0) {
		# filesytem is not mounted at boot
		splice(@o, $j, 1);
		$rv[$i]->[5] = "no";
		}
	$rv[$i]->[3] = (@o ? join(',' , @o) : "-");
	$rv[$i]->[4] = (@p >= 5 ? $p[5] : 0);
	$i++;
	}
close(FSTAB);
return @rv;
}


# create_mount(directory, device, type, options, fsck_order, mount_at_boot)
# Add a new entry to the fstab file, old or new automounter file
sub create_mount
{
local(@mlist, @amd, $_); local($opts);

# Adding a normal mount to the fstab file
&open_tempfile(FSTAB, ">> $config{'fstab_file'}");
&print_tempfile(FSTAB, "$_[1]  $_[0]  $_[2]");
$opts = $_[3] eq "-" ? "" : $_[3];
if ($_[5] eq "no") {
	$opts = join(',' , (split(/,/ , $opts) , "noauto"));
	}
if ($opts eq "") { &print_tempfile(FSTAB, "  defaults"); }
else { &print_tempfile(FSTAB, "  $opts"); }
&print_tempfile(FSTAB, "  0  ");
&print_tempfile(FSTAB, $_[4] eq "-" ? "0\n" : "$_[4]\n");
&close_tempfile(FSTAB);
}


# change_mount(num, directory, device, type, options, fsck_order, mount_at_boot)
# Change an existing permanent mount
sub change_mount
{
local($i, @fstab, $line, $opts, $j, @amd);
$i = 0;

# Update fstab file
open(FSTAB, $config{fstab_file});
@fstab = <FSTAB>;
close(FSTAB);
&open_tempfile(FSTAB, "> $config{fstab_file}");
foreach (@fstab) {
	chop; ($line = $_) =~ s/#.*$//g;
	if ($line =~ /\S/ && $i++ == $_[0]) {
		# Found the line to replace
		&print_tempfile(FSTAB, "$_[2]  $_[1]  $_[3]");
		$opts = $_[4] eq "-" ? "" : $_[4];
		if ($_[6] eq "no") {
			$opts = join(',' , (split(/,/ , $opts) , "noauto"));
			}
		if ($opts eq "") { &print_tempfile(FSTAB, "  defaults"); }
		else { &print_tempfile(FSTAB, "  $opts"); }
		&print_tempfile(FSTAB, "  0  ");
		&print_tempfile(FSTAB, $_[5] eq "-" ? "0\n" : "$_[5]\n");
		}
	else {
		&print_tempfile(FSTAB, $_,"\n");
		}
	}
&close_tempfile(FSTAB);
}


# delete_mount(index)
# Delete an existing permanent mount
sub delete_mount
{
local($i, @fstab, $line, $opts, $j, @amd);
$i = 0;

# Update fstab file
open(FSTAB, $config{fstab_file});
@fstab = <FSTAB>;
close(FSTAB);
&open_tempfile(FSTAB, "> $config{fstab_file}");
foreach (@fstab) {
	chop; ($line = $_) =~ s/#.*$//g;
	if ($line !~ /\S/ || $i++ != $_[0]) {
		# Don't delete this line
		&print_tempfile(FSTAB, $_,"\n");
		}
	}
&close_tempfile(FSTAB);
}


# list_mounted()
# Return a list of all the currently mounted filesystems and swap files.
# The list is in the form:
#  directory device type options
# Under OpenBSD, there seems to be no way to get additional mount options
# used by filesystems like NFS etc. Even getting the full details of mounted
# filesystems requires C code! So we have to call a specially-written external
# program to get the mount list
sub list_mounted
{
# get the list of mounted filesystems
local(@rv, $_);
local $cmd = $uname_release =~ /^5\./ ? "openbsd-mounts-5" :
	     $uname_release =~ /^4\./ ? "openbsd-mounts-4" :
	     $uname_release =~ /^3\./ ? "openbsd-mounts-3" :
					"openbsd-mounts-2";
&compile_program($cmd, '.*86');
&open_execute_command(CMD, "$module_config_directory/$cmd", 1, 1);
while(<CMD>) {
	local @p = split(/\t/, $_);
	if ($p[2] eq "procfs" || $p[1] eq "procfs") { $p[1] = $p[2] = "proc"; }
	push(@rv, \@p);
	}
close(CMD);

# add output from swapinfo
&open_execute_command(SWAP, "swapinfo", 1, 1);
while(<SWAP>) {
	if (/^(\/\S+)\s+\d+\s+\d+/) {
{'fraction_non_alphanumeric': 0.2312582463715965, 'fraction_numerical': 0.014633561233057455, 'mean_word_length': 4.038066465256797, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2717113', 'n_tokens_mistral': 3674, 'n_tokens_neox': 3504, 'n_words': 903}