sparse.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341
  1. /* Functions for dealing with sparse files
  2. Copyright 2003-2022 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify it
  4. under the terms of the GNU General Public License as published by the
  5. Free Software Foundation; either version 3, or (at your option) any later
  6. version.
  7. This program is distributed in the hope that it will be useful, but
  8. WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  10. Public License for more details.
  11. You should have received a copy of the GNU General Public License along
  12. with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. #include <system.h>
  14. #include <inttostr.h>
  15. #include <quotearg.h>
  16. #include "common.h"
  17. struct tar_sparse_file;
  18. static bool sparse_select_optab (struct tar_sparse_file *file);
  19. enum sparse_scan_state
  20. {
  21. scan_begin,
  22. scan_block,
  23. scan_end
  24. };
  25. struct tar_sparse_optab
  26. {
  27. bool (*init) (struct tar_sparse_file *);
  28. bool (*done) (struct tar_sparse_file *);
  29. bool (*sparse_member_p) (struct tar_sparse_file *);
  30. bool (*dump_header) (struct tar_sparse_file *);
  31. bool (*fixup_header) (struct tar_sparse_file *);
  32. bool (*decode_header) (struct tar_sparse_file *);
  33. bool (*scan_block) (struct tar_sparse_file *, enum sparse_scan_state,
  34. void *);
  35. bool (*dump_region) (struct tar_sparse_file *, size_t);
  36. bool (*extract_region) (struct tar_sparse_file *, size_t);
  37. };
  38. struct tar_sparse_file
  39. {
  40. int fd; /* File descriptor */
  41. bool seekable; /* Is fd seekable? */
  42. off_t offset; /* Current offset in fd if seekable==false.
  43. Otherwise unused */
  44. off_t dumped_size; /* Number of bytes actually written
  45. to the archive */
  46. struct tar_stat_info *stat_info; /* Information about the file */
  47. struct tar_sparse_optab const *optab; /* Operation table */
  48. void *closure; /* Any additional data optab calls might
  49. require */
  50. };
  51. /* Dump zeros to file->fd until offset is reached. It is used instead of
  52. lseek if the output file is not seekable */
  53. static bool
  54. dump_zeros (struct tar_sparse_file *file, off_t offset)
  55. {
  56. static char const zero_buf[BLOCKSIZE];
  57. if (offset < file->offset)
  58. {
  59. errno = EINVAL;
  60. return false;
  61. }
  62. while (file->offset < offset)
  63. {
  64. size_t size = (BLOCKSIZE < offset - file->offset
  65. ? BLOCKSIZE
  66. : offset - file->offset);
  67. ssize_t wrbytes;
  68. wrbytes = write (file->fd, zero_buf, size);
  69. if (wrbytes <= 0)
  70. {
  71. if (wrbytes == 0)
  72. errno = EINVAL;
  73. return false;
  74. }
  75. file->offset += wrbytes;
  76. }
  77. return true;
  78. }
  79. static bool
  80. tar_sparse_member_p (struct tar_sparse_file *file)
  81. {
  82. if (file->optab->sparse_member_p)
  83. return file->optab->sparse_member_p (file);
  84. return false;
  85. }
  86. static bool
  87. tar_sparse_init (struct tar_sparse_file *file)
  88. {
  89. memset (file, 0, sizeof *file);
  90. if (!sparse_select_optab (file))
  91. return false;
  92. if (file->optab->init)
  93. return file->optab->init (file);
  94. return true;
  95. }
  96. static bool
  97. tar_sparse_done (struct tar_sparse_file *file)
  98. {
  99. if (file->optab->done)
  100. return file->optab->done (file);
  101. return true;
  102. }
  103. static bool
  104. tar_sparse_scan (struct tar_sparse_file *file, enum sparse_scan_state state,
  105. void *block)
  106. {
  107. if (file->optab->scan_block)
  108. return file->optab->scan_block (file, state, block);
  109. return true;
  110. }
  111. static bool
  112. tar_sparse_dump_region (struct tar_sparse_file *file, size_t i)
  113. {
  114. if (file->optab->dump_region)
  115. return file->optab->dump_region (file, i);
  116. return false;
  117. }
  118. static bool
  119. tar_sparse_extract_region (struct tar_sparse_file *file, size_t i)
  120. {
  121. if (file->optab->extract_region)
  122. return file->optab->extract_region (file, i);
  123. return false;
  124. }
  125. static bool
  126. tar_sparse_dump_header (struct tar_sparse_file *file)
  127. {
  128. if (file->optab->dump_header)
  129. return file->optab->dump_header (file);
  130. return false;
  131. }
  132. static bool
  133. tar_sparse_decode_header (struct tar_sparse_file *file)
  134. {
  135. if (file->optab->decode_header)
  136. return file->optab->decode_header (file);
  137. return true;
  138. }
  139. static bool
  140. tar_sparse_fixup_header (struct tar_sparse_file *file)
  141. {
  142. if (file->optab->fixup_header)
  143. return file->optab->fixup_header (file);
  144. return true;
  145. }
  146. static bool
  147. lseek_or_error (struct tar_sparse_file *file, off_t offset)
  148. {
  149. if (file->seekable
  150. ? lseek (file->fd, offset, SEEK_SET) < 0
  151. : ! dump_zeros (file, offset))
  152. {
  153. seek_diag_details (file->stat_info->orig_file_name, offset);
  154. return false;
  155. }
  156. return true;
  157. }
  158. /* Takes a blockful of data and basically cruises through it to see if
  159. it's made *entirely* of zeros, returning a 0 the instant it finds
  160. something that is a nonzero, i.e., useful data. */
  161. static bool
  162. zero_block_p (char const *buffer, size_t size)
  163. {
  164. while (size--)
  165. if (*buffer++)
  166. return false;
  167. return true;
  168. }
  169. static void
  170. sparse_add_map (struct tar_stat_info *st, struct sp_array const *sp)
  171. {
  172. struct sp_array *sparse_map = st->sparse_map;
  173. size_t avail = st->sparse_map_avail;
  174. if (avail == st->sparse_map_size)
  175. st->sparse_map = sparse_map =
  176. x2nrealloc (sparse_map, &st->sparse_map_size, sizeof *sparse_map);
  177. sparse_map[avail] = *sp;
  178. st->sparse_map_avail = avail + 1;
  179. }
  180. /* Scan the sparse file byte-by-byte and create its map. */
  181. static bool
  182. sparse_scan_file_raw (struct tar_sparse_file *file)
  183. {
  184. struct tar_stat_info *st = file->stat_info;
  185. int fd = file->fd;
  186. char buffer[BLOCKSIZE];
  187. size_t count = 0;
  188. off_t offset = 0;
  189. struct sp_array sp = {0, 0};
  190. st->archive_file_size = 0;
  191. if (!tar_sparse_scan (file, scan_begin, NULL))
  192. return false;
  193. while ((count = blocking_read (fd, buffer, sizeof buffer)) != 0
  194. && count != SAFE_READ_ERROR)
  195. {
  196. /* Analyze the block. */
  197. if (zero_block_p (buffer, count))
  198. {
  199. if (sp.numbytes)
  200. {
  201. sparse_add_map (st, &sp);
  202. sp.numbytes = 0;
  203. if (!tar_sparse_scan (file, scan_block, NULL))
  204. return false;
  205. }
  206. }
  207. else
  208. {
  209. if (sp.numbytes == 0)
  210. sp.offset = offset;
  211. sp.numbytes += count;
  212. st->archive_file_size += count;
  213. if (!tar_sparse_scan (file, scan_block, buffer))
  214. return false;
  215. }
  216. offset += count;
  217. }
  218. /* save one more sparse segment of length 0 to indicate that
  219. the file ends with a hole */
  220. if (sp.numbytes == 0)
  221. sp.offset = offset;
  222. sparse_add_map (st, &sp);
  223. st->archive_file_size += count;
  224. return tar_sparse_scan (file, scan_end, NULL);
  225. }
  226. static bool
  227. sparse_scan_file_wholesparse (struct tar_sparse_file *file)
  228. {
  229. struct tar_stat_info *st = file->stat_info;
  230. struct sp_array sp = {0, 0};
  231. /* Note that this function is called only for truly sparse files of size >= 1
  232. block size (checked via ST_IS_SPARSE before). See the thread
  233. http://www.mail-archive.com/[email protected]/msg04209.html for more info */
  234. if (ST_NBLOCKS (st->stat) == 0)
  235. {
  236. st->archive_file_size = 0;
  237. sp.offset = st->stat.st_size;
  238. sparse_add_map (st, &sp);
  239. return true;
  240. }
  241. return false;
  242. }
  243. #ifdef SEEK_HOLE
  244. /* Try to engage SEEK_HOLE/SEEK_DATA feature. */
  245. static bool
  246. sparse_scan_file_seek (struct tar_sparse_file *file)
  247. {
  248. struct tar_stat_info *st = file->stat_info;
  249. int fd = file->fd;
  250. struct sp_array sp = {0, 0};
  251. off_t offset = 0;
  252. off_t data_offset;
  253. off_t hole_offset;
  254. st->archive_file_size = 0;
  255. for (;;)
  256. {
  257. /* locate first chunk of data */
  258. data_offset = lseek (fd, offset, SEEK_DATA);
  259. if (data_offset == (off_t)-1)
  260. /* ENXIO == EOF; error otherwise */
  261. {
  262. if (errno == ENXIO)
  263. {
  264. /* file ends with hole, add one more empty chunk of data */
  265. sp.numbytes = 0;
  266. sp.offset = st->stat.st_size;
  267. sparse_add_map (st, &sp);
  268. return true;
  269. }
  270. return false;
  271. }
  272. hole_offset = lseek (fd, data_offset, SEEK_HOLE);
  273. /* according to specs, if FS does not fully support
  274. SEEK_DATA/SEEK_HOLE it may just implement kind of "wrapper" around
  275. classic lseek() call. We must detect it here and try to use other
  276. hole-detection methods. */
  277. if (offset == 0 /* first loop */
  278. && data_offset == 0
  279. && hole_offset == st->stat.st_size)
  280. {
  281. lseek (fd, 0, SEEK_SET);
  282. return false;
  283. }
  284. sp.offset = data_offset;
  285. sp.numbytes = hole_offset - data_offset;
  286. sparse_add_map (st, &sp);
  287. st->archive_file_size += sp.numbytes;
  288. offset = hole_offset;
  289. }
  290. }
  291. #endif
  292. static bool
  293. sparse_scan_file (struct tar_sparse_file *file)
  294. {
  295. /* always check for completely sparse files */
  296. if (sparse_scan_file_wholesparse (file))
  297. return true;
  298. switch (hole_detection)
  299. {
  300. case HOLE_DETECTION_DEFAULT:
  301. case HOLE_DETECTION_SEEK:
  302. #ifdef SEEK_HOLE
  303. if (sparse_scan_file_seek (file))
  304. return true;
  305. #else
  306. if (hole_detection == HOLE_DETECTION_SEEK)
  307. WARN((0, 0,
  308. _("\"seek\" hole detection is not supported, using \"raw\".")));
  309. /* fall back to "raw" for this and all other files */
  310. hole_detection = HOLE_DETECTION_RAW;
  311. #endif
  312. FALLTHROUGH;
  313. case HOLE_DETECTION_RAW:
  314. if (sparse_scan_file_raw (file))
  315. return true;
  316. }
  317. return false;
  318. }
  319. static struct tar_sparse_optab const oldgnu_optab;
  320. static struct tar_sparse_optab const star_optab;
  321. static struct tar_sparse_optab const pax_optab;
  322. static bool
  323. sparse_select_optab (struct tar_sparse_file *file)
  324. {
  325. switch (current_format == DEFAULT_FORMAT ? archive_format : current_format)
  326. {
  327. case V7_FORMAT:
  328. case USTAR_FORMAT:
  329. return false;
  330. case OLDGNU_FORMAT:
  331. case GNU_FORMAT: /*FIXME: This one should disappear? */
  332. file->optab = &oldgnu_optab;
  333. break;
  334. case POSIX_FORMAT:
  335. file->optab = &pax_optab;
  336. break;
  337. case STAR_FORMAT:
  338. file->optab = &star_optab;
  339. break;
  340. default:
  341. return false;
  342. }
  343. return true;
  344. }
  345. static bool
  346. sparse_dump_region (struct tar_sparse_file *file, size_t i)
  347. {
  348. union block *blk;
  349. off_t bytes_left = file->stat_info->sparse_map[i].numbytes;
  350. if (!lseek_or_error (file, file->stat_info->sparse_map[i].offset))
  351. return false;
  352. while (bytes_left > 0)
  353. {
  354. size_t bufsize = (bytes_left > BLOCKSIZE) ? BLOCKSIZE : bytes_left;
  355. size_t bytes_read;
  356. blk = find_next_block ();
  357. bytes_read = safe_read (file->fd, blk->buffer, bufsize);
  358. if (bytes_read == SAFE_READ_ERROR)
  359. {
  360. read_diag_details (file->stat_info->orig_file_name,
  361. (file->stat_info->sparse_map[i].offset
  362. + file->stat_info->sparse_map[i].numbytes
  363. - bytes_left),
  364. bufsize);
  365. return false;
  366. }
  367. else if (bytes_read == 0)
  368. {
  369. char buf[UINTMAX_STRSIZE_BOUND];
  370. struct stat st;
  371. size_t n;
  372. if (fstat (file->fd, &st) == 0)
  373. n = file->stat_info->stat.st_size - st.st_size;
  374. else
  375. n = file->stat_info->stat.st_size
  376. - (file->stat_info->sparse_map[i].offset
  377. + file->stat_info->sparse_map[i].numbytes
  378. - bytes_left);
  379. WARNOPT (WARN_FILE_SHRANK,
  380. (0, 0,
  381. ngettext ("%s: File shrank by %s byte; padding with zeros",
  382. "%s: File shrank by %s bytes; padding with zeros",
  383. n),
  384. quotearg_colon (file->stat_info->orig_file_name),
  385. STRINGIFY_BIGINT (n, buf)));
  386. if (! ignore_failed_read_option)
  387. set_exit_status (TAREXIT_DIFFERS);
  388. return false;
  389. }
  390. memset (blk->buffer + bytes_read, 0, BLOCKSIZE - bytes_read);
  391. bytes_left -= bytes_read;
  392. file->dumped_size += bytes_read;
  393. set_next_block_after (blk);
  394. }
  395. return true;
  396. }
  397. static bool
  398. sparse_extract_region (struct tar_sparse_file *file, size_t i)
  399. {
  400. off_t write_size;
  401. if (!lseek_or_error (file, file->stat_info->sparse_map[i].offset))
  402. return false;
  403. write_size = file->stat_info->sparse_map[i].numbytes;
  404. if (write_size == 0)
  405. {
  406. /* Last block of the file is a hole */
  407. if (file->seekable && sys_truncate (file->fd))
  408. truncate_warn (file->stat_info->orig_file_name);
  409. }
  410. else while (write_size > 0)
  411. {
  412. size_t count;
  413. size_t wrbytes = (write_size > BLOCKSIZE) ? BLOCKSIZE : write_size;
  414. union block *blk = find_next_block ();
  415. if (!blk)
  416. {
  417. ERROR ((0, 0, _("Unexpected EOF in archive")));
  418. return false;
  419. }
  420. set_next_block_after (blk);
  421. file->dumped_size += BLOCKSIZE;
  422. count = blocking_write (file->fd, blk->buffer, wrbytes);
  423. write_size -= count;
  424. mv_size_left (file->stat_info->archive_file_size - file->dumped_size);
  425. file->offset += count;
  426. if (count != wrbytes)
  427. {
  428. write_error_details (file->stat_info->orig_file_name,
  429. count, wrbytes);
  430. return false;
  431. }
  432. }
  433. return true;
  434. }
  435. /* Interface functions */
  436. enum dump_status
  437. sparse_dump_file (int fd, struct tar_stat_info *st)
  438. {
  439. bool rc;
  440. struct tar_sparse_file file;
  441. if (!tar_sparse_init (&file))
  442. return dump_status_not_implemented;
  443. file.stat_info = st;
  444. file.fd = fd;
  445. file.seekable = true; /* File *must* be seekable for dump to work */
  446. rc = sparse_scan_file (&file);
  447. if (rc && file.optab->dump_region)
  448. {
  449. tar_sparse_dump_header (&file);
  450. if (fd >= 0)
  451. {
  452. size_t i;
  453. mv_begin_write (file.stat_info->file_name,
  454. file.stat_info->stat.st_size,
  455. file.stat_info->archive_file_size - file.dumped_size);
  456. for (i = 0; rc && i < file.stat_info->sparse_map_avail; i++)
  457. rc = tar_sparse_dump_region (&file, i);
  458. }
  459. }
  460. pad_archive (file.stat_info->archive_file_size - file.dumped_size);
  461. return (tar_sparse_done (&file) && rc) ? dump_status_ok : dump_status_short;
  462. }
  463. bool
  464. sparse_member_p (struct tar_stat_info *st)
  465. {
  466. struct tar_sparse_file file;
  467. if (!tar_sparse_init (&file))
  468. return false;
  469. file.stat_info = st;
  470. return tar_sparse_member_p (&file);
  471. }
  472. bool
  473. sparse_fixup_header (struct tar_stat_info *st)
  474. {
  475. struct tar_sparse_file file;
  476. if (!tar_sparse_init (&file))
  477. return false;
  478. file.stat_info = st;
  479. return tar_sparse_fixup_header (&file);
  480. }
  481. enum dump_status
  482. sparse_extract_file (int fd, struct tar_stat_info *st, off_t *size)
  483. {
  484. bool rc = true;
  485. struct tar_sparse_file file;
  486. size_t i;
  487. if (!tar_sparse_init (&file))
  488. {
  489. *size = st->stat.st_size;
  490. return dump_status_not_implemented;
  491. }
  492. file.stat_info = st;
  493. file.fd = fd;
  494. file.seekable = lseek (fd, 0, SEEK_SET) == 0;
  495. file.offset = 0;
  496. rc = tar_sparse_decode_header (&file);
  497. for (i = 0; rc && i < file.stat_info->sparse_map_avail; i++)
  498. rc = tar_sparse_extract_region (&file, i);
  499. *size = file.stat_info->archive_file_size - file.dumped_size;
  500. return (tar_sparse_done (&file) && rc) ? dump_status_ok : dump_status_short;
  501. }
  502. enum dump_status
  503. sparse_skim_file (struct tar_stat_info *st, bool must_copy)
  504. {
  505. bool rc = true;
  506. struct tar_sparse_file file;
  507. if (!tar_sparse_init (&file))
  508. return dump_status_not_implemented;
  509. file.stat_info = st;
  510. file.fd = -1;
  511. rc = tar_sparse_decode_header (&file);
  512. skim_file (file.stat_info->archive_file_size - file.dumped_size, must_copy);
  513. return (tar_sparse_done (&file) && rc) ? dump_status_ok : dump_status_short;
  514. }
  515. static bool
  516. check_sparse_region (struct tar_sparse_file *file, off_t beg, off_t end)
  517. {
  518. if (!lseek_or_error (file, beg))
  519. return false;
  520. while (beg < end)
  521. {
  522. size_t bytes_read;
  523. size_t rdsize = BLOCKSIZE < end - beg ? BLOCKSIZE : end - beg;
  524. char diff_buffer[BLOCKSIZE];
  525. bytes_read = safe_read (file->fd, diff_buffer, rdsize);
  526. if (bytes_read == SAFE_READ_ERROR)
  527. {
  528. read_diag_details (file->stat_info->orig_file_name,
  529. beg,
  530. rdsize);
  531. return false;
  532. }
  533. else if (bytes_read == 0)
  534. {
  535. report_difference (file->stat_info, _("Size differs"));
  536. return false;
  537. }
  538. if (!zero_block_p (diff_buffer, bytes_read))
  539. {
  540. char begbuf[INT_BUFSIZE_BOUND (off_t)];
  541. report_difference (file->stat_info,
  542. _("File fragment at %s is not a hole"),
  543. offtostr (beg, begbuf));
  544. return false;
  545. }
  546. beg += bytes_read;
  547. }
  548. return true;
  549. }
  550. static bool
  551. check_data_region (struct tar_sparse_file *file, size_t i)
  552. {
  553. off_t size_left;
  554. if (!lseek_or_error (file, file->stat_info->sparse_map[i].offset))
  555. return false;
  556. size_left = file->stat_info->sparse_map[i].numbytes;
  557. mv_size_left (file->stat_info->archive_file_size - file->dumped_size);
  558. while (size_left > 0)
  559. {
  560. size_t bytes_read;
  561. size_t rdsize = (size_left > BLOCKSIZE) ? BLOCKSIZE : size_left;
  562. char diff_buffer[BLOCKSIZE];
  563. union block *blk = find_next_block ();
  564. if (!blk)
  565. {
  566. ERROR ((0, 0, _("Unexpected EOF in archive")));
  567. return false;
  568. }
  569. set_next_block_after (blk);
  570. file->dumped_size += BLOCKSIZE;
  571. bytes_read = safe_read (file->fd, diff_buffer, rdsize);
  572. if (bytes_read == SAFE_READ_ERROR)
  573. {
  574. read_diag_details (file->stat_info->orig_file_name,
  575. (file->stat_info->sparse_map[i].offset
  576. + file->stat_info->sparse_map[i].numbytes
  577. - size_left),
  578. rdsize);
  579. return false;
  580. }
  581. else if (bytes_read == 0)
  582. {
  583. report_difference (&current_stat_info, _("Size differs"));
  584. return false;
  585. }
  586. size_left -= bytes_read;
  587. mv_size_left (file->stat_info->archive_file_size - file->dumped_size);
  588. if (memcmp (blk->buffer, diff_buffer, bytes_read))
  589. {
  590. report_difference (file->stat_info, _("Contents differ"));
  591. return false;
  592. }
  593. }
  594. return true;
  595. }
  596. bool
  597. sparse_diff_file (int fd, struct tar_stat_info *st)
  598. {
  599. bool rc = true;
  600. struct tar_sparse_file file;
  601. size_t i;
  602. off_t offset = 0;
  603. if (!tar_sparse_init (&file))
  604. return false;
  605. file.stat_info = st;
  606. file.fd = fd;
  607. file.seekable = true; /* File *must* be seekable for compare to work */
  608. rc = tar_sparse_decode_header (&file);
  609. mv_begin_read (st);
  610. for (i = 0; rc && i < file.stat_info->sparse_map_avail; i++)
  611. {
  612. rc = check_sparse_region (&file,
  613. offset, file.stat_info->sparse_map[i].offset)
  614. && check_data_region (&file, i);
  615. offset = file.stat_info->sparse_map[i].offset
  616. + file.stat_info->sparse_map[i].numbytes;
  617. }
  618. if (!rc)
  619. skim_file (file.stat_info->archive_file_size - file.dumped_size, false);
  620. mv_end ();
  621. tar_sparse_done (&file);
  622. return rc;
  623. }
  624. /* Old GNU Format. The sparse file information is stored in the
  625. oldgnu_header in the following manner:
  626. The header is marked with type 'S'. Its 'size' field contains
  627. the cumulative size of all non-empty blocks of the file. The
  628. actual file size is stored in 'realsize' member of oldgnu_header.
  629. The map of the file is stored in a list of 'struct sparse'.
  630. Each struct contains offset to the block of data and its
  631. size (both as octal numbers). The first file header contains
  632. at most 4 such structs (SPARSES_IN_OLDGNU_HEADER). If the map
  633. contains more structs, then the field 'isextended' of the main
  634. header is set to 1 (binary) and the 'struct sparse_header'
  635. header follows, containing at most 21 following structs
  636. (SPARSES_IN_SPARSE_HEADER). If more structs follow, 'isextended'
  637. field of the extended header is set and next next extension header
  638. follows, etc... */
  639. enum oldgnu_add_status
  640. {
  641. add_ok,
  642. add_finish,
  643. add_fail
  644. };
  645. static bool
  646. oldgnu_sparse_member_p (struct tar_sparse_file *file MAYBE_UNUSED)
  647. {
  648. return current_header->header.typeflag == GNUTYPE_SPARSE;
  649. }
  650. /* Add a sparse item to the sparse file and its obstack */
  651. static enum oldgnu_add_status
  652. oldgnu_add_sparse (struct tar_sparse_file *file, struct sparse *s)
  653. {
  654. struct sp_array sp;
  655. if (s->numbytes[0] == '\0')
  656. return add_finish;
  657. sp.offset = OFF_FROM_HEADER (s->offset);
  658. sp.numbytes = OFF_FROM_HEADER (s->numbytes);
  659. if (sp.offset < 0 || sp.numbytes < 0
  660. || INT_ADD_OVERFLOW (sp.offset, sp.numbytes)
  661. || file->stat_info->stat.st_size < sp.offset + sp.numbytes
  662. || file->stat_info->archive_file_size < 0)
  663. return add_fail;
  664. sparse_add_map (file->stat_info, &sp);
  665. return add_ok;
  666. }
  667. static bool
  668. oldgnu_fixup_header (struct tar_sparse_file *file)
  669. {
  670. /* NOTE! st_size was initialized from the header
  671. which actually contains archived size. The following fixes it */
  672. off_t realsize = OFF_FROM_HEADER (current_header->oldgnu_header.realsize);
  673. file->stat_info->archive_file_size = file->stat_info->stat.st_size;
  674. file->stat_info->stat.st_size = max (0, realsize);
  675. return 0 <= realsize;
  676. }
  677. /* Convert old GNU format sparse data to internal representation */
  678. static bool
  679. oldgnu_get_sparse_info (struct tar_sparse_file *file)
  680. {
  681. size_t i;
  682. union block *h = current_header;
  683. int ext_p;
  684. enum oldgnu_add_status rc;
  685. file->stat_info->sparse_map_avail = 0;
  686. for (i = 0; i < SPARSES_IN_OLDGNU_HEADER; i++)
  687. {
  688. rc = oldgnu_add_sparse (file, &h->oldgnu_header.sp[i]);
  689. if (rc != add_ok)
  690. break;
  691. }
  692. for (ext_p = h->oldgnu_header.isextended;
  693. rc == add_ok && ext_p; ext_p = h->sparse_header.isextended)
  694. {
  695. h = find_next_block ();
  696. if (!h)
  697. {
  698. ERROR ((0, 0, _("Unexpected EOF in archive")));
  699. return false;
  700. }
  701. set_next_block_after (h);
  702. for (i = 0; i < SPARSES_IN_SPARSE_HEADER && rc == add_ok; i++)
  703. rc = oldgnu_add_sparse (file, &h->sparse_header.sp[i]);
  704. }
  705. if (rc == add_fail)
  706. {
  707. ERROR ((0, 0, _("%s: invalid sparse archive member"),
  708. file->stat_info->orig_file_name));
  709. return false;
  710. }
  711. return true;
  712. }
  713. static void
  714. oldgnu_store_sparse_info (struct tar_sparse_file *file, size_t *pindex,
  715. struct sparse *sp, size_t sparse_size)
  716. {
  717. for (; *pindex < file->stat_info->sparse_map_avail
  718. && sparse_size > 0; sparse_size--, sp++, ++*pindex)
  719. {
  720. OFF_TO_CHARS (file->stat_info->sparse_map[*pindex].offset,
  721. sp->offset);
  722. OFF_TO_CHARS (file->stat_info->sparse_map[*pindex].numbytes,
  723. sp->numbytes);
  724. }
  725. }
  726. static bool
  727. oldgnu_dump_header (struct tar_sparse_file *file)
  728. {
  729. off_t block_ordinal = current_block_ordinal ();
  730. union block *blk;
  731. size_t i;
  732. blk = start_header (file->stat_info);
  733. blk->header.typeflag = GNUTYPE_SPARSE;
  734. if (file->stat_info->sparse_map_avail > SPARSES_IN_OLDGNU_HEADER)
  735. blk->oldgnu_header.isextended = 1;
  736. /* Store the real file size */
  737. OFF_TO_CHARS (file->stat_info->stat.st_size, blk->oldgnu_header.realsize);
  738. /* Store the effective (shrunken) file size */
  739. OFF_TO_CHARS (file->stat_info->archive_file_size, blk->header.size);
  740. i = 0;
  741. oldgnu_store_sparse_info (file, &i,
  742. blk->oldgnu_header.sp,
  743. SPARSES_IN_OLDGNU_HEADER);
  744. blk->oldgnu_header.isextended = i < file->stat_info->sparse_map_avail;
  745. finish_header (file->stat_info, blk, block_ordinal);
  746. while (i < file->stat_info->sparse_map_avail)
  747. {
  748. blk = find_next_block ();
  749. memset (blk->buffer, 0, BLOCKSIZE);
  750. oldgnu_store_sparse_info (file, &i,
  751. blk->sparse_header.sp,
  752. SPARSES_IN_SPARSE_HEADER);
  753. if (i < file->stat_info->sparse_map_avail)
  754. blk->sparse_header.isextended = 1;
  755. set_next_block_after (blk);
  756. }
  757. return true;
  758. }
  759. static struct tar_sparse_optab const oldgnu_optab = {
  760. NULL, /* No init function */
  761. NULL, /* No done function */
  762. oldgnu_sparse_member_p,
  763. oldgnu_dump_header,
  764. oldgnu_fixup_header,
  765. oldgnu_get_sparse_info,
  766. NULL, /* No scan_block function */
  767. sparse_dump_region,
  768. sparse_extract_region,
  769. };
  770. /* Star */
  771. static bool
  772. star_sparse_member_p (struct tar_sparse_file *file MAYBE_UNUSED)
  773. {
  774. return current_header->header.typeflag == GNUTYPE_SPARSE;
  775. }
  776. static bool
  777. star_fixup_header (struct tar_sparse_file *file)
  778. {
  779. /* NOTE! st_size was initialized from the header
  780. which actually contains archived size. The following fixes it */
  781. off_t realsize = OFF_FROM_HEADER (current_header->star_in_header.realsize);
  782. file->stat_info->archive_file_size = file->stat_info->stat.st_size;
  783. file->stat_info->stat.st_size = max (0, realsize);
  784. return 0 <= realsize;
  785. }
  786. /* Convert STAR format sparse data to internal representation */
  787. static bool
  788. star_get_sparse_info (struct tar_sparse_file *file)
  789. {
  790. size_t i;
  791. union block *h = current_header;
  792. int ext_p;
  793. enum oldgnu_add_status rc = add_ok;
  794. file->stat_info->sparse_map_avail = 0;
  795. if (h->star_in_header.prefix[0] == '\0'
  796. && h->star_in_header.sp[0].offset[10] != '\0')
  797. {
  798. /* Old star format */
  799. for (i = 0; i < SPARSES_IN_STAR_HEADER; i++)
  800. {
  801. rc = oldgnu_add_sparse (file, &h->star_in_header.sp[i]);
  802. if (rc != add_ok)
  803. break;
  804. }
  805. ext_p = h->star_in_header.isextended;
  806. }
  807. else
  808. ext_p = 1;
  809. for (; rc == add_ok && ext_p; ext_p = h->star_ext_header.isextended)
  810. {
  811. h = find_next_block ();
  812. if (!h)
  813. {
  814. ERROR ((0, 0, _("Unexpected EOF in archive")));
  815. return false;
  816. }
  817. set_next_block_after (h);
  818. for (i = 0; i < SPARSES_IN_STAR_EXT_HEADER && rc == add_ok; i++)
  819. rc = oldgnu_add_sparse (file, &h->star_ext_header.sp[i]);
  820. file->dumped_size += BLOCKSIZE;
  821. }
  822. if (rc == add_fail)
  823. {
  824. ERROR ((0, 0, _("%s: invalid sparse archive member"),
  825. file->stat_info->orig_file_name));
  826. return false;
  827. }
  828. return true;
  829. }
  830. static struct tar_sparse_optab const star_optab = {
  831. NULL, /* No init function */
  832. NULL, /* No done function */
  833. star_sparse_member_p,
  834. NULL,
  835. star_fixup_header,
  836. star_get_sparse_info,
  837. NULL, /* No scan_block function */
  838. NULL, /* No dump region function */
  839. sparse_extract_region,
  840. };
  841. /* GNU PAX sparse file format. There are several versions:
  842. * 0.0
  843. The initial version of sparse format used by tar 1.14-1.15.1.
  844. The sparse file map is stored in x header:
  845. GNU.sparse.size Real size of the stored file
  846. GNU.sparse.numblocks Number of blocks in the sparse map
  847. repeat numblocks time
  848. GNU.sparse.offset Offset of the next data block
  849. GNU.sparse.numbytes Size of the next data block
  850. end repeat
  851. This has been reported as conflicting with the POSIX specs. The reason is
  852. that offsets and sizes of non-zero data blocks were stored in multiple
  853. instances of GNU.sparse.offset/GNU.sparse.numbytes variables, whereas
  854. POSIX requires the latest occurrence of the variable to override all
  855. previous occurrences.
  856. To avoid this incompatibility two following versions were introduced.
  857. * 0.1
  858. Used by tar 1.15.2 -- 1.15.91 (alpha releases).
  859. The sparse file map is stored in
  860. x header:
  861. GNU.sparse.size Real size of the stored file
  862. GNU.sparse.numblocks Number of blocks in the sparse map
  863. GNU.sparse.map Map of non-null data chunks. A string consisting
  864. of comma-separated values "offset,size[,offset,size]..."
  865. The resulting GNU.sparse.map string can be *very* long. While POSIX does not
  866. impose any limit on the length of a x header variable, this can confuse some
  867. tars.
  868. * 1.0
  869. Starting from this version, the exact sparse format version is specified
  870. explicitly in the header using the following variables:
  871. GNU.sparse.major Major version
  872. GNU.sparse.minor Minor version
  873. X header keeps the following variables:
  874. GNU.sparse.name Real file name of the sparse file
  875. GNU.sparse.realsize Real size of the stored file (corresponds to the old
  876. GNU.sparse.size variable)
  877. The name field of the ustar header is constructed using the pattern
  878. "%d/GNUSparseFile.%p/%f".
  879. The sparse map itself is stored in the file data block, preceding the actual
  880. file data. It consists of a series of octal numbers of arbitrary length,
  881. delimited by newlines. The map is padded with nulls to the nearest block
  882. boundary.
  883. The first number gives the number of entries in the map. Following are map
  884. entries, each one consisting of two numbers giving the offset and size of
  885. the data block it describes.
  886. The format is designed in such a way that non-posix aware tars and tars not
  887. supporting GNU.sparse.* keywords will extract each sparse file in its
  888. condensed form with the file map attached and will place it into a separate
  889. directory. Then, using a simple program it would be possible to expand the
  890. file to its original form even without GNU tar.
  891. Bu default, v.1.0 archives are created. To use other formats,
  892. --sparse-version option is provided. Additionally, v.0.0 can be obtained
  893. by deleting GNU.sparse.map from 0.1 format: --sparse-version 0.1
  894. --pax-option delete=GNU.sparse.map
  895. */
  896. static bool
  897. pax_sparse_member_p (struct tar_sparse_file *file)
  898. {
  899. return file->stat_info->sparse_map_avail > 0
  900. || file->stat_info->sparse_major > 0;
  901. }
  902. /* Start a header that uses the effective (shrunken) file size. */
  903. static union block *
  904. pax_start_header (struct tar_stat_info *st)
  905. {
  906. off_t realsize = st->stat.st_size;
  907. union block *blk;
  908. st->stat.st_size = st->archive_file_size;
  909. blk = start_header (st);
  910. st->stat.st_size = realsize;
  911. return blk;
  912. }
  913. static bool
  914. pax_dump_header_0 (struct tar_sparse_file *file)
  915. {
  916. off_t block_ordinal = current_block_ordinal ();
  917. union block *blk;
  918. size_t i;
  919. char nbuf[UINTMAX_STRSIZE_BOUND];
  920. struct sp_array *map = file->stat_info->sparse_map;
  921. char *save_file_name = NULL;
  922. /* Store the real file size */
  923. xheader_store ("GNU.sparse.size", file->stat_info, NULL);
  924. xheader_store ("GNU.sparse.numblocks", file->stat_info, NULL);
  925. if (xheader_keyword_deleted_p ("GNU.sparse.map")
  926. || tar_sparse_minor == 0)
  927. {
  928. for (i = 0; i < file->stat_info->sparse_map_avail; i++)
  929. {
  930. xheader_store ("GNU.sparse.offset", file->stat_info, &i);
  931. xheader_store ("GNU.sparse.numbytes", file->stat_info, &i);
  932. }
  933. }
  934. else
  935. {
  936. xheader_store ("GNU.sparse.name", file->stat_info, NULL);
  937. save_file_name = file->stat_info->file_name;
  938. file->stat_info->file_name = xheader_format_name (file->stat_info,
  939. "%d/GNUSparseFile.%p/%f", 0);
  940. xheader_string_begin (&file->stat_info->xhdr);
  941. for (i = 0; i < file->stat_info->sparse_map_avail; i++)
  942. {
  943. if (i)
  944. xheader_string_add (&file->stat_info->xhdr, ",");
  945. xheader_string_add (&file->stat_info->xhdr,
  946. umaxtostr (map[i].offset, nbuf));
  947. xheader_string_add (&file->stat_info->xhdr, ",");
  948. xheader_string_add (&file->stat_info->xhdr,
  949. umaxtostr (map[i].numbytes, nbuf));
  950. }
  951. if (!xheader_string_end (&file->stat_info->xhdr,
  952. "GNU.sparse.map"))
  953. {
  954. free (file->stat_info->file_name);
  955. file->stat_info->file_name = save_file_name;
  956. return false;
  957. }
  958. }
  959. blk = pax_start_header (file->stat_info);
  960. finish_header (file->stat_info, blk, block_ordinal);
  961. if (save_file_name)
  962. {
  963. free (file->stat_info->file_name);
  964. file->stat_info->file_name = save_file_name;
  965. }
  966. return true;
  967. }
  968. static bool
  969. pax_dump_header_1 (struct tar_sparse_file *file)
  970. {
  971. off_t block_ordinal = current_block_ordinal ();
  972. union block *blk;
  973. char *p, *q;
  974. size_t i;
  975. char nbuf[UINTMAX_STRSIZE_BOUND];
  976. off_t size = 0;
  977. struct sp_array *map = file->stat_info->sparse_map;
  978. char *save_file_name = file->stat_info->file_name;
  979. #define COPY_STRING(b,dst,src) do \
  980. { \
  981. char *endp = b->buffer + BLOCKSIZE; \
  982. char const *srcp = src; \
  983. while (*srcp) \
  984. { \
  985. if (dst == endp) \
  986. { \
  987. set_next_block_after (b); \
  988. b = find_next_block (); \
  989. dst = b->buffer; \
  990. endp = b->buffer + BLOCKSIZE; \
  991. } \
  992. *dst++ = *srcp++; \
  993. } \
  994. } while (0)
  995. /* Compute stored file size */
  996. p = umaxtostr (file->stat_info->sparse_map_avail, nbuf);
  997. size += strlen (p) + 1;
  998. for (i = 0; i < file->stat_info->sparse_map_avail; i++)
  999. {
  1000. p = umaxtostr (map[i].offset, nbuf);
  1001. size += strlen (p) + 1;
  1002. p = umaxtostr (map[i].numbytes, nbuf);
  1003. size += strlen (p) + 1;
  1004. }
  1005. size = (size + BLOCKSIZE - 1) / BLOCKSIZE;
  1006. file->stat_info->archive_file_size += size * BLOCKSIZE;
  1007. file->dumped_size += size * BLOCKSIZE;
  1008. /* Store sparse file identification */
  1009. xheader_store ("GNU.sparse.major", file->stat_info, NULL);
  1010. xheader_store ("GNU.sparse.minor", file->stat_info, NULL);
  1011. xheader_store ("GNU.sparse.name", file->stat_info, NULL);
  1012. xheader_store ("GNU.sparse.realsize", file->stat_info, NULL);
  1013. file->stat_info->file_name =
  1014. xheader_format_name (file->stat_info, "%d/GNUSparseFile.%p/%f", 0);
  1015. /* Make sure the created header name is shorter than NAME_FIELD_SIZE: */
  1016. if (strlen (file->stat_info->file_name) > NAME_FIELD_SIZE)
  1017. file->stat_info->file_name[NAME_FIELD_SIZE] = 0;
  1018. blk = pax_start_header (file->stat_info);
  1019. finish_header (file->stat_info, blk, block_ordinal);
  1020. free (file->stat_info->file_name);
  1021. file->stat_info->file_name = save_file_name;
  1022. blk = find_next_block ();
  1023. q = blk->buffer;
  1024. p = umaxtostr (file->stat_info->sparse_map_avail, nbuf);
  1025. COPY_STRING (blk, q, p);
  1026. COPY_STRING (blk, q, "\n");
  1027. for (i = 0; i < file->stat_info->sparse_map_avail; i++)
  1028. {
  1029. p = umaxtostr (map[i].offset, nbuf);
  1030. COPY_STRING (blk, q, p);
  1031. COPY_STRING (blk, q, "\n");
  1032. p = umaxtostr (map[i].numbytes, nbuf);
  1033. COPY_STRING (blk, q, p);
  1034. COPY_STRING (blk, q, "\n");
  1035. }
  1036. memset (q, 0, BLOCKSIZE - (q - blk->buffer));
  1037. set_next_block_after (blk);
  1038. return true;
  1039. }
  1040. static bool
  1041. pax_dump_header (struct tar_sparse_file *file)
  1042. {
  1043. file->stat_info->sparse_major = tar_sparse_major;
  1044. file->stat_info->sparse_minor = tar_sparse_minor;
  1045. return (file->stat_info->sparse_major == 0) ?
  1046. pax_dump_header_0 (file) : pax_dump_header_1 (file);
  1047. }
  1048. static bool
  1049. decode_num (uintmax_t *num, char const *arg, uintmax_t maxval)
  1050. {
  1051. uintmax_t u;
  1052. char *arg_lim;
  1053. if (!ISDIGIT (*arg))
  1054. return false;
  1055. errno = 0;
  1056. u = strtoumax (arg, &arg_lim, 10);
  1057. if (! (u <= maxval && errno != ERANGE) || *arg_lim)
  1058. return false;
  1059. *num = u;
  1060. return true;
  1061. }
  1062. static bool
  1063. pax_decode_header (struct tar_sparse_file *file)
  1064. {
  1065. if (file->stat_info->sparse_major > 0)
  1066. {
  1067. uintmax_t u;
  1068. char nbuf[UINTMAX_STRSIZE_BOUND];
  1069. union block *blk;
  1070. char *p;
  1071. size_t i;
  1072. off_t start;
  1073. #define COPY_BUF(b,buf,src) do \
  1074. { \
  1075. char *endp = b->buffer + BLOCKSIZE; \
  1076. char *dst = buf; \
  1077. do \
  1078. { \
  1079. if (dst == buf + UINTMAX_STRSIZE_BOUND -1) \
  1080. { \
  1081. ERROR ((0, 0, _("%s: numeric overflow in sparse archive member"), \
  1082. file->stat_info->orig_file_name)); \
  1083. return false; \
  1084. } \
  1085. if (src == endp) \
  1086. { \
  1087. set_next_block_after (b); \
  1088. b = find_next_block (); \
  1089. if (!b) \
  1090. FATAL_ERROR ((0, 0, _("Unexpected EOF in archive"))); \
  1091. src = b->buffer; \
  1092. endp = b->buffer + BLOCKSIZE; \
  1093. } \
  1094. *dst = *src++; \
  1095. } \
  1096. while (*dst++ != '\n'); \
  1097. dst[-1] = 0; \
  1098. } while (0)
  1099. start = current_block_ordinal ();
  1100. set_next_block_after (current_header);
  1101. blk = find_next_block ();
  1102. if (!blk)
  1103. FATAL_ERROR ((0, 0, _("Unexpected EOF in archive")));
  1104. p = blk->buffer;
  1105. COPY_BUF (blk,nbuf,p);
  1106. if (!decode_num (&u, nbuf, TYPE_MAXIMUM (size_t)))
  1107. {
  1108. ERROR ((0, 0, _("%s: malformed sparse archive member"),
  1109. file->stat_info->orig_file_name));
  1110. return false;
  1111. }
  1112. file->stat_info->sparse_map_size = u;
  1113. file->stat_info->sparse_map = xcalloc (file->stat_info->sparse_map_size,
  1114. sizeof (*file->stat_info->sparse_map));
  1115. file->stat_info->sparse_map_avail = 0;
  1116. for (i = 0; i < file->stat_info->sparse_map_size; i++)
  1117. {
  1118. struct sp_array sp;
  1119. COPY_BUF (blk,nbuf,p);
  1120. if (!decode_num (&u, nbuf, TYPE_MAXIMUM (off_t)))
  1121. {
  1122. ERROR ((0, 0, _("%s: malformed sparse archive member"),
  1123. file->stat_info->orig_file_name));
  1124. return false;
  1125. }
  1126. sp.offset = u;
  1127. COPY_BUF (blk,nbuf,p);
  1128. if (!decode_num (&u, nbuf, TYPE_MAXIMUM (off_t))
  1129. || INT_ADD_OVERFLOW (sp.offset, u)
  1130. || file->stat_info->stat.st_size < sp.offset + u)
  1131. {
  1132. ERROR ((0, 0, _("%s: malformed sparse archive member"),
  1133. file->stat_info->orig_file_name));
  1134. return false;
  1135. }
  1136. sp.numbytes = u;
  1137. sparse_add_map (file->stat_info, &sp);
  1138. }
  1139. set_next_block_after (blk);
  1140. file->dumped_size += BLOCKSIZE * (current_block_ordinal () - start);
  1141. }
  1142. return true;
  1143. }
  1144. static struct tar_sparse_optab const pax_optab = {
  1145. NULL, /* No init function */
  1146. NULL, /* No done function */
  1147. pax_sparse_member_p,
  1148. pax_dump_header,
  1149. NULL,
  1150. pax_decode_header,
  1151. NULL, /* No scan_block function */
  1152. sparse_dump_region,
  1153. sparse_extract_region,
  1154. };