FILE_NETWORK_PHYSICAL_NAME_INFORMATION struttura (ntifs.h)

La struttura FILE_NETWORK_PHYSICAL_NAME_INFORMATION contiene il nome percorso fisico UNC completo per un file o una directory in una condivisione file remota.

Sintassi

typedef struct _FILE_NETWORK_PHYSICAL_NAME_INFORMATION {
  ULONG FileNameLength;
  WCHAR FileName[1];
} FILE_NETWORK_PHYSICAL_NAME_INFORMATION, *PFILE_NETWORK_PHYSICAL_NAME_INFORMATION;

Members

FileNameLength

Lunghezza, in byte, del nome fisico in FileName.

FileName[1]

Percorso UNC completo della condivisione file di rete della destinazione.

Commenti

La struttura FILE_NETWORK_PHYSICAL_NAME_INFORMATION viene usata per recuperare le informazioni sul nome fisico di rete per un file. Questa operazione può essere eseguita in uno dei modi seguenti:

  • Chiamare ZwQueryInformationFile, passando FileNetworkPhysicalNameInformation come valore di FileInformationClass e passando un buffer allocato del chiamante formattato come struttura FILE_NETWORK_PHYSICAL_NAME_INFORMATION per il valore di FileInformation. Il parametro FileHandle specifica la destinazione del file per le informazioni sul nome.

    I minifilter del file system devono usare FltQueryInformationFile per eseguire query sulle informazioni sul nome fisico.

  • Creare un'IRP con codice di funzione principale IRP_MJ_QUERY_INFORMATION.

FileName di FILE_NETWORK_PHYSICAL_NAME_INFORMATION conterrà il nome di rete dell'handle di destinazione file passato a ZwQueryInformationFile. Il nome della rete fisica restituito è nel formato di ; X:\Server\ShareName\Dir1\Dir2...\FileName.

Se il nome fisico è più lungo del set di lunghezza in FileNameLength, STATUS_BUFFER_OVERFLOW viene restituito da ZwQueryInformationFile e FileNameLength viene aggiornato con il numero di byte necessari per contenere l'intera stringa di nome. Il numero di caratteri nel nome è FileNameLength / sizeof(WCHAR).

Nel caso in cui un file venga memorizzato nella cache in un client e il relativo nome fisico di rete viene eseguito una query, il percorso restituito in FileName potrebbe non essere noto alla cache client. Il sistema di memorizzazione nella cache potrebbe non associare il file memorizzato nella cache al file aperto usando il percorso restituito in FileName.

Di seguito è riportato un esempio di query sulle informazioni sul nome fisico di rete di una destinazione file usando ZwQueryInformationFile.

NTSTATUS GetPhysicalNetworkName(HANDLE Target, WCHAR *NetworkName, ULONG MaxNetworkNameLength)
{
    NTSTATUS Status;
    IO_STATUS_BLOCK IoStatus;
    ULONG NameInfoLength;
    PFILE_NETWORK_PHYSICAL_NAME_INFORMATION NetFileNameInfo = NULL;

    if ( MaxNetworkNameLength < sizeof(WCHAR) )
    {
        return STATUS_NAME_TOO_LONG;
    }
    if (NetworkName != NULL)
    {
        return STATUS_INVALID_PARAMETER;
    }

    NetworkName[0] = (WCHAR)0;  // initially terminate the output string;

    // set the initial name length, the one WCHAR in NetFileNameInfo.FileName is reserved for the terminating NULL
    NameInfoLength = sizeof(PFILE_NETWORK_PHYSICAL_NAME_INFORMATION) +
                     min(1024, MaxNetworkNameLength - sizeof(WCHAR));
    NetFileNameInfo = (PFILE_NETWORK_PHYSICAL_NAME_INFORMATION)ExAllocatePool(PagedPool, NameInfoLength);

    if (NetFileNameInfo == NULL)
    {
        Status = STATUS_NO_MEMORY;
    }
    else
    {
        Status = ZwQueryInformationFile(Target,
                                        &IoStatus,
                                        NetFileNameInfo,
                                        NameInfoLength,
                                        FileNetworkPhysicalNameInformation);
    }
    if (Status == STATUS_BUFFER_OVERFLOW)
    {
        if (NetFileNameInfo->FileNameLength <= (MaxNetworkNameLength - sizeof(WCHAR)))
        {
            NameInfoLength += sizeof(PFILE_NETWORK_PHYSICAL_NAME_INFORMATION) + NetFileNameInfo->FileNameLength;
            ExFreePool(NetFileNameInfo);
            NetFileNameInfo = (PFILE_NETWORK_PHYSICAL_NAME_INFORMATION)ExAllocatePool(PagedPool, NameInfoLength);
            if (NetFileNameInfo == NULL)
            {
                Status = STATUS_NO_MEMORY;
            }
            else
            {
                Status = ZwQueryInformationFile(Target,
                                                &IoStatus,
                                                NetFileNameInfo,
                                                NameInfoLength,
                                                FileNetworkPhysicalNameInformation);
            }
        }
    }
    if (NetFileNameInfo != NULL)
    {
        if (NT_SUCCESS(Status))
        {
            NameInfoLength = min(NameInfoLength, NetFileNameInfo->FileNameLength);
            RtlCopyMemory(NetworkName, NetFileNameInfo->FileName, NameInfoLength);
            NetworkName[NameInfoLength / sizeof(WCHAR)] = (WCHAR)0;
        }
        ExFreePool(NetFileNameInfo);
    }

    return Status;
}

Requisiti

Requisito Valore
Intestazione ntifs.h (include Ntifs.h, Fltkernel.h)

Vedi anche

FILE_INFORMATION_CLASS

IRP_MJ_QUERY_INFORMATION

ZwQueryInformationFile