Next Previous Contents

9.3 Linux swap manager internals

Any Linux swap partition unfortunately must be created explicitely for the platform where it will be used. Currently this implementation autodetects the values (like endianity) needed for mkfs during its compilation, existing partitions are detected platform independently. Please don't rely on the ordering of value of each of the parameter - these are compilation-type dependent just to have the default value always as the first choice.

Default parameters autodetection descriptions

header version

Default Version 1 if possible is autodected by the run time code stored in autoheader() function called from swap_fs_mkfs(). The value is dependent on pagesize, warning is generated depending on currently running kernel version.

endianity

Compilation-time detected by G_BYTE_ORDER dependant #ifdef in inits.c, set by glib library.

pagesize

Compilation-time detected by SWAP_PAGESIZE_* macros from params.h.m4 source, currently uses system offered PAGE_SIZE macro.

Swap partition values autodetection descriptions

When we encounter some already created partition, we have to guess and/or detect its parameters as it can be principially created on foreign platform. All these detections are done in swap_read_super.

pagesize

We try to recognize swap partition header from the smaller (4096) to larger (8192) pagesize. During reuse of the partition, the smaller one gets certainly overwritten by larger pagesize, in the opposite direction we could falsely detected old (and not used) larger header.

header version

Version is easily detectable by its "SWAP-SPACE" (ver. 1) or "SWAPSPACE2" (ver. 2) magic string. Please note that these strings don't follow the endianity in any way.

endianity

This detection depends on the (well) detected header version:

Version 1

This is the only a bit nonreliable swap manager part. We currently believe that swap page (in pagesize counting) #24 is not marked as bad. Swap page #0 is always non-used, there must be bit 0. When we find also bit 0 on the position for swap page #24, we just give warning to the user and guess the endianity as the endianity of the platform where is Surprise currently running.

Version 2

Easy task, we currently support (only exists) "swapinfo.version" value 1 given as "unsigned int", endianity is determinable by swapping the bytes.

Header block building

We build the block #0 (starting in swap_fs_mkfs) in endianity of our current platform, badblocks (in Version 2 header) are not sorted. When badblocks count is exceeded during the creation (for Version 2 header), we will refuse (with error return) to continue the operation. The proper endianity is swapped (together with possible badblocks sorting) just before writing of the block in swap_fs_fsdone.

File writing

As we are general filesystem of Surprise project, a foolish user may want to for example convert existing filesystem to Linux swap type. We are refusing to create any files or directiories in swap_fs_check.


Next Previous Contents