public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] Add /proc/devices
@ 2011-08-04  5:20 Yaakov (Cygwin/X)
  2011-08-18 18:50 ` Yaakov (Cygwin/X)
  0 siblings, 1 reply; 9+ messages in thread
From: Yaakov (Cygwin/X) @ 2011-08-04  5:20 UTC (permalink / raw)
  To: cygwin-patches

[-- Attachment #1: Type: text/plain, Size: 555 bytes --]

This patchset implements /proc/devices[1]:

$ cat /proc/devices
Character devices:
  1 mem
  5 /dev/tty
  5 /dev/console
  5 /dev/ptmx
  9 st
 13 misc
 14 sound
117 ttyS
136 tty

Block devices:
  2 fd
  8 sd
 11 sr
 65 sd
 66 sd
 67 sd
 68 sd
 69 sd
 70 sd
 71 sd

The question is how to handle /dev/tty and /dev/console as the
apparently vary now, per cgf's remarks on the main list.

Patches for winsup/cygwin and winsup/doc attached.


Yaakov

[1] http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s2-proc-devices.html

[-- Attachment #2: cygwin-proc-devices.patch --]
[-- Type: application/octet-stream, Size: 4271 bytes --]

2011-08-04  Yaakov Selkowitz  <yselkowitz@...>

	* devices.h (fh_devices): Define DEV_MISC_MAJOR, DEV_MEM_MAJOR,
	DEV_SOUND_MAJOR.  Use throughout.
	* fhandler_proc.cc (proc_tab): Add /proc/devices virtual file.
	(format_proc_devices): New function.

Index: devices.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/devices.h,v
retrieving revision 1.32
diff -u -p -r1.32 devices.h
--- devices.h	12 Jun 2011 20:15:26 -0000	1.32
+++ devices.h	4 Aug 2011 05:05:18 -0000
@@ -44,8 +44,9 @@ enum fh_devices
   DEV_SERIAL_MAJOR = 117,
   FH_SERIAL  = FHDEV (117, 0),	/* /dev/ttyS? */
 
-  FH_WINDOWS = FHDEV (13, 255),
-  FH_CLIPBOARD=FHDEV (13, 254),
+  DEV_MISC_MAJOR = 13,
+  FH_WINDOWS = FHDEV (DEV_MISC_MAJOR, 255),
+  FH_CLIPBOARD=FHDEV (DEV_MISC_MAJOR, 254),
 
   /* begin /proc directories */
 
@@ -225,16 +226,19 @@ enum fh_devices
   FH_SDDW    = FHDEV (DEV_SD7_MAJOR, 224),
   FH_SDDX    = FHDEV (DEV_SD7_MAJOR, 240),
 
-  FH_MEM     = FHDEV (1, 1),
-  FH_KMEM    = FHDEV (1, 2),	/* not implemented yet */
-  FH_NULL    = FHDEV (1, 3),
-  FH_PORT    = FHDEV (1, 4),
-  FH_ZERO    = FHDEV (1, 5),
-  FH_FULL    = FHDEV (1, 7),
-  FH_RANDOM  = FHDEV (1, 8),
-  FH_URANDOM = FHDEV (1, 9),
-  FH_KMSG    = FHDEV (1, 11),
-  FH_OSS_DSP = FHDEV (14, 3),
+  DEV_MEM_MAJOR = 1,
+  FH_MEM     = FHDEV (DEV_MEM_MAJOR, 1),
+  FH_KMEM    = FHDEV (DEV_MEM_MAJOR, 2),	/* not implemented yet */
+  FH_NULL    = FHDEV (DEV_MEM_MAJOR, 3),
+  FH_PORT    = FHDEV (DEV_MEM_MAJOR, 4),
+  FH_ZERO    = FHDEV (DEV_MEM_MAJOR, 5),
+  FH_FULL    = FHDEV (DEV_MEM_MAJOR, 7),
+  FH_RANDOM  = FHDEV (DEV_MEM_MAJOR, 8),
+  FH_URANDOM = FHDEV (DEV_MEM_MAJOR, 9),
+  FH_KMSG    = FHDEV (DEV_MEM_MAJOR, 11),
+
+  DEV_SOUND_MAJOR = 14,
+  FH_OSS_DSP = FHDEV (DEV_SOUND_MAJOR, 3),
 
   DEV_CYGDRIVE_MAJOR = 98,
   FH_CYGDRIVE= FHDEV (DEV_CYGDRIVE_MAJOR, 0),
Index: fhandler_proc.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/fhandler_proc.cc,v
retrieving revision 1.107
diff -u -p -r1.107 fhandler_proc.cc
--- fhandler_proc.cc	12 Jun 2011 20:15:26 -0000	1.107
+++ fhandler_proc.cc	4 Aug 2011 05:05:19 -0000
@@ -46,12 +46,14 @@ static _off64_t format_proc_self (void *
 static _off64_t format_proc_mounts (void *, char *&);
 static _off64_t format_proc_filesystems (void *, char *&);
 static _off64_t format_proc_swaps (void *, char *&);
+static _off64_t format_proc_devices (void *, char *&);
 
 /* names of objects in /proc */
 static const virt_tab_t proc_tab[] = {
   { _VN ("."),		 FH_PROC,	virt_directory,	NULL },
   { _VN (".."),		 FH_PROC,	virt_directory,	NULL },
   { _VN ("cpuinfo"),	 FH_PROC,	virt_file,	format_proc_cpuinfo },
+  { _VN ("devices"),	 FH_PROC,	virt_file,	format_proc_devices },
   { _VN ("filesystems"), FH_PROC,	virt_file,	format_proc_filesystems },
   { _VN ("loadavg"),	 FH_PROC,	virt_file,	format_proc_loadavg },
   { _VN ("meminfo"),	 FH_PROC,	virt_file,	format_proc_meminfo },
@@ -1309,4 +1311,47 @@ format_proc_swaps (void *, char *&destbu
   return bufptr - buf;
 }
 
+static _off64_t
+format_proc_devices (void *, char *&destbuf)
+{
+  tmp_pathbuf tp;
+  char *buf = tp.c_get ();
+  char *bufptr = buf;
+
+  bufptr += __small_sprintf (bufptr,
+			     "Character devices:\n"
+			     "%3d mem\n"
+			     "%3d /dev/tty\n"
+			     "%3d /dev/console\n"
+			     "%3d /dev/ptmx\n"
+			     "%3d st\n"
+			     "%3d misc\n"
+			     "%3d sound\n"
+			     "%3d ttyS\n"
+			     "%3d tty\n"
+			     "\n"
+			     "Block devices:\n"
+			     "%3d fd\n"
+			     "%3d sd\n"
+			     "%3d sr\n"
+			     "%3d sd\n"
+			     "%3d sd\n"
+			     "%3d sd\n"
+			     "%3d sd\n"
+			     "%3d sd\n"
+			     "%3d sd\n"
+			     "%3d sd\n",
+			     DEV_MEM_MAJOR, _major (FH_TTY), _major (FH_CONSOLE),
+			     _major (FH_PTYM), DEV_TAPE_MAJOR, DEV_MISC_MAJOR,
+			     DEV_SOUND_MAJOR, DEV_SERIAL_MAJOR, DEV_TTYS_MAJOR,
+			     DEV_FLOPPY_MAJOR, DEV_SD_MAJOR, DEV_CDROM_MAJOR,
+			     DEV_SD1_MAJOR, DEV_SD2_MAJOR, DEV_SD3_MAJOR,
+			     DEV_SD4_MAJOR, DEV_SD5_MAJOR, DEV_SD6_MAJOR,
+			     DEV_SD7_MAJOR);
+
+  destbuf = (char *) crealloc_abort (destbuf, bufptr - buf);
+  memcpy (destbuf, buf, bufptr - buf);
+  return bufptr - buf;
+}
+
 #undef print

[-- Attachment #3: doc-proc-devices.patch --]
[-- Type: application/octet-stream, Size: 730 bytes --]

2011-08-04  Yaakov Selkowitz  <yselkowitz@...>

	* new-features.sgml (ov-new1.7.10): Document /proc/devices.

Index: new-features.sgml
===================================================================
RCS file: /cvs/src/src/winsup/doc/new-features.sgml,v
retrieving revision 1.88
diff -u -p -r1.88 new-features.sgml
--- new-features.sgml	3 Aug 2011 19:18:07 -0000	1.88
+++ new-features.sgml	4 Aug 2011 05:12:36 -0000
@@ -63,6 +63,10 @@ total number of processes.
 </para></listitem>
 
 <listitem><para>
+Added /proc/devices, which lists supported device types and their major numbers.
+</para></listitem>
+
+<listitem><para>
 Added /proc/swaps, which shows the location and size of Windows paging file(s).
 </para></listitem>
 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Add /proc/devices
  2011-08-04  5:20 [PATCH] Add /proc/devices Yaakov (Cygwin/X)
@ 2011-08-18 18:50 ` Yaakov (Cygwin/X)
  2011-08-18 19:56   ` Corinna Vinschen
  0 siblings, 1 reply; 9+ messages in thread
From: Yaakov (Cygwin/X) @ 2011-08-18 18:50 UTC (permalink / raw)
  To: cygwin-patches

[-- Attachment #1: Type: text/plain, Size: 484 bytes --]

On Thu, 2011-08-04 at 00:20 -0500, Yaakov (Cygwin/X) wrote:
> This patchset implements /proc/devices[1]:
> 
> The question is how to handle /dev/tty and /dev/console as the
> apparently vary now, per cgf's remarks on the main list.
> 
> Patches for winsup/cygwin and winsup/doc attached.

Here is a second version which adds the closely related /proc/misc[1] as
well.


Yaakov

[1] http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s2-proc-misc.html


[-- Attachment #2: cygwin-proc-devices.patch --]
[-- Type: text/x-patch, Size: 5045 bytes --]

2011-08-18  Yaakov Selkowitz  <yselkowitz@...>

	* devices.h (fh_devices): Define DEV_MISC_MAJOR, DEV_MEM_MAJOR,
	DEV_SOUND_MAJOR.  Use throughout.
	* fhandler_proc.cc (proc_tab): Add /proc/devices and /proc/misc
	virtual files.
	(format_proc_devices): New function.
	(format_proc_misc): New function.

Index: devices.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/devices.h,v
retrieving revision 1.32
diff -u -p -r1.32 devices.h
--- devices.h	12 Jun 2011 20:15:26 -0000	1.32
+++ devices.h	18 Aug 2011 17:01:47 -0000
@@ -44,8 +44,9 @@ enum fh_devices
   DEV_SERIAL_MAJOR = 117,
   FH_SERIAL  = FHDEV (117, 0),	/* /dev/ttyS? */
 
-  FH_WINDOWS = FHDEV (13, 255),
-  FH_CLIPBOARD=FHDEV (13, 254),
+  DEV_MISC_MAJOR = 13,
+  FH_WINDOWS = FHDEV (DEV_MISC_MAJOR, 255),
+  FH_CLIPBOARD=FHDEV (DEV_MISC_MAJOR, 254),
 
   /* begin /proc directories */
 
@@ -225,16 +226,19 @@ enum fh_devices
   FH_SDDW    = FHDEV (DEV_SD7_MAJOR, 224),
   FH_SDDX    = FHDEV (DEV_SD7_MAJOR, 240),
 
-  FH_MEM     = FHDEV (1, 1),
-  FH_KMEM    = FHDEV (1, 2),	/* not implemented yet */
-  FH_NULL    = FHDEV (1, 3),
-  FH_PORT    = FHDEV (1, 4),
-  FH_ZERO    = FHDEV (1, 5),
-  FH_FULL    = FHDEV (1, 7),
-  FH_RANDOM  = FHDEV (1, 8),
-  FH_URANDOM = FHDEV (1, 9),
-  FH_KMSG    = FHDEV (1, 11),
-  FH_OSS_DSP = FHDEV (14, 3),
+  DEV_MEM_MAJOR = 1,
+  FH_MEM     = FHDEV (DEV_MEM_MAJOR, 1),
+  FH_KMEM    = FHDEV (DEV_MEM_MAJOR, 2),	/* not implemented yet */
+  FH_NULL    = FHDEV (DEV_MEM_MAJOR, 3),
+  FH_PORT    = FHDEV (DEV_MEM_MAJOR, 4),
+  FH_ZERO    = FHDEV (DEV_MEM_MAJOR, 5),
+  FH_FULL    = FHDEV (DEV_MEM_MAJOR, 7),
+  FH_RANDOM  = FHDEV (DEV_MEM_MAJOR, 8),
+  FH_URANDOM = FHDEV (DEV_MEM_MAJOR, 9),
+  FH_KMSG    = FHDEV (DEV_MEM_MAJOR, 11),
+
+  DEV_SOUND_MAJOR = 14,
+  FH_OSS_DSP = FHDEV (DEV_SOUND_MAJOR, 3),
 
   DEV_CYGDRIVE_MAJOR = 98,
   FH_CYGDRIVE= FHDEV (DEV_CYGDRIVE_MAJOR, 0),
Index: fhandler_proc.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/fhandler_proc.cc,v
retrieving revision 1.110
diff -u -p -r1.110 fhandler_proc.cc
--- fhandler_proc.cc	12 Aug 2011 12:35:37 -0000	1.110
+++ fhandler_proc.cc	18 Aug 2011 17:01:48 -0000
@@ -46,15 +46,19 @@ static _off64_t format_proc_self (void *
 static _off64_t format_proc_mounts (void *, char *&);
 static _off64_t format_proc_filesystems (void *, char *&);
 static _off64_t format_proc_swaps (void *, char *&);
+static _off64_t format_proc_devices (void *, char *&);
+static _off64_t format_proc_misc (void *, char *&);
 
 /* names of objects in /proc */
 static const virt_tab_t proc_tab[] = {
   { _VN ("."),		 FH_PROC,	virt_directory,	NULL },
   { _VN (".."),		 FH_PROC,	virt_directory,	NULL },
   { _VN ("cpuinfo"),	 FH_PROC,	virt_file,	format_proc_cpuinfo },
+  { _VN ("devices"),	 FH_PROC,	virt_file,	format_proc_devices },
   { _VN ("filesystems"), FH_PROC,	virt_file,	format_proc_filesystems },
   { _VN ("loadavg"),	 FH_PROC,	virt_file,	format_proc_loadavg },
   { _VN ("meminfo"),	 FH_PROC,	virt_file,	format_proc_meminfo },
+  { _VN ("misc"),	 FH_PROC,	virt_file,	format_proc_misc },
   { _VN ("mounts"),	 FH_PROC,	virt_symlink,	format_proc_mounts },
   { _VN ("net"),	 FH_PROCNET,	virt_directory,	NULL },
   { _VN ("partitions"),  FH_PROC,	virt_file,	format_proc_partitions },
@@ -1335,4 +1339,64 @@ format_proc_swaps (void *, char *&destbu
   return bufptr - buf;
 }
 
+static _off64_t
+format_proc_devices (void *, char *&destbuf)
+{
+  tmp_pathbuf tp;
+  char *buf = tp.c_get ();
+  char *bufptr = buf;
+
+  bufptr += __small_sprintf (bufptr,
+			     "Character devices:\n"
+			     "%3d mem\n"
+			     "%3d /dev/tty\n"
+			     "%3d /dev/console\n"
+			     "%3d /dev/ptmx\n"
+			     "%3d st\n"
+			     "%3d misc\n"
+			     "%3d sound\n"
+			     "%3d ttyS\n"
+			     "%3d tty\n"
+			     "\n"
+			     "Block devices:\n"
+			     "%3d fd\n"
+			     "%3d sd\n"
+			     "%3d sr\n"
+			     "%3d sd\n"
+			     "%3d sd\n"
+			     "%3d sd\n"
+			     "%3d sd\n"
+			     "%3d sd\n"
+			     "%3d sd\n"
+			     "%3d sd\n",
+			     DEV_MEM_MAJOR, _major (FH_TTY), _major (FH_CONSOLE),
+			     _major (FH_PTYM), DEV_TAPE_MAJOR, DEV_MISC_MAJOR,
+			     DEV_SOUND_MAJOR, DEV_SERIAL_MAJOR, DEV_TTYS_MAJOR,
+			     DEV_FLOPPY_MAJOR, DEV_SD_MAJOR, DEV_CDROM_MAJOR,
+			     DEV_SD1_MAJOR, DEV_SD2_MAJOR, DEV_SD3_MAJOR,
+			     DEV_SD4_MAJOR, DEV_SD5_MAJOR, DEV_SD6_MAJOR,
+			     DEV_SD7_MAJOR);
+
+  destbuf = (char *) crealloc_abort (destbuf, bufptr - buf);
+  memcpy (destbuf, buf, bufptr - buf);
+  return bufptr - buf;
+}
+
+static _off64_t
+format_proc_misc (void *, char *&destbuf)
+{
+  tmp_pathbuf tp;
+  char *buf = tp.c_get ();
+  char *bufptr = buf;
+
+  bufptr += __small_sprintf (bufptr,
+			     "%3d clipboard\n"
+			     "%3d windows\n",
+			     _minor (FH_CLIPBOARD), _minor (FH_WINDOWS));
+
+  destbuf = (char *) crealloc_abort (destbuf, bufptr - buf);
+  memcpy (destbuf, buf, bufptr - buf);
+  return bufptr - buf;
+}
+
 #undef print

[-- Attachment #3: doc-proc-devices.patch --]
[-- Type: text/x-patch, Size: 765 bytes --]

2011-08-18  Yaakov Selkowitz  <yselkowitz@...>

	* new-features.sgml (ov-new1.7.10): Document /proc/devices
	and /proc/misc.

Index: new-features.sgml
===================================================================
RCS file: /cvs/src/src/winsup/doc/new-features.sgml,v
retrieving revision 1.90
diff -u -p -r1.90 new-features.sgml
--- new-features.sgml	16 Aug 2011 14:51:06 -0000	1.90
+++ new-features.sgml	18 Aug 2011 17:06:17 -0000
@@ -77,6 +77,11 @@ total number of processes.
 </para></listitem>
 
 <listitem><para>
+Added /proc/devices and /proc/misc, which lists supported device types and
+their device numbers.
+</para></listitem>
+
+<listitem><para>
 Added /proc/swaps, which shows the location and size of Windows paging file(s).
 </para></listitem>
 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Add /proc/devices
  2011-08-18 18:50 ` Yaakov (Cygwin/X)
