ReactOS 0.4.15-dev-8127-g6338913
winfs.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2003, 2004, 2005 Martin Fuchs
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19
20 //
21 // Explorer clone
22 //
23 // winfs.cpp
24 //
25 // Martin Fuchs, 23.07.2003
26 //
27
28
29#include <precomp.h>
30
31#ifndef _NO_WIN_FS
32
33//#include "winfs.h"
34
35
36#ifdef BACKUP_READ_IMPLEMENTED
37int ScanNTFSStreams(Entry* entry, HANDLE hFile)
38{
39 PVOID ctx = 0;
40 DWORD read, seek_high;
41 Entry** pnext = &entry->_down;
42 int cnt = 0;
43
44 for(;;) {
45 struct NTFS_StreamHdr : public WIN32_STREAM_ID {
46 WCHAR name_padding[_MAX_FNAME]; // room for reading stream name
47 } hdr;
48
49 if (!BackupRead(hFile, (LPBYTE)&hdr, (LPBYTE)&hdr.cStreamName-(LPBYTE)&hdr, &read, FALSE, FALSE, &ctx) ||
50 (long)read!=(LPBYTE)&hdr.cStreamName-(LPBYTE)&hdr)
51 break;
52
53 if (hdr.dwStreamId == BACKUP_ALTERNATE_DATA) {
54 if (hdr.dwStreamNameSize &&
55 BackupRead(hFile, (LPBYTE)hdr.cStreamName, hdr.dwStreamNameSize, &read, FALSE, FALSE, &ctx) &&
56 read==hdr.dwStreamNameSize)
57 {
58 ++cnt;
59
60 int l = hdr.dwStreamNameSize / sizeof(WCHAR);
61 LPCWSTR p = hdr.cStreamName;
62 LPCWSTR e = hdr.cStreamName + l;
63
64 if (l>0 && *p==':') {
65 ++p, --l;
66
67 e = p;
68
69 while(l>0 && *e!=':')
70 ++e, --l;
71
72 l = e - p;
73 }
74
75 Entry* stream_entry = new WinEntry(entry);
76
77 memcpy(&stream_entry->_data, &entry->_data, sizeof(WIN32_FIND_DATA));
78 lstrcpy(stream_entry->_data.cFileName, String(p, l));
79
80 stream_entry->_down = NULL;
81 stream_entry->_expanded = false;
82 stream_entry->_scanned = false;
83 stream_entry->_level = entry->_level + 1;
84
85 *pnext = stream_entry;
86 pnext = &stream_entry->_next;
87 }
88 }
89
90 // jump to the next stream header
91 if (!BackupSeek(hFile, ~0, ~0, &read, &seek_high, &ctx)) {
93
94 if (error != ERROR_SEEK) {
95 BackupRead(hFile, 0, 0, &read, TRUE, FALSE, &ctx); // terminate BackupRead() loop
97 //break;
98 }
99
100 hdr.Size.QuadPart -= read;
101 hdr.Size.HighPart -= seek_high;
102
103 BYTE buffer[4096];
104
105 while(hdr.Size.QuadPart > 0) {
106 if (!BackupRead(hFile, buffer, sizeof(buffer), &read, FALSE, FALSE, &ctx) || read!=sizeof(buffer))
107 break;
108
109 hdr.Size.QuadPart -= read;
110 }
111 }
112 }
113
114 if (ctx)
115 if (!BackupRead(hFile, 0, 0, &read, TRUE, FALSE, &ctx)) // terminate BackupRead() loop
117
118 return cnt;
119}
120#endif
121
122
124{
125 CONTEXT("WinDirectory::read_directory()");
126
127 int level = _level + 1;
128
129 Entry* first_entry = NULL;
130 Entry* last = NULL;
131 Entry* entry;
132
135 for(pname=buffer; *path; )
136 *pname++ = *path++;
137
138 lstrcpy(pname, TEXT("\\*"));
139
140 WIN32_FIND_DATA w32fd;
141 HANDLE hFind = FindFirstFile(buffer, &w32fd);
142
143 if (hFind != INVALID_HANDLE_VALUE) {
144 do {
145 lstrcpy(pname+1, w32fd.cFileName);
146
147 if (w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
148 entry = new WinDirectory(this, buffer);
149 else
150 entry = new WinEntry(this);
151
152 if (!first_entry)
153 first_entry = entry;
154
155 if (last)
156 last->_next = entry;
157
158 memcpy(&entry->_data, &w32fd, sizeof(WIN32_FIND_DATA));
159 entry->_level = level;
160
161 // display file type names, but don't hide file extensions
163
164 if (!(scan_flags & SCAN_DONT_ACCESS)) {
167
170 entry->_bhfi_valid = true;
171
172#ifdef BACKUP_READ_IMPLEMENTED
173 if (ScanNTFSStreams(entry, hFile))
174 entry->_scanned = true; // There exist named NTFS sub-streams in this file.
175#endif
176
178 }
179 }
180
181 last = entry; // There is always at least one entry, because FindFirstFile() succeeded and we don't filter the file entries.
182 } while(FindNextFile(hFind, &w32fd));
183
184 if (last)
185 last->_next = NULL;
186
187 FindClose(hFind);
188 }
189
190 _down = first_entry;
191 _scanned = true;
192}
193
194
195const void* WinDirectory::get_next_path_component(const void* p) const
196{
197 LPCTSTR s = (LPCTSTR) p;
198
199 while(*s && *s!=TEXT('\\') && *s!=TEXT('/'))
200 ++s;
201
202 while(*s==TEXT('\\') || *s==TEXT('/'))
203 ++s;
204
205 if (!*s)
206 return NULL;
207
208 return s;
209}
210
211
213{
215
216 for(Entry*entry=_down; entry; entry=entry->_next) {
217 LPCTSTR p = name;
218 LPCTSTR q = entry->_data.cFileName;
219
220 do {
221 if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
222 return entry;
223 } while(tolower(*p++) == tolower(*q++));
224
225 p = name;
226 q = entry->_data.cAlternateFileName;
227
228 do {
229 if (!*p || *p==TEXT('\\') || *p==TEXT('/'))
230 return entry;
231 } while(tolower(*p++) == tolower(*q++));
232 }
233
234 return NULL;
235}
236
237
238 // get full path of specified directory entry
239bool WinEntry::get_path(PTSTR path, size_t path_count) const
240{
241 return get_path_base(path, path_count, ET_WINDOWS);
242}
243
245{
246 CONTEXT("WinEntry::create_absolute_pidl()");
247
249
250 if (get_path(path, COUNTOF(path)))
251 return ShellPath(path);
252
253 return ShellPath();
254}
255
256#endif // _NO_WIN_FS
int tolower(int c)
Definition: utclib.c:902
#define read
Definition: acwin.h:96
BOOL WINAPI BackupSeek(HANDLE hFile, DWORD dwLowBytesToSeek, DWORD dwHighBytesToSeek, LPDWORD lpdwLowByteSeeked, LPDWORD lpdwHighByteSeeked, LPVOID *lpContext)
Definition: backup.c:43
BOOL WINAPI BackupRead(HANDLE hFile, LPBYTE lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, BOOL bAbort, BOOL bProcessSecurity, LPVOID *lpContext)
Definition: backup.c:23
r l[0]
Definition: byte_order.h:168
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define MAX_PATH
Definition: compat.h:34
#define FILE_SHARE_READ
Definition: compat.h:136
BOOL WINAPI GetFileInformationByHandle(HANDLE hFile, LPBY_HANDLE_FILE_INFORMATION lpFileInformation)
Definition: fileinfo.c:458
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
@ SCAN_DONT_ACCESS
Definition: entries.h:54
@ ET_WINDOWS
Definition: entries.h:32
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint level
Definition: gl.h:1546
GLdouble s
Definition: gl.h:2039
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
GLuint buffer
Definition: glext.h:5915
GLenum pname
Definition: glext.h:5645
GLfloat GLfloat p
Definition: glext.h:8902
char hdr[14]
Definition: iptest.cpp:33
uint32_t entry
Definition: isohybrid.c:63
#define TEXT(s)
Definition: k32.h:26
#define e
Definition: ke_i.h:82
#define error(str)
Definition: mkdosfs.c:1605
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
ExplorerGlobals g_Globals
Definition: explorer.cpp:52
#define _MAX_FNAME
Definition: utility.h:74
#define COUNTOF(x)
Definition: utility.h:93
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
static UINT UINT last
Definition: font.c:45
_In_ HANDLE hFile
Definition: mswsock.h:90
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
struct _CONTEXT CONTEXT
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
#define THROW_EXCEPTION(hr)
Definition: shellclasses.h:161
void * _path
Definition: entries.h:143
base of all file and directory entries
Definition: entries.h:83
bool _expanded
Definition: entries.h:96
bool get_path_base(PTSTR path, size_t path_count, ENTRY_TYPE etype) const
Definition: entries.cpp:639
Entry * _down
Definition: entries.h:93
WIN32_FIND_DATA _data
Definition: entries.h:100
Entry * _next
Definition: entries.h:92
int _level
Definition: entries.h:98
bool _scanned
Definition: entries.h:97
FileTypeManager _ftype_mgr
Definition: globals.h:284
LPCTSTR set_type(struct Entry *entry, bool dont_hide_ext=false)
Definition: explorer.cpp:213
wrapper class for item ID lists
Definition: shellclasses.h:652
Windows file system directory-entry.
Definition: winfs.h:46
virtual const void * get_next_path_component(const void *) const
Definition: winfs.cpp:195
virtual Entry * find_entry(const void *)
Definition: winfs.cpp:212
virtual void read_directory(int scan_flags=0)
Definition: winfs.cpp:123
Windows file system file-entry.
Definition: winfs.h:33
virtual bool get_path(PTSTR path, size_t path_count) const
Definition: winfs.cpp:239
WinEntry()
Definition: winfs.h:37
virtual ShellPath create_absolute_pidl() const
Definition: winfs.cpp:244
Definition: name.c:39
unsigned char * LPBYTE
Definition: typedefs.h:53
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
#define BACKUP_ALTERNATE_DATA
Definition: winbase.h:480
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define lstrcpy
Definition: winbase.h:3874
#define FindNextFile
Definition: winbase.h:3788
#define FindFirstFile
Definition: winbase.h:3782
#define CreateFile
Definition: winbase.h:3749
#define ERROR_SEEK
Definition: winerror.h:128
char TCHAR
Definition: xmlstorage.h:189
__wchar_t WCHAR
Definition: xmlstorage.h:180
CHAR * PTSTR
Definition: xmlstorage.h:191
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
unsigned char BYTE
Definition: xxhash.c:193