This is the mail archive of the cygwin-developers mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: More: [1.7] packaging problem? Both /usr/bin/ and /usr/lib/ are non-empty


On Tue, May 12, 2009 at 11:41:16AM +0200, Corinna Vinschen wrote:
>Ok, here's another patch.  It works basically as my patch in
>http://cygwin.com/ml/cygwin-developers/2009-05/msg00030.html, so it
>creates default /usr/bin and /usr/lib entries from the current setting
>of the root dir entry, after reading the fstab files.  Unless, of
>course, /usr/bin and /usr/lib entries have been specified in the fstab
>files.
>
>It adds a "force" option to /etc/fstab and the mount command.  The root
>mount point is marked as R/O.  Only if the "force" flag has been specifed,
>the new entry will override the default setting.
>
>This patch also contains the changes to the mount command, as well
>as the documentation changes.
>
>If nobody has strong objections, I'll check it in tomorrow.

Wouldn't it be better to check entries as fstab is being parsed rather
than rescan the whole table a second time?  It seems like just adding a
couple of strcmp's as in add_itm would be all that you need.

Also, since mount already has a force entry maybe this option should
be called "override" instead.  And, I agree with Eric that calling this
"read-only" is confusing.  It doesn't mean what you'd expect if you have
an idea of a similar option from linux.

With those ideas in mind, I present my variation of your patch.

I've called what we do with '/' "immutable".  An immutable mount setting
needs to be overridden with an "override" option.

I've also marked all of the automatic mounts with a ",auto" to make it
clear that Cygwin is creating them automatically.  I also added this
to cygdrive mounts.

Finally, I sorted the options table whereever I found it.  At some point
we should look into exporting the options table to the mount command so
that changes in Cygwin could be automatically reflected in the mount
command.

Patch below.

Oh, and one additional thing that I did was allow the use of -o nouser
as a mount option.  Was there a reason why we disabled that for 1.7?

cgf

Index: cygwin/mount.cc
===================================================================
RCS file: /cvs/uberbaum/winsup/cygwin/mount.cc,v
retrieving revision 1.35
diff -d -u -r1.35 mount.cc
--- cygwin/mount.cc	4 May 2009 09:16:42 -0000	1.35
+++ cygwin/mount.cc	13 May 2009 02:54:02 -0000
@@ -31,6 +31,7 @@
 #include <ntdll.h>
 #include <wchar.h>
 #include <stdio.h>
+#include <assert.h>
 
 /* Determine if path prefix matches current cygdrive */
 #define iscygdrive(path) \
@@ -44,6 +45,10 @@
 #define isproc(path) \
   (path_prefix_p (proc, (path), proc_len, false))
 
+bool mount_info::got_usr_bin;
+bool mount_info::got_usr_lib;
+int mount_info::root_idx = -1;
+
 /* is_unc_share: Return non-zero if PATH begins with //server/share
 		 or with one of the native prefixes //./ or //?/
    This function is only used to test for valid input strings.
@@ -298,10 +303,12 @@
 inline void
 mount_info::create_root_entry (const PWCHAR root)
 {
-  /* Create a default root dir from the path the Cygwin DLL is in. */
+ /* Create a default root dir derived from the location of the Cygwin DLL.
+    The entry is immutable, unless the "override" option is given in /etc/fstab. */
   char native_root[PATH_MAX];
   sys_wcstombs (native_root, PATH_MAX, root);
-  mount_table->add_item (native_root, "/", MOUNT_SYSTEM | MOUNT_BINARY);
+  mount_table->add_item (native_root, "/",
+			 MOUNT_SYSTEM | MOUNT_BINARY | MOUNT_OVERRIDE | MOUNT_AUTOMATIC);
   /* Create a default cygdrive entry.  Note that this is a user entry.
      This allows to override it with mount, unless the sysadmin created
      a cygdrive entry in /etc/fstab. */
@@ -322,12 +329,28 @@
   pathend = wcpcpy (path, cygwin_shared->installation_root);
   create_root_entry (path);
   pathend = wcpcpy (pathend, L"\\etc\\fstab");
-  if (from_fstab (false, path, pathend)   /* The single | is correct! */
-      | from_fstab (true, path, pathend))
-      return;
 
