summaryrefslogtreecommitdiffstats
path: root/private/os2/client/dllname.c
blob: a6b29c65c83fd5c07288d1f8acb016083b9ab700 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
/*++

Copyright (c) 1989  Microsoft Corporation

Module Name:

    name.c

Abstract:

    This module implements OS/2 V2.0 name processing

Author:

    Therese Stowell (thereses) 26-Sep-1989

Revision History:

    Yaron Shamir (YaronS) 7-June-91
    Move Named Pipes from \OS2SS\DRIVES\NamedPipe to
        \OS2SS\PIPE

    Yaron Shamir (YaronS) 26-Aug-91
    Support UNC. Link to \OS2SS\UNC

    Beni Lavi (BeniL) 4-Mar-92
    Support MAILSLOT. Link to \OS2SS\MAILSLOT

--*/

#define INCL_OS2V20_MEMORY
#define INCL_OS2V20_QUEUES
#define INCL_OS2V20_SEMAPHORES
#define INCL_OS2V20_ERRORS
#include "os2dll.h"
#ifdef DBCS
// MSKK Oct.20.1993 V-AkihiS
#include "conrqust.h"
#include "os2win.h"
#endif

APIRET
VerifyDriveExists(
    IN ULONG DiskNumber
    );

#ifdef DBCS
// MSKK Oct.27.1993 V-Akihis
CHAR Od2InvalidCharacters[]= { '"',
                               '/',
                               (CHAR)OBJ_NAME_PATH_SEPARATOR,
                               ':',
                               '<',
                               '|',
                               '>',
                               '\0'
                              };

CHAR Od2FatInvalidCharacters[]= { '"',
                                  '/',
                                  (CHAR)OBJ_NAME_PATH_SEPARATOR,
                                  '[',
                                  ']',
                                  ':',
                                  '<',
                                  '|',
                                  '>',
                                  '+',
                                  '=',
                                  ';',
                                  ',',
                                  '\0'
                                 };
#else
CHAR Od2InvalidCharacters[]= { '"',
                               '/',
                               (CHAR)OBJ_NAME_PATH_SEPARATOR,
                               '[',
                               ']',
                               ':',
                               '<',
                               '|',
                               '>',
                               '+',
                               '=',
                               ';',
                               ',',
                               '\0'
                              };
#endif

//character devices:
//  emulate existence of "default" devices
//  maintain list of installed devices.  symbolic link to real name.
//
//question:  what if device exists not in \DEV\ directory and process opens it?
//
//name processing
//
//    - map all /s to \s
//    - process . and ..s
//    - prepend current directory to relative paths
//    - remove trailing blanks and dots
//    - detect UNC.  compact multiple leading \s
//    - compact multiple \s
//    - detect pipe.  disallow leading d:
//    - detect installed and "default" devices
//    - detect illegal chars?
//
//
//    detect device (in list of default/installed devices)
//    detect UNC (multiple leading \\s)
//    detect PIPE (leading \PIPE\)
//    if !(UNC || PIPE) && relative path
//   prepend current directory
//    process . and ..s
//    map all /s to \s
//    remove trailing blanks and dots
//
//

BOOLEAN
TestForPipe(
    IN PSZ name
    )

/*++

Routine Description:

    This routine determines whether a filename is a pipe name.

Arguments:

    name - filename to test

Return Value:

    BOOLEAN - TRUE if the filename is a pipe name.  FALSE
        otherwise

--*/

{
    while (ISSLASH(*name)) {  // eat any extra slashes
        name++;
    }
    if (_strnicmp(name,"pipe",4)) {
        return FALSE;
    }
    if (!(ISSLASH(*(name+4)))) {
        return FALSE;
    }
    return TRUE;
}

BOOLEAN
TestForMailslot(
    IN PSZ name
    )

/*++

Routine Description:

    This routine determines whether a filename is a mailslot name.

Arguments:

    name - filename to test

Return Value:

    BOOLEAN - TRUE if the filename is a mailslot name.  FALSE
        otherwise

--*/

{
    while (ISSLASH(*name)) {  // eat any extra slashes
        name++;
    }
    if (_strnicmp(name,"mailslot",8)) {
        return FALSE;
    }
    if (!(ISSLASH(*(name+8)))) {
        return FALSE;
    }
    return TRUE;
}

PSZ
FindLastComponent(
    IN PSZ String
    )

/*++

Routine Description:

    This routine finds the last component in a string.  the string has not
    been canonicalized.

Arguments:

    String - string to examine

Return Value:

    pointer to last component

--*/

