grub-symdb.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921
  1. /* grub-symdb.c - manage symbol database */
  2. /*
  3. * BURG - Brand-new Universal loadeR from GRUB
  4. * Copyright 2009 Bean Lee - All Rights Reserved
  5. *
  6. * BURG is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * BURG is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with BURG. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <config.h>
  20. #include <grub/types.h>
  21. #include <grub/util/obj.h>
  22. #include <grub/util/misc.h>
  23. #include <grub/i18n.h>
  24. #include <stdio.h>
  25. #include <unistd.h>
  26. #include <string.h>
  27. #include <stdlib.h>
  28. #include <sys/stat.h>
  29. #define _GNU_SOURCE 1
  30. #include <getopt.h>
  31. #include "progname.h"
  32. int
  33. grub_strcmp (const char *s1, const char *s2)
  34. {
  35. return strcmp (s1, s2);
  36. }
  37. struct grub_symbol_list
  38. {
  39. struct grub_symbol_list *next;
  40. char *name;
  41. struct grub_named_list *defs;
  42. struct grub_named_list *unds;
  43. };
  44. static struct grub_symbol_list *symbol_list;
  45. struct grub_update_list
  46. {
  47. struct grub_update_list *next;
  48. char *name;
  49. struct grub_named_list *add_mods;
  50. struct grub_named_list *del_mods;
  51. struct grub_named_list *cur_mods;
  52. struct grub_named_list *mod_attr;
  53. };
  54. static struct grub_update_list *update_list;
  55. struct grub_mod_syms
  56. {
  57. struct grub_named_list *defs;
  58. struct grub_named_list *unds;
  59. };
  60. void *
  61. grub_sort_list_find (grub_named_list_t head, const char *name)
  62. {
  63. while (head)
  64. {
  65. int r;
  66. r = strcmp (name, head->name);
  67. if (! r)
  68. return head;
  69. if (r < 0)
  70. break;
  71. head = head->next;
  72. }
  73. return 0;
  74. }
  75. static int
  76. grub_sort_list_insert_test (grub_named_list_t new_item, grub_named_list_t item,
  77. void *closure __attribute__ ((unused)))
  78. {
  79. return (strcmp (new_item->name, item->name) < 0);
  80. }
  81. static void
  82. grub_sort_list_insert (grub_named_list_t *head, grub_named_list_t item)
  83. {
  84. grub_list_insert (GRUB_AS_LIST_P (head), GRUB_AS_LIST (item),
  85. (grub_list_test_t) grub_sort_list_insert_test, 0);
  86. }
  87. static void
  88. free_named_list (grub_named_list_t *head)
  89. {
  90. grub_named_list_t cur = *head;
  91. while (cur)
  92. {
  93. grub_named_list_t tmp;
  94. tmp = cur;
  95. cur = cur->next;
  96. free ((char *) tmp->name);
  97. free (tmp);
  98. }
  99. *head = 0;
  100. }
  101. static int
  102. remove_string (grub_named_list_t *head, char *name)
  103. {
  104. grub_named_list_t p;
  105. p = grub_sort_list_find (*head, name);
  106. if (p)
  107. {
  108. grub_list_remove (GRUB_AS_LIST_P (head), GRUB_AS_LIST (p));
  109. free ((char *) p->name);
  110. free (p);
  111. return 1;
  112. }
  113. return 0;
  114. }
  115. static int
  116. insert_string (grub_named_list_t *head, char *name)
  117. {
  118. struct grub_named_list *n;
  119. n = grub_sort_list_find (*head, name);
  120. if (n)
  121. return 0;
  122. n = xmalloc (sizeof (struct grub_named_list));
  123. n->name = xstrdup (name);
  124. grub_sort_list_insert (head, n);
  125. return 1;
  126. }
  127. static struct grub_symbol_list *
  128. insert_symbol (char *name)
  129. {
  130. struct grub_symbol_list *n;
  131. n = grub_sort_list_find (GRUB_AS_NAMED_LIST (symbol_list), name);
  132. if (! n)
  133. {
  134. n = xmalloc (sizeof (struct grub_symbol_list));
  135. n->name = xstrdup (name);
  136. n->defs = 0;
  137. n->unds = 0;
  138. grub_sort_list_insert (GRUB_AS_NAMED_LIST_P (&symbol_list),
  139. GRUB_AS_NAMED_LIST (n));
  140. }
  141. return n;
  142. }
  143. static struct grub_update_list *
  144. insert_update (char *name)
  145. {
  146. struct grub_update_list *n;
  147. n = grub_sort_list_find (GRUB_AS_NAMED_LIST (update_list), name);
  148. if (! n)
  149. {
  150. n = xmalloc (sizeof (struct grub_update_list));
  151. n->name = xstrdup (name);
  152. n->add_mods = 0;
  153. n->del_mods = 0;
  154. n->cur_mods = 0;
  155. n->mod_attr = 0;
  156. grub_sort_list_insert (GRUB_AS_NAMED_LIST_P (&update_list),
  157. GRUB_AS_NAMED_LIST (n));
  158. }
  159. return n;
  160. }
  161. static void
  162. add_update (char *m1, char *m2, int is_add)
  163. {
  164. struct grub_update_list *u;
  165. u = insert_update (m2);
  166. if (is_add)
  167. {
  168. remove_string (&u->del_mods, m1);
  169. insert_string (&u->add_mods, m1);
  170. }
  171. else
  172. insert_string (&u->del_mods, m1);
  173. }
  174. static void
  175. read_symdb (char *path)
  176. {
  177. FILE *fp;
  178. char line[512];
  179. struct grub_symbol_list *sym = 0;
  180. fp = fopen (path, "r");
  181. if (! fp)
  182. return;
  183. while (fgets (line, sizeof (line), fp))
  184. {
  185. char *p;
  186. p = line + strlen (line) - 1;
  187. while ((p >= line) && ((*p == '\r') || (*p == '\n') || (*p == ' ')))
  188. p--;
  189. if (p < line)
  190. continue;
  191. *(p + 1) = 0;
  192. p = line;
  193. while (*p == ' ')
  194. p++;
  195. if (*p == '#')
  196. continue;
  197. if ((*p == '+') || (*p == '-'))
  198. {
  199. if (! sym)
  200. grub_util_error ("No current symbol.");
  201. insert_string ((*p == '+') ? &sym->defs : &sym->unds, p + 1);
  202. }
  203. else
  204. sym = insert_symbol (p);
  205. }
  206. fclose (fp);
  207. }
  208. static void
  209. write_symdb (char *path)
  210. {
  211. FILE *fp;
  212. struct grub_symbol_list *sym;
  213. fp = fopen (path, "w");
  214. if (! fp)
  215. grub_util_error ("Can\'t write to ", path);
  216. sym = symbol_list;
  217. while (sym)
  218. {
  219. struct grub_named_list *mod;
  220. fprintf (fp, "%s\n", sym->name);
  221. mod = sym->defs;
  222. while (mod)
  223. {
  224. fprintf (fp, "+%s\n", mod->name);
  225. mod = mod->next;
  226. }
  227. mod = sym->unds;
  228. while (mod)
  229. {
  230. fprintf (fp, "-%s\n", mod->name);
  231. mod = mod->next;
  232. }
  233. sym = sym->next;
  234. }
  235. fclose (fp);
  236. }
  237. static void
  238. check_symdb (void)
  239. {
  240. struct grub_symbol_list *sym;
  241. sym = symbol_list;
  242. while (sym)
  243. {
  244. if (! sym->defs)
  245. printf ("undefined: %s\n", sym->name);
  246. else if (sym->defs->next)
  247. printf ("duplicate: %s\n", sym->name);
  248. sym = sym->next;
  249. }
  250. }
  251. static void
  252. read_mod_syms (struct grub_mod_syms *mod_syms, char *path)
  253. {
  254. struct grub_util_obj *obj;
  255. char *image;
  256. size_t size;
  257. struct grub_util_obj_symbol *sym;
  258. struct grub_util_obj_reloc *rel;
  259. mod_syms->defs = 0;
  260. mod_syms->unds = 0;
  261. image = grub_util_read_image (path);
  262. size = grub_util_get_image_size (path);
  263. obj = grub_obj_load (image, size, 0);
  264. sym = obj->symbols;
  265. while (sym)
  266. {
  267. insert_string (&mod_syms->defs, sym->name);
  268. sym = sym->next;
  269. }
  270. rel = obj->relocs;
  271. while (rel)
  272. {
  273. if (rel->symbol_name)
  274. insert_string (&mod_syms->unds, rel->symbol_name);
  275. rel = rel->next;
  276. }
  277. grub_obj_free (obj);
  278. free (image);
  279. }
  280. static void
  281. update_mods (char *mods[], const char *dir)
  282. {
  283. for (; mods[0]; mods++)
  284. {
  285. char *mod_name, *mod_path;
  286. struct grub_mod_syms mod_syms;
  287. struct grub_named_list *m;
  288. mod_name = grub_util_get_module_name (mods[0]);
  289. mod_path = grub_util_get_module_path (dir, mod_name);
  290. if (strstr (mod_name, "-symdb"))
  291. {
  292. free (mod_name);
  293. free (mod_path);
  294. continue;
  295. }
  296. insert_update (mod_name);
  297. read_mod_syms (&mod_syms, mod_path);
  298. m = mod_syms.defs;
  299. while (m)
  300. {
  301. struct grub_symbol_list *sym;
  302. struct grub_named_list *n;
  303. sym = insert_symbol ((char *) m->name);
  304. insert_string (&sym->defs, mod_name);
  305. n = sym->unds;
  306. while (n)
  307. {
  308. add_update ((char *) mod_name, (char *) n->name, 1);
  309. n = n->next;
  310. }
  311. m = m->next;
  312. }
  313. m = mod_syms.unds;
  314. while (m)
  315. {
  316. struct grub_symbol_list *sym;
  317. struct grub_named_list *n;
  318. sym = insert_symbol ((char *) m->name);
  319. insert_string (&sym->unds, mod_name);
  320. n = sym->defs;
  321. while (n)
  322. {
  323. add_update ((char *) n->name, (char *) mod_name, 1);
  324. n = n->next;
  325. }
  326. m = m->next;
  327. }
  328. free (mod_name);
  329. free (mod_path);
  330. }
  331. }
  332. static void
  333. remove_mods (char *mods[])
  334. {
  335. for (; mods[0]; mods++)
  336. {
  337. char *mod_name;
  338. struct grub_symbol_list *sym;
  339. mod_name = grub_util_get_module_name (mods[0]);
  340. sym = symbol_list;
  341. while (sym)
  342. {
  343. struct grub_named_list *m, *n;
  344. m = sym->defs;
  345. while (m)
  346. {
  347. int r;
  348. r = strcmp (mod_name, m->name);
  349. if (! r)
  350. break;
  351. if (r < 0)
  352. {
  353. m = 0;
  354. break;
  355. }
  356. m = m->next;
  357. }
  358. n = sym->unds;
  359. while (n)
  360. {
  361. if (m)
  362. {
  363. add_update ((char *) m->name, (char *) n->name, 0);
  364. }
  365. else
  366. {
  367. int r;
  368. r = strcmp (mod_name, n->name);
  369. if (! r)
  370. {
  371. m = sym->defs;
  372. while (m)
  373. {
  374. add_update ((char *) m->name, (char *) n->name, 0);
  375. m = m->next;
  376. }
  377. break;
  378. }
  379. if (r < 0)
  380. break;
  381. }
  382. n = n->next;
  383. }
  384. sym = sym->next;
  385. }
  386. free (mod_name);
  387. }
  388. }
  389. static void
  390. dump_update (void)
  391. {
  392. struct grub_update_list *u;
  393. u = update_list;
  394. while (u)
  395. {
  396. struct grub_named_list *n;
  397. printf ("%s:" , u->name);
  398. n = u->add_mods;
  399. while (n)
  400. {
  401. printf (" +%s", n->name);
  402. n = n->next;
  403. }
  404. n = u->del_mods;
  405. while (n)
  406. {
  407. printf (" -%s", n->name);
  408. n = n->next;
  409. }
  410. printf ("\n");
  411. u = u->next;
  412. }
  413. }
  414. static void
  415. update_deps (struct grub_update_list *u, char *path)
  416. {
  417. struct grub_obj_header *hdr;
  418. struct grub_obj_segment *seg;
  419. struct grub_named_list *n;
  420. char *image, *p;
  421. int size, modified;
  422. image = grub_util_read_image (path);
  423. hdr = (struct grub_obj_header *) image;
  424. seg = &hdr->segments[0];
  425. while (seg->type != GRUB_OBJ_SEGMENT_END)
  426. seg++;
  427. insert_string (&u->mod_attr, "fs");
  428. insert_string (&u->mod_attr, "partmap");
  429. insert_string (&u->mod_attr, "parttool");
  430. insert_string (&u->mod_attr, "command");
  431. insert_string (&u->mod_attr, "handler");
  432. insert_string (&u->mod_attr, "terminal");
  433. insert_string (&u->mod_attr, "video");
  434. p = image + grub_target_to_host32 (seg->offset);
  435. while (*p)
  436. {
  437. insert_string (&u->mod_attr, (char *) p);
  438. p += strlen (p) + 1;
  439. }
  440. size = grub_target_to_host32 (hdr->mod_deps);
  441. size += strlen (image + size) + 1;
  442. p = image + size;
  443. while (*p)
  444. {
  445. insert_string (&u->cur_mods, (char *) p);
  446. p += strlen (p) + 1;
  447. }
  448. modified = 0;
  449. n = u->del_mods;
  450. while (n)
  451. {
  452. modified |= remove_string (&u->cur_mods, (char *) n->name);
  453. n = n->next;
  454. }
  455. n = u->add_mods;
  456. while (n)
  457. {
  458. if (strcmp (n->name, "kernel"))
  459. modified |= insert_string (&u->cur_mods, (char *) n->name);
  460. n = n->next;
  461. }
  462. if (modified)
  463. {
  464. FILE *fp;
  465. fp = fopen (path, "wb");
  466. if (! fp)
  467. grub_util_error ("Can\'t write to %s", path);
  468. grub_util_write_image (image, size, fp);
  469. p = image;
  470. n = u->cur_mods;
  471. while (n)
  472. {
  473. strcpy (p, n->name);
  474. p += strlen (p) + 1;
  475. n = n->next;
  476. }
  477. *(p++) = 0;
  478. grub_util_write_image (image, p - image, fp);
  479. fclose (fp);
  480. }
  481. free (image);
  482. }
  483. static void
  484. write_moddep (struct grub_update_list *u, FILE *fp)
  485. {
  486. struct grub_named_list *n;
  487. if (! u->cur_mods)
  488. return;
  489. fprintf (fp, "%s:", u->name);
  490. n = u->cur_mods;
  491. while (n)
  492. {
  493. fprintf (fp, " %s", n->name);
  494. n = n->next;
  495. }
  496. fprintf (fp, "\n");
  497. free_named_list (&u->cur_mods);
  498. }
  499. static void
  500. write_modattr (struct grub_update_list *u, char *attr, FILE *fp)
  501. {
  502. struct grub_named_list *n, *c;
  503. int len;
  504. if (! u->mod_attr)
  505. return;
  506. n = grub_sort_list_find (u->mod_attr, attr);
  507. if (! n)
  508. return;
  509. len = strlen (attr);
  510. c = n->next;
  511. while (c)
  512. {
  513. grub_named_list_t t;
  514. if ((memcmp (c->name, attr, len)) || (c->name[len] != ':'))
  515. break;
  516. if (c->name[len + 1])
  517. fprintf (fp, "%s: %s\n", c->name + len + 1, u->name);
  518. else
  519. fprintf (fp, "%s\n", u->name);
  520. t = c;
  521. c = c->next;
  522. free ((char *) t->name);
  523. free (t);
  524. }
  525. n->next = c;
  526. }
  527. static void
  528. update_lists (char *dir, char *name, int is_moddep, int has_value)
  529. {
  530. FILE *fp;
  531. struct stat st;
  532. char *path, *image;
  533. struct grub_update_list *u;
  534. char buf[strlen(name) + 5];
  535. sprintf (buf, "%s.lst", name);
  536. path = grub_util_get_path (dir, buf);
  537. if (stat (path, &st) == 0)
  538. {
  539. int size;
  540. size = grub_util_get_image_size (path);
  541. image = xmalloc (size + 1);
  542. grub_util_load_image (path, image);
  543. image[size] = 0;
  544. }
  545. else
  546. image = 0;
  547. fp = fopen (path, "w");
  548. if (! fp)
  549. grub_util_error ("Can\'t write to ", path);
  550. if (image)
  551. {
  552. char *line;
  553. line = image;
  554. while (*line)
  555. {
  556. char *p, *c, *saved;
  557. int n;
  558. n = strcspn (line, "\r\n");
  559. p = line;
  560. line += n;
  561. while ((*line == '\r') || (*line == '\n'))
  562. line++;
  563. saved = p;
  564. *(p + n) = 0;
  565. c = strchr (p, ':');
  566. if (is_moddep)
  567. {
  568. if (! c)
  569. continue;
  570. *c = 0;
  571. }
  572. else
  573. {
  574. if (has_value)
  575. {
  576. if (! c)
  577. continue;
  578. p = c + 1;
  579. while (*p == ' ')
  580. p++;
  581. }
  582. c = 0;
  583. }
  584. u = update_list;
  585. while (u)
  586. {
  587. int r;
  588. r = strcmp (p, u->name);
  589. if (! r)
  590. break;
  591. if (r < 0)
  592. {
  593. u = 0;
  594. break;
  595. }
  596. u = u->next;
  597. }
  598. if (c)
  599. *c = ':';
  600. if (u)
  601. (is_moddep) ? write_moddep (u, fp) : write_modattr (u, name, fp);
  602. else
  603. fprintf (fp, "%s\n", saved);
  604. }
  605. }
  606. u = update_list;
  607. while (u)
  608. {
  609. (is_moddep) ? write_moddep (u, fp) : write_modattr (u, name, fp);
  610. u = u->next;
  611. }
  612. fclose (fp);
  613. free (path);
  614. free (image);
  615. }
  616. static void
  617. apply_update (char *dir)
  618. {
  619. struct grub_update_list *u;
  620. u = update_list;
  621. while (u)
  622. {
  623. char *mod_path;
  624. mod_path = grub_util_get_module_path (dir, u->name);
  625. update_deps (u, mod_path);
  626. free (mod_path);
  627. u = u->next;
  628. }
  629. update_lists (dir, "moddep", 1, 0);
  630. update_lists (dir, "fs", 0, 0);
  631. update_lists (dir, "partmap", 0, 0);
  632. update_lists (dir, "parttool", 0, 1);
  633. update_lists (dir, "command", 0, 1);
  634. update_lists (dir, "handler", 0, 1);
  635. update_lists (dir, "terminal", 0, 1);
  636. update_lists (dir, "video", 0, 0);
  637. }
  638. static struct option options[] =
  639. {
  640. {"directory", required_argument, 0, 'd'},
  641. {"test", no_argument, 0, 't'},
  642. {"help", no_argument, 0, 'h'},
  643. {"version", no_argument, 0, 'V'},
  644. {"verbose", no_argument, 0, 'v'},
  645. {0, 0, 0, 0}
  646. };
  647. static void
  648. usage (int status)
  649. {
  650. if (status)
  651. fprintf (stderr, _("Try `%s --help' for more information.\n"), program_name);
  652. else
  653. printf (_("\
  654. Usage: %s [OPTION]... COMMAND\n\
  655. \n\
  656. Manage the symbol database of GRUB.\n\
  657. \nCommands:\n\
  658. update MODULES add/update modules to the symbol database\n\
  659. remove MODULES remove modules from the symbol databsae\n\
  660. check check for duplicate and unresolved symbols\n\
  661. \n\
  662. -d, --directory=DIR use images and modules under DIR [default=%s]\n\
  663. -t, --test test mode\n\
  664. -h, --help display this message and exit\n\
  665. -V, --version print version information and exit\n\
  666. -v, --verbose print verbose messages\n\
  667. \n\
  668. Report bugs to <%s>.\n\
  669. "), program_name, GRUB_LIBDIR, PACKAGE_BUGREPORT);
  670. exit (status);
  671. }
  672. int
  673. main (int argc, char *argv[])
  674. {
  675. char *dir = NULL;
  676. char *path;
  677. int test_mode = 0;
  678. set_program_name (argv[0]);
  679. grub_util_init_nls ();
  680. while (1)
  681. {
  682. int c = getopt_long (argc, argv, "d:thVv", options, 0);
  683. if (c == -1)
  684. break;
  685. else
  686. switch (c)
  687. {
  688. case 'd':
  689. if (dir)
  690. free (dir);
  691. dir = xstrdup (optarg);
  692. break;
  693. case 't':
  694. test_mode++;
  695. break;
  696. case 'h':
  697. usage (0);
  698. break;
  699. case 'V':
  700. printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
  701. return 0;
  702. case 'v':
  703. verbosity++;
  704. break;
  705. default:
  706. usage (1);
  707. break;
  708. }
  709. }
  710. if (! dir)
  711. dir = xstrdup (GRUB_LIBDIR);
  712. path = grub_util_get_path (dir, "modsym.lst");
  713. argv += optind;
  714. argc -= optind;
  715. if (argc == 0)
  716. grub_util_error ("No command specified.");
  717. read_symdb (path);
  718. if (! strcmp (argv[0], "update"))
  719. {
  720. remove_mods (argv + 1);
  721. update_mods (argv + 1, dir);
  722. if (test_mode)
  723. dump_update ();
  724. else
  725. {
  726. apply_update (dir);
  727. write_symdb (path);
  728. }
  729. }
  730. else if (! strcmp (argv[0], "remove"))
  731. {
  732. remove_mods (argv + 1);
  733. if (test_mode)
  734. dump_update ();
  735. else
  736. {
  737. apply_update (dir);
  738. write_symdb (path);
  739. }
  740. }
  741. else if (! strcmp (argv[0], "check"))
  742. {
  743. check_symdb ();
  744. }
  745. else
  746. grub_util_error ("Unkown command %s.", argv[0]);
  747. free (path);
  748. free (dir);
  749. return 0;
  750. }