2004-12-03 Pierre Humblet <pierre.humblet@ieee.org>
* registry.h (reg_key::reg_key): Change arguments. * shared_info.h (class mount_info): Remove had_to_create_mount_areas. * registry.cc (reg_key::reg_key): Change constructors to always handle HKLM and to avoid relying on HKCU. Do not set mount_table->had_to_create_mount_areas. * path.cc (mount_info::conv_to_win32_path): Improve update of sys_mount_table_counter. (mount_info::read_mounts): Use new reg_key constructor. (mount_info::add_reg_mount): Ditto. (mount_info::del_reg_mount): Ditto. (mount_info::read_cygdrive_info_from_registry): Ditto. (mount_info::write_cygdrive_info_to_registry): Ditto. Update cygwin_shared->sys_mount_table_counter after registry update. (mount_info::get_cygdrive_info): Ditto. * shared.cc (shared_info::heap_chunk_size): Use new reg_key constructor. * environ.cc (regopt): Ditto.
This commit is contained in:
		
							parent
							
								
									3263f819aa
								
							
						
					
					
						commit
						8151e674ba
					
				| 
						 | 
				
			
			@ -1,3 +1,22 @@
 | 
			
		|||
2004-12-03  Pierre Humblet <pierre.humblet@ieee.org>
 | 
			
		||||
 | 
			
		||||
	* registry.h (reg_key::reg_key): Change arguments.
 | 
			
		||||
	* shared_info.h (class mount_info): Remove had_to_create_mount_areas.
 | 
			
		||||
	* registry.cc (reg_key::reg_key): Change constructors to always handle
 | 
			
		||||
	HKLM and to avoid relying on HKCU. 
 | 
			
		||||
	Do not set mount_table->had_to_create_mount_areas. 
 | 
			
		||||
	* path.cc (mount_info::conv_to_win32_path): Improve update of 
 | 
			
		||||
	sys_mount_table_counter.
 | 
			
		||||
	(mount_info::read_mounts): Use new reg_key constructor.	
 | 
			
		||||
	(mount_info::add_reg_mount): Ditto. 
 | 
			
		||||
	(mount_info::del_reg_mount): Ditto.
 | 
			
		||||
	(mount_info::read_cygdrive_info_from_registry): Ditto. 
 | 
			
		||||
	(mount_info::write_cygdrive_info_to_registry): Ditto.
 | 
			
		||||
	Update cygwin_shared->sys_mount_table_counter after registry update.
 | 
			
		||||
	(mount_info::get_cygdrive_info): Ditto.
 | 
			
		||||
	* shared.cc (shared_info::heap_chunk_size): Use new reg_key constructor.
 | 
			
		||||
	* environ.cc (regopt): Ditto.
 | 
			
		||||
 | 
			
		||||
2004-12-01  Christopher Faylor  <cgf@timesys.com>
 | 
			
		||||
 | 
			
		||||
	* include/features.h: Include sys/cdefs.h, like linux.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -640,29 +640,22 @@ static bool __stdcall
 | 
			
		|||