-  /* FIXME: Remove warning message before releasing 1.7.0. */
-  small_printf ("Huh?  No /etc/fstab file in %W?  Using default root and cygdrive prefix...\n", path);
+  from_fstab (false, path, pathend);
+  from_fstab (true, path, pathend);
+
+  if (!got_usr_bin || !got_usr_lib)
+    {
+      char native[PATH_MAX];
+      assert (root_idx != -1);
+      char *p = stpcpy (native, mount[root_idx].native_path);
+      if (!got_usr_bin)
+      {
+	stpcpy (p, "\\bin");
+	mount_table->add_item (native, "/usr/bin",
+			       MOUNT_SYSTEM | MOUNT_BINARY | MOUNT_AUTOMATIC);
+      }
+      if (!got_usr_lib)
+      {
+	stpcpy (p, "\\lib");
+	mount_table->add_item (native, "/usr/lib",
+			       MOUNT_SYSTEM | MOUNT_BINARY | MOUNT_AUTOMATIC);
+      }
+    }
 }
 
 static void
@@ -835,18 +858,19 @@
   bool clear;
 } oopts[] =
 {
-  {"user", MOUNT_SYSTEM, 1},
-  {"nouser", MOUNT_SYSTEM, 0},
+  {"acl", MOUNT_NOACL, 1},
   {"binary", MOUNT_BINARY, 0},
-  {"text", MOUNT_BINARY, 1},
-  {"exec", MOUNT_EXEC, 0},
-  {"notexec", MOUNT_NOTEXEC, 0},
   {"cygexec", MOUNT_CYGWIN_EXEC, 0},
-  {"nosuid", 0, 0},
-  {"acl", MOUNT_NOACL, 1},
+  {"exec", MOUNT_EXEC, 0},
   {"noacl", MOUNT_NOACL, 0},
+  {"nosuid", 0, 0},
+  {"notexec", MOUNT_NOTEXEC, 0},
+  {"nouser", MOUNT_SYSTEM, 0},
+  {"override", MOUNT_OVERRIDE, 0},
+  {"posix=0", MOUNT_NOPOSIX, 0},
   {"posix=1", MOUNT_NOPOSIX, 1},
-  {"posix=0", MOUNT_NOPOSIX, 0}
+  {"text", MOUNT_BINARY, 1},
+  {"user", MOUNT_SYSTEM, 1}
 };
 
 static bool
@@ -1054,7 +1078,7 @@
       set_errno (EINVAL);
       return -1;
     }
