ReactOS 0.4.16-dev-297-gc569aee
dbcsname.c File Reference
#include <ntoskrnl.h>
#include <debug.h>
Include dependency graph for dbcsname.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID NTAPI FsRtlDissectDbcs (IN ANSI_STRING Name, OUT PANSI_STRING FirstPart, OUT PANSI_STRING RemainingPart)
 
BOOLEAN NTAPI FsRtlDoesDbcsContainWildCards (IN PANSI_STRING Name)
 
BOOLEAN NTAPI FsRtlIsDbcsInExpression (IN PANSI_STRING Expression, IN PANSI_STRING Name)
 
BOOLEAN NTAPI FsRtlIsFatDbcsLegal (IN ANSI_STRING DbcsName, IN BOOLEAN WildCardsPermissible, IN BOOLEAN PathNamePermissible, IN BOOLEAN LeadingBackslashPermissible)
 
BOOLEAN NTAPI FsRtlIsHpfsDbcsLegal (IN ANSI_STRING DbcsName, IN BOOLEAN WildCardsPermissible, IN BOOLEAN PathNamePermissible, IN BOOLEAN LeadingBackslashPermissible)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file dbcsname.c.

Function Documentation

◆ FsRtlDissectDbcs()

VOID NTAPI FsRtlDissectDbcs ( IN ANSI_STRING  Name,
OUT PANSI_STRING  FirstPart,
OUT PANSI_STRING  RemainingPart 
)

Definition at line 45 of file dbcsname.c.

48{
49 USHORT FirstPosition, i;
50 USHORT SkipFirstSlash = 0;
51 PAGED_CODE();
52
53 /* Zero the strings before continuing */
56
57 /* Just quit if the string is empty */
58 if (!Name.Length) return;
59
60 /* Find first backslash */
61 FirstPosition = Name.Length;
62 for (i = 0; i < Name.Length; i++)
63 {
64 /* First make sure the character it's not the Lead DBCS */
65 if (FsRtlIsLeadDbcsCharacter(Name.Buffer[i]))
66 {
67 i++;
68 }
69 /* If we found one... */
70 else if (Name.Buffer[i] == '\\')
71 {
72 /* If it begins string, just notice it and continue */
73 if (i == 0)
74 {
75 SkipFirstSlash = 1;
76 }
77 else
78 {
79 /* Else, save its position and break out of the loop */
80 FirstPosition = i;
81 break;
82 }
83 }
84 }
85
86 /* Set up the first result string */
87 FirstPart->Buffer = Name.Buffer + SkipFirstSlash;
88 FirstPart->Length = (FirstPosition - SkipFirstSlash);
90
91 /* And second one, if necessary */
92 if (FirstPosition < (Name.Length))
93 {
94 RemainingPart->Buffer = Name.Buffer + FirstPosition + 1;
95 RemainingPart->Length = Name.Length - (FirstPosition + 1);
97 }
98}
#define PAGED_CODE()
#define FsRtlIsLeadDbcsCharacter(DBCS_CHAR)
Definition: init.c:428
_Out_ PANSI_STRING _Out_ PANSI_STRING RemainingPart
Definition: fsrtlfuncs.h:379
_Out_ PANSI_STRING FirstPart
Definition: fsrtlfuncs.h:378
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned short USHORT
Definition: pedump.c:61
USHORT MaximumLength
Definition: env_spec_w32.h:377
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

Referenced by FsRtlIsFatDbcsLegal(), FsRtlIsHpfsDbcsLegal(), and START_TEST().

◆ FsRtlDoesDbcsContainWildCards()

BOOLEAN NTAPI FsRtlDoesDbcsContainWildCards ( IN PANSI_STRING  Name)

Definition at line 117 of file dbcsname.c.

118{
119 USHORT i;
120 PAGED_CODE();
121
122 /* Check every character */
123 for (i = 0; i < Name->Length; i++)
124 {
125 /* First make sure it's not the Lead DBCS */
126 if (FsRtlIsLeadDbcsCharacter(Name->Buffer[i]))
127 {
128 i++;
129 }
130 else if (FsRtlIsAnsiCharacterWild(Name->Buffer[i]))
131 {
132 /* Now return if it has a wildcard */
133 return TRUE;
134 }
135 }
136
137 /* We didn't return above...so none found */
138 return FALSE;
139}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define FsRtlIsAnsiCharacterWild(C)
Definition: fsrtlfuncs.h:1608

