VirtualBox

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

Last change on this file since 73907 was 70890, checked in by vboxsync, 7 years ago

IPRT: dir.c,dir-posix.cpp,direnum-nt.cpp: Implemented RTDIR_F_NO_FOLLOW on posix, adjusted NT implementation and documented the VERR_IS_A_SYMLINK return code for the relevant APIs.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 7.0 KB
Line 
1/* $Id: dir.h 70890 2018-02-07 14:05:43Z 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 /** Handle to the opened directory search. */
102 HANDLE hDir;
103# ifndef RTNT_USE_NATIVE_NT
104 /** Find data buffer.
105 * fDataUnread indicates valid data. */
106 WIN32_FIND_DATAW Data;
107# else
108 /** The size of the name buffer pszName points to. */
109 size_t cbNameAlloc;
110 /** NT filter string. */
111 UNICODE_STRING NtFilterStr;
112 /** Pointer to NtFilterStr if applicable, otherwise NULL. */
113 PUNICODE_STRING pNtFilterStr;
114 /** The information class we're using. */
115 FILE_INFORMATION_CLASS enmInfoClass;
116 /** Object directory context data. */
117 ULONG uObjDirCtx;
118 /** Pointer to the current data entry in the buffer. */
119 union
120 {
121 /** Both file names, no file ID. */
122 PFILE_BOTH_DIR_INFORMATION pBoth;
123 /** Both file names with file ID. */
124 PFILE_ID_BOTH_DIR_INFORMATION pBothId;
125 /** Object directory info. */
126 POBJECT_DIRECTORY_INFORMATION pObjDir;
127 /** Unsigned view. */
128 uintptr_t u;
129 } uCurData;
130 /** The amount of valid data in the buffer. */
131 uint32_t cbBuffer;
132 /** The allocate buffer size. */
133 uint32_t cbBufferAlloc;
134 /** Find data buffer containing multiple directory entries.
135 * fDataUnread indicates valid data. */
136 uint8_t *pabBuffer;
137 /** The device number for the directory (serial number). */
138 RTDEV uDirDev;
139# endif
140# else /* 'POSIX': */
141 /** What opendir() returned. */
142 DIR *pDir;
143 /** Find data buffer.
144 * fDataUnread indicates valid data. */
145 struct dirent Data;
146# endif
147#endif
148} RTDIRINTERNAL;
149
150
151
152/**
153 * Validates a directory handle.
154 * @returns true if valid.
155 * @returns false if valid after having bitched about it first.
156 */
157DECLINLINE(bool) rtDirValidHandle(PRTDIRINTERNAL pDir)
158{
159 AssertMsgReturn(VALID_PTR(pDir), ("%p\n", pDir), false);
160 AssertMsgReturn(pDir->u32Magic == RTDIR_MAGIC, ("%#RX32\n", pDir->u32Magic), false);
161 return true;
162}
163
164
165/**
166 * Initialize the OS specific part of the handle and open the directory.
167 * Called by rtDirOpenCommon().
168 *
169 * @returns IPRT status code.
170 * @param pDir The directory to open. The pszPath member contains the
171 * path to the directory.
172 * @param pszPathBuf Pointer to a RTPATH_MAX sized buffer containing
173 * pszPath. Find-first style systems can use this
174 * to setup the wildcard expression.
175 * @param hRelativeDir The directory @a pvNativeRelative is relative,
176 * ~(uintptr_t)0 if absolute.
177 * @param pvNativeRelative The native relative path. NULL if absolute or
178 * we're to use (consume) hRelativeDir.
179 */
180int rtDirNativeOpen(PRTDIRINTERNAL pDir, char *pszPathBuf, uintptr_t hRelativeDir, void *pvNativeRelative);
181
182/**
183 * Returns the size of the directory structure.
184 *
185 * @returns The size in bytes.
186 * @param pszPath The path to the directory we're about to open.
187 */
188size_t rtDirNativeGetStructSize(const char *pszPath);
189
190
191DECLHIDDEN(int) rtDirOpenRelativeOrHandle(RTDIR *phDir, const char *pszRelativeAndFilter, RTDIRFILTER enmFilter,
192 uint32_t fFlags, uintptr_t hRelativeDir, void *pvNativeRelative);
193
194#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