2 * reactos filesystem name strings functions emulation of libcaptive
3 * Copyright (C) 2002 Jan Kratochvil <project-captive@jankratochvil.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; exactly version 2 of June 1991 is required
9 * This program 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
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "reactos/ddk/fsfuncs.h" /* self */
23 #include <glib/gmessages.h>
24 #include "captive/unicode.h"
28 * FsRtlIsFatDbcsLegal:
29 * @DbcsName_nonconst: #ANSI_STRING to check.
30 * Yes, the string is passed by value, not by reference!
31 * @WildCardsPermissible: Allow '*' or '?' characters?
32 * @PathNamePermissible: Allow '\' for pathname checking? Otherwise plain filename is required.
33 * @LeadingBackslashPermissible: Allow first directory component empty?
35 * Characters 0x00..0x1F, '"', '/', ':', '|', '+', ',', ';', '=', '[' and ']' are always forbidden anywhere.
36 * Characters '*' and '?' are permitted if @WildCardsPermissible.
37 * Basename length must be >=1 && <=8. Extension length must be >=0 && <=3.
38 * Basename or extension must not contain trailing space (' ').
39 * Only one '.' is allowed inside one filename component - to split filename to basename and extension.
41 * Returns: %TRUE if @DbcsName_nonconst is a valid pathname according to the constaints.
43 BOOLEAN FsRtlIsFatDbcsLegal(IN ANSI_STRING DbcsName_nonconst,
44 IN BOOLEAN WildCardsPermissible,IN BOOLEAN PathNamePermissible,IN BOOLEAN LeadingBackslashPermissible)
46 const ANSI_STRING *cDbcsName;
47 gboolean gotdot=FALSE;
50 g_return_val_if_fail(captive_validate_AnsiString(&DbcsName_nonconst),FALSE);
51 g_return_val_if_fail(PathNamePermissible==FALSE,FALSE); /* FIXME: 'PathNamePermissible' not yet implemented */
53 cDbcsName=&DbcsName_nonconst;
54 for (i=0;i<cDbcsName->Length;i++) {
55 char c=cDbcsName->Buffer[i];
57 if ((c>=0x00 && c<=0x1F)
58 || c=='"' || c=='/' || c==':' || c=='|' || c=='+'
59 || c==',' || c==';' || c=='=' || c=='[' || c==']') /* always invalid */
61 if (!PathNamePermissible && c=='\\')
63 if (!LeadingBackslashPermissible && i==0 && c=='\\')
65 if (!WildCardsPermissible && (c=='*' || c=='?'))
79 if (' '==cDbcsName->Buffer[i-1])
82 if (!cDbcsName->Length)
84 if (' '==cDbcsName->Buffer[cDbcsName->Length-1])
86 if (len>(!gotdot ? 8 : 3))