Referenced by FsRtlIsDbcsInExpression(), and FsRtlIsFatDbcsLegal().

◆ FsRtlIsDbcsInExpression()

BOOLEAN NTAPI FsRtlIsDbcsInExpression ( IN PANSI_STRING  Expression,
IN PANSI_STRING  Name 
)

Definition at line 160 of file dbcsname.c.

162{
163 USHORT Offset, Position, BackTrackingPosition, OldBackTrackingPosition;
164 USHORT BackTrackingBuffer[16], OldBackTrackingBuffer[16] = {0};
165 PUSHORT BackTrackingSwap, BackTracking = BackTrackingBuffer, OldBackTracking = OldBackTrackingBuffer;
166 ULONG BackTrackingBufferSize = RTL_NUMBER_OF(BackTrackingBuffer);
167 PVOID AllocatedBuffer = NULL;
168 USHORT ExpressionPosition, NamePosition = 0, MatchingChars = 1;
169 USHORT NameChar = 0, ExpressionChar;
170 BOOLEAN EndOfName = FALSE;
172 BOOLEAN DontSkipDot;
173 PAGED_CODE();
174
175 ASSERT(Name->Length);
176 ASSERT(Expression->Length);
178
179 /* Check if we were given strings at all */
180 if (!Name->Length || !Expression->Length)
181 {
182 /* Return TRUE if both strings are empty, otherwise FALSE */
183 if (Name->Length == 0 && Expression->Length == 0)
184 return TRUE;
185 else
186 return FALSE;
187 }
188
189 /* Check for a shortcut: just one wildcard */
190 if (Expression->Length == sizeof(CHAR))
191 {
192 if (Expression->Buffer[0] == '*')
193 return TRUE;
194 }
195
196 //ASSERT(FsRtlDoesDbcsContainWildCards(Expression));
197
198 /* Another shortcut, wildcard followed by some string */
199 if (Expression->Buffer[0] == '*')
200 {
201 /* Copy Expression to our local variable */
202 ANSI_STRING IntExpression = *Expression;
203
204 /* Skip the first char */
205 IntExpression.Buffer++;
206 IntExpression.Length -= sizeof(CHAR);
207
208 /* Continue only if the rest of the expression does NOT contain
209 any more wildcards */
210 if (!FsRtlDoesDbcsContainWildCards(&IntExpression))
211 {
212 /* Check for a degenerate case */
213 if (Name->Length < (Expression->Length - sizeof(CHAR)))
214 return FALSE;
215
216 /* Calculate position */
217 NamePosition = (Name->Length - IntExpression.Length) / sizeof(CHAR);
218
219 /* Check whether we are breaking a two chars char (DBCS) */
221 {
222 MatchingChars = 0;
223
224 while (MatchingChars < NamePosition)
225 {
226 /* Check if current char is DBCS lead char, if so, jump by two chars */
227 MatchingChars += FsRtlIsLeadDbcsCharacter(Name->Buffer[MatchingChars]) ? 2 : 1;
228 }
229
230 /* If so, deny */
231 if (MatchingChars > NamePosition)
232 return FALSE;
233 }
234
235 /* Compare */
236 return RtlEqualMemory(IntExpression.Buffer,
237 (Name->Buffer + NamePosition),
238 IntExpression.Length);
239 }
240 }
241
242 /* Name parsing loop */
243 for (; !EndOfName; MatchingChars = BackTrackingPosition)
244 {
245 /* Reset positions */
246 OldBackTrackingPosition = BackTrackingPosition = 0;
247
248 if (NamePosition >= Name->Length)
249 {
250 EndOfName = TRUE;
251 if (MatchingChars && OldBackTracking[MatchingChars - 1] == Expression->Length * 2)
252 break;
253 }
254 else
255 {
256 /* If lead byte present */
257 if (FsRtlIsLeadDbcsCharacter(Name->Buffer[NamePosition]))
258 {
259 NameChar = Name->Buffer[NamePosition] +
260 (0x100 * Name->Buffer[NamePosition + 1]);
261 NamePosition += sizeof(USHORT);
262 }
263 else
264 {
265 NameChar = Name->Buffer[NamePosition];
266 NamePosition += sizeof(UCHAR);
267 }
268 }
269
270 while (MatchingChars > OldBackTrackingPosition)
271 {
272 ExpressionPosition = (OldBackTracking[OldBackTrackingPosition++] + 1) / 2;
273
274 /* Expression parsing loop */
275 for (Offset = 0; ExpressionPosition < Expression->Length; )
276 {
277 ExpressionPosition += Offset;
278
279 if (ExpressionPosition == Expression->Length)
280 {
281 BackTracking[BackTrackingPosition++] = Expression->Length * 2;
282 break;
283 }
284
285 /* If buffer too small */
286 if (BackTrackingPosition > BackTrackingBufferSize - 3)
287 {
288 /* We should only ever get here once! */
289 ASSERT(AllocatedBuffer == NULL);
290 ASSERT((BackTracking == BackTrackingBuffer) || (BackTracking == OldBackTrackingBuffer));
291 ASSERT((OldBackTracking == BackTrackingBuffer) || (OldBackTracking == OldBackTrackingBuffer));
292
293 /* Calculate buffer size */
294 BackTrackingBufferSize = Expression->Length * 2 + 1;
295
296 /* Allocate memory for both back-tracking buffers */
298 2 * BackTrackingBufferSize * sizeof(USHORT),
299 'nrSF');
300 if (AllocatedBuffer == NULL)
301 {
302 DPRINT1("Failed to allocate BackTracking buffer. BackTrackingBufferSize = =x%lx\n",
303 BackTrackingBufferSize);
304 Result = FALSE;
305 goto Exit;
306 }
307
308 /* Copy BackTracking content. Note that it can point to either BackTrackingBuffer or OldBackTrackingBuffer */
309 RtlCopyMemory(AllocatedBuffer,
310 BackTracking,
311 RTL_NUMBER_OF(BackTrackingBuffer) * sizeof(USHORT));
312
313 /* Place current Backtracking is at the start of the new buffer */
314 BackTracking = AllocatedBuffer;
315
316 /* Copy OldBackTracking content */
317 RtlCopyMemory(&BackTracking[BackTrackingBufferSize],
318 OldBackTracking,
319 RTL_NUMBER_OF(OldBackTrackingBuffer) * sizeof(USHORT));
320
321 /* Place current OldBackTracking after current BackTracking in the buffer */
322 OldBackTracking = &BackTracking[BackTrackingBufferSize];
323 }
324
325 /* If lead byte present */
326 if (FsRtlIsLeadDbcsCharacter(Expression->Buffer[ExpressionPosition]))
327 {
328 ExpressionChar = Expression->Buffer[ExpressionPosition] +
329 (0x100 * Expression->Buffer[ExpressionPosition + 1]);
330 Offset = sizeof(USHORT);
331 }
332 else
333 {
334 ExpressionChar = Expression->Buffer[ExpressionPosition];
335 Offset = sizeof(UCHAR);
336 }
337
338 /* Basic check to test if chars are equal */
339 if (ExpressionChar == NameChar && !EndOfName)
340 {
341 BackTracking[BackTrackingPosition++] = (ExpressionPosition + Offset) * 2;
342 }
343 /* Check cases that eat one char */
344 else if (ExpressionChar == '?' && !EndOfName)
345 {
346 BackTracking[BackTrackingPosition++] = (ExpressionPosition + Offset) * 2;
347 }
348 /* Test star */
349 else if (ExpressionChar == '*')
350 {
351 BackTracking[BackTrackingPosition++] = ExpressionPosition * 2;
352 BackTracking[BackTrackingPosition++] = (ExpressionPosition * 2) + 1;
353 continue;
354 }
355 /* Check DOS_STAR */
356 else if (ExpressionChar == ANSI_DOS_STAR)
357 {
358 /* Look for last dot */
359 DontSkipDot = TRUE;
360 if (!EndOfName && NameChar == '.')
361 {
362 for (Position = NamePosition; Position < Name->Length; )
363 {
364 /* If lead byte not present */
366 {
367 if (Name->Buffer[Position] == '.')
368 {
369 DontSkipDot = FALSE;
370 break;
371 }
372
373 Position += sizeof(UCHAR);
374 }
375 else
376 {
377 Position += sizeof(USHORT);
378 }
379 }
380 }
381
382 if (EndOfName || NameChar != '.' || !DontSkipDot)
383 BackTracking[BackTrackingPosition++] = ExpressionPosition * 2;
384
385 BackTracking[BackTrackingPosition++] = (ExpressionPosition * 2) + 1;
386 continue;
387 }
388 /* Check DOS_DOT */
389 else if (ExpressionChar == ANSI_DOS_DOT)
390 {
391 if (EndOfName) continue;
392
393 if (NameChar == '.')
394 BackTracking[BackTrackingPosition++] = (ExpressionPosition + Offset) * 2;
395 }
396 /* Check DOS_QM */
397 else if (ExpressionChar == ANSI_DOS_QM)
398 {
399 if (EndOfName || NameChar == '.') continue;
400
401 BackTracking[BackTrackingPosition++] = (ExpressionPosition + Offset) * 2;
402 }
403
404 /* Leave from loop */
405 break;
406 }
407
408 for (Position = 0; MatchingChars > OldBackTrackingPosition && Position < BackTrackingPosition; Position++)
409 {
410 while (MatchingChars > OldBackTrackingPosition &&
411 BackTracking[Position] > OldBackTracking[OldBackTrackingPosition])
412 {
413 ++OldBackTrackingPosition;
414 }
415 }
416 }
417
418 /* Swap pointers */
419 BackTrackingSwap = BackTracking;
420 BackTracking = OldBackTracking;
421 OldBackTracking = BackTrackingSwap;
422 }
423
424 /* Store result value */
425 Result = MatchingChars && (OldBackTracking[MatchingChars - 1] == Expression->Length * 2);
426
427Exit:
428
429 /* Frees the memory if necessary */
430 if (AllocatedBuffer != NULL)
431 {
432 ExFreePoolWithTag(AllocatedBuffer, 'nrSF');
433 }
434
435 return Result;
436}
PCWSTR Expression
unsigned char BOOLEAN
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
#define DPRINT1
Definition: precomp.h:8
#define CHAR(Char)
BOOLEAN NTAPI FsRtlDoesDbcsContainWildCards(IN PANSI_STRING Name)
Definition: dbcsname.c:117
#define NULL
Definition: types.h:112
#define ANSI_DOS_STAR
Definition: env_spec_w32.h:908
#define ANSI_DOS_QM
Definition: env_spec_w32.h:909
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define ANSI_DOS_DOT
Definition: env_spec_w32.h:910
#define PagedPool
Definition: env_spec_w32.h:308
#define RtlEqualMemory(dst, src, len)
Definition: kdvm.h:18
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
BOOLEAN NlsMbOemCodePageTag
Definition: nlsboot.c:19
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
static void Exit(void)
Definition: sock.c:1330
static COORD Position
Definition: mouse.c:34
uint16_t * PUSHORT
Definition: typedefs.h:56
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG
Definition: typedefs.h:59
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
#define POOL_RAISE_IF_ALLOCATION_FAILURE
unsigned char UCHAR
Definition: xmlstorage.h:181
char CHAR
Definition: xmlstorage.h:175

