📄 zlibc.texi
字号:
this file is scanned later. The @var{criterion} parameter may be omittedif it can be deduced from the @var{name}. In that case, the followingheuristics are used:@itemize @bullet@item@var{Name}s beginning with a dot are considered as @code{suffix}.@item@var{Name}s beginning with a slash, but not ending with a slash areconsidered as @var{filename}.@item@var{Name}s beginning and ending with a slash are considered as@code{subdirectory}.@itemA missing @var{name} is considered as @code{default}.@itemAll the other @var{name}s are considered as @code{basename}.@end itemize@c With the exception of the @code{filesystem} criterion, these selection@c criteria are applied on the filename @emph{as it was provided by the@c user program}. Names might not match if they are accessed by a@c different path than the one specified in the config file. This is@c especially true for criteria using the directory part of a@c filename. Whenever possible, use the @code{suffix}, @code{basename} or@code{filesystem} criteria, because these tend to be more predictable.@node Mode, , Criteria, Class section@subsubsection ModeThe @var{mode} describes the behavior of zlibc in certainsituations. These are:@enumerate@itemWhat to do when a file is accessed in readonly mode.@itemWhat to do when a user program tries to append data to an existing file.@itemWhat to do when a user program tries to create a new file.@itemWhat to do when a user program tries to access an existing file and noneof the preceding situations apply (@pxref{Write}).@itemWhether to show the size of the uncompressed file or the size of thecompressed file as a response to stat (@pxref{Size}).@end enumerateThe mode for each off these 5 situations has to be described separately.For each of these 5 situations, the scan through the class descriptionis done until the reaction of zlibc for this situation is defined.@menu* Readonly:: Behavior for programs wanting to only read files* Append:: - for programs wanting to add more data to existing files* Creation:: - for programs wanting to create new files* Write:: - for programs wanting to apply other modifications to files* Size:: - for programs wanting to know the size of a file@end menu@node Readonly, Append, Mode, Mode@unnumberedsubsubsec Reaction to a readonly requestThe reaction to a @code{readonly} request may be one of the following:@table @code@item show-pipeThe uncompressed data file is sent to the user program using apipe. This consumes very few resources, and it allows the decompressionto run in paralell with the user process, but it has the disadvantagethat the user program cannot use lseek. To warn the user program ofthis, the data file is shown as a named pipe (FIFO) when it isstat'ed.@item use-tmp-fileThis is the default setting. The data is uncompressed and put into atemporary file. The user programs then reads its data from the temporaryfile. This has the advantage that the user program may lseek, and thedisadvantage that more disk space is consumed, while the programming isaccessing the file.@item hide-pipeThe data is sent through a pipe, but the file is shown as a regular file("hidden") to the user program when it stats it. This might be neededfor programs which are picky about a file type, but who actually don'tneed lseek.@item leave-compressedThe virtual (uncompressed) file is shown as non-existent to stat, andreaddir shows the physical (compressed) file. For certain programs, thisis enough to disable zlibc on a file per file basis. This is useful, forexample, to make emacs use its own compression support (crypt.el)instead of zlibc. Crypt.el is able to compress files when writing themback, whereas zlibc isn't able to do so. The @code{leave-compressed}doesn't work correctly with the @code{directory} and @code{subdirectory}criteria. Use the @code{filesystem} criterion instead.@item dir-leave-compressedThe virtual (uncompressed) file is shown to stat, but readdir shows thephysical (compressed) file. This is useful to tell zlibc that we preferworking on the physical file, but without making access to the virtualfile impossible. The @code{dir-leave-compressed} doesn't work with the@code{dir} and @code{subdir} criteria. Use the @code{filesystem}criterion instead.@end table@node Append, Creation, Readonly, Mode@unnumberedsubsubsec Reaction to an append requestThe reaction to an @code{append} request may be one of the following:@table @code@item append-compressedWhen a user program tries to append data to a non-existant file, but thecorresponding compressed file exists, zlibc translates this request intoappending the compressed data to the compressed file.@strong{WARNING-1:}This works with gzip, and might not work with other (un)compressors!This relies on gzip's feature to consider a concatenation of compressedfiles as a compression of concatenated files.@strong{WARNING-2:}This is only reliable if you can guarantee that the file is not accessedby some other program while the first one has it still open, or that itwon't be opened again (even by the same program) shortly after it hasbeen closed. Delays longer than a second should be ok. Don't enable@code{append-compressed} if you expect the file to be written to byseveral programs at once.@item no-append-compressedDon't append to a compressed file (the user program will get a file notfound error). This is the default behavior.@end table@node Creation, Write, Append, Mode@unnumberedsubsubsec Reaction to a file creation requestThe reaction to a @code{create} request may be one of the following:@table @code@item create-compressedWhen a user program tries to create a new file whose name matches thepattern, zlibc translates this request into creating a compressedfile. A file is considered to be created, if the @code{O_TRUNC} flag isset, or if both @code{O_CREAT} and @code{O_EXCL} are set. This onlyapplies to files opened write-only.@strong{WARNING-1:}This is only reliable if you can guarantee that the newlycreated file is not accessed by some other program while the first onehas it still open, or that it won't be opened again (even by the sameprogram) shortly after it has been closed.@strong{WARNING-2:}This should not be used if you expect the program to seek in thisfile.@item no-create-compressedNewly created files are created uncompressed. This is the default.@end table@node Write, Size, Creation, Mode@unnumberedsubsubsec Other write requestsThe reaction to other @code{write} requests may be one of the following:@table @code@item uncompress-before-writeWhen a user program tries to write to a non-existing file, and when acompressed file with a corresponding name exists, this file isuncompressed in place (i.e. having the same name, but without the .gzextension)@strong{WARNING-1:}This is only safe when you can guarantee that the file is not opened byseveral programs at once. However, once the call to the open functionhas returned, other programs may open this file safely. If a secondprogram tries to open the file during the open call of the first, thissecond program gets a permission error.@strong{WARNING-2:}When using this option, be careful when opening files belonging toanother user, or files living in a directory where you have no writeaccess to. Using this option in a directory without write access willresult in a permission error. Using this option in a directory where youdo have write access will change the ownership of the file to you, evenif it belonged to another user initially.@item no-uncompress-before-writeCompressed files are not uncompressed before writing to them, and zlibcreturns a "file not found" error. This is the default.@end tableIf several of these options apply for the same file,@code{create-compressed} has priority over @code{append-compressed}which has priority over @code{uncompress-before-write}.@node Size, , Write, Mode@unnumberedsubsubsec Size shown for compressed files@cindex find@cindex size of compressed files@cindex slowness (of find due to reading the size)@vindex show-compressed-size@cindex ftpfs@cindex ls slowness (on an ftpfs filesystem)@cindex slowness (of ls, on an ftpfs filesystem)@cindex hanging (of ls, on an ftpfs filesystem)When an application calls @code{stat} to fetch the attributes of a file(such as its permissions, size, type, etc.), zlibc stats thecorresponding compressed file instead. After doing so, zlibc has toadjust some of the values returned by stat, such as the type and thesize. The type has to be adjusted for those files that should be shownas pipes. The size has to be adjusted because user programs are usuallyinterested in the amount of data that they can actually read from thefile (i.e. the size of the uncompressed file) rather than the size ofthe physical file (i.e. the size of the compressed file). However, inorder to find out the size of the uncompressed file, zlibc has to readsome data of the file, which may impact performance in situations wheremany files are stat'ed. This is for instance the case for @code{find},or for @code{ls} on an @code{ftpfs} filesystem. The following twobehaviors of the stat call may be specified:@table @code@item show-compressed-sizeStat returns the size of the compressed file. This is less useful forthe application, but more efficient. If you mount any @code{ftpfs}filesystems, you may switch on @code{show-compressed-size} just for thatfilesystem by using the @code{filesystem} criterion (@pxref{Criteria}).@item show-uncompressed-sizeStat returns the size of the uncompressed file. This is more useful forthe application, but less efficient. This is the default behavior.@end table@ignore@subsection See alsozlibc(3)@end ignore@c zlibc.3end-skip@c zlibc-conf.5skip@node Compiled-in defaults, Compile-time configuration, Configuration files, Customization@section Compiled-in defaultsIt is possible to operate zlibc entirely without configuration files.In this case, it uses the @emph{compiled-in defaults}. These aregenerated at compile-time from the @file{zlibrc.sample} file. This filehas the same syntax as the configuration files described above(@pxref{Configuration files}). If you want to change the compiled-indefaults of zlibc, edit that file, and remake.@node Compile-time configuration, , Compiled-in defaults, Customization@section Compile-time configuration via GNU autoconf@cindex configure options@cindex temporary file directory@cindex directory for temporary files@cindex compile-time configurationBefore it can be compiled, zlibc must be configured using the GNUautoconf script @code{./configure}. In most circumstances, running@code{./configure} without any parameters is enough. However, you maycustomize zlibc using various options to @code{./configure}. Thefollowing options are supported:@table @code@item --prefix @var{directory}Prefix used for any directories used by zlibc. By default, this is@file{/usr/local}. Zlibc is installed in @file{$prefix/lib}, looks forits system wide configuration file in @file{$prefix/etc}. Man pages areinstalled in @file{$prefix/man}, info pages in @file{$prefix/info} etc.On Linux, if you use zlibc via @file{/etc/ld.so.preload}, you should use@file{/} as the prefix instead of the default @file{$prefix/lib}.@item --sysconfdir @var{directory}Directory containing the system-wide configuration file@file{zlibc.conf}. By default, this is derived from @code{prefix} (seeabove).@item --disable-runtime-confDisables run time configuration via environmental variables and via theconfiguration files. This may be needed in hyper secure environments.@item --disable-env-confDisables run time configuration via environmental variables@item --disable-have-procTells zlibc not to use the /proc filesystem to find out the commandlineof the programs for which it runs, even if a working /proc is detected.@item --disable-have-procTells zlibc to use the /proc filesystem to find out the commandline ofthe programs for which it runs, even if no working /proc is detected.@item --with-compr-ext=@var{extension}Uses @var{extension} as the filename extension of compressed files. Bydefault, is @code{.gz}@item --with-extlen=@var{length}Allows to configure compressed filename extensions with at most@var{length} character via runtime configuration. By default is 5.@item --with-tmpdir=@var{directory}Uses @var{directory} to store the uncompressed files. By default is@code{/tmp}. @item --with-uncompressor=@var{uncompressor-command-line}Defines how the program for uncompressing files should be invoked. Thiscommand should read the compressed file from stdin, and output theuncompressed data to stdout By default is @code{gzip -dc}.@end tableIn addition to the above-listed options, the standard GNU autoconfoptions apply. Type @code{./configure --help} to get a complete list ofthese.@ignore@subsection See alsozlibc.conf(5)@end ignore@c zlibc-conf.5end-skip@c MANskip@node Porting zlibc, Variable Index, Customization, Top@chapter Porting zlibcZlibc has been tested on three variants of Unix so far: Linux, SunOs,Solaris. On all three platforms, zlibc has been compiled using GNU makeand gcc. However, porting it to other platforms should bestraightforward as long as they verify both of the following conditions:@enumerate@itemThe target platform should have shared library support. The defaultMakefile links zlibc by supplying the flags @code{-nostdlib -shared} togcc in addition to the usual @code{CFLAGS}. If your target platformneeds different flags to make shared libraries, change the definition ofthe variable @code{SHAREDCFLAGS} in the Makefile.@itemThe target platform should supply a way to perform system callsdirectly without going through the library functions. Indeed, this isneeded because we are redefining the library functions and thus thedefault functions become unavailable.Usually direct syscalls done by calling the syscall function. Forinstance, in order to perform @code{open("test", O_RDONLY)} directly,@code{sycall(SYS_open, "test", O_RDONLY)} is called.If your target platform uses a different way to perform directsystem calls, you need to supply different definitions for the real_xxxfunctions in direct_sys.h. This is the case for AIX.@itemThe target platform should provide a way to instruct the dynamic linkerto preload programs with extra object files not present in the sharedlibrary. Any symbols defined in that object file override equivalentsymbols from libc. Usually this is done by pointing the@code{LD_PRELOAD} variable to the object file to be used.Unfortunately, I have found no way to achieve this on AIX. Any ideasabout how to do this are welcome.@end enumerateMany platforms, including Solaris, provide several aliases for theirsyscall stubs. It would be interesting to leave one of them alone, anduse it as a "direct syscall" stub, but unfortunately, it turns out thatin sometimes both stubs are used by the library! Thus, what would be anadvantage, becomes actually a disadvantage, because we will need tooverride these aliases in addition to the canonical names. This is donein altnames.c. Change it as needed. In order to know the names ofthese aliases, try the following command: @code{nm /lib/libc.so | greplstat}. This lists any library symbols with @code{unlink} in theirname, which could be aliases.If you have successfully ported zlibc to a new platform, could you dropme a note, so that I can include support for that platform in my nextrelease. Thanks@node Variable Index, Concept Index, Porting zlibc, Top@unnumbered Variable index@printindex vr@node Concept Index, , Variable Index, Top@unnumbered Concept index@printindex cp@contents@c MANend-skip@bye
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -