Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

  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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
/* -*-C++-*-	$NetBSD: menu.cpp,v 1.13 2011/11/23 15:49:58 nonaka Exp $	*/

/*-
 * Copyright (c) 2001 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by UCHIYAMA Yasushi.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <hpcmenu.h>
#include <hpcboot.h>
#include <res/resource.h>
#include <menu/window.h>
#include <menu/tabwindow.h>
#include <menu/rootwindow.h>
#include <machine/bootinfo.h>
#include <framebuffer.h>
#include <console.h>

#include <menu/menu.h>

#define SCALEX(x) (((x) * dpix) / 96/*DPI*/)
#define SCALEY(y) (((y) * dpiy) / 96/*DPI*/)
#define UNSCALEX(x) (((x) * 96) / dpix)
#define UNSCALEY(y) (((y) * 96) / dpiy)

TabWindow *
TabWindowBase::boot(int id)
{
	TabWindow *w = NULL;
	HpcMenuInterface &menu = HPC_MENU;

	switch(id) {
	default:
		break;
	case IDC_BASE_MAIN:
		menu._main = new MainTabWindow(*this, IDC_BASE_MAIN);
		w = menu._main;
		break;
	case IDC_BASE_OPTION:
		menu._option = new OptionTabWindow(*this, IDC_BASE_OPTION);
		w = menu._option;
		break;
	case IDC_BASE_CONSOLE:
		menu._console = new ConsoleTabWindow(*this, IDC_BASE_CONSOLE);
		w = menu._console;
		break;
	}

	if (w)
		w->create(0);

	return w;
}

//
// Main window
//
void
MainTabWindow::_insert_item(HWND w, TCHAR *name, int id)
{
	int idx = SendDlgItemMessage(w, id, CB_ADDSTRING, 0,
	    reinterpret_cast <LPARAM>(name));
	if (idx != CB_ERR)
		SendDlgItemMessage(w, IDC_MAIN_DIR, CB_SETITEMDATA,
		    idx, _item_idx++);
}

void
MainTabWindow::init(HWND w)
{
	HpcMenuInterface &menu = HPC_MENU;
	struct HpcMenuInterface::HpcMenuPreferences &pref = HPC_PREFERENCE;

	_window = w;
	// insert myself to tab-control
	TabWindow::init(w);

	// setup child.
	TCHAR *entry;
	int i;
	// kernel directory path
	for (i = 0; entry = menu.dir(i); i++)
		_insert_item(w, entry, IDC_MAIN_DIR);
	SendDlgItemMessage(w, IDC_MAIN_DIR, CB_SETCURSEL, menu.dir_default(),
	    0);
	// platform
	_sort_platids(w);
	// kernel file name.
	Edit_SetText(GetDlgItem(w, IDC_MAIN_KERNEL), pref.kernel_user ?
	    pref.kernel_user_file : TEXT("netbsd.gz"));

	// root file system.
	int fs = pref.rootfs + IDC_MAIN_ROOT_;
	_set_check(fs, TRUE);

	_edit_md_root = GetDlgItem(w, IDC_MAIN_ROOT_MD_OPS);
	Edit_SetText(_edit_md_root, pref.rootfs_file);
	EnableWindow(_edit_md_root, fs == IDC_MAIN_ROOT_MD ? TRUE : FALSE);

	// layout checkbox and editbox.
	layout();

	// set default kernel boot options.
	_set_check(IDC_MAIN_OPTION_A, pref.boot_ask_for_name);
	_set_check(IDC_MAIN_OPTION_D, pref.boot_debugger);
	_set_check(IDC_MAIN_OPTION_S, pref.boot_single_user);
	_set_check(IDC_MAIN_OPTION_V, pref.boot_verbose);
	_set_check(IDC_MAIN_OPTION_H, pref.boot_serial);

	// serial console speed.
	TCHAR *speed_tab[] = { L"9600", L"19200", L"115200", 0 };
	int sel = 0;
	i = 0;
	for (TCHAR **speed = speed_tab; *speed; speed++, i++) {
		_insert_item(w, *speed, IDC_MAIN_OPTION_H_SPEED);
		if (_wtoi(*speed) == pref.serial_speed)
			sel = i;
	}
	_combobox_serial_speed = GetDlgItem(_window, IDC_MAIN_OPTION_H_SPEED);
	SendDlgItemMessage(w, IDC_MAIN_OPTION_H_SPEED, CB_SETCURSEL, sel, 0);
	EnableWindow(_combobox_serial_speed, pref.boot_serial);
}

