VirtualBox

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

Last change on this file since 76274 was 75652, checked in by vboxsync, 6 years ago

IPRT/dir: Adding RTDirRewind for use with shared folders.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 7.1 KB
Line 
1/* $Id: dir.h 75652 2018-11-21 21:00:31Z vboxsync $ */
2/** @file
3 * IPRT - Internal Header for RTDir.
4 */
5
6/*
7 * Copyright (C) 2006-2017 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 ___internal_dir_h
28#define ___internal_dir_h
29
30#include <iprt/cdefs.h>
31#include <iprt/types.h>
32#include "internal/magics.h"
33
34
35/** Pointer to the data behind an open directory handle. */
36typedef struct RTDIRINTERNAL *PRTDIRINTERNAL;
37
38/**
39 * Filter a the filename in the against a filter.
40 *
41 * @returns true if the name matches the filter.
42 * @returns false if the name doesn't match filter.
43 * @param pDir The directory handle.
44 * @param pszName The path to match to the filter.
45 */
46typedef DECLCALLBACK(bool) FNRTDIRFILTER(PRTDIRINTERNAL pDir, const char *pszName);
47/** Pointer to a filter function. */
48typedef FNRTDIRFILTER *PFNRTDIRFILTER;
49
50
51/**
52 * Open directory.
53 */
54typedef struct RTDIRINTERNAL
55{
56 /** Magic value, RTDIR_MAGIC. */
57 uint32_t u32Magic;
58 /** The type of filter that's to be applied to the directory listing. */
59 RTDIRFILTER enmFilter;
60 /** The filter function. */
61 PFNRTDIRFILTER pfnFilter;
62 /** The filter Code Point string.
63 * This is allocated in the same block as this structure. */
64 PRTUNICP puszFilter;
65 /** The number of Code Points in the filter string. */
66 size_t cucFilter;
67 /** The filter string.
68 * This is allocated in the same block as this structure, thus the const. */
69 const char *pszFilter;
70 /** The length of the filter string. */
71 size_t cchFilter;
72 /** Normalized path to the directory including a trailing slash.
73 * We keep this around so we can query more information if required (posix).
74 * This is allocated in the same block as this structure, thus the const. */
75 const char *pszPath;
76 /** The length of the path. */
77 size_t cchPath;
78 /** Pointer to the converted filename.
79 * This can be NULL. */
80#ifdef RT_OS_WINDOWS
81 char *pszName;
82#else
83 char const *pszName;
84#endif
85 /** The length of the converted filename. */
86 size_t cchName;
87 /** The size of this structure. */
88 size_t cbSelf;
89 /** The RTDIR_F_XXX flags passed to RTDirOpenFiltered */
90 uint32_t fFlags;
91 /** Set if the specified path included a directory slash or if enmFilter is not RTDIRFILTER_NONE.
92 * This is relevant for how to interpret the RTDIR_F_NO_FOLLOW flag, as it won't
93 * have any effect if the specified path ends with a slash on posix systems. We
94 * implement that on the other systems too, for consistency. */
95 bool fDirSlash;
96 /** Set to indicate that the Data member contains unread data. */
97 bool fDataUnread;
98
99#ifndef RTDIR_AGNOSTIC
100# ifdef RT_OS_WINDOWS
101 /** Set by RTDirRewind. */
102 bool fRestartScan;
103 /** Handle to the opened directory search. */
104 HANDLE hDir;
105# ifndef RTNT_USE_NATIVE_NT
106 /** Find data buffer.
107 * fDataUnread indicates valid data. */
108 WIN32_FIND_DATAW Data;
109# else
110 /** The size of the name buffer pszName points to. */
111 size_t cbNameAlloc;
112 /** NT filter string. */
113 UNICODE_STRING NtFilterStr;
114 /** Pointer to NtFilterStr if applicable, otherwise NULL. */
115 PUNICODE_STRING pNtFilterStr;
116 /** The information class we're using. */
117 FILE_INFORMATION_CLASS enmInfoClass;
118 /** Object directory context data. */
119 ULONG uObjDirCtx;
120 /** Pointer to the current data entry in the buffer. */
121 union
122 {
123 /** Both file names, no file ID. */
124 PFILE_BOTH_DIR_INFORMATION pBoth;
125 /** Both file names with file ID. */
126 PFILE_ID_BOTH_DIR_INFORMATION pBothId;
127 /** Object directory info. */
128 POBJECT_DIRECTORY_INFORMATION pObjDir;
129 /** Unsigned view. */
130 uintptr_t u;
131 } uCurData;
132 /** The amount of valid data in the buffer. */
133 uint32_t cbBuffer;
134 /** The allocate buffer size. */
135 uint32_t cbBufferAlloc;
136 /** Find data buffer containing multiple directory entries.
137 * fDataUnread indicates valid data. */
138 uint8_t *pabBuffer;
139 /** The device number for the directory (serial number). */
140 RTDEV uDirDev;
141# endif
142# else /* 'POSIX': */
143 /** What opendir() returned. */
144 DIR *pDir;
145 /** Find data buffer.
146 * fDataUnread indicates valid data. */
147 struct dirent Data;
148# endif
149#endif
150} RTDIRINTERNAL;
151
152
153
154/**
155 * Validates a directory handle.
156 * @returns true if valid.
157 * @returns false if valid after having bitched about it first.
158 */
159DECLINLINE(bool) rtDirValidHandle(PRTDIRINTERNAL pDir)
160{
161 AssertMsgReturn(VALID_PTR(pDir), ("%p\n", pDir), false);
162 AssertMsgReturn(pDir->u32Magic == RTDIR_MAGIC, ("%#RX32\n", pDir->u32Magic), false);
163 return true;
164}
165
166
167/**
168 * Initialize the OS specific part of the handle and open the directory.
169 * Called by rtDirOpenCommon().
170 *
171 * @returns IPRT status code.
172 * @param pDir The directory to open. The pszPath member contains the
173 * path to the directory.
174 * @param pszPathBuf Pointer to a RTPATH_MAX sized buffer containing
175 * pszPath. Find-first style systems can use this
176 * to setup the wildcard expression.
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, char *pszPathBuf, 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
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