Referenced by FatIsNameInExpression(), and FsRtlIsDbcsInExpressionTest().

◆ FsRtlIsFatDbcsLegal()

BOOLEAN NTAPI FsRtlIsFatDbcsLegal ( IN ANSI_STRING  DbcsName,
IN BOOLEAN  WildCardsPermissible,
IN BOOLEAN  PathNamePermissible,
IN BOOLEAN  LeadingBackslashPermissible 
)

Definition at line 466 of file dbcsname.c.

470{
472 BOOLEAN LastDot;
473 USHORT i;
474 PAGED_CODE();
475
476 /* Just quit if the string is empty */
477 if (!DbcsName.Length)
478 return FALSE;
479
480 /* Accept special filename if wildcards are allowed */
481 if (WildCardsPermissible && (DbcsName.Length == 1 || DbcsName.Length == 2) && DbcsName.Buffer[0] == '.')
482 {
483 if (DbcsName.Length == 2)
484 {
485 if (DbcsName.Buffer[1] == '.')
486 return TRUE;
487 }
488 else
489 {
490 return TRUE;
491 }
492 }
493
494 /* DbcsName wasn't supposed to be started with \ */
495 if (!LeadingBackslashPermissible && DbcsName.Buffer[0] == '\\')
496 return FALSE;
497 /* DbcsName was allowed to be started with \, but now, remove it */
498 else if (LeadingBackslashPermissible && DbcsName.Buffer[0] == '\\')
499 {
500 DbcsName.Buffer = DbcsName.Buffer + 1;
501 DbcsName.Length = DbcsName.Length - 1;
502 DbcsName.MaximumLength = DbcsName.MaximumLength - 1;
503 }
504
506 {
507 /* We copy the buffer for FsRtlDissectDbcs call */
508 RemainingPart.Buffer = DbcsName.Buffer;
509 RemainingPart.Length = DbcsName.Length;
510 RemainingPart.MaximumLength = DbcsName.MaximumLength;
511
512 while (RemainingPart.Length > 0)
513 {
514 if (RemainingPart.Buffer[0] == '\\')
515 return FALSE;
516
517 /* Call once again our dissect function */
519
522 FALSE,
523 FALSE))
524 {
525 return FALSE;
526 }
527 }
528
529 return TRUE;
530 }
531
533 {
534 for (i = 0; i < DbcsName.Length; i++)
535 {
536 /* First make sure the character it's not the Lead DBCS */
537 if (FsRtlIsLeadDbcsCharacter(DbcsName.Buffer[i]))
538 {
539 i++;
540 }
541 /* Then check for bad characters */
542 else if (!FsRtlIsAnsiCharacterLegalFat(DbcsName.Buffer[i], TRUE))
543 {
544 return FALSE;
545 }
546 }
547
548 return TRUE;
549 }
550
551 /* Filename must be 8.3 filename */
552 if (DbcsName.Length > 12)
553 return FALSE;
554
555 /* Reset dots count */
556 LastDot = FALSE;
557
558 for (i = 0; i < DbcsName.Length; i++)
559 {
560 /* First make sure the character it's not the Lead DBCS */
561 if (FsRtlIsLeadDbcsCharacter(DbcsName.Buffer[i]))
562 {
563 if (!LastDot && (i >= 7))
564 return FALSE;
565
566 if (i == (DbcsName.Length - 1))
567 return FALSE;
568
569 i++;
570 continue;
571 }
572 /* Then check for bad characters */
573 else if (!FsRtlIsAnsiCharacterLegalFat(DbcsName.Buffer[i], WildCardsPermissible))
574 {
575 return FALSE;
576 }
577 else if (DbcsName.Buffer[i] == '.')
578 {
579 /* Filename can only contain one dot */
580 if (LastDot)
581 return FALSE;
582
583 LastDot = TRUE;
584
585 /* We mustn't have spaces before dot or at the end of the filename
586 * and no dot at the beginning of the filename */
587 if (i == (DbcsName.Length - 1) || i == 0)
588 return FALSE;
589
590 /* Filename must be 8.3 filename and not 3.8 filename */
591 if ((DbcsName.Length - 1) - i > 3)
592 return FALSE;
593
594 if ((i > 0) && DbcsName.Buffer[i - 1] == ' ')
595 return FALSE;
596 }
597 /* Filename mustn't finish with a space */
598 else if (DbcsName.Buffer[i] == ' ' && i == (DbcsName.Length - 1))
599 {
600 return FALSE;
601 }
602
603 if (!LastDot && (i >= 8))
604 return FALSE;
605 }
606
607 return TRUE;
608}
BOOLEAN NTAPI FsRtlIsFatDbcsLegal(IN ANSI_STRING DbcsName, IN BOOLEAN WildCardsPermissible, IN BOOLEAN PathNamePermissible, IN BOOLEAN LeadingBackslashPermissible)
Definition: dbcsname.c:466
VOID NTAPI FsRtlDissectDbcs(IN ANSI_STRING Name, OUT PANSI_STRING FirstPart, OUT PANSI_STRING RemainingPart)
Definition: dbcsname.c:45
_Must_inspect_result_ _In_ BOOLEAN _In_ BOOLEAN PathNamePermissible
Definition: fsrtlfuncs.h:406
_Must_inspect_result_ _In_ BOOLEAN _In_ BOOLEAN _In_ BOOLEAN LeadingBackslashPermissible
Definition: fsrtlfuncs.h:407
#define FsRtlIsAnsiCharacterLegalFat(C, WILD)
Definition: fsrtlfuncs.h:1611
_Must_inspect_result_ _In_ BOOLEAN WildCardsPermissible
Definition: fsrtlfuncs.h:405

