How the Operating system deal with the File ?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
green1
Posts: 5
Joined: Fri Apr 18, 2014 5:29 am

How the Operating system deal with the File ?

Post by green1 »

Hi There !

I have a great interest in Computer Science and to know how actually the things works. I have a question although its very basic but I could not find a direct answer. Please help me out.

What are the steps behind, when the file is clicked on the Desktop ? Does operating system calls a loader and how it knows that this is the specific loader for this file type. Lets take an example that there is a PDF file now this file is opened by Adobe reader, How the file extension pdf let the operating system know that this is the right program to open the file ? Does it maintain a table of file extensions that will choose that loader ?

Best Regards
User avatar
Bender
Member
Member
Posts: 449
Joined: Wed Aug 21, 2013 3:53 am
Libera.chat IRC: bender|
Location: Asia, Singapore

Re: How the Operating system deal with the File ?

Post by Bender »

If you're talking about Windows I'd recommend reading Windows Internals. Under Windows when a program is started:
1) The shell validates and converts parameters to native
2) Opens the file for reading, and loads the executable from the file system.
3) Inside the kernel a new structure is dynamically created. I'm too lazy to search, by try finding EPROCESS structure.
4) Creates the main thread.
5) Initialization of .NET VM (If it's a .NET Application)
6) Loads and configures the dynamic linked libraries (DLLs)
7) WinMain(); :)
I am not sure about Linux 'cause I'm from the Windows Community. :lol:
Yes. Windows maintains the list of file extensions inside it's registry, it'll be under HKEY_CLASSES_ROOT, which file to open with what program is done by the shell, what you see is the magic done by userspace not the Windows Kernel, in fact the Windows Kernel only has core features like memory management etc. That's why NTOSKRNL.EXE is so small. :)
In my OS my executable format has a list of required services at the EOF, so does my kernel while loading them. The kernel checks the list before loading the program, if there is something new, it then searches in a directory (kernel/lib), and loads them.
"In a time of universal deceit - telling the truth is a revolutionary act." -- George Orwell
(R3X Runtime VM)(CHIP8 Interpreter OS)
onlyonemac
Member
Member
Posts: 1146
Joined: Sat Mar 01, 2014 2:59 pm

Re: How the Operating system deal with the File ?

Post by onlyonemac »

Under Linux there's not really any such thing as different types of files as far as the kernel is concerned. Most programs work by simply trying to interpret any specified files, which are named as command-line options (they're like filenames appended to the name of the program when the name of the program is passed to the kernel for execution). (Often, however, this will fail if the file is not of the correct type.)

When double-clicking on a file in the GUI, the desktop manager (just a really complex user-space application) will look in its own internal list of the file types and try to determine the best program to use based on various factors including the file extension and any file header patterns which may be present. Once the program has been determined, it simply executes it with the filename on the command-line.
When you start writing an OS you do the minimum possible to get the x86 processor in a usable state, then you try to get as far away from it as possible.

Syntax checkup:
Wrong: OS's, IRQ's, zero'ing
Right: OSes, IRQs, zeroing
Rew
Member
Member
Posts: 28
Joined: Mon Oct 29, 2012 2:26 pm

Re: How the Operating system deal with the File ?

Post by Rew »

green1 wrote:Hi There !

I have a great interest in Computer Science and to know how actually the things works. I have a question although its very basic but I could not find a direct answer. Please help me out.

What are the steps behind, when the file is clicked on the Desktop ? Does operating system calls a loader and how it knows that this is the specific loader for this file type. Lets take an example that there is a PDF file now this file is opened by Adobe reader, How the file extension pdf let the operating system know that this is the right program to open the file ? Does it maintain a table of file extensions that will choose that loader ?

Best Regards
Yes, when you double click a file a component in windows handles that. Microsoft keeps a list of registration information by extension. Windows does not check the contents of the file to determine an appropriate action. Based on how that extension is configured (it can have a default program, multiple supported opens with registered, or nothing registered) windows does something. In the case of not having a default application, the user is prompted to select an application. Windows keeps this extension information in HKEY_CLASSES_ROOT\.pdf for example. The .pdf node has a Default attribute as well as an optional key "OpenWithList" for other applications. On my computer, HKEY_CLASSES_ROOT\.pdf\Default = "AcroExch.Document.11".

Once an application has been identified, windows uses that application's default VERB (uses the default because you double clicked). If you instead right clicked on the icon, windows uses the same process as above to find a default application and then displays a list of verbs for you. Once a VERB has been identified, the action specified by the verb is invoked. This looks like HKEY_CLASSES_ROOT\AcroExch.Document.11\Shell\Default = "Read". This specifies that the shell should invoke the read action by default. Then there is HKEY_CLASSES_ROOT\AcroExch.Document.11\Shell\Read\Command = "C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe" "%1". Windows uses the command specified and substitutes the file as the first argument for the command. Different VERBs can have a different command line so that you can expose multiple actions to the user via a right click on file menu. Infact, different VERBS can sometimes even open different executable for the same extension. Obviously after the command is invoked, the way the underlying application acts is not controlled by windows.
Post Reply