arch/um/drivers/cow_user.c
Source file repositories/reference/linux-study-clean/arch/um/drivers/cow_user.c
File Facts
- System
- Linux kernel
- Corpus path
arch/um/drivers/cow_user.c- Extension
.c- Size
- 12528 bytes
- Lines
- 451
- Domain
- Architecture Layer
- Bucket
- arch/um
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
unistd.herrno.hstring.harpa/inet.hendian.hcow.hcow_sys.h
Detected Declarations
struct cow_header_v1struct cow_header_v2struct cow_header_v3struct cow_header_v3_brokenfunction cow_sizesfunction absolutizefunction write_cow_headerfunction file_readerfunction read_cow_headerfunction init_cow_file
Annotated Snippet
struct cow_header_v1 {
__s32 magic;
__s32 version;
char backing_file[PATH_LEN_V1];
time32_t mtime;
__u64 size;
__s32 sectorsize;
} __attribute__((packed));
/*
* Define PATH_LEN_V3 as the usual value of MAXPATHLEN, just hard-code it in
* case other systems have different values for MAXPATHLEN.
*
* The same must hold for V2 - we want file format compatibility, not anything
* else.
*/
#define PATH_LEN_V3 4096
#define PATH_LEN_V2 PATH_LEN_V3
struct cow_header_v2 {
__u32 magic;
__u32 version;
char backing_file[PATH_LEN_V2];
time32_t mtime;
__u64 size;
__s32 sectorsize;
} __attribute__((packed));
/*
* Changes from V2 -
* PATH_LEN_V3 as described above
* Explicitly specify field bit lengths for systems with different
* lengths for the usual C types. Not sure whether char or
* time_t should be changed, this can be changed later without
* breaking compatibility
* Add alignment field so that different alignments can be used for the
* bitmap and data
* Add cow_format field to allow for the possibility of different ways
* of specifying the COW blocks. For now, the only value is 0,
* for the traditional COW bitmap.
* Move the backing_file field to the end of the header. This allows
* for the possibility of expanding it into the padding required
* by the bitmap alignment.
* The bitmap and data portions of the file will be aligned as specified
* by the alignment field. This is to allow COW files to be
* put on devices with restrictions on access alignments, such as
* /dev/raw, with a 512 byte alignment restriction. This also
* allows the data to be more aligned more strictly than on
* sector boundaries. This is needed for ubd-mmap, which needs
* the data to be page aligned.
* Fixed (finally!) the rounding bug
*/
/*
* Until Dec2005, __attribute__((packed)) was left out from the below
* definition, leading on 64-bit systems to 4 bytes of padding after mtime, to
* align size to 8-byte alignment. This shifted all fields above (no padding
* was present on 32-bit, no other padding was added).
*
* However, this _can be detected_: it means that cow_format (always 0 until
* now) is shifted onto the first 4 bytes of backing_file, where it is otherwise
* impossible to find 4 zeros. -bb */
struct cow_header_v3 {
__u32 magic;
__u32 version;
__u32 mtime;
__u64 size;
__u32 sectorsize;
__u32 alignment;
__u32 cow_format;
char backing_file[PATH_LEN_V3];
} __attribute__((packed));
/* This is the broken layout used by some 64-bit binaries. */
struct cow_header_v3_broken {
__u32 magic;
__u32 version;
__s64 mtime;
__u64 size;
__u32 sectorsize;
__u32 alignment;
__u32 cow_format;
char backing_file[PATH_LEN_V3];
};
/* COW format definitions - for now, we have only the usual COW bitmap */
#define COW_BITMAP 0
union cow_header {
Annotation
- Immediate include surface: `unistd.h`, `errno.h`, `string.h`, `arpa/inet.h`, `endian.h`, `cow.h`, `cow_sys.h`.
- Detected declarations: `struct cow_header_v1`, `struct cow_header_v2`, `struct cow_header_v3`, `struct cow_header_v3_broken`, `function cow_sizes`, `function absolutize`, `function write_cow_header`, `function file_reader`, `function read_cow_header`, `function init_cow_file`.
- Atlas domain: Architecture Layer / arch/um.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.