int
MainTabWindow::_platcmp(const void *a, const void *b)
{
	const MainTabWindow::PlatMap *pa =
		reinterpret_cast <const MainTabWindow::PlatMap *>(a);
	const MainTabWindow::PlatMap *pb =
		reinterpret_cast <const MainTabWindow::PlatMap *>(b);

	return wcscmp(pa->name, pb->name);
}

void
MainTabWindow::_sort_platids(HWND w)
{
	HpcMenuInterface &menu = HPC_MENU;
	MainTabWindow::PlatMap *p;
	TCHAR *entry;
	int nids;
	int i;

	for (nids = 0; menu.platform_get(nids); ++nids)
		continue;

	_platmap = reinterpret_cast <MainTabWindow::PlatMap *>
		(malloc(nids * sizeof(MainTabWindow::PlatMap)));

	if (_platmap == NULL) {
		// can't sort, present in the order of definition
		for (i = 0; entry = menu.platform_get(i); i++)
			_insert_item(w, entry, IDC_MAIN_PLATFORM);
		SendDlgItemMessage(w, IDC_MAIN_PLATFORM, CB_SETCURSEL,
				   menu.platform_default(), 0);
		return;
	}

	for (i = 0, p = _platmap; i < nids; ++i, ++p) {
		p->id = i;
		p->name = menu.platform_get(i);
	}

	qsort(_platmap, nids, sizeof(MainTabWindow::PlatMap),
	      MainTabWindow::_platcmp);

	int defid = menu.platform_default();
	int defitem = 0;
	for (i = 0; i < nids; ++i) {
		if (_platmap[i].id == defid)
			defitem = i;
		_insert_item(w, _platmap[i].name, IDC_MAIN_PLATFORM);
	}
	SendDlgItemMessage(w, IDC_MAIN_PLATFORM, CB_SETCURSEL, defitem, 0);
}

int
MainTabWindow::_item_to_platid(int idx)
{
	if (_platmap == NULL)
		return idx;
	else
		return _platmap[idx].id;
}

void
MainTabWindow::layout()
{
	// inquire display size.
	HDC hdc = GetDC(0);
	int width = GetDeviceCaps(hdc, HORZRES);
	int height = GetDeviceCaps(hdc, VERTRES);
	int dpix = GetDeviceCaps(hdc, LOGPIXELSX);
	int dpiy = GetDeviceCaps(hdc, LOGPIXELSY);
	ReleaseDC(0, hdc);

	// set origin
	int x, y;
	if (width <= 320) {
		x = 5, y = 140;
	} else if (height <= 240) {
		x = 250, y = 5;
	} else {
		x = 5, y = 140;
	}

	HWND h;
	h = GetDlgItem(_window, IDC_MAIN_OPTION_V);
	SetWindowPos(h, 0, SCALEX(x), SCALEY(y),
	    SCALEX(120), SCALEY(10), SWP_NOSIZE | SWP_NOZORDER);
	h = GetDlgItem(_window, IDC_MAIN_OPTION_S);
	SetWindowPos(h, 0, SCALEX(x), SCALEY(y + 20),
            SCALEX(120), SCALEY(10), SWP_NOSIZE | SWP_NOZORDER);
	h = GetDlgItem(_window, IDC_MAIN_OPTION_A);
	SetWindowPos(h, 0, SCALEX(x), SCALEY(y + 40),
	    SCALEX(120), SCALEY(10), SWP_NOSIZE | SWP_NOZORDER);
	h = GetDlgItem(_window, IDC_MAIN_OPTION_D);
	SetWindowPos(h, 0, SCALEX(x), SCALEY(y + 60),
	    SCALEX(120), SCALEY(10), SWP_NOSIZE | SWP_NOZORDER);
	h = GetDlgItem(_window, IDC_MAIN_OPTION_H);
	SetWindowPos(h, 0, SCALEX(x), SCALEY(y + 80),
	    SCALEX(120), SCALEY(10), SWP_NOSIZE | SWP_NOZORDER);
	h = GetDlgItem(_window, IDC_MAIN_OPTION_H_SPEED);
	SetWindowPos(h, 0, SCALEX(x + 100), SCALEY(y + 80),
	    SCALEX(120), SCALEY(10), SWP_NOSIZE | SWP_NOZORDER);
}

