]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - SQUASHFS/squashfs-tools-4.4/squashfs-tools/unsquashfs_info.c
added Spanish (Latinoamérica) translation (#1865)
[Ventoy.git] / SQUASHFS / squashfs-tools-4.4 / squashfs-tools / unsquashfs_info.c
1 /*
2 * Create a squashfs filesystem. This is a highly compressed read only
3 * filesystem.
4 *
5 * Copyright (c) 2013
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 * unsquashfs_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 "unsquashfs.h"
42 #include "error.h"
43
44 static int silent = 0;
45 char *pathname = NULL;
46
47 pthread_t info_thread;
48
49
50 void disable_info()
51 {
52 if(pathname)
53 free(pathname);
54
55 pathname = NULL;
56 }
57
58
59 void update_info(char *name)
60 {
61 if(pathname)
62 free(pathname);
63
64 pathname = name;
65 }
66
67
68 void dump_state()
69 {
70 disable_progress_bar();
71
72 printf("Queue and cache status dump\n");
73 printf("===========================\n");
74
75 printf("file buffer read queue (main thread -> reader thread)\n");
76 dump_queue(to_reader);
77
78 printf("file buffer decompress queue (reader thread -> inflate"
79 " thread(s))\n");
80 dump_queue(to_inflate);
81
82 printf("file buffer write queue (main thread -> writer thread)\n");
83 dump_queue(to_writer);
84
85 printf("\nbuffer cache (uncompressed blocks and compressed blocks "
86 "'in flight')\n");
87 dump_cache(data_cache);
88
89 printf("fragment buffer cache (uncompressed frags and compressed"
90 " frags 'in flight')\n");
91 dump_cache(fragment_cache);
92
93 enable_progress_bar();
94 }
95
96
97 void *info_thrd(void *arg)
98 {
99 sigset_t sigmask;
100 struct timespec timespec = { .tv_sec = 1, .tv_nsec = 0 };
101 int sig, waiting = 0;
102
103 sigemptyset(&sigmask);
104 sigaddset(&sigmask, SIGQUIT);
105 sigaddset(&sigmask, SIGHUP);
106
107 while(1) {
108 if(waiting)
109 sig = sigtimedwait(&sigmask, NULL, &timespec);
110 else
111 sig = sigwaitinfo(&sigmask, NULL);
112
113 if(sig == -1) {
114 switch(errno) {
115 case EAGAIN:
116 /* interval timed out */
117 waiting = 0;
118 /* FALLTHROUGH */
119 case EINTR:
120 /* if waiting, the wait will be longer, but
121 that's OK */
122 continue;
123 default:
124 BAD_ERROR("sigtimedwait/sigwaitinfo failed "
125 "because %s\n", strerror(errno));
126 }
127 }
128
129 if(sig == SIGQUIT && !waiting) {
130 if(pathname)
131 INFO("%s\n", pathname);
132
133 /* set one second interval period, if ^\ received
134 within then, dump queue and cache status */
135 waiting = 1;
136 } else
137 dump_state();
138 }
139 }
140
141
142 void init_info()
143 {
144 pthread_create(&info_thread, NULL, info_thrd, NULL);
145 }