blob: 5a39aeb70d793c9a6c0ada05d9ccf02ed93b55d8 [file] [log] [blame]
Mohan Srinivasanb707f302017-01-19 16:40:52 -08001/*
2 * Copyright (C) 2016 The Android Open Source Project
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
ThiƩbaud Weksteen1c72a412020-10-26 19:21:21 +010017#include <stdio.h>
18#include <sys/types.h>
19#include <unistd.h>
20
21#include "ioshark.h"
22
Mohan Srinivasanb707f302017-01-19 16:40:52 -080023#define FILE_DB_HASHSIZE 8192
24
25struct files_db_s {
26 char *filename;
27 int fileno;
28 struct files_db_s *next;
29 size_t size;
Mohan Srinivasan02f86262017-02-24 16:34:28 -080030 int global_filename_ix;
Mohan Srinivasanb707f302017-01-19 16:40:52 -080031};
32
33/* Lifted from Wikipedia Jenkins Hash function page */
34static inline u_int32_t
35jenkins_one_at_a_time_hash(char *key, size_t len)
36{
37 u_int32_t hash, i;
38
39 for(hash = i = 0; i < len; ++i) {
40 hash += key[i];
41 hash += (hash << 10);
42 hash ^= (hash >> 6);
43 }
44 hash += (hash << 3);
45 hash ^= (hash >> 11);
46 hash += (hash << 15);
47 return hash;
48}
49
50static inline void
51files_db_update_size(void *node, u_int64_t new_size)
52{
53 struct files_db_s *db_node = (struct files_db_s *)node;
54
55 if (db_node->size < new_size)
56 db_node->size = new_size;
57}
58
59static inline void
60files_db_add_to_size(void *node, u_int64_t size_incr)
61{
62 ((struct files_db_s *)node)->size += size_incr;
63}
64
65static inline int
66files_db_get_fileno(void *node)
67{
68 return (((struct files_db_s *)node)->fileno);
69}
70
71static inline char *
72files_db_get_filename(void *node)
73{
74 return (((struct files_db_s *)node)->filename);
75}
76
Mohan Srinivasanb707f302017-01-19 16:40:52 -080077void *files_db_create_handle(void);
78void files_db_write_objects(FILE *fp);
79void *files_db_add(char *filename);
80void *files_db_lookup(char *filename);
81int files_db_get_total_obj(void);
Mohan Srinivasan02f86262017-02-24 16:34:28 -080082void init_filename_cache(void);
83void store_filename_cache(void);
Mohan Srinivasanb707f302017-01-19 16:40:52 -080084
Mohan Srinivasan9dd78702017-07-19 15:26:57 -070085int ioshark_write_header(FILE *fp, struct ioshark_header *header);
86int ioshark_write_file_state(FILE *fp, struct ioshark_file_state *state);
87int ioshark_write_file_op(FILE *fp, struct ioshark_file_operation *file_op);