Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Unix file types

From Wikipedia, the free encyclopedia
(Redirected fromRegular file)
File types in Unix operating systems

The seven standardUnix file types areregular,directory,symbolic link,FIFO special,block special,character special, andsocket as defined byPOSIX.[1] Different OS-specific implementations allow more types than what POSIX requires (e.g. Solarisdoors). A file's type can be identified by thels -l command, which displays the type in the first character of thefile-system permissions field.

Forregular files,Unix does not impose or provide any internal file structure; therefore, their structure and interpretation is entirely dependent on the software using them.[2] However, thefile command can usually be used to determine whattype of data they contain.[3]

Representations

[edit]
See also:File-system permissions § Notation of traditional Unix permissions, andchmod

Numeric

[edit]

In thestat structure, file type and permissions (themode) are stored together in ast_modebit field, which has a size of at least 12 bits (3 bits to specify the type among the seven possible types of files; 9 bits for permissions). The layout for permissions is defined by POSIX to be at theleast-significant 9 bits, but the rest is undefined.[1]

By convention, the mode is a 16-bit value written out as a six-digit octal number without a leading zero. The format part occupies the lead 4-bits (2 octal digits), and "010" (1000 in binary) usually stands for a regular file. The next 3 bits (1 digit) are usually used forsetuid, setgid, and sticky. The last part is already defined by POSIX to contain the permission. An example is "100644" for a typical file. This format can be seen ingit,tar, andar, among other places.[4]

The type of a file can be tested using macros likeS_ISDIR. Such a check is usually performed by masking the mode withS_IFMT (often the octal number "170000" for the lead 4 bits convention) and checking whether the result matchesS_IFDIR.S_IFMT is not a core POSIX concept, but a X/Open System Interfaces (XSI) extension; systems conforming toonly POSIX may use some other methods.[1]

Mode string

[edit]

Take for example one line in thels -l output:

drwxr-xr-x 2 root root     0 Jan  1  1970 home

POSIX specifies[5] the format of the output for the long format (-l option). In particular, the first field (before the first space) is dubbed the "file mode string", heredrwxr-xr-x. Its first character describes the file type, hered (directory). The rest of this string indicates thefile permissions.

Examples of implementations

[edit]

TheGNU coreutils version ofls uses a call tofilemode(), aglibc function (exposed in thegnulib library[6]) to get the mode string.

FreeBSD uses a simpler approach but allows a smaller number of file types.[7]

Directory

[edit]
Main article:Directory (computing)
This sectionneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources in this section. Unsourced material may be challenged and removed.
Find sources: "Unix file types" – news ·newspapers ·books ·scholar ·JSTOR
(October 2023) (Learn how and when to remove this message)

The most common special file is the directory. The layout of a directory file is defined by the filesystem used. As several filesystems are available under Unix, both native and non-native, there is no one directory file layout.

A directory is marked with ad as the first letter in the mode field in the output ofls -dl[5] orstat, e.g.

$ ls -dl /drwxr-xr-x 26 root root 4096 Sep 22 09:29 /$ stat /  File: "/"  Size: 4096            Blocks: 8          IO Block: 4096directoryDevice: 802h/2050d      Inode: 128         Links: 26Access: (0755/drwxr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)...

Symbolic link

[edit]
Main article:Symbolic link
This sectionneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources in this section. Unsourced material may be challenged and removed.
Find sources: "Unix file types" – news ·newspapers ·books ·scholar ·JSTOR
(October 2023) (Learn how and when to remove this message)

A symbolic link is a reference to another file. This special file is stored as a textual representation of the referenced file's path (which means the destination may be a relative path, or may not exist at all).

A symbolic link is marked with anl (lower caseL) as the first letter of the mode string, e.g. in this abbreviatedls -l output:[5]

lrwxrwxrwx ... termcap -> /usr/share/misc/termcaplrwxrwxrwx ... S03xinetd -> ../init.d/xinetd

