aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / native / disk / disk_file.h
| 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * disk_file.h -- hosted file-backed disk backend for tests (libc). Never part |
| 19 | * of a freestanding image. |
| 20 | * |
| 21 | * Power-cut injection: disk_file_arm_cut(f, n) lets exactly n more logical |
| 22 | * blocks of writes reach the file (in order, block by block); every later |
| 23 | * write or flush returns DISK_EPOWER and changes nothing, as if power was |
| 24 | * lost after block n. disk_file_disarm restores normal operation (the |
| 25 | * "reboot"). Counters record writes and flushes for tests. |
| 26 | */ |
| 27 | #ifndef AIENOS_DISK_FILE_H |
| 28 | #define AIENOS_DISK_FILE_H |
| 29 | |
| 30 | #include "disk.h" |
| 31 | |
| 32 | typedef struct { |
| 33 | int fd; |
| 34 | uint32_t block_size; |
| 35 | uint64_t block_count; |
| 36 | int cut_armed; |
| 37 | uint64_t cut_remaining; /* blocks still allowed through */ |
| 38 | uint64_t blocks_written, flushes; |
| 39 | } disk_file; |
| 40 | |
| 41 | /* Open (create == 1: create/truncate to block_count blocks of zeros) a file |
| 42 | * as a device of block_size (512 or 4096). Fills *dev. */ |
| 43 | int disk_file_open(disk_file *f, disk_dev *dev, const char *path, uint32_t block_size, |
| 44 | uint64_t block_count, int create); |
| 45 | void disk_file_close(disk_file *f); |
| 46 | void disk_file_arm_cut(disk_file *f, uint64_t blocks_allowed); |
| 47 | void disk_file_disarm(disk_file *f); |
| 48 | |
| 49 | #endif /* AIENOS_DISK_FILE_H */ |