nilfs2.c 31 KB

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