1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2012 Auke Kok <auke-jan.h.kok@intel.com>
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
28 #include <linux/limits.h>
29 #include <sys/types.h>
33 #include "readahead-common.h"
35 int main_analyze(const char *pack_path) {
37 _cleanup_fclose_ FILE *pack = NULL;
43 pack_path = "/.readahead";
45 pack = fopen(pack_path, "re");
47 log_error("Pack file missing.");
51 if (!fgets(line, sizeof(line), pack)) {
52 log_error("Pack file corrupt.");
58 if (!endswith(line, READAHEAD_PACK_FILE_VERSION)) {
59 log_error("Pack file version incompatible with this parser.");
63 if ((a = getc(pack)) == EOF) {
64 log_error("Pack file corrupt.");
68 fputs(" pct sections size: path\n"
69 " === ======== ====: ====\n", stdout);
78 if (!fgets(path, sizeof(path), pack))
81 path[strlen(path)-1] = 0;
83 if (fread(&inode, sizeof(inode), 1, pack) != 1) {
84 log_error("Pack file corrupt.");
91 if (fread(&b, sizeof(b), 1, pack) != 1 ||
92 fread(&c, sizeof(c), 1, pack) != 1) {
93 log_error("Pack file corrupt.");
96 if ((b == 0) && (c == 0))
99 /* Uncomment this to get all the chunks separately
100 printf(" %d: %d %d\n", sections, b, c);
107 if (stat(path, &st) == 0) {
113 size = pages * page_size();
117 printf(" %4jd%% (%2d) %12jd: %s\n",
118 (intmax_t) (sections && st.st_size ? size * 100 / st.st_size : 100),
119 sections ? sections : 1,
123 printf(" %4dp (%2d) %12s: %s (MISSING)\n",
124 sections ? pages : -1,
125 sections ? sections : 1,