How does C access files? [closed] - c

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 11 months ago.
Improve this question
everyone! I'm learning how to access files in C but, I wonder how my program(or C) access files(drive sectors)? I'm searching the Internet for answers but they don't have some proper explanation on how C(or my program), loads drive sectors to memory. Please give me some clarity, and thanks in advance.

C programs use functions of the kernel or a device driver to access hardware. A computing platform (Windows, Linux, OSX, etc) that supports C provides an implementation of the C standard library for programmers. This library contains system specific implementations of functions for accessing files, like fopen. The systems implementation of the standard library is most often just a wrapper around their specific system calls. For example on Windows, the C standard library is going to end up calling these functions: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/

Related

Install a C program to another machine without share code [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
This post was edited and submitted for review 11 months ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I need to install a C program UNIX to another UNIX machine, what can I do?
In case the other machine has different architecture how can I share my program in the best way?
The simplest way to share your program is compile it and share the binaries. There are a lot of open question you will have to solve (libraries dependencies, specific distribution configurations, ...). You must to precompile for every targeted hardware architecture (x86-64, ARM, ...) and for every specific SO (BSD, Linux, ... even Windows).
As an example, Gimp is coded in C/C++ and exists binaries for many hardware architectures and operating systems.

How to create a multistage bootloader with asm and c? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I want to create a simple 32-bit text-based operating system.
Bootloader :
Firstly I want to create a multistage bootloader.
Stage 1 : Assembly code (NASM-Compiler)
Stage 2 : C (GCC-Compiler)
Kernel:
Then it should load Kernel which should be written in C (GCC-Compiler)
I would also like to know how to properly compile and execute it.
Emulator should be Qemu
A sample 32-bit Operating System that displays "Hello world" would be helpful.
Don't write your own bootloader. Configure and use an existing bootloader, probably GRUB. This would make using your toy OS much easier (both for you and for other users).
Read http://osdev.org/ since they have a lot of resources about OS building on PCs (including a hello world OS).
Read also some good operating system book (e.g. Operating Systems: Three Easy Pieces). You'll find out that there cannot be very simple OSes. See also this answer.
Also, be at least quite fluent with POSIX and with Linux system programming (read Advanced Linux Programming at first).

What is the difference between drivers and libraries in embedded C [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am wondering what is the difference between drivers and libraries in the embedded C programming. Assuming that I am using uControllers that only have application code/firmware like PICs
With respect to deeply embedded systems (such as the PIC) the distinction is generally that a driver is tied to the hardware and is not portable between platforms, while a regular library should be portable and have no direct hardware dependencies. This is not a hard and fast rule, however it is the most consistent one that I have come across in embedded systems.
It is also common for vendors to call a collection of drivers a library so in a way you can think of drivers as just a special type of hardware dependent library, and a library as simply a collection of related code.

C language compiler for new OS (theoretical questions)? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Let’s assume that I wrote a primitive bootloader using assembly language. The computer is still on real mode. Now I want to write a primitive kernel and shell using C language.
Questions:
1.Do I need to write a C Language compiler in assembly for this new OS or can I use a C compiler running on a different OS? I guess it could be both!
2.If I use a C compiler from a different OS, functions like printf () can be compiled to target the BIOS’s functions instead of the OS’s API to avoid dependencies?
3.If my bootloader switch the computer into protected mode the kernel will need to implement the equivalent to the BIOS functions?
4.Assuming a YES to question 3: If I use a C compiler from a different OS what is required to make it target the new OS kernel functions? Rewriting the headers files?
(EDIT) PD: These are theoretical questions. I don’t need specific details about the actual implementation. I just want to validate the concepts. Don’t feel obligated to answer all of them!
You can do either. I would strongly recommend to just use a standard compiler though. Writing a good compiler is very complex and time consuming.
As long as you do not have an implementation of the standard library just don't use it. You can tell C-compilers to assume that there is no standard library and write your own printf-like functions.
You lose access to the BIOS functions in real mode. If you need them you do need to reimplement them.
Not much change is required actually. Executables are incomplete and require to be linked against something that implements the used standard library functions and whatever other libraries used. All you need to do is link the executable against a (possible self-written) library that somehow implements the required functions.

Trimming down freebsd [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I am trying to trim down FreeBSD to understand/learn how things work. I have a few questions if someone can help me with that:
1) when we say kernel, can I separate code wise from the rest of the FreeBSD code? What I mean is, I want to know what all files/dirs come under kernel.
2) I know a book called Linux from scratch. Is there any related book for FreeBSD?
Any pointers are most welcome.
Thank you.
FreeBSD is one cohesive system. Whereas Linux is a kernel plus a bunch of packages, all of FreeBSD core is built together (everything but the ports tree). The FreeBSD Handbook is the best resource to start from for learning FreeBSD. There is also a Developer's handbook that can be found on the FreeBSD website. As for what the kernel is in terms of source files, anything under /usr/src/sys is kernel source code. If you want to know about the workings of the kernel, the book "The Design and Implementation of the FreeBSD Operating System" is the definitive guide to the details of the kernel.

Resources