if some files are pseudo, why open() function still can access it?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















We know there are many files that are pseudo files, i.e. not a real file.



ex:



/sys/xxx
/proc/xxx
/dev/xxxx


In my understanding, the open() will call x86 ASM code, the ASM code will do hardware interrupt to access to the disk.



The problem is if the open() will eventually access to the disk, how pseudo file still get access by open()?










share|improve this question
























  • But you don't always need to access the disk… if you're accessing a pure memory based file

    – 炸鱼薯条德里克
    Mar 15 at 8:43

















1















We know there are many files that are pseudo files, i.e. not a real file.



ex:



/sys/xxx
/proc/xxx
/dev/xxxx


In my understanding, the open() will call x86 ASM code, the ASM code will do hardware interrupt to access to the disk.



The problem is if the open() will eventually access to the disk, how pseudo file still get access by open()?










share|improve this question
























  • But you don't always need to access the disk… if you're accessing a pure memory based file

    – 炸鱼薯条德里克
    Mar 15 at 8:43













1












1








1








We know there are many files that are pseudo files, i.e. not a real file.



ex:



/sys/xxx
/proc/xxx
/dev/xxxx


In my understanding, the open() will call x86 ASM code, the ASM code will do hardware interrupt to access to the disk.



The problem is if the open() will eventually access to the disk, how pseudo file still get access by open()?










share|improve this question
















We know there are many files that are pseudo files, i.e. not a real file.



ex:



/sys/xxx
/proc/xxx
/dev/xxxx


In my understanding, the open() will call x86 ASM code, the ASM code will do hardware interrupt to access to the disk.



The problem is if the open() will eventually access to the disk, how pseudo file still get access by open()?







linux kernel drivers disk






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 15 at 8:40









Kusalananda

141k18263439




141k18263439










asked Mar 15 at 8:29









MarkMark

1006




1006












  • But you don't always need to access the disk… if you're accessing a pure memory based file

    – 炸鱼薯条德里克
    Mar 15 at 8:43

















  • But you don't always need to access the disk… if you're accessing a pure memory based file

    – 炸鱼薯条德里克
    Mar 15 at 8:43
















But you don't always need to access the disk… if you're accessing a pure memory based file

– 炸鱼薯条德里克
Mar 15 at 8:43





But you don't always need to access the disk… if you're accessing a pure memory based file

– 炸鱼薯条德里克
Mar 15 at 8:43










2 Answers
2






active

oldest

votes


















2














As Fox noted in their answer, the kernel handles the open() syscall, and meanwhile, filesystems implement file operations in their own way. Filesystems, on the other hand, implement their version of syscalls, and that's what kernel should be using.



Consider, for instance, ext4 call to open directory or file operations in procfs (which notably has no .open mentioned anywhere), and pipefs which handles named and unnamed pipes. But the general idea is that the open() syscall is not going to be necessarily assembly, nor it is guaranteed to be specific to a particular architecture.



And to quote an answer by the user Warren Young who noted that way before this question appeared,




there is no single file where mkdir() exists. Linux supports many different file systems and each one has its own implementation of the "mkdir" operation. The abstraction layer that lets the kernel hide all that behind a single system call is called the VFS. So, you probably want to start digging in fs/namei.c, with vfs_mkdir(). The actual implementations of the low-level file system modifying code are elsewhere. For instance, the ext4 implementation is called ext4_mkdir(), defined in fs/ext4/namei.c.




As for why open() works this way, this is also due to Unix design philosophy that everything is a file. If you're using an API, you want to deal with consistent interface and not reinvent the wheel for every filesystem in existence (unless a person is a kernel developer, in which case they have our gratitude and respect).






