Accessing native NT namespace as filesystem

Corinna Vinschen corinna-cygwin@cygwin.com
Fri Sep 3 20:20:00 GMT 2010


On Sep  3 11:02, Christopher Faylor wrote:
> On Fri, Sep 03, 2010 at 09:58:00AM +0200, Corinna Vinschen wrote:
> >Oooohkeeey.  I still like /proc/sys more, though.  It just *sounds*
> >better, imho.  Could you all live with that, too?
> 
> No!  Absolutely not!  Red is a much better color for a bikeshed!
> 
> cgf
> (/proc/sys is fine)

Super!

Attached is the more or less final patch which uses /proc/sys.

I also improved cygwin_conv_path to generate always valid Win32 paths
from paths via the native NT namespace, for instance

  /proc/sys/Device/CdRom0  ->  \\.\GLOBALROOT\Device\CdRom0

or

  /dev/sda1  ->  \\.\GLOBALROOT\Device\Harddisk0\Partition1

The patch also contains a change to cygpath which now groks the
GLOBALROOT prefix and still tries to find a better, shorter match by
searching the \??\ DOS device namespace, *iff* the path points into the
\Device directory.  So, by using cygpath, you can still get something
really short like this:

  $ cygpath -w /dev/sda1
  \\.\C:
  $ cygpath -w /proc/sys/Device/CdRom0
  \\.\D:

If the path is not the path to the block device, but a path to a file
on the block device, cygpath now takes this even a step beyond:

  $ cygpath -w /proc/sys/Device/CdRom0/foo
  D:\foo

So it removes the \\.\ prefix if the path is a perfectly valid DOS
standard pathname even without the prefix.  If it's shorter than MAX_PATH.

Please have a look.  If nobody finds something terribly wrong, I'll
check this in on Monday.


Corinna


P.S, this is neat:

  $ ln -s /proc/sys/SystemRoot /WINDOWS

  You neither have to know the drive letter of the system drive, nor the
  actual name of the systemroot (Windows, WINNT, whatever).  Very
  helpful if you have a machine with multiple Windows installations.


	* Makefile.in (DLL_OFILES): Add fhandler_procsys.o.
	* devices.h (enum fh_devices): Add FH_PROCSYS.
	* devices.in (dev_procsys_storage): New device.
	* devices.cc: Regenerate.
	* fhandler.h (proc_len): Convert to size_t.
	(procsys): Declare.
	(procsys_len): Declare.
	(enum virtual_ftype_t): Move here from fhandler_virtual.h.
	Add members supported by fhandler_procsys.
	(fhandler_virtual::exists): Return virtual_ftype_t.  Change
	in all derived classes.
	(class fhandler_procsys): New class.
	(fhandler_union): Add fhandler_procnet and fhandler_procsys members.
	* fhandler_disk_file.cc (__DIR_mounts::check_missing_mount): Use
	ro_u_proc.
	(fhandler_base::fstat_by_name): Add special case for virtual
	directories.
	* fhandler_netdrive.cc (fhandler_netdrive::exists): Return
	virtual_ftype_t.
	* fhandler_proc.cc (proc_tab): Sort alphabetically.  Use _VN macro
	to store length.
	(proc_len): Change to size_t.
	(proc_tab_cmp): New static function.
	(virt_tab_search): New function to search entry in virt_tab_t
	arrays.  Use throughout in /proc and sibling classes instead of
	loop.
	(fhandler_proc::exists): Return virtual_ftype_t.
	* fhandler_process.cc (process_tab): Sort alphabetically.  Use _VN
	macro to store length.
	(fhandler_process::exists): Return virtual_ftype_t.
	(fhandler_process::open): Simplify code.
	* fhandler_procnet.cc (procnet_tab): Sort alphabetically.  Use _VN
	macro to store length.
	(fhandler_procnet::exists): Return virtual_ftype_t.
	(fhandler_procnet::open): Simplify.
	* fhandler_procsys.cc: New file.
	* fhandler_registry.cc (fhandler_registry::exists): Return
	virtual_ftype_t.
	* fhandler_virtual.cc (fhandler_virtual::exists): Ditto.
	* fhandler_virtual.h (enum virtual_ftype_t): Move to fhandler.h.
	(virt_tab_t): Add name_len member.
	(_VN): New macro.
	(virt_tab_search): Declare.
	* mount.cc (mount_info::conv_to_win32_path): Fix comment.
	backslashify isprocsys_dev paths, rather than just copying as
	other proc paths.
	* ntdll.h (STATUS_OBJECT_TYPE_MISMATCH): Define
	(STATUS_INSTANCE_NOT_AVAILABLE): Define.
	(STATUS_PIPE_NOT_AVAILABLE): Define.
	(STATUS_INVALID_PIPE_STATE): Define.
	(STATUS_PIPE_BUSY): Define.
	(SYMBOLIC_LINK_QUERY): Define.
	(NtOpenSymbolicLinkObject): Declare.
	(NtQuerySymbolicLinkObject): Declare.
	* path.cc (path_conv::check): Accommodate fact that exists method
	returns virtual_ftype_t now.  Add cases for new virtual_ftype_t
	types.
	(cygwin_conv_path): Add GLOBALROOT prefix to native device paths.
	Make sure to strip \\?\ prefix only for actual filesystem-based
	paths, not for all paths.
	* path.h (isproc_dev): Add FH_PROCSYS.
	(isprocsys_dev): Define.

	* cygpath.cc (RtlEqualUnicodePathPrefix): New help function.
	(HARDDISK_PREFIX): Move.
	(GLOBALROOT_PREFIX): Define.
	(get_device_name): Take GLOBALROOT_PREFIX into account.
	Improve check for path to allow filesystem access via block devices.
	Potentially drop \\.\ prefix if resulting path is a valid DOS
	pathname.
	(do_pathconv): Make sure to drop \\?\ prefix only if path is
	actually a filesystem based path.
	(print_version): Fix copyright.

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat
-------------- next part --------------
A non-text attachment was scrubbed...
Name: procsys.diff
Type: text/x-patch
Size: 59003 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-developers/attachments/20100903/d51a17bf/attachment.bin>


More information about the Cygwin-developers mailing list