@ 2011-08-18 19:56   ` Corinna Vinschen
  2011-08-18 20:28     ` Christopher Faylor
  2011-08-19  1:54     ` Yaakov (Cygwin/X)
  0 siblings, 2 replies; 9+ messages in thread
From: Corinna Vinschen @ 2011-08-18 19:56 UTC (permalink / raw)
  To: cygwin-patches

On Aug 18 13:50, Yaakov (Cygwin/X) wrote:
> On Thu, 2011-08-04 at 00:20 -0500, Yaakov (Cygwin/X) wrote:
> > This patchset implements /proc/devices[1]:
> > 
> > The question is how to handle /dev/tty and /dev/console as the
> > apparently vary now, per cgf's remarks on the main list.

/dev/tty, /dev/console and /dev/ptmx have fixed major and minor numbers.
But I see what you mean.  While `ls -l /dev/tty' on Linux always returns
with 5, 0 as major, minor, on Cygwin it returns with the major and minor
numbers of the actual tty it refers to:

  $ tty
  /dev/tty2
  $ ls -l /dev/tty
  crw--w---- 1 corinna vinschen 136, 2 Aug 18 21:51 /dev/tty

Same for /dev/console.  Chris, is it tricky to return always the
real major, minor pairs 5, 0 and 5, 1 for /dev/tty and /dev/console?