share|improve this answer
































    4














    The open() system call does not work as you describe. Instead, it asks the kernel to open a file. The kernel knows which filesystem that file is on and what device it is associated with. This may be a physical hard drive, a block of memory, etc. If the associated device is just a block of memory, no disk access is performed.






    share|improve this answer


















    • 2





      Also, the hardware architecture may not even be x86.

      – Kusalananda
      Mar 15 at 8:40











    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f506438%2fif-some-files-are-pseudo-why-open-function-still-can-access-it%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    As Fox noted in their answer, the kernel handles the open() syscall, and meanwhile, filesystems implement file operations in their own way. Filesystems, on the other hand, implement their version of syscalls, and that's what kernel should be using.



    Consider, for instance, ext4 call to open directory or file operations in procfs (which notably has no .open mentioned anywhere), and pipefs which handles named and unnamed pipes. But the general idea is that the open() syscall is not going to be necessarily assembly, nor it is guaranteed to be specific to a particular architecture.



    And to quote an answer by the user Warren Young who noted that way before this question appeared,




    there is no single file where mkdir() exists. Linux supports many different file systems and each one has its own implementation of the "mkdir" operation. The abstraction layer that lets the kernel hide all that behind a single system call is called the VFS. So, you probably want to start digging in fs/namei.c, with vfs_mkdir(). The actual implementations of the low-level file system modifying code are elsewhere. For instance, the ext4 implementation is called ext4_mkdir(), defined in fs/ext4/namei.c.




    As for why open() works this way, this is also due to Unix design philosophy that everything is a file. If you're using an API, you want to deal with consistent interface and not reinvent the wheel for every filesystem in existence (unless a person is a kernel developer, in which case they have our gratitude and respect).






    share|improve this answer





























      2














      As Fox noted in their answer, the kernel handles the open() syscall, and meanwhile, filesystems implement file operations in their own way. Filesystems, on the other hand, implement their version of syscalls, and that's what kernel should be using.



      Consider, for instance, ext4 call to open directory or file operations in procfs (which notably has no .open mentioned anywhere), and pipefs which handles named and unnamed pipes. But the general idea is that the open() syscall is not going to be necessarily assembly, nor it is guaranteed to be specific to a particular architecture.



      And to quote an answer by the user Warren Young who noted that way before this question appeared,




      there is no single file where mkdir() exists. Linux supports many different file systems and each one has its own implementation of the "mkdir" operation. The abstraction layer that lets the kernel hide all that behind a single system call is called the VFS. So, you probably want to start digging in fs/namei.c, with vfs_mkdir(). The actual implementations of the low-level file system modifying code are elsewhere. For instance, the ext4 implementation is called ext4_mkdir(), defined in fs/ext4/namei.c.




      As for why open() works this way, this is also due to Unix design philosophy that everything is a file. If you're using an API, you want to deal with consistent interface and not reinvent the wheel for every filesystem in existence (unless a person is a kernel developer, in which case they have our gratitude and respect).






      share|improve this answer



























        2












        2








        2







        As Fox noted in their answer, the kernel handles the open() syscall, and meanwhile, filesystems implement file operations in their own way. Filesystems, on the other hand, implement their version of syscalls, and that's what kernel should be using.



        Consider, for instance, ext4 call to open directory or file operations in procfs (which notably has no .open mentioned anywhere), and pipefs which handles named and unnamed pipes. But the general idea is that the open() syscall is not going to be necessarily assembly, nor it is guaranteed to be specific to a particular architecture.



        And to quote an answer by the user Warren Young who noted that way before this question appeared,




        there is no single file where mkdir() exists. Linux supports many different file systems and each one has its own implementation of the "mkdir" operation. The abstraction layer that lets the kernel hide all that behind a single system call is called the VFS. So, you probably want to start digging in fs/namei.c, with vfs_mkdir(). The actual implementations of the low-level file system modifying code are elsewhere. For instance, the ext4 implementation is called ext4_mkdir(), defined in fs/ext4/namei.c.




        As for why open() works this way, this is also due to Unix design philosophy that everything is a file. If you're using an API, you want to deal with consistent interface and not reinvent the wheel for every filesystem in existence (unless a person is a kernel developer, in which case they have our gratitude and respect).






        share|improve this answer















        As Fox noted in their answer, the kernel handles the open() syscall, and meanwhile, filesystems implement file operations in their own way. Filesystems, on the other hand, implement their version of syscalls, and that's what kernel should be using.



        Consider, for instance, ext4 call to open directory or file operations in procfs (which notably has no .open mentioned anywhere), and pipefs which handles named and unnamed pipes. But the general idea is that the open() syscall is not going to be necessarily assembly, nor it is guaranteed to be specific to a particular architecture.



        And to quote an answer by the user Warren Young who noted that way before this question appeared,




        there is no single file where mkdir() exists. Linux supports many different file systems and each one has its own implementation of the "mkdir" operation. The abstraction layer that lets the kernel hide all that behind a single system call is called the VFS. So, you probably want to start digging in fs/namei.c, with vfs_mkdir(). The actual implementations of the low-level file system modifying code are elsewhere. For instance, the ext4 implementation is called ext4_mkdir(), defined in fs/ext4/namei.c.




        As for why open() works this way, this is also due to Unix design philosophy that everything is a file. If you're using an API, you want to deal with consistent interface and not reinvent the wheel for every filesystem in existence (unless a person is a kernel developer, in which case they have our gratitude and respect).







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 15 at 15:04









        Prajwal Dhatwalia

        31019




        31019










        answered Mar 15 at 9:40









        Sergiy KolodyazhnyySergiy Kolodyazhnyy

        10.7k42764




        10.7k42764























            4














            The open() system call does not work as you describe. Instead, it asks the kernel to open a file. The kernel knows which filesystem that file is on and what device it is associated with. This may be a physical hard drive, a block of memory, etc. If the associated device is just a block of memory, no disk access is performed.






            share|improve this answer


















            • 2





              Also, the hardware architecture may not even be x86.

              – Kusalananda
              Mar 15 at 8:40















            4














            The open() system call does not work as you describe. Instead, it asks the kernel to open a file. The kernel knows which filesystem that file is on and what device it is associated with. This may be a physical hard drive, a block of memory, etc. If the associated device is just a block of memory, no disk access is performed.






            share|improve this answer


















            • 2





              Also, the hardware architecture may not even be x86.

              – Kusalananda
              Mar 15 at 8:40













            4












            4








            4







            The open() system call does not work as you describe. Instead, it asks the kernel to open a file. The kernel knows which filesystem that file is on and what device it is associated with. This may be a physical hard drive, a block of memory, etc. If the associated device is just a block of memory, no disk access is performed.






            share|improve this answer













            The open() system call does not work as you describe. Instead, it asks the kernel to open a file. The kernel knows which filesystem that file is on and what device it is associated with. This may be a physical hard drive, a block of memory, etc. If the associated device is just a block of memory, no disk access is performed.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Mar 15 at 8:38









            FoxFox

            5,76211233




            5,76211233







            • 2





              Also, the hardware architecture may not even be x86.

              – Kusalananda
              Mar 15 at 8:40












            • 2





              Also, the hardware architecture may not even be x86.

              – Kusalananda
              Mar 15 at 8:40







            2




            2





            Also, the hardware architecture may not even be x86.

            – Kusalananda
            Mar 15 at 8:40





            Also, the hardware architecture may not even be x86.

            – Kusalananda
            Mar 15 at 8:40

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f506438%2fif-some-files-are-pseudo-why-open-function-still-can-access-it%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown






            Popular posts from this blog

            Peggy Mitchell

            Palaiologos

            The Forum (Inglewood, California)