void
MainTabWindow::get()
{
	HpcMenuInterface &menu = HPC_MENU;
	struct HpcMenuInterface::HpcMenuPreferences &pref = HPC_PREFERENCE;

	HWND w = GetDlgItem(_window, IDC_MAIN_DIR);
	ComboBox_GetText(w, pref.dir_user_path, MAX_PATH);
	pref.dir_user = TRUE;
	w = GetDlgItem(_window, IDC_MAIN_KERNEL);
	Edit_GetText(w, pref.kernel_user_file, MAX_PATH);
	pref.kernel_user = TRUE;

	int i = ComboBox_GetCurSel(GetDlgItem(_window, IDC_MAIN_PLATFORM));
	menu.platform_set(_item_to_platid(i));

	if (_is_checked(IDC_MAIN_ROOT_WD))
		pref.rootfs = 0;
	else if (_is_checked(IDC_MAIN_ROOT_SD))
		pref.rootfs = 1;
	else if (_is_checked(IDC_MAIN_ROOT_MD))
		pref.rootfs = 2;
	else if (_is_checked(IDC_MAIN_ROOT_NFS))
		pref.rootfs = 3;
	else if (_is_checked(IDC_MAIN_ROOT_DK))
		pref.rootfs = 4;
	else if (_is_checked(IDC_MAIN_ROOT_LD))
		pref.rootfs = 5;

	pref.boot_ask_for_name	= _is_checked(IDC_MAIN_OPTION_A);
	pref.boot_debugger	= _is_checked(IDC_MAIN_OPTION_D);
	pref.boot_verbose	= _is_checked(IDC_MAIN_OPTION_V);
	pref.boot_single_user	= _is_checked(IDC_MAIN_OPTION_S);
	pref.boot_serial	= _is_checked(IDC_MAIN_OPTION_H);
	Edit_GetText(_edit_md_root, pref.rootfs_file, MAX_PATH);

	TCHAR tmpbuf[8];
	ComboBox_GetText(_combobox_serial_speed, tmpbuf, 8);
	pref.serial_speed = _wtoi(tmpbuf);
}

void
MainTabWindow::command(int id, int msg)
{
	switch (id) {
	case IDC_MAIN_OPTION_H:
		EnableWindow(_combobox_serial_speed,
		    _is_checked(IDC_MAIN_OPTION_H));
		break;
	case IDC_MAIN_ROOT_WD:
		/* FALLTHROUGH */
	case IDC_MAIN_ROOT_SD:
		/* FALLTHROUGH */
	case IDC_MAIN_ROOT_MD:
		/* FALLTHROUGH */
	case IDC_MAIN_ROOT_NFS:
		/* FALLTHROUGH */
	case IDC_MAIN_ROOT_DK:
		/* FALLTHROUGH */
	case IDC_MAIN_ROOT_LD:
		EnableWindow(_edit_md_root, _is_checked(IDC_MAIN_ROOT_MD));
	}
}

//
// Option window
//
void
OptionTabWindow::init(HWND w)
{
	struct HpcMenuInterface::HpcMenuPreferences &pref = HPC_PREFERENCE;
	HDC hdc = GetDC(0);
	int dpix = GetDeviceCaps(hdc, LOGPIXELSX);
	int dpiy = GetDeviceCaps(hdc, LOGPIXELSY);
	ReleaseDC(0, hdc);

	_window = w;

	TabWindow::init(_window);
	_spin_edit = GetDlgItem(_window, IDC_OPT_AUTO_INPUT);
	_spin = CreateUpDownControl(WS_CHILD | WS_BORDER | WS_VISIBLE |
	    UDS_SETBUDDYINT | UDS_ALIGNRIGHT,
	    SCALEX(80), SCALEY(0), SCALEX(50), SCALEY(50), _window,
	    IDC_OPT_AUTO_UPDOWN, _app._instance, _spin_edit, 60, 1, 30);
	BOOL onoff = pref.auto_boot ? TRUE : FALSE;
	EnableWindow(_spin_edit, onoff);
	EnableWindow(_spin, onoff);

	SET_CHECK(AUTO, pref.auto_boot);
	if (pref.auto_boot) {
		TCHAR tmp[32];
		wsprintf(tmp, TEXT("%d"), pref.auto_boot);
		Edit_SetText(_spin_edit, tmp);
	}
	SET_CHECK(VIDEO,	pref.reverse_video);
	SET_CHECK(PAUSE,	pref.pause_before_boot);
	SET_CHECK(DEBUG,	pref.load_debug_info);
	SET_CHECK(SAFETY,	pref.safety_message);
	Edit_SetText(GetDlgItem(w, IDC_OPT_EXTKOPT), pref.boot_extra);
}

