Android system development (6)-underlying Linux input and output, android System Development

Source: Internet
Author: User

Android system development (6)-underlying Linux input and output, android System Development
1. The operating system architecture computer is composed of a pile of hardware. The operating system is used to effectively control these hardware resources. In addition to effectively controlling the allocation of these hardware resources and providing the functions required for computer operation, the operating system provides an environment where programmers can easily develop software, the Operating System also provides a whole set of system call interfaces.
As shown in, the most intermediate part is hardware. The operating system is composed of the kernel and the system call interface. The kernel directly operates the hardware, the kernel provides control over these hardware resources and process management. The system call interface provides a unified call interface for developers to call. The top layer is the application. You can call the system interface in the application to perform hardware operations. Ii. Linux I/O system
For example, in the Linux I/O system structure, the kernel layer has a virtual file system, which is an api encapsulated by a standard c class library, therefore, to operate the file system, you only need to call the api here.
Iii. Operation Process of I/O 1. Open the file. An application requests the kernel to open the corresponding file and declares that it wants to access an I/O device. The kernel returns a non-negative integer, description symbol (Descriptor) [unique identifier of a file] 2. read/write file: Copy n> 0 bytes from a file to memory (memory) Write: From memory (memory) copy n> 0 bytes to file 3, change file location 4, close the file for the kernel, all open files are referenced by the file descriptor. The file descriptor is a non-negative integer. When an existing file is opened or a new file is created, the kernel returns a file descriptor to the process. When reading and writing a file, use the file descriptor fd returned by open or create to identify the file and send it as a parameter to read or write. the stream (for example, fopen) returns a FILE structure pointer. The FILE structure contains FILE descriptors. The FILE structure function can be seen as an encapsulation of system calls for direct fd operations, it has the advantage of I/O caching.

Linux supports various file system formats, such as ext2, ext3, reiserfs, FAT, NTFS, and iso9660, different disk partitions, CDs, or other storage devices have different file system formats. However, these file systems can be mounted to a directory, allowing us to see a unified directory tree, the directories and files on various file systems look the same with the ls command, and the read/write operations are the same. How does this happen? The Linux kernel creates an abstraction layer on top of various file system formats, which makes the concepts of files, directories, read/write access, and so on the abstraction layer. Therefore, all file systems look the same, this abstraction layer is called a Virtual File System (VFS, Virtual Filesystem)


4. Linux underlying Input and Output we can go to GNU to download the libc source code and help documentation (source code: http://ftp.gnu.org/gnu/glibc/) open and close the file stream
#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <stdlib.h>int main(int argc, char *argv[]){        //open file        if(argc<2){                printf("please input filename\n");                exit(1);        }else{                int fd;                umask(0000);                fd = open(argv[1], O_RDWR|O_CREAT, 0666);                if(fd < -1){                        printf("error\n");                        exit(1);                }else{                        printf("success=%d\n", fd);                        close(fd);                        printf("closed\n");                }        }        return 0;}
Read a file (the process of writing a file is similar to that of reading a file)
#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <stdlib.h>#include <string.h>int main(int argc, char *argv[]){        //open file        if(argc<2){                printf("please input filename\n");                exit(1);        }else{                int fd;                umask(0000);                fd = open(argv[1], O_RDWR|O_CREAT, 0666);                if(fd < -1){                        printf("error\n");                        exit(1);                }else{                        printf("success=%d\n", fd);                        char buf[1024];                        memset(buf, 0, 1024);                        int returnum = read(fd, buf, 1024);                        if(returnum != -1){                                printf("buf=%s\n", buf);                        }else{                                printf("read error\n");                                exit(1);                        }                        close(fd);                        printf("closed\n");                }        }        return 0;}



The underlying layer of the Android system is built on the Linux system. The platform consists of four layers.

Android uses a layered architecture and consists of four layers: application layer, application framework layer, system Runtime Library layer, and Linux core layer.
1. Android Application Layer
Applications are programs written in the Java language and run on virtual machines, that is, the upper-layer blue part in the figure. In fact, Google initially bundled some core applications in the Android system, for example, e-mail client, SMS Short Message program, calendar, MAP, browser, and contact management program.
2. Application Framework Layer
This layer is the API framework used to compile the core applications released by Google. developers can also use these frameworks to develop their own applications, which simplifies the architecture design of program development, however, the development principles of the framework must be observed.
3. System runtime database layer
When we use the Android Application Framework, the Android system uses some C/C ++ libraries to support various components we use so that they can better serve developers.
4. Linux core layer
Android core system services are based on the Linux2.6 kernel, such as security, memory management, process management, network protocol stack, and driver model. The Linux kernel is also an abstraction layer between hardware and software stacks.

How to get started with android underlying driver development? I have never touched on linux before and understand android application development.

Drivers are written in C, so you need to have a certain C base for underlying driver development. For development drivers, Windows systems are very unsuitable, especially Android itself is the Linux kernel. Therefore, you must master the Linux operating system, such as writing scripts and compiling C code.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.