-  /* Don't allow to override a system cygdrive prefix. */
+  /* Don't allow overriding of a system cygdrive prefix. */
   if (cygdrive_flags & MOUNT_SYSTEM)
     {
       set_errno (EPERM);
@@ -1238,14 +1262,26 @@
     {
       if (!strcmp (mount[i].posix_path, posixtmp))
 	{
-	  /* Don't allow to override a system mount with a user mount. */
+	  /* Don't allow overriding of a system mount with a user mount. */
 	  if ((mount[i].flags & MOUNT_SYSTEM) && !(mountflags & MOUNT_SYSTEM))
 	    {
 	      set_errno (EPERM);
 	      return -1;
 	    }
-	  if ((mount[i].flags & MOUNT_SYSTEM) == (mountflags & MOUNT_SYSTEM))
+	  if ((mount[i].flags & MOUNT_SYSTEM) != (mountflags & MOUNT_SYSTEM))
+	    continue;
+	  else if (!(mount[i].flags & MOUNT_IMMUTABLE))
 	    break;
+	  else if (mountflags & MOUNT_OVERRIDE)
+	    {
+	      mountflags |= MOUNT_IMMUTABLE;
+	      break;
+	    }
+	  else
+	    {
+	      set_errno (EPERM);
+	      return -1;
+	    }
 	}
     }
 
@@ -1257,6 +1293,16 @@
 
   if (i == nmounts)
     nmounts++;
+
+  if (strcmp (posixtmp, "/usr/bin") == 0)
+    got_usr_bin = true;
+
+  if (strcmp (posixtmp, "/usr/lib") == 0)
+    got_usr_lib = true;
+
+  if (posixtmp[0] == '/' && posixtmp[1] == '\0')
+    root_idx = i;
+
   mount[i].init (nativetmp, posixtmp, mountflags);
   sort ();
 
@@ -1301,8 +1347,8 @@
 	   ? !strcmp (mount[ent].posix_path, pathtmp)
 	   : strcasematch (mount[ent].native_path, pathtmp)))
 	{
-	  /* Don't allow to remove a system mount. */
-	  if ((mount[ent].flags & MOUNT_SYSTEM))
+	  /* Don't allow removal of a system mount. */
+	  if (mount[ent].flags & MOUNT_SYSTEM)
 	    {
 	      set_errno (EPERM);
 	      return -1;
@@ -1407,9 +1453,15 @@
   if (!(flags & MOUNT_SYSTEM))		/* user mount */
     strcat (_my_tls.locals.mnt_opts, (char *) ",user");
 
-  if ((flags & MOUNT_CYGDRIVE))		/* cygdrive */
+  if (flags & MOUNT_CYGDRIVE)		/* cygdrive */
     strcat (_my_tls.locals.mnt_opts, (char *) ",noumount");
 
+  if (flags & MOUNT_IMMUTABLE)
+    strcat (_my_tls.locals.mnt_opts, (char *) ",immutable");
+
+  if (flags & (MOUNT_AUTOMATIC | MOUNT_CYGDRIVE))
+    strcat (_my_tls.locals.mnt_opts, (char *) ",auto");
+
   ret.mnt_opts = _my_tls.locals.mnt_opts;
 
   ret.mnt_freq = 1;
@@ -1488,7 +1540,6 @@
 mount (const char *win32_path, const char *posix_path, unsigned flags)
 {
   int res = -1;
-  flags &= ~MOUNT_SYSTEM;
 
   myfault efault;
   if (efault.faulted (EFAULT))
Index: cygwin/mount.h
===================================================================
RCS file: /cvs/uberbaum/winsup/cygwin/mount.h,v
retrieving revision 1.4
diff -d -u -r1.4 mount.h
--- cygwin/mount.h	4 May 2009 09:16:42 -0000	1.4
+++ cygwin/mount.h	13 May 2009 02:54:02 -0000
@@ -104,6 +104,10 @@
   int nmounts;
   mount_item mount[MAX_MOUNTS];
 
+  static bool got_usr_bin;
+  static bool got_usr_lib;
+  static int root_idx;
+
   /* cygdrive_prefix is used as the root of the path automatically
      prepended to a path when the path has no associated mount.
      cygdrive_flags are the default flags for the cygdrives. */
Index: cygwin/include/sys/mount.h
===================================================================
RCS file: /cvs/uberbaum/winsup/cygwin/include/sys/mount.h,v
retrieving revision 1.12
diff -d -u -r1.12 mount.h
--- cygwin/include/sys/mount.h	16 Jul 2008 20:20:45 -0000	1.12
+++ cygwin/include/sys/mount.h	13 May 2009 02:54:02 -0000
@@ -17,21 +17,26 @@
 
 enum
 {
-  MOUNT_SYMLINK =	0x0001,	/* "mount point" is a symlink */
-  MOUNT_BINARY =	0x0002,	/* "binary" format read/writes */
-  MOUNT_SYSTEM =	0x0008,	/* mount point came from system table */
-  MOUNT_EXEC   =	0x0010,	/* Any file in the mounted directory gets 'x' bit */
-  MOUNT_CYGDRIVE   =	0x0020,	/* mount point refers to cygdrive device mount */
-  MOUNT_CYGWIN_EXEC =	0x0040,	/* file or directory is or contains a cygwin
-				   executable */
-  MOUNT_MIXED	=	0x0080,	/* reads are text, writes are binary
-				   not yet implemented */
-  MOUNT_NOTEXEC =	0x0100,	/* don't check files for executable magic */
-  MOUNT_DEVFS =		0x0200,	/* /device "filesystem" */
-  MOUNT_PROC =		0x0400,	/* /proc "filesystem" */
-  MOUNT_RO =		0x1000, /* read-only "filesystem" */
-  MOUNT_NOACL =		0x2000, /* support reading/writing ACLs */
-  MOUNT_NOPOSIX =	0x4000  /* Case insensitve path handling */
+  MOUNT_SYMLINK =	0x00001,	/* "mount point" is a symlink */
+  MOUNT_BINARY =	0x00002,	/* "binary" format read/writes */
+  MOUNT_SYSTEM =	0x00008,	/* mount point came from system table */
+  MOUNT_EXEC   =	0x00010,	/* Any file in the mounted directory
+					   gets 'x' bit */
+  MOUNT_CYGDRIVE   =	0x00020,	/* mount point refers to cygdrive
+					   device mount */
+  MOUNT_CYGWIN_EXEC =	0x00040,	/* file or directory is or contains a
+					   cygwin executable */
+  MOUNT_MIXED	=	0x00080,	/* reads are text, writes are binary
+					   not yet implemented */
+  MOUNT_NOTEXEC =	0x00100,	/* don't check files for executable magic */
+  MOUNT_DEVFS =		0x00200,	/* /device "filesystem" */
+  MOUNT_PROC =		0x00400,	/* /proc "filesystem" */
+  MOUNT_RO =		0x01000,	/* read-only "filesystem" */
+  MOUNT_NOACL =		0x02000,	/* support reading/writing ACLs */
+  MOUNT_NOPOSIX =	0x04000,	/* Case insensitve path handling */
+  MOUNT_OVERRIDE =	0x08000,	/* Allow overriding of root */
+  MOUNT_IMMUTABLE =	0x10000,	/* Mount point can't be changed */
+  MOUNT_AUTOMATIC =	0x20000		/* Mount point was added automatically */
 };
 
 int mount (const char *, const char *, unsigned __flags);
Index: doc/pathnames.sgml
===================================================================
RCS file: /cvs/uberbaum/winsup/doc/pathnames.sgml,v
retrieving revision 1.38
diff -d -u -r1.38 pathnames.sgml
--- doc/pathnames.sgml	3 Apr 2009 11:51:31 -0000	1.38
+++ doc/pathnames.sgml	13 May 2009 02:54:02 -0000
@@ -67,25 +67,26 @@
 posix=[0|1].  The meaning of the options is as follows.</para>
 
 <screen>
-  acl      - Cygwin uses the filesystem's access control lists (ACLs) to
-             implement real POSIX permissions (default).  This flag only
-	     affects filesystems supporting ACLs (NTFS) and is ignored
-	     otherwise.
-  noacl    - Cygwin ignores filesystem ACLs and only fakes a subset of
-	     permission bits based on the DOS readonly attribute.  This
-	     behaviour is the default on FAT and FAT32.  The flag is
-	     ignored on NFS filesystems.
-  binary   - Files default to binary mode (default).
-  text     - Files default to CRLF text mode line endings.
-  nouser   - Mount is a system-wide mount.
-  user     - Mount is a user mount.
-  exec     - Treat all files below mount point as executable.
-  notexec  - Treat all files below mount point as not executable.
-  cygexec  - Treat all files below mount point as cygwin executables.
-  nosuid   - No suid files are allowed (currently unimplemented).
-  posix=0  - Switch off case sensitivity for paths under this mount point.
-  posix=1  - Switch on case sensitivity for paths under this mount point
-	     (default).
+  acl       - Cygwin uses the filesystem's access control lists (ACLs) to
+              implement real POSIX permissions (default).  This flag only
+	      affects filesystems supporting ACLs (NTFS) and is ignored
+	      otherwise.
+  binary    - Files default to binary mode (default).
+  cygexec   - Treat all files below mount point as cygwin executables.
+  exec      - Treat all files below mount point as executable.
+  immutable - Mount point can only be overridden with mount "override" option.
+  noacl     - Cygwin ignores filesystem ACLs and only fakes a subset of
+	      permission bits based on the DOS readonly attribute.  This
+	      behaviour is the default on FAT and FAT32.  The flag is
+	      ignored on NFS filesystems.
+  nosuid    - No suid files are allowed (currently unimplemented).
+  notexec   - Treat all files below mount point as not executable.
+  nouser    - Mount is a system-wide mount.
+  posix=0   - Switch off case sensitivity for paths under this mount point.
+  posix=1   - Switch on case sensitivity for paths under this mount point
+	      (default).
+  text      - Files default to CRLF text mode line endings.
+  user      - Mount is a user mount.
 </screen>
 
 <para>While normally the execute permission bits are used to evaluate
@@ -105,8 +106,16 @@
 but also prevents Cygwin from setting up commands and environment variables
 for a normal Windows program, adding another small performance gain.  The
 opposite of these options is the <literal>notexec</literal> option, which
-means that no files should be marked as executable under that mount point.
-</para>
+means that no files should be marked as executable under that mount point.</para>
+<para>A correct root directory is quite essential to the operation of
+Cygwin.  A default root directory is evaluated at startup so a
+<filename>fstab</filename> entry for the root directory is not necessary.
+If it's wrong, nothing will work as expected.  Therefore, the root directory
+evaluated by Cygwin itself is treated as an immutable mount point and can't
+be overridden in /etc/fstab... unless you think you really know what you're
+doing.  In this case, use the <literal>override</literal> flag in the options
+field in the <filename>/etc/fstab</filename> file.  Since this is a dangerous
+thing to do, do so at your own risk.</para>
 
 <para><literal>nouser</literal> mount points are not overridable by a later
 call to <command>mount</command>.
Index: utils/mount.cc
===================================================================
RCS file: /cvs/uberbaum/winsup/utils/mount.cc,v
retrieving revision 1.44
diff -d -u -r1.44 mount.cc
--- utils/mount.cc	2 Mar 2009 10:47:04 -0000	1.44
+++ utils/mount.cc	13 May 2009 02:54:02 -0000
@@ -1,7 +1,7 @@
 /* mount.cc
 
    Copyright 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005,
-   2008 Red Hat, Inc.
+   2008, 2009 Red Hat, Inc.
 
 This file is part of Cygwin.
 
@@ -132,16 +132,19 @@
   bool clear;
 } oopts[] =
 {
+  {"acl", MOUNT_NOACL, true},
   {"binary", MOUNT_BINARY, false},
-  {"text", MOUNT_BINARY, true},
-  {"exec", MOUNT_EXEC, false},
-  {"notexec", MOUNT_NOTEXEC, false},
   {"cygexec", MOUNT_CYGWIN_EXEC, false},
-  {"nosuid", 0, 0},
-  {"acl", MOUNT_NOACL, true},
+  {"exec", MOUNT_EXEC, false},
   {"noacl", MOUNT_NOACL, false},
-  {"posix=1", MOUNT_NOPOSIX, true},
+  {"nosuid", 0, 0},
+  {"notexec", MOUNT_NOTEXEC, false},
+  {"nouser", MOUNT_SYSTEM, false},
+  {"override", MOUNT_OVERRIDE, true},
   {"posix=0", MOUNT_NOPOSIX, false},
+  {"posix=1", MOUNT_NOPOSIX, true},
+  {"text", MOUNT_BINARY, true},
+  {"user", MOUNT_SYSTEM, true}
 };
 
 static void
Index: utils/utils.sgml
===================================================================
RCS file: /cvs/uberbaum/winsup/utils/utils.sgml,v
retrieving revision 1.76
diff -d -u -r1.76 utils.sgml
--- utils/utils.sgml	3 Apr 2009 11:50:26 -0000	1.76
+++ utils/utils.sgml	13 May 2009 02:54:02 -0000
@@ -786,16 +786,17 @@
 <screen>
   acl        - Use the filesystem's access control lists (ACLs) to
                implement real POSIX permissions (default).
-  noacl      - Ignore ACLs and fake POSIX permissions.
   binary     - Files default to binary mode (default).
-  text       - Files default to CRLF text mode line endings.
-  exec       - Treat all files below mount point as executable.
-  notexec    - Treat all files below mount point as not executable.
   cygexec    - Treat all files below mount point as cygwin executables.
+  exec       - Treat all files below mount point as executable.
+  noacl      - Ignore ACLs and fake POSIX permissions.
   nosuid     - No suid files are allowed (currently unimplemented)
+  notexec    - Treat all files below mount point as not executable.
+  override   - Override immutable mount points.
   posix=0    - Switch off case sensitivity for paths under this mount point.
   posix=1    - Switch on case sensitivity for paths under this mount point
                (default).
+  text       - Files default to CRLF text mode line endings.
 </screen>
 
 <para>For a more complete description of the mount options and the


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]