1f9f848faSopenharmony_ci/*- 2f9f848faSopenharmony_ci * SPDX-License-Identifier: BSD-2-Clause 3f9f848faSopenharmony_ci * 4f9f848faSopenharmony_ci * Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank 5f9f848faSopenharmony_ci * Copyright (c) 1995 Martin Husemann 6f9f848faSopenharmony_ci * 7f9f848faSopenharmony_ci * Redistribution and use in source and binary forms, with or without 8f9f848faSopenharmony_ci * modification, are permitted provided that the following conditions 9f9f848faSopenharmony_ci * are met: 10f9f848faSopenharmony_ci * 1. Redistributions of source code must retain the above copyright 11f9f848faSopenharmony_ci * notice, this list of conditions and the following disclaimer. 12f9f848faSopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright 13f9f848faSopenharmony_ci * notice, this list of conditions and the following disclaimer in the 14f9f848faSopenharmony_ci * documentation and/or other materials provided with the distribution. 15f9f848faSopenharmony_ci * 16f9f848faSopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 17f9f848faSopenharmony_ci * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18f9f848faSopenharmony_ci * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19f9f848faSopenharmony_ci * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20f9f848faSopenharmony_ci * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21f9f848faSopenharmony_ci * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22f9f848faSopenharmony_ci * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23f9f848faSopenharmony_ci * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24f9f848faSopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25f9f848faSopenharmony_ci * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26f9f848faSopenharmony_ci * $NetBSD: ext.h,v 1.6 2000/04/25 23:02:51 jdolecek Exp $ 27f9f848faSopenharmony_ci */ 28f9f848faSopenharmony_ci 29f9f848faSopenharmony_ci#ifndef EXT_H 30f9f848faSopenharmony_ci#define EXT_H 31f9f848faSopenharmony_ci 32f9f848faSopenharmony_ci#include <sys/types.h> 33f9f848faSopenharmony_ci 34f9f848faSopenharmony_ci#include <stdbool.h> 35f9f848faSopenharmony_ci 36f9f848faSopenharmony_ci#include "dosfs.h" 37f9f848faSopenharmony_ci 38f9f848faSopenharmony_ci#define LOSTDIR "LOST.DIR" 39f9f848faSopenharmony_ci 40f9f848faSopenharmony_ci/* 41f9f848faSopenharmony_ci * Options: 42f9f848faSopenharmony_ci */ 43f9f848faSopenharmony_ciextern int alwaysno; /* assume "no" for all questions */ 44f9f848faSopenharmony_ciextern int alwaysyes; /* assume "yes" for all questions */ 45f9f848faSopenharmony_ciextern int preen; /* we are preening */ 46f9f848faSopenharmony_ciextern int rdonly; /* device is opened read only (supersedes above) */ 47f9f848faSopenharmony_ciextern int skipclean; /* skip clean file systems if preening */ 48f9f848faSopenharmony_ciextern int allow_mmap; /* allow the use of mmap() */ 49f9f848faSopenharmony_ci 50f9f848faSopenharmony_ci/* 51f9f848faSopenharmony_ci * function declarations 52f9f848faSopenharmony_ci */ 53f9f848faSopenharmony_ciint ask(int, const char *, ...) __printflike(2, 3); 54f9f848faSopenharmony_ci 55f9f848faSopenharmony_ci/* 56f9f848faSopenharmony_ci * Check the dirty flag. If the file system is clean, then return 1. 57f9f848faSopenharmony_ci * Otherwise, return 0 (this includes the case of FAT12 file systems -- 58f9f848faSopenharmony_ci * they have no dirty flag, so they must be assumed to be unclean). 59f9f848faSopenharmony_ci */ 60f9f848faSopenharmony_ciint checkdirty(int, struct bootblock *); 61f9f848faSopenharmony_ci 62f9f848faSopenharmony_ci/* 63f9f848faSopenharmony_ci * Check file system given as arg 64f9f848faSopenharmony_ci */ 65f9f848faSopenharmony_ciint checkfilesys(const char *); 66f9f848faSopenharmony_ci 67f9f848faSopenharmony_ci/* 68f9f848faSopenharmony_ci * Return values of various functions 69f9f848faSopenharmony_ci */ 70f9f848faSopenharmony_ci#define FSOK 0 /* Check was OK */ 71f9f848faSopenharmony_ci#define FSBOOTMOD 1 /* Boot block was modified */ 72f9f848faSopenharmony_ci#define FSDIRMOD 2 /* Some directory was modified */ 73f9f848faSopenharmony_ci#define FSFATMOD 4 /* The FAT was modified */ 74f9f848faSopenharmony_ci#define FSERROR 8 /* Some unrecovered error remains */ 75f9f848faSopenharmony_ci#define FSFATAL 16 /* Some unrecoverable error occurred */ 76f9f848faSopenharmony_ci#define FSDIRTY 32 /* File system is dirty */ 77f9f848faSopenharmony_ci 78f9f848faSopenharmony_ci/* 79f9f848faSopenharmony_ci * read a boot block in a machine independent fashion and translate 80f9f848faSopenharmony_ci * it into our struct bootblock. 81f9f848faSopenharmony_ci */ 82f9f848faSopenharmony_ciint readboot(int, struct bootblock *); 83f9f848faSopenharmony_ci 84f9f848faSopenharmony_ci/* 85f9f848faSopenharmony_ci * Correct the FSInfo block. 86f9f848faSopenharmony_ci */ 87f9f848faSopenharmony_ciint writefsinfo(int, struct bootblock *); 88f9f848faSopenharmony_ci 89f9f848faSopenharmony_ci/* Opaque type */ 90f9f848faSopenharmony_cistruct fat_descriptor; 91f9f848faSopenharmony_ci 92f9f848faSopenharmony_ciint cleardirty(struct fat_descriptor *); 93f9f848faSopenharmony_ci 94f9f848faSopenharmony_civoid fat_clear_cl_head(struct fat_descriptor *, cl_t); 95f9f848faSopenharmony_cibool fat_is_cl_head(struct fat_descriptor *, cl_t); 96f9f848faSopenharmony_ci 97f9f848faSopenharmony_cicl_t fat_get_cl_next(struct fat_descriptor *, cl_t); 98f9f848faSopenharmony_ci 99f9f848faSopenharmony_ciint fat_set_cl_next(struct fat_descriptor *, cl_t, cl_t); 100f9f848faSopenharmony_ci 101f9f848faSopenharmony_cicl_t fat_allocate_cluster(struct fat_descriptor *fat); 102f9f848faSopenharmony_ci 103f9f848faSopenharmony_cistruct bootblock* fat_get_boot(struct fat_descriptor *); 104f9f848faSopenharmony_ciint fat_get_fd(struct fat_descriptor *); 105f9f848faSopenharmony_cibool fat_is_valid_cl(struct fat_descriptor *, cl_t); 106f9f848faSopenharmony_ci 107f9f848faSopenharmony_ci/* 108f9f848faSopenharmony_ci * Read the FAT 0 and return a pointer to the newly allocated 109f9f848faSopenharmony_ci * descriptor of it. 110f9f848faSopenharmony_ci */ 111f9f848faSopenharmony_ciint readfat(int, struct bootblock *, struct fat_descriptor **); 112f9f848faSopenharmony_ci 113f9f848faSopenharmony_ci/* 114f9f848faSopenharmony_ci * Write back FAT entries 115f9f848faSopenharmony_ci */ 116f9f848faSopenharmony_ciint writefat(struct fat_descriptor *); 117f9f848faSopenharmony_ci 118f9f848faSopenharmony_ci/* 119f9f848faSopenharmony_ci * Read a directory 120f9f848faSopenharmony_ci */ 121f9f848faSopenharmony_ciint resetDosDirSection(struct fat_descriptor *); 122f9f848faSopenharmony_civoid finishDosDirSection(void); 123f9f848faSopenharmony_ciint handleDirTree(struct fat_descriptor *); 124f9f848faSopenharmony_ci 125f9f848faSopenharmony_ci/* 126f9f848faSopenharmony_ci * Cross-check routines run after everything is completely in memory 127f9f848faSopenharmony_ci */ 128f9f848faSopenharmony_ciint checkchain(struct fat_descriptor *, cl_t, size_t *); 129f9f848faSopenharmony_ci 130f9f848faSopenharmony_ci/* 131f9f848faSopenharmony_ci * Check for lost cluster chains 132f9f848faSopenharmony_ci */ 133f9f848faSopenharmony_ciint checklost(struct fat_descriptor *); 134f9f848faSopenharmony_ci/* 135f9f848faSopenharmony_ci * Try to reconnect a lost cluster chain 136f9f848faSopenharmony_ci */ 137f9f848faSopenharmony_ciint reconnect(struct fat_descriptor *, cl_t, size_t); 138f9f848faSopenharmony_civoid finishlf(void); 139f9f848faSopenharmony_ci 140f9f848faSopenharmony_ci/* 141f9f848faSopenharmony_ci * Small helper functions 142f9f848faSopenharmony_ci */ 143f9f848faSopenharmony_ci/* 144f9f848faSopenharmony_ci * Return the type of a reserved cluster as text 145f9f848faSopenharmony_ci */ 146f9f848faSopenharmony_ciconst char *rsrvdcltype(cl_t); 147f9f848faSopenharmony_ci 148f9f848faSopenharmony_ci/* 149f9f848faSopenharmony_ci * Clear a cluster chain in a FAT 150f9f848faSopenharmony_ci */ 151f9f848faSopenharmony_civoid clearchain(struct fat_descriptor *, cl_t); 152f9f848faSopenharmony_ci 153f9f848faSopenharmony_ci#endif 154