- Fixed the calculated file attribute in CdfsFileFlagsToAttributes.
[reactos.git] / reactos / drivers / fs / cdfs / misc.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2002, 2004 ReactOS Team
4 *
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; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id: misc.c,v 1.7 2004/05/23 13:27:26 hbirr Exp $
20 *
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * FILE: services/fs/cdfs/misc.c
24 * PURPOSE: CDROM (ISO 9660) filesystem driver
25 * PROGRAMMER: Eric Kohl
26 * UPDATE HISTORY:
27 */
28
29 /* INCLUDES *****************************************************************/
30
31 #include <ddk/ntddk.h>
32
33 #define NDEBUG
34 #include <debug.h>
35
36 #include "cdfs.h"
37
38
39 /* FUNCTIONS ****************************************************************/
40
41
42 BOOLEAN
43 wstrcmpjoki(PWSTR s1,
44 PWSTR s2)
45 /*
46 * FUNCTION: Compare two wide character strings, s2 with jokers (* or ?)
47 * return TRUE if s1 like s2
48 */
49 {
50 while ((*s2=='*')||(*s2=='?')||(towlower(*s1)==towlower(*s2)))
51 {
52 if ((*s1)==0 && (*s2)==0)
53 return(TRUE);
54
55 if(*s2=='*')
56 {
57 s2++;
58 while (*s1)
59 if (wstrcmpjoki(s1,s2))
60 return(TRUE);
61 else
62 s1++;
63 }
64 else
65 {
66 s1++;
67 s2++;
68 }
69 }
70
71 if ((*s2)=='.')
72 {
73 for (;((*s2)=='.')||((*s2)=='*')||((*s2)=='?');s2++)
74 ;
75 }
76
77 if ((*s1)==0 && (*s2)==0)
78 return(TRUE);
79
80 return(FALSE);
81 }
82
83
84 VOID
85 CdfsSwapString(PWCHAR Out,
86 PUCHAR In,
87 ULONG Count)
88 {
89 PUCHAR t = (PUCHAR)Out;
90 ULONG i;
91
92 for (i = 0; i < Count; i += 2)
93 {
94 t[i] = In[i+1];
95 t[i+1] = In[i];
96 if (t[i+1] == 0 && t[i] == ';')
97 break;
98 }
99 t[i] = 0;
100 t[i+1] = 0;
101 }
102
103
104 VOID
105 CdfsDateTimeToFileTime(PFCB Fcb,
106 TIME *FileTime)
107 {
108 TIME_FIELDS TimeFields;
109
110 TimeFields.Milliseconds = 0;
111 TimeFields.Second = Fcb->Entry.Second;
112 TimeFields.Minute = Fcb->Entry.Minute;
113 TimeFields.Hour = Fcb->Entry.Hour;
114
115 TimeFields.Day = Fcb->Entry.Day;
116 TimeFields.Month = Fcb->Entry.Month;
117 TimeFields.Year = Fcb->Entry.Year + 1900;
118
119 RtlTimeFieldsToTime(&TimeFields,
120 (PLARGE_INTEGER)FileTime);
121 }
122
123
124 VOID
125 CdfsFileFlagsToAttributes(PFCB Fcb,
126 PULONG FileAttributes)
127 {
128 /* FIXME: Fix attributes */
129
130 *FileAttributes = // FILE_ATTRIBUTE_READONLY |
131 ((Fcb->Entry.FileFlags & FILE_FLAG_HIDDEN) ? FILE_ATTRIBUTE_HIDDEN : 0) |
132 ((Fcb->Entry.FileFlags & FILE_FLAG_DIRECTORY) ? FILE_ATTRIBUTE_DIRECTORY : 0) |
133 ((Fcb->Entry.FileFlags & FILE_FLAG_SYSTEM) ? FILE_ATTRIBUTE_SYSTEM : 0) |
134 ((Fcb->Entry.FileFlags & FILE_FLAG_READONLY) ? FILE_ATTRIBUTE_READONLY : 0);
135 }
136
137 /* EOF */