regopt (const char *name)
 | 
			
		||||
{
 | 
			
		||||
  bool parsed_something = false;
 | 
			
		||||
  /* FIXME: should not be under mount */
 | 
			
		||||
  reg_key r (KEY_READ, CYGWIN_INFO_PROGRAM_OPTIONS_NAME, NULL);
 | 
			
		||||
  char buf[CYG_MAX_PATH];
 | 
			
		||||
  char lname[strlen (name) + 1];
 | 
			
		||||
  strlwr (strcpy (lname, name));
 | 
			
		||||
 | 
			
		||||
  if (r.get_string (lname, buf, sizeof (buf) - 1, "") == ERROR_SUCCESS)
 | 
			
		||||
  for (int i = 0; i < 2; i++)
 | 
			
		||||
    {
 | 
			
		||||
      parse_options (buf);
 | 
			
		||||
      parsed_something = true;
 | 
			
		||||
    }
 | 
			
		||||
  else
 | 
			
		||||
    {
 | 
			
		||||
      reg_key r1 (HKEY_LOCAL_MACHINE, KEY_READ, "SOFTWARE",
 | 
			
		||||
		  CYGWIN_INFO_CYGNUS_REGISTRY_NAME,
 | 
			
		||||
		  CYGWIN_INFO_CYGWIN_REGISTRY_NAME,
 | 
			
		||||
		  CYGWIN_INFO_PROGRAM_OPTIONS_NAME, NULL);
 | 
			
		||||
      if (r1.get_string (lname, buf, sizeof (buf) - 1, "") == ERROR_SUCCESS)
 | 
			
		||||
      reg_key r (i, KEY_READ, CYGWIN_INFO_PROGRAM_OPTIONS_NAME, NULL);
 | 
			
		||||
 | 
			
		||||
      if (r.get_string (lname, buf, sizeof (buf) - 1, "") == ERROR_SUCCESS)
 | 
			
		||||
	{
 | 
			
		||||
	  parse_options (buf);
 | 
			
		||||
	  parsed_something = true;
 | 
			
		||||
	  break;
 | 
			
		||||
	}
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  MALLOC_CHECK;
 | 
			
		||||
  return parsed_something;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -120,8 +120,6 @@ create_shortcut_header (void)
 | 
			
		|||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#define CYGWIN_REGNAME (cygheap->cygwin_regname ?: CYGWIN_INFO_CYGWIN_REGISTRY_NAME)
 | 
			
		||||
 | 
			
		||||
/* Determine if path prefix matches current cygdrive */
 | 
			
		||||
#define iscygdrive(path) \
 | 
			
		||||
  (path_prefix_p (mount_table->cygdrive, (path), mount_table->cygdrive_len))
 | 
			
		||||
| 
						 | 
				
			
			@ -1400,8 +1398,9 @@ mount_info::conv_to_win32_path (const char *src_path, char *dst, device& dev,
 | 
			
		|||
  bool chroot_ok = !cygheap->root.exists ();
 | 
			
		||||
  while (sys_mount_table_counter < cygwin_shared->sys_mount_table_counter)
 | 
			
		||||
    {
 | 
			
		||||
      int current = cygwin_shared->sys_mount_table_counter;
 | 
			
		||||
      init ();
 | 
			
		||||
      sys_mount_table_counter++;
 | 
			
		||||
      sys_mount_table_counter = current;
 | 
			
		||||
    }
 | 
			
		||||
  MALLOC_CHECK;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1753,7 +1752,7 @@ mount_info::read_mounts (reg_key& r)
 | 
			
		|||
      char native_path[CYG_MAX_PATH];
 | 
			
		||||
      int mount_flags;
 | 
			
		||||
 | 
			
		||||
      posix_path_size = CYG_MAX_PATH;
 | 
			
		||||
      posix_path_size = sizeof (posix_path);
 | 
			
		||||
      /* FIXME: if maximum posix_path_size is 256, we're going to
 | 
			
		||||
	 run into problems if we ever try to store a mount point that's
 | 
			
		||||
	 over 256 but is under CYG_MAX_PATH. */
 | 
			
		||||
| 
						 | 
				
			
			@ -1788,27 +1787,23 @@ mount_info::read_mounts (reg_key& r)
 | 
			
		|||
void
 | 
			
		||||
mount_info::from_registry ()
 | 
			
		||||
{
 | 
			
		||||
  /* Use current mount areas if either user or system mount areas
 | 
			
		||||
     already exist.  Otherwise, import old mounts. */
 | 
			
		||||
 | 
			
		||||
  reg_key r;
 | 
			
		||||
 | 
			
		||||
  /* Retrieve cygdrive-related information. */
 | 
			
		||||
  read_cygdrive_info_from_registry ();
 | 
			
		||||
 | 
			
		||||
  nmounts = 0;
 | 
			
		||||
 | 
			
		||||
  /* First read mounts from user's table. */
 | 
			
		||||
  read_mounts (r);
 | 
			
		||||
 | 
			
		||||
  /* Then read mounts from system-wide mount table. */
 | 
			
		||||
  cygheap->user.deimpersonate ();
 | 
			
		||||
  reg_key r1 (HKEY_LOCAL_MACHINE, KEY_READ, "SOFTWARE",
 | 
			
		||||
	      CYGWIN_INFO_CYGNUS_REGISTRY_NAME, CYGWIN_REGNAME,
 | 
			
		||||
	      CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME,
 | 
			
		||||
	      NULL);
 | 
			
		||||
  read_mounts (r1);
 | 
			
		||||
  cygheap->user.reimpersonate ();
 | 
			
		||||
  /* First read mounts from user's table.
 | 
			
		||||
     Then read mounts from system-wide mount table while deimpersonated . */
 | 
			
		||||
  for (int i = 0; i < 2; i++)
 | 
			
		||||
    {
 | 
			
		||||
      if (i)
 | 
			
		||||
	cygheap->user.deimpersonate ();
 | 
			
		||||
      reg_key r (i, KEY_READ, CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME, NULL);
 | 
			
		||||
      read_mounts (r);
 | 
			
		||||
      if (i)
 | 
			
		||||
	cygheap->user.reimpersonate ();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* add_reg_mount: Add mount item to registry.  Return zero on success,
 | 
			
		||||
| 
						 | 
				
			
			@ -1818,66 +1813,37 @@ mount_info::from_registry ()
 | 
			
		|||
int
 | 
			
		||||
mount_info::add_reg_mount (const char *native_path, const char *posix_path, unsigned mountflags)
 | 
			
		||||
{
 | 
			
		||||
  int res = 0;
 | 
			
		||||
 | 
			
		||||
  if (strchr (posix_path, '\\'))
 | 
			
		||||
    {
 | 
			
		||||
      set_errno (EINVAL);
 | 
			
		||||
      goto err1;
 | 
			
		||||
    }
 | 
			
		||||
  int res;
 | 
			
		||||
 | 
			
		||||
  /* Add the mount to the right registry location, depending on
 | 
			
		||||
     whether MOUNT_SYSTEM is set in the mount flags. */
 | 
			
		||||
  if (!(mountflags & MOUNT_SYSTEM)) /* current_user mount */
 | 
			
		||||
 | 
			
		||||
  reg_key reg (mountflags & MOUNT_SYSTEM,  KEY_ALL_ACCESS,
 | 
			
		||||
	       CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME, NULL);
 | 
			
		||||
 | 
			
		||||
  /* Start by deleting existing mount if one exists. */
 | 
			
		||||
  res = reg.kill (posix_path);
 | 
			
		||||
  if (res != ERROR_SUCCESS && res != ERROR_FILE_NOT_FOUND)
 | 
			
		||||
    {
 | 
			
		||||
      /* reg_key for user mounts in HKEY_CURRENT_USER. */
 | 
			
		||||
      reg_key reg_user;
 | 
			
		||||
 | 
			
		||||
      /* Start by deleting existing mount if one exists. */
 | 
			
		||||
      res = reg_user.kill (posix_path);
 | 
			
		||||
      if (res != ERROR_SUCCESS && res != ERROR_FILE_NOT_FOUND)
 | 
			
		||||
	goto err;
 | 
			
		||||
 | 
			
		||||
      /* Create the new mount. */
 | 
			
		||||
      reg_key subkey = reg_key (reg_user.get_key (),
 | 
			
		||||
				KEY_ALL_ACCESS,
 | 
			
		||||
				posix_path, NULL);
 | 
			
		||||
      res = subkey.set_string ("native", native_path);
 | 
			
		||||
      if (res != ERROR_SUCCESS)
 | 
			
		||||
	goto err;
 | 
			
		||||
      res = subkey.set_int ("flags", mountflags);
 | 
			
		||||
 err:
 | 
			
		||||
      __seterrno_from_win_error (res);
 | 
			
		||||
      return -1;
 | 
			
		||||
    }
 | 
			
		||||
  else /* local_machine mount */
 | 
			
		||||
 | 
			
		||||
  /* Create the new mount. */
 | 
			
		||||
  reg_key subkey (reg.get_key (), KEY_ALL_ACCESS, posix_path, NULL);
 | 
			
		||||
 | 
			
		||||
  res = subkey.set_string ("native", native_path);
 | 
			
		||||
  if (res != ERROR_SUCCESS)
 | 
			
		||||
    goto err;
 | 
			
		||||
  res = subkey.set_int ("flags", mountflags);
 | 
			
		||||
  
 | 
			
		||||
  if (mountflags & MOUNT_SYSTEM)
 | 
			
		||||
    {
 | 
			
		||||
      /* reg_key for system mounts in HKEY_LOCAL_MACHINE. */
 | 
			
		||||
      reg_key reg_sys (HKEY_LOCAL_MACHINE, KEY_ALL_ACCESS, "SOFTWARE",
 | 
			
		||||
		       CYGWIN_INFO_CYGNUS_REGISTRY_NAME, CYGWIN_REGNAME,
 | 
			
		||||
		       CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME,
 | 
			
		||||
		       NULL);
 | 
			
		||||
 | 
			
		||||
      /* Start by deleting existing mount if one exists. */
 | 
			
		||||
      res = reg_sys.kill (posix_path);
 | 
			
		||||
      if (res != ERROR_SUCCESS && res != ERROR_FILE_NOT_FOUND)
 | 
			
		||||
	goto err;
 | 
			
		||||
 | 
			
		||||
      /* Create the new mount. */
 | 
			
		||||
      reg_key subkey = reg_key (reg_sys.get_key (),
 | 
			
		||||
				KEY_ALL_ACCESS,
 | 
			
		||||
				posix_path, NULL);
 | 
			
		||||
      res = subkey.set_string ("native", native_path);
 | 
			
		||||
      if (res != ERROR_SUCCESS)
 | 
			
		||||
	goto err;
 | 
			
		||||
      res = subkey.set_int ("flags", mountflags);
 | 
			
		||||
 | 
			
		||||
      sys_mount_table_counter++;
 | 
			
		||||
      cygwin_shared->sys_mount_table_counter++;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    }  
 | 
			
		||||
  return 0; /* Success */
 | 
			
		||||
 err:
 | 
			
		||||
  __seterrno_from_win_error (res);
 | 
			
		||||
 err1:
 | 
			
		||||
  return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* del_reg_mount: delete mount item from registry indicated in flags.
 | 
			
		||||
| 
						 | 
				
			
			@ -1889,22 +1855,9 @@ mount_info::del_reg_mount (const char * posix_path, unsigned flags)
 | 
			
		|||
{
 | 
			
		||||
  int res;
 | 
			
		||||
 | 
			
		||||
  if (!(flags & MOUNT_SYSTEM))	/* Delete from user registry */
 | 
			
		||||
    {
 | 
			
		||||
      reg_key reg_user (KEY_ALL_ACCESS,
 | 
			
		||||
			CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME, NULL);
 | 
			
		||||
      res = reg_user.kill (posix_path);
 | 
			
		||||
    }
 | 
			
		||||
  else					/* Delete from system registry */
 | 
			
		||||
    {
 | 
			
		||||
      sys_mount_table_counter++;
 | 
			
		||||
      cygwin_shared->sys_mount_table_counter++;
 | 
			
		||||
      reg_key reg_sys (HKEY_LOCAL_MACHINE, KEY_ALL_ACCESS, "SOFTWARE",
 | 
			
		||||
		       CYGWIN_INFO_CYGNUS_REGISTRY_NAME, CYGWIN_REGNAME,
 | 
			
		||||
		       CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME,
 | 
			
		||||
		       NULL);
 | 
			
		||||
      res = reg_sys.kill (posix_path);
 | 
			
		||||
    }
 | 
			
		||||
  reg_key reg (flags & MOUNT_SYSTEM, KEY_ALL_ACCESS,
 | 
			
		||||
	       CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME, NULL);
 | 
			
		||||
  res = reg.kill (posix_path);
 | 
			
		||||
 | 
			
		||||
  if (res != ERROR_SUCCESS)
 | 
			
		||||
    {
 | 
			
		||||
| 
						 | 
				
			
			@ -1912,6 +1865,12 @@ mount_info::del_reg_mount (const char * posix_path, unsigned flags)
 | 
			
		|||
      return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  if (flags & MOUNT_SYSTEM)
 | 
			
		||||
    {
 | 
			
		||||
      sys_mount_table_counter++;
 | 
			
		||||
      cygwin_shared->sys_mount_table_counter++;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  return 0; /* Success */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1922,31 +1881,29 @@ mount_info::del_reg_mount (const char * posix_path, unsigned flags)
 | 
			
		|||
void
 | 
			
		||||
mount_info::read_cygdrive_info_from_registry ()
 | 
			
		||||
{
 | 
			
		||||
  /* reg_key for user path prefix in HKEY_CURRENT_USER. */
 | 
			
		||||
  reg_key r;
 | 
			
		||||
  /* First read cygdrive from user's registry. */
 | 
			
		||||
  if (r.get_string (CYGWIN_INFO_CYGDRIVE_PREFIX, cygdrive, sizeof (cygdrive), "") != 0)
 | 
			
		||||
  /* First read cygdrive from user's registry.
 | 
			
		||||
     If failed, then read cygdrive from system-wide registry
 | 
			
		||||
     while deimpersonated. */
 | 
			
		||||
  for (int i = 0; i < 2; i++)
 | 
			
		||||
    {
 | 
			
		||||
      /* Then read cygdrive from system-wide registry. */
 | 
			
		||||
      cygheap->user.deimpersonate ();
 | 
			
		||||
      reg_key r2 (HKEY_LOCAL_MACHINE, KEY_READ, "SOFTWARE",
 | 
			
		||||
		 CYGWIN_INFO_CYGNUS_REGISTRY_NAME, CYGWIN_REGNAME,
 | 
			
		||||
		 CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME,
 | 
			
		||||
		 NULL);
 | 
			
		||||
      cygheap->user.reimpersonate ();
 | 
			
		||||
      if (i)
 | 
			
		||||
	cygheap->user.deimpersonate ();	
 | 
			
		||||
      reg_key r (i, KEY_READ, CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME, NULL);
 | 
			
		||||
      if (i)
 | 
			
		||||
	cygheap->user.reimpersonate ();
 | 
			
		||||
 | 
			
		||||
      if (r2.get_string (CYGWIN_INFO_CYGDRIVE_PREFIX, cygdrive,
 | 
			
		||||
	  sizeof (cygdrive), ""))
 | 
			
		||||
	strcpy (cygdrive, CYGWIN_INFO_CYGDRIVE_DEFAULT_PREFIX);
 | 
			
		||||
      cygdrive_flags = r2.get_int (CYGWIN_INFO_CYGDRIVE_FLAGS, MOUNT_CYGDRIVE | MOUNT_BINARY);
 | 
			
		||||
      slashify (cygdrive, cygdrive, 1);
 | 
			
		||||
      cygdrive_len = strlen (cygdrive);
 | 
			
		||||
    }
 | 
			
		||||
  else
 | 
			
		||||
    {
 | 
			
		||||
      /* Fetch user cygdrive_flags from registry; returns MOUNT_CYGDRIVE on
 | 
			
		||||
	 error. */
 | 
			
		||||
      cygdrive_flags = r.get_int (CYGWIN_INFO_CYGDRIVE_FLAGS, MOUNT_CYGDRIVE | MOUNT_BINARY);
 | 
			
		||||
      if (r.get_string (CYGWIN_INFO_CYGDRIVE_PREFIX, cygdrive, sizeof (cygdrive), 
 | 
			
		||||
			CYGWIN_INFO_CYGDRIVE_DEFAULT_PREFIX) != ERROR_SUCCESS && i == 0)
 | 
			
		||||
	continue;
 | 
			
		||||
 | 
			
		||||
      /* Fetch user cygdrive_flags from registry; returns MOUNT_CYGDRIVE on error. */
 | 
			
		||||
      cygdrive_flags = r.get_int (CYGWIN_INFO_CYGDRIVE_FLAGS, 
 | 
			
		||||
				  MOUNT_CYGDRIVE | MOUNT_BINARY);
 | 
			
		||||
      /* Sanitize */
 | 
			
		||||
      if (i == 0)
 | 
			
		||||
        cygdrive_flags &= ~MOUNT_SYSTEM;
 | 
			
		||||
      else
 | 
			
		||||
        cygdrive_flags |= MOUNT_SYSTEM;	
 | 
			
		||||
      slashify (cygdrive, cygdrive, 1);
 | 
			
		||||
      cygdrive_len = strlen (cygdrive);
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -1959,22 +1916,6 @@ mount_info::read_cygdrive_info_from_registry ()
 | 
			
		|||
int
 | 
			
		||||
mount_info::write_cygdrive_info_to_registry (const char *cygdrive_prefix, unsigned flags)
 | 
			
		||||
{
 | 
			
		||||
  /* Determine whether to modify user or system cygdrive path prefix. */
 | 
			
		||||
  HKEY top = (flags & MOUNT_SYSTEM) ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
 | 
			
		||||
 | 
			
		||||
  if (flags & MOUNT_SYSTEM)
 | 
			
		||||
    {
 | 
			
		||||
      sys_mount_table_counter++;
 | 
			
		||||
      cygwin_shared->sys_mount_table_counter++;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  /* reg_key for user path prefix in HKEY_CURRENT_USER or system path prefix in
 | 
			
		||||
     HKEY_LOCAL_MACHINE.  */
 | 
			
		||||
  reg_key r (top, KEY_ALL_ACCESS, "SOFTWARE",
 | 
			
		||||
	     CYGWIN_INFO_CYGNUS_REGISTRY_NAME, CYGWIN_REGNAME,
 | 
			
		||||
	     CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME,
 | 
			
		||||
	     NULL);
 | 
			
		||||
 | 
			
		||||
  /* Verify cygdrive prefix starts with a forward slash and if there's
 | 
			
		||||
     another character, it's not a slash. */
 | 
			
		||||
  if ((cygdrive_prefix == NULL) || (*cygdrive_prefix == 0) ||
 | 
			
		||||
| 
						 | 
				
			
			@ -1989,6 +1930,8 @@ mount_info::write_cygdrive_info_to_registry (const char *cygdrive_prefix, unsign
 | 
			
		|||
  /* Ensure that there is never a final slash */
 | 
			
		||||
  nofinalslash (cygdrive_prefix, hold_cygdrive_prefix);
 | 
			
		||||
 | 
			
		||||
  reg_key r (flags & MOUNT_SYSTEM, KEY_ALL_ACCESS, 
 | 
			
		||||
	     CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME, NULL);
 | 
			
		||||
  int res;
 | 
			
		||||
  res = r.set_string (CYGWIN_INFO_CYGDRIVE_PREFIX, hold_cygdrive_prefix);
 | 
			
		||||
  if (res != ERROR_SUCCESS)
 | 
			
		||||
| 
						 | 
				
			
			@ -1998,15 +1941,18 @@ mount_info::write_cygdrive_info_to_registry (const char *cygdrive_prefix, unsign
 | 
			
		|||
    }
 | 
			
		||||
  r.set_int (CYGWIN_INFO_CYGDRIVE_FLAGS, flags);
 | 
			
		||||
 | 
			
		||||
  if (flags & MOUNT_SYSTEM)
 | 
			
		||||
    sys_mount_table_counter = ++cygwin_shared->sys_mount_table_counter;
 | 
			
		||||
 | 
			
		||||
  /* This also needs to go in the in-memory copy of "cygdrive", but only if
 | 
			
		||||
     appropriate:
 | 
			
		||||
       1. setting user path prefix, or
 | 
			
		||||
       2. overwriting (a previous) system path prefix */
 | 
			
		||||
  if (!(flags & MOUNT_SYSTEM) || (mount_table->cygdrive_flags & MOUNT_SYSTEM))
 | 
			
		||||
    {
 | 
			
		||||
      slashify (cygdrive_prefix, mount_table->cygdrive, 1);
 | 
			
		||||
      mount_table->cygdrive_flags = flags;
 | 
			
		||||
      mount_table->cygdrive_len = strlen (mount_table->cygdrive);
 | 
			
		||||
      slashify (cygdrive_prefix, cygdrive, 1);
 | 
			
		||||
      cygdrive_flags = flags;
 | 
			
		||||
      cygdrive_len = strlen (cygdrive);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  return 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -2015,19 +1961,7 @@ mount_info::write_cygdrive_info_to_registry (const char *cygdrive_prefix, unsign
 | 
			
		|||
int
 | 
			
		||||
mount_info::remove_cygdrive_info_from_registry (const char *cygdrive_prefix, unsigned flags)
 | 
			
		||||
{
 | 
			
		||||
  /* Determine whether to modify user or system cygdrive path prefix. */
 | 
			
		||||
  HKEY top = (flags & MOUNT_SYSTEM) ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
 | 
			
		||||
 | 
			
		||||
  if (flags & MOUNT_SYSTEM)
 | 
			
		||||
    {
 | 
			
		||||
      sys_mount_table_counter++;
 | 
			
		||||
      cygwin_shared->sys_mount_table_counter++;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
  /* reg_key for user path prefix in HKEY_CURRENT_USER or system path prefix in
 | 
			
		||||
     HKEY_LOCAL_MACHINE.  */
 | 
			
		||||
  reg_key r (top, KEY_ALL_ACCESS, "SOFTWARE",
 | 
			
		||||
	     CYGWIN_INFO_CYGNUS_REGISTRY_NAME, CYGWIN_REGNAME,
 | 
			
		||||
  reg_key r (flags & MOUNT_SYSTEM, KEY_ALL_ACCESS, 
 | 
			
		||||
	     CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME,
 | 
			
		||||
	     NULL);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2035,11 +1969,20 @@ mount_info::remove_cygdrive_info_from_registry (const char *cygdrive_prefix, uns
 | 
			
		|||
  int res = r.killvalue (CYGWIN_INFO_CYGDRIVE_PREFIX);
 | 
			
		||||
  int res2 = r.killvalue (CYGWIN_INFO_CYGDRIVE_FLAGS);
 | 
			
		||||
 | 
			
		||||
  if (flags & MOUNT_SYSTEM)
 | 
			
		||||
    sys_mount_table_counter = ++cygwin_shared->sys_mount_table_counter;
 | 
			
		||||
 | 
			
		||||
  /* Reinitialize the cygdrive path prefix to reflect to removal from the
 | 
			
		||||
     registry. */
 | 
			
		||||
  read_cygdrive_info_from_registry ();
 | 
			
		||||
 | 
			
		||||
  return (res != ERROR_SUCCESS) ? res : res2;
 | 
			
		||||
  if (res == ERROR_SUCCESS)
 | 
			
		||||
    res = res2;
 | 
			
		||||
  if (res == ERROR_SUCCESS)
 | 
			
		||||
    return 0;
 | 
			
		||||
 | 
			
		||||
  __seterrno_from_win_error (res);
 | 
			
		||||
  return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
| 
						 | 
				
			
			@ -2047,7 +1990,7 @@ mount_info::get_cygdrive_info (char *user, char *system, char* user_flags,
 | 
			
		|||
			       char* system_flags)
 | 
			
		||||
{
 | 
			
		||||
  /* Get the user path prefix from HKEY_CURRENT_USER. */
 | 
			
		||||
  reg_key r;
 | 
			
		||||
  reg_key r (false,  KEY_READ, CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME, NULL);
 | 
			
		||||
  int res = r.get_string (CYGWIN_INFO_CYGDRIVE_PREFIX, user, CYG_MAX_PATH, "");
 | 
			
		||||
 | 
			
		||||
  /* Get the user flags, if appropriate */
 | 
			
		||||
| 
						 | 
				
			
			@ -2058,10 +2001,7 @@ mount_info::get_cygdrive_info (char *user, char *system, char* user_flags,
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
  /* Get the system path prefix from HKEY_LOCAL_MACHINE. */
 | 
			
		||||
  reg_key r2 (HKEY_LOCAL_MACHINE, KEY_READ, "SOFTWARE",
 | 
			
		||||
	      CYGWIN_INFO_CYGNUS_REGISTRY_NAME, CYGWIN_REGNAME,
 | 
			
		||||
	      CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME,
 | 
			
		||||
	      NULL);
 | 
			
		||||
  reg_key r2 (true,  KEY_READ, CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME, NULL);
 | 
			
		||||
  int res2 = r2.get_string (CYGWIN_INFO_CYGDRIVE_PREFIX, system, CYG_MAX_PATH, "");
 | 
			
		||||
 | 
			
		||||
  /* Get the system flags, if appropriate */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,8 +13,12 @@ details. */
 | 
			
		|||
#include "registry.h"
 | 
			
		||||
#include "security.h"
 | 
			
		||||
#include <cygwin/version.h>
 | 
			
		||||
 | 
			
		||||
static char NO_COPY cygnus_class[] = "cygnus";
 | 
			
		||||
#include "path.h"
 | 
			
		||||
#include "fhandler.h"
 | 
			
		||||
#include "dtable.h"
 | 
			
		||||
#include "cygerrno.h"
 | 
			
		||||
#include "cygheap.h"
 | 
			
		||||
static const char cygnus_class[] = "cygnus";
 | 
			
		||||
 | 
			
		||||
reg_key::reg_key (HKEY top, REGSAM access, ...)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -24,30 +28,46 @@ reg_key::reg_key (HKEY top, REGSAM access, ...)
 | 
			
		|||
  va_end (av);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
reg_key::reg_key (REGSAM access, ...)
 | 
			
		||||
/* Opens a key under the appropriate Cygwin key.
 | 
			
		||||
   Do not use HKCU per MS KB 199190  */
 | 
			
		||||
 
 | 
			
		||||
reg_key::reg_key (bool isHKLM, REGSAM access, ...)
 | 
			
		||||
{
 | 
			
		||||
  va_list av;
 | 
			
		||||
  HKEY top;
 | 
			
		||||
 | 
			
		||||
  new (this) reg_key (HKEY_CURRENT_USER, access, "SOFTWARE",
 | 
			
		||||
		 CYGWIN_INFO_CYGNUS_REGISTRY_NAME,
 | 
			
		||||
		 CYGWIN_INFO_CYGWIN_REGISTRY_NAME, NULL);
 | 
			
		||||
 | 
			
		||||
  HKEY top = key;
 | 
			
		||||
  if (isHKLM)
 | 
			
		||||
    top = HKEY_LOCAL_MACHINE;
 | 
			
		||||
  else
 | 
			
		||||
    {
 | 
			
		||||
      char name[128]; 
 | 
			
		||||
      const char *names[2] = {cygheap->user.get_windows_id (name), ".DEFAULT"}; 
 | 
			
		||||
      for (int i = 0; i < 2; i++)
 | 
			
		||||
	{
 | 
			
		||||
	  key_is_invalid = RegOpenKeyEx (HKEY_USERS, names[i], 0, access, &top);
 | 
			
		||||
	  if (key_is_invalid == ERROR_SUCCESS)
 | 
			
		||||
	    goto OK;
 | 
			
		||||
	  debug_printf ("HKU\\%s failed, Win32 error %ld", names[i], key_is_invalid);
 | 
			
		||||
	}
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
OK:
 | 
			
		||||
  new (this) reg_key (top, access, "SOFTWARE", 
 | 
			
		||||
		      CYGWIN_INFO_CYGNUS_REGISTRY_NAME,
 | 
			
		||||
		      CYGWIN_INFO_CYGWIN_REGISTRY_NAME, NULL);
 | 
			
		||||
  if (top != HKEY_LOCAL_MACHINE)
 | 
			
		||||
    RegCloseKey (top);
 | 
			
		||||
  if (key_is_invalid)
 | 
			
		||||
    return;
 | 
			
		||||
    
 | 
			
		||||
  top = key;
 | 
			
		||||
  va_start (av, access);
 | 
			
		||||
  build_reg (top, KEY_READ, av);
 | 
			
		||||
  build_reg (top, access, av);
 | 
			
		||||
  va_end (av);
 | 
			
		||||
  if (top != key)
 | 
			
		||||
    RegCloseKey (top);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
reg_key::reg_key (REGSAM access)
 | 
			
		||||
{
 | 
			
		||||
  new (this) reg_key (HKEY_CURRENT_USER, access, "SOFTWARE",
 | 
			
		||||
		 CYGWIN_INFO_CYGNUS_REGISTRY_NAME,
 | 
			
		||||
		 CYGWIN_INFO_CYGWIN_REGISTRY_NAME,
 | 
			
		||||
		 CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME, NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
reg_key::build_reg (HKEY top, REGSAM access, va_list av)
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -62,16 +82,15 @@ reg_key::build_reg (HKEY top, REGSAM access, va_list av)
 | 
			
		|||
 | 
			
		||||
  while ((name = va_arg (av, char *)) != NULL)
 | 
			
		||||
    {
 | 
			
		||||
      DWORD disp;
 | 
			
		||||
      int res = RegCreateKeyExA (r,
 | 
			
		||||
				 name,
 | 
			
		||||
				 0,
 | 
			
		||||
				 cygnus_class,
 | 
			
		||||
				 (char *) cygnus_class,
 | 
			
		||||
				 REG_OPTION_NON_VOLATILE,
 | 
			
		||||
				 access,
 | 
			
		||||
				 &sec_none_nih,
 | 
			
		||||
				 &key,
 | 
			
		||||
				 &disp);
 | 
			
		||||
				 NULL);
 | 
			
		||||
      if (r != top)
 | 
			
		||||
	RegCloseKey (r);
 | 
			
		||||
      r = key;
 | 
			
		||||
| 
						 | 
				
			
			@ -81,12 +100,6 @@ reg_key::build_reg (HKEY top, REGSAM access, va_list av)
 | 
			
		|||
	  debug_printf ("failed to create key %s in the registry", name);
 | 
			
		||||
	  break;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
      /* If we're considering the mounts key, check if it had to
 | 
			
		||||
	 be created and set had_to_create appropriately. */
 | 
			
		||||
      if (strcmp (name, CYGWIN_INFO_CYGWIN_MOUNT_REGISTRY_NAME) == 0)
 | 
			
		||||
	if (disp == REG_CREATED_NEW_KEY)
 | 
			
		||||
	  mount_table->had_to_create_mount_areas++;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,8 +18,7 @@ private:
 | 
			
		|||
public:
 | 
			
		||||
 | 
			
		||||
  reg_key (HKEY toplev, REGSAM access, ...);
 | 
			
		||||
  reg_key (REGSAM access, ...);
 | 
			
		||||
  reg_key (REGSAM access = KEY_ALL_ACCESS);
 | 
			
		||||
  reg_key (bool isHKLM, REGSAM access, ...);
 | 
			
		||||
 | 
			
		||||
  void *operator new (size_t, void *p) {return p;}
 | 
			
		||||
  void build_reg (HKEY key, REGSAM access, va_list av);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -250,22 +250,20 @@ shared_info::heap_chunk_size ()
 | 
			
		|||
{
 | 
			
		||||
  if (!heap_chunk)
 | 
			
		||||
    {
 | 
			
		||||
      /* Fetch misc. registry entries.  */
 | 
			
		||||
      /* Fetch from registry, first user then local machine.  */
 | 
			
		||||
      for (int i = 0; i < 2; i++)
 | 
			
		||||
	{
 | 
			
		||||
	  reg_key reg (i, KEY_READ, NULL);
 | 
			
		||||
 | 
			
		||||
      reg_key reg (KEY_READ, NULL);
 | 
			
		||||
	  /* Note that reserving a huge amount of heap space does not result in
 | 
			
		||||
	     the use of swap since we are not committing it. */
 | 
			
		||||
	  /* FIXME: We should not be restricted to a fixed size heap no matter
 | 
			
		||||
	     what the fixed size is. */
 | 
			
		||||
 | 
			
		||||
      /* Note that reserving a huge amount of heap space does not result in
 | 
			
		||||
      the use of swap since we are not committing it. */
 | 
			
		||||
      /* FIXME: We should not be restricted to a fixed size heap no matter
 | 
			
		||||
      what the fixed size is. */
 | 
			
		||||
 | 
			
		||||
      heap_chunk = reg.get_int ("heap_chunk_in_mb", 0);
 | 
			
		||||
      if (!heap_chunk) {
 | 
			
		||||
	reg_key r1 (HKEY_LOCAL_MACHINE, KEY_READ, "SOFTWARE",
 | 
			
		||||
		    CYGWIN_INFO_CYGNUS_REGISTRY_NAME,
 | 
			
		||||
		    CYGWIN_INFO_CYGWIN_REGISTRY_NAME, NULL);
 | 
			
		||||
	heap_chunk = r1.get_int ("heap_chunk_in_mb", 384);
 | 
			
		||||
      }
 | 
			
		||||
	  if ((heap_chunk = reg.get_int ("heap_chunk_in_mb", 0)))
 | 
			
		||||
	    break;
 | 
			
		||||
	  heap_chunk = 384; /* Default */
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
      if (heap_chunk < 4)
 | 
			
		||||
	heap_chunk = 4 * 1024 * 1024;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -70,10 +70,6 @@ class mount_info
 | 
			
		|||
  int native_sorted[MAX_MOUNTS];
 | 
			
		||||
 | 
			
		||||
 public:
 | 
			
		||||
  /* Increment when setting up a reg_key if mounts area had to be
 | 
			
		||||
     created so we know when we need to import old mount tables. */
 | 
			
		||||
  int had_to_create_mount_areas;
 | 
			
		||||
 | 
			
		||||
  void init ();
 | 
			
		||||
  int add_item (const char *dev, const char *path, unsigned flags, int reg_p);
 | 
			
		||||
  int del_item (const char *path, unsigned flags, int reg_p);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue