Filesystem block/page size



  • I know this was there is qtextended, but since it's been discontinued; is there still a way in Qt to get the filesystem block size or the operating system page size?

    The reason I ask is because I'm not finding it anywhere browsing through the api and I need it in order to determine the most appropriate and fastest filesystem read/write operations...

    Thanks,



  • Posix? (A standard C api for operating systems calls.)

    In other words, should Qt be offering an api to all operating system calls when there is already another standard for that? Although I don't know whether Windows offers a posix api, and whether the posix api offers a function to get what you want.



  • While the Mac, iOS, and unix/linux variants support posix calls by default, please keep in mind that posix is a standard, and like TR2 from boost, not everything is included as standardized or intended.

    That said, no, Windows does NOT support Posix at this time without the user needing to install linux or unix-based ports. And I cannot have that just so I can determine a block or page size..

    We used to do this in code. Obviously, I only need block sizes for desktop/laptop operating systems - meaning I only need this for full-blown computers. I already have code to do this, which I will place below...

    So since nobody could answer my question, I guess I can just rephrase it: How do I make this code compile differently for each system under QT?

    Thanks,

    @
    #include "systemstats.h"

    #include "unistd.h"

    SystemStats::SystemStats()
    {
    }

    int SystemStats::getPageSize()
    {
    return sysconf (_SC_PAGESIZE); //Android, linux

    //return (int) NSPageSize(); //mac
    
    //windows
    //SYSTEM_INFO systemInfo;
    //GetNativeSystemInfo (&systemInfo);
    //return (int) systemInfo.dwPageSize;
    

    }
    @

    ^^That is the code I need (I also need the header include for mac os x and windows) that needs to be compiled differently under different sytems (win32, macosx, linux/unix). How do I do that? Should I move it all to the header file?

    Regards,



  • Here is all the required code to get the correct page size for linux/unix, mac os x, and windows variants (instead of just statfs or statvfs, which is commonly unsupported, or Posix, which is also commonly unsupported...

    @
    #include "systemstats.h"

    #include "unistd.h"

    //#import <Foundation/Foundation.h> //mac
    //#include Windows.h //windows

    SystemStats::SystemStats()
    {
    }

    int SystemStats::getPageSize()
    {
    return sysconf (_SC_PAGESIZE); //Android, linux

    //return (int) NSPageSize(); //mac
    
    //windows
    //SYSTEM_INFO systemInfo;
    //GetNativeSystemInfo (&systemInfo);
    //return (int) systemInfo.dwPageSize;
    

    }
    @

    Now I just need to know how to make the commented out sections compile differently under different platforms. The first version, sysconf, should work for most unix/linux variants. It's just that to get the correct page size in windows and mac os x, it requires a little different code. This is the platform-specific way of correctly getting the block/page size for an operating system...

    Regards,



  • Sorry - I wish I could edit these posts... I just found out as of xcode tools 4.0 and mac osx version 10.8.2, sysconf is supported in mac as well... So the code becomes the following: (also, sysconf seems to be a c++ posix wrapper, it's just that ms doesn't support posix, which is why it's easier to do it this way...)

    @
    #include "systemstats.h"

    #include "unistd.h"

    //#include Windows.h //windows

    SystemStats::SystemStats()
    {
    }

    int SystemStats::getPageSize()
    {
    return sysconf (_SC_PAGESIZE); //linux, unix, mac, other

    //windows
    //SYSTEM_INFO systemInfo;
    //GetNativeSystemInfo (&systemInfo);
    //return (int) systemInfo.dwPageSize;
    

    }
    @

    I think a simple elif directive should do the trick with compiling under different situations, even in the code. I'll have to do some digging to see what all supports sysconf and compare that with the various systems that are supported by Qt. Give me a bit....



  • You can generally do this to find out the OS page size, since now iOS and Mac variants use sysconf. I found that most QT-related systems are Unix/Linux and generally Posix-compliant. Someone would need to test it on all systems for Qt to know for sure..

    On another note, Qt extended used a unsafe method of finding out the block size, and rather what we are interested in is coming from the processor - a filesystem may have a block size of 4096, but the OS has a page size of 32,768. That's why it's important to know. But the Qt-extended package used 'statvfs' and 'statfs', and in many cases the results were off or not supported by certain systems. That's why we do this in code instead of a system call. There is no system call, for instance, in windows variants to get the page size - you have to do it in their win32 api...

    Here's the revision:

    SysStats.h:
    @
    #ifdef Q_OS_WIN
    #include <windows.h>
    #else
    #include "unistd.h"
    #endif

    class SysStats {
    public:
    SysStats() {}

    qint64 getPageSize() {
    

    #ifdef Q_OS_WIN
    //windows method
    SYSTEM_INFO systemInfo;
    GetNativeSystemInfo (&systemInfo);
    return (qint64) systemInfo.dwPageSize;
    #endif
    #ifdef Q_OS_UNIXWARE
    return (qint64) sysconf (_SC_PAGESIZE); //posix method call
    #endif
    ...
    //repeat for all other Qt supported OS's..
    @

    Or if you're lazy and you don't want to test this on all Qt platforms you could just do the following, assuming all Qt supported OS's are Posix-compliant except for windows:

    @
    #ifdef Q_OS_WIN
    #include <windows.h>
    #else
    #include "unistd.h"
    #endif

    class SysStats {
    public:
    SysStats() {}

    qint64 getPageSize() {
    

    #ifdef Q_OS_WIN
    //windows method
    SYSTEM_INFO systemInfo;
    GetNativeSystemInfo (&systemInfo);
    return (qint64) systemInfo.dwPageSize;
    #else
    return (qint64) sysconf (_SC_PAGESIZE); //posix method call
    #endif
    @

    May want the guys at Digia to add this to their repo and test. It's an important piece for anyone wanting fast disk IO.... Actually, it's a necessity. Doesn't matter if it's an old standard, it's not a good thing to assume 4096 byte buffers or 32768 byte buffers just for $hits and giggles - for fast IO you need to know the page sizes...

    Later, dudes


  • Lifetime Qt Champion

    Hi,

    You can look at the "bug report system":http://bugreports.qt-project.org to see whether there's already something like that and if not post a feature request with it.

    You can edit your post on the forum, under your avatar you have an "edit" link that allows to do that.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.