VirtualBox

source: vbox/trunk/src/VBox/Runtime/include/internal/dir.h@ 96781

Last change on this file since 96781 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 7.3 KB
Line 
1/* $Id: dir.h 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 * IPRT - Internal Header for RTDir.
4 */
5
6/*
7 * Copyright (C) 2006-2022 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
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 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
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
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.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37#ifndef IPRT_INCLUDED_INTERNAL_dir_h
38#define IPRT_INCLUDED_INTERNAL_dir_h
39#ifndef RT_WITHOUT_PRAGMA_ONCE
40# pragma once
41#endif
42
43#include <iprt/cdefs.h>
44#include <iprt/types.h>
45#include "internal/magics.h"
46
47
48/** Pointer to the data behind an open directory handle. */
49typedef struct RTDIRINTERNAL *PRTDIRINTERNAL;
50
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 */
59typedef DECLCALLBACKTYPE(bool, FNRTDIRFILTER,(PRTDIRINTERNAL pDir, const char *pszName));
60/** Pointer to a filter function. */
61typedef FNRTDIRFILTER *PFNRTDIRFILTER;
62
63
64/**
65 * Open directory.
66 */
67typedef struct RTDIRINTERNAL
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. */
84 size_t cchFilter;
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. */
90 size_t cchPath;
91 /** Pointer to the converted filename.
92 * This can be NULL. */
93#ifdef RT_OS_WINDOWS
94 char *pszName;
95#else
96 char const *pszName;
97#endif
98 /** The length of the converted filename. */
99 size_t cchName;
100 /** The size of this structure. */
101 size_t cbSelf;
102 /** The RTDIR_F_XXX flags passed to RTDirOpenFiltered */
103 uint32_t fFlags;
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;
109 /** Set to indicate that the Data member contains unread data. */
110 bool fDataUnread;
111
112#ifndef RTDIR_AGNOSTIC
113# ifdef RT_OS_WINDOWS
114 /** Set by RTDirRewind. */
115 bool fRestartScan;
116 /** Handle to the opened directory search. */
117 HANDLE hDir;
118# ifndef RTNT_USE_NATIVE_NT
119 /** Find data buffer.
120 * fDataUnread indicates valid data. */
121 WIN32_FIND_DATAW Data;
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;
152 /** The device number for the directory (serial number). */
153 RTDEV uDirDev;
154# endif
155# else /* 'POSIX': */
156 /** What opendir() returned. */
157 DIR *pDir;
158 /** Find data buffer.
159 * fDataUnread indicates valid data. */
160 struct dirent Data;
161# endif
162#endif
163} RTDIRINTERNAL;
164
165
166
167/**
168 * Validates a directory handle.
169 * @returns true if valid.
170 * @returns false if valid after having bitched about it first.
171 */
172DECLINLINE(bool) rtDirValidHandle(PRTDIRINTERNAL pDir)
173{
174 AssertPtrReturn(pDir, false);
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.
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.
189 * @param pvNativeRelative The native relative path. NULL if absolute or
190 * we're to use (consume) hRelativeDir.
191 */
192int rtDirNativeOpen(PRTDIRINTERNAL pDir, uintptr_t hRelativeDir, void *pvNativeRelative);
193
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 */
200size_t rtDirNativeGetStructSize(const char *pszPath);
201
202
203DECLHIDDEN(int) rtDirOpenRelativeOrHandle(RTDIR *phDir, const char *pszRelativeAndFilter, RTDIRFILTER enmFilter,
204 uint32_t fFlags, uintptr_t hRelativeDir, void *pvNativeRelative);
205
206#endif /* !IPRT_INCLUDED_INTERNAL_dir_h */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette