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

Corinna Vinschen corinna-cygwin@cygwin.com
Tue May 12 09:41:00 GMT 2009


On May 12 10:13, Corinna Vinschen wrote:
> On May 11 16:18, Christopher Faylor wrote:
> > I don't understand how that fstab would ever mean anything if we're not
> > allowing the overriding of "/".  As I said, I think that the / entry in
> > /etc/fstab should be ignored in favor of finding the root from where the
> > cygwin dll is located.  We could add a "force" option to the "/" option
> > in /etc/fstab if we wanted to override the default behavior.
> 
> How exactly does that influence the /usr/bin and /usr/lib entries?
> Did you see my patch in
> http://cygwin.com/ml/cygwin-developers/2009-05/msg00030.html ?
> Adding a "force" option is not much extra code.

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.


Corinna


    cygwin:

	* mount.cc (mount_info::create_root_entry): Mark root mount as R/O.
	Fix comment.
	(mount_info::create_usr_entries): New function to create
	/usr/bin and /usr/lib entries if they are missing in fstab files.
	(mount_info::init): Simplify.  Remove "Huh?" message.  Call
	create_usr_entries after reading fstab.
	(oopts): Add "force" option.
	(mount_info::add_item): Don't allow to override R/O mount point
	unless the "force" option has been specified.
	(fillout_mntent): Add output for "force" option.
	* mount.h (mount_info::create_usr_entries): Declare.
	* include/sys/mount.h (MOUNT_FORCE): Add.

    doc:

    	* pathnames.sgml: Add "force" mount option description.

    utils:

    	* mount.cc (oopts): Add "force" option.
	(main): Add MOUNT_FORCE mount flag if -f option has been given.
	* utils.sgml: Add "force" mount option description.


Index: cygwin/mount.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/mount.cc,v
retrieving revision 1.35
diff -u -p -r1.35 mount.cc
--- cygwin/mount.cc	4 May 2009 09:16:42 -0000	1.35
+++ cygwin/mount.cc	12 May 2009 09:34:12 -0000
@@ -298,10 +298,12 @@ fs_info::update (PUNICODE_STRING upath, 
 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 from the path the Cygwin DLL is in.
+     The entry is R/O, unless the "force" 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_RO);
   /* 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. */
@@ -310,6 +312,44 @@ mount_info::create_root_entry (const PWC
   cygdrive_len = strlen (cygdrive);
 }
 
+inline void
+mount_info::create_usr_entries ()
+{
+  /* Create default /usr/bin and /usr/lib mount points if they are
+     missing in /etc/fstab. */
+  bool got_usr_bin = false;
+  bool got_usr_lib = false;
+  int root_idx = -1;
+
+  for (int i = 0; i < nmounts; i++)
+    {
+      if (!strcmp (mount[i].posix_path, "/"))
+	root_idx = i;
+      else if (!strcmp (mount[i].posix_path, "/usr/bin"))
+	got_usr_bin = true;
+      else if (!strcmp (mount[i].posix_path, "/usr/lib"))
+	got_usr_lib = true;
+    }
+  if (!got_usr_bin || !got_usr_lib)
+    {
+      char native[PATH_MAX];
+      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);
+	}
+      if (!got_usr_lib)
+	{
+	  stpcpy (p, "\\lib");
+	  mount_table->add_item (native, "/usr/lib",
+				 MOUNT_SYSTEM | MOUNT_BINARY);
+	}
+
+    }
+}
+
 /* init: Initialize the mount table.  */
 
 void
@@ -322,12 +362,9 @@ mount_info::init ()
   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);
+  create_usr_entries ();
 }
 
 static void
@@ -846,7 +883,8 @@ struct opt
   {"acl", MOUNT_NOACL, 1},
   {"noacl", MOUNT_NOACL, 0},
   {"posix=1", MOUNT_NOPOSIX, 1},
-  {"posix=0", MOUNT_NOPOSIX, 0}
+  {"posix=0", MOUNT_NOPOSIX, 0},
+  {"force", MOUNT_FORCE, 0}
 };
 
 static bool
@@ -1244,6 +1282,17 @@ mount_info::add_item (const char *native
 	      set_errno (EPERM);
 	      return -1;
 	    }
+	  /* Don't allow to override R/O mount points unless the "force"
+	     option has been specified. */
+	  if ((mount[i].flags & MOUNT_RO))
+	    {
+	      if (!(mountflags & MOUNT_FORCE))
+		{
+		  set_errno (EPERM);
+		  return -1;
+		}
+	      mountflags |= MOUNT_RO;
+	    }
 	  if ((mount[i].flags & MOUNT_SYSTEM) == (mountflags & MOUNT_SYSTEM))
 	    break;
 	}
