perl - 如何从 statfs 获取 f_type?
问题描述
我需要f_type
从statfs
. 我尝试修补Filesys::Df
:
---
Df.pm | 6 +++---
Makefile.PL | 7 +------
XS_statfs | 1 +
3 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/Df.pm b/Df.pm
index b24bd9c..986082a 100644
--- a/Df.pm
+++ b/Df.pm
@@ -28,7 +28,7 @@ my %fs = ();
($block_size) ||
($block_size = 1024);
- my ($frsize, $blocks, $bfree, $bavail, $files, $ffree, $favail);
+ my ($frsize, $blocks, $bfree, $bavail, $files, $ffree, $favail, $ftype);
#### If open filehandle call fstatvfs or fstatfs
if(defined(fileno($dir))) {
@@ -36,7 +36,7 @@ my %fs = ();
}
else {
- ($frsize, $blocks, $bfree, $bavail, $files, $ffree, $favail) = _df($dir);
+ ($frsize, $blocks, $bfree, $bavail, $files, $ffree, $favail, $ftype) = _df($dir);
}
@@ -199,7 +199,7 @@ my %fs = ();
# $fs{user_files} = undef;
#}
-
+ $fs{type} = $ftype;
return(\%fs);
}
diff --git a/Makefile.PL b/Makefile.PL
index 6a89ec4..e91cbb3 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -21,12 +21,7 @@ if($Config{osname} =~ /^MSWin/i) {
die "You might try Filesys::DfPortable instead.\n";
}
-#### Check for the existance of statvfs
-if(check_statvfs()) {
- ####$define .= "-DDF_STATVFS ";
- copy_xs("XS_statvfs", $xs_file);
- print "Building with statvfs ....\n";
-}
+# force statfs
#### Check for the existance of statfs
elsif(check_statfs()) {
diff --git a/XS_statfs b/XS_statfs
index 856c646..ef801c3 100644
--- a/XS_statfs
+++ b/XS_statfs
@@ -45,6 +45,7 @@ _df(dir)
PUSHs(sv_2mortal(newSVnv((double)st.f_ffree)));
/* No favail */
PUSHs(sv_2mortal(newSVnv((double)st.f_ffree)));
+ PUSHs(sv_2mortal(newSVnv((double)st.f_type)));
}
else {
--
2.21.0
其次是
perl Makefile.PL ; make ; perl -Mblib -MFilesys::Df=df -E'say df("/")->{type}'
但这会崩溃
panic: XSUB Filesys::Df::_df (Df.c) failed to extend arg stack: base=11d3b10, sp=11d3b50, hwm=11d3b48
我该如何解决这个问题?
解决方案
与, 不同XPUSH*
,PUSH*
不能确保堆栈上有足够的空间。
推
将 SV 压入堆栈。堆栈必须为该元素留出空间。不处理“设置”魔法。不使用
TARG
. 另请参阅PUSHmortal
、XPUSHs
和XPUSHmortal
。void PUSHs(SV* sv)
为确保有足够的空间用于返回的附加值,只需替换
EXTEND(sp, 7)
和
EXTEND(sp, 8)
延长
用于扩展 XSUB 返回值的参数堆栈。一旦使用,保证至少有空间
nitems
被压入堆栈。void EXTEND(SP, SSize_t nitems)
小费:
PUSHs(sv_2mortal(newSVnv((double)st.f_type)));
应该
PUSHs(sv_2mortal(newSVnv((NV)st.f_type)));
可以缩短为
mPUSHs(newSVnv((NV)st.f_type));
这可以缩短为
mPUSHn((NV)st.f_type);
我意识到您正在创建一个最小的补丁并且您正在努力保持一致性,但这可能会使您和其他情况下的其他读者受益。
推荐阅读
- angular - 获取用户从 ngFor 列表中选择的值
- node.js - 我想发出一个命令,让机器人可以记录编辑过的消息
- python - 我从音频文件中提取 mfccs 功能并指定 numcep = 13 但它超过 13 列,为什么?
- javascript - 如何在 JavaScript 中使用包?
- asp.net - 是否有可能知道从我们的邮箱发送了多少封电子邮件?(ASP.NET)
- mysql - 无法在 mac mini 上安装 mariadb
- java - 有没有办法强制 Transformer 在 XML 中将空格写成 unicode 转义?
- flutter - 我是否必须在此错误中更改软件包版本?
- amazon-s3 - 我如何在同一台服务器上同时执行 S3 AWS 入站和出站命令
- reactjs - 用于 React-native 应用程序的 react-native-maps 中的 initialRegion 函数