/* $Id$ * reactos filesystem name strings functions emulation of libcaptive * Copyright (C) 2002 Jan Kratochvil * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; exactly version 2 of June 1991 is required * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" #include "reactos/ddk/fsfuncs.h" /* self */ #include #include "captive/unicode.h" #include "reactos/unicode.h" /* for ANSI_* */ #include "captive/macros.h" #include UCHAR **FsRtlLegalAnsiCharacterArray; /** * captive_FsRtlLegalAnsiCharacterArray_init: * Initialize #FsRtlLegalAnsiCharacterArray character classes * by appropriate #FSRTL_FAT_LEGAL etc. flags. */ void captive_FsRtlLegalAnsiCharacterArray_init(void) { static UCHAR *array; guint ui; /* Use allocation instead of static array to get ElectricFence sanity boundaries. * Use even the negative 0x80 part as someone may access 'FsRtlLegalAnsiCharacterArray' * with 'signed char' (but also with 'unsigned char'). See also memcpy(3) below. */ captive_new0n(array,0x80+0x100); array+=0x80; for (ui=0;ui<0x100;ui++) { UCHAR f=0; if (isalnum(ui)) f|=FSRTL_FAT_LEGAL; if (isalnum(ui)) f|=FSRTL_HPFS_LEGAL; if (isalnum(ui)) f|=FSRTL_NTFS_LEGAL; if (ui=='*' || ui=='?') f|=FSRTL_WILD_CHARACTER; if (isalnum(ui)) f|=FSRTL_OLE_LEGAL; array[(unsigned int)(unsigned char)ui]=f; } memcpy(array-0x80,array+0x80,0x80*sizeof(*array)); FsRtlLegalAnsiCharacterArray=&array; } /** * FsRtlDoesNameContainWildCards: * @Name: Filename to check for wildcards. * %NULL value is forbidden. * Non-zero terminated #PUNICODE_STRING is permitted. * * Check if @Name contains wildcard markers as its substring(s). * * Returns: %TRUE if @Name contains "*", "?", %ANSI_DOS_STAR, %ANSI_DOS_DOT or %ANSI_DOS_QM. */ BOOLEAN FsRtlDoesNameContainWildCards(IN PUNICODE_STRING Name_nonconst) { const UNICODE_STRING *cName=Name_nonconst; const WCHAR *wcp; g_return_val_if_fail(captive_validate_UnicodeString_noterm(cName),FALSE); for (wcp=cName->Buffer;wcpBuffer+(cName->Length/sizeof(*cName->Buffer));*wcp++) if (0 || *wcp=='*' || *wcp=='?' || *wcp==ANSI_DOS_STAR || *wcp==ANSI_DOS_DOT || *wcp==ANSI_DOS_QM) return TRUE; return FALSE; } /** * FsRtlDissectName: * @Path: Initialized #UNICODE_STRING to parse. * @FirstName: Returns the first filename from @Path. * %NULL value is forbidden. * @RemainingName: Returns the part of @Path behind @FirstName. * %NULL value is forbidden. * * Will parse @Path as regex (FirstName,RemainingName)=/^\?([^/]*)/?(.*)$/; * @FirstName and @RemainingName must be pointers to allocated #UNICODE_STRING * but their #Buffer will be pointing to inside @Path buffer afterwards. * Therefore do not free it! The returned strings may not be 0-terminated strings. */ VOID FsRtlDissectName(IN UNICODE_STRING Path,OUT PUNICODE_STRING FirstName,OUT PUNICODE_STRING RemainingName) { PWSTR Path_end; PWSTR delim_FirstName_start ,delim_FirstName_end; PWSTR delim_RemainingName_start,delim_RemainingName_end; g_return_if_fail(captive_validate_UnicodeString(&Path)); g_return_if_fail(FirstName!=NULL); g_return_if_fail(RemainingName!=NULL); Path_end=Path.Buffer+Path.Length/sizeof(*Path.Buffer); delim_FirstName_start=Path.Buffer; if (delim_FirstName_startBuffer=delim_FirstName_start; FirstName->Length=(delim_FirstName_end-delim_FirstName_start)*sizeof(*FirstName->Buffer); FirstName->MaximumLength=FirstName->Length; FirstName->Buffer=delim_FirstName_start; RemainingName->Buffer=delim_RemainingName_start; RemainingName->Length=(delim_RemainingName_end-delim_RemainingName_start)*sizeof(*RemainingName->Buffer); RemainingName->MaximumLength=RemainingName->Length; RemainingName->Buffer=delim_RemainingName_start; }