nilfs2.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248
  1. /*
  2. * nilfs2.c - New Implementation of Log filesystem
  3. *
  4. * Written by Jiro SEKIBA <jir@unicus.jp>
  5. *
  6. * Copyright (C) 2003,2004,2005,2007,2008,2010 Free Software Foundation, Inc.
  7. *
  8. * GRUB is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * GRUB 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.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. /* Filetype information as used in inodes. */
  22. #define FILETYPE_INO_MASK 0170000
  23. #define FILETYPE_INO_REG 0100000
  24. #define FILETYPE_INO_DIRECTORY 0040000
  25. #define FILETYPE_INO_SYMLINK 0120000
  26. #include <grub/err.h>
  27. #include <grub/file.h>
  28. #include <grub/mm.h>
  29. #include <grub/misc.h>
  30. #include <grub/disk.h>
  31. #include <grub/dl.h>
  32. #include <grub/types.h>
  33. #include <grub/fshelp.h>
  34. #include <grub/lockdown.h>
  35. GRUB_MOD_LICENSE ("GPLv3+");
  36. #define NILFS_INODE_BMAP_SIZE 7
  37. #define NILFS_SUPORT_REV 2
  38. /* Magic value used to identify an nilfs2 filesystem. */
  39. #define NILFS2_SUPER_MAGIC 0x3434
  40. /* nilfs btree node flag. */
  41. #define NILFS_BTREE_NODE_ROOT 0x01
  42. /* nilfs btree node level. */
  43. #define NILFS_BTREE_LEVEL_DATA 0
  44. #define NILFS_BTREE_LEVEL_NODE_MIN (NILFS_BTREE_LEVEL_DATA + 1)
  45. /* nilfs 1st super block posission from beginning of the partition
  46. in 512 block size */
  47. #define NILFS_1ST_SUPER_BLOCK 2
  48. /* nilfs 2nd super block posission from beginning of the partition
  49. in 512 block size */
  50. #define NILFS_2ND_SUPER_BLOCK(devsize) (((devsize >> 3) - 1) << 3)
  51. #define LOG_INODE_SIZE 7
  52. struct grub_nilfs2_inode
  53. {
  54. grub_uint64_t i_blocks;
  55. grub_uint64_t i_size;
  56. grub_uint64_t i_ctime;
  57. grub_uint64_t i_mtime;
  58. grub_uint32_t i_ctime_nsec;
  59. grub_uint32_t i_mtime_nsec;
  60. grub_uint32_t i_uid;
  61. grub_uint32_t i_gid;
  62. grub_uint16_t i_mode;
  63. grub_uint16_t i_links_count;
  64. grub_uint32_t i_flags;
  65. grub_uint64_t i_bmap[NILFS_INODE_BMAP_SIZE];
  66. #define i_device_code i_bmap[0]
  67. grub_uint64_t i_xattr;
  68. grub_uint32_t i_generation;
  69. grub_uint32_t i_pad;
  70. };
  71. struct grub_nilfs2_super_root
  72. {
  73. grub_uint32_t sr_sum;
  74. grub_uint16_t sr_bytes;
  75. grub_uint16_t sr_flags;
  76. grub_uint64_t sr_nongc_ctime;
  77. struct grub_nilfs2_inode sr_dat;
  78. struct grub_nilfs2_inode sr_cpfile;
  79. struct grub_nilfs2_inode sr_sufile;
  80. };
  81. struct grub_nilfs2_super_block
  82. {
  83. grub_uint32_t s_rev_level;
  84. grub_uint16_t s_minor_rev_level;
  85. grub_uint16_t s_magic;
  86. grub_uint16_t s_bytes;
  87. grub_uint16_t s_flags;
  88. grub_uint32_t s_crc_seed;
  89. grub_uint32_t s_sum;
  90. grub_uint32_t s_log_block_size;
  91. grub_uint64_t s_nsegments;
  92. grub_uint64_t s_dev_size;
  93. grub_uint64_t s_first_data_block;
  94. grub_uint32_t s_blocks_per_segment;
  95. grub_uint32_t s_r_segments_percentage;
  96. grub_uint64_t s_last_cno;
  97. grub_uint64_t s_last_pseg;
  98. grub_uint64_t s_last_seq;
  99. grub_uint64_t s_free_blocks_count;
  100. grub_uint64_t s_ctime;
  101. grub_uint64_t s_mtime;
  102. grub_uint64_t s_wtime;
  103. grub_uint16_t s_mnt_count;
  104. grub_uint16_t s_max_mnt_count;
  105. grub_uint16_t s_state;
  106. grub_uint16_t s_errors;
  107. grub_uint64_t s_lastcheck;
  108. grub_uint32_t s_checkinterval;
  109. grub_uint32_t s_creator_os;
  110. grub_uint16_t s_def_resuid;
  111. grub_uint16_t s_def_resgid;
  112. grub_uint32_t s_first_ino;
  113. grub_uint16_t s_inode_size;
  114. grub_uint16_t s_dat_entry_size;
  115. grub_uint16_t s_checkpoint_size;
  116. grub_uint16_t s_segment_usage_size;
  117. grub_uint8_t s_uuid[16];
  118. char s_volume_name[80];
  119. grub_uint32_t s_c_interval;
  120. grub_uint32_t s_c_block_max;
  121. grub_uint32_t s_reserved[192];
  122. };
  123. struct grub_nilfs2_dir_entry
  124. {
  125. grub_uint64_t inode;
  126. grub_uint16_t rec_len;
  127. #define MAX_NAMELEN 255
  128. grub_uint8_t name_len;
  129. grub_uint8_t file_type;
  130. #if 0 /* followed by file name. */
  131. char name[NILFS_NAME_LEN];
  132. char pad;
  133. #endif
  134. } GRUB_PACKED;
  135. enum
  136. {
  137. NILFS_FT_UNKNOWN,
  138. NILFS_FT_REG_FILE,
  139. NILFS_FT_DIR,
  140. NILFS_FT_CHRDEV,
  141. NILFS_FT_BLKDEV,
  142. NILFS_FT_FIFO,
  143. NILFS_FT_SOCK,
  144. NILFS_FT_SYMLINK,
  145. NILFS_FT_MAX
  146. };
  147. struct grub_nilfs2_finfo
  148. {
  149. grub_uint64_t fi_ino;
  150. grub_uint64_t fi_cno;
  151. grub_uint32_t fi_nblocks;
  152. grub_uint32_t fi_ndatablk;
  153. };
  154. struct grub_nilfs2_binfo_v
  155. {
  156. grub_uint64_t bi_vblocknr;
  157. grub_uint64_t bi_blkoff;
  158. };
  159. struct grub_nilfs2_binfo_dat
  160. {
  161. grub_uint64_t bi_blkoff;
  162. grub_uint8_t bi_level;
  163. grub_uint8_t bi_pad[7];
  164. };
  165. union grub_nilfs2_binfo
  166. {
  167. struct grub_nilfs2_binfo_v bi_v;
  168. struct grub_nilfs2_binfo_dat bi_dat;
  169. };
  170. struct grub_nilfs2_segment_summary
  171. {
  172. grub_uint32_t ss_datasum;
  173. grub_uint32_t ss_sumsum;
  174. grub_uint32_t ss_magic;
  175. grub_uint16_t ss_bytes;
  176. grub_uint16_t ss_flags;
  177. grub_uint64_t ss_seq;
  178. grub_uint64_t ss_create;
  179. grub_uint64_t ss_next;
  180. grub_uint32_t ss_nblocks;
  181. grub_uint32_t ss_nfinfo;
  182. grub_uint32_t ss_sumbytes;
  183. grub_uint32_t ss_pad;
  184. };
  185. struct grub_nilfs2_btree_node
  186. {
  187. grub_uint8_t bn_flags;
  188. grub_uint8_t bn_level;
  189. grub_uint16_t bn_nchildren;
  190. grub_uint32_t bn_pad;
  191. grub_uint64_t keys[0];
  192. };
  193. struct grub_nilfs2_palloc_group_desc
  194. {
  195. grub_uint32_t pg_nfrees;
  196. };
  197. #define LOG_SIZE_GROUP_DESC 2
  198. #define LOG_NILFS_DAT_ENTRY_SIZE 5
  199. struct grub_nilfs2_dat_entry
  200. {
  201. grub_uint64_t de_blocknr;
  202. grub_uint64_t de_start;
  203. grub_uint64_t de_end;
  204. grub_uint64_t de_rsv;
  205. };
  206. struct grub_nilfs2_snapshot_list
  207. {
  208. grub_uint64_t ssl_next;
  209. grub_uint64_t ssl_prev;
  210. };
  211. struct grub_nilfs2_cpfile_header
  212. {
  213. grub_uint64_t ch_ncheckpoints;
  214. grub_uint64_t ch_nsnapshots;
  215. struct grub_nilfs2_snapshot_list ch_snapshot_list;
  216. };
  217. struct grub_nilfs2_checkpoint
  218. {
  219. grub_uint32_t cp_flags;
  220. grub_uint32_t cp_checkpoints_count;
  221. struct grub_nilfs2_snapshot_list cp_snapshot_list;
  222. grub_uint64_t cp_cno;
  223. grub_uint64_t cp_create;
  224. grub_uint64_t cp_nblk_inc;
  225. grub_uint64_t cp_inodes_count;
  226. grub_uint64_t cp_blocks_count;
  227. struct grub_nilfs2_inode cp_ifile_inode;
  228. };
  229. #define NILFS_BMAP_LARGE 0x1
  230. #define NILFS_BMAP_SIZE (NILFS_INODE_BMAP_SIZE * sizeof(grub_uint64_t))
  231. /* nilfs extra padding for nonroot btree node. */
  232. #define NILFS_BTREE_NODE_EXTRA_PAD_SIZE (sizeof(grub_uint64_t))
  233. #define NILFS_BTREE_ROOT_SIZE NILFS_BMAP_SIZE
  234. #define NILFS_BTREE_ROOT_NCHILDREN_MAX \
  235. ((NILFS_BTREE_ROOT_SIZE - sizeof(struct nilfs_btree_node)) / \
  236. (sizeof(grub_uint64_t) + sizeof(grub_uint64_t)) )
  237. struct grub_fshelp_node
  238. {
  239. struct grub_nilfs2_data *data;
  240. struct grub_nilfs2_inode inode;
  241. grub_uint64_t ino;
  242. int inode_read;
  243. };
  244. struct grub_nilfs2_data
  245. {
  246. struct grub_nilfs2_super_block sblock;
  247. struct grub_nilfs2_super_root sroot;
  248. struct grub_nilfs2_inode ifile;
  249. grub_disk_t disk;
  250. struct grub_nilfs2_inode *inode;
  251. struct grub_fshelp_node diropen;
  252. };
  253. /* Log2 size of nilfs2 block in 512 blocks. */
  254. #define LOG2_NILFS2_BLOCK_SIZE(data) \
  255. (grub_le_to_cpu32 (data->sblock.s_log_block_size) + 1)
  256. /* Log2 size of nilfs2 block in bytes. */
  257. #define LOG2_BLOCK_SIZE(data) \
  258. (grub_le_to_cpu32 (data->sblock.s_log_block_size) + 10)
  259. /* The size of an nilfs2 block in bytes. */
  260. #define NILFS2_BLOCK_SIZE(data) (1 << LOG2_BLOCK_SIZE (data))
  261. static grub_uint64_t
  262. grub_nilfs2_dat_translate (struct grub_nilfs2_data *data, grub_uint64_t key);
  263. static grub_dl_t my_mod;
  264. static inline unsigned long
  265. grub_nilfs2_log_palloc_entries_per_group (struct grub_nilfs2_data *data)
  266. {
  267. return LOG2_BLOCK_SIZE (data) + 3;
  268. }
  269. static inline grub_uint64_t
  270. grub_nilfs2_palloc_group (struct grub_nilfs2_data *data,
  271. grub_uint64_t nr, grub_uint64_t * offset)
  272. {
  273. *offset = nr & ((1 << grub_nilfs2_log_palloc_entries_per_group (data)) - 1);
  274. return nr >> grub_nilfs2_log_palloc_entries_per_group (data);
  275. }
  276. static inline grub_uint32_t
  277. grub_nilfs2_palloc_log_groups_per_desc_block (struct grub_nilfs2_data *data)
  278. {
  279. return LOG2_BLOCK_SIZE (data) - LOG_SIZE_GROUP_DESC;
  280. COMPILE_TIME_ASSERT (sizeof (struct grub_nilfs2_palloc_group_desc)
  281. == (1 << LOG_SIZE_GROUP_DESC));
  282. }
  283. static inline grub_uint32_t
  284. grub_nilfs2_log_entries_per_block_log (struct grub_nilfs2_data *data,
  285. unsigned long log_entry_size)
  286. {
  287. return LOG2_BLOCK_SIZE (data) - log_entry_size;
  288. }
  289. static inline grub_uint32_t
  290. grub_nilfs2_blocks_per_group_log (struct grub_nilfs2_data *data,
  291. unsigned long log_entry_size)
  292. {
  293. return (1 << (grub_nilfs2_log_palloc_entries_per_group (data)
  294. - grub_nilfs2_log_entries_per_block_log (data,
  295. log_entry_size))) + 1;
  296. }
  297. static inline grub_uint32_t
  298. grub_nilfs2_blocks_per_desc_block_log (struct grub_nilfs2_data *data,
  299. unsigned long log_entry_size)
  300. {
  301. return(grub_nilfs2_blocks_per_group_log (data, log_entry_size)
  302. << grub_nilfs2_palloc_log_groups_per_desc_block (data)) + 1;
  303. }
  304. static inline grub_uint32_t
  305. grub_nilfs2_palloc_desc_block_offset_log (struct grub_nilfs2_data *data,
  306. unsigned long group,
  307. unsigned long log_entry_size)
  308. {
  309. grub_uint32_t desc_block =
  310. group >> grub_nilfs2_palloc_log_groups_per_desc_block (data);
  311. return desc_block * grub_nilfs2_blocks_per_desc_block_log (data,
  312. log_entry_size);
  313. }
  314. static inline grub_uint32_t
  315. grub_nilfs2_palloc_bitmap_block_offset (struct grub_nilfs2_data *data,
  316. unsigned long group,
  317. unsigned long log_entry_size)
  318. {
  319. unsigned long desc_offset = group
  320. & ((1 << grub_nilfs2_palloc_log_groups_per_desc_block (data)) - 1);
  321. return grub_nilfs2_palloc_desc_block_offset_log (data, group, log_entry_size)
  322. + 1
  323. + desc_offset * grub_nilfs2_blocks_per_group_log (data, log_entry_size);
  324. }
  325. static inline grub_uint32_t
  326. grub_nilfs2_palloc_entry_offset_log (struct grub_nilfs2_data *data,
  327. grub_uint64_t nr,
  328. unsigned long log_entry_size)
  329. {
  330. unsigned long group;
  331. grub_uint64_t group_offset;
  332. group = grub_nilfs2_palloc_group (data, nr, &group_offset);
  333. return grub_nilfs2_palloc_bitmap_block_offset (data, group,
  334. log_entry_size) + 1 +
  335. (group_offset >> grub_nilfs2_log_entries_per_block_log (data,
  336. log_entry_size));
  337. }
  338. static inline struct grub_nilfs2_btree_node *
  339. grub_nilfs2_btree_get_root (struct grub_nilfs2_inode *inode)
  340. {
  341. return (struct grub_nilfs2_btree_node *) &inode->i_bmap[0];
  342. }
  343. static inline int
  344. grub_nilfs2_btree_get_level (struct grub_nilfs2_btree_node *node)
  345. {
  346. return node->bn_level;
  347. }
  348. static inline grub_uint64_t *
  349. grub_nilfs2_btree_node_dkeys (struct grub_nilfs2_btree_node *node)
  350. {
  351. return (node->keys +
  352. ((node->bn_flags & NILFS_BTREE_NODE_ROOT) ?
  353. 0 : (NILFS_BTREE_NODE_EXTRA_PAD_SIZE / sizeof (grub_uint64_t))));
  354. }
  355. static inline grub_uint64_t
  356. grub_nilfs2_btree_node_get_key (struct grub_nilfs2_btree_node *node,
  357. int index)
  358. {
  359. return grub_le_to_cpu64 (*(grub_nilfs2_btree_node_dkeys (node) + index));
  360. }
  361. static inline int
  362. grub_nilfs2_btree_node_nchildren_max (struct grub_nilfs2_data *data,
  363. struct grub_nilfs2_btree_node *node)
  364. {
  365. int node_children_max = ((NILFS2_BLOCK_SIZE (data) -
  366. sizeof (struct grub_nilfs2_btree_node) -
  367. NILFS_BTREE_NODE_EXTRA_PAD_SIZE) /
  368. (sizeof (grub_uint64_t) + sizeof (grub_uint64_t)));
  369. return (node->bn_flags & NILFS_BTREE_NODE_ROOT) ? 3 : node_children_max;
  370. }
  371. static inline int
  372. grub_nilfs2_btree_node_lookup (struct grub_nilfs2_data *data,
  373. struct grub_nilfs2_btree_node *node,
  374. grub_uint64_t key, int *indexp)
  375. {
  376. grub_uint64_t nkey;
  377. int index = 0, low, high, s;
  378. low = 0;
  379. high = grub_le_to_cpu16 (node->bn_nchildren) - 1;
  380. if (high >= grub_nilfs2_btree_node_nchildren_max (data, node))
  381. {
  382. grub_error (GRUB_ERR_BAD_FS, "too many children");
  383. *indexp = index;
  384. return 0;
  385. }
  386. s = 0;
  387. while (low <= high)
  388. {
  389. index = (low + high) / 2;
  390. nkey = grub_nilfs2_btree_node_get_key (node, index);
  391. if (nkey == key)
  392. {
  393. *indexp = index;
  394. return 1;
  395. }
  396. else if (nkey < key)
  397. {
  398. low = index + 1;
  399. s = -1;
  400. }
  401. else
  402. {
  403. high = index - 1;
  404. s = 1;
  405. }
  406. }
  407. if (node->bn_level > NILFS_BTREE_LEVEL_NODE_MIN)
  408. {
  409. if (s > 0 && index > 0)
  410. index--;
  411. }
  412. else if (s < 0)
  413. index++;
  414. *indexp = index;
  415. return s == 0;
  416. }
  417. static inline grub_uint64_t *
  418. grub_nilfs2_btree_node_dptrs (struct grub_nilfs2_data *data,
  419. struct grub_nilfs2_btree_node *node)
  420. {
  421. return (grub_uint64_t *) (grub_nilfs2_btree_node_dkeys (node) +
  422. grub_nilfs2_btree_node_nchildren_max (data,
  423. node));
  424. }
  425. static inline grub_uint64_t
  426. grub_nilfs2_btree_node_get_ptr (struct grub_nilfs2_data *data,
  427. struct grub_nilfs2_btree_node *node,
  428. int index)
  429. {
  430. return
  431. grub_le_to_cpu64 (*(grub_nilfs2_btree_node_dptrs (data, node) + index));
  432. }
  433. static inline int
  434. grub_nilfs2_btree_get_nonroot_node (struct grub_nilfs2_data *data,
  435. grub_uint64_t ptr, void *block)
  436. {
  437. grub_disk_t disk = data->disk;
  438. unsigned int nilfs2_block_count = (1 << LOG2_NILFS2_BLOCK_SIZE (data));
  439. return grub_disk_read (disk, ptr * nilfs2_block_count, 0,
  440. NILFS2_BLOCK_SIZE (data), block);
  441. }
  442. static grub_uint64_t
  443. grub_nilfs2_btree_lookup (struct grub_nilfs2_data *data,
  444. struct grub_nilfs2_inode *inode,
  445. grub_uint64_t key, int need_translate)
  446. {
  447. struct grub_nilfs2_btree_node *node;
  448. void *block;
  449. grub_uint64_t ptr;
  450. int level, found = 0, index;
  451. block = grub_malloc (NILFS2_BLOCK_SIZE (data));
  452. if (!block)
  453. return -1;
  454. node = grub_nilfs2_btree_get_root (inode);
  455. level = grub_nilfs2_btree_get_level (node);
  456. found = grub_nilfs2_btree_node_lookup (data, node, key, &index);
  457. if (grub_errno != GRUB_ERR_NONE)
  458. goto fail;
  459. ptr = grub_nilfs2_btree_node_get_ptr (data, node, index);
  460. if (need_translate)
  461. ptr = grub_nilfs2_dat_translate (data, ptr);
  462. for (level--; level >= NILFS_BTREE_LEVEL_NODE_MIN; level--)
  463. {
  464. grub_nilfs2_btree_get_nonroot_node (data, ptr, block);
  465. if (grub_errno)
  466. {
  467. goto fail;
  468. }
  469. node = (struct grub_nilfs2_btree_node *) block;
  470. if (node->bn_level != level)
  471. {
  472. grub_error (GRUB_ERR_BAD_FS, "btree level mismatch\n");
  473. goto fail;
  474. }
  475. if (!found)
  476. found = grub_nilfs2_btree_node_lookup (data, node, key, &index);
  477. else
  478. index = 0;
  479. if (index < grub_nilfs2_btree_node_nchildren_max (data, node) &&
  480. grub_errno == GRUB_ERR_NONE)
  481. {
  482. ptr = grub_nilfs2_btree_node_get_ptr (data, node, index);
  483. if (need_translate)
  484. ptr = grub_nilfs2_dat_translate (data, ptr);
  485. }
  486. else
  487. {
  488. grub_error (GRUB_ERR_BAD_FS, "btree corruption\n");
  489. goto fail;
  490. }
  491. }
  492. grub_free (block);
  493. if (!found)
  494. return -1;
  495. return ptr;
  496. fail:
  497. grub_free (block);
  498. return -1;
  499. }
  500. static inline grub_uint64_t
  501. grub_nilfs2_direct_lookup (struct grub_nilfs2_inode *inode, grub_uint64_t key)
  502. {
  503. if (1 + key > 6)
  504. {
  505. grub_error (GRUB_ERR_BAD_FS, "key is too large");
  506. return 0xffffffffffffffff;
  507. }
  508. return grub_le_to_cpu64 (inode->i_bmap[1 + key]);
  509. }
  510. static inline grub_uint64_t
  511. grub_nilfs2_bmap_lookup (struct grub_nilfs2_data *data,
  512. struct grub_nilfs2_inode *inode,
  513. grub_uint64_t key, int need_translate)
  514. {
  515. struct grub_nilfs2_btree_node *root = grub_nilfs2_btree_get_root (inode);
  516. if (root->bn_flags & NILFS_BMAP_LARGE)
  517. return grub_nilfs2_btree_lookup (data, inode, key, need_translate);
  518. else
  519. {
  520. grub_uint64_t ptr;
  521. ptr = grub_nilfs2_direct_lookup (inode, key);
  522. if (ptr != ((grub_uint64_t) 0xffffffffffffffff) && need_translate)
  523. ptr = grub_nilfs2_dat_translate (data, ptr);
  524. return ptr;
  525. }
  526. }
  527. static grub_uint64_t
  528. grub_nilfs2_dat_translate (struct grub_nilfs2_data *data, grub_uint64_t key)
  529. {
  530. struct grub_nilfs2_dat_entry entry;
  531. grub_disk_t disk = data->disk;
  532. grub_uint64_t pptr;
  533. grub_uint64_t blockno, offset;
  534. unsigned int nilfs2_block_count = (1 << LOG2_NILFS2_BLOCK_SIZE (data));
  535. blockno = grub_nilfs2_palloc_entry_offset_log (data, key,
  536. LOG_NILFS_DAT_ENTRY_SIZE);
  537. offset = ((key * sizeof (struct grub_nilfs2_dat_entry))
  538. & ((1 << LOG2_BLOCK_SIZE (data)) - 1));
  539. pptr = grub_nilfs2_bmap_lookup (data, &data->sroot.sr_dat, blockno, 0);
  540. if (pptr == (grub_uint64_t) - 1)
  541. {
  542. grub_error (GRUB_ERR_BAD_FS, "btree lookup failure");
  543. return -1;
  544. }
  545. grub_disk_read (disk, pptr * nilfs2_block_count, offset,
  546. sizeof (struct grub_nilfs2_dat_entry), &entry);
  547. return grub_le_to_cpu64 (entry.de_blocknr);
  548. }
  549. static grub_disk_addr_t
  550. grub_nilfs2_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock)
  551. {
  552. struct grub_nilfs2_data *data = node->data;
  553. struct grub_nilfs2_inode *inode = &node->inode;
  554. grub_uint64_t pptr = -1;
  555. pptr = grub_nilfs2_bmap_lookup (data, inode, fileblock, 1);
  556. if (pptr == (grub_uint64_t) - 1)
  557. {
  558. grub_error (GRUB_ERR_BAD_FS, "btree lookup failure");
  559. return -1;
  560. }
  561. return pptr;
  562. }
  563. /* Read LEN bytes from the file described by DATA starting with byte
  564. POS. Return the amount of read bytes in READ. */
  565. static grub_ssize_t
  566. grub_nilfs2_read_file (grub_fshelp_node_t node,
  567. grub_disk_read_hook_t read_hook, void *read_hook_data,
  568. grub_off_t pos, grub_size_t len, char *buf)
  569. {
  570. return grub_fshelp_read_file (node->data->disk, node,
  571. read_hook, read_hook_data,
  572. pos, len, buf, grub_nilfs2_read_block,
  573. grub_le_to_cpu64 (node->inode.i_size),
  574. LOG2_NILFS2_BLOCK_SIZE (node->data), 0);
  575. }
  576. static grub_err_t
  577. grub_nilfs2_read_checkpoint (struct grub_nilfs2_data *data,
  578. grub_uint64_t cpno,
  579. struct grub_nilfs2_checkpoint *cpp)
  580. {
  581. grub_uint64_t blockno;
  582. grub_uint64_t offset;
  583. grub_uint64_t pptr;
  584. grub_disk_t disk = data->disk;
  585. unsigned int nilfs2_block_count = (1 << LOG2_NILFS2_BLOCK_SIZE (data));
  586. /* Assume sizeof(struct grub_nilfs2_cpfile_header) <
  587. sizeof(struct grub_nilfs2_checkpoint).
  588. */
  589. blockno = grub_divmod64 (cpno, NILFS2_BLOCK_SIZE (data) /
  590. sizeof (struct grub_nilfs2_checkpoint), &offset);
  591. pptr = grub_nilfs2_bmap_lookup (data, &data->sroot.sr_cpfile, blockno, 1);
  592. if (pptr == (grub_uint64_t) - 1)
  593. {
  594. return grub_error (GRUB_ERR_BAD_FS, "btree lookup failure");
  595. }
  596. return grub_disk_read (disk, pptr * nilfs2_block_count,
  597. offset * sizeof (struct grub_nilfs2_checkpoint),
  598. sizeof (struct grub_nilfs2_checkpoint), cpp);
  599. }
  600. static inline grub_err_t
  601. grub_nilfs2_read_last_checkpoint (struct grub_nilfs2_data *data,
  602. struct grub_nilfs2_checkpoint *cpp)
  603. {
  604. return grub_nilfs2_read_checkpoint (data,
  605. grub_le_to_cpu64 (data->
  606. sblock.s_last_cno),
  607. cpp);
  608. }
  609. /* Read the inode INO for the file described by DATA into INODE. */
  610. static grub_err_t
  611. grub_nilfs2_read_inode (struct grub_nilfs2_data *data,
  612. grub_uint64_t ino, struct grub_nilfs2_inode *inodep)
  613. {
  614. grub_uint64_t blockno;
  615. grub_uint64_t offset;
  616. grub_uint64_t pptr;
  617. grub_disk_t disk = data->disk;
  618. unsigned int nilfs2_block_count = (1 << LOG2_NILFS2_BLOCK_SIZE (data));
  619. blockno = grub_nilfs2_palloc_entry_offset_log (data, ino,
  620. LOG_INODE_SIZE);
  621. offset = ((sizeof (struct grub_nilfs2_inode) * ino)
  622. & ((1 << LOG2_BLOCK_SIZE (data)) - 1));
  623. pptr = grub_nilfs2_bmap_lookup (data, &data->ifile, blockno, 1);
  624. if (pptr == (grub_uint64_t) - 1)
  625. {
  626. return grub_error (GRUB_ERR_BAD_FS, "btree lookup failure");
  627. }
  628. return grub_disk_read (disk, pptr * nilfs2_block_count, offset,
  629. sizeof (struct grub_nilfs2_inode), inodep);
  630. }
  631. static int
  632. grub_nilfs2_valid_sb (struct grub_nilfs2_super_block *sbp)
  633. {
  634. if (grub_le_to_cpu16 (sbp->s_magic) != NILFS2_SUPER_MAGIC)
  635. return 0;
  636. if (grub_le_to_cpu32 (sbp->s_rev_level) != NILFS_SUPORT_REV)
  637. return 0;
  638. /* 20 already means 1GiB blocks. We don't want to deal with blocks overflowing int32. */
  639. if (grub_le_to_cpu32 (sbp->s_log_block_size) > 20)
  640. return 0;
  641. return 1;
  642. }
  643. static grub_err_t
  644. grub_nilfs2_load_sb (struct grub_nilfs2_data *data)
  645. {
  646. grub_disk_t disk = data->disk;
  647. struct grub_nilfs2_super_block sb2;
  648. grub_uint64_t partition_size;
  649. int valid[2];
  650. int swp = 0;
  651. grub_err_t err;
  652. /* Read first super block. */
  653. err = grub_disk_read (disk, NILFS_1ST_SUPER_BLOCK, 0,
  654. sizeof (struct grub_nilfs2_super_block), &data->sblock);
  655. if (err)
  656. return err;
  657. /* Make sure if 1st super block is valid. */
  658. valid[0] = grub_nilfs2_valid_sb (&data->sblock);
  659. if (valid[0])
  660. partition_size = (grub_le_to_cpu64 (data->sblock.s_dev_size)
  661. >> GRUB_DISK_SECTOR_BITS);
  662. else
  663. partition_size = grub_disk_native_sectors (disk);
  664. if (partition_size != GRUB_DISK_SIZE_UNKNOWN)
  665. {
  666. /* Read second super block. */
  667. err = grub_disk_read (disk, NILFS_2ND_SUPER_BLOCK (partition_size), 0,
  668. sizeof (struct grub_nilfs2_super_block), &sb2);
  669. if (err)
  670. {
  671. valid[1] = 0;
  672. grub_errno = GRUB_ERR_NONE;
  673. }
  674. else
  675. /* Make sure if 2nd super block is valid. */
  676. valid[1] = grub_nilfs2_valid_sb (&sb2);
  677. }
  678. else
  679. /* 2nd super block may not exist, so it's invalid. */
  680. valid[1] = 0;
  681. if (!valid[0] && !valid[1])
  682. return grub_error (GRUB_ERR_BAD_FS, "not a nilfs2 filesystem");
  683. swp = valid[1] && (!valid[0] ||
  684. grub_le_to_cpu64 (data->sblock.s_last_cno) <
  685. grub_le_to_cpu64 (sb2.s_last_cno));
  686. /* swap if first super block is invalid or older than second one. */
  687. if (swp)
  688. grub_memcpy (&data->sblock, &sb2,
  689. sizeof (struct grub_nilfs2_super_block));
  690. return GRUB_ERR_NONE;
  691. }
  692. static struct grub_nilfs2_data *
  693. grub_nilfs2_mount (grub_disk_t disk)
  694. {
  695. struct grub_nilfs2_data *data;
  696. struct grub_nilfs2_segment_summary ss;
  697. struct grub_nilfs2_checkpoint last_checkpoint;
  698. grub_uint64_t last_pseg;
  699. grub_uint32_t nblocks;
  700. unsigned int nilfs2_block_count;
  701. data = grub_malloc (sizeof (struct grub_nilfs2_data));
  702. if (!data)
  703. return 0;
  704. data->disk = disk;
  705. /* Read the superblock. */
  706. grub_nilfs2_load_sb (data);
  707. if (grub_errno)
  708. goto fail;
  709. nilfs2_block_count = (1 << LOG2_NILFS2_BLOCK_SIZE (data));
  710. /* Read the last segment summary. */
  711. last_pseg = grub_le_to_cpu64 (data->sblock.s_last_pseg);
  712. grub_disk_read (disk, last_pseg * nilfs2_block_count, 0,
  713. sizeof (struct grub_nilfs2_segment_summary), &ss);
  714. if (grub_errno)
  715. goto fail;
  716. /* Read the super root block. */
  717. nblocks = grub_le_to_cpu32 (ss.ss_nblocks);
  718. grub_disk_read (disk, (last_pseg + (nblocks - 1)) * nilfs2_block_count, 0,
  719. sizeof (struct grub_nilfs2_super_root), &data->sroot);
  720. if (grub_errno)
  721. goto fail;
  722. grub_nilfs2_read_last_checkpoint (data, &last_checkpoint);
  723. if (grub_errno)
  724. goto fail;
  725. grub_memcpy (&data->ifile, &last_checkpoint.cp_ifile_inode,
  726. sizeof (struct grub_nilfs2_inode));
  727. data->diropen.data = data;
  728. data->diropen.ino = 2;
  729. data->diropen.inode_read = 1;
  730. data->inode = &data->diropen.inode;
  731. grub_nilfs2_read_inode (data, 2, data->inode);
  732. return data;
  733. fail:
  734. if (grub_errno == GRUB_ERR_OUT_OF_RANGE)
  735. grub_error (GRUB_ERR_BAD_FS, "not a nilfs2 filesystem");
  736. grub_free (data);
  737. return 0;
  738. }
  739. static char *
  740. grub_nilfs2_read_symlink (grub_fshelp_node_t node)
  741. {
  742. char *symlink;
  743. struct grub_fshelp_node *diro = node;
  744. if (!diro->inode_read)
  745. {
  746. grub_nilfs2_read_inode (diro->data, diro->ino, &diro->inode);
  747. if (grub_errno)
  748. return 0;
  749. }
  750. symlink = grub_malloc (grub_le_to_cpu64 (diro->inode.i_size) + 1);
  751. if (!symlink)
  752. return 0;
  753. grub_nilfs2_read_file (diro, 0, 0, 0,
  754. grub_le_to_cpu64 (diro->inode.i_size), symlink);
  755. if (grub_errno)
  756. {
  757. grub_free (symlink);
  758. return 0;
  759. }
  760. symlink[grub_le_to_cpu64 (diro->inode.i_size)] = '\0';
  761. return symlink;
  762. }
  763. static int
  764. grub_nilfs2_iterate_dir (grub_fshelp_node_t dir,
  765. grub_fshelp_iterate_dir_hook_t hook, void *hook_data)
  766. {
  767. grub_off_t fpos = 0;
  768. struct grub_fshelp_node *diro = (struct grub_fshelp_node *) dir;
  769. if (!diro->inode_read)
  770. {
  771. grub_nilfs2_read_inode (diro->data, diro->ino, &diro->inode);
  772. if (grub_errno)
  773. return 0;
  774. }
  775. /* Iterate files. */
  776. while (fpos < grub_le_to_cpu64 (diro->inode.i_size))
  777. {
  778. struct grub_nilfs2_dir_entry dirent;
  779. grub_nilfs2_read_file (diro, 0, 0, fpos,
  780. sizeof (struct grub_nilfs2_dir_entry),
  781. (char *) &dirent);
  782. if (grub_errno)
  783. return 0;
  784. if (dirent.rec_len == 0)
  785. return 0;
  786. if (dirent.name_len != 0)
  787. {
  788. char filename[MAX_NAMELEN + 1];
  789. struct grub_fshelp_node *fdiro;
  790. enum grub_fshelp_filetype type = GRUB_FSHELP_UNKNOWN;
  791. grub_nilfs2_read_file (diro, 0, 0,
  792. fpos + sizeof (struct grub_nilfs2_dir_entry),
  793. dirent.name_len, filename);
  794. if (grub_errno)
  795. return 0;
  796. fdiro = grub_malloc (sizeof (struct grub_fshelp_node));
  797. if (!fdiro)
  798. return 0;
  799. fdiro->data = diro->data;
  800. fdiro->ino = grub_le_to_cpu64 (dirent.inode);
  801. filename[dirent.name_len] = '\0';
  802. if (dirent.file_type != NILFS_FT_UNKNOWN)
  803. {
  804. fdiro->inode_read = 0;
  805. if (dirent.file_type == NILFS_FT_DIR)
  806. type = GRUB_FSHELP_DIR;
  807. else if (dirent.file_type == NILFS_FT_SYMLINK)
  808. type = GRUB_FSHELP_SYMLINK;
  809. else if (dirent.file_type == NILFS_FT_REG_FILE)
  810. type = GRUB_FSHELP_REG;
  811. }
  812. else
  813. {
  814. /* The filetype can not be read from the dirent, read
  815. the inode to get more information. */
  816. grub_nilfs2_read_inode (diro->data,
  817. grub_le_to_cpu64 (dirent.inode),
  818. &fdiro->inode);
  819. if (grub_errno)
  820. {
  821. grub_free (fdiro);
  822. return 0;
  823. }
  824. fdiro->inode_read = 1;
  825. if ((grub_le_to_cpu16 (fdiro->inode.i_mode)
  826. & FILETYPE_INO_MASK) == FILETYPE_INO_DIRECTORY)
  827. type = GRUB_FSHELP_DIR;
  828. else if ((grub_le_to_cpu16 (fdiro->inode.i_mode)
  829. & FILETYPE_INO_MASK) == FILETYPE_INO_SYMLINK)
  830. type = GRUB_FSHELP_SYMLINK;
  831. else if ((grub_le_to_cpu16 (fdiro->inode.i_mode)
  832. & FILETYPE_INO_MASK) == FILETYPE_INO_REG)
  833. type = GRUB_FSHELP_REG;
  834. }
  835. if (hook (filename, type, fdiro, hook_data))
  836. return 1;
  837. }
  838. fpos += grub_le_to_cpu16 (dirent.rec_len);
  839. }
  840. return 0;
  841. }
  842. /* Open a file named NAME and initialize FILE. */
  843. static grub_err_t
  844. grub_nilfs2_open (struct grub_file *file, const char *name)
  845. {
  846. struct grub_nilfs2_data *data = NULL;
  847. struct grub_fshelp_node *fdiro = 0;
  848. grub_dl_ref (my_mod);
  849. data = grub_nilfs2_mount (file->device->disk);
  850. if (!data)
  851. goto fail;
  852. grub_fshelp_find_file (name, &data->diropen, &fdiro,
  853. grub_nilfs2_iterate_dir, grub_nilfs2_read_symlink,
  854. GRUB_FSHELP_REG);
  855. if (grub_errno)
  856. goto fail;
  857. if (!fdiro->inode_read)
  858. {
  859. grub_nilfs2_read_inode (data, fdiro->ino, &fdiro->inode);
  860. if (grub_errno)
  861. goto fail;
  862. }
  863. grub_memcpy (data->inode, &fdiro->inode, sizeof (struct grub_nilfs2_inode));
  864. grub_free (fdiro);
  865. file->size = grub_le_to_cpu64 (data->inode->i_size);
  866. file->data = data;
  867. file->offset = 0;
  868. return 0;
  869. fail:
  870. if (fdiro != &data->diropen)
  871. grub_free (fdiro);
  872. grub_free (data);
  873. grub_dl_unref (my_mod);
  874. return grub_errno;
  875. }
  876. static grub_err_t
  877. grub_nilfs2_close (grub_file_t file)
  878. {
  879. grub_free (file->data);
  880. grub_dl_unref (my_mod);
  881. return GRUB_ERR_NONE;
  882. }
  883. /* Read LEN bytes data from FILE into BUF. */
  884. static grub_ssize_t
  885. grub_nilfs2_read (grub_file_t file, char *buf, grub_size_t len)
  886. {
  887. struct grub_nilfs2_data *data = (struct grub_nilfs2_data *) file->data;
  888. return grub_nilfs2_read_file (&data->diropen,
  889. file->read_hook, file->read_hook_data,
  890. file->offset, len, buf);
  891. }
  892. /* Context for grub_nilfs2_dir. */
  893. struct grub_nilfs2_dir_ctx
  894. {
  895. grub_fs_dir_hook_t hook;
  896. void *hook_data;
  897. struct grub_nilfs2_data *data;
  898. };
  899. /* Helper for grub_nilfs2_dir. */
  900. static int
  901. grub_nilfs2_dir_iter (const char *filename, enum grub_fshelp_filetype filetype,
  902. grub_fshelp_node_t node, void *data)
  903. {
  904. struct grub_nilfs2_dir_ctx *ctx = data;
  905. struct grub_dirhook_info info;
  906. grub_memset (&info, 0, sizeof (info));
  907. if (!node->inode_read)
  908. {
  909. grub_nilfs2_read_inode (ctx->data, node->ino, &node->inode);
  910. if (!grub_errno)
  911. node->inode_read = 1;
  912. grub_errno = GRUB_ERR_NONE;
  913. }
  914. if (node->inode_read)
  915. {
  916. info.mtimeset = 1;
  917. info.mtime = grub_le_to_cpu64 (node->inode.i_mtime);
  918. }
  919. info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
  920. grub_free (node);
  921. return ctx->hook (filename, &info, ctx->hook_data);
  922. }
  923. static grub_err_t
  924. grub_nilfs2_dir (grub_device_t device, const char *path,
  925. grub_fs_dir_hook_t hook, void *hook_data)
  926. {
  927. struct grub_nilfs2_dir_ctx ctx = {
  928. .hook = hook,
  929. .hook_data = hook_data
  930. };
  931. struct grub_fshelp_node *fdiro = 0;
  932. grub_dl_ref (my_mod);
  933. ctx.data = grub_nilfs2_mount (device->disk);
  934. if (!ctx.data)
  935. goto fail;
  936. grub_fshelp_find_file (path, &ctx.data->diropen, &fdiro,
  937. grub_nilfs2_iterate_dir, grub_nilfs2_read_symlink,
  938. GRUB_FSHELP_DIR);
  939. if (grub_errno)
  940. goto fail;
  941. grub_nilfs2_iterate_dir (fdiro, grub_nilfs2_dir_iter, &ctx);
  942. fail:
  943. if (fdiro != &ctx.data->diropen)
  944. grub_free (fdiro);
  945. grub_free (ctx.data);
  946. grub_dl_unref (my_mod);
  947. return grub_errno;
  948. }
  949. static grub_err_t
  950. grub_nilfs2_label (grub_device_t device, char **label)
  951. {
  952. struct grub_nilfs2_data *data;
  953. grub_disk_t disk = device->disk;
  954. grub_dl_ref (my_mod);
  955. data = grub_nilfs2_mount (disk);
  956. if (data)
  957. *label = grub_strndup (data->sblock.s_volume_name,
  958. sizeof (data->sblock.s_volume_name));
  959. else
  960. *label = NULL;
  961. grub_dl_unref (my_mod);
  962. grub_free (data);
  963. return grub_errno;
  964. }
  965. static grub_err_t
  966. grub_nilfs2_uuid (grub_device_t device, char **uuid)
  967. {
  968. struct grub_nilfs2_data *data;
  969. grub_disk_t disk = device->disk;
  970. grub_dl_ref (my_mod);
  971. data = grub_nilfs2_mount (disk);
  972. if (data)
  973. {
  974. *uuid =
  975. grub_xasprintf
  976. ("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
  977. data->sblock.s_uuid[0], data->sblock.s_uuid[1],
  978. data->sblock.s_uuid[2], data->sblock.s_uuid[3],
  979. data->sblock.s_uuid[4], data->sblock.s_uuid[5],
  980. data->sblock.s_uuid[6], data->sblock.s_uuid[7],
  981. data->sblock.s_uuid[8], data->sblock.s_uuid[9],
  982. data->sblock.s_uuid[10], data->sblock.s_uuid[11],
  983. data->sblock.s_uuid[12], data->sblock.s_uuid[13],
  984. data->sblock.s_uuid[14], data->sblock.s_uuid[15]);
  985. }
  986. else
  987. *uuid = NULL;
  988. grub_dl_unref (my_mod);
  989. grub_free (data);
  990. return grub_errno;
  991. }
  992. /* Get mtime. */
  993. static grub_err_t
  994. grub_nilfs2_mtime (grub_device_t device, grub_int64_t * tm)
  995. {
  996. struct grub_nilfs2_data *data;
  997. grub_disk_t disk = device->disk;
  998. grub_dl_ref (my_mod);
  999. data = grub_nilfs2_mount (disk);
  1000. if (!data)
  1001. *tm = 0;
  1002. else
  1003. *tm = (grub_int32_t) grub_le_to_cpu64 (data->sblock.s_wtime);
  1004. grub_dl_unref (my_mod);
  1005. grub_free (data);
  1006. return grub_errno;
  1007. }
  1008. static struct grub_fs grub_nilfs2_fs = {
  1009. .name = "nilfs2",
  1010. .fs_dir = grub_nilfs2_dir,
  1011. .fs_open = grub_nilfs2_open,
  1012. .fs_read = grub_nilfs2_read,
  1013. .fs_close = grub_nilfs2_close,
  1014. .fs_label = grub_nilfs2_label,
  1015. .fs_uuid = grub_nilfs2_uuid,
  1016. .fs_mtime = grub_nilfs2_mtime,
  1017. #ifdef GRUB_UTIL
  1018. .reserved_first_sector = 1,
  1019. .blocklist_install = 0,
  1020. #endif
  1021. .next = 0
  1022. };
  1023. GRUB_MOD_INIT (nilfs2)
  1024. {
  1025. COMPILE_TIME_ASSERT ((1 << LOG_NILFS_DAT_ENTRY_SIZE)
  1026. == sizeof (struct
  1027. grub_nilfs2_dat_entry));
  1028. COMPILE_TIME_ASSERT (1 << LOG_INODE_SIZE
  1029. == sizeof (struct grub_nilfs2_inode));
  1030. if (!grub_is_lockdown ())
  1031. {
  1032. grub_nilfs2_fs.mod = mod;
  1033. grub_fs_register (&grub_nilfs2_fs);
  1034. }
  1035. my_mod = mod;
  1036. }
  1037. GRUB_MOD_FINI (nilfs2)
  1038. {
  1039. if (!grub_is_lockdown ())
  1040. grub_fs_unregister (&grub_nilfs2_fs);
  1041. }