void
OptionTabWindow::command(int id, int msg)
{
	switch (id) {
	case IDC_OPT_AUTO:
		if (IS_CHECKED(AUTO)) {
			EnableWindow(_spin_edit, TRUE);
			EnableWindow(_spin, TRUE);
		} else {
			EnableWindow(_spin_edit, FALSE);
			EnableWindow(_spin, FALSE);
		}
		break;
	}
}

void
OptionTabWindow::get()
{
	HWND w;
	struct HpcMenuInterface::HpcMenuPreferences &pref = HPC_PREFERENCE;
	if (IS_CHECKED(AUTO)) {
		TCHAR tmp[32];
		Edit_GetText(_spin_edit, tmp, 32);
		pref.auto_boot = _wtoi(tmp);
	} else
		pref.auto_boot = 0;
	pref.reverse_video	= IS_CHECKED(VIDEO);
	pref.pause_before_boot	= IS_CHECKED(PAUSE);
	pref.load_debug_info	= IS_CHECKED(DEBUG);
	pref.safety_message	= IS_CHECKED(SAFETY);

	w = GetDlgItem(_window, IDC_OPT_EXTKOPT);
	Edit_GetText(w, pref.boot_extra, MAX_BOOT_STR);
}
#undef IS_CHECKED
#undef SET_CHECK


//
// Console window
//
void
ConsoleTabWindow::print(TCHAR *buf, BOOL force_display)
{
	int cr;
	TCHAR *p;

	if (force_display)
		goto display;

	if (_filesave) {
		if (_logfile == INVALID_HANDLE_VALUE && !_open_log_file()) {
			_filesave = FALSE;
			_set_check(IDC_CONS_FILESAVE, _filesave);
			EnableWindow(_filename_edit, _filesave);
			goto display;
		}
		DWORD cnt;
		char c;
		for (int i = 0; *buf != TEXT('\0'); buf++) {
			c = *buf & 0x7f;
			WriteFile(_logfile, &c, 1, &cnt, 0);
		}
		FlushFileBuffers(_logfile);
		return;
	}

 display:
	// count number of '\n'
	for (cr = 0, p = buf; p = wcschr(p, TEXT('\n')); cr++, p++)
		continue;

	// total length of new buffer ('\n' -> "\r\n" + '\0')
	size_t sz = (wcslen(buf) + cr + 1) * sizeof(TCHAR);

	p = reinterpret_cast <TCHAR *>(malloc(sz));
	if (p == NULL)
		return;

	// convert newlines
	TCHAR *d = p;
	while (*buf != TEXT('\0')) {
		TCHAR c = *buf++;
		if (c == TEXT('\n'))
			*d++ = TEXT('\r');
		*d++ = c;
	}
	*d = TEXT('\0');

	// append the text and scroll
	int end = Edit_GetTextLength(_edit);
	Edit_SetSel(_edit, end, end);
	Edit_ReplaceSel(_edit, p);
	Edit_ScrollCaret(_edit);
	UpdateWindow(_edit);

	free(p);
}

void
ConsoleTabWindow::init(HWND w)
{
	HDC hdc = GetDC(0);
	int dpix = GetDeviceCaps(hdc, LOGPIXELSX);
	int dpiy = GetDeviceCaps(hdc, LOGPIXELSY);
	ReleaseDC(0, hdc);

	// at this time _window is NULL.
	// use argument of window procedure.
	TabWindow::init(w);
	_edit = GetDlgItem(w, IDC_CONS_EDIT);
	MoveWindow(_edit, SCALEX(5), SCALEY(60),
	    SCALEX(UNSCALEX(_rect.right - _rect.left) - 10),
	    SCALEY(UNSCALEY(_rect.bottom - _rect.top) - 60), TRUE);
	Edit_FmtLines(_edit, TRUE);

	// log file.
	_filename_edit = GetDlgItem(w, IDC_CONS_FILENAME);
	_filesave = FALSE;
	Edit_SetText(_filename_edit, L"bootlog.txt");
	EnableWindow(_filename_edit, _filesave);
}

