Author: pschweitzer
Date: Thu Jul 17 04:57:23 2008
New Revision: 34561
URL:
http://svn.reactos.org/svn/reactos?rev=34561&view=rev
Log:
- Implemented FsRtlDissectDbcs, FsRtlIsFatDbcsLegal
- Updated comments
Modified:
branches/pierre-fsd/ntoskrnl/fsrtl/dbcsname.c
Modified: branches/pierre-fsd/ntoskrnl/fsrtl/dbcsname.c
URL:
http://svn.reactos.org/svn/reactos/branches/pierre-fsd/ntoskrnl/fsrtl/dbcsn…
==============================================================================
--- branches/pierre-fsd/ntoskrnl/fsrtl/dbcsname.c [iso-8859-1] (original)
+++ branches/pierre-fsd/ntoskrnl/fsrtl/dbcsname.c [iso-8859-1] Thu Jul 17 04:57:23 2008
@@ -45,19 +45,58 @@
OUT PANSI_STRING FirstPart,
OUT PANSI_STRING RemainingPart)
{
- KEBUGCHECK(0);
+ ULONG FirstPosition, i;
+ ULONG SkipFirstSlash = 0;
+
+ /* Just quit if the string is empty */
+ if (!Name.Length) return;
+
+ /* Find first backslash */
+ FirstPosition = Name.Length / sizeof(CHAR) ;
+ for (i = 0; i < Name.Length / sizeof(CHAR); i++)
+ {
+ /* If we found one... */
+ if (Name.Buffer[i] == '\\')
+ {
+ /* If it begins string, just notice it and continue */
+ if (i == 0)
+ {
+ SkipFirstSlash = 1;
+ }
+ else
+ {
+ /* Else, save its position and break out of the loop */
+ FirstPosition = i;
+ break;
+ }
+ }
+ }
+
+ /* Set up the first result string */
+ FirstPart->Buffer = Name.Buffer + SkipFirstSlash;
+ FirstPart->Length = (FirstPosition - SkipFirstSlash) * sizeof(CHAR);
+ FirstPart->MaximumLength = Name.MaximumLength - FirstPart->Length;
+
+ /* And second one, if necessary */
+ if (FirstPosition < (Name.Length / sizeof(CHAR)))
+ {
+ RemainingPart->Buffer = Name.Buffer + FirstPosition + 1;
+ RemainingPart->Length = (Name.Length - FirstPosition) * sizeof(CHAR);
+ RemainingPart->MaximumLength = Name.MaximumLength - RemainingPart->Length;
+ }
}
/*++
* @name FsRtlDoesDbcsContainWildCards
* @implemented
*
- * FILLME
+ * Returns TRUE if the given DbcsName contains wildcards such as *, ?,
+ * ANSI_DOS_STAR, ANSI_DOS_DOT, and ANSI_DOS_QM
*
* @param Name
- * FILLME
- *
- * @return None
+ * The Name to check
+ *
+ * @return TRUE if there are wildcards, FALSE otherwise
*
* @remarks None
*
@@ -115,21 +154,24 @@
/*++
* @name FsRtlIsFatDbcsLegal
- * @unimplemented
- *
- * FILLME
+ * @implemented
+ *
+ * Returns TRUE if the given DbcsName is a valid FAT filename (in 8.3)
*
* @param DbcsName
- * FILLME
+ * The filename to check. It can also contains pathname.
*
* @param WildCardsPermissible
- * FILLME
+ * If this is set to FALSE and if filename contains wildcard, the function
+ * will fail
*
* @param PathNamePermissible
- * FILLME
+ * If this is set to FALSE and if the filename comes with a pathname, the
+ * function will fail
*
* @param LeadingBackslashPermissible
- * FILLME
+ * If this is set to FALSE and if the filename starts with a backslash, the
+ * function will fail
*
* @return TRUE if the DbcsName is legal, FALSE otherwise
*
@@ -143,8 +185,98 @@
IN BOOLEAN PathNamePermissible,
IN BOOLEAN LeadingBackslashPermissible)
{
- KEBUGCHECK(0);
- return FALSE;
+ BOOLEAN FirstSlash = FALSE, IsIllegal = FALSE;
+ ULONG i, LastSlash = 0, LastDot = 0;
+ ANSI_STRING FileName;
+
+ /* Just quit if the string is empty */
+ if (!DbcsName.Length)
+ return FALSE;
+
+ /* Check if we have a filename and a pathname
+ * Continue until we get the last one to extract the filename
+ */
+ for (i = 0; i < DbcsName.Length / sizeof(CHAR); i++)
+ {
+ if (DbcsName.Buffer[i] == '\\')
+ {
+ LastSlash = i;
+ if (!i)
+ {
+ FirstSlash = TRUE;
+ }
+ }
+ }
+
+ /* DbcsName was to be a filename */
+ if (!PathNamePermissible && LastSlash)
+ return FALSE;
+
+ /* DbcsName wasn't supposed to be started with \ if it's a filename */
+ if (!LeadingBackslashPermissible && !LastSlash && FirstSlash)
+ return FALSE;
+
+ /* Now, only work on filename */
+ if (LastSlash)
+ {
+ FileName.Buffer = DbcsName.Buffer + LastSlash + 1;
+ FileName.Length = (DbcsName.Length - LastSlash) * sizeof(CHAR);
+ FileName.MaximumLength = DbcsName.MaximumLength - FileName.Length;
+
+ }
+ else
+ {
+ FileName.Buffer = DbcsName.Buffer;
+ FileName.Length = DbcsName.Length;
+ FileName.MaximumLength = DbcsName.MaximumLength;
+ }
+
+ /* Filename must be 8.3 filename */
+ if (FileName.Length < 3 || FileName.Length > 12)
+ return FALSE;
+
+ if (!WildCardsPermissible && FsRtlDoesDbcsContainWildCards(&FileName))
+ return FALSE;
+
+ /* Now, we will parse the filename to find everything bad in
+ * It mustn't contain:
+ * 0x00-0x1F, 0x22, 0x2B, 0x2C, 0x2F, 0x3A, 0x3B, 0x3D, 0x5B, 0x5D, 0x7C */
+ for (i = 0; i < FileName.Length / sizeof(CHAR); i++)
+ {
+ if ((FileName.Buffer[i] < 0x1F) || (FileName.Buffer[i] == 0x22) ||
+ (FileName.Buffer[i] == 0x2B) || (FileName.Buffer[i] == 0x2C) ||
+ (FileName.Buffer[i] == 0x2F) || (FileName.Buffer[i] == 0x3A) ||
+ (FileName.Buffer[i] == 0x3B) || (FileName.Buffer[i] == 0x3D) ||
+ (FileName.Buffer[i] == 0x5B) || (FileName.Buffer[i] == 0x5D) ||
+ (FileName.Buffer[i] == 0x7C))
+ {
+ IsIllegal = TRUE;
+ break;
+ }
+ if (FileName.Buffer[i] == '.')
+ {
+ LastDot = i;
+ if (!i)
+ {
+ IsIllegal = TRUE;
+ break;
+ }
+ }
+ }
+ if (IsIllegal || LastDot == (FileName.Length / sizeof(CHAR)) - 1)
+ return FALSE;
+
+ /* We mustn't have spaces before dot or at the end of the filename */
+ if ((LastDot && FileName.Buffer[LastDot - 1] == ' ') ||
+ (FileName.Buffer[FileName.Length / sizeof(CHAR) - 1] == ' '))
+ return FALSE;
+
+ /* Filename must be 8.3 filename and not 3.8 filename */
+ if (LastDot && ((FileName.Length / sizeof(CHAR) - 1) - LastDot > 3))
+ return FALSE;
+
+ /* We have a valid filename */
+ return TRUE;
}
/*++