VirtualBox

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

Last change on this file since 85121 was 85121, checked in by vboxsync, 4 years ago

iprt/cdefs.h: Refactored the typedef use of DECLCALLBACK as well as DECLCALLBACKMEMBER to wrap the whole expression, similar to the DECLR?CALLBACKMEMBER macros. This allows adding a throw() at the end when compiling with the VC++ compiler to indicate that the callbacks won't throw anything, so we can stop supressing the C5039 warning about passing functions that can potential throw C++ exceptions to extern C code that can't necessarily cope with such (unwind,++). Introduced a few _EX variations that allows specifying different/no calling convention too, as that's handy when dynamically resolving host APIs. Fixed numerous places missing DECLCALLBACK and such. Left two angry @todos regarding use of CreateThread. bugref:9794

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