Skip to content

Commit 0aa606e

Browse files
committed
- Move root to /usr. - Change sorting mount points. - Do not show warnings for DOS paths. - By default mount without ACLs. - Can read /etc/fstab with short mount point format.
1 parent fae0d72 commit 0aa606e

File tree

5 files changed

+177
-31
lines changed

5 files changed

+177
-31
lines changed

winsup/cygwin/cygheap.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,22 @@ init_cygheap::init_installation_root ()
181181

182182
/* Strip off last path component ("\\cygwin1.dll") */
183183
PWCHAR w = wcsrchr (installation_root, L'\\');
184+
#ifdef __MSYS__
185+
/* Back two folders to get root as we have all stuff in usr subfolder */
186+
for (int i=1; i >=0; --i)
187+
{
188+
#endif
184189
if (w)
185190
{
186191
*w = L'\0';
187192
w = wcsrchr (installation_root, L'\\');
188193
}
189194
if (!w)
190-
api_fatal ("Can't initialize Cygwin installation root dir.\n"
195+
api_fatal ("Can't initialize MSYS2 installation root dir.\n"
191196
"Invalid DLL path");
197+
#ifdef __MSYS__
198+
}
199+
#endif
192200

193201
/* Copy result into installation_dir before stripping off "bin" dir and
194202
revert to Win32 path. This path is added to the Windows environment
@@ -211,6 +219,7 @@ init_cygheap::init_installation_root ()
211219
if (w > p)
212220
*w = L'\0';
213221

222+
#ifndef __MSYS__
214223
for (int i = 1; i >= 0; --i)
215224
{
216225
reg_key r (i, KEY_WRITE, _WIDE (CYGWIN_INFO_INSTALLATIONS_NAME),
@@ -219,6 +228,7 @@ init_cygheap::init_installation_root ()
219228
installation_root)))
220229
break;
221230
}
231+
#endif
222232

223233
if (cygwin_props.disable_key)
224234
{

winsup/cygwin/globals.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ int NO_COPY dynamically_loaded;
6969
/* Some CYGWIN environment variable variables. */
7070
bool allow_glob = true;
7171
bool detect_bloda;
72-
bool dos_file_warning;
72+
bool dos_file_warning = false;
7373
bool ignore_case_with_glob;
7474
bool pipe_byte;
7575
bool reset_com;

winsup/cygwin/mount.cc

Lines changed: 162 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ details. */
4242
(path_prefix_p (proc, (path), proc_len, false))
4343

4444
bool NO_COPY mount_info::got_usr_bin;
45-
bool NO_COPY mount_info::got_usr_lib;
4645
int NO_COPY mount_info::root_idx = -1;
4746

4847
/* 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)
308307
#define MINIMAL_WIN_NTFS_FLAGS (FILE_CASE_SENSITIVE_SEARCH \
309308
| FILE_CASE_PRESERVED_NAMES \
310309
| FILE_UNICODE_ON_DISK \
311-
| FILE_PERSISTENT_ACLS \
312310
| FILE_FILE_COMPRESSION \
313311
| FILE_VOLUME_QUOTAS \
314312
| FILE_SUPPORTS_SPARSE_FILES \
@@ -454,13 +452,13 @@ mount_info::create_root_entry (const PWCHAR root)
454452
sys_wcstombs (native_root, PATH_MAX, root);
455453
assert (*native_root != '\0');
456454
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)
458456
< 0)
459457
api_fatal ("add_item (\"%s\", \"/\", ...) failed, errno %d", native_root, errno);
460458
/* Create a default cygdrive entry. Note that this is a user entry.
461459
This allows to override it with mount, unless the sysadmin created
462460
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;
464462
strcpy (cygdrive, CYGWIN_INFO_CYGDRIVE_DEFAULT_PREFIX "/");
465463
cygdrive_len = strlen (cygdrive);
466464
}
@@ -480,25 +478,17 @@ mount_info::init (bool user_init)
480478
pathend = wcpcpy (pathend, L"\\etc\\fstab");
481479
from_fstab (user_init, path, pathend);
482480

483-
if (!user_init && (!got_usr_bin || !got_usr_lib))
481+
482+
if (!user_init && !got_usr_bin)
484483
{
485484
char native[PATH_MAX];
486485
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);
488487
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+
}
502492
}
503493

504494
static void
@@ -596,6 +586,7 @@ mount_info::conv_to_win32_path (const char *src_path, char *dst, device& dev,
596586
/* See if this is a cygwin "device" */
597587
if (win32_device_name (src_path, dst, dev))
598588
{
589+
debug_printf ("win32_device_name (%s)", src_path);
599590
*flags = MOUNT_BINARY; /* FIXME: Is this a sensible default for devices? */
600591
rc = 0;
601592
goto out_no_chroot_check;
@@ -627,6 +618,7 @@ mount_info::conv_to_win32_path (const char *src_path, char *dst, device& dev,
627618
}
628619
if (isproc (src_path))
629620
{
621+
debug_printf ("isproc (%s)", src_path);
630622
dev = *proc_dev;
631623
dev = fhandler_proc::get_proc_fhandler (src_path);
632624
if (dev == FH_NADA)
@@ -648,6 +640,7 @@ mount_info::conv_to_win32_path (const char *src_path, char *dst, device& dev,
648640
off the prefix and transform it into an MS-DOS path. */
649641
else if (iscygdrive (src_path))
650642
{
643+
debug_printf ("iscygdrive (%s) mount_table->cygdrive %s", src_path, mount_table->cygdrive);
651644
int n = mount_table->cygdrive_len - 1;
652645
int unit;
653646

@@ -659,11 +652,15 @@ mount_info::conv_to_win32_path (const char *src_path, char *dst, device& dev,
659652
}
660653
else if (cygdrive_win32_path (src_path, dst, unit))
661654
{
655+
debug_printf ("cygdrive_win32_path (%s)", src_path);
662656
set_flags (flags, (unsigned) cygdrive_flags);
663657
goto out;
664658
}
665659
else if (mount_table->cygdrive_len > 1)
660+
{
661+
debug_printf ("mount_table->cygdrive_len > 1 (%s)", src_path);
666662
return ENOENT;
663+
}
667664
}
668665

669666
int chroot_pathlen;
@@ -674,7 +671,9 @@ mount_info::conv_to_win32_path (const char *src_path, char *dst, device& dev,
674671
const char *path;
675672
int len;
676673

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+
678677
if (!cygheap->root.exists ()
679678
|| (mi->posix_pathlen == 1 && mi->posix_path[0] == '/'))
680679
{
@@ -893,7 +892,8 @@ mount_info::conv_to_posix_path (const char *src_path, char *posix_path,
893892
int pathbuflen = tail - pathbuf;
894893
for (int i = 0; i < nmounts; ++i)
895894
{
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);
897897
if (!path_prefix_p (mi.native_path, pathbuf, mi.native_pathlen,
898898
mi.flags & MOUNT_NOPOSIX))
899899
continue;
@@ -1121,8 +1121,17 @@ mount_info::from_fstab_line (char *line, bool user)
11211121
if (!*c)
11221122
return true;
11231123
cend = find_ws (c);
1124-
*cend = '\0';
11251124
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';
11261135
/* Third field: FS type. */
11271136
c = skip_ws (cend + 1);
11281137
if (!*c)
@@ -1333,16 +1342,145 @@ sort_by_native_name (const void *a, const void *b)
13331342
return res;
13341343
}
13351344

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+
13361445
void
13371446
mount_info::sort ()
13381447
{
13391448
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;
13411450
/* Sort them into reverse length order, otherwise we won't
13421451
be able to look for /foo in /. */
13431452
mounts_for_sort = mount; /* ouch. */
13441453
qsort (posix_sorted, nmounts, sizeof (posix_sorted[0]), sort_by_posix_name);
13451454
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+
}
13461484
}
13471485

13481486
/* Add an entry to the mount table.
@@ -1433,12 +1571,9 @@ mount_info::add_item (const char *native, const char *posix,
14331571
if (i == nmounts)
14341572
nmounts++;
14351573

1436-
if (strcmp (posixtmp, "/usr/bin") == 0)
1574+
if (strcmp (posixtmp, "/bin") == 0)
14371575
got_usr_bin = true;
14381576

1439-
if (strcmp (posixtmp, "/usr/lib") == 0)
1440-
got_usr_lib = true;
1441-
14421577
if (posixtmp[0] == '/' && posixtmp[1] == '\0' && !(mountflags & MOUNT_CYGDRIVE))
14431578
root_idx = i;
14441579

winsup/cygwin/mount.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ class mount_info
170170
mount_item mount[MAX_MOUNTS];
171171

172172
static bool got_usr_bin;
173-
static bool got_usr_lib;
174173
static int root_idx;
175174

176175
/* cygdrive_prefix is used as the root of the path automatically
@@ -182,6 +181,8 @@ class mount_info
182181
private:
183182
int posix_sorted[MAX_MOUNTS];
184183
int native_sorted[MAX_MOUNTS];
184+
int longest_posix_sorted[MAX_MOUNTS];
185+
int shortest_native_sorted[MAX_MOUNTS];
185186

186187
public:
187188
void init (bool);

winsup/cygwin/uinfo.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2524,7 +2524,7 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, cyg_ldap *pldap)
25242524
dom, name,
25252525
sid.string ((char *) sidstr),
25262526
home ?: "/home/", home ? L"" : name,
2527-
shell ?: "/bin/bash");
2527+
shell ?: "/usr/bin/bash");
25282528
if (gecos)
25292529
free (gecos);
25302530
if (home)

0 commit comments

Comments
 (0)