Download Chapter 2 U N i X Standardization and Implementation 2.1 Introduction The standardization of U N i x and c programming languages has been done a lot. Although the u N i x application is relatively easy to transplant between different U N i X versions, the population of U N i x version of the 80s and the expansion between them cause many large users (such as the US government) to standardize them. This chapter will introduce a variety of standardization work, and then discuss the impact of these standards to the actual U N i x realization listed in this book. An important part of all standardized work is a description of each limit that must be defined for each implementation, so we will explain that these restrictions and a variety of ways to determine their values. 2.2 UNIX Standardization 2.2.1 ANSI C1 9 8 9 years later, C programming language A N S I standard x 3. 1 5 9 - 1 9 8 9 Get approval [ANSI 1989]. This standard has been adopted for international standard ISO / IEC 9899: 1990. A N S I is a US National Standard Society that is a non-profit organization consisting of manufacturers and users. In the United States, it is a national unpaid standard switching station that represents members of the United States in the International Standardization Organization (I S O). The intent of the ANSI C standard is to provide the portability of the C program, which makes it suitable for a large number of different operating systems, not just UN i X. This standard not only defines the syntax and semantics of the C programming language, but also defines its standard library [ANSI 1989 Chapter 4; Plauger 1992; Kernighan and Ritchie 1988] Appendix B]. Because many new U N i x systems (such as a few U N i x systems introduced by this book) provide library functions illustrated in the C standard, this library is important to us. The library can be divided into 1 5 districts according to each header file defined by this standard. The header files defined by the C standard definition in Table 2 - 1 are listed in Table 2 - 1, and the header files defined by the other two standards (P O S i x. 1 and x p g 3) described in the following sections. There are also headers supported by S V R 4 and 4. 3 B S D. This chapter will also perform the two U N i X implementations.
Table 2-1 Implementation of the header file standards for various standards and implementations ANSI CPOSIX. 1 xpg 3 SVR 4 4. 3 BSD
• • System Name (6. 8)
X P G 3 Volume 2 XSI System Interface and Headers defines an interface for systems similar to U N i x, which is developed on the basis of the IEEE STD.1003.1-1988 interface. X P G 3 contains some of the features that P O S i x. 1. For example, P O S i x. 1 does not have a function of X / O P e n, which can be used to display text messages in different languages in different languages. The X P G 3 interface uses the ANSI C draft instead of the final formal standard, some of the features included in the X P G 3 interface specification are no longer used. These issues are likely to be solved in the new version of the future X P g specification. (About XPG 4 is working, may be completed in 1 993.) 2.2.4 FIPSF IPS The meaning of FIPSF IPS is Federal Information Processing Standard, which is published by the US government, and by the United States. The government is used in the purchase of computer systems. F I P S 1 5 1 - 1 (1 98 9) Based on I E E ES T D. 1 0 0 3. 1 - 1 9 8 8 and ANSI C. FIPS 151-1 requires some options in P O S i x. 1. This F i P S is sometimes referred to as POSIX.1 FIPS. 2. The selection items required for the P O S i x. 1 required by F I P S are listed. The impact of POSIX.1 FIPS is: it requires either hope to sell P O S i x to the US government. 1 Computer system of computers should support certain options for P O S i x. 1. We will not treat POSIX.1 FIPS as another standard, because it is actually just a more stringent P O S i x. 1 standard. 2.3 Unix Implementation The above section describes three standards made by their independent organizations: ANSI C, IEEE POSIX and X / O P Chapter 2 U N i x Standardization and Implementation 1 9 Download x P G 3. However, the standard is just a specifications of the interface. How do these standards related to the real world? These standards are adopted by the manufacturer and then transition into specific implementation. In this book, we are interested in these standards and their specific implementation. Detailed history and relationship diagram of the U N i X tree is given in 1. 1 section of LE Ffler, 1. 1. All versions and variants of UNIX originate from the 6th edition (1 9 76) and 7th edition (1 979) (1 979) (1 979) (usually called V 6) on the PDP - 11 system And V7). These two versions are first widely used in the Bell Labs. From this tree, three branches have been developed: (a) AT & T branch, exported to system III and system V (called UNIX commercial version), (b) California University Berkeley branch, from now on exported 4 . x BSD implementation, (c) Unix research versions developed by the AT & T Bell Laboratory Research Center, from now on, from now 8, 9, and 1 0. 2.3.1 SVR4S VR 4 is a product of the AT & T UNIX system laboratory, which brings together the following systems: AT & T UNIX System V No. 3.2 (SVR 3. 2), Sun's S U NOS system, California University Berkeley's 4. 3 BSD and Microsoft's X Enix System (Xenix is developed on the basis of V7, and later uses a lot of system V's functionality). Sourcecodes were distributed in late 1989, and in 1990 began to provide end users.
SVR4 complies with the POSIX 1003.1 standard and X / Open XPG3 standards. AT & T also published system V interface definition (S V i d) [AT & T 1989]. S V i D 3rd edition illustrates the function of the U N i x system to reach S V R 4 quality requirements. Like P O S i x. 1, S V I D illustrates an interface instead of an implementation. For a specific implementation S V R4, you should look at its reference manual to understand its differences [AT & T 1990E]. S V R 4 contains the compatibility library of B S D [AT & T 1990C] provides functions and commands corresponding to 4. 3 B S D. However, some of these functions are different from the corresponding part of P O S i x, and all S V R 4 instances in this book use this compatible library. Only if you have some early applications, you don't want to change them, it is recommended to use this compatible library, and new applications should not use it. 2.3.2 4.3 BSDB S D is research and development and distribution of computer system research teams from the University of California. 4. 2 B S D came from 1 9 83 years, 4. 3 B S D was in 1 986 years. These two versions are running on the VA X miniature. The next version of the next version 4. 3 BS DTA Ho was released in 1 988, in a small machine called TA HoE (LE E FF LER et al. [1 9 8 9] illustrated 4.3bsd Ta Hoe Version). Thereafter, there are 4.3BSD RENO versions in 1 990, which supports many features of P O S i x. 1. The next major version 4. 4 B S D should be released in 1 9 92. Early B S D systems contain AT & T proprietary source code, which requires AT & T licenses. In order to obtain the source code of the B S D system, the U N i x license of AT & T is required. This situation is being changed. In recent years, the AT & T source code is being converted into non-AT & T source code, and there are many new features that are added to the BSD system from non-AT & T. . 1 989, Berkeley put many non-AT & T source packages in 4.3bsd TA H O e into B S D network software, 1. 0, and make it a public available software. Thereafter, there is a BSD network software 2. 0, it is exported from 4.3bsd reno, its purpose is to make most (if not all) 4. 4 BSD system is no longer limited by the AT & T license Then, all of its source code can be used for the public. As explained in the preface, the book uses the term 4. 3 b S D represents the B S D system, the system is located between the B S D network software 2. 0 and the upcoming 4. 4 B S D. U N i x development work in Berkeley is starting from P D P - 11, then transferred to the VA X miniature, and then transferred to the workstation. In the early 1990s, Berkeley was supported on a wide range of applications 8 0 3 8 6 personal computers to develop B S D version 2 0 u n i x Environment Advanced programming download book, resulting 3 8 6 B S D. This work is done by Bill Jolitz. Its related documentation has a series of articles on the 1 9 91st D R.dobb's Journal (one one). Many of the code appears in the B S D Network Software 2. 0. 2.4 The relationship between standards and implementations We have already mentioned the standards of any actual system. Although IEEE POSIX is committed to formulating standards in other desired aspects (for example, communication between network interfaces, processes, system management), these standards do not exist when writing this book. This book is set in the two actual U N i x systems: S V R 4 and 4. 3 B S D.
Because these two systems declared that it is based on P O S i x, we focus on the functionality required by P O S i x. 1 standard, but also points out the difference between the P O S i X and the specific implementation of the two systems. Therefore, S V R 4 or 4. 3 B S D unique features and routines are clearly marked. Since X P G 3 is a supercoming of P O S i x. 1, we will also describe the functionality that belongs to X P G 3, but does not belong to P O S i x. 1. It should be understood that both S V R 4 and 4. 3 B S D provide compatibility to their earlier version of the function (eg, S V R 3. 2 pair 4. 3 B S D). For example, S V R 4 provides support for non-blocking I / O (O _ N O N B L O C K) in P O S i X Specifications and Traditional System V Method (O _ N D E L AY). This book will only use the function of P O S i x. 1, but will also mention which non-standard function it is replaced. Similar to this, S V R 3. 2 and 4. 3 B S D provide a reliable signaling mechanism in some way, and this method is different from P O S i x. 1 standard. Chapter 1 0 will only explain the signal mechanism of P O S i x. 1. 2.5 Restrictions There are many magic numbers and constants that are defined by implementation, with many of which have been written in the program, or determined by specific techniques. Due to the efforts of a large number of standardized work, several portable methods are used to determine the limitations of these illusion and implementation. This is very helpful in the portability of the software. The following three types of functions are required: • Compile time selection (whether the system supports job control). • Compile time limit (what is the maximum of short integer). • Runtime limit (how much is the maximum number of file names). The first two, compile time selection and restrictions can be defined in the header file. The program can contain these header files when compiling. However, runtime limits require that the process calls a function to obtain such a limit value. In addition, some limitations may be fixed in a given implementation (so it can be defined in a header file), and in another implementation may be variable (there is a run time function call). An example of this type limit is the maximum number of characters of the file name. System V Only the file name is allowed to have 1 4 characters due to historical reasons, while Berkeley's system will increase this to 2 5 5. S V R 4 allows us to indicate each created file system is a system V file system or a B S D file system, while each system has different restrictions. This is an instance of runtime limits, and the maximum length of the file name relies on the file system where the file is located. For example, the file name length limit in the root file system may be 1 4 characters, and the file name length limit in some other file system may be 2 5 5 characters. In order to solve these problems, three restrictions are provided: (1) Edit Time Selection and Restrictions (header files). (2) Do not be related to the runtime limit associated with the file or directory. (3) Operation time limits associated with files or directories. What makes things more complicated is that if a specific runtime limit does not change on a given system, it can be static in a header file, but if not defined in the header file. In the application, the application will be chapter 2 UNIX Standardization and Implementation 2 1 Download One of the three conf functions (we will explain them soon) to determine its runtime value. 2.5.1 ANSI C Restriction All restrictions defined by ANSI C are compilation time limits. The C standard restrictions defined in File
Column 4 lists the values of the current system having a total length of 3 2 bits, and 2 of the complement indication method. Note that there is no minimum value for the data type without the symbol, which should be 0. One difference we will encounter is whether the system provides a character value with symbol (S i g n e d) or without symbol (U N S I g n e d). As can be seen from column 4 in Table 2 - 2, the particular system uses symbol characters. From the table, it can be seen that C H A r _ m i n is equal to S c H a r _ m i n, C H a r _ m a x is equal to S c H a r _ m a x. If the system uses without a symbolic character, C H a r _ m i n is equal to 0, C H a r _ m a x is equal to U C H a r _ m a x. In the header file , the maximum number of unique file names generated by the T M P n a m function. About this constant will be more described in 5. 1 3. Table 2-2
2 2 U N i x Environment Advanced programming Download which includes 3 3 limitations and constants, which are divided into the following eight categories: (1) unchanged minimum (1 3 constants in Table 2 - 3). (2) Unset value: s I z e _ m a x. (3) Running time cannot be increased: N g R o u p s _ m a x. (4) Runtime constant value (may be uncertain): arg_max, child_max, open_max, stream_m a x, t z n a m e _ m a x. (5) path name variable value (may be uncertain): link_max, max_canon, max_input, name_max, pat h _ m a x, and P i p e _ b u F. (6) Edit time symbol constant: _P o s i x _ s aved_ids, _posix_version and _ p o s i x _ j o b _C o N T R O L. (7) Perform time symbol constant: _posix_no_trunc, _posix_vdisable, and _p O s i x _c H o w n _ r e s T R i C T E D. (8) Constants that are no longer used: C L K _ T C K. In this 33 restrictions and constants, 1 5 must be defined, and the rest can be defined as a specific condition. In 2. 5. 4, when the Sysconf, PathConf, and F P A T H C O N f functions, we describe definable non-definition restrictions and constants (Articles 4-8). In Table 2 - 7, we summarize all limitations and constants. 1 3 constant minimal values are shown in Table 2 - 3. Table 2-3
In addition, _ p o s i x _ PAT H _ m a x minimum is 2 5 5 is too small, and the path name may exceed this limit. This means that these two constants cannot be used when editing _ p o s i x _ o p e n _ m a x and _ p o s i x _ Pat H _ m a x as array length. Each of Table 2 - 3 has a related implementation value, which is composed of the name of the name in Table 2 - 3 to delete the prefix _ P o s i x _ after. (These 1 3 implementations are 2 ~ 5 items listed in this section: unchanged value, running, unchette Unix standardization and implementation 2 3 download can increase, the runtime constant value, And pathname variable value.) The problem is that all this 1 3 implementations do not make sure to define in the
#include
Table 2-5 Restrictions on Sysconf, Pathconf and FPathConf and Name Parameter Limit Name Description Name Parameters Arg _ MAX, EXEC function parameters (bytes) _ SC _ arg _ ma Xc Hild _ max, every actual user ID Maximum process number _ sc _ child _ ma xclock ticks / second, such as clock, clock diameter _ SC _ CLK _ TC KN Groups _ max If the maximum number of IDs in each process _ SC _ ngroups _ ma Xo Pen _ MAX, the maximum number of records per process _ SC _ open _ ma XP ASS _ max, such as the maximum number of valid characters in the password _ SC _ pass _ ma Xs Tream _ max, such as the maximum standard I / O, every time every moment Most - such as _ sc _ stream _ max If the value is defined, the value must be the same as the maximum number of bytes in the same TZNAME _ MAX time zone name _ SC _ TZNAME _ MA X_ POSIX _ JOB _ Control If you specify whether to implement your job Control _ SC _ Job _ Contro L_ POSIX _ SAVED _ IDS If you specify whether to support save settings - User - ID and Save _ SC _ SAVED _ IDS Settings - Group - I D_ POSIX _ VERSION If you specify POSIX. 1 version SC _ VERSIO N_ XOpen _ Version, such as the XPG version (non-POSIX. 1) _ SC _ XOpen _ VERSIO NL INK _ MAX such as file connection number maximum _ PC _ link _ ma XM AX _ Canon is in a terminal specification input Queue's maximum number of bytes _ PC _ Max _ CANO NM AX _ INPUT such as terminal input queue available space bytes _ PC _ max _ invu TN AME _ max, such as file name (excluding NULL end compact) _ PC _ Name _ ma xp Ath _max Such as the maximum number of bytes in the relative path name (excluding NULL end compact) _ pc _ path _ ma XP IPE _ BUF, like atomic, write to a pipe, maximum number of bytes _ PC _ PIPE _ bu f_ POSIX _ Chown _ Restricted Indicates if you are restricted using Chown_ pc _ chown _ restrict D_ POSIX _ no _ trunc, if the path is long than Name _ max is generated error _ PC _ no _ trun c_ pOSIX _ vdisable if defined, terminal dedicated characters available This value prohibits _ PC _ vdisable we need to explain the different return values of these three functions more detailed. (1) If n a m e is not a suitable constant in the 3rd column of Table 2 - 5, all three functions return - 1, and standardize Chapter 2 U N i x and implement 2 5 Download E R R O R Set to e i n va L.
(2) 1 2 Name and NAM E_ PC _ PIPE _ BUF may or return the value of the variable (return value ≥o), or return -1, indicating that this value is not sure, this is not Change the value of Errno. (3) The return value of _ S c _ C L K _ T C K is a clock tick of each second to use the return value of the T i m e s function (see 8.15). (4) The return value of the _ S c_ V e R s I O n is indicated by 4 digits and 2 digits, respectively, respectively, respectively, the year and month respectively. This may be or 1 9 8 8 0 8 L or 1 9 9 0 0 9 L, or the value of this standard a later version. (5) The return value of the _ S c_ x o p e n _ v e R s I O N indicates the X P g version of this system, whose current value is 3. (6) _SC_JOB_CONTROL and _ S C_ S AV E D _ I D S is two optional functions. The corresponding function is not supported if S Y S Y C O N f returns -1 (without changing e r R N o). These two functions can also be determined from header files at compile. (7) If the return value of the _ P C_ C HO W N _ R E S R I C T E D and _ P C_ N O _ T R U N C is -1 (not changed ER R N o), it means that this function is not supported for the specified P A T H n M e or F I L E D e S. (8) If the return value of _ P C_ V D I S A B L E is - 1 (does not change E R R N o), this function is not supported by the specified P A T H n M e or F I L E D e s. If this feature is supported, the return value is a character value (see Table 11 - 6) that is forbidden to enter a particular terminal input character. Example Program 2 - 1 Used to print all of these restrictions and process a limit that is not defined. Program 2-1 Print All S Y S C O N F and P A T H C O N F Value 2 6 U N i X Environment Advanced Programming Download We include two constants, which have been added to P O S i x. 1, but not part of IEEE STD.1003.1-1988. Table 2 - 6 shows the sample output of the program 2 - 1 on several different systems. We can understand in 4. 1 4, the SVR4 S5 file system is a traditional system V file system that can be retrosted to V7. U f s is an implementation of S V R 4 of the Berkeley Express File System.
Table 2-6 Configuration restrictions Limit SUNOS 4.1.1s VR 44. 3 BS DS5 FileSys UFS Filesysa RG _ Max 1 048 576 5 120 5 120 20 480C Hild _ max 1 3 3 3 0 3 0 4 0 per second clock Tick 6 0 1 0 0 0 0 0 0 6 0N Groups _ max 1 6 1 6 1 6 1 6o Pen _ MAX 6 4 6 4 6 4 6 4_POSIX _ Job _ Control 1 1 1 1_ POSIX _ Saved _ IDS 1 1 1 Undefined _ POSIX _ VERSION 198 808 198 808 198 808 198 808M AX _ Canon 2 5 6 2 5 6 2 5 6 2 5 5M AX _ Input 2 5 6 5 1 2 5 1 2 2 5 5_ POSIX _ VDISABLE 0 0 0 2 5 5L INK _ MAX 32 767 1 000 1 000 32 767 Chapter 2 UNIX Standardization and Implementation 2 7 Download Argv [1], _PC_Chown_RESTRICTED); (Continued) Limit SUNOS 4.1.1s VR 44. 3 BS DS5 FileSys UFS FileSysn AME_Max 2 5 5 1 4 2 5 5 2 5 5P Ath_max 1 024 1 024 1 024 1 024P IPE_BUF 4 096 5 120 5 120 5 1 2_POSIX_N _ Trunc 1 Unefained 1 1_ POSIX _ Chown _ Restricted 1 Undefined Undefined 12.5.5 FIPS 151-1 Requirements FIPS 151-1 (we have mentioned in 2. 2. 4) Due to the following functions, it is stricter than POSIX. 1 standard: • Require the following POSIX. 1 optional function: _posix_Job_Control, _POSIX_SAVED_I DS, _POSIX_NO_TRUNC, _POSIX_CHOWN_RESTRICTED and _ P O S i x _ V D i S A B L E. • The minimum value of ngroups_max is 8. • Group I D of the newly created file or directory should be set to Group I D it in its directory (4. 6). • After some data has been transmitted, if R E A D or W R I TE is interrupted by a captured signal, these functions should return the number of bytes already transmitted (1 0. 5 Section will discuss the interrupted system call). • Login S h e l L should define environment variable H o M E and L O g n M E. Because the US government has purchased a lot of computer systems, most P O S i X manufacturers will support these increased F i P s requirements. 2.5.6 Summary Summary We have explained many restrictions and illusion, some of which must be included in the header file, some optionally in the header file, other can be determined at runtime. Table 2 - 7 summarizes all of these constants in alphabetical sequence and to get various methods for they. The running time name starting with _ S c _ is the parameter of the S Y s c o n F, with the name of the _ P c _ starting the P A T H C O N f and the F function parameters, if it has a minimum, it is also listed in it. Note that 1 3 P O S i x in Table 2 - 3 is shown unchanged minimum values in Table 2 - 7.
Table 2-7 Compile time and runtime limit summary compilation time constant name header file requirements No run time name minimum arg _ max
Optional _ SC _ Open _ MAX _ POSIX _ OPEN _M AX = 1 6P ASS _ Max
Requirements _ SC _ XOpen _ Versio N2.5.9 Undeterified Runtime Limits We have mentioned that some values in Table 2 - 7 may be undefined, these values are marked in the third column (Optional) The name is included in the name, or pipe _ buf. The problem we encountered is if these values are not defined in the header file The constant M a x Pat H L e n is the correct value, but there are many 4. 3 B S D application does not use it. P O s i x. 1 Try to use PAT H _ M a X value to help us, but if this value is uncertain, then it is still unheeditive. Program 2 - 2 is a full book that will use a function that dynamically allocates a memory for the path name. If constant PAT H _ M A x is defined in versions to provide constants as the upper limit _ n f i l E. Some procedures are directly set to 2 0.
We want to use POSIX. 1 Open _ max to determine this value to improve portability, but if this value is uncertain, there is still a problem if we use the following code #include If we only want to use P O s i x. 1 definition, then you can set the first line of the source file to: #define _posix_source 1 another function test macro is: _ _STDC_ _, which is automatically defined by complication of the ANSI C standard. This allows us to write an agent that ANSI C compiler and non-ANSI C compiler can compile. For example, a header file may be: #ifdef _ std c__void * myfunc (const char *, int); # els evphot); # Endif This can play the strength of ANSI C prototype function, pay attention to starting and The two consecutive underscons at the end are often printed into a long line (as in one of the above sample source code). 2.7 Basic System Data Type History, some UNIX variables have been associated with certain C data types, for example, the historical master, the secondary device number is stored in a 1 6-bit short integer, and 8 represent the main device number. The other 8 indicates the secondary device number. However, many larger systems need to use more than 2 5 6 values to represent their device number, so there is a need for different techniques. (Indeed, SVR 4 represents device number with 3 2 digits: 1 4 digits for primary device number, 1 8 digits for the secondary device number.) Header file Table 2-8 Basic System Data Type Type Description CADDR_T Memory Address (1 2. 9) Clock_ T Tissue Counter (Process Time) (1. 1 0) COMP_T Compressed Clock Tick (8. 1 3 section) DEV _ T device number (main sum) (4. 2 3) FD _ set file descriptor set (1 2. 5. 1) fpos _ T file location (5. 1 0) GID _ T numeric group I di NO _ Ti node number (4. 1 4) MODE _ T file type, file creation mode (4. 5) N 1 ink _ T directory item connection count (4. 1 0) OFF _ T file length and displacement (with symbol) (Lseek, 3.6) PID _ T process ID and process group ID (with symbol) (8. 2 and 9. 4) PTRDIFF _ T two pointers Results (with symbol) R 1 IM _ T resource limit (7.11) SIG _ Atomic _ T can access data type (1 0. 1 5) SIGSET _ T signal set (1 0. 11 section) SIZE _ T object (such as string) length (without symbol) (3. 7) SSIZE _ T Return to byte count (with symbol) (READ, WRITE, 3.7) Time _ T The second counter (1. 1 0) UID _ T Value User I DW Char _ T can indicate that all different character codes define these data types, no longer need to consider the system when compiling Differential implementation details, in this book involve these data types, we will explain why they use them. 2.8 The conflict between the standards is considerable, and these different standards are quite good. But we also pay attention to the difference between them, especially the difference between the ANSI C standard and P O S i x. 1. (Because XPG 3 is an older is being revised standard, FIPS is a more stringent POSIX. 1.) ANSI C defines a function clock, which returns the CPU time used by the process, the return value is a clock _ T type value. In order to convert this value into seconds, divide it in the