@@ -42,7 +42,6 @@ details. */
42
42
(path_prefix_p (proc, (path), proc_len, false ))
43
43
44
44
bool NO_COPY mount_info::got_usr_bin;
45
- bool NO_COPY mount_info::got_usr_lib;
46
45
int NO_COPY mount_info::root_idx = -1 ;
47
46
48
47
/* is_unc_share: Return non-zero if PATH begins with //server/share
@@ -308,7 +307,6 @@ fs_info::update (PUNICODE_STRING upath, HANDLE in_vol)
308
307
#define MINIMAL_WIN_NTFS_FLAGS (FILE_CASE_SENSITIVE_SEARCH \
309
308
| FILE_CASE_PRESERVED_NAMES \
310
309
| FILE_UNICODE_ON_DISK \
311
- | FILE_PERSISTENT_ACLS \
312
310
| FILE_FILE_COMPRESSION \
313
311
| FILE_VOLUME_QUOTAS \
314
312
| FILE_SUPPORTS_SPARSE_FILES \
@@ -454,13 +452,13 @@ mount_info::create_root_entry (const PWCHAR root)
454
452
sys_wcstombs (native_root, PATH_MAX, root);
455
453
assert (*native_root != ' \0 ' );
456
454
if (add_item (native_root, " /" ,
457
- MOUNT_SYSTEM | MOUNT_BINARY | MOUNT_IMMUTABLE | MOUNT_AUTOMATIC)
455
+ MOUNT_SYSTEM | MOUNT_BINARY | MOUNT_IMMUTABLE | MOUNT_AUTOMATIC | MOUNT_NOACL )
458
456
< 0 )
459
457
api_fatal (" add_item (\" %s\" , \" /\" , ...) failed, errno %d" , native_root, errno);
460
458
/* Create a default cygdrive entry. Note that this is a user entry.
461
459
This allows to override it with mount, unless the sysadmin created
462
460
a cygdrive entry in /etc/fstab. */
463
- cygdrive_flags = MOUNT_BINARY | MOUNT_NOPOSIX | MOUNT_CYGDRIVE;
461
+ cygdrive_flags = MOUNT_BINARY | MOUNT_NOPOSIX | MOUNT_CYGDRIVE | MOUNT_NOACL ;
464
462
strcpy (cygdrive, CYGWIN_INFO_CYGDRIVE_DEFAULT_PREFIX " /" );
465
463
cygdrive_len = strlen (cygdrive);
466
464
}
@@ -480,25 +478,17 @@ mount_info::init (bool user_init)
480
478
pathend = wcpcpy (pathend, L" \\ etc\\ fstab" );
481
479
from_fstab (user_init, path, pathend);
482
480
483
- if (!user_init && (!got_usr_bin || !got_usr_lib))
481
+
482
+ if (!user_init && !got_usr_bin)
484
483
{
485
484
char native[PATH_MAX];
486
485
if (root_idx < 0 )
487
- api_fatal (" root_idx %d, user_shared magic %y, nmounts %d" , root_idx, user_shared->version , nmounts);
486
+ api_fatal (" root_idx %d, user_shared magic %y, nmounts %d" , root_idx, user_shared->version , nmounts);
488
487
char *p = stpcpy (native, mount[root_idx].native_path );
489
- if (!got_usr_bin)
490
- {
491
- stpcpy (p, " \\ bin" );
492
- add_item (native, " /usr/bin" ,
493
- MOUNT_SYSTEM | MOUNT_BINARY | MOUNT_AUTOMATIC);
494
- }
495
- if (!got_usr_lib)
496
- {
497
- stpcpy (p, " \\ lib" );
498
- add_item (native, " /usr/lib" ,
499
- MOUNT_SYSTEM | MOUNT_BINARY | MOUNT_AUTOMATIC);
500
- }
501
- }
488
+ stpcpy (p, " \\ usr\\ bin" );
489
+ add_item (native, " /bin" ,
490
+ MOUNT_SYSTEM | MOUNT_BINARY | MOUNT_AUTOMATIC | MOUNT_NOACL);
491
+ }
502
492
}
503
493
504
494
static void
@@ -596,6 +586,7 @@ mount_info::conv_to_win32_path (const char *src_path, char *dst, device& dev,
596
586
/* See if this is a cygwin "device" */
597
587
if (win32_device_name (src_path, dst, dev))
598
588
{
589
+ debug_printf (" win32_device_name (%s)" , src_path);
599
590
*flags = MOUNT_BINARY; /* FIXME: Is this a sensible default for devices? */
600
591
rc = 0 ;
601
592
goto out_no_chroot_check;
@@ -627,6 +618,7 @@ mount_info::conv_to_win32_path (const char *src_path, char *dst, device& dev,
627
618
}
628
619
if (isproc (src_path))
629
620
{
621
+ debug_printf (" isproc (%s)" , src_path);
630
622
dev = *proc_dev;
631
623
dev = fhandler_proc::get_proc_fhandler (src_path);
632
624
if (dev == FH_NADA)
@@ -648,6 +640,7 @@ mount_info::conv_to_win32_path (const char *src_path, char *dst, device& dev,
648
640
off the prefix and transform it into an MS-DOS path. */
649
641
else if (iscygdrive (src_path))
650
642
{
643
+ debug_printf (" iscygdrive (%s) mount_table->cygdrive %s" , src_path, mount_table->cygdrive );
651
644
int n = mount_table->cygdrive_len - 1 ;
652
645
int unit;
653
646
@@ -659,11 +652,15 @@ mount_info::conv_to_win32_path (const char *src_path, char *dst, device& dev,
659
652
}
660
653
else if (cygdrive_win32_path (src_path, dst, unit))
661
654
{
655
+ debug_printf (" cygdrive_win32_path (%s)" , src_path);
662
656
set_flags (flags, (unsigned ) cygdrive_flags);
663
657
goto out;
664
658
}
665
659
else if (mount_table->cygdrive_len > 1 )
660
+ {
661
+ debug_printf (" mount_table->cygdrive_len > 1 (%s)" , src_path);
666
662
return ENOENT;
663
+ }
667
664
}
668
665
669
666
int chroot_pathlen;
@@ -674,7 +671,9 @@ mount_info::conv_to_win32_path (const char *src_path, char *dst, device& dev,
674
671
const char *path;
675
672
int len;
676
673
677
- mi = mount + posix_sorted[i];
674
+ mi = mount + shortest_native_sorted[i];
675
+ debug_printf (" mount[%d] .. checking %s -> %s " , i, mi->posix_path , mi->native_path );
676
+
678
677
if (!cygheap->root .exists ()
679
678
|| (mi->posix_pathlen == 1 && mi->posix_path [0 ] == ' /' ))
680
679
{
@@ -893,7 +892,8 @@ mount_info::conv_to_posix_path (const char *src_path, char *posix_path,
893
892
int pathbuflen = tail - pathbuf;
894
893
for (int i = 0 ; i < nmounts; ++i)
895
894
{
896
- mount_item &mi = mount[native_sorted[i]];
895
+ mount_item &mi = mount[longest_posix_sorted[i]];
896
+ debug_printf (" mount[%d] .. checking %s -> %s " , i, mi.posix_path , mi.native_path );
897
897
if (!path_prefix_p (mi.native_path , pathbuf, mi.native_pathlen ,
898
898
mi.flags & MOUNT_NOPOSIX))
899
899
continue ;
@@ -1121,8 +1121,17 @@ mount_info::from_fstab_line (char *line, bool user)
1121
1121
if (!*c)
1122
1122
return true ;
1123
1123
cend = find_ws (c);
1124
- *cend = ' \0 ' ;
1125
1124
posix_path = conv_fstab_spaces (c);
1125
+ if (!*cend)
1126
+ {
1127
+ unsigned mount_flags = MOUNT_SYSTEM | MOUNT_BINARY | MOUNT_NOPOSIX | MOUNT_NOACL;
1128
+
1129
+ int res = mount_table->add_item (native_path, posix_path, mount_flags);
1130
+ if (res && get_errno () == EMFILE)
1131
+ return false ;
1132
+ return true ;
1133
+ }
1134
+ *cend = ' \0 ' ;
1126
1135
/* Third field: FS type. */
1127
1136
c = skip_ws (cend + 1 );
1128
1137
if (!*c)
@@ -1333,16 +1342,145 @@ sort_by_native_name (const void *a, const void *b)
1333
1342
return res;
1334
1343
}
1335
1344
1345
+ /* sort_by_longest_posix_name: qsort callback to sort the mount entries.
1346
+ Sort user mounts ahead of system mounts to the same POSIX path. */
1347
+ /* FIXME: should the user should be able to choose whether to
1348
+ prefer user or system mounts??? */
1349
+ static int
1350
+ sort_by_longest_posix_name (const void *a, const void *b)
1351
+ {
1352
+ mount_item *ap = mounts_for_sort + (*((int *) a));
1353
+ mount_item *bp = mounts_for_sort + (*((int *) b));
1354
+
1355
+ /* Base weighting on the conversion that would give the longest
1356
+ posix path. */
1357
+ ssize_t alen = (ssize_t ) strlen (ap->posix_path ) - (ssize_t ) strlen (ap->native_path );
1358
+ ssize_t blen = (ssize_t ) strlen (bp->posix_path ) - (ssize_t ) strlen (bp->native_path );
1359
+
1360
+ int res = blen - alen;
1361
+
1362
+ if (res)
1363
+ return res; /* Path lengths differed */
1364
+
1365
+ /* The two paths were the same length, so just determine normal
1366
+ lexical sorted order. */
1367
+ res = strcmp (ap->posix_path , bp->posix_path );
1368
+
1369
+ if (res == 0 )
1370
+ {
1371
+ /* need to select between user and system mount to same POSIX path */
1372
+ if (!(bp->flags & MOUNT_SYSTEM)) /* user mount */
1373
+ return 1 ;
1374
+ else
1375
+ return -1 ;
1376
+ }
1377
+
1378
+ return res;
1379
+ }
1380
+
1381
+ /* sort_by_shortest_native_name: qsort callback to sort the mount entries.
1382
+ Sort user mounts ahead of system mounts to the same POSIX path. */
1383
+ /* FIXME: should the user should be able to choose whether to
1384
+ prefer user or system mounts??? */
1385
+ static int
1386
+ sort_by_shortest_native_name (const void *a, const void *b)
1387
+ {
1388
+ mount_item *ap = mounts_for_sort + (*((int *) a));
1389
+ mount_item *bp = mounts_for_sort + (*((int *) b));
1390
+
1391
+ /* Base weighting on the conversion that would give the shortest
1392
+ native path. */
1393
+ ssize_t alen = (ssize_t ) strlen (ap->native_path );
1394
+ ssize_t blen = (ssize_t ) strlen (bp->native_path );
1395
+
1396
+ int res = alen - blen;
1397
+
1398
+ if (res)
1399
+ return res; /* Path lengths differed */
1400
+
1401
+ /* The two paths were the same length, so just determine normal
1402
+ lexical sorted order. */
1403
+ res = strcmp (ap->native_path , bp->native_path );
1404
+
1405
+ if (res == 0 )
1406
+ {
1407
+ /* need to select between user and system mount to same POSIX path */
1408
+ if (!(bp->flags & MOUNT_SYSTEM)) /* user mount */
1409
+ return 1 ;
1410
+ else
1411
+ return -1 ;
1412
+ }
1413
+
1414
+ return res;
1415
+ }
1416
+
1417
+ static int
1418
+ sort_posix_subdirs_before_parents (const void *a, const void *b)
1419
+ {
1420
+ mount_item *ap = mounts_for_sort + (*((int *) a));
1421
+ mount_item *bp = mounts_for_sort + (*((int *) b));
1422
+
1423
+ if (ap->posix_pathlen > bp->posix_pathlen )
1424
+ {
1425
+ if (!memcmp (bp->posix_path , ap->posix_path , bp->posix_pathlen ))
1426
+ {
1427
+ // bp is a subdir of ap (bp must be moved in-front)
1428
+ return -1 ;
1429
+ }
1430
+ }
1431
+ else if (ap->posix_pathlen < bp->posix_pathlen )
1432
+ {
1433
+ if (!memcmp (ap->posix_path , bp->posix_path , ap->posix_pathlen ))
1434
+ {
1435
+ // ap is a subdir of bp (good as we are)
1436
+ return 1 ;
1437
+ }
1438
+ }
1439
+ return 0 ;
1440
+ }
1441
+
1442
+ #define DISABLE_NEW_STUFF 0
1443
+ #define ONLY_USE_NEW_STUFF 1
1444
+
1336
1445
void
1337
1446
mount_info::sort ()
1338
1447
{
1339
1448
for (int i = 0 ; i < nmounts; i++)
1340
- native_sorted[i] = posix_sorted[i] = i;
1449
+ native_sorted[i] = posix_sorted[i] = shortest_native_sorted[i] = longest_posix_sorted[i] = i;
1341
1450
/* Sort them into reverse length order, otherwise we won't
1342
1451
be able to look for /foo in /. */
1343
1452
mounts_for_sort = mount; /* ouch. */
1344
1453
qsort (posix_sorted, nmounts, sizeof (posix_sorted[0 ]), sort_by_posix_name);
1345
1454
qsort (native_sorted, nmounts, sizeof (native_sorted[0 ]), sort_by_native_name);
1455
+ qsort (longest_posix_sorted, nmounts, sizeof (longest_posix_sorted[0 ]), sort_by_longest_posix_name);
1456
+ qsort (shortest_native_sorted, nmounts, sizeof (shortest_native_sorted[0 ]), sort_by_shortest_native_name);
1457
+ qsort (shortest_native_sorted, nmounts, sizeof (shortest_native_sorted[0 ]), sort_posix_subdirs_before_parents);
1458
+ /* Disabling my new crap. */
1459
+ #if DISABLE_NEW_STUFF
1460
+ for (int i = 0 ; i < nmounts; i++)
1461
+ {
1462
+ longest_posix_sorted[i] = native_sorted[i];
1463
+ shortest_native_sorted[i] = posix_sorted[i];
1464
+ }
1465
+ #else
1466
+ #if ONLY_USE_NEW_STUFF
1467
+ for (int i = 0 ; i < nmounts; i++)
1468
+ {
1469
+ native_sorted[i] = longest_posix_sorted[i];
1470
+ posix_sorted[i] = shortest_native_sorted[i];
1471
+ }
1472
+ #endif
1473
+ #endif
1474
+ for (int i = 0 ; i < nmounts; i++)
1475
+ {
1476
+ mount_item *mi = mount + shortest_native_sorted[i];
1477
+ debug_printf (" shortest_native_sorted (subdirs before parents)[%d] %12s %12s" , i, mi->native_path , mi->posix_path );
1478
+ }
1479
+ for (int i = 0 ; i < nmounts; i++)
1480
+ {
1481
+ mount_item *mi = mount + longest_posix_sorted[i];
1482
+ debug_printf (" longest_posix_sorted[%d] %12s %12s" , i, mi->native_path , mi->posix_path );
1483
+ }
1346
1484
}
1347
1485
1348
1486
/* Add an entry to the mount table.
@@ -1433,12 +1571,9 @@ mount_info::add_item (const char *native, const char *posix,
1433
1571
if (i == nmounts)
1434
1572
nmounts++;
1435
1573
1436
- if (strcmp (posixtmp, " /usr/ bin" ) == 0 )
1574
+ if (strcmp (posixtmp, " /bin" ) == 0 )
1437
1575
got_usr_bin = true ;
1438
1576
1439
- if (strcmp (posixtmp, " /usr/lib" ) == 0 )
1440
- got_usr_lib = true ;
1441
-
1442
1577
if (posixtmp[0 ] == ' /' && posixtmp[1 ] == ' \0 ' && !(mountflags & MOUNT_CYGDRIVE))
1443
1578
root_idx = i;
1444
1579
0 commit comments