1/* 2 * Copyright (c) 2007-2011 Apple 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 24#ifndef __ASL_FILE_H__ 25#define __ASL_FILE_H__ 26 27#include <stdio.h> 28#include <stdint.h> 29#include <sys/types.h> 30#include <asl.h> 31#include <Availability.h> 32 33#define DB_HEADER_LEN 80 34#define DB_HEADER_COOKIE_OFFSET 0 35#define DB_HEADER_VERS_OFFSET 12 36#define DB_HEADER_FIRST_OFFSET 16 37#define DB_HEADER_TIME_OFFSET 24 38#define DB_HEADER_CSIZE_OFFSET 32 39#define DB_HEADER_LAST_OFFSET 36 40 41/* 42 * Magic Cookie for database files. 43 * MAXIMUM 12 CHARS! (DB_HEADER_VERS_OFFSET) 44 */ 45#define ASL_DB_COOKIE "ASL DB" 46#define ASL_DB_COOKIE_LEN 6 47#define DB_VERSION 2 48#define DB_VERSION_LEGACY_1 1 49 50#define ASL_FILE_FLAG_READ_ONLY 0x00000001 51#define ASL_FILE_FLAG_UNLIMITED_CACHE 0x00000002 52#define ASL_FILE_FLAG_PRESERVE_MSG_ID 0x00000004 53#define ASL_FILE_FLAG_LEGACY_STORE 0x00000008 54 55#define ASL_FILE_TYPE_MSG 0 56#define ASL_FILE_TYPE_STR 1 57 58#define ASL_FILE_POSITION_FIRST 0 59#define ASL_FILE_POSITION_PREVIOUS 1 60#define ASL_FILE_POSITION_NEXT 2 61#define ASL_FILE_POSITION_LAST 3 62 63/* NB CACHE_SIZE must be > 1 */ 64#define CACHE_SIZE 256 65 66/* Size of the fixed-length part of a MSG record */ 67#define MSG_RECORD_FIXED_LENGTH 122 68 69/* 70 * The first record (header) in the database has the format: 71 * 72 * | 12 | 4 | 8 | 8 | 4 | 8 | 36 | (80 bytes) 73 * | Cookie | Vers | First | Time | String cache size | Last | Zero | 74 * 75 * MSG records have the format: 76 * 77 * | 2 | 4 | 8 | 8 | 8 | 4 | 2 | 2 | 4 | 4 | 4 | 4 | 4 | 4 | 4 78 * | 00 | Len | Next | ID | Time | Nano | Level | Flags | PID | UID | GID | RUID | RGID | RefPID | KV count ... 79 * 80 * | 8 | 8 | 8 | 8 | 8 | 8 | 8 | 8 | | 8 81 * | Host | Sender | Facility | Message | RefProc | Session | Key0 | Val0 | ... | Previous | 82 * 83 * STR records have the format: 84 * 85 * | 2 | 4 | Len | (Len + 6 bytes) 86 * | 01 | Len | Data+NUL | 87 * 88 */ 89 90typedef struct file_string_s 91{ 92 uint64_t where; 93 uint32_t hash; 94 struct file_string_s *next; 95 char str[]; 96} file_string_t; 97 98typedef struct 99{ 100 uint32_t flags; 101 uint32_t version; 102 uint32_t string_count; 103 file_string_t *string_list; 104 uint64_t first; 105 uint64_t last; 106 uint64_t prev; 107 uint64_t cursor; 108 uint64_t cursor_xid; 109 uint64_t dob; 110 size_t file_size; 111 FILE *store; 112 void *legacy; 113 char *scratch; 114} asl_file_t; 115 116typedef struct asl_file_list_s 117{ 118 asl_file_t *file; 119 struct asl_file_list_s *next; 120} asl_file_list_t; 121 122asl_file_list_t *asl_file_list_add(asl_file_list_t *list, asl_file_t *f) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); 123void asl_file_list_close(asl_file_list_t *list) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); 124 125uint32_t asl_file_open_write(const char *path, mode_t mode, uid_t uid, gid_t gid, asl_file_t **s) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); 126uint32_t asl_file_close(asl_file_t *s) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); 127 128uint32_t asl_file_save(asl_file_t *s, aslmsg msg, uint64_t *mid) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); 129 130uint32_t asl_file_open_read(const char *path, asl_file_t **s) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); 131uint32_t asl_file_fetch(asl_file_t *s, uint64_t mid, aslmsg *msg) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); 132 133uint32_t asl_file_read_set_position(asl_file_t *s, uint32_t pos) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); 134uint32_t asl_file_fetch_next(asl_file_t *s, aslmsg *msg) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); 135uint32_t asl_file_fetch_previous(asl_file_t *s, aslmsg *msg) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); 136 137uint32_t asl_file_match(asl_file_t *s, aslresponse query, aslresponse *res, uint64_t *last_id, uint64_t start_id, uint32_t count, int32_t direction) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); 138uint32_t asl_file_list_match_timeout(asl_file_list_t *list, aslresponse query, aslresponse *res, uint64_t *last_id, uint64_t start_id, uint32_t count, int32_t direction, uint32_t usec) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_3_2); 139uint32_t asl_file_list_match(asl_file_list_t *list, aslresponse query, aslresponse *res, uint64_t *last_id, uint64_t start_id, uint32_t count, int32_t direction) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); 140 141void *asl_file_list_match_start(asl_file_list_t *list, uint64_t start_id, int32_t direction) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); 142uint32_t asl_file_list_match_next(void *token, aslresponse query, aslresponse *res, uint32_t count) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); 143void asl_file_list_match_end(void *token) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); 144 145size_t asl_file_size(asl_file_t *s) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); 146uint64_t asl_file_ctime(asl_file_t *s) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); 147 148uint32_t asl_file_compact(asl_file_t *s, const char *path, mode_t mode, uid_t uid, gid_t gid) __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0); 149 150#endif /* __ASL_FILE_H__ */ 151