[NTFS]
[reactos.git] / drivers / filesystems / ffs / src / misc.c
1 /*
2 * FFS File System Driver for Windows
3 *
4 * misc.c
5 *
6 * 2004.5.6 ~
7 *
8 * Lee Jae-Hong, http://www.pyrasis.com
9 *
10 * See License.txt
11 *
12 */
13
14 #include "ntifs.h"
15 #include "ffsdrv.h"
16
17 /* Globals */
18
19 extern PFFS_GLOBAL FFSGlobal;
20
21
22 /* Definitions */
23
24 #ifdef ALLOC_PRAGMA
25 #pragma alloc_text(PAGE, FFSLog2)
26 #pragma alloc_text(PAGE, FFSSysTime)
27 #pragma alloc_text(PAGE, FFSInodeTime)
28 #pragma alloc_text(PAGE, FFSOEMToUnicode)
29 #pragma alloc_text(PAGE, FFSUnicodeToOEM)
30 #endif
31
32 ULONG
33 FFSLog2(
34 ULONG Value)
35 {
36 ULONG Order = 0;
37
38 PAGED_CODE();
39
40 ASSERT(Value > 0);
41
42 while (Value)
43 {
44 Order++;
45 Value >>= 1;
46 }
47
48 return (Order - 1);
49 }
50
51
52 LARGE_INTEGER
53 FFSSysTime(
54 IN ULONG i_time)
55 {
56 LARGE_INTEGER SysTime;
57
58 PAGED_CODE();
59
60 RtlSecondsSince1970ToTime(i_time, &SysTime);
61
62 return SysTime;
63 }
64
65 ULONG
66 FFSInodeTime(
67 IN LARGE_INTEGER SysTime)
68 {
69 ULONG FFSTime;
70
71 PAGED_CODE();
72
73 RtlTimeToSecondsSince1970(&SysTime, &FFSTime);
74
75 return FFSTime;
76 }
77
78
79 NTSTATUS
80 FFSOEMToUnicode(
81 IN OUT PUNICODE_STRING Unicode,
82 IN POEM_STRING Oem)
83 {
84 NTSTATUS Status;
85
86 PAGED_CODE();
87
88 Status = RtlOemStringToUnicodeString(
89 Unicode,
90 Oem,
91 FALSE);
92
93 if (!NT_SUCCESS(Status))
94 {
95 FFSBreakPoint();
96 goto errorout;
97 }
98
99 errorout:
100
101 return Status;
102 }
103
104
105 NTSTATUS
106 FFSUnicodeToOEM(
107 IN OUT POEM_STRING Oem,
108 IN PUNICODE_STRING Unicode)
109 {
110 NTSTATUS Status;
111
112 PAGED_CODE();
113
114 Status = RtlUnicodeStringToOemString(
115 Oem,
116 Unicode,
117 FALSE);
118
119 if (!NT_SUCCESS(Status))
120 {
121 FFSBreakPoint();
122 goto errorout;
123 }
124
125 errorout:
126
127 return Status;
128 }