[1] | 1 | /* $Id: dir.h 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[8245] | 3 | * IPRT - Internal Header for RTDir.
|
---|
[1] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[1] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
[5999] | 11 | *
|
---|
[96407] | 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
[5999] | 25 | * The contents of this file may alternatively be used under the terms
|
---|
| 26 | * of the Common Development and Distribution License Version 1.0
|
---|
[96407] | 27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
| 28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
[5999] | 29 | * CDDL are applicable instead of those of the GPL.
|
---|
| 30 | *
|
---|
| 31 | * You may elect to license modified versions of this file under the
|
---|
| 32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
[96407] | 33 | *
|
---|
| 34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
[1] | 35 | */
|
---|
| 36 |
|
---|
[76559] | 37 | #ifndef IPRT_INCLUDED_INTERNAL_dir_h
|
---|
| 38 | #define IPRT_INCLUDED_INTERNAL_dir_h
|
---|
[76513] | 39 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
| 40 | # pragma once
|
---|
| 41 | #endif
|
---|
[1] | 42 |
|
---|
| 43 | #include <iprt/cdefs.h>
|
---|
| 44 | #include <iprt/types.h>
|
---|
[1816] | 45 | #include "internal/magics.h"
|
---|
[1] | 46 |
|
---|
| 47 |
|
---|
[69753] | 48 | /** Pointer to the data behind an open directory handle. */
|
---|
| 49 | typedef struct RTDIRINTERNAL *PRTDIRINTERNAL;
|
---|
| 50 |
|
---|
[1] | 51 | /**
|
---|
| 52 | * Filter a the filename in the against a filter.
|
---|
| 53 | *
|
---|
| 54 | * @returns true if the name matches the filter.
|
---|
| 55 | * @returns false if the name doesn't match filter.
|
---|
| 56 | * @param pDir The directory handle.
|
---|
| 57 | * @param pszName The path to match to the filter.
|
---|
| 58 | */
|
---|
[85121] | 59 | typedef DECLCALLBACKTYPE(bool, FNRTDIRFILTER,(PRTDIRINTERNAL pDir, const char *pszName));
|
---|
[1] | 60 | /** Pointer to a filter function. */
|
---|
| 61 | typedef FNRTDIRFILTER *PFNRTDIRFILTER;
|
---|
| 62 |
|
---|
| 63 |
|
---|
| 64 | /**
|
---|
| 65 | * Open directory.
|
---|
| 66 | */
|
---|
[69753] | 67 | typedef struct RTDIRINTERNAL
|
---|
[1] | 68 | {
|
---|
| 69 | /** Magic value, RTDIR_MAGIC. */
|
---|
| 70 | uint32_t u32Magic;
|
---|
| 71 | /** The type of filter that's to be applied to the directory listing. */
|
---|
| 72 | RTDIRFILTER enmFilter;
|
---|
| 73 | /** The filter function. */
|
---|
| 74 | PFNRTDIRFILTER pfnFilter;
|
---|
| 75 | /** The filter Code Point string.
|
---|
| 76 | * This is allocated in the same block as this structure. */
|
---|
| 77 | PRTUNICP puszFilter;
|
---|
| 78 | /** The number of Code Points in the filter string. */
|
---|
| 79 | size_t cucFilter;
|
---|
| 80 | /** The filter string.
|
---|
| 81 | * This is allocated in the same block as this structure, thus the const. */
|
---|
| 82 | const char *pszFilter;
|
---|
| 83 | /** The length of the filter string. */
|
---|
[14059] | 84 | size_t cchFilter;
|
---|
[1] | 85 | /** Normalized path to the directory including a trailing slash.
|
---|
| 86 | * We keep this around so we can query more information if required (posix).
|
---|
| 87 | * This is allocated in the same block as this structure, thus the const. */
|
---|
| 88 | const char *pszPath;
|
---|
| 89 | /** The length of the path. */
|
---|
[14059] | 90 | size_t cchPath;
|
---|
[1] | 91 | /** Pointer to the converted filename.
|
---|
| 92 | * This can be NULL. */
|
---|
[28917] | 93 | #ifdef RT_OS_WINDOWS
|
---|
| 94 | char *pszName;
|
---|
| 95 | #else
|
---|
[28915] | 96 | char const *pszName;
|
---|
[28917] | 97 | #endif
|
---|
[1] | 98 | /** The length of the converted filename. */
|
---|
[14059] | 99 | size_t cchName;
|
---|
[47535] | 100 | /** The size of this structure. */
|
---|
| 101 | size_t cbSelf;
|
---|
[69674] | 102 | /** The RTDIR_F_XXX flags passed to RTDirOpenFiltered */
|
---|
| 103 | uint32_t fFlags;
|
---|
[70890] | 104 | /** Set if the specified path included a directory slash or if enmFilter is not RTDIRFILTER_NONE.
|
---|
| 105 | * This is relevant for how to interpret the RTDIR_F_NO_FOLLOW flag, as it won't
|
---|
| 106 | * have any effect if the specified path ends with a slash on posix systems. We
|
---|
| 107 | * implement that on the other systems too, for consistency. */
|
---|
| 108 | bool fDirSlash;
|
---|
[69674] | 109 | /** Set to indicate that the Data member contains unread data. */
|
---|
| 110 | bool fDataUnread;
|
---|
[1] | 111 |
|
---|
[47535] | 112 | #ifndef RTDIR_AGNOSTIC
|
---|
| 113 | # ifdef RT_OS_WINDOWS
|
---|
[75652] | 114 | /** Set by RTDirRewind. */
|
---|
| 115 | bool fRestartScan;
|
---|
[1] | 116 | /** Handle to the opened directory search. */
|
---|
| 117 | HANDLE hDir;
|
---|
[49150] | 118 | # ifndef RTNT_USE_NATIVE_NT
|
---|
[1] | 119 | /** Find data buffer.
|
---|
| 120 | * fDataUnread indicates valid data. */
|
---|
| 121 | WIN32_FIND_DATAW Data;
|
---|
[47535] | 122 | # else
|
---|
| 123 | /** The size of the name buffer pszName points to. */
|
---|
| 124 | size_t cbNameAlloc;
|
---|
| 125 | /** NT filter string. */
|
---|
| 126 | UNICODE_STRING NtFilterStr;
|
---|
| 127 | /** Pointer to NtFilterStr if applicable, otherwise NULL. */
|
---|
| 128 | PUNICODE_STRING pNtFilterStr;
|
---|
| 129 | /** The information class we're using. */
|
---|
| 130 | FILE_INFORMATION_CLASS enmInfoClass;
|
---|
| 131 | /** Object directory context data. */
|
---|
| 132 | ULONG uObjDirCtx;
|
---|
| 133 | /** Pointer to the current data entry in the buffer. */
|
---|
| 134 | union
|
---|
| 135 | {
|
---|
| 136 | /** Both file names, no file ID. */
|
---|
| 137 | PFILE_BOTH_DIR_INFORMATION pBoth;
|
---|
| 138 | /** Both file names with file ID. */
|
---|
| 139 | PFILE_ID_BOTH_DIR_INFORMATION pBothId;
|
---|
| 140 | /** Object directory info. */
|
---|
| 141 | POBJECT_DIRECTORY_INFORMATION pObjDir;
|
---|
| 142 | /** Unsigned view. */
|
---|
| 143 | uintptr_t u;
|
---|
| 144 | } uCurData;
|
---|
| 145 | /** The amount of valid data in the buffer. */
|
---|
| 146 | uint32_t cbBuffer;
|
---|
| 147 | /** The allocate buffer size. */
|
---|
| 148 | uint32_t cbBufferAlloc;
|
---|
| 149 | /** Find data buffer containing multiple directory entries.
|
---|
| 150 | * fDataUnread indicates valid data. */
|
---|
| 151 | uint8_t *pabBuffer;
|
---|
[64623] | 152 | /** The device number for the directory (serial number). */
|
---|
| 153 | RTDEV uDirDev;
|
---|
[47535] | 154 | # endif
|
---|
| 155 | # else /* 'POSIX': */
|
---|
[1] | 156 | /** What opendir() returned. */
|
---|
| 157 | DIR *pDir;
|
---|
| 158 | /** Find data buffer.
|
---|
| 159 | * fDataUnread indicates valid data. */
|
---|
| 160 | struct dirent Data;
|
---|
[47535] | 161 | # endif
|
---|
[1] | 162 | #endif
|
---|
[69753] | 163 | } RTDIRINTERNAL;
|
---|
[1] | 164 |
|
---|
| 165 |
|
---|
[69753] | 166 |
|
---|
[1] | 167 | /**
|
---|
| 168 | * Validates a directory handle.
|
---|
| 169 | * @returns true if valid.
|
---|
| 170 | * @returns false if valid after having bitched about it first.
|
---|
| 171 | */
|
---|
[69753] | 172 | DECLINLINE(bool) rtDirValidHandle(PRTDIRINTERNAL pDir)
|
---|
[1] | 173 | {
|
---|
[90789] | 174 | AssertPtrReturn(pDir, false);
|
---|
[1] | 175 | AssertMsgReturn(pDir->u32Magic == RTDIR_MAGIC, ("%#RX32\n", pDir->u32Magic), false);
|
---|
| 176 | return true;
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 |
|
---|
| 180 | /**
|
---|
| 181 | * Initialize the OS specific part of the handle and open the directory.
|
---|
| 182 | * Called by rtDirOpenCommon().
|
---|
| 183 | *
|
---|
| 184 | * @returns IPRT status code.
|
---|
[69691] | 185 | * @param pDir The directory to open. The pszPath member contains the
|
---|
| 186 | * path to the directory.
|
---|
| 187 | * @param hRelativeDir The directory @a pvNativeRelative is relative,
|
---|
| 188 | * ~(uintptr_t)0 if absolute.
|
---|
[69716] | 189 | * @param pvNativeRelative The native relative path. NULL if absolute or
|
---|
| 190 | * we're to use (consume) hRelativeDir.
|
---|
[1] | 191 | */
|
---|
[78050] | 192 | int rtDirNativeOpen(PRTDIRINTERNAL pDir, uintptr_t hRelativeDir, void *pvNativeRelative);
|
---|
[1] | 193 |
|
---|
[47535] | 194 | /**
|
---|
| 195 | * Returns the size of the directory structure.
|
---|
| 196 | *
|
---|
| 197 | * @returns The size in bytes.
|
---|
| 198 | * @param pszPath The path to the directory we're about to open.
|
---|
| 199 | */
|
---|
| 200 | size_t rtDirNativeGetStructSize(const char *pszPath);
|
---|
| 201 |
|
---|
[69691] | 202 |
|
---|
[69753] | 203 | DECLHIDDEN(int) rtDirOpenRelativeOrHandle(RTDIR *phDir, const char *pszRelativeAndFilter, RTDIRFILTER enmFilter,
|
---|
| 204 | uint32_t fFlags, uintptr_t hRelativeDir, void *pvNativeRelative);
|
---|
[69691] | 205 |
|
---|
[76585] | 206 | #endif /* !IPRT_INCLUDED_INTERNAL_dir_h */
|
---|