void
ConsoleTabWindow::command(int id, int msg)
{
	HpcMenuInterface &menu = HPC_MENU;
	struct HpcMenuInterface::cons_hook_args *hook = 0;
	int bit;

	switch(id) {
	case IDC_CONS_FILESAVE:
		_filesave = _is_checked(IDC_CONS_FILESAVE);
		EnableWindow(_filename_edit, _filesave);
		break;
	case IDC_CONS_CHK0:
		/* FALLTHROUGH */
	case IDC_CONS_CHK1:
		/* FALLTHROUGH */
	case IDC_CONS_CHK2:
		/* FALLTHROUGH */
	case IDC_CONS_CHK3:
		/* FALLTHROUGH */
	case IDC_CONS_CHK4:
		/* FALLTHROUGH */
	case IDC_CONS_CHK5:
		/* FALLTHROUGH */
	case IDC_CONS_CHK6:
		/* FALLTHROUGH */
	case IDC_CONS_CHK7:
		bit = 1 << (id - IDC_CONS_CHK_);
		if (SendDlgItemMessage(_window, id, BM_GETCHECK, 0, 0))
			menu._cons_parameter |= bit;
		else
			menu._cons_parameter &= ~bit;
		break;
	case IDC_CONS_BTN0:
		/* FALLTHROUGH */
	case IDC_CONS_BTN1:
		/* FALLTHROUGH */
	case IDC_CONS_BTN2:
		/* FALLTHROUGH */
	case IDC_CONS_BTN3:
		hook = &menu._cons_hook[id - IDC_CONS_BTN_];
		if (hook->func)
			hook->func(hook->arg, menu._cons_parameter);

		break;
	}
}

BOOL
ConsoleTabWindow::_open_log_file()
{
	TCHAR path[MAX_PATH];
	TCHAR filename[MAX_PATH];
	TCHAR filepath[MAX_PATH];

	if (!_find_pref_dir(path)) {
		print(L"couldn't find temporary directory.\n", TRUE);
		return FALSE;
	}

	Edit_GetText(_filename_edit, filename, MAX_PATH);
	wsprintf(filepath, TEXT("\\%s\\%s"), path, filename);
	_logfile = CreateFile(filepath, GENERIC_WRITE, 0, 0,
	    CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
	if (_logfile == INVALID_HANDLE_VALUE)
		return FALSE;

	wsprintf(path, TEXT("log file is %s\n"), filepath);
	print(path, TRUE);

	return TRUE;
}

//
// Common utility
//
static BOOL
is_ignore_directory(TCHAR *filename)
{
	static const TCHAR *dirs[] = {
		// Network (in Japanese)
		(const TCHAR *)"\xcd\x30\xc3\x30\xc8\x30\xef\x30\xfc\x30\xaf\x30\x00\x00",
	};

	for (int i = 0; i < sizeof(dirs) / sizeof(dirs[0]); i++) {
		if (wcscmp(filename, dirs[i]) == 0) {
			return TRUE;
		}
	}
	return FALSE;
}

BOOL
_find_pref_dir(TCHAR *path)
{
	WIN32_FIND_DATA fd;
	HANDLE find;

	lstrcpy(path, TEXT("\\*.*"));
	find = FindFirstFile(path, &fd);

	if (find != INVALID_HANDLE_VALUE) {
		do {
			int attr = fd.dwFileAttributes;
			if ((attr & FILE_ATTRIBUTE_DIRECTORY) &&
			    (attr & FILE_ATTRIBUTE_TEMPORARY) &&
			    !is_ignore_directory(fd.cFileName)) {
				wcscpy(path, fd.cFileName);
				FindClose(find);
				return TRUE;
			}
		} while (FindNextFile(find, &fd));
	}
	FindClose(find);

	return FALSE;
}