]>
glassweightruler.freedombox.rocks Git - Ventoy.git/blob - SQUASHFS/squashfs-tools-4.4/squashfs-tools/restore.c
2 * Create a squashfs filesystem. This is a highly compressed read only
5 * Copyright (c) 2013, 2014, 2019
6 * Phillip Lougher <phillip@squashfs.org.uk>
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.
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.
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.
26 #include <sys/ioctl.h>
36 #include <sys/types.h>
39 #include "caches-queues-lists.h"
40 #include "squashfs_fs.h"
41 #include "mksquashfs.h"
43 #include "progressbar.h"
49 extern pthread_t reader_thread
, writer_thread
, main_thread
, order_thread
;
50 extern pthread_t
*deflator_thread
, *frag_deflator_thread
, *frag_thread
;
51 extern struct queue
*to_deflate
, *to_writer
, *to_frag
, *to_process_frag
;
52 extern struct seq_queue
*to_main
, *to_order
;
53 extern void restorefs();
54 extern int processors
;
55 extern int reproducible
;
57 static int interrupted
= 0;
58 static pthread_t restore_thread
;
60 void *restore_thrd(void *arg
)
62 sigset_t sigmask
, old_mask
;
65 sigemptyset(&sigmask
);
66 sigaddset(&sigmask
, SIGINT
);
67 sigaddset(&sigmask
, SIGTERM
);
68 sigaddset(&sigmask
, SIGUSR1
);
69 pthread_sigmask(SIG_BLOCK
, &sigmask
, &old_mask
);
72 sigwait(&sigmask
, &sig
);
74 if((sig
== SIGINT
|| sig
== SIGTERM
) && !interrupted
) {
75 ERROR("Interrupting will restore original "
77 ERROR("Interrupt again to quit\n");
82 /* kill main thread/worker threads and restore */
83 set_progressbar_state(FALSE
);
86 /* first kill the reader thread */
87 pthread_cancel(reader_thread
);
88 pthread_join(reader_thread
, NULL
);
91 * then flush the reader to deflator thread(s) output queue.
92 * The deflator thread(s) will idle
94 queue_flush(to_deflate
);
96 /* now kill the deflator thread(s) */
97 for(i
= 0; i
< processors
; i
++)
98 pthread_cancel(deflator_thread
[i
]);
99 for(i
= 0; i
< processors
; i
++)
100 pthread_join(deflator_thread
[i
], NULL
);
103 * then flush the reader to process fragment thread(s) output
104 * queue. The process fragment thread(s) will idle
106 queue_flush(to_process_frag
);
108 /* now kill the process fragment thread(s) */
109 for(i
= 0; i
< processors
; i
++)
110 pthread_cancel(frag_thread
[i
]);
111 for(i
= 0; i
< processors
; i
++)
112 pthread_join(frag_thread
[i
], NULL
);
115 * then flush the reader/deflator/process fragment to main
116 * thread output queue. The main thread will idle
118 seq_queue_flush(to_main
);
120 /* now kill the main thread */
121 pthread_cancel(main_thread
);
122 pthread_join(main_thread
, NULL
);
124 /* then flush the main thread to fragment deflator thread(s)
125 * queue. The fragment deflator thread(s) will idle
127 queue_flush(to_frag
);
129 /* now kill the fragment deflator thread(s) */
130 for(i
= 0; i
< processors
; i
++)
131 pthread_cancel(frag_deflator_thread
[i
]);
132 for(i
= 0; i
< processors
; i
++)
133 pthread_join(frag_deflator_thread
[i
], NULL
);
136 /* then flush the fragment deflator_threads(s)
137 * to frag orderer thread. The frag orderer
140 seq_queue_flush(to_order
);
142 /* now kill the frag orderer thread */
143 pthread_cancel(order_thread
);
144 pthread_join(order_thread
, NULL
);
148 * then flush the main thread/fragment deflator thread(s)
149 * to writer thread queue. The writer thread will idle
151 queue_flush(to_writer
);
153 /* now kill the writer thread */
154 pthread_cancel(writer_thread
);
155 pthread_join(writer_thread
, NULL
);
157 TRACE("All threads cancelled\n");
164 pthread_t
*init_restore_thread()
166 pthread_create(&restore_thread
, NULL
, restore_thrd
, NULL
);
167 return &restore_thread
;