Accessing native NT namespace as filesystem

Corinna Vinschen corinna-cygwin@cygwin.com
Thu Sep 2 16:20:00 GMT 2010


Hi guys,


for those who want to play with this, I attached a patch which adds the
entire native NT namespace under the /sys directory.  I called it
fhandler_sysfs, and it works nicely afaics.  However, I was wondering if
that's really useful.  I'm also not really sure the name sysfs and the
/sys path is such a good idea.

Anyway, it's kind of fun.  First of all, you can now actually list the
contents of the NT namespace in Cygwin, something you needed the
sysinternals winobj tool for, so far.  Second, it's a neat way to examine
which filesystems you have:

  $ ls -l /sys/Device/Harddisk*

Third, you can easily access filesystems which are not mounted in
Windows via /sys:

  $ ls -l /sys/Device/rddiskVolumeShadowCopy1
  brwxrwx--x 1 Administrators SYSTEM 0, 242 2010-09-02 17:40 /sys/Device/HarddiskVolumeShadowCopy1

  $ ls -l /sys/Device/rddiskVolumeShadowCopy1/
  total 1834666
  drwxrwx---+ 1 Administrators Administrators          0 2010-04-12 11:32 $Recycle.Bin
  drwxr-x---  1 ????????       ????????                0 2009-07-14 04:37 PerfLogs
  drwxrwx---+ 1 ????????       ????????                0 2010-08-03 15:24 Program Files
  [...]
  drwxr-xr-x  1 corinna        Administrators          0 2010-08-23 18:16 cygwin
  -rw-r-----  1 ????????       ????????        804954112 2010-08-24 15:12 hiberfil.sys
  -rw-r-----  1 ????????       ????????       1073741824 2010-08-24 15:12 pagefile.sys

Note the difference between using a trailing backslash or not.  Without
trailing BS it's just a block device.  With the trailing backslash it's
recognized as the root directory of the filesystem on that block device.
That's default NT semantics, and it's quite neat, IMHO.

Due to syntactical checks in mount(2) it's not yet possible to add a
mountpoint to a filesystem in /etc/fstab, but you can use a symlink
if you like:

  $ ln -s /sys/Device/HarddiskVolumeShadowCopy1/ /my_shadow_copy

Here the trailing BS is necessary for the aforementioned reason.

Last but not least I added the ability to open, read and write device
files within /sys as well.  If you have permissions, of course:

  # dd if=/sys/Device/HarddiskVolumeShadowCopy1 bs=512 count=1 | od -c -N 32
  0000000 353   R 220   N   T   F   S                  \0 002  \b  \0  \0
  0000020  \0  \0  \0  \0  \0 370  \0  \0   ?  \0 377  \0  \0   ( 003  \0
  0000040
  1+0 records in
  1+0 records out
  512 bytes (512 B) copied, 0 s, Infinity B/s

Here the device is used as device, so no backspace, please.

Nice would be a way to send Windows ioctl's to devices via Cygwin's
ioctl call.  That shouldn't be too hard to add, too.

So, what do you think?  Useful/Useless/Tasteless/Ridiculous?

Would /sys be ok?  Or what else?  Not /dev, certainly, since that's
reserved for Cygwin/POSIX devices.  /devices, maybe, as on Solaris?


Corinna

-- 
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: sysfs.diff
Type: text/x-patch
Size: 41814 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin-developers/attachments/20100902/06c8a2f6/attachment.bin>


More information about the Cygwin-developers mailing list