@@ -1391,6 +1440,9 @@ fillout_mntent (const char *native_path,
   else
     strcpy (_my_tls.locals.mnt_opts, (char *) "binary");
 
+  if ((flags & (MOUNT_RO | MOUNT_FORCE)) == (MOUNT_RO | MOUNT_FORCE))
+    strcat (_my_tls.locals.mnt_opts, (char *) ",force");
+
   if (flags & MOUNT_CYGWIN_EXEC)
     strcat (_my_tls.locals.mnt_opts, (char *) ",cygexec");
   else if (flags & MOUNT_EXEC)
Index: cygwin/mount.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/mount.h,v
retrieving revision 1.4
diff -u -p -r1.4 mount.h
--- cygwin/mount.h	4 May 2009 09:16:42 -0000	1.4
+++ cygwin/mount.h	12 May 2009 09:34:12 -0000
@@ -140,6 +140,7 @@ class mount_info
   void sort ();
   void mount_slash ();
   void create_root_entry (const PWCHAR root);
+  void create_usr_entries ();
 
   bool from_fstab_line (char *line, bool user);
   bool from_fstab (bool user, WCHAR [], PWCHAR);
Index: cygwin/include/sys/mount.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/include/sys/mount.h,v
retrieving revision 1.12
diff -u -p -r1.12 mount.h
--- cygwin/include/sys/mount.h	16 Jul 2008 20:20:45 -0000	1.12
+++ cygwin/include/sys/mount.h	12 May 2009 09:34:12 -0000
@@ -31,7 +31,8 @@ enum
   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_NOPOSIX =	0x4000, /* Case insensitve path handling */
+  MOUNT_FORCE =		0x8000  /* root dir is R/O unless "forced" */
 };
 
 int mount (const char *, const char *, unsigned __flags);
Index: doc/pathnames.sgml
===================================================================
RCS file: /cvs/src/src/winsup/doc/pathnames.sgml,v
retrieving revision 1.38
diff -u -p -r1.38 pathnames.sgml
--- doc/pathnames.sgml	3 Apr 2009 11:51:31 -0000	1.38
+++ doc/pathnames.sgml	12 May 2009 09:34:12 -0000
@@ -64,7 +64,7 @@ with the filesystem.  It is formatted as
 options.  It contains at least the type of mount (binary or text) plus
 any additional options appropriate to the filesystem type.  Recognized
 options are binary, text, nouser, user, exec, notexec, cygexec, nosuid,
-posix=[0|1].  The meaning of the options is as follows.</para>
+posix=[0|1], force.  The meaning of the options is as follows.</para>
 
 <screen>
   acl      - Cygwin uses the filesystem's access control lists (ACLs) to
@@ -86,6 +86,8 @@ posix=[0|1].  The meaning of the options
   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).
+  force    - The root directory is a readonly mountpoint, unless the "force"
+             flag is given in the options.
 </screen>
 
 <para>While normally the execute permission bits are used to evaluate
@@ -108,6 +110,18 @@ opposite of these options is the <litera
 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 a readonly 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>force</literal> flag in the options
+field in the <filename>/etc/fstab</filename> file.  Only if you specify the
+<literal>force</literal> flag, the automatically generated root directory
+mount point will be overruled by the entry in <filename>/etc/fstab</filename>.
+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>.
 Mount points given in <filename>/etc/fstab</filename> are by default
Index: utils/mount.cc
===================================================================
RCS file: /cvs/src/src/winsup/utils/mount.cc,v
retrieving revision 1.44
diff -u -p -r1.44 mount.cc
--- utils/mount.cc	2 Mar 2009 10:47:04 -0000	1.44
+++ utils/mount.cc	12 May 2009 09:34:12 -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.
 
@@ -142,6 +142,7 @@ struct opt
   {"noacl", MOUNT_NOACL, false},
   {"posix=1", MOUNT_NOPOSIX, true},
   {"posix=0", MOUNT_NOPOSIX, false},
+  {"force", MOUNT_FORCE, true}
 };
 
 static void
@@ -327,7 +328,8 @@ main (int argc, char **argv)
 	  usage ();
 	}
       if (force || !mount_already_exists (argv[optind + 1], flags))
-	do_mount (argv[optind], argv[optind + 1], flags);
+	do_mount (argv[optind], argv[optind + 1],
+		  flags | (force ? MOUNT_FORCE : 0));
       else
 	{
 	  errno = EBUSY;
Index: utils/utils.sgml
===================================================================
RCS file: /cvs/src/src/winsup/utils/utils.sgml,v
retrieving revision 1.76
diff -u -p -r1.76 utils.sgml
--- utils/utils.sgml	3 Apr 2009 11:50:26 -0000	1.76
+++ utils/utils.sgml	12 May 2009 09:34:13 -0000
@@ -796,6 +796,9 @@ most of the options are duplicates of ot
   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).
+  force      - The root directory is a readonly mountpoint, unless the "force"
+               flag is given in the options, or the -f command line option
+	       has been used.
 </screen>
 
 <para>For a more complete description of the mount options and the

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat



More information about the Cygwin-developers mailing list