In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Stat, fstst, lstat-get file status
1. Stat, fstat and lstat#include # include # include int stat (const char * path, struct stat * buf); int fstat (int fd, struct stat * buf); int lstat (const char * path, struct stat * buf); stat () stats the file pointed to by path and fills in buf. Lstat () is identical to stat (), except that if path is a sym- bolic link, then the link itself is stat-ed, not the file that it refers to. Fstat () is identical to stat (), except that the file to be stat-ed is specified by the file descriptor fd.struct stat {dev_t st_dev; / * ID of device containing file * / ino_t st_ino; / * inode number * / mode_t st_mode; / * protection * / nlink_t st_nlink; / * number of hard links * / uid_t st_uid; / * user ID of owner * / gid_t st_gid; / * group ID of owner * / dev_t st_rdev / * device ID (if special file) * / off_t st_size; / * total size, in bytes.used for regular file or symbolic link * / blksize_t st_blksize; / * blocksize for file system Imax O * / blkcnt_t st_blocks; / * number of 512B blocks allocated * / time_t st_atime; / * time of last access * / time_t st_mtime; / * time of last modification * / time_t st_ctime; / * time of last status change * /}. File type: can be judged by the corresponding macro in sys/stat.h. These macros are basically mode and S_IFxx & get the results. (1)。 Normal files: the kernel does not distinguish between text files and binary files. The interpretation of a normal file is performed by the application that processes the file. It is judged by the S_ISREG () macro. (2)。 Directory files: only the kernel can write directory files. It is judged by the S_ISDIR () macro. (3)。 Block special file: provides access to buffered devices. Each visit is conducted in fixed-length units. It is judged by the S_ISCHR () macro. (4)。 Word special file: provides access to devices without buffering. The length of each visit is variable. There are only two types of devices in the system. It is judged by the S_ISBLK () macro. (5) .FIFO: this type of file is used for interprocess communication, sometimes referred to as named pipes. It is judged by the S_ISFIFO () macro. (6)。 Nested word socket: this file type is used for network communication of process keys. It can also be used for non-network communication between processes on a host. It is judged by the S_ISSOCK () macro. (7)。 Symbolic link: this file type points to another file. It is judged by the S_ISLNK () macro. POSIX.1 allows IPC objects to be represented as files, and macros can also determine the shared storage of S_TYPEPEISMQ () message queues, S_TYPEISSEM semaphores, and S_TYPEISSHM (). 3. St_uid and st_gid in the file access rights stat: the actual user ID and the actual group ID identify who the file belongs to. The valid user ID and the additional group ID determine our file access rights. Usually the two are equal, but set a special flag in the file mode word: when the file is executed, the valid user ID of its process is set to the file owner's ID (st_uid). Similarly, set another special flag: when this file is executed, the valid user group ID for its process is set to the ID (st_gid) of the file owner group. For example, the owner of the / etc/passwd,/etc/shadow file is root, and only root has write access to / etc/passwd,/etc/shadow. Passwd allows any user to change his or her password. Therefore, you need to set the setup bit of passwd to ensure that the process executing the program has files related to changes in the root permission area. Rule: (1). Open with O_TRUNC must have write permission to the file. (2)。 To create a file, you must have write and execute permissions to the directory in which it is located. Similarly, to delete a file, you must have write and execute permissions to the file's directory (no write and execute permissions are required for the file). (3)。 If you use any exec function on the file, you must have execute permissions on the file and make sure that the file is a normal file. Each time a file is opened, created, and deleted, the kernel tests file access permissions, which may involve the owner of the file, a valid ID (valid user and group ID), and an additional group ID (if supported). The order of kernel testing is: a). If the process valid user ID is 0, all permissions are allowed. b)。 If the valid user ID of the process is equal to the owner ID of the file, it is judged according to the access rights of the owner of the file. c)。 If the valid group ID of the process or one of the additional groups ID of the process is equal to the group ID of the file, it is judged according to the access rights of the file owner group. d)。 Finally, it is judged according to the appropriate access rights of other users. For any of these steps (whether permission is allowed or denied), the following test is not performed. Create a new file: the user ID of the new file is set to the valid user ID of the process, and the group ID can be one of the following: the group ID of the new file can be a valid group ID of the process or a group ID of the directory in which it resides. (Linux ext2/3 can be set when mount) 4.umask, access, chmod, fchmod, chown, fchown, lchown system call: slightly. Note: in linux, only root can use the chown directive to change the user ID, but the group ID can be changed to a valid group ID of the process (provided the current process owns this file). 5.sticky bit: if this bit of an executable file is set, a copy of the body part (machine instruction part) of the program is still saved in the exchange area when the program is executed for the first time and ends, so that it can be loaded into the memory area more quickly the next time the program is executed. The swap area takes up contiguous disk space and can be thought of as contiguous files. And the body of a program is also continuously stored in the exchange area, compared with the general UNIX file system, the data blocks of the file are stored randomly. So for commonly used applications, it is common to set the sticky bit of the file in which they are located. But for most UNIX systems, virtual storage systems and fast file systems are no longer needed. By setting sticky bit on a directory, only users with write access to that directory can delete and rename files in the directory if they meet one of the following conditions: owning the file, owning the directory, or superuser. The directories / tmp and / var/spool/uucppublic are typical candidates for setting up sticky bit, and any user can create files in both directories. The permissions of any user to these two directories are usually both read and write. However, users cannot delete or rename files that belong to others, so the file mode of both directories is set to sticky bit. Reference documentation: Linux Programmer's Manual STAT (2) APUE
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.