1/* 2 * Copyright (c) 2008 Apple Computer, Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23#include <stdio.h> 24 25#ifndef _FSCK_MESSAGES_H 26#define _FSCK_MESSAGES_H 27 28/* 29 * Internal structure for each fsck message. This is the same 30 * structure in which the message number, message string and 31 * their corresponding attributes are mapped in fsck_strings.c 32 * and fsck_hfs_strings.c 33 */ 34struct fsck_message { 35 unsigned int msgnum; /* fsck message number as an unsigned value */ 36 char *msg; /* fsck message as a C string */ 37 int type; /* type of message (see fsck_msgtype below) */ 38 int level; /* verbosity level at which this message should be output/presented to the user */ 39 int numargs; /* number of arguments for this message string */ 40 const int *argtype; /* pointer to an array of argument types (see fsck_argtype below) */ 41}; 42typedef struct fsck_message fsck_message_t; 43 44typedef void *fsck_ctx_t; 45 46/* Type of fsck message string. 47 * These values are internal values used in the mapping array of 48 * message number and string to identify the type of message for 49 * each entry. 50 */ 51enum fsck_msgtype { 52 fsckMsgUnknown = 0, 53 fsckMsgVerify, /* fsck is performing a read-only operation on the volume */ 54 fsckMsgRepair, /* fsck is writing to file system to repair a corruption */ 55 fsckMsgSuccess, /* verify found that the volume is clean, or repair was successful */ 56 fsckMsgFail, /* verify found that the volume is corrupt, or verify did not complete due to error, or repair failed */ 57 fsckMsgError, /* information of corruption found or condition that causes verify/repair to fail */ 58 fsckMsgDamageInfo, /* information about corrupt files/folders */ 59 fsckMsgInfo, /* information about an error message or any fsck operation */ 60 fsckMsgProgress, /* percentage progress of verify/repair operation */ 61 fsckMsgNotice, /* A traditional notice that doesn't fall into other categories */ 62}; 63 64/* Type of parameter for fsck message string. 65 * These values are internal values used in the mapping array of 66 * message number and string to identify the type of parameter 67 * for each entry. 68 */ 69enum fsck_arg_type { 70 fsckTypeUnknown = 0, 71 fsckTypeInt, /* positive integer */ 72 fsckTypeLong, /* positive long value */ 73 fsckTypeString, /* UTF-8 string */ 74 fsckTypePath, /* path to a file or directory on the volume */ 75 fsckTypeFile, /* name of file */ 76 fsckTypeDirectory, /* name of directory */ 77 fsckTypeVolume, /* name of a volume */ 78 fsckTypeProgress, /* percentage progress number */ 79 fsckTypeFSType, /* type of file system being checked */ 80 fsckTypeFileSize, /* A file size or offset */ 81}; 82 83/* Verbosity of fsck message string. 84 * These values are internal values used in the mapping array of 85 * message number and string to identify the verbosity of each entry. 86 */ 87enum fsck_message_levels { 88 fsckLevel0 = 0, /* level 0 messages should always be displayed to the user */ 89 fsckLevel1 = 1 /* level 1 messages should be only displayed in advanced mode */ 90}; 91 92/* Type of fsck_hfs output */ 93enum fsck_output_type { 94 fsckOutputUndefined = 0, 95 fsckOutputTraditional, /* standard string output */ 96 fsckOutputGUI, /* output for -g option */ 97 fsckOutputXML /* XML output for -x option */ 98}; 99 100/* Types of default answers for user input questions in fsck */ 101enum fsck_default_answer_type { 102 fsckDefaultNone = 0, 103 fsckDefaultNo, 104 fsckDefaultYes 105}; 106 107/* 108 * Return value from a status block. The block is called 109 * in fsckPrint(), before and after a status message is 110 * printed. Returning fsckBlockContinue means to continue as 111 * it would otherwise; returning fsckBlockAbort means that 112 * fsckPrint should return an error at that point; and fsckBlockIgnore 113 * means that fsckPrint should return immediately, but without an error. 114 * 115 * The most common use of fsckBlockIgnore would be to suppress extraneous 116 * messages. 117 */ 118enum fsck_block_status_type { 119 fsckBlockAbort = -1, 120 fsckBlockContinue = 0, 121 fsckBlockIgnore, 122}; 123typedef enum fsck_block_status_type fsck_block_status_t; 124 125/* 126 * Phases for the status block. The block is called in fsckPrint(), 127 * either before printing the message (with fsckPhaseBeforeMessage), or 128 * afterwards (with fsckPhaseAfterMessage). It's allowed ot have both 129 * set up with different blocks. 130 */ 131enum fsck_block_phase_type { 132 fsckPhaseNone = 0, 133 fsckPhaseBeforeMessage, 134 fsckPhaseAfterMessage, 135}; 136typedef enum fsck_block_phase_type fsck_block_phase_t; 137 138/* 139 * The type of a status block. The first argument is the context 140 * for the messaging; the second argument is the message number; 141 * the third is a va_list of the arguments for the message. 142 */ 143 144typedef fsck_block_status_t (^fsckBlock_t)(fsck_ctx_t, int, va_list); 145 146extern fsckBlock_t fsckGetBlock(fsck_ctx_t, fsck_block_phase_t); 147extern void fsckSetBlock(fsck_ctx_t, fsck_block_phase_t, fsckBlock_t); 148 149extern fsck_ctx_t fsckCreate(void); 150extern int fsckSetOutput(fsck_ctx_t, FILE*); 151extern int fsckSetFile(fsck_ctx_t, int); 152extern int fsckSetWriter(fsck_ctx_t, void (*)(fsck_ctx_t, const char *)); 153extern int fsckSetLogger(fsck_ctx_t, void (*)(fsck_ctx_t, const char *)); 154extern int fsckSetVerbosity(fsck_ctx_t, int); 155extern int fsckGetVerbosity(fsck_ctx_t); 156extern int fsckSetOutputStyle(fsck_ctx_t, enum fsck_output_type); 157extern enum fsck_output_type fsckGetOutputStyle(fsck_ctx_t); 158extern int fsckSetDefaultResponse(fsck_ctx_t, enum fsck_default_answer_type); 159extern int fsckAskPrompt(fsck_ctx_t, const char *, ...); 160extern int fsckAddMessages(fsck_ctx_t, fsck_message_t *msgs); 161extern int fsckPrint(fsck_ctx_t, int msgNum, ...); 162extern enum fsck_msgtype fsckMsgClass(fsck_ctx_t, int msgNum); 163extern void fsckDestroy(fsck_ctx_t); 164 165#endif /* _FSCK_MESSAGES_H */ 166