Referenced by CdIs8dot3Name(), FsRtlIsFatDbcsLegal(), and START_TEST().

◆ FsRtlIsHpfsDbcsLegal()

BOOLEAN NTAPI FsRtlIsHpfsDbcsLegal ( IN ANSI_STRING  DbcsName,
IN BOOLEAN  WildCardsPermissible,
IN BOOLEAN  PathNamePermissible,
IN BOOLEAN  LeadingBackslashPermissible 
)

Definition at line 638 of file dbcsname.c.

642{
644 USHORT i;
645 PAGED_CODE();
646
647 /* Just quit if the string is empty */
648 if (!DbcsName.Length)
649 return FALSE;
650
651 /* Accept special filename if wildcards are allowed */
652 if (WildCardsPermissible && (DbcsName.Length == 1 || DbcsName.Length == 2) && DbcsName.Buffer[0] == '.')
653 {
654 if (DbcsName.Length == 2)
655 {
656 if (DbcsName.Buffer[1] == '.')
657 return TRUE;
658 }
659 else
660 {
661 return TRUE;
662 }
663 }
664
665 /* DbcsName wasn't supposed to be started with \ */
666 if (!LeadingBackslashPermissible && DbcsName.Buffer[0] == '\\')
667 return FALSE;
668 /* DbcsName was allowed to be started with \, but now, remove it */
669 else if (LeadingBackslashPermissible && DbcsName.Buffer[0] == '\\')
670 {
671 DbcsName.Buffer = DbcsName.Buffer + 1;
672 DbcsName.Length = DbcsName.Length - 1;
673 DbcsName.MaximumLength = DbcsName.MaximumLength - 1;
674 }
675
677 {
678 /* We copy the buffer for FsRtlDissectDbcs call */
679 RemainingPart.Buffer = DbcsName.Buffer;
680 RemainingPart.Length = DbcsName.Length;
681 RemainingPart.MaximumLength = DbcsName.MaximumLength;
682
683 while (RemainingPart.Length > 0)
684 {
685 if (RemainingPart.Buffer[0] == '\\')
686 return FALSE;
687
688 /* Call once again our dissect function */
690
693 FALSE,
694 FALSE))
695 {
696 return FALSE;
697 }
698 }
699
700 return TRUE;
701 }
702
703 if (DbcsName.Length > 255)
704 return FALSE;
705
706 for (i = 0; i < DbcsName.Length; i++)
707 {
708 /* First make sure the character it's not the Lead DBCS */
709 if (FsRtlIsLeadDbcsCharacter(DbcsName.Buffer[i]))
710 {
711 if (i == (DbcsName.Length - 1))
712 return FALSE;
713 i++;
714 }
715 /* Then check for bad characters */
716 else if (!FsRtlIsAnsiCharacterLegalHpfs(DbcsName.Buffer[i], WildCardsPermissible))
717 {
718 return FALSE;
719 }
720 /* Filename mustn't finish with a space or a dot */
721 else if ((DbcsName.Buffer[i] == ' ' || DbcsName.Buffer[i] == '.') && i == (DbcsName.Length - 1))
722 {
723 return FALSE;
724 }
725 }
726
727 return TRUE;
728}
BOOLEAN NTAPI FsRtlIsHpfsDbcsLegal(IN ANSI_STRING DbcsName, IN BOOLEAN WildCardsPermissible, IN BOOLEAN PathNamePermissible, IN BOOLEAN LeadingBackslashPermissible)
Definition: dbcsname.c:638
#define FsRtlIsAnsiCharacterLegalHpfs(C, WILD)
Definition: fsrtlfuncs.h:1614

Referenced by FsRtlIsHpfsDbcsLegal(), and START_TEST().