]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - SQUASHFS/squashfs-tools-4.4/squashfs-tools/info.c
1.1.07 release
[Ventoy.git] / SQUASHFS / squashfs-tools-4.4 / squashfs-tools / info.c
1 /*
2 * Create a squashfs filesystem. This is a highly compressed read only
3 * filesystem.
4 *
5 * Copyright (c) 2013, 2014, 2019
6 * Phillip Lougher <phillip@squashfs.org.uk>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2,
11 * or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 *
22 * info.c
23 */
24
25 #include <pthread.h>
26 #include <sys/ioctl.h>
27 #include <unistd.h>
28 #include <signal.h>
29 #include <sys/time.h>
30 #include <stdio.h>
31 #include <math.h>
32 #include <stdarg.h>
33 #include <errno.h>
34 #include <stdlib.h>
35 #include <dirent.h>
36 #include <sys/types.h>
37 #include <sys/stat.h>
38 #include <string.h>
39
40 #include "squashfs_fs.h"
41 #include "mksquashfs.h"
42 #include "error.h"
43 #include "progressbar.h"
44 #include "caches-queues-lists.h"
45
46 static int silent = 0;
47 static struct dir_ent *ent = NULL;
48
49 pthread_t info_thread;
50
51
52 void disable_info()
53 {
54 ent = NULL;
55 }
56
57
58 void update_info(struct dir_ent *dir_ent)
59 {
60 ent = dir_ent;
61 }
62
63
64 void print_filename()
65 {
66 struct dir_ent *dir_ent = ent;
67
68 if(dir_ent == NULL)
69 return;
70
71 if(dir_ent->our_dir->subpath[0] != '\0')
72 INFO("%s/%s\n", dir_ent->our_dir->subpath, dir_ent->name);
73 else
74 INFO("/%s\n", dir_ent->name);
75 }
76
77
78 void dump_state()
79 {
80 disable_progress_bar();
81
82 printf("Queue and Cache status dump\n");
83 printf("===========================\n");
84
85 printf("file buffer queue (reader thread -> deflate thread(s))\n");
86 dump_queue(to_deflate);
87
88 printf("uncompressed fragment queue (reader thread -> fragment"
89 " thread(s))\n");
90 dump_queue(to_process_frag);
91
92 printf("processed fragment queue (fragment thread(s) -> main"
93 " thread)\n");
94 dump_seq_queue(to_main, 1);
95
96 printf("compressed block queue (deflate thread(s) -> main thread)\n");
97 dump_seq_queue(to_main, 0);
98
99 printf("uncompressed packed fragment queue (main thread -> fragment"
100 " deflate thread(s))\n");
101 dump_queue(to_frag);
102
103 if(!reproducible) {
104 printf("locked frag queue (compressed frags waiting while multi-block"
105 " file is written)\n");
106 dump_queue(locked_fragment);
107
108 printf("compressed block queue (main & fragment deflate threads(s) ->"
109 " writer thread)\n");
110 dump_queue(to_writer);
111 } else {
112 printf("compressed fragment queue (fragment deflate threads(s) ->"
113 "fragment order thread)\n");
114
115 dump_seq_queue(to_order, 0);
116
117 printf("compressed block queue (main & fragment order threads ->"
118 " writer thread)\n");
119 dump_queue(to_writer);
120 }
121
122 printf("read cache (uncompressed blocks read by reader thread)\n");
123 dump_cache(reader_buffer);
124
125 printf("block write cache (compressed blocks waiting for the writer"
126 " thread)\n");
127 dump_cache(bwriter_buffer);
128 printf("fragment write cache (compressed fragments waiting for the"
129 " writer thread)\n");
130 dump_cache(fwriter_buffer);
131
132 printf("fragment cache (frags waiting to be compressed by fragment"
133 " deflate thread(s))\n");
134 dump_cache(fragment_buffer);
135
136 printf("fragment reserve cache (avoids pipeline stall if frag cache"
137 " full in dup check)\n");
138 dump_cache(reserve_cache);
139
140 enable_progress_bar();
141 }
142
143
144 void *info_thrd(void *arg)
145 {
146 sigset_t sigmask;
147 struct timespec timespec = { .tv_sec = 1, .tv_nsec = 0 };
148 int sig, waiting = 0;
149
150 sigemptyset(&sigmask);
151 sigaddset(&sigmask, SIGQUIT);
152 sigaddset(&sigmask, SIGHUP);
153
154 while(1) {
155 if(waiting)
156 sig = sigtimedwait(&sigmask, NULL, &timespec);
157 else
158 sig = sigwaitinfo(&sigmask, NULL);
159
160 if(sig == -1) {
161 switch(errno) {
162 case EAGAIN:
163 /* interval timed out */
164 waiting = 0;
165 /* FALLTHROUGH */
166 case EINTR:
167 /* if waiting, the wait will be longer, but
168 that's OK */
169 continue;
170 default:
171 BAD_ERROR("sigtimedwait/sigwaitinfo failed "
172 "because %s\n", strerror(errno));
173 }
174 }
175
176 if(sig == SIGQUIT && !waiting) {
177 print_filename();
178
179 /* set one second interval period, if ^\ received
180 within then, dump queue and cache status */
181 waiting = 1;
182 } else
183 dump_state();
184 }
185 }
186
187
188 void init_info()
189 {
190 pthread_create(&info_thread, NULL, info_thrd, NULL);
191 }