Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 See also  





2 References  














Everything is a file






Deutsch
Español
Lombard
 

Edit links
 









Article
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Cite this page
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 


"Everything is a file" is an idea that Unix, and its derivatives, handle input/output to and from resources such as documents, hard-drives, modems, keyboards, printers and even some inter-process and network communications as simple streams of bytes exposed through the filesystem name space.[1] Exceptions include semaphores, processes and threads.

The advantage of this approach is that the same set of tools, utilities and APIs can be used on a wide range of resources and a number of file types. When a file is opened, a file descriptor is created, using the file path as an addressing system. The file descriptor is then a byte stream I/O interface on which file operations are performed. File descriptors are also created for objects such as anonymous pipes and network sockets – and therefore a more accurate description of this feature is Everything is a file descriptor.[2][3]

Additionally, a range of pseudo and virtual filesystems exists which exposes internal kernel data, such as information about processes, to user space in a hierarchical file-like structure.[4] These are mounted into the single file hierarchy.

An example of this purely virtual filesystem is under /proc that exposes many system properties as files. All of these files, in the broader sense of the word, have standard Unix file attributes such as an owner and access permissions, and can be queried by the same classic Unix tools and filters. However, this is not universally considered a fast or portable approach. Some operating systems do not mount /proc by default due to security or speed concerns, relying on system calls instead.[5] It is, though, used heavily by Linux shell utilities,[6][7] such as procps ps implementation and the widely installed on embedded systems BusyBox.[8] Android Toolbox program depend on it as well.[9]

Another example is sysfs, which is usually mounted to /sys, which exposes kernel data structures.[10] sysfs provides functionality similar to the sysctl mechanism found in BSD operating systems, with the difference that sysfs is implemented as a virtual file system instead of being a purpose-built kernel mechanism.[11] The philosophy behind sysfs is to represent each value with a dedicated file. In addition each file has a maximum size of PAGE_SIZE bytes.

For a kernel module there are three possibilities to use a file below /sys:

The standard sysfs API uses a dedicated terminology: A file is called an attribute, the function executed upon reading an attribute is called show and the one for writing an attribute store.[12]

Sysfs was derived from procfs between Linux kernel versions 2.5-2.6, initially as a dedicated filesystem to debug a new driver model. Both sysfs and procfs are memory-based. Sysfs contains directories for block devices, physical bus types, device classes (such as those used for graphics, networking, inputorprinting), firmware-specific objects and attributes, kernel modules and the power subsystem.[13]

For example, writing memto/sys/power/state will trigger a suspend-to-RAM procedure.[14]

Another example of files with specific behaviors are /dev/null and /dev/zero device files. Writes to them will be discarded.[15] This can, for example, be used to redirect unneeded standard streams.

See also[edit]

References[edit]

  • ^ "Linus Torvalds - 'everything is a file descriptor or a process'". Yarchive.net. Retrieved 2015-08-28.
  • ^ "Ghosts of Unix Past". Lwn.net. Retrieved 2015-08-28.
  • ^ Benvenuti, Christian (2006). "3. User-Space-to-Kernel Interface". Understanding Linux network internals (Nachdr. ed.). Beijing Köln: O'Reilly. p. 58. ISBN 9780596002558.
  • ^ "8. procfs: Gone But Not Forgotten". Freebsd.org. Retrieved 2015-08-28.
  • ^ Xiao, Yang; Li, Frank Haizhon; Chen, Hui (2011). Handbook of security and networks. Hackensack (NJ): World scientific. p. 160. ISBN 9789814273039.
  • ^ "27. Upgrading and customizing the kernel". Red Hat Linux Networking and System Administration. John Wiley & Sons. 2007. p. 662. ISBN 9780471777311.
  • ^ "busybox - BusyBox: The Swiss Army Knife of Embedded Linux". Git.busybox.net. Retrieved 2015-08-28.
  • ^ "platform_system_core/ps.c at master · android/platform_system_core · GitHub". GitHub.com. 2015-03-09. Retrieved 2015-08-28.
  • ^ Mochel, Patrick; Murphy, Mike (16 August 2011). "sysfs - _The_ filesystem for exporting kernel objects". kernel.org. Archived from the original on 13 March 2024. Retrieved 15 June 2024.
  • ^ Vskills, Team. "SysFS and proc". Tutorial. Retrieved 2024-06-15.
  • ^ "sysfs, procfs, sysctl, debugfs and other similar kernel interfaces". John's Blog. 2013-11-20. Retrieved 2024-06-15.
  • ^ Patrick Mochel, The sysfs subsystem, 2005 Linux Symposium, pp. 314-317
  • ^ Wysocki, Rafael J. "System Power Management Sleep States". kernel.org. Retrieved 15 June 2024.
  • ^ "null(4) - Linux manual page". www.man7.org. Retrieved 2024-06-15.

  • Retrieved from "https://en.wikipedia.org/w/index.php?title=Everything_is_a_file&oldid=1231170297"

    Categories: 
    Information theory
    Unix file system technology
    Hidden categories: 
    Webarchive template wayback links
    Articles with short description
    Short description is different from Wikidata
    Articles lacking reliable references from August 2015
    All articles lacking reliable references
     



    This page was last edited on 26 June 2024, at 21:25 (UTC).

    Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



    Privacy policy

    About Wikipedia

    Disclaimers

    Contact Wikipedia

    Code of Conduct

    Developers

    Statistics

    Cookie statement

    Mobile view



    Wikimedia Foundation
    Powered by MediaWiki