Add support for FreeBSD in FSUtils::getDirectoryFileSystem().
AbandonedPublic

Authored by tcberner on May 9 2017, 10:08 AM.

Details

Reviewers
poboiko
bruns
kfunk
Group Reviewers
FreeBSD
Summary

This is not really needed at the moment, as it only seems to be needed to check if the filesystem is btrfs.

I'm however not sure, if the simpler code used for FreeBSD would not also work on linux :)

Diff Detail

Repository
R293 Baloo
Branch
master
Lint
No Linters Available
Unit
No Unit Test Coverage
tcberner created this revision.May 9 2017, 10:08 AM
Restricted Application added a project: Frameworks. · View Herald TranscriptMay 9 2017, 10:08 AM
Restricted Application added a subscriber: Frameworks. · View Herald Transcript
kfunk added a subscriber: kfunk.EditedMay 9 2017, 10:41 AM

What about http://doc.qt.io/qt-5/qstorageinfo.html#fileSystemType?

Uses statfs internally, on both platforms:

void QStorageInfoPrivate::retrieveVolumeInfo()
{
    QT_STATFSBUF statfs_buf;
    int result;
    EINTR_LOOP(result, QT_STATFS(QFile::encodeName(rootPath).constData(), &statfs_buf));
    if (result == 0) {
        valid = true;
        ready = true;

#if defined(Q_OS_INTEGRITY) || (defined(Q_OS_BSD4) && !defined(Q_OS_NETBSD))
        bytesTotal = statfs_buf.f_blocks * statfs_buf.f_bsize;
        bytesFree = statfs_buf.f_bfree * statfs_buf.f_bsize;
        bytesAvailable = statfs_buf.f_bavail * statfs_buf.f_bsize;
#else
        bytesTotal = statfs_buf.f_blocks * statfs_buf.f_frsize;
        bytesFree = statfs_buf.f_bfree * statfs_buf.f_frsize;
        bytesAvailable = statfs_buf.f_bavail * statfs_buf.f_frsize;
#endif
        blockSize = statfs_buf.f_bsize;
#if defined(Q_OS_ANDROID) || defined(Q_OS_BSD4) || defined(Q_OS_INTEGRITY)
#if defined(_STATFS_F_FLAGS)
        readOnly = (statfs_buf.f_flags & ST_RDONLY) != 0;
#endif
#else
        readOnly = (statfs_buf.f_flag & ST_RDONLY) != 0;
#endif
    }
}

//...

inline QByteArray QStorageIterator::fileSystemType() const
{
    return QByteArray(stat_buf[currentIndex].f_fstypename);
}

Hm, QStorageInfo does not seem to return anything sensible on FreeBSD:

""
name: ""
fileSystemType: ""
size: 0 MB
availableSize: 0 MB

This is the output from the QStorageInfo::root() example.

kfunk added a comment.EditedMay 9 2017, 1:48 PM

Okay, then maybe support for the current FreeBSD version is not implemented? I have no idea about FreeBSD, to be honest. But it looks like using this API, and implementing the proper support in QStorageInfo internals would be the appropriate place.

Anyhow, if Qt support is lacking, this patch here makes sense then -- at least the hunks for FreeBSD. I'll let others review this patch in detail.

tcberner planned changes to this revision.May 9 2017, 3:04 PM

I agree. I'll try and figure out whats wrong inside QStorageInfo, and then update the review here to be using it.

Ok, I think I found the issue in QStorageInfo -- it calls getmntinfo() with flags=0 [1] . Instead one of the valid arguments 1-4 [2].

[1] https://github.com/qt/qtbase/blob/dev/src/corelib/io/qstorageinfo_unix.cpp#L199
[2] https://svnweb.freebsd.org/base/head/sys/sys/mount.h?revision=318736&view=markup#l441

tcberner updated this revision to Diff 14965.May 30 2017, 6:35 AM

Use QStorageInfo.

adridg added a subscriber: adridg.Jun 24 2017, 11:53 AM

So this patch looks ready to land to me: it simplifies the code, defers fstype-detection to QStorageInfo (for FreeBSD, we should fix the original issue there), and is otherwise non-intrusive.

Add reviewers who have commented, or who have committed to baloo recently.

bruns added a subscriber: bruns.Apr 9 2018, 7:35 PM

The whole function as currently used is pointless.

Currently, it sets the NO_COW flag on BTRFS, but this is insufficient:

At least on Linux, the correct thing is to *try* to set the no_cow flag, and silently ignore any EOPNOTSUPP errors.

Thats what I get on Linux for:

  • File without permission to write: ioctl(3, FS_IOC_SETFLAGS, 0x7ffee879084c) = -1 EPERM (Operation not permitted)
  • On an old XFS: ioctl(3, FS_IOC_SETFLAGS, 0x7fff8e52467c) = -1 EOPNOTSUPP (Operation not supported)
  • BTRFS: ioctl(3, FS_IOC_SETFLAGS, 0x7fff06817a2c) = 0

This way the code is future proof even when a new FS appears or an old one gains new features.

Restricted Application added a project: Baloo. · View Herald TranscriptApr 9 2018, 7:35 PM
bruns added a reviewer: bruns.Apr 9 2018, 7:36 PM
kfunk resigned from this revision.Apr 9 2018, 8:22 PM
adridg added a comment.Apr 9 2018, 9:09 PM

The question is mostly: does the existing (complicated) code do anything that QStorageInfo doesn't? Because switching to QStorageInfo gives us the functionality on FreeBSD for free (even if it's not useful because we'll never have btrfs).

bruns added a comment.Apr 10 2018, 2:38 AM

The question is mostly: does the existing (complicated) code do anything that QStorageInfo doesn't? Because switching to QStorageInfo gives us the functionality on FreeBSD for free (even if it's not useful because we'll never have btrfs).

My opinion is to scrap the function completely, on *BSD and on Linux. Iff there ever is a need, one can add it back, or just call QStorageInfo directly wherever it is used.

Given the other reviews (which just drop this function), this one should be abandoned. tcberner@?

tcberner abandoned this revision.Apr 12 2018, 4:14 PM