Why files get created with srwxrwxrwt under /dev/?

$ uname -a
SunOS myhost 5.11 11.2 sun4v sparc sun4v

I see following 0 byte (regular)files getting created under /dev/mydisks directory :

srwxrwxrwt   1 gusr   dba       0 Sep 14 23:57 VF_10
srwxrwxrwt   1 gusr   dba       0 Sep 14 23:57 DATA1
srwxrwxrwt   1 gusr   dba       0 Sep 14 23:57 DATA2
$ echo test > testfile
bash: testfile: Permission denied

Even though the command above returns an error I see the file being created with 'srwxrwxrwt'

$ ls -ltr
total 0
srwxrwxrwt   1 gusr   dba       0 Sep 14 23:57 testfile
srwxrwxrwt   1 gusr   dba       0 Sep 14 23:57 VF_10
srwxrwxrwt   1 gusr   dba       0 Sep 14 23:57 DATA1
srwxrwxrwt   1 gusr   dba       0 Sep 14 23:57 DATA2

$ file testfile
testfile:       socket

Note that this happens for regular files only under /dev directory. What setting or env. is causing this behavior?
Why 0 byte files? Why regular files get 'srwxrwxrwt' under /dev?
Are these really 'socket' files?

They are not regular files, which permissions would have started with a dash, but file named domain sockets as file rightly reports.

Well, my concern is when I try to create a regular file under /dev it gets created as 0 byte file with srwxrwxrwt. Why?

Are you creating them, though? In your test above you get 'permission denied'. Which is what you'd expect trying to write to socket files, which don't work that way.

My intention is to create a text file under /dev directory.
But whenever I try creating it through a program or even from the command line as mentioned earlier they get created as 'socket' files. Some weird process is doing this.

I wonder if it's some odd property of the filesystem itself. I don't know Solaris in any detail but /dev/ is often its own pseudo-filesystem with unusual properties. Usually one doesn't make txt files under /dev.

In fact, /dev is not a regular file system.

Source code for the open call on Illumos /dev file system is here: Cross Reference: /illumos-gate/usr/src/uts/common/fs/dev/sdev_vnops.c It's been a few years since that was forked from OpenSolaris code, but it's probably still really close to Solaris 11.2 /dev file system code.

Excerpt from that:

/*
 * vnode ops for the /dev filesystem
 *
 * - VDIR, VCHR, CBLK, and VLNK are considered must supported files
 * - VREG and VDOOR are used for some internal implementations in
 *    the global zone, e.g. devname and devfsadm communication
 * - other file types are unusual in this namespace and
 *    not supported for now
 */
1 Like

Yes. You are not supposed to create plain files under /dev. /dev is mounted using a specific file system type and is normally under the control of devfsadm.
You should only create directories and named sockets here.
One side effect of that feature is that it prevents the disk full situations that would happen should someone mistype a tape or other device while trying to archive something.

1 Like