2

The file mode for a file on AIX returned by the Ruby stat method has 6 digits:

ruby -e 'puts File::stat("testfile_upload-003").mode.to_s(8)'
100644

FWIW, Ruby version is ruby 2.1.6p336 (2015-04-13 revision 50298) [powerpc-aix6.1.0.0], but Perl returns the very same value:

perl -e 'use File::stat; printf "%o\n", stat("testfile_upload-003")->mode;'
100644

Here is the output of istat for the same file.

# /bin/istat testfile_upload-003
Inode 33780 on device 10/7      File
Protection: rw-r--r--
Owner: 0(root)          Group: 0(system)
Link count:   2         Length 51200 bytes

Last updated:   Thu Mar  9 01:13:24 CST 2017
Last modified:  Wed Mar  8 11:52:52 CST 2017
Last accessed:  Wed Mar  8 11:52:52 CST 2017

EDIT: the chmod man page andistat man page do not provide info for the 5th and 6th digits.

And there is no fancy setuid bits set for that file:

# ls -l testfile_upload-003
-rw-r--r--    2 root     system        51200 Mar 08 11:52 testfile_upload-003
ilkkachu
  • 138,973
philant
  • 201

2 Answers2

3

I found them in <sys/mode.h> :

/*
 *      (stat) st_mode bit values
 */

#define _S_IFMT         0170000         /* type of file */
#define   _S_IFREG      0100000         /*   regular */
#define   _S_IFDIR      0040000         /*   directory */
#define   _S_IFBLK      0060000         /*   block special */
#define   _S_IFCHR      0020000         /*   character special */
#define   _S_IFIFO      0010000         /*   fifo */

The leading '1' indicates a regular file.

A directory has 240755, the '4' indicates a directory, and the '2' means "not a regular file".

philant
  • 201
2

The *NIX systems (an AIX is a UNIX, but it's true on Linux, Solaris and BSD too) has 16bit long file mode info: 4bit for file type; 3bit for special bits (setuid, setgid, t-git or sticky); and 9bit for permissions (owner rwx, group rwx, others rwx - rwx means read-write-execute). The standard enables the octal representation (without leading zeros - which are sometimes writen), first one or two is the file type, next one is for the special bits, last three is for permissions.

Examples (3 binary digit = 1 octal digit):

Binary 1000000111101101 = Octal 100755 (-rwxr-xr-x)
Binary 0100000110100100 = Octal 40644  (drw-r--r--)
Binary 1010000111111111 = Octal 120777 (lrwxrwxrwx)

The previous examples in parts:

Binary 1/000 000 111/101/101 = Octal 10 0 755 = -rwxr-xr-x Binary 0/100 000 110/100/100 = Octal 4 0 644 = drw-r--r-- Binary 1/010 000 111/111/111 = Octal 12 0 777 = lrwxrwxrwx

The file types:

  • 10 (-) = regular file
  • 4 (d) = directory
  • 12 (l) = symbolic link
  • 1 (p) = FIFO (named pipe)
  • 14 (s) = socket
  • 2 (c) = character special file (like TTY, eg.: /dev/tty1)
  • 6 (b) = block special file (like HDD, eg.: /dev/sda)
  • and in other systems there are more (eg. Solaris D = door, P = port; etc.)
Hauke Laging
  • 90,279
kgyt
  • 21