{
    PSZ LastComponent;

#ifdef DBCS
// MSKK Apr.11.1993 V-AkihiS
    if ((!Ow2NlsIsDBCSLeadByte(String[COLON-1], SesGrp->DosCP)) && String[COLON] == ':') {
#else
    if (String[COLON] == ':') {
#endif
        LastComponent = String+FIRST_SLASH;
    }
    else {
        LastComponent = String;
    }
    while (*String) {
#ifdef DBCS
// MSKK Apr.11.1993 V-AkihiS
        if (Ow2NlsIsDBCSLeadByte(*String, SesGrp->DosCP)) {
            String++;
            if (*String) {
                String++;
            }
        }
        else {
            if (ISSLASH(*String))
                LastComponent = String;
            String++;
        }
#else
        if (ISSLASH(*String))
        LastComponent = String;
        String++;       // BUGBUG make dbcs-correct
#endif
    }
    if (ISSLASH(*LastComponent))
        return LastComponent+1;
    else
        return LastComponent;
}

/*
;***    DOSICANONICALIZE - Convert a path name into a standard format
;
;       INTERNAL ONLY API.  Used by a couple of dynamic link libraries.
;       The worker routine does NO error checking or memory protection
;       checks.  It is possible to general an internal error if used
;       incorrectly.  DO NOT PUBLISH.
;
;       INVOKE  PUSH@   ASCIIZ  Source          (2 words)
;               PUSH@   ASCIIZ  Dest            (2 words)
;               PUSH    WORD    BackupOffset    (1 word)
;               PUSH    WORD    DestEnd         (1 word)
;               PUSH    WORD    Flags           (1 word)
;               call    DOSICANONICALIZE
;
;       RETURN  (ax) = error code
;
*/
void DosICanonicalize(PCHAR Source, PCHAR Dest, USHORT BackupOffset,
                      USHORT DestEnd, USHORT Flags)
{
    PCHAR SourcePtr,DestPtr;
    char Buffer[256];
    STRING tmpstr;

    tmpstr.Length=0;
    tmpstr.MaximumLength=256;
    tmpstr.Buffer=Buffer;

    SourcePtr = Source + BackupOffset;
    DestPtr = Dest + BackupOffset;

    Od2Canonicalize(
        SourcePtr,
        CANONICALIZE_FILE_DEV_OR_PIPE,
        &tmpstr,
        NULL,                         // OUT PHANDLE DirectoryHandle OPTIONAL,
        NULL,                         // OUT PULONG ParseFlags OPTIONAL,
        NULL                          // OUT PULONG FileType OPTIONAL
              );
    strncpy(DestPtr,tmpstr.Buffer,DestEnd-BackupOffset);
}

APIRET
Od2Canonicalize(
    IN PSZ Name,
    IN ULONG ExpectedType,
    OUT PSTRING CanonicalString,
    OUT PHANDLE DirectoryHandle OPTIONAL,
    OUT PULONG ParseFlags OPTIONAL,
    OUT PULONG FileType OPTIONAL
    )

/*++

Routine Description:

    This routine canonicalizes a filename and determines its type, based
    on naming conventions.

Arguments:

    Name - Supplies a pointer to a null terminated path name that will be
        parsed.

    ExpectedType - Supplies the expected type of the path string that will be
        parsed.  Any of the following:

        CANONICALIZE_FILE_DEV_OR_PIPE - the input path must refer to either
            a local file or device name, a UNC file name, or a named pipe.

        CANONICALIZE_FILE_OR_DEV - the input path must refer to either
            a local file or device name, or a UNC file name.  Named pipes
            are treated as local files.  Used by DosMove for renaming
            files that begin with \pipe

        CANONICALIZE_SHARED_MEMORY - the input path must refer to a shared
            memory section.  This means it must begin with \sharemem\

        CANONICALIZE_SEMAPHORE - the input path must refer to a 32-bit
            semaphore name.  This means it must begin with \sem32\

        CANONICALIZE_QUEUE - the input path must refer to a 32-bit queue
            name.  This means it must begin with \queues\

        CANONICALIZE_MAILSLOT - the input path must refer to a mailslot
            name.  This means it must begin with \mailslot\ or \\*\mailslot\

    CanonicalString - Supplies a pointer to a counted string that will be
        set to point to a buffer containing the result of canonicalizing
        the input path string.  The space for the buffer is allocated
        from the heap specified by the OutputHeap parameter or Od2Heap
        if that parameter is not specified.

    DirectoryHandle - Supplies an optional pointer to a place to store an
        NT Directory handle if the output string can be expressed as a
        relative path string, relative to a current directory.  If this
        parameter is not specified or if the returned directory handle is
        NULL then the canonical path string placed in OutputString will
        be a fully qualified path string.

    ParseFlags - Supplies an optional pointer to flags will be used to
        return information about the results of the parse.

        This parameter is ignored if the ExpectedType parameter is
        anything other than CANONICALIZE_FILE_DEV_OR_PIPE or
        CANONICALIZE_FILE_OR_DEV.

        Flag values set by this function:

        CANONICALIZE_META_CHARS_FOUND - the path name contains either an
            asterisk (*) and/or question marks (?) in the last component
            of the output string.

        CANONICALIZE_IS_ROOT_DIRECTORY - the output string specifies a root
            directory (e.g. D:\).

    FileType - Supplies an optional pointer to a place to store the type
        of object the canonical path string describes.  Possible values
        are:

            FILE_TYPE_FILE
            FILE_TYPE_NMPIPE
            FILE_TYPE_DEV
            FILE_TYPE_PSDEV
            FILE_TYPE_MAILSLOT

        This parameter is ignored if the ExpectedType parameter is
        anything other than CANONICALIZE_FILE_DEV_OR_PIPE,
        CANONICALIZE_FILE_OR_DEV or CANONICALIZE_MAILSLOT.

Return Value:

    OS/2 Error Code

Return Value:

    ERROR_FILE_NOT_FOUND - the filename is invalid.

Note:

    This routine allocates a buffer to hold the canonicalized name.  it
    is the caller's responsibility to free this buffer.

Pseudocode:
    determine expected prefix
    if (file_pipe_or_dev)
        detect UNC - insert correct prefix
        detect devices - insert correct prefix
        insert drive letter if needed - insert correct prefix
        insert current directory if needed
    else
        check for ///prefix/
        insert correct prefix
    copy string, removing . and .., checking for illegal characters,
       detecting metacharacters

Routine Description:

    This function performs the OS/2 V2.0 Path Name canonicalization
    function.  It takes as input a pointer to a null terminated string
    that is considered unprobed, along with flags that specify optional
    behavior while parsing the path string.  The output of this function
    is a canonical path string that is in NT format.  The OS/2 Subsystem
    creates the following objects in the NT Object Name Space in order
    to support the output of this function:

        \OS2SS                   object directory
        \OS2SS\DRIVES            object directory
        \OS2SS\DRIVES\A:         symbolic link => \Device\Floppy0
        \OS2SS\DRIVES\C:         symbolic link => \Device\Harddisk0\Partition1
        \OS2SS\DRIVES\D:         symbolic link => \Device\Harddisk1\Partition1
        \OS2SS\PIPE              symbolic link => \DosDevices\PIPE
        \OS2SS\UNC               symbolic link => \DosDevices\UNC
        \OS2SS\DEVICES           object directory
        \OS2SS\DEVICES\NUL       symbolic link => @0
        \OS2SS\DEVICES\CON       symbolic link => @1
        \OS2SS\DEVICES\AUX       symbolic link => @2
        \OS2SS\DEVICES\COM1      symbolic link => @2.0
        \OS2SS\DEVICES\COM2      symbolic link => @2.1
        \OS2SS\DEVICES\COM3      symbolic link => @2.2
        \OS2SS\DEVICES\COM4      symbolic link => @2.3
        \OS2SS\DEVICES\PRN       symbolic link => @3
        \OS2SS\DEVICES\LPT1      symbolic link => @3.0
        \OS2SS\DEVICES\LPT2      symbolic link => @3.1
        \OS2SS\DEVICES\LPT3      symbolic link => @3.2
        \OS2SS\DEVICES\KBD$      symbolic link => @4
        \OS2SS\DEVICES\MOUSE$    symbolic link => @5
        \OS2SS\DEVICES\CLOCK$    symbolic link => @6
        \OS2SS\DEVICES\SCREEN$   symbolic link => @7
        \OS2SS\DEVICES\POINTER$  symbolic link => @8
        \OS2SS\QUEUES            object directory
        \OS2SS\SHAREMEM          object directory
        \OS2SS\SEMAPHORES        object directory

    The actual drive letters that will be defined in the \OS2SS\DRIVES
    object directory actually depend upon the hardware configuration you
    are running on.  The above is an example for a particular machine.
    Also notice that the GlobalDFS link actually is the same as the
    LocalDFS link, namely the redirector.  This will be true until we
    implement a real name service file system.

    Listed below are some examples of OS/2 path strings and the desired
    NT path string.  These examples assume the current drive and
    directory for the OS/2 application are C:\Os2\Dll

        OS/2 Path                       NT Path

        pmwin.dll                       \OS2SS\DRIVES\C:\Os2\Dll\pmwin.dll
        c:pmwin.dll                     \OS2SS\DRIVES\C:\Os2\Dll\pmwin.dll
        C:\os2\dll\pmwin.dll            \OS2SS\DRIVES\C:\os2\dll\pmwin.dll
        c:\DLL\..\pmwin.dll             \OS2SS\DRIVES\C:\Os2\DLL\pmwin.dll
        c:\OS2\.\DLL\..\..\pmwin.dll    \OS2SS\DRIVES\C:\OS2\DLL\pmwin.dll
        \\mach\shr\a\b\c                \OS2SS\DRIVES\LocalDFS\mach\shr\a\b\c
        \\\mach\shr\a\b\c               \OS2SS\DRIVES\GlobalDFS\mach\shr\a\b\c
        \pipe\a\b\c\pipe.C              \OS2SS\DRIVES\PIPE/a/b/c/pipe.C
        con                             @1 - internal pseudo device
        c:clock$                        @6 - internal pseudo device
        \a\b\c\screen$                  @7 - internal pseudo device
        \queUES\a\b\c\..\..\..\que.     \OS2SS\QUEUES\QUE
        \shaREmem\a\b\c\.\mem.c         \OS2SS\SHAREDMEMORY\A/B/C/MEM.C
        \sem32\a\b\c\..\sem.b           \OS2SS\SEMAPHORES\A/B/SEM.B

    Notice that for the last three examples, the output string contains
    forward slashes instead of the normal backslash path separator.
    This allows the names to be stored in the NT Object Name Space
    without having to create the implied directory structure.  The
    NamedPipes example also does this, although this can be changed
    if the NamedPipe File System is integrated into the NT Pinball File
    System.

    Also for the first five examples, since each NT path begins with the
    current drive and directory, the output path returned by this function
    will be just the file name, pmwin.dll and the NT handle that points
    to the current directory of C: (i.e. \OS2SS\DRIVES\C:\Os2\Dll).  This
    allows cheaper relative opens to be used for most opens of files.

    What follows is a description of how this function parses the input
    path string:

        - first allocates a buffer from Od2Heap.  The buffer is large
          enough to contain the longest possible OS/2 path string, plus
          the space implied by the length of the input path string.

        - figures out what prefix to use based on expected file type.

        - if a file system path is expected (file, pipe, unc, or device),
          determines what type of path is input.  the correct constant prefix is
          copied to the beginning of the buffer.  A UNC path is first detected
          by checking for two leading slashes.  If "\\" is found,
          "\OS2SS\UNC" is copied to the buffer.
          Then the server name is copied to the buffer.  The end of the server name is the backup limit for
          '..' processing.  Then a pipe path is checked for by looking for the
          "PIPE" prefix at the beginning of the path.  If it is found,
          "\OS2SS\PIPE" is copied into the buffer.  Also
          set a flag so that all backslash path separator characters in the
          output string will be mapped to forward slashes.  The end of the
          \pipe\ prefix is the backup limit for ".." processing.  If the
          path is not UNC or pipe, a device path is checked for by doing the
          following:

              lookup the trailing component of the output path string in
              the \OS2SS\DEVICES directory as a symbolic link.  If found
              then extract the target string of the symbolic link and
              parse it as follows:

                @n[.m] - specifies a pseudo-device that is builtin to
                the OS/2 Emulation subsystem.  n is a decimal, zero
                based index into the pseudo-device table.  The ".m" is
                optional and if present, m is a decimal, zero based
                number that represents the unit number.  For devices
                with unit numbers, if m is not present a default unit
                number should be used (zero in most cases).  In either
                case the type returned is FILE_TYPE_PSDEV.  The caller
                should key off of this type to determine if it should
                parse the contents of the canonical name string.

                NT Path String - specifies a fully qualified name of a
                physical device.  The type returned is FILE_TYPE_DEV

          If the path is not a device, it is assumed to be a file.  The
          drive letter and current directory are copied to buffer if needed.
          The buffer will contain \OS2SS\DRIVES\d:\currentdir at this point.
          The slash after the drive letter is the backup limit for ".."
          processing.

          The filetype is set according to the type of path found.

        - if a non-file system path is expected, the expected prefix is
          verified and the constant and expected prefixes are copied to the
          buffer.

          if the ExpectedType parameter is CANONICALIZE_QUEUES, then see
          if the beginning of the input path string matches \QUEUES\
          ignoring case.  If they do not match, then the
          ERROR_PATH_NOT_FOUND error code is returned from this
          function.  Also set a flag so that all backslash path
          separator characters in the output string will be mapped
          to forward slashes.  If it does match then \OS2SS\QUEUES\QUEUES
          is copied to the buffer.  The end of the second QUEUES prefix
          is the backup limit for ".." processing.

          if the ExpectedType parameter is CANONICALIZE_SEMAPHORE, then
          see if the beginning of the input path string matches \SEM32\
          ignoring case.  If they do not match, then the
          ERROR_PATH_NOT_FOUND error code is returned from this
          function.  Also set a flag so that all backslash path
          separator characters in the output string will be mapped to
          forward slashes.  If it does match then \OS2SS\SEMAPHORES\SEM32
          is copied to the buffer.  The end of the SEM32 prefix
          is the backup limit for ".." processing.

          if the ExpectedType parameter is CANONICALIZE_SHARED_MEMORY,
          then see if the beginning of the input path string matches
          \SHAREMEM\ ignoring case.  If they do not match, then the
          ERROR_PATH_NOT_FOUND error code is returned from this
          function.  Also set a flag so that all backslash path
          separator characters in the output string will be mapped
          to forward slashes.  If it does match then
          \OS2SS\SHAREDMEMORY\SHAREMEM is copied to the buffer.  The end of
          the SHAREMEM prefix is the backup limit for ".." processing.

        - copies the unprobed remainder of the input path string to the
          allocated buffer, performing the following logic for each character:

            - if an access violation exception occurs when fetching a
              character from the input path string, the ERROR_INVALID_ADDRESS
              error code is returned as the value of this function.

            - forward slash (/) path separators into are converted to the
              NT path separator character (OBJ_NAME_PATH_SEPARATOR).

            - meta characters (* and ?) are detected.  If found before a
              path separator then the ERROR_PATH_NOT_FOUND error code is
              returned as the value of this function.

            - if the ExpectedType parameter is neither of
              CANONICALIZE_FILE_DEV_OR_PIPE or CANONICALIZE_FILE_OR_DEV,
              then lower case letters are converted to upper case when
              they are copied to the output buffer.

            - if the ExpectedType parameter is neither of
              CANONICALIZE_FILE_DEV_OR_PIPE or CANONICALIZE_FILE_OR_DEV and
              meta characters are detected then the ERROR_PATH_NOT_FOUND error
              code is returned as the value of this function.

            - if the input string begins with a character followed by a
              colon (:), then map the drive letter to upper case.

            - sequences one or more adjacent backslashes
              (OBJ_NAME_PATH_SEPARATOR) are converted to a single backslash.

            - process '.' and '..' path components.  '.' are removed.  '..'
              components cause the immediately previous component to be
              removed.  i.e.  d:\foo\..\bar -> d:\bar.  An error is returned
              if there is no component to remove.

            - If specified by the earlier logic, the trailing path separator
              of each component is set to be a forward slash after the copy.
              This basically maps any multiple component path string into a
              single component name.

            - After copying each path component, remove trailing blanks
              and periods.  If the last path component contained meta
              characters then put a trailing period at the end of the last
              component if it does contained one or more trailing periods
              already.

            - when unicode strings are put into the system, the code page to
              unicode conversion will happen in this step.

            - return the type of path via the FileType parameter, which
              must be specified if the ExpectedType parameter is
              CANONICALIZE_FILE_DEV_OR_PIPE or CANONICALIZE_FILE_OR_DEV.

    - if this function returns an error code instead of NO_ERROR then
      free the output buffer that was allocated.  Otherwise set the
      Length and Maximum length fields in the counted string pointed
      to by the OutputString parameter.

--*/

{
    PSZ Dest,
    Src,
    LastComponent,
    BackUpLimit;
    CHAR c;
    ULONG Drive;
    PSTRING CurrentDirectoryString;
    HANDLE CurrentDirectoryHandle;
    ULONG CurrentDirectoryLength;
    PSZ NameBuffer;
    ULONG NameBufferLength;
    APIRET RetCode;
    PSZ PipePrefix;
    PSZ MailslotPrefix;
    PSZ UNCPrefix;
    PSZ ExpectedPrefix;
    PSZ ConstantPrefix;
    PSZ Os2Name;
    int RemoveBlanksAndDots;
    ULONG ExpectedPrefixLength;
    BOOLEAN MetaCharactersAllowed;
    BOOLEAN PreserveCase;
    BOOLEAN MapToRootName;
    BOOLEAN ValidateChars;
    ULONG OutputFlags;
    ULONG OutputType;
    NTSTATUS Status;
    HANDLE DeviceHandle;
    OBJECT_ATTRIBUTES ObjectAttributes;
    STRING DeviceName;
    UNICODE_STRING DeviceName_U;
    WCHAR DeviceNameBuffer[ CCHMAXPATH ];
#ifdef DBCS
// Oct.27.1993 V-AkihiS
    CHAR *InvalidCharacters = Od2InvalidCharacters;
#endif

#if DBG
    IF_OD2_DEBUG( FILESYS ) {
        DbgPrint( "Od2Canonicalize: entering with path %s\n", Name);
    }
#endif

    PipePrefix = NULL;
    MailslotPrefix = NULL;
    UNCPrefix = NULL;
    PreserveCase = FALSE;
    MetaCharactersAllowed = FALSE;
    MapToRootName = TRUE;
    ValidateChars = TRUE;
    OutputType = 0xFFFFFFFF;
    OutputFlags = 0;
    CurrentDirectoryString = NULL;
    CurrentDirectoryHandle = NULL;
    Os2Name = NULL;
    RetCode = NO_ERROR;

    //
    // determine the expected and constant prefixes of the path,
    // where the constant prefix is the
    //

    switch( ExpectedType ) {
        case CANONICALIZE_FILE_DEV_OR_PIPE:
        case CANONICALIZE_FILE_OR_DEV:
        case CANONICALIZE_MAILSLOT:
            PipePrefix = "\\PIPE\\";
            UNCPrefix = "\\UNC\\";
            ExpectedPrefix = NULL;
            ConstantPrefix = "\\OS2SS\\DRIVES";
            PreserveCase = TRUE;
            MetaCharactersAllowed = TRUE;
            MapToRootName = FALSE;
            OutputType = FILE_TYPE_FILE;
            MailslotPrefix = "\\MAILSLOT\\";
            break;

        case CANONICALIZE_SHARED_MEMORY:
            ExpectedPrefix = DA_SHAREMEM_NAMEPREFIX;
            ConstantPrefix = "\\OS2SS\\SHAREMEM";
            break;

        case CANONICALIZE_SEMAPHORE:
            ExpectedPrefix = DC_SEM_NAMEPREFIX;
            ConstantPrefix = "\\OS2SS\\SEMAPHORES";
            break;

        case CANONICALIZE_QUEUE:
            ExpectedPrefix = DC_QUEUES_NAMEPREFIX;
            ConstantPrefix = "\\OS2SS\\QUEUES";
            break;

        default:
            return( ERROR_INVALID_FUNCTION );
    }

    if (ExpectedPrefix != NULL) {
        ExpectedPrefixLength = strlen( ExpectedPrefix );
    }

    try {
        if (*Name == '\0')
             return ERROR_FILE_NOT_FOUND;

        if (*Name == ' ' && *(Name+1) == '\0')
             return ERROR_PATH_NOT_FOUND;

        //
        // initialize DirectoryHandle to indicate full path returned.
        //

        if (DirectoryHandle != NULL) {
            *DirectoryHandle = NULL;
        }

        //
        // allocate name buffer.  make it big enough that we can't overrun the
        // end of it.
        //

        NameBufferLength = CCHMAXPATH + strlen(Name)+ CANONICALIZE_MAX_PREFIX_LENGTH;
    } except( EXCEPTION_EXECUTE_HANDLER ) {
       Od2ExitGP();
    }

    if (( NameBuffer = RtlAllocateHeap(Od2Heap,0,NameBufferLength)) == NULL )
    {
        return(ERROR_NOT_ENOUGH_MEMORY);
    }
    Dest = NameBuffer;
    Src = Name;



    //
    // if we're doing a canonicalization for an IO system API (a file, device,
    // UNC, or pipe name is expected), we
    //    detect UNC - insert correct prefix
    //    detect devices - insert correct prefix
    //    insert drive letter if needed - insert correct prefix
    //    insert current directory if needed
    //

    if ((ExpectedType == CANONICALIZE_FILE_DEV_OR_PIPE) ||
        (ExpectedType == CANONICALIZE_FILE_OR_DEV) ||
        (ExpectedType == CANONICALIZE_MAILSLOT)
       ) {

        //
        // detect UNC and pipe names
        //
        // NOTES on UNC naming conventions:
        //
        //   Two or three leading slashes are OK, and unmodified.
        //
        //   Four or more leading slashes are compressed to three
        //    leading slashes.
        //
        //   Any number of slashes as a separator, in a local or UNC
        //    path, are compressed to a single slash.
        //
        // The \\ is a short hand for the 'current name space' whereas
        // three slashes are the root of the world-wide name space.
        //
        //

        CurrentDirectoryString = NULL;
        if (ISSLASH(Src[0])) {
            if (ISSLASH(Src[1])) {
#if DBG
                IF_OD2_DEBUG( FILESYS ) {
                    DbgPrint( "processing UNC name\n");
                }
#endif
                OutputType = FILE_TYPE_UNC;

                //
                // copy constant prefix to buffer
                //
                ConstantPrefix = "\\OS2SS";
                while (*Dest++ = *ConstantPrefix++)
                    ;
                Dest--;

                Os2Name = Dest;   // Os2Name points to beginning of OS/2 name

                while (*Dest++ = *UNCPrefix++)
                    ;
                Dest--;

                Src += 2;    // for the two slashes
                if (ISSLASH(*Src)) {
                   RetCode = ERROR_BAD_NETPATH;
                   goto ErrorExit;      // go free buffer(s) and return error
                }

                Os2Name = Dest-1;   // Os2Name points to beginning of OS/2 name

                /*
                   path is \OS2SS\UNC\
                   copy the server name.
                */

                while (!ISPATHSEP(*Src)) {
                    if ((*Src == '?') ||
                        ((*Src == '*') && (ExpectedType != CANONICALIZE_MAILSLOT))) {
                                RetCode = ERROR_BAD_NETPATH;
                        goto ErrorExit;
                    }
#ifdef JAPAN
// MSKK Feb.18.1993 V-AkihiS
                    if (Ow2NlsIsDBCSLeadByte(*Src, SesGrp->DosCP)) {
                        *Dest++ = *Src++;
                        if (*Src) {
                            //
                            // Check Trailing byte is valid or not.
                            //
                            if ((UCHAR)*Src < 0x40 || (UCHAR)*Src > 0xFC || (UCHAR)*Src == 0x7F) {
                                        RetCode = ERROR_BAD_NETPATH;
                                goto ErrorExit;
                            } else {
                                *Dest++ = *Src++;
                            }
                        } else {
                                    RetCode = ERROR_BAD_NETPATH;
                            goto ErrorExit;
                        }
                    }
                    else {
                        if (ValidateChars && ((UCHAR)*Src < (UCHAR)' ' ||
                                              strchr( InvalidCharacters, *Src )
                                             )
                           ) {
                                    RetCode = ERROR_BAD_NETPATH;
                            goto ErrorExit;
                        }
                        *Dest++ = *Src++;
                    }
#else
                    if (ValidateChars && ((UCHAR)*Src < (UCHAR)' ' ||
                                          strchr( Od2InvalidCharacters, *Src )
                                         )
                       ) {
                                RetCode = ERROR_BAD_NETPATH;
                        goto ErrorExit;
                    }
                    *Dest++ = *Src++;
#endif
                }
                if (*Src == '\0') {
                        RetCode = ERROR_BAD_NETPATH;
                    goto ErrorExit;      // go free buffer(s) and return error
                }
                *Dest++ = (CHAR)OBJ_NAME_PATH_SEPARATOR;              // append '\'
                Src++;
                while (ISSLASH(*Src))
                    Src++;
                BackUpLimit = Dest;    // set up backup pointer. points after server name

                /*
                   at this point, we have a UNC name composed of
                              \OS2SS\UNC\servername\
                                                    ^
                                                    |
                                                   dest

                     \\\\servername\\\sharepoint
                                      ^
                                      |
                                     src
                */
            }
            else if (TestForPipe(Src)) {    // \PIPE\ ?
#if DBG
                IF_OD2_DEBUG( FILESYS ) {
                    DbgPrint( "processing pipe name\n");
                }
#endif
                OutputType = FILE_TYPE_NMPIPE;

                //
                // this code assumes that pipes are in \OS2SS
                // copy \OS2SS\PIPE into buffer
                //

            //
            // we can't use drives for pipes
            // (see ..\server\srvname.c)
            //
                ConstantPrefix = "\\OS2SS";
                while (*Dest++ = *ConstantPrefix++)
                    ;
                Dest--;

                Os2Name = Dest;   // Os2Name points to beginning of OS/2 name

                while (*Dest++ = *PipePrefix++)
                    ;
                Dest--;

                /*
                   update src pointer past \pipe\
                */

                while (ISSLASH(*Src))   // eat any extra slashes
                    Src++;
                Src += 5;
                while (ISSLASH(*Src))   // eat any extra slashes
                    Src++;
                if (*Src == '\0') {
                    RetCode = ERROR_FILE_NOT_FOUND;
                    goto ErrorExit;      // go free buffer(s) and return error
                }
                ValidateChars = TRUE;
                BackUpLimit = Dest;    // set up backup pointer. points after "\pipe\"
            }
            else if (TestForMailslot(Src)) {    // \MAILSLOT\ ?
#if DBG
                IF_OD2_DEBUG( FILESYS ) {
                    DbgPrint( "processing mailslot name\n");
                }
#endif
                OutputType = FILE_TYPE_MAILSLOT;

                //
                // this code assumes that mailslots are in \OS2SS
                // copy \OS2SS\MAILSLOT into buffer
                //

                //
                // we can't use drives for maislots
                // (see ..\server\srvname.c)
                //
                ConstantPrefix = "\\OS2SS";
                while (*Dest++ = *ConstantPrefix++)
                    ;
                Dest--;

                Os2Name = Dest;   // Os2Name points to beginning of OS/2 name

                while (*Dest++ = *MailslotPrefix++)
                    ;
                Dest--;

                /*
                   update src pointer past \mailslot\
                */

                while (ISSLASH(*Src))   // eat any extra slashes
                    Src++;
                Src += 9;
                while (ISSLASH(*Src))   // eat any extra slashes
                    Src++;
                if (*Src == '\0') {
                    RetCode = ERROR_FILE_NOT_FOUND;
                    goto ErrorExit;      // go free buffer(s) and return error
                }
                ValidateChars = TRUE;
                BackUpLimit = Dest;    // set up backup pointer. points after "\pipe\"
            }
        }

        // haven't detected pipe or UNC
        if (OutputType == FILE_TYPE_FILE) {

#ifdef DBCS
// MSKK Oct.27.1993 V-AkihIS
            InvalidCharacters = Od2FatInvalidCharacters;
#endif
            /*
               detect devices here.
               device names are recognized as follows:
                    installed/default devices are allowed in any d:\path
                    pseudochar devices must match exactly, starting with \DEV\
            */

            LastComponent = FindLastComponent(Src);

            if (*LastComponent)
            {
                PWSTR DotPlace;
                USHORT NewLen;

                //
                // Open as a symbolic link, relative to the OS/2 Device Directory in the
                // object name space, the last component of the file path.
                //

                Od2InitMBString( &DeviceName, LastComponent );

                    //
                    // UNICODE conversion -
                    //

                RetCode = Od2MBStringToUnicodeString(
                                &DeviceName_U,
                                &DeviceName,
                                TRUE);

                if (RetCode)
                {
#if DBG
                    IF_OD2_DEBUG( FILESYS )
                    {
                        DbgPrint("Od2Canonicalize: no memory for Unicode Conversion\n");
                    }
#endif
                    //return RetCode;
                    goto ErrorExit;
                }

                for (DotPlace = DeviceName_U.Buffer, NewLen = 0;
                     NewLen < DeviceName_U.Length;
                     DotPlace++, NewLen += sizeof(WCHAR)) {

                    if ((*DotPlace == L'.') || (*DotPlace == L' ')) {

                        DeviceName_U.Length = NewLen;
                        break;
                    }
                }

                InitializeObjectAttributes( &ObjectAttributes,
                                            &DeviceName_U,
                                            OBJ_CASE_INSENSITIVE,
                                            Od2DeviceDirectory,
                                            NULL
                                          );

                Status = NtOpenSymbolicLinkObject( &DeviceHandle,
                                                   SYMBOLIC_LINK_QUERY,
                                                   &ObjectAttributes
                                                 );
                RtlFreeUnicodeString (&DeviceName_U);
                if (NT_SUCCESS( Status )) {

#if DBG
                    IF_OD2_DEBUG( FILESYS ) {
                        DbgPrint( "processing device name\n");
                    }
#endif
                    //
                    // Found a symbolic link in the OS/2 Device Directory whose
                    // name matches the last component of the file path.  Query
                    // the target string from the symbolic link.
                    //

                    DeviceName_U.Length = 0;
                    DeviceName_U.MaximumLength = sizeof( DeviceNameBuffer );
                    DeviceName_U.Buffer = DeviceNameBuffer;
                    Status = NtQuerySymbolicLinkObject( DeviceHandle,
                                                        &DeviceName_U,
                                                        NULL
                                                      );
                    NtClose(DeviceHandle);
                    if (NT_SUCCESS( Status )) {
                        //
                        // Successfully queried the target string, so copy it as
                        // is to the output path buffer, obliterating what was there.
                        // Next determine the file type by examining the first
                        // character of the target string.  @n is a pseudo-device
                        // builtin to the OS/2 subsystem.  Otherwise it is a physical
                        // NT device path.
                        //

                        RetCode = Od2UnicodeStringToMBString( &DeviceName, &DeviceName_U, TRUE );
                        if (RetCode)
                        {
#if DBG
                            IF_OD2_DEBUG( FILESYS )
                            {
                                DbgPrint("Od2Canonicalize: no memory for Unicode Conversion-2\n");
                            }
#endif
                            //return RetCode;
                            goto ErrorExit;
                        }

                        strncpy( Dest,
                                 &DeviceName.Buffer[1],
                                 DeviceName.Length - 1
                               );

                        *(Dest + DeviceName.Length - 1) = '\0'; // for debug printing

                        if (DeviceName.Buffer[0] == '@') {
                            OutputType = FILE_TYPE_PSDEV;
                        }
                        else if (DeviceName.Buffer[0] == '#') {
                            OutputType = FILE_TYPE_COM;
                        }
                        else {
                            OutputType = FILE_TYPE_DEV;
                        }
                        CanonicalString->MaximumLength = (USHORT) NameBufferLength;
                        CanonicalString->Length = DeviceName.Length - 1;
                        CanonicalString->Buffer = NameBuffer;
                        Od2FreeMBString( &DeviceName );
                        goto ErrorExit;
                    }
                    else {
                        RetCode = ERROR_PATH_NOT_FOUND;  // FIX, FIX - Should never happen.
                        goto ErrorExit;
                    }
                }
            }
        }

        //
        // if we didn't detect a device, we have a file.  add a drive letter
        // and current directory, if necessary.
        //

        if (OutputType == FILE_TYPE_FILE) {
#if DBG
            IF_OD2_DEBUG( FILESYS ) {
                DbgPrint( "processing file name\n");
            }
#endif

            //
            // A xxxx\ is not allowed
            //
#ifdef DBCS
// MSKK Feb.26.1993 V-AkihiS
            {
                ULONG i = 0;
                BOOLEAN LastSlashFlag = FALSE;
                BOOLEAN ColonFlag = FALSE;

                //
                // Check last charater is '\' and privious character of last
                // character is not ':'. If so(i.e. LastSlashFlag is true,
                // when exiting while-loop), it is not allowed.
                //
                while (i < strlen(Name)) {
                    if (Ow2NlsIsDBCSLeadByte(Name[i], SesGrp->DosCP)) {
                        LastSlashFlag = ColonFlag = FALSE;
                        i++;
                        if (i < strlen(Name))  i ++;
                    } else {
                        if (Name[i] == ':') {
                            LastSlashFlag = FALSE;
                            ColonFlag = TRUE;
                        } else if (ISSLASH(Name[i])) {
                            if (ColonFlag) {
                                LastSlashFlag = FALSE;
                            } else {
                                LastSlashFlag = TRUE;
                            }
                            ColonFlag = FALSE;
                        } else {
                            LastSlashFlag = ColonFlag = FALSE;
                        }
                        i++;
                    }
                }
                if ( LastSlashFlag && (strlen(Name) > 1)) {
#if DBG
                    IF_OD2_DEBUG( FILESYS ) {
                        DbgPrint( "Canonicalize: filename is D:xxx\\, return ERROR_PATH_NOT_FOUND \n");
                    }
#endif
                   return(ERROR_PATH_NOT_FOUND);
                }

            }
#else
            if ( ISSLASH(Name[strlen(Name)-1]) && (strlen(Name) > 1 )
                && (Name[strlen(Name)-2] != ':') /* slash root is a fine name */ ) {
#if DBG
                IF_OD2_DEBUG( FILESYS ) {
                    DbgPrint( "Canonicalize: filename is D:xxx\\, return ERROR_PATH_NOT_FOUND \n");
                }
#endif
               return(ERROR_PATH_NOT_FOUND);
            }
#endif

            //
            // copy the constant prefix.
            //

            while (*Dest++ = *ConstantPrefix++)
                ;
            Dest--;
            *Dest++ = (CHAR)OBJ_NAME_PATH_SEPARATOR;
            Os2Name = Dest;   // Os2Name points to beginning of OS/2 name
#ifdef DBCS
// MSKK Apr.11.1993 V-AkihiS
            if (!(*(Src+1) == ':' && !IsDBCSLeadByte(*Src))) {   // if no drive letter, get one
#else
            if (*(Src+1) != ':') {   // if no drive letter, get one
#endif
                *Dest++ = CONVERTTOASCII(Od2CurrentDisk);
                *Dest++ = ':';
                Drive = Od2CurrentDisk;
            }
            else {

                // figure out which zero-based drive to use

                if (*Src > 'Z') {
                    Drive = *Src - 'a';
                }
                else {
                    Drive = *Src - 'A';
                }
                if (RetCode = VerifyDriveExists(Drive+1)){
                    return(RetCode);
                }
                *Dest++ = *Src++; // copy drive letter
                *Dest++ = *Src++;
                if (*Src == '\0') {
                    RetCode = ERROR_FILE_NOT_FOUND;
                    goto ErrorExit;      // go free buffer(s) and return error
                }
            }

            //
            // Buffer contains \\OS2SS\DRIVES\D:
            //                                  ^
            //                                  |
            //                                 dest
            //
            //  d:\foo
            //    ^
            //    |
            //   src
            //
            // set up backup pointer

            BackUpLimit = Dest;   // set up backup pointer. points to first '\'

            //
            // prepend logondirectory here
            //
            //       if (relative path)
            //          copy current directory;
            //          append '\';
            //       else
            //          copy first '\';
            //

            if (!ISSLASH(*Src)) { // if path not absolute

                //
                //  if no current directory, append '\'
                //

                *Dest++ = (CHAR)OBJ_NAME_PATH_SEPARATOR;
                RetCode = Od2GetCurrentDirectory(Drive,
                                              &CurrentDirectoryString,
                                              &CurrentDirectoryHandle,
                                              &CurrentDirectoryLength,
                                              FALSE
                                             );
                if (RetCode != NO_ERROR) {
                    goto ErrorExit;      // go free buffer(s) and return error
                }
#if DBG
                IF_OD2_DEBUG( FILESYS ) {
                    DbgPrint("GetCurrentDirectory returned %s\n",CurrentDirectoryString->Buffer);
                }
#endif
                if (CurrentDirectoryHandle != NULL) {  // if not root directory
                    CurrentDirectoryString->Length -= DRIVE_LETTER_SIZE + FILE_PREFIX_LENGTH;
                    CurrentDirectoryString->Buffer += DRIVE_LETTER_SIZE + FILE_PREFIX_LENGTH;
                    strncpy(Dest,
                            CurrentDirectoryString->Buffer,
                            CurrentDirectoryString->Length
                           );
                    Dest += CurrentDirectoryString->Length;
                    *Dest++ = (CHAR)OBJ_NAME_PATH_SEPARATOR;
                }
            }
            else {                          // copy one '\' and eat any others
                *Dest++ = (CHAR)OBJ_NAME_PATH_SEPARATOR;
                Src++;
                while (ISSLASH(*Src))
                    Src++;
            }

            /*
               the buffer contains:
                \OS2SS\DRIVES\D:\currentdir\
                                            ^
                                            |
                                           dest
                d:foo
                  ^
                  |
                 src
            */
        }
    }

    //
    // we're doing canonicalization for a non IO system API - semaphores,
    // queues, or shared memory.  we check for the expected prefix and copy
    // it to the buffer.  there can be any number of slashes anywhere in
    // the name.  i.e.  \\/\SEM32/////foo -> \SEM32\foo.
    //

    else {

        //
        // copy constant prefix to buffer
        //

        while (*Dest++ = *ConstantPrefix++)
            ;
        Dest--;

        //
        // verify that the expected prefix is there.  advance Src past
        // all leading slashes.
        //

        if (ISSLASH(*Src)) {
            do {
                Src++;
            } while (ISSLASH(*Src));

            //
            // use the strnicmp to compare for the text part of the prefix and
            // ISSLASH to compare for the trailing slash.
            //

#ifdef DBCS
// MSKK Feb.26.1993 V-AkihiS
            {
                ULONG   i = 0;
                BOOLEAN SlashFlag = FALSE;

                //
                // verify whether the last character of the text part of
                // the prefix is slash or not.
                //
                while (i < ExpectedPrefixLength - 1) {
                    if (Ow2NlsIsDBCSLeadByte(*(Src+i), SesGrp->DosCP)) {
                        SlashFlag = FALSE;
                        i++;
                        if (i < ExpectedPrefixLength - 1) {
                            i++;
                        }
                    } else {
                        if (ISSLASH(*(Src+i))) {
                            SlashFlag = TRUE;
                        } else {
                            SlashFlag = FALSE;
                        }
                        i++;
                    }
                }

                if (_strnicmp( Src, ExpectedPrefix+1, ExpectedPrefixLength-2 ) ||
                    !SlashFlag) {
                    RetCode = ERROR_PATH_NOT_FOUND;
                }
            }
#else
            if (_strnicmp( Src, ExpectedPrefix+1 , ExpectedPrefixLength-2 ) ||
                !(ISSLASH(*(Src+ExpectedPrefixLength-2)))) {
                RetCode = ERROR_PATH_NOT_FOUND;
            }
#endif

            Os2Name = Dest;   // Os2Name points to beginning of OS/2 name

            //
            // copy the expected prefix.  Make sure terminating slash is
            // the correct type.
            //

            while (c = *ExpectedPrefix++) {
                if (c == (CHAR)OBJ_NAME_PATH_SEPARATOR && MapToRootName) {
                    c = '/';
                }
                *Dest++ = c;
            }
            BackUpLimit = Dest-1;   // backup pointer. points to last '\'

            //
            // update the src pointer past the prefix and slashes
            //

            Src += ExpectedPrefixLength-1;
            while (ISSLASH(*Src)) {
                Src++;
            }

            //
            // error if nothing after expected prefix
            //

            if (*Src == '\0') {
                RetCode = ERROR_FILE_NOT_FOUND;
            }
        }
        else {
            RetCode = ERROR_PATH_NOT_FOUND;
        }

        if (RetCode) {
            goto ErrorExit;
        }

        /*                                                 target
                                                             |
                                                             V
           at this point, the target contains \OS2SS\xxx\xxx\
                                                               source
                                                                |
           the source points after the expected prefix          V
                                                        \SEM32\\
        */

     }

    /*
       copy user string

           *Dest -> first char after d:\
           *src -> first char after d:\

        if we see a metacharacter, we verify that they're allowed.  if there
        is a metacharacter in any component other than the last, we return
        an error.
    */

    LastComponent = Dest;           // LastComponent points to first letter
    while (*Src) {

        //
        // if we get here and meta characters have already been found, they
        // aren't in the last component, so we return an error.
        //

        if (OutputFlags & CANONICALIZE_META_CHARS_FOUND) {
            RetCode = ERROR_PATH_NOT_FOUND;
            goto ErrorExit;
        }
        RemoveBlanksAndDots=TRUE;

        //
        // if path is '.', copy . and don't remove dots
        //

        if ((*Src == '.') &&
            (ISPATHSEP(Src[1]))) {
            Src++;
            Dest--;
            RemoveBlanksAndDots=FALSE;
        }

        //
        // else if path is '..', copy .. and don't remove dots
        //

        else if ((Src[0] == '.') &&
                 (Src[1] == '.') ) {
            if (Src[2] == '.') {
               RetCode = ERROR_PATH_NOT_FOUND;
               goto ErrorExit;
            }
            if (ISPATHSEP(Src[2])) {
                Src += 2;      // Src points past ..
                Dest -= 2;     // Dest points to char before last path sep
#ifdef DBCS
// MSKK Feb.28.1993 V-AkihiS
                {
                    PSZ String, LastSlashPtr;

                    String = LastSlashPtr = NameBuffer;
                    while (String <= Dest) {
                        if (Ow2NlsIsDBCSLeadByte(*String, SesGrp->DosCP)) {
                            String++;
                            if (String <= Dest) {
                                String++;
                            }
                        } else {
                            if (ISSLASH(*String)) {
                                if (String >= BackUpLimit) {
                                    LastSlashPtr = String;
                                }
                            }
                            String++;
                        }
                    }

                    if (ISSLASH(*LastSlashPtr)) {
                        Dest = LastSlashPtr;
                    } else {
                        Dest = BackUpLimit - 1;
                        RetCode = ERROR_PATH_NOT_FOUND;
                        goto ErrorExit;      // go free buffer(s) and return error
                    }
                }
#else
                while ((Dest >= BackUpLimit) && !(ISSLASH(*Dest))) {  // have to use ISSLASH because of MapToRootName
                    Dest--;   // BUGBUG make DBCS correct
                }
                if (!ISSLASH(*Dest)) {
                    RetCode = ERROR_PATH_NOT_FOUND;
                    goto ErrorExit;      // go free buffer(s) and return error
                }
#endif
                RemoveBlanksAndDots=FALSE;
           }
           else {
               RetCode = ERROR_FILE_NOT_FOUND;
               goto ErrorExit;
           }
        }

        //
        // else copy path
        //

        else {
            while (!ISPATHSEP(*Src)) {
                c = *Src++;
                if ((c == '?') || (c == '*')) {
                    if (!MetaCharactersAllowed) {
                        RetCode = ERROR_PATH_NOT_FOUND;
                        goto ErrorExit;
                    }
                    else {
                        OutputFlags |= CANONICALIZE_META_CHARS_FOUND;
                    }
                }
#ifdef DBCS
// MSKK Apr.18.1993 V-AkihiS
                if (Ow2NlsIsDBCSLeadByte(c, SesGrp->DosCP)) {
                    *Dest++ = c;
                    if (*Src) {
                        //
                        // Check Trailing byte is valid or not.
                        //
                        if ((UCHAR)*Src < 0x40 || (UCHAR)*Src > 0xFC || (UCHAR)*Src == 0x7F) {
                                    RetCode = ERROR_INVALID_NAME;
                            goto ErrorExit;
                        } else {
                            *Dest++ = *Src++;
                        }
                    } else {
                        RetCode = ERROR_INVALID_NAME;
                        goto ErrorExit;
                    }
                }
                else {
                    if (ValidateChars && ((UCHAR)c < (UCHAR)' ' ||
                                          strchr( InvalidCharacters, c )
                                         )
                       ) {
                        RetCode = ERROR_INVALID_NAME;
                        goto ErrorExit;
                    }

                    if ((!PreserveCase) && (c >= 'a' && c <= 'z')) {
                        c = (CHAR) (c - 'a' + 'A');
                    }
                    *Dest++ = c;
                }
#else
                if (ValidateChars && ((UCHAR)c < (UCHAR)' ' ||
                                      strchr( Od2InvalidCharacters, c )
                                     )
                   ) {
                    RetCode = ERROR_INVALID_NAME;
                    goto ErrorExit;
                }

                if ((!PreserveCase) && (c >= 'a' && c <= 'z')) {
                    c = (CHAR) (c - 'a' + 'A');
                }
                *Dest++ = c;
#endif
            }
        }

        //
        // truncate trailing dots and blanks here.  if there is a metacharacter
        // in the name, we must leave one trailing dot, if there is one.
        // DBCS correct because '.' and ' ' aren't valid trailing bytes
        //

        if (RemoveBlanksAndDots) {
            if ((Dest > LastComponent) && ((*(Dest-1) == '.') || (*(Dest-1) == ' '))) {
                do {
                    Dest--;
                } while ((Dest > LastComponent) && ((*(Dest-1) == '.') || (*(Dest-1) == ' ')));
                if (OutputFlags & CANONICALIZE_META_CHARS_FOUND) {
                    if (*Dest == '.') {
                        Dest++;
                    }
                }
            }
            if (Dest <= LastComponent) {
                RetCode = ERROR_FILE_NOT_FOUND;
                goto ErrorExit;      // go free buffer(s) and return error
            }
        }

     // *Src == '\' or '/'
        if (ISSLASH(*Src)) {
            if (MapToRootName) {
                *Dest++ = '/';
            }
            else {
                *Dest++ = (CHAR)OBJ_NAME_PATH_SEPARATOR;
            }
            LastComponent = Dest;

            while (ISSLASH(*Src)) {
                Src++; // eat up extra '\'s
            }
        }
    }

    //
    // null terminate
    //

    *Dest = '\0';
    if (OutputType != FILE_TYPE_FILE &&
        OutputType != FILE_TYPE_DEV &&
        OutputType != FILE_TYPE_PSDEV
       ) {
        if (Dest == LastComponent || Dest <= BackUpLimit) {
            RetCode = ERROR_FILE_NOT_FOUND;
            goto ErrorExit;      // go free buffer(s) and return error
        }

        if (OutputType == FILE_TYPE_NMPIPE && !TestForPipe(Os2Name)) {
            RetCode = ERROR_FILE_NOT_FOUND;
            goto ErrorExit;
        }
        else if (OutputType == FILE_TYPE_MAILSLOT && !TestForMailslot(Os2Name)) {
            RetCode = ERROR_FILE_NOT_FOUND;
            goto ErrorExit;
        }
    }

    //
    // Enforce 260 max path length.  remember that length does not include
    // the terminating null.  Remember the 260 limit includes the null byte.
    //

    ASSERT (Os2Name != NULL);
    if (strlen(Os2Name) > CCHMAXPATH - 1) {
        RetCode = ERROR_FILENAME_EXCED_RANGE;
        goto ErrorExit;
    }

    //
    // do some file-specific stuff.
    //

    if (OutputType == FILE_TYPE_FILE) {

        //
        // detect root directory
        // test for "d:".  if so, map to "d:\"
        //

        if (NameBuffer[FIRST_SLASH+FILE_PREFIX_LENGTH] == '\0') { // resulting path is d:
            NameBuffer[FIRST_SLASH+FILE_PREFIX_LENGTH] = (CHAR)OBJ_NAME_PATH_SEPARATOR;
            NameBuffer[ROOTDIRLENGTH+FILE_PREFIX_LENGTH] = '\0';
            Dest++;
            OutputFlags |= CANONICALIZE_IS_ROOT_DIRECTORY;
#if DBG
            IF_OD2_DEBUG( FILESYS ) {
                DbgPrint("path is root dir\n");
            }
#endif
        }
        else if (NameBuffer[FIRST_SLASH+FILE_PREFIX_LENGTH] == (CHAR)OBJ_NAME_PATH_SEPARATOR && NameBuffer[ROOTDIRLENGTH+FILE_PREFIX_LENGTH] == '\0') {
            OutputFlags |= CANONICALIZE_IS_ROOT_DIRECTORY;
#if DBG
            IF_OD2_DEBUG( FILESYS ) {
                DbgPrint("path is root dir\n");
            }
#endif
        }

        //
        // test for "d:\pipe" or "d:\pipe\..."  this is illegal unless
        // CANONICALIZE_FILE_OR_DEV is specified.  only DosMove sets this flag.
        //

        else if ((!(_strnicmp(NameBuffer+DRIVE_LETTER_SIZE+FILE_PREFIX_LENGTH,"PIPE",4))) &&
            (((*(NameBuffer+DRIVE_LETTER_SIZE+FILE_PREFIX_LENGTH+PIPE_DIR_SIZE-2)) == 0) ||
             ((*(NameBuffer+DRIVE_LETTER_SIZE+FILE_PREFIX_LENGTH+PIPE_DIR_SIZE-2)) == (CHAR)OBJ_NAME_PATH_SEPARATOR))) {
            if (ExpectedType != CANONICALIZE_FILE_OR_DEV) {
                RetCode = ERROR_PATH_NOT_FOUND;
                goto ErrorExit;      // go free buffer(s) and return error
            }
        }

        //
        // optimize to use open handle to current directory if 1) the user doesn't
        // need the full path (i.e. not for current directory operations) 2) we
        // have the current directory (the user didn't specify a full path), and
        // 3) current directory isn't root.
        //

        if ((ARGUMENT_PRESENT( DirectoryHandle )) &&
            (CurrentDirectoryHandle != NULL) &&
            (!_strnicmp(NameBuffer+DRIVE_LETTER_SIZE+FILE_PREFIX_LENGTH,
                       CurrentDirectoryString->Buffer,
                       CurrentDirectoryString->Length)) &&
            (NameBuffer[DRIVE_LETTER_SIZE+FILE_PREFIX_LENGTH+
             CurrentDirectoryString->Length] == '\\')
                           ) {
#if DBG
            IF_OD2_DEBUG( FILESYS ) {
                DbgPrint("Optimized relative path\n");
            }
#endif
            *DirectoryHandle = CurrentDirectoryHandle;

            //
            // we have to return a pointer to the relative path.  we can
            // either allocate a second buffer and copy the name from
            // the current directory on, or ripple copy the relative path
            // over the full path.  since the ripple copy is less work, we
            // do it.
            //
            // if canonical path is "\os2ss\drives\a:\dir1\dir2" and current
            // directory is "\os2ss\drives\a:\dir1", we want to copy "dir2"
            // to the beginning of the buffer.
            //

            Src = NameBuffer+CurrentDirectoryString->Length+1+DRIVE_LETTER_SIZE+FILE_PREFIX_LENGTH;
            Dest = NameBuffer;
            while (*Dest++ = *Src++)
                ;
            Dest--;
        }
    }

#if DBG
    IF_OD2_DEBUG( FILESYS ) {
        DbgPrint("got to here.  name is %s\n",NameBuffer);
        if (DirectoryHandle != NULL)
            DbgPrint("              handle is %ld\n",*DirectoryHandle);
    }
#endif

    CanonicalString->MaximumLength = (USHORT) NameBufferLength;
    CanonicalString->Length = (USHORT) (Dest - NameBuffer);
    CanonicalString->Buffer = NameBuffer;

#if 0
#ifndef DBCS // MSKK move max path length check
    //
    // Enforce 260 max path length.  remember that length does not include
    // the terminating null.  Remember the 260 limit includes the null byte.
    //

    ASSERT (Os2Name != NULL);
    if (CanonicalString->Length - (Os2Name - NameBuffer) >=
        CCHMAXPATH) {
        RetCode = ERROR_PATH_NOT_FOUND;
    }
#endif
#endif // 0

ErrorExit:
    if (CurrentDirectoryString != NULL) {
        RtlFreeHeap( Od2Heap, 0, CurrentDirectoryString );
    }

    if (RetCode != NO_ERROR) {
        if (NameBuffer != NULL) {
            RtlFreeHeap( Od2Heap, 0, NameBuffer );
        }
    }
    else {
        if (ARGUMENT_PRESENT( ParseFlags )) {
            *ParseFlags = OutputFlags;
        }

        if (ExpectedPrefix == NULL && ARGUMENT_PRESENT( FileType )) {
            *FileType = OutputType;
        }

#if DBG
        IF_OD2_DEBUG( FILESYS ) {
            DbgPrint( "Od2Canonicalize: returning path %s\n", NameBuffer);
        }
#endif
    }

    return( RetCode );
}


BOOLEAN
Od2IsAbsolutePath(
    IN PSZ Path
    )
{
    CHAR c;

    if (Path[ 0 ] && Path[ 1 ] != ':') {
        while (c = *Path++) {
            if (c == '/' || c == (CHAR)OBJ_NAME_PATH_SEPARATOR) {
                return( TRUE );
                }
#ifdef DBCS
// MSKK Apr.11.1993 V-AkihiS
            if (Ow2NlsIsDBCSLeadByte(c, SesGrp->DosCP)) {
                if (*Path) Path++;
                }
#endif
            }

        return( FALSE );
        }
    else {
        return( TRUE );
        }
}