1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
/**
* NetNuke - Erases all storage media detected by the system
* Copyright (C) 2009-2010 Joseph Hunkeler <jhunkeler@gmail.com, jhunk@stsci.edu>
*
* This file is part of NetNuke.
*
* NetNuke is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NetNuke is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NetNuke. If not, see <http://www.gnu.org/licenses/>.
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <ncurses.h>
#include "netnuke.h"
WINDOW* main_window;
WINDOW* info_window;
pthread_mutex_t main_window_lock = PTHREAD_MUTEX_INITIALIZER;
WINDOW *create_window(int height, int width, int starty, int startx)
{
WINDOW *window;
window = newwin(height, width, starty, startx);
wborder(window, '+', '+', '+','+','+','+','+','+');
wrefresh(window);
return window;
}
void free_window(WINDOW* window)
{
wborder(window, ' ', ' ', ' ',' ',' ',' ',' ',' ');
wrefresh(window);
delwin(window);
}
void update_window(WINDOW* window)
{
wborder(window, '+', '+', '+','+','+','+','+','+');
wrefresh(window);
}
extern pthread_mutex_t lock_global;
extern pthread_mutex_t lock_write;
extern unsigned long long total_written_bytes;
extern unsigned int blksz_override;
extern int list_flag;
extern int ignore_first_flag;
extern int ignore_flag;
extern int safety_flag;
extern int logging_flag;
extern int verbose_flag;
extern int bus_mask;
extern int device_timeout;
extern char** bus_flags;
extern char** ignore_list;
extern nndevice_t** device;
void* main_window_worker(void* args)
{
pthread_t thread[MAXTHREAD];
int thread_count = 0;
int i = 0;
device = (nndevice_t**)malloc(MAXTHREAD * sizeof(nndevice_t));
if(device == NULL)
{
perror("device list");
exit(1);
}
if(list_flag)
{
bus_mask = selectbus(bus_flags);
scanbus_sysfs(device);
exit(0);
}
/* Select the bus mask and scan for devices */
bus_mask = selectbus(bus_flags);
scanbus_sysfs(device);
/* If the operator wants to preserve the first device */
if(ignore_first_flag)
{
int first = 0;
int last = 0;
/* Count how many devices we have */
int i = 0;
while(device[i] != NULL)
{
i++;
}
last = i - 1;
COM("IGNORING: %s", device[first]->path);
/* Replace the first device's array entry and then clear the original */
memmove(device[first], device[last], sizeof(nndevice_t));
memset(device[last], 0, sizeof(nndevice_t));
device[last] = NULL;
}
if(ignore_flag)
{
ignore_device(ignore_list, device);
}
/* Run check to see if any devices were returned */
if(device[0] == NULL)
{
COM(self, "No devices detected\n");
exit(0);
}
COM(self, "Safety is %s", safety_flag ? "OFF" : "ON");
if(device_timeout) COM(self, "%ds timeout set\n", device_timeout);
if(blksz_override) COM(self, "Forcing %d block size\n", blksz_override);
COM(self, "Initializing mutex\n");
pthread_mutex_init(&lock_global, NULL);
pthread_mutex_init(&lock_write, NULL);
COM(self, "Generating threads\n");
/* Tell the random generator to start */
nnrandinit();
/* Start a single thread per device node*/
for( i = 0; device[i] != NULL ; i++ )
{
thread[i] = (pthread_t)nnthread(device[i]);
COM(self, "thread id: %8X %8X\n", thread[i]);
}
/* Catch up */
usleep(10000);
/* Using the original device count, set thread_count and join all threads */
thread_count = i;
COM(self, "Joining %d thread%c\n", thread_count, (thread_count > 1 || thread_count < 1) ? 's' : '\b');
for( i = 0 ; i < thread_count ; i++)
{
pthread_join(thread[i], NULL);
}
COM(self, "Destroying mutex\n");
pthread_mutex_destroy(&lock_global);
pthread_mutex_destroy(&lock_write);
COM(self, "Total bytes written: %lu\n", total_written_bytes);
nnrandfree();
return NULL;
}
void main_init()
{
pthread_t main_window_thread;
pthread_t info_window_thread;
int startx = 0, starty = 0, width = 0, height = 0;
cbreak();
keypad(stdscr, TRUE);
height = getmaxy(stdscr) / 2;
width = getmaxx(stdscr);
main_window = create_window(height, width, starty, startx);
starty = getmaxy(stdscr) / 2;
height = getmaxy(stdscr) / 2;
width = getmaxx(stdscr);
info_window = create_window(height, width, starty, startx);
//refresh();
pthread_mutex_init(&main_window_lock, NULL);
pthread_create(&main_window_thread, NULL, main_window_worker, NULL);
pthread_join(main_window_thread, NULL);
pthread_mutex_destroy(&main_window_lock);
}
void main_deinit()
{
endwin();
}
|