File system calls in linux

Which linux system call is used by ls command in linux to display the folder/file name?

I wanted to know which system call is used in linux by the ls command to display the folder’s (or file’s name)? Especially the files/folders starting with «.» (dot) I executed the strace ls -a command to look at the system calls.There is a lot of fstat calls which occur for the all the other attributes (inode to permisisons). Which one actually gives it’s name?

execve("/bin/ls", ["ls", "-a"], [/* 37 vars */]) = 0 brk(0) = 0x1762000 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1c14025000 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 fstat(3, ) = 0 mmap(NULL, 109464, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f1c1400a000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/x86_64-linux-gnu/libselinux.so.1", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\20T\0\0\0\0\0\0". 832) = 832 fstat(3, ) = 0 mmap(NULL, 2221680, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f1c13be6000 mprotect(0x7f1c13c03000, 2093056, PROT_NONE) = 0 mmap(0x7f1c13e02000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1c000) = 0x7f1c13e02000 mmap(0x7f1c13e04000, 1648, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f1c13e04000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/x86_64-linux-gnu/librt.so.1", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\340!\0\0\0\0\0\0". 832) = 832 fstat(3, ) = 0 mmap(NULL, 2128984, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f1c139de000 mprotect(0x7f1c139e5000, 2093056, PROT_NONE) = 0 mmap(0x7f1c13be4000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6000) = 0x7f1c13be4000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/x86_64-linux-gnu/libacl.so.1", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\33\0\0\0\0\0\0". 832) = 832 fstat(3, ) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1c14009000 mmap(NULL, 2126312, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f1c137d6000 mprotect(0x7f1c137dd000, 2093056, PROT_NONE) = 0 mmap(0x7f1c139dc000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x6000) = 0x7f1c139dc000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\200\30\2\0\0\0\0\0". 832) = 832 fstat(3, ) = 0 mmap(NULL, 3925208, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f1c13417000 mprotect(0x7f1c135cc000, 2093056, PROT_NONE) = 0 mmap(0x7f1c137cb000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1b4000) = 0x7f1c137cb000 mmap(0x7f1c137d1000, 17624, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f1c137d1000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/x86_64-linux-gnu/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\340\r\0\0\0\0\0\0". 832) = 832 fstat(3, ) = 0 mmap(NULL, 2109704, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f1c13213000 mprotect(0x7f1c13215000, 2097152, PROT_NONE) = 0 mmap(0x7f1c13415000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f1c13415000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/x86_64-linux-gnu/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\200l\0\0\0\0\0\0". 832) = 832 fstat(3, ) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1c14008000 mmap(NULL, 2212904, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f1c12ff6000 mprotect(0x7f1c1300e000, 2093056, PROT_NONE) = 0 mmap(0x7f1c1320d000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x17000) = 0x7f1c1320d000 mmap(0x7f1c1320f000, 13352, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f1c1320f000 close(3) = 0 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) open("/lib/x86_64-linux-gnu/libattr.so.1", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\340\17\0\0\0\0\0\0". 832) = 832 fstat(3, ) = 0 mmap(NULL, 2113736, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f1c12df1000 mprotect(0x7f1c12df5000, 2093056, PROT_NONE) = 0 mmap(0x7f1c12ff4000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x3000) = 0x7f1c12ff4000 close(3) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1c14007000 mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1c14005000 arch_prctl(ARCH_SET_FS, 0x7f1c140057c0) = 0 mprotect(0x7f1c137cb000, 16384, PROT_READ) = 0 mprotect(0x7f1c12ff4000, 4096, PROT_READ) = 0 mprotect(0x7f1c1320d000, 4096, PROT_READ) = 0 mprotect(0x7f1c13415000, 4096, PROT_READ) = 0 mprotect(0x7f1c139dc000, 4096, PROT_READ) = 0 mprotect(0x7f1c13be4000, 4096, PROT_READ) = 0 mprotect(0x7f1c13e02000, 4096, PROT_READ) = 0 mprotect(0x618000, 4096, PROT_READ) = 0 mprotect(0x7f1c14027000, 4096, PROT_READ) = 0 munmap(0x7f1c1400a000, 109464) = 0 set_tid_address(0x7f1c14005a90) = 4490 set_robust_list(0x7f1c14005aa0, 0x18) = 0 futex(0x7fff2e09d99c, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 1, NULL, 7f1c140057c0) = -1 EAGAIN (Resource temporarily unavailable) rt_sigaction(SIGRTMIN, , NULL, 8) = 0 rt_sigaction(SIGRT_1, , NULL, 8) = 0 rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0 getrlimit(RLIMIT_STACK, ) = 0 statfs("/selinux", , f_namelen=255, f_frsize=4096>) = 0 brk(0) = 0x1762000 brk(0x1783000) = 0x1783000 open("/proc/filesystems", O_RDONLY) = 3 fstat(3, ) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1c14024000 read(3, "nodev\tsysfs\nnodev\trootfs\nnodev\tb". 1024) = 328 read(3, "", 1024) = 0 close(3) = 0 munmap(0x7f1c14024000, 4096) = 0 open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3 fstat(3, ) = 0 mmap(NULL, 7220736, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f1c1270e000 close(3) = 0 ioctl(1, SNDCTL_TMR_TIMEBASE or TCGETS, ) = 0 ioctl(1, TIOCGWINSZ, ) = 0 openat(AT_FDCWD, ".", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = 3 getdents(3, /* 2 entries */, 32768) = 48 getdents(3, /* 0 entries */, 32768) = 0 close(3) = 0 fstat(1, ) = 0 mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f1c14024000 write(1, ". ..\n", 6. .. ) = 6 close(1) = 0 munmap(0x7f1c14024000, 4096) = 0 close(2) = 0 exit_group(0) = ? 

Источник

Читайте также:  Resolve domain name linux

Linux system call in Detail

A system call is a procedure that provides the interface between a process and the operating system. It is the way by which a computer program requests a service from the kernel of the operating system.

Different operating systems execute different system calls.

In Linux, making a system call involves transferring control from unprivileged user mode to privileged kernel mode; the details of this transfer vary from architecture to architecture. The libraries take care of collecting the system-call arguments and, if necessary, arranging those arguments in the special form necessary to make the system call.

System calls are divided into 5 categories mainly :

  • Process Control
  • File Management
  • Device Management
  • Information Maintenance
  • Communication

Process Control :

This system calls perform the task of process creation, process termination, etc.

The Linux System calls under this are fork() , exit() , exec().

  • fork()
    • A new process is created by the fork() system call.
    • A new process may be created with fork() without a new program being run-the new sub-process simply continues to execute exactly the same program that the first (parent) process was running.
    • It is one of the most widely used system calls under process management.
    • The exit() system call is used by a program to terminate its execution.
    • The operating system reclaims resources that were used by the process after the exit() system call.
    • A new program will start executing after a call to exec()
    • Running a new program does not require that a new process be created first: any process may call exec() at any time. The currently running program is immediately terminated, and the new program starts executing in the context of the existing process.

    File Management :

    File management system calls handle file manipulation jobs like creating a file, reading, and writing, etc. The Linux System calls under this are open(), read(), write(), close().

    • open():
      • It is the system call to open a file.
      • This system call just opens the file, to perform operations such as read and write, we need to execute different system call to perform the operations.
      • This system call opens the file in reading mode
      • We can not edit the files with this system call.
      • Multiple processes can execute the read() system call on the same file simultaneously.
      • This system call opens the file in writing mode
      • We can edit the files with this system call.
      • Multiple processes can not execute the write() system call on the same file simultaneously.
      • This system call closes the opened file.

      Device Management :

      Device management does the job of device manipulation like reading from device buffers, writing into device buffers, etc. The Linux System calls under this is ioctl().

      • ioctl():
        • ioctl() is referred to as Input and Output Control.
        • ioctl is a system call for device-specific input/output operations and other operations which cannot be expressed by regular system calls.

        Information Maintenance:

        It handles information and its transfer between the OS and the user program. In addition, OS keeps the information about all its processes and system calls are used to access this information. The System calls under this are getpid(), alarm(), sleep().

        • getpid():
          • getpid stands for Get the Process ID.
          • The getpid() function shall return the process ID of the calling process.
          • The getpid() function shall always be successful and no return value is reserved to indicate an error.
          • This system call sets an alarm clock for the delivery of a signal that when it has to be reached.
          • It arranges for a signal to be delivered to the calling process.
          • This System call suspends the execution of the currently running process for some interval of time
          • Meanwhile, during this interval, another process is given chance to execute

          Communication :

          These types of system calls are specially used for inter-process communications.

          Two models are used for inter-process communication

          1. Message Passing(processes exchange messages with one another)
          2. Shared memory(processes share memory region to communicate)

          The system calls under this are pipe() , shmget() ,mmap().

          • pipe():
            • The pipe() system call is used to communicate between different Linux processes.
            • It is mainly used for inter-process communication.
            • The pipe() system function is used to open file descriptors.
            • shmget stands for shared memory segment.
            • It is mainly used for Shared memory communication.
            • This system call is used to access the shared memory and access the messages in order to communicate with the process.
            • This function call is used to map or unmap files or devices into memory.
            • The mmap() system call is responsible for mapping the content of the file to the virtual memory space of the process.

            These are the various system calls involved in LINUX operating system.

            Источник

Оцените статью
Adblock
detector