9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync/* $Id$ */
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync/** @file
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync * IPRT - File I/O, RTFileFsQuerySizes, POSIX.
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync */
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync/*
c58f1213e628a545081c70e26c6b67a841cff880vboxsync * Copyright (C) 2006-2011 Oracle Corporation
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync *
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync * available from http://www.virtualbox.org. This file is free software;
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync * you can redistribute it and/or modify it under the terms of the GNU
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync * General Public License (GPL) as published by the Free Software
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync *
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync * The contents of this file may alternatively be used under the terms
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync * of the Common Development and Distribution License Version 1.0
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync * VirtualBox OSE distribution, in which case the provisions of the
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync * CDDL are applicable instead of those of the GPL.
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync *
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync * You may elect to license modified versions of this file under the
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync * terms and conditions of either the GPL or the CDDL or both.
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync */
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync/*******************************************************************************
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync* Header Files *
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync*******************************************************************************/
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync#define LOG_GROUP RTLOGGROUP_FILE
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync#include <errno.h>
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync#include <sys/types.h>
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync#include <fcntl.h>
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync#include <sys/statvfs.h>
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync#include <iprt/file.h>
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync#include <iprt/assert.h>
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync#include <iprt/err.h>
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync#include <iprt/log.h>
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync#include <iprt/string.h>
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsyncRTR3DECL(int) RTFileQueryFsSizes(RTFILE hFile, PRTFOFF pcbTotal, RTFOFF *pcbFree,
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync uint32_t *pcbBlock, uint32_t *pcbSector)
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync{
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync struct statvfs StatVFS;
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync RT_ZERO(StatVFS);
dc0a54940789f994c84390cb4a9f03da0b492285vboxsync if (fstatvfs(RTFileToNative(hFile), &StatVFS))
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync return RTErrConvertFromErrno(errno);
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync /*
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync * Calc the returned values.
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync */
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync if (pcbTotal)
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync *pcbTotal = (RTFOFF)StatVFS.f_blocks * StatVFS.f_frsize;
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync if (pcbFree)
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync *pcbFree = (RTFOFF)StatVFS.f_bavail * StatVFS.f_frsize;
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync if (pcbBlock)
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync *pcbBlock = StatVFS.f_frsize;
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync /* no idea how to get the sector... */
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync if (pcbSector)
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync *pcbSector = 512;
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync return VINF_SUCCESS;
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync}
9944a1231eb05af16f6e0f90db244ad98c8312eavboxsync