Condividi tramite


struttura FILE_NETWORK_PHYSICAL_NAME_INFORMATION (ntifs.h)

La struttura FILE_NETWORK_PHYSICAL_NAME_INFORMATION contiene il 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;

Membri

FileNameLength

Lunghezza, in byte, del nome fisico in NomeFile.

FileName[1]

Percorso UNC completo della condivisione file di rete della destinazione.

Osservazioni

La struttura FILE_NETWORK_PHYSICAL_NAME_INFORMATION viene utilizzata 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 dal 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 minifiltri del file system devono usare FltQueryInformationFile per eseguire query sulle informazioni sul nome fisico.

  • Creare un IRP con il codice della funzione principale IRP_MJ_QUERY_INFORMATION.

Il 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 è maggiore della lunghezza impostata in FileNameLength, STATUS_BUFFER_OVERFLOW viene restituito da ZwQueryInformationFile e FileNameLength viene aggiornato con il numero di byte necessari per contenere l'intera stringa del 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 venga sottoposto a query, il percorso restituito in NomeFile potrebbe non essere noto alla cache del 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;
}

Fabbisogno

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

Vedere anche

FILE_INFORMATION_CLASS

IRP_MJ_QUERY_INFORMATION

ZwQueryInformationFile