Path: utzoo!mnetor!uunet!husc6!bbn!gatech!rebel!didsgn!jlc From: jlc@didsgn.UUCP (jlc) Newsgroups: comp.os.misc Subject: Re: Contiguous files; extent based file systems Message-ID: <189@didsgn.UUCP> Date: 18 Dec 87 03:24:14 GMT References: <561@amethyst.ma.arizona.edu> <3228@tut.cis.ohio-state.edu> <9828@mimsy.UUCP> Distribution: na Organization: Digital Design Inc., Atlanta, GA USA. Lines: 174 Summary: An example of contiguous file implementation on a UNIX like OS In article <9828@mimsy.UUCP>, chris@mimsy.UUCP (Chris Torek) writes: > Completely contiguous files are hard to build. You must either > declare their size initially or else constantly rearrange disk > blocks. Contiguous files tend to be fast to access, but if your > OS has a heavy multiuser load, it will often be using several files > at once, destroying the effect created by the contiguous files. > > Extent based file systems are usually implemented with a small > maximum number of extents. This means that the file size must > (implicitly, by extent size) be declared in advance, if the file > may be large. If you are interested in contiguous file, here is an example of how it is done on UN/V which is a real version of system V designed by Charles River Data. I have personnaly used this implementation for real time and image processing software and it very very fast. (All the following is copyrighted by Charles River Data System, etc etc....) The following is extracted out of the open() subroutine manual entry NAME open() opens a file for reading or writing FORMAT #include int open (path, oflag [, omodes [ , minext, maxext ] ]) char *path; int oflag; int omodes, minext, maxext; DESCRIPTION open() opens a file descriptor for the named file and sets the file status flags according to the value of o_flag. path points to a pathname naming a file. o_flag values are composed by ORing values from the following, which are declared in (only one from the first three): O_RDONLY Open for reading only. O_WRONLY Open for writing only. O_RDWR Open for reading and writing. { some verbiage cut here } O_CONTIG Force a contiguous file (a file which is allocated disk space in large extents). If the file is truncated or created by this open, it becomes a contiguous file with an initial allocated extent of extend_size bytes. Otherwise, the file must already be contiguous and have extent_size bytes available for growth (a new extent is allocated if necessary) or the open will fail. If O_CONTIG is not specified, contiguous files can be opened just like any other file. The following is extracted out of the command manual: contig UNOS COMMANDS MANUAL contig NAME contig make a contiguous file FORMAT contig [extent=range] [alloc=rangelist] [-freeze] [-truncate] file ... DESCRIPTION contig makes a contiguous file (a file which owns disk space in large extents rather than in single blocks). If the file named already exists, it must be truncated in order to become contiguous; this command saves the old contents of the file (in a file in /tmp or in main memory, depending on size) and writes it back later. Contiguous files have two parameters, min and max, which govern allocation of disk space as the file grows. Whenever a write past the end of the space currently used by the file is done, the file system allocates a new extent of at least min blocks and at most max blocks (or at most large enough to contain the write, if that's larger). The write fails if there is no free extent of at least min blocks. There are system default values for min and max, which are used if the file's min and max are -1. All allocation is inhibited whn the max value is 0. OPTIONS extent=range Sets the file's min and max allocation parameters, but does not cause any space to be allocated. range is a number (sets both min and max) or a pair of numbers separated by '-' (e.g. extent=1024-4096 sets min to 1024 and max to 4096). The number(s) can end in 'b' or 'k' to indicate units of blocks (times 512) and kilobytes (times 1024). This multiplier will be applied to both min and max even if only max specifies it, so extent=10-20b means extent=10b-20b. If extent= is omitted, min and max are set to -1, which causes the system default values to be used. alloc=rangelist Allocates one or more extents of disk space to the file. rangelist is a range (as above) or a list of ranges separated by ',' (e.g., alloc=10b,10b causes the file to have two ten block extents). If alloc= is omitted, contig tries to get a single extent to hold the current file contents (if any) by assuming alloc=512-filesize. -freeze Marks the file to prevent any further allocation, by setting exten to 0. Any attempt to write past the end of the allocated space will fail. Since the filesize may indicate the file ends anywhere in the last extent, it is still possible to extend the file up to the allocation limit. The contig command always unfreezes files if -freeze is not specified. -freeze and extent= are mutually exclusive. -truncate Discards any current file contents and disk space. Truncating a file requires write access to it. EXAMPLES To turn all commands into contiguous files for speed: @>contig /bin/* /sys/* /usr/bin/* To prevent additional allocation of space to a contiguous file: @>contig -freeze able To allocate 5 1000 block extents: @>contig -truncate alloc=1000b,1000b,1000b,1000b,1000b able To cause subsequent allocations to be 300 blocks while allowing allocations down to 100 blocks to be acceptable if 300 blocks is not available: @>contig extent=100-300b able NOTES -freeze does not prevent the file from being truncated, for example by '> filename' in the shell, or the create() subroutine. If a frozen file is truncated it will be frozen at zero length, so no write to it can succeed. Hope this of interest.... ___ _ __ _ ( > _// / ) / _/_ // __/_/> __. ____ --- / . . _. / /_ __. / _ // __. o ____ / / (__(_/|_/ / <__ /___ (_/_(__ (__/ / /_(_/|_<__