/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*-
 * ex: set softtabstop=4 tabstop=8 expandtab shiftwidth=4: *
 * Editor Settings: expandtabs and use 4 spaces for indentation */

/*
 * Copyright Likewise Software
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.  You should have received a copy of the GNU General
 * Public License along with this program.  If not, see
 * <http://www.gnu.org/licenses/>.
 *
 * LIKEWISE SOFTWARE MAKES THIS SOFTWARE AVAILABLE UNDER OTHER LICENSING
 * TERMS AS WELL.  IF YOU HAVE ENTERED INTO A SEPARATE LICENSE AGREEMENT
 * WITH LIKEWISE SOFTWARE, THEN YOU MAY ELECT TO USE THE SOFTWARE UNDER THE
 * TERMS OF THAT SOFTWARE LICENSE AGREEMENT INSTEAD OF THE TERMS OF THE GNU
 * GENERAL PUBLIC LICENSE, NOTWITHSTANDING THE ABOVE NOTICE.  IF YOU
 * HAVE QUESTIONS, OR WISH TO REQUEST A COPY OF THE ALTERNATE LICENSING
 * TERMS OFFERED BY LIKEWISE SOFTWARE, PLEASE CONTACT LIKEWISE SOFTWARE AT
 * license@likewisesoftware.com
 */

/*
 * Copyright (C) Likewise Software. All rights reserved.
 *
 * Module Name:
 *
 *        getfsinfo.c
 *
 * Abstract:
 *
 *        Likewise IO (LWIO) - SRV
 *
 *        Protocols API - SMBV2
 *
 *        Query File System Information
 *
 * Authors: Krishna Ganugapati (kganugapati@likewise.com)
 *          Sriram Nambakam (snambakam@likewise.com)
 *
 *
 */

#include "includes.h"

static GET_INFO_CLASS_MARSHAL_FUNC SrvMarshalFileSystemControlInfo_SMB_V2;

static GET_INFO_CLASS_DISPATCH_ENTRY FsInfoClassDispatchTable_SMB_V2[] =
{
    [SMB2_FS_INFO_CLASS_VOLUME]     =
    {
        SrvGetFileSystemInfoGeneric_WithString,
        SrvMarshalFileSystemVolumeInfo,
        FileFsVolumeInformation,
        sizeof(SMB_FS_VOLUME_INFO_HEADER),
        sizeof(FILE_FS_VOLUME_INFORMATION)
    },
    [SMB2_FS_INFO_CLASS_SIZE]       =
    {
        SrvGetFileSystemInfoGeneric,
        SrvMarshalFileSystemSizeInfo,
        FileFsSizeInformation,
        sizeof(SMB_FS_SIZE_INFO),
        sizeof(FILE_FS_SIZE_INFORMATION)
    },
    [SMB2_FS_INFO_CLASS_DEVICE]     =
    {
        SrvGetUnsupportedInfo,
        SrvMarshalUnsupportedInfo,
        FileFsDeviceInformation,
        sizeof(SMB_FS_DEVICE_INFO),
        sizeof(FILE_FS_DEVICE_INFORMATION)
    },
    [SMB2_FS_INFO_CLASS_ATTRIBUTE]  =
    {
        SrvGetFileSystemInfoGeneric_WithString,
        SrvMarshalFileSystemAttributeInfo,
        FileFsAttributeInformation,
        sizeof(SMB_FS_ATTRIBUTE_INFO_HEADER),
        sizeof(FILE_FS_ATTRIBUTE_INFORMATION)
    },
    [SMB2_FS_INFO_CLASS_CONTROL]    =
    {
        SrvGetFileSystemInfoGeneric,
        SrvMarshalFileSystemControlInfo_SMB_V2,
        FileFsControlInformation,
        sizeof(SMB_FS_CONTROL_INFO),
        sizeof(FILE_FS_CONTROL_INFORMATION)
    },
    [SMB2_FS_INFO_CLASS_FULL_SIZE]  =
    {
        SrvGetFileSystemInfoGeneric,
        SrvMarshalFileSystemFullSizeInfo,
        FileFsFullSizeInformation,
        sizeof(SMB_FS_FULL_SIZE_INFO),
        sizeof(FILE_FS_FULL_SIZE_INFORMATION)
    },
    [SMB_FS_INFO_CLASS_OBJECTID]    =
    {
        SrvGetUnsupportedInfo,
        SrvMarshalUnsupportedInfo,
        FileFsObjectIdInformation,
        sizeof(SMB_FS_OBJECTID_INFO),
        sizeof(FILE_FS_OBJECTID_INFORMATION)
    }
};

PGET_INFO_CLASS_DISPATCH_ENTRY
SrvGetFileSystemInfoDispatchTable_SMB_V2(
    VOID
    )
{
    return FsInfoClassDispatchTable_SMB_V2;
}

size_t
SrvGetFileSystemInfoDispatchTableSize_SMB_V2(
    VOID
    )
{
    return LW_ARRAY_SIZE(FsInfoClassDispatchTable_SMB_V2);
}

static
NTSTATUS
SrvMarshalFileSystemControlInfo_SMB_V2(
    PSRV_EXEC_CONTEXT               pExecContext,
    PSRV_PROCESS_INFO_STATE         pInfoState,
    PGET_INFO_CLASS_DISPATCH_ENTRY  pInfoEntry,
    PBYTE                           pOutBuffer,
    ULONG                           ulBytesAvailable,
    PULONG                          pulBytesUsed
    )
{
    NTSTATUS                     ntStatus          = STATUS_SUCCESS;
    PFILE_FS_CONTROL_INFORMATION pFSControlInfo    = NULL;
    PSMB_FS_CONTROL_INFO         pSMBFSControlInfo = NULL;

    pFSControlInfo    = (PFILE_FS_CONTROL_INFORMATION)pInfoState->pData;
    pSMBFSControlInfo = (PSMB_FS_CONTROL_INFO)pOutBuffer;

    pSMBFSControlInfo->llFreeSpaceStartFiltering = 
        pFSControlInfo->FreeSpaceStartFiltering;
    pSMBFSControlInfo->llFreeSpaceThreshold =
        pFSControlInfo->FreeSpaceThreshold;
    pSMBFSControlInfo->llFreeSpaceStopFiltering =
        pFSControlInfo->FreeSpaceStopFiltering;
    pSMBFSControlInfo->llDefaultQuotaThreshold =
        pFSControlInfo->DefaultQuotaThreshold;
    pSMBFSControlInfo->llDefaultQuotaLimit =
        pFSControlInfo->DefaultQuotaLimit;
    pSMBFSControlInfo->FileSystemControlFlags =
        pFSControlInfo->FileSystemControlFlags;
    memset(pSMBFSControlInfo->Pad, 0, sizeof(pSMBFSControlInfo->Pad)); 

    *pulBytesUsed = pInfoEntry->ProtoStructSize;

    return ntStatus;
}
