VirtualBox

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

Last change on this file since 69705 was 69691, checked in by vboxsync, 7 years ago

iprt: Started on RTDirRel for NT.

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