简体   繁体   English

如何从statfs获取f_type?

[英]How do I get f_type from statfs?

I need to get f_type from statfs . 我需要从statfs获取f_type I tried patching Filesys::Df : 我尝试修补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

followed by 其次是

perl Makefile.PL ; make ; perl -Mblib -MFilesys::Df=df -E'say df("/")->{type}'

but that crashes 但这崩溃了

panic: XSUB Filesys::Df::_df (Df.c) failed to extend arg stack: base=11d3b10, sp=11d3b50, hwm=11d3b48

How do I solve this problem? 我该如何解决这个问题?

Unlike XPUSH* , PUSH* doesn't ensure there's enough room on the stack. XPUSH*不同, PUSH*不能确保堆栈上有足够的空间。

PUSHs 按键

Push an SV onto the stack. 将SV推入堆栈。 The stack must have room for this element. 堆栈必须为该元素留出空间。 Does not handle 'set' magic. 不处理“定型”魔法。 Does not use TARG . 不使用TARG See also PUSHmortal , XPUSHs , and XPUSHmortal . 另请参见PUSHmortalXPUSHsXPUSHmortal

 void PUSHs(SV* sv) 

To ensure there's enough space for the additional value being returned, simply replace 为了确保有足够的空间来返回附加值,只需替换

EXTEND(sp, 7)

with

EXTEND(sp, 8)

EXTEND 延伸

Used to extend the argument stack for an XSUB's return values. 用于扩展XSUB返回值的参数堆栈。 Once used, guarantees that there is room for at least nitems to be pushed onto the stack. 一旦使用,请确保至少有空间将nitems推入堆栈。

 void EXTEND(SP, SSize_t nitems) 

Tip: 小费:

PUSHs(sv_2mortal(newSVnv((double)st.f_type)));

should be 应该

PUSHs(sv_2mortal(newSVnv((NV)st.f_type)));

That can be shortened to 可以缩短为

mPUSHs(newSVnv((NV)st.f_type));

And that can be shortened to 可以缩短为

mPUSHn((NV)st.f_type);

I realize you're creating a minimal patch and that you're striving for consistency, but this could benefit you and other readers in other situations. 我意识到您正在创建一个最小的补丁程序,并且您正在努力追求一致性,但这可以使您和其他情况下的其他读者受益。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM