]> git.saurik.com Git - apple/libc.git/blob - gen/asl_file.h
Libc-594.1.4.tar.gz
[apple/libc.git] / gen / asl_file.h
1 #ifndef __ASL_FILE_H__
2 #define __ASL_FILE_H__
3
4 /*
5 * Copyright (c) 2007 Apple Inc. All rights reserved.
6 *
7 * @APPLE_LICENSE_HEADER_START@
8 *
9 * "Portions Copyright (c) 2007 Apple Inc. All Rights
10 * Reserved. This file contains Original Code and/or Modifications of
11 * Original Code as defined in and that are subject to the Apple Public
12 * Source License Version 1.0 (the 'License'). You may not use this file
13 * except in compliance with the License. Please obtain a copy of the
14 * License at http://www.apple.com/publicsource and read it before using
15 * this file.
16 *
17 * The Original Code and all software distributed under the License are
18 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
19 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
20 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
22 * License for the specific language governing rights and limitations
23 * under the License."
24 *
25 * @APPLE_LICENSE_HEADER_END@
26 */
27
28 #include <stdio.h>
29 #include <stdint.h>
30 #include <sys/types.h>
31 #include <asl.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
90 typedef 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
98 typedef 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
116 typedef struct asl_file_list_s
117 {
118 asl_file_t *file;
119 struct asl_file_list_s *next;
120 } asl_file_list_t;
121
122 asl_file_list_t *asl_file_list_add(asl_file_list_t *list, asl_file_t *f);
123 void asl_file_list_close(asl_file_list_t *list);
124
125 uint32_t asl_file_open_write(const char *path, mode_t mode, uid_t uid, gid_t gid, asl_file_t **s);
126 uint32_t asl_file_close(asl_file_t *s);
127
128 uint32_t asl_file_save(asl_file_t *s, aslmsg msg, uint64_t *mid);
129
130 uint32_t asl_file_open_read(const char *path, asl_file_t **s);
131 uint32_t asl_file_fetch(asl_file_t *s, uint64_t mid, aslmsg *msg);
132
133 uint32_t asl_file_read_set_position(asl_file_t *s, uint32_t pos);
134 uint32_t asl_file_fetch_next(asl_file_t *s, aslmsg *msg);
135 uint32_t asl_file_fetch_previous(asl_file_t *s, aslmsg *msg);
136
137 uint32_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);
138 uint32_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);
139 uint32_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);
140
141 void *asl_file_list_match_start(asl_file_list_t *list, uint64_t start_id, int32_t direction);
142 uint32_t asl_file_list_match_next(void *token, aslresponse query, aslresponse *res, uint32_t count);
143 void asl_file_list_match_end(void *token);
144
145 size_t asl_file_size(asl_file_t *s);
146 uint64_t asl_file_ctime(asl_file_t *s);
147
148 uint32_t asl_file_compact(asl_file_t *s, const char *path, mode_t mode, uid_t uid, gid_t gid);
149
150 #endif __ASL_FILE_H__