Platform SDK: Hardware

FSCTL_RECALL_FILE

The FSCTL_RECALL_FILE operation recalls a file from storage media managed by Remote Storage, the hierarchical storage management software in Windows 2000.

To perform this operation, call the DeviceIoControl function with the following parameters.

BOOL DeviceIoControl(
  (HANDLE) hDevice,            // handle to file or directory
  FSCTL_RECALL_FILE,           // dwIoControlCode operation
  NULL,                        // lpInBuffer; must be NULL
  0,                           // nInBufferSize; must be zero
  NULL,                        // lpOutBuffer; must be NULL
  0,                           // nOutBufferSize; must be zero
  (LPDWORD) lpBytesReturned,   // number of bytes returned
  (LPOVERLAPPED) lpOverlapped  // OVERLAPPED structure
);

Parameters

hDevice
[in] Handle to the file whose data is to be recalled from remote storage media. The handle must be opened with read access, write access, or both. To obtain a device handle, call the CreateFile function.
dwIoControlCode
[in] Control code for the operation. This value identifies the specific operation to be performed and the type of device on which to perform it. Use FSCTL_RECALL_FILE for this operation.
lpInBuffer
[in] Pointer to the input buffer. Not used; must be NULL.
nInBufferSize
[in] Size, in bytes, of the input buffer. Not used; must be zero.
lpOutBuffer
[out] Pointer to the output buffer. Not used; must be NULL.
nOutBufferSize
[in] Size, in bytes, of the output buffer. Not used; must be zero.
lpBytesReturned
[out] Pointer to a variable that receives the actual count of bytes returned by the function in the output buffer. The lpBytesReturned value is meaningless because there is no output buffer. With an asynchronous call, the programmer must provide a non-NULL pointer to a valid value.

If lpOverlapped is NULL (nonoverlapped I/O), lpBytesReturned is used internally and cannot be NULL.

If lpOverlapped is not NULL (overlapped I/O), lpBytesReturned can be NULL.

lpOverlapped
[in] Pointer to an OVERLAPPED structure.

If hDevice was opened with the FILE_FLAG_OVERLAPPED flag, lpOverlapped must point to a valid OVERLAPPED structure. In this case, DeviceIoControl is performed as an overlapped (asynchronous) operation. If the device was opened with the FILE_FLAG_OVERLAPPED flag and lpOverlapped is NULL, the function fails in unpredictable ways.

If hDevice was opened without specifying the FILE_FLAG_OVERLAPPED flag, lpOverlapped is ignored and the DeviceIoControl function does not return until the operation has been completed, or until an error occurs.

Return Values

If the operation succeeds, DeviceIoControl returns a nonzero value.

If the operation fails, DeviceIoControl returns zero. To get extended error information, call GetLastError.

Remarks

FSCTL_RECALL_FILE recovers a file from storage, such as tape, that is managed by Remote Storage. If the file is already cached locally, this operation has no effect. Similarly, if the file has not been moved to remote storage, this operation has no effect.

FSCTL_RECALL_FILE operates only on systems on which Remote Storage is installed. Where Remote Storage is not installed, the operation fails, and GetLastError returns the error code ERROR_INVALID_FUNCTION.

Directories cannot be moved to remote storage. Calling FSCTL_RECALL_FILE for a directory fails, and GetLastError returns the error code ERROR_INVALID_HANDLE.

Files stored on media managed by Remote Storage are usually recalled when an application attempts to make the first access to data. An application that opens a file without immediately accessing the data can speed up the first access by using FSCTL_RECALL_FILE immediately after opening the file. However, you should avoid indiscriminate recall of files that your application will not touch.

You need not test a file's attributes for the flag FILE_ATTRIBUTE_OFFLINE with the function GetFileAttributes before calling FSCTL_RECALL_FILE. A test is unnecessary because an online file is not affected by this operation. However, any operating system call takes processor time. To conserve processor time, call GetFileAttributes to check file attributes to determine if FSCTL_RECALL_FILE is necessary.

For the implications of overlapped I/O on this operation, see the Remarks section of the DeviceIoControl topic.

The following short program, Recall.c, shows a command-line utility that recalls one or more files indicated on the command line from remote storage.

/*++
Copyright (c) 1999  Microsoft Corporation

Module Name:
    Recall.c
    Simple utility to recall files managed by Remote Storage
*/

#include <windows.h>
#include <malloc.h>
#include <stdio.h>
#include <winioctl.h>

DWORD
RecallFile(PUCHAR FileName);

int _cdecl
main(int argc, char *argv[])
{
  HANDLE file;
  LONG   i;
  DWORD  nbytes;

  if (argc < 2) {
    printf("Usage: recall <file-name1> <file-name2> ...\n");
    return 1;
  }

  for (i = 1; i < argc; i++) {
    (void) RecallFile(argv[i]);
  }
  return 0;
}

DWORD
RecallFile(IN PUCHAR FileName)
  /*++
Routine Description
    Recalls the file with the supplied path.
Arguments
    FileName - Path of the file to be recalled
Return Value
    0                   - Recall is successful.
    Any other value     - Error code for the operation.

--*/

{
  HANDLE fileHandle;
  DWORD  nbytes;
  DWORD  errorCode = 0;

  fileHandle = CreateFile(FileName,
                          GENERIC_READ,
                          FILE_SHARE_READ,
                          NULL,
                          OPEN_EXISTING,
                          FILE_ATTRIBUTE_NORMAL,
                          NULL);
  if (fileHandle == INVALID_HANDLE_VALUE) {
    errorCode = GetLastError();
    printf("Couldn't open file %s: error %x\n", FileName, errorCode);
    return errorCode;
  }

  if (!DeviceIoControl(fileHandle,
                       FSCTL_RECALL_FILE,
                       NULL,
                       0,
                       NULL,
                       0,
                       &nbytes,
                       NULL)) {

    errorCode = GetLastError();
    printf("Couldn't recall file %s: error %x\n", FileName, errorCode);
  }
  CloseHandle(fileHandle);
  return errorCode;
}

Requirements

  Windows NT/2000: Requires Windows 2000.
  Windows 95/98: Unsupported.
  Header: Declared in Winioctl.h.

See Also

Device Input and Output Overview, Device Input and Output Control Codes, CreateFile, DeviceIoControl, GetFileAttributes, OVERLAPPED