> Here is a second version which adds the closely related /proc/misc[1] as
> well.
> 
> 
> Yaakov
> 
> [1] http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/6/html/Deployment_Guide/s2-proc-misc.html
> 

> 2011-08-18  Yaakov Selkowitz  <yselkowitz@...>
> 
> 	* devices.h (fh_devices): Define DEV_MISC_MAJOR, DEV_MEM_MAJOR,
> 	DEV_SOUND_MAJOR.  Use throughout.
> 	* fhandler_proc.cc (proc_tab): Add /proc/devices and /proc/misc
> 	virtual files.
> 	(format_proc_devices): New function.
> 	(format_proc_misc): New function.

I think the patch is basically ok, but it's missing the "cons" entry
for consoles, equivalent to the "tty" entry.


Corinna

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Add /proc/devices
  2011-08-18 19:56   ` Corinna Vinschen
@ 2011-08-18 20:28     ` Christopher Faylor
  2011-08-19  1:54     ` Yaakov (Cygwin/X)
  1 sibling, 0 replies; 9+ messages in thread
From: Christopher Faylor @ 2011-08-18 20:28 UTC (permalink / raw)
  To: cygwin-patches

On Thu, Aug 18, 2011 at 09:55:37PM +0200, Corinna Vinschen wrote:
>On Aug 18 13:50, Yaakov (Cygwin/X) wrote:
>> On Thu, 2011-08-04 at 00:20 -0500, Yaakov (Cygwin/X) wrote:
>> > This patchset implements /proc/devices[1]:
>> > 
>> > The question is how to handle /dev/tty and /dev/console as the
>> > apparently vary now, per cgf's remarks on the main list.
>
>/dev/tty, /dev/console and /dev/ptmx have fixed major and minor numbers.
>But I see what you mean.  While `ls -l /dev/tty' on Linux always returns
>with 5, 0 as major, minor, on Cygwin it returns with the major and minor
>numbers of the actual tty it refers to:
>
>  $ tty
>  /dev/tty2
>  $ ls -l /dev/tty
>  crw--w---- 1 corinna vinschen 136, 2 Aug 18 21:51 /dev/tty
>
>Same for /dev/console.  Chris, is it tricky to return always the
>real major, minor pairs 5, 0 and 5, 1 for /dev/tty and /dev/console?

