Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Nativ Systemcall statvfs with .netCore

$
0
0

Hey,

ive got a Problem with the Interop of .netCore. 

I want to call the statvfs Systemcall on my Linux machines with .netCore. Im doing this with the Example fromMicrosoft. 

The Example with ftw is working great, but with statvfs i seems that the delagation is doing nothing, but strace shows, that the statvfs syscall will be executed. Also the success Variable will be set to 0.

I hope anyone can help!

Sorry for that bad English.

Here is my code:

using System;
using System.Runtime.InteropServices;


namespace ServerEye_LinuxClient.Sensorhub.Disk
{
    class systemfs
    {
        delegate int DirClbk(string dPath, StatClass stat);
        [DllImport("libc.so.6")]
        static extern int statvfs(string dirpath, DirClbk cl);
        int DisplayEntry(string dPathe, StatClass stat)
        {
            Console.WriteLine(stat.f_bfree);
            return 2;
        }


        public systemfs()
        {
            DirClbk displayEntry = new DirClbk(DisplayEntry);

            int success = 50;
            success = statvfs("/etc", displayEntry);

        }
    }

    public enum MountFlags : uint
    {
        ST_RDONLY = 1,  // Mount read-only
        ST_NOSUID = 2,  // Ignore suid and sgid bits
        ST_NODEV = 4,  // Disallow access to device special files
        ST_NOEXEC = 8,  // Disallow program execution
        ST_SYNCHRONOUS = 16,  // Writes are synced at once
        ST_REMOUNT = 32,  // Alter flags of a mounted FS
        ST_MANDLOCK = 64,  // Allow mandatory locks on an FS
        ST_WRITE = 128,  // Write on file/directory/symlink
        ST_APPEND = 256,  // Append-only file
        ST_IMMUTABLE = 512,  // Immutable file
        ST_NOATIME = 1024,  // Do not update access times
        ST_NODIRATIME = 2048,  // Do not update directory access times
        ST_BIND = 4096,  // Bind directory at different place
    }

    [StructLayout(LayoutKind.Sequential)]
    public class StatClass
    {
        public uint f_bsize;    /* file system block size */
        public uint f_frsize;   /* fragment size */
        public uint f_blocks;   /* size of fs in f_frsize units */
        public uint f_bfree;    /* # free blocks */
        public uint f_bavail;   /* # free blocks for unprivileged users */
        public uint f_files;    /* # inodes */
        public uint f_ffree;    /* # free inodes */
        public uint f_favail;   /* # free inodes for unprivileged users */
        public uint f_fsid;     /* file system ID */
        public uint f_flag;     /* mount flags */
        public uint f_namemax;  /* maximum filename length */


    }


}

Viewing all articles
Browse latest Browse all 9386

Trending Articles