FIFO (named pipe)

[edit]
Main article:Named pipe
This sectionneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources in this section. Unsourced material may be challenged and removed.
Find sources: "Unix file types" – news ·newspapers ·books ·scholar ·JSTOR
(October 2023) (Learn how and when to remove this message)

One of the strengths of Unix has always beeninter-process communication. Among the facilities provided by the OS arepipes, which connect the output of oneprocess to the input of another. This is fine if both processes exist in the same parent process space, started by the same user, but there are circumstances where the communicating processes must use FIFOs, here referred to asnamed pipes. One such circumstance occurs when the processes must be executed under different user names and permissions.

Named pipes are special files that can exist anywhere in the file system. They can be created with the commandmkfifo as inmkfifo mypipe.

A named pipe is marked with ap as the first letter of the mode string, e.g. in this abbreviatedls -l output:[5]

prw-rw---- ... mypipe

Socket

[edit]
Main article:Unix domain socket
This sectiondoes notcite anysources. Please helpimprove this section byadding citations to reliable sources. Unsourced material may be challenged andremoved.
Find sources: "Unix file types" – news ·newspapers ·books ·scholar ·JSTOR
(October 2023) (Learn how and when to remove this message)

A socket is a special file used forinter-process communication, which enables communication between two processes. In addition to sending data, processes can sendfile descriptors across a Unix domain socket connection using thesendmsg() andrecvmsg() system calls.

Unlike named pipes which allow only unidirectional data flow, sockets are fullyduplex-capable.

A socket is marked with ans as the first letter of the mode string, e.g.

srwxrwxrwx /tmp/.X11-unix/X0

Device file (block, character)

[edit]
Main article:Device file
This sectionneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources in this section. Unsourced material may be challenged and removed.
Find sources: "Unix file types" – news ·newspapers ·books ·scholar ·JSTOR
(October 2023) (Learn how and when to remove this message)

In Unix, almost all things are handled as files and have a location in the file system, even hardware devices like hard drives. The great exception is network devices, which do not turn up in the file system but are handled separately.

Device files are used to apply access rights to the devices and to direct operations on the files to the appropriate device drivers.

Unix makes a distinction between character devices and block devices. The distinction is roughly as follows:

  • Character devices provide only a serial stream of input or accept a serial stream of output
  • Block devices are randomly accessible

Although, for example,disk partitions may have both character devices that provide un-buffered random access to blocks on the partition and block devices that provide buffered random access to blocks on the partition.

A character device is marked with ac as the first letter of the mode string and a block device is marked with ab, e.g. in this abbreviatedls -l output:[5]

crw-rw-rw- .../dev/nullbrw-rw---- .../dev/sda

References

[edit]
  1. ^abc"<sys/stat.h>".The Open Group Base Specifications Issue 6. The Open Group. 21 July 2019.Archived from the original on 27 November 2016. Retrieved10 February 2017.
  2. ^Loukides, Mike (October 2002). "When Is a File Not a File?".Unix Power Tools (3 ed.). O'Reilly. p. 80.ISBN 9780596003302.A file is nothing more than a stream of bytes ...
  3. ^"file".IEEE Std 1003.1-2017 (POSIX).The Open Group. 2018.Archived from the original on 2018-10-12. Retrieved2023-10-26.
  4. ^Kitt, Stephen."What file mode is a symlink?".Unix & Linux Stack Exchange.
  5. ^abcde"ls".IEEE Std 1003.1-2008 (POSIX). The Open Group. 11 March 2017.Archived from the original on 3 August 2017. Retrieved10 February 2017.
  6. ^"filemode function in GNU coreutils". GNU. 11 March 2017.
  7. ^"printtype function from FreeBSD". FreeBSD. 11 March 2017.
Retrieved from "https://en.wikipedia.org/w/index.php?title=Unix_file_types&oldid=1236483480#Regular_file"
Category:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp