Пример #1
0
NTSTATUS
LwIoFuseGetNtFilename(
    PIO_FUSE_CONTEXT pFuseContext,
    PCSTR pszPath,
    PIO_FILE_NAME pFilename
    )
{
    NTSTATUS status = STATUS_SUCCESS;

    memset(pFilename, 0, sizeof(*pFilename));

    status = LwRtlUnicodeStringAllocatePrintfW(
        &pFilename->Name,
        L"%ws/%s",
        pFuseContext->pwszInternalPath,
        pszPath);
    BAIL_ON_NT_STATUS(status);
    
cleanup:

    return status;

error:

    RTL_UNICODE_STRING_FREE(&pFilename->Name);
 
    memset(pFilename, 0, sizeof(*pFilename));

    goto cleanup;
}
Пример #2
0
NTSTATUS
LwIoFuseUnlink(
    const char* pszPath
    )
{
    NTSTATUS status = STATUS_SUCCESS;
    IO_STATUS_BLOCK ioStatus = {0};
    IO_FILE_HANDLE handle = NULL;
    PIO_FUSE_CONTEXT pFuseContext = NULL;
    IO_FILE_NAME filename = {0};

    pFuseContext = LwIoFuseGetContext();

    status = LwIoFuseGetNtFilename(
        pFuseContext,
        pszPath,
        &filename);
    BAIL_ON_NT_STATUS(status);

    status = LwNtCreateFile(
        &handle,                 /* File handle */
        NULL,                    /* Async control block */
        &ioStatus,               /* IO status block */
        &filename,               /* Filename */
        NULL,                    /* Security descriptor */
        NULL,                    /* Security QOS */
        DELETE,                  /* Desired access mask */
        0,                       /* Allocation size */
        0,                       /* File attributes */
        FILE_SHARE_READ |
        FILE_SHARE_WRITE |
        FILE_SHARE_DELETE,       /* Share access */
        FILE_OPEN,               /* Create disposition */
        FILE_DELETE_ON_CLOSE,    /* Create options */
        NULL,                    /* EA buffer */
        0,                       /* EA length */
        NULL,                    /* ECP list */
        NULL);
    BAIL_ON_NT_STATUS(status);

cleanup:

    if (handle)
    {
        LwNtCloseFile(handle);
    }

    RTL_UNICODE_STRING_FREE(&filename.Name);

    return status;

error:

    goto cleanup;
}
Пример #3
0
NTSTATUS
LwIoFuseRename(
    const char* pszOldPath,
    const char* pszNewPath
    )
{
    NTSTATUS status = STATUS_SUCCESS;
    IO_STATUS_BLOCK ioStatus = {0};
    IO_FILE_HANDLE handle = NULL;
    PIO_FUSE_CONTEXT pFuseContext = NULL;
    IO_FILE_NAME filename = {0};
    PFILE_RENAME_INFORMATION pRenameInfo = NULL;
    PWSTR pwszNewPath = NULL;
    size_t newPathLength = 0;
    
    pFuseContext = LwIoFuseGetContext();

    status = LwIoFuseGetDriverRelativePath(
        pFuseContext,
        pszNewPath,
        &pwszNewPath);
    BAIL_ON_NT_STATUS(status);

    newPathLength = LwRtlWC16StringNumChars(pwszNewPath);

    status = RTL_ALLOCATE(
        &pRenameInfo,
        FILE_RENAME_INFORMATION,
        sizeof(*pRenameInfo) + (newPathLength + 1) * sizeof(WCHAR));
    BAIL_ON_NT_STATUS(status);

    pRenameInfo->ReplaceIfExists = TRUE;
    pRenameInfo->RootDirectory = NULL;
    pRenameInfo->FileNameLength = newPathLength * sizeof(WCHAR);
    
    memcpy(pRenameInfo->FileName, pwszNewPath, newPathLength * sizeof(WCHAR));

    status = LwIoFuseGetNtFilename(
        pFuseContext,
        pszOldPath,
        &filename);
    BAIL_ON_NT_STATUS(status);
    
    status = LwNtCreateFile(
        &handle,                 /* File handle */
        NULL,                    /* Async control block */
        &ioStatus,               /* IO status block */
        &filename,               /* Filename */
        NULL,                    /* Security descriptor */
        NULL,                    /* Security QOS */
        DELETE,                  /* Desired access mask */
        0,                       /* Allocation size */
        0,                       /* File attributes */
        FILE_SHARE_READ |
        FILE_SHARE_WRITE |
        FILE_SHARE_DELETE,       /* Share access */
        FILE_OPEN,               /* Create disposition */
        0,                       /* Create options */
        NULL,                    /* EA buffer */
        0,                       /* EA length */
        NULL,                    /* ECP list */
        NULL);
    BAIL_ON_NT_STATUS(status);
    
    status = LwNtSetInformationFile(
        handle, /* File handle */
        NULL, /* Async control block */
        &ioStatus, /* IO status block */
        pRenameInfo, /* File information */
        sizeof(*pRenameInfo) + (newPathLength + 1) * sizeof(WCHAR), /* File information size */
        FileRenameInformation); /* Information class */
    BAIL_ON_NT_STATUS(status);
    
cleanup:

    if (handle)
    {
        LwNtCloseFile(handle);
    }

    RTL_UNICODE_STRING_FREE(&filename.Name);
    RTL_FREE(&pwszNewPath);
    RTL_FREE(&pRenameInfo);

    return status;

error:

    goto cleanup;
}
Пример #4
0
NTSTATUS
LwIoFuseCreate(
    const char* pszPath,
    mode_t mode,
    struct fuse_file_info* pFileInfo
    )
{
    NTSTATUS status = STATUS_SUCCESS;
    IO_STATUS_BLOCK ioStatus = {0};
    IO_FILE_HANDLE handle = NULL;
    PIO_FUSE_CONTEXT pFuseContext = NULL;
    IO_FILE_NAME filename = {0};

    /* We only support creating regular files */
    if (!S_ISREG(mode))
    {
        status = STATUS_NOT_SUPPORTED;
        BAIL_ON_NT_STATUS(status);
    }

    pFuseContext = LwIoFuseGetContext();
    
    status = LwIoFuseGetNtFilename(
        pFuseContext,
        pszPath,
        &filename);
    BAIL_ON_NT_STATUS(status);
    
    status = LwNtCreateFile(
        &handle,                 /* File handle */
        NULL,                    /* Async control block */
        &ioStatus,               /* IO status block */
        &filename,               /* Filename */
        NULL,                    /* Security descriptor */
        NULL,                    /* Security QOS */
        FILE_WRITE_DATA,         /* Desired access mask */
        0,                       /* Allocation size */
        0,                       /* File attributes */
        FILE_SHARE_READ |
        FILE_SHARE_WRITE |
        FILE_SHARE_DELETE,       /* Share access */
        FILE_CREATE,             /* Create disposition */
        FILE_NON_DIRECTORY_FILE, /* Create options */
        NULL,                    /* EA buffer */
        0,                       /* EA length */
        NULL,                    /* ECP list */
        NULL);
    BAIL_ON_NT_STATUS(status);

    pFileInfo->fh = NT_TO_FUSE_FH(handle);

cleanup:

    RTL_UNICODE_STRING_FREE(&filename.Name);

    return status;

error:

    if (handle)
    {
        LwNtCloseFile(handle);
    }

    goto cleanup;
}
Пример #5
0
NTSTATUS
LwIoFuseTruncate(
    const char* pszPath,
    off_t size
    )
{
    NTSTATUS status = STATUS_SUCCESS;
    IO_STATUS_BLOCK ioStatus = {0};
    IO_FILE_HANDLE handle = NULL;
    PIO_FUSE_CONTEXT pFuseContext = NULL;
    FILE_END_OF_FILE_INFORMATION endOfFileInfo = {0};
    IO_FILE_NAME filename = {0};

    endOfFileInfo.EndOfFile = (LONG64) size;

    pFuseContext = LwIoFuseGetContext();

    status = LwIoFuseGetNtFilename(
        pFuseContext,
        pszPath,
        &filename);
    BAIL_ON_NT_STATUS(status);

    status = LwNtCreateFile(
        &handle,                 /* File handle */
        NULL,                    /* Async control block */
        &ioStatus,               /* IO status block */
        &filename,               /* Filename */
        NULL,                    /* Security descriptor */
        NULL,                    /* Security QOS */
        FILE_WRITE_DATA,         /* Desired access mask */
        0,                       /* Allocation size */
        0,                       /* File attributes */
        FILE_SHARE_READ |
        FILE_SHARE_WRITE |
        FILE_SHARE_DELETE,       /* Share access */
        FILE_OPEN,               /* Create disposition */
        FILE_NON_DIRECTORY_FILE, /* Create options */
        NULL,                    /* EA buffer */
        0,                       /* EA length */
        NULL,                     /* ECP list */
        NULL);
    BAIL_ON_NT_STATUS(status);

    status = LwNtSetInformationFile(
        handle, /* File handle */
        NULL, /* Async control block */
        &ioStatus, /* IO status block */
        &endOfFileInfo, /* File information */
        sizeof(endOfFileInfo), /* File information size */
        FileEndOfFileInformation); /* Information class */
    BAIL_ON_NT_STATUS(status);

cleanup:

    if (handle)
    {
        LwNtCloseFile(handle);
    }

    RTL_UNICODE_STRING_FREE(&filename.Name);

    return status;

error:

    goto cleanup;
}