I think I mentioned this when /proc/devices was first proposed.  I
changed this when I merged the console and tty handling more closely a
couple of months ago.

It's not impossible to fix.  I'll get around to it eventually.

cgf

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Add /proc/devices
  2011-08-18 19:56   ` Corinna Vinschen
  2011-08-18 20:28     ` Christopher Faylor
@ 2011-08-19  1:54     ` Yaakov (Cygwin/X)
  2011-08-19 11:53       ` Corinna Vinschen
  1 sibling, 1 reply; 9+ messages in thread
From: Yaakov (Cygwin/X) @ 2011-08-19  1:54 UTC (permalink / raw)
  To: cygwin-patches

[-- Attachment #1: Type: text/plain, Size: 564 bytes --]

On Thu, 2011-08-18 at 21:55 +0200, Corinna Vinschen wrote:
> > 2011-08-18  Yaakov Selkowitz  <yselkowitz@...>
> > 
> > 	* devices.h (fh_devices): Define DEV_MISC_MAJOR, DEV_MEM_MAJOR,
> > 	DEV_SOUND_MAJOR.  Use throughout.
> > 	* fhandler_proc.cc (proc_tab): Add /proc/devices and /proc/misc
> > 	virtual files.
> > 	(format_proc_devices): New function.
> > 	(format_proc_misc): New function.
> 
> I think the patch is basically ok, but it's missing the "cons" entry
> for consoles, equivalent to the "tty" entry.

Revised patch attached.  OK to commit?


Yaakov


[-- Attachment #2: cygwin-proc-devices.patch --]
[-- Type: text/x-patch, Size: 5083 bytes --]

2011-08-18  Yaakov Selkowitz  <yselkowitz@...>

	* devices.h (fh_devices): Define DEV_MISC_MAJOR, DEV_MEM_MAJOR,
	DEV_SOUND_MAJOR.  Use throughout.
	* fhandler_proc.cc (proc_tab): Add /proc/devices and /proc/misc
	virtual files.
	(format_proc_devices): New function.
	(format_proc_misc): New function.

Index: devices.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/devices.h,v
retrieving revision 1.32
diff -u -p -r1.32 devices.h
--- devices.h	12 Jun 2011 20:15:26 -0000	1.32
+++ devices.h	19 Aug 2011 01:48:43 -0000
@@ -44,8 +44,9 @@ enum fh_devices
   DEV_SERIAL_MAJOR = 117,
   FH_SERIAL  = FHDEV (117, 0),	/* /dev/ttyS? */
 
-  FH_WINDOWS = FHDEV (13, 255),
-  FH_CLIPBOARD=FHDEV (13, 254),
+  DEV_MISC_MAJOR = 13,
+  FH_WINDOWS = FHDEV (DEV_MISC_MAJOR, 255),
+  FH_CLIPBOARD=FHDEV (DEV_MISC_MAJOR, 254),
 
   /* begin /proc directories */
 
@@ -225,16 +226,19 @@ enum fh_devices
   FH_SDDW    = FHDEV (DEV_SD7_MAJOR, 224),
   FH_SDDX    = FHDEV (DEV_SD7_MAJOR, 240),
 
-  FH_MEM     = FHDEV (1, 1),
-  FH_KMEM    = FHDEV (1, 2),	/* not implemented yet */
-  FH_NULL    = FHDEV (1, 3),
-  FH_PORT    = FHDEV (1, 4),
-  FH_ZERO    = FHDEV (1, 5),
-  FH_FULL    = FHDEV (1, 7),
-  FH_RANDOM  = FHDEV (1, 8),
-  FH_URANDOM = FHDEV (1, 9),
-  FH_KMSG    = FHDEV (1, 11),
-  FH_OSS_DSP = FHDEV (14, 3),
+  DEV_MEM_MAJOR = 1,
+  FH_MEM     = FHDEV (DEV_MEM_MAJOR, 1),
+  FH_KMEM    = FHDEV (DEV_MEM_MAJOR, 2),	/* not implemented yet */
+  FH_NULL    = FHDEV (DEV_MEM_MAJOR, 3),
+  FH_PORT    = FHDEV (DEV_MEM_MAJOR, 4),
+  FH_ZERO    = FHDEV (DEV_MEM_MAJOR, 5),
+  FH_FULL    = FHDEV (DEV_MEM_MAJOR, 7),
+  FH_RANDOM  = FHDEV (DEV_MEM_MAJOR, 8),
+  FH_URANDOM = FHDEV (DEV_MEM_MAJOR, 9),
+  FH_KMSG    = FHDEV (DEV_MEM_MAJOR, 11),
+
+  DEV_SOUND_MAJOR = 14,
+  FH_OSS_DSP = FHDEV (DEV_SOUND_MAJOR, 3),
 
   DEV_CYGDRIVE_MAJOR = 98,
   FH_CYGDRIVE= FHDEV (DEV_CYGDRIVE_MAJOR, 0),
Index: fhandler_proc.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/fhandler_proc.cc,v
retrieving revision 1.110
diff -u -p -r1.110 fhandler_proc.cc
--- fhandler_proc.cc	12 Aug 2011 12:35:37 -0000	1.110
+++ fhandler_proc.cc	19 Aug 2011 01:48:44 -0000
@@ -46,15 +46,19 @@ static _off64_t format_proc_self (void *
 static _off64_t format_proc_mounts (void *, char *&);
 static _off64_t format_proc_filesystems (void *, char *&);
 static _off64_t format_proc_swaps (void *, char *&);
+static _off64_t format_proc_devices (void *, char *&);
+static _off64_t format_proc_misc (void *, char *&);
 
 /* names of objects in /proc */
 static const virt_tab_t proc_tab[] = {
   { _VN ("."),		 FH_PROC,	virt_directory,	NULL },
   { _VN (".."),		 FH_PROC,	virt_directory,	NULL },
   { _VN ("cpuinfo"),	 FH_PROC,	virt_file,	format_proc_cpuinfo },
+  { _VN ("devices"),	 FH_PROC,	virt_file,	format_proc_devices },
   { _VN ("filesystems"), FH_PROC,	virt_file,	format_proc_filesystems },
   { _VN ("loadavg"),	 FH_PROC,	virt_file,	format_proc_loadavg },
   { _VN ("meminfo"),	 FH_PROC,	virt_file,	format_proc_meminfo },
+  { _VN ("misc"),	 FH_PROC,	virt_file,	format_proc_misc },
   { _VN ("mounts"),	 FH_PROC,	virt_symlink,	format_proc_mounts },
   { _VN ("net"),	 FH_PROCNET,	virt_directory,	NULL },
   { _VN ("partitions"),  FH_PROC,	virt_file,	format_proc_partitions },
@@ -1335,4 +1339,65 @@ format_proc_swaps (void *, char *&destbu
   return bufptr - buf;
 }
 
+static _off64_t
+format_proc_devices (void *, char *&destbuf)
+{
+  tmp_pathbuf tp;
+  char *buf = tp.c_get ();
+  char *bufptr = buf;
+
+  bufptr += __small_sprintf (bufptr,
+			     "Character devices:\n"
+			     "%3d mem\n"
+			     "%3d cons\n"
+			     "%3d /dev/tty\n"
+			     "%3d /dev/console\n"
+			     "%3d /dev/ptmx\n"
+			     "%3d st\n"
+			     "%3d misc\n"
+			     "%3d sound\n"
+			     "%3d ttyS\n"
+			     "%3d tty\n"
+			     "\n"
+			     "Block devices:\n"
+			     "%3d fd\n"
+			     "%3d sd\n"
+			     "%3d sr\n"
+			     "%3d sd\n"
+			     "%3d sd\n"
+			     "%3d sd\n"
+			     "%3d sd\n"
+			     "%3d sd\n"
+			     "%3d sd\n"
+			     "%3d sd\n",
+			     DEV_MEM_MAJOR, DEV_CONS_MAJOR, _major (FH_TTY),
+			     _major (FH_CONSOLE), _major (FH_PTYM),
+			     DEV_TAPE_MAJOR, DEV_MISC_MAJOR, DEV_SOUND_MAJOR,
+			     DEV_SERIAL_MAJOR, DEV_TTYS_MAJOR, DEV_FLOPPY_MAJOR,
+			     DEV_SD_MAJOR, DEV_CDROM_MAJOR, DEV_SD1_MAJOR,
+			     DEV_SD2_MAJOR, DEV_SD3_MAJOR, DEV_SD4_MAJOR,
+			     DEV_SD5_MAJOR, DEV_SD6_MAJOR, DEV_SD7_MAJOR);
+
+  destbuf = (char *) crealloc_abort (destbuf, bufptr - buf);
+  memcpy (destbuf, buf, bufptr - buf);
+  return bufptr - buf;
+}
+
+static _off64_t
+format_proc_misc (void *, char *&destbuf)
+{
+  tmp_pathbuf tp;
+  char *buf = tp.c_get ();
+  char *bufptr = buf;
+
+  bufptr += __small_sprintf (bufptr,
+			     "%3d clipboard\n"
+			     "%3d windows\n",
+			     _minor (FH_CLIPBOARD), _minor (FH_WINDOWS));
+
+  destbuf = (char *) crealloc_abort (destbuf, bufptr - buf);
+  memcpy (destbuf, buf, bufptr - buf);
+  return bufptr - buf;
+}
+
 #undef print

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Add /proc/devices
  2011-08-19  1:54     ` Yaakov (Cygwin/X)
@ 2011-08-19 11:53       ` Corinna Vinschen
  2011-08-19 14:44         ` Christopher Faylor
  0 siblings, 1 reply; 9+ messages in thread
From: Corinna Vinschen @ 2011-08-19 11:53 UTC (permalink / raw)
  To: cygwin-patches

On Aug 18 20:54, Yaakov (Cygwin/X) wrote:
> On Thu, 2011-08-18 at 21:55 +0200, Corinna Vinschen wrote:
> > > 2011-08-18  Yaakov Selkowitz  <yselkowitz@...>
> > > 
> > > 	* devices.h (fh_devices): Define DEV_MISC_MAJOR, DEV_MEM_MAJOR,
> > > 	DEV_SOUND_MAJOR.  Use throughout.
> > > 	* fhandler_proc.cc (proc_tab): Add /proc/devices and /proc/misc
> > > 	virtual files.
> > > 	(format_proc_devices): New function.
> > > 	(format_proc_misc): New function.
> > 
> > I think the patch is basically ok, but it's missing the "cons" entry
> > for consoles, equivalent to the "tty" entry.
> 
> Revised patch attached.  OK to commit?
> 
> 
> Yaakov
> 

> 2011-08-18  Yaakov Selkowitz  <yselkowitz@...>
> 
> 	* devices.h (fh_devices): Define DEV_MISC_MAJOR, DEV_MEM_MAJOR,
> 	DEV_SOUND_MAJOR.  Use throughout.
> 	* fhandler_proc.cc (proc_tab): Add /proc/devices and /proc/misc
> 	virtual files.
> 	(format_proc_devices): New function.
> 	(format_proc_misc): New function.

Yes, I think that's ok.


Thanks,
Corinna

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Add /proc/devices
  2011-08-19 11:53       ` Corinna Vinschen
@ 2011-08-19 14:44         ` Christopher Faylor
  2011-08-19 19:50           ` Yaakov (Cygwin/X)
  0 siblings, 1 reply; 9+ messages in thread
From: Christopher Faylor @ 2011-08-19 14:44 UTC (permalink / raw)
  To: cygwin-patches

On Fri, Aug 19, 2011 at 01:52:53PM +0200, Corinna Vinschen wrote:
>On Aug 18 20:54, Yaakov (Cygwin/X) wrote:
>> On Thu, 2011-08-18 at 21:55 +0200, Corinna Vinschen wrote:
>> > > 2011-08-18  Yaakov Selkowitz  <yselkowitz@...>
>> > > 
>> > > 	* devices.h (fh_devices): Define DEV_MISC_MAJOR, DEV_MEM_MAJOR,
>> > > 	DEV_SOUND_MAJOR.  Use throughout.
>> > > 	* fhandler_proc.cc (proc_tab): Add /proc/devices and /proc/misc
>> > > 	virtual files.
>> > > 	(format_proc_devices): New function.
>> > > 	(format_proc_misc): New function.
>> > 
>> > I think the patch is basically ok, but it's missing the "cons" entry
>> > for consoles, equivalent to the "tty" entry.
>> 
>> Revised patch attached.  OK to commit?
>> 
>> 
>> Yaakov
>> 
>
>> 2011-08-18  Yaakov Selkowitz  <yselkowitz@...>
>> 
>> 	* devices.h (fh_devices): Define DEV_MISC_MAJOR, DEV_MEM_MAJOR,
>> 	DEV_SOUND_MAJOR.  Use throughout.
>> 	* fhandler_proc.cc (proc_tab): Add /proc/devices and /proc/misc
>> 	virtual files.
>> 	(format_proc_devices): New function.
>> 	(format_proc_misc): New function.
>
>Yes, I think that's ok.

Isn't it somehow possible to just iterate over dev_storage and generate
this automatically rather than hard-coding the names of devices?

cgf

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Add /proc/devices
  2011-08-19 14:44         ` Christopher Faylor
@ 2011-08-19 19:50           ` Yaakov (Cygwin/X)
  2011-08-19 19:57             ` Christopher Faylor
  0 siblings, 1 reply; 9+ messages in thread
From: Yaakov (Cygwin/X) @ 2011-08-19 19:50 UTC (permalink / raw)
  To: cygwin-patches

On Fri, 2011-08-19 at 10:44 -0400, Christopher Faylor wrote:
> On Fri, Aug 19, 2011 at 01:52:53PM +0200, Corinna Vinschen wrote:
> >On Aug 18 20:54, Yaakov (Cygwin/X) wrote:
> >> 2011-08-18  Yaakov Selkowitz  <yselkowitz@...>
> >> 
> >> 	* devices.h (fh_devices): Define DEV_MISC_MAJOR, DEV_MEM_MAJOR,
> >> 	DEV_SOUND_MAJOR.  Use throughout.
> >> 	* fhandler_proc.cc (proc_tab): Add /proc/devices and /proc/misc
> >> 	virtual files.
> >> 	(format_proc_devices): New function.
> >> 	(format_proc_misc): New function.
> >
> >Yes, I think that's ok.
> 
> Isn't it somehow possible to just iterate over dev_storage and generate
> this automatically rather than hard-coding the names of devices?

I don't think so.  For the most part, /proc/devices doesn't list
individual devices but only groups thereof, and there is the "misc"
major device which is only descriptive and not an actual device name.
There is also the matter of distinguishing between block and character
devices.

As for /proc/misc, technically it could be done as you describe, but is
it worth the price of iterating over a 2581-member array to find the two
matching cases?  If the misc devices would vary based on configuration
as on Linux, I would see your point, but as we only and always have
these two, I'm not so sure.

Let me know how you want to proceed.


Yaakov


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Add /proc/devices
  2011-08-19 19:50           ` Yaakov (Cygwin/X)
@ 2011-08-19 19:57             ` Christopher Faylor
  0 siblings, 0 replies; 9+ messages in thread
From: Christopher Faylor @ 2011-08-19 19:57 UTC (permalink / raw)
  To: cygwin-patches

On Fri, Aug 19, 2011 at 02:50:24PM -0500, Yaakov (Cygwin/X) wrote:
>On Fri, 2011-08-19 at 10:44 -0400, Christopher Faylor wrote:
>> On Fri, Aug 19, 2011 at 01:52:53PM +0200, Corinna Vinschen wrote:
>> >On Aug 18 20:54, Yaakov (Cygwin/X) wrote:
>> >> 2011-08-18  Yaakov Selkowitz  <yselkowitz@...>
>> >> 
>> >> 	* devices.h (fh_devices): Define DEV_MISC_MAJOR, DEV_MEM_MAJOR,
>> >> 	DEV_SOUND_MAJOR.  Use throughout.
>> >> 	* fhandler_proc.cc (proc_tab): Add /proc/devices and /proc/misc
>> >> 	virtual files.
>> >> 	(format_proc_devices): New function.
>> >> 	(format_proc_misc): New function.
>> >
>> >Yes, I think that's ok.
>> 
>> Isn't it somehow possible to just iterate over dev_storage and generate
>> this automatically rather than hard-coding the names of devices?
>
>I don't think so.  For the most part, /proc/devices doesn't list
>individual devices but only groups thereof, and there is the "misc"
>major device which is only descriptive and not an actual device name.
>There is also the matter of distinguishing between block and character
>devices.
>
>As for /proc/misc, technically it could be done as you describe, but is
>it worth the price of iterating over a 2581-member array to find the two
>matching cases?  If the misc devices would vary based on configuration
>as on Linux, I would see your point, but as we only and always have
>these two, I'm not so sure.

It's not just two matching names.  You could infer most of the device
abbreviations from the list or you could conceivably change what is
generated by devices.in so that a table was output automatically.

But, I'm not looking for work for you to do.  I was just trying
to brainstorm.

cgf

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2011-08-19 19:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-04  5:20 [PATCH] Add /proc/devices Yaakov (Cygwin/X)
2011-08-18 18:50 ` Yaakov (Cygwin/X)
2011-08-18 19:56   ` Corinna Vinschen
2011-08-18 20:28     ` Christopher Faylor
2011-08-19  1:54     ` Yaakov (Cygwin/X)
2011-08-19 11:53       ` Corinna Vinschen
2011-08-19 14:44         ` Christopher Faylor
2011-08-19 19:50           ` Yaakov (Cygwin/X)
2011-08-19 19:57             ` Christopher Faylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).