2009-11-21 Samuel Thibault <samuel.thibault@ens-lyon.org>
[grub2.git] / fs / reiserfs.c
blobfb4f1bc5921dfc2f87aa7718943afadb460d4b16
1 /* reiserfs.c - ReiserFS versions up to 3.6 */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2003,2004,2005,2008 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
21 TODO:
22 implement journal handling (ram replay)
23 test tail packing & direct files
24 validate partition label position
27 #if 0
28 # define GRUB_REISERFS_DEBUG
29 # define GRUB_REISERFS_JOURNALING
30 # define GRUB_HEXDUMP
31 #endif
33 #include <grub/err.h>
34 #include <grub/file.h>
35 #include <grub/mm.h>
36 #include <grub/misc.h>
37 #include <grub/disk.h>
38 #include <grub/dl.h>
39 #include <grub/types.h>
40 #include <grub/fshelp.h>
42 #define MIN(a, b) \
43 ({ typeof (a) _a = (a); \
44 typeof (b) _b = (b); \
45 _a < _b ? _a : _b; })
47 #define MAX(a, b) \
48 ({ typeof (a) _a = (a); \
49 typeof (b) _b = (b); \
50 _a > _b ? _a : _b; })
52 #define REISERFS_SUPER_BLOCK_OFFSET 0x10000
53 #define REISERFS_MAGIC_LEN 12
54 #define REISERFS_MAGIC_STRING "ReIsEr"
55 #define REISERFS_MAGIC_DESC_BLOCK "ReIsErLB"
56 /* If the 3rd bit of an item state is set, then it's visible. */
57 #define GRUB_REISERFS_VISIBLE_MASK ((grub_uint16_t) 0x04)
58 #define REISERFS_MAX_LABEL_LENGTH 16
59 #define REISERFS_LABEL_OFFSET 0x64
61 #define S_IFLNK 0xA000
63 static grub_dl_t my_mod;
65 #define assert(boolean) real_assert (boolean, __FILE__, __LINE__)
66 static inline void
67 real_assert (int boolean, const char *file, const int line)
69 if (! boolean)
70 grub_printf ("Assertion failed at %s:%d\n", file, line);
73 enum grub_reiserfs_item_type
75 GRUB_REISERFS_STAT,
76 GRUB_REISERFS_DIRECTORY,
77 GRUB_REISERFS_DIRECT,
78 GRUB_REISERFS_INDIRECT,
79 /* Matches both _DIRECT and _INDIRECT when searching. */
80 GRUB_REISERFS_ANY,
81 GRUB_REISERFS_UNKNOWN
84 struct grub_reiserfs_superblock
86 grub_uint32_t block_count;
87 grub_uint32_t block_free_count;
88 grub_uint32_t root_block;
89 grub_uint32_t journal_block;
90 grub_uint32_t journal_device;
91 grub_uint32_t journal_original_size;
92 grub_uint32_t journal_max_transaction_size;
93 grub_uint32_t journal_block_count;
94 grub_uint32_t journal_max_batch;
95 grub_uint32_t journal_max_commit_age;
96 grub_uint32_t journal_max_transaction_age;
97 grub_uint16_t block_size;
98 grub_uint16_t oid_max_size;
99 grub_uint16_t oid_current_size;
100 grub_uint16_t state;
101 grub_uint8_t magic_string[REISERFS_MAGIC_LEN];
102 grub_uint32_t function_hash_code;
103 grub_uint16_t tree_height;
104 grub_uint16_t bitmap_number;
105 grub_uint16_t version;
106 grub_uint16_t reserved;
107 grub_uint32_t inode_generation;
108 grub_uint8_t unused[4];
109 grub_uint16_t uuid[8];
110 } __attribute__ ((packed));
112 struct grub_reiserfs_journal_header
114 grub_uint32_t last_flush_uid;
115 grub_uint32_t unflushed_offset;
116 grub_uint32_t mount_id;
117 } __attribute__ ((packed));
119 struct grub_reiserfs_description_block
121 grub_uint32_t id;
122 grub_uint32_t len;
123 grub_uint32_t mount_id;
124 grub_uint32_t real_blocks[0];
125 } __attribute__ ((packed));
127 struct grub_reiserfs_commit_block
129 grub_uint32_t id;
130 grub_uint32_t len;
131 grub_uint32_t real_blocks[0];
132 } __attribute__ ((packed));
134 struct grub_reiserfs_stat_item_v1
136 grub_uint16_t mode;
137 grub_uint16_t hardlink_count;
138 grub_uint16_t uid;
139 grub_uint16_t gid;
140 grub_uint32_t size;
141 grub_uint32_t atime;
142 grub_uint32_t mtime;
143 grub_uint32_t ctime;
144 grub_uint32_t rdev;
145 grub_uint32_t first_direct_byte;
146 } __attribute__ ((packed));
148 struct grub_reiserfs_stat_item_v2
150 grub_uint16_t mode;
151 grub_uint16_t reserved;
152 grub_uint32_t hardlink_count;
153 grub_uint64_t size;
154 grub_uint32_t uid;
155 grub_uint32_t gid;
156 grub_uint32_t atime;
157 grub_uint32_t mtime;
158 grub_uint32_t ctime;
159 grub_uint32_t blocks;
160 grub_uint32_t first_direct_byte;
161 } __attribute__ ((packed));
163 struct grub_reiserfs_key
165 grub_uint32_t directory_id;
166 grub_uint32_t object_id;
167 union
169 struct
171 grub_uint32_t offset;
172 grub_uint32_t type;
173 } v1 __attribute__ ((packed));
174 struct
176 grub_uint64_t offset_type;
177 } v2 __attribute__ ((packed));
178 } u;
179 } __attribute__ ((packed));
181 struct grub_reiserfs_item_header
183 struct grub_reiserfs_key key;
184 union
186 grub_uint16_t free_space;
187 grub_uint16_t entry_count;
188 } u __attribute__ ((packed));
189 grub_uint16_t item_size;
190 grub_uint16_t item_location;
191 grub_uint16_t version;
192 } __attribute__ ((packed));
194 struct grub_reiserfs_block_header
196 grub_uint16_t level;
197 grub_uint16_t item_count;
198 grub_uint16_t free_space;
199 grub_uint16_t reserved;
200 struct grub_reiserfs_key block_right_delimiting_key;
201 } __attribute__ ((packed));
203 struct grub_reiserfs_disk_child
205 grub_uint32_t block_number;
206 grub_uint16_t size;
207 grub_uint16_t reserved;
208 } __attribute__ ((packed));
210 struct grub_reiserfs_directory_header
212 grub_uint32_t offset;
213 grub_uint32_t directory_id;
214 grub_uint32_t object_id;
215 grub_uint16_t location;
216 grub_uint16_t state;
217 } __attribute__ ((packed));
219 struct grub_fshelp_node
221 struct grub_reiserfs_data *data;
222 grub_uint32_t block_number; /* 0 if node is not found. */
223 grub_uint16_t block_position;
224 grub_uint64_t next_offset;
225 enum grub_reiserfs_item_type type; /* To know how to read the header. */
226 struct grub_reiserfs_item_header header;
229 /* Returned when opening a file. */
230 struct grub_reiserfs_data
232 struct grub_reiserfs_superblock superblock;
233 grub_disk_t disk;
236 /* Internal-only functions. Not to be used outside of this file. */
238 /* Return the type of given v2 key. */
239 static enum grub_reiserfs_item_type
240 grub_reiserfs_get_key_v2_type (const struct grub_reiserfs_key *key)
242 switch (grub_le_to_cpu64 (key->u.v2.offset_type) >> 60)
244 case 0:
245 return GRUB_REISERFS_STAT;
246 case 15:
247 return GRUB_REISERFS_ANY;
248 case 3:
249 return GRUB_REISERFS_DIRECTORY;
250 case 2:
251 return GRUB_REISERFS_DIRECT;
252 case 1:
253 return GRUB_REISERFS_INDIRECT;
255 return GRUB_REISERFS_UNKNOWN;
258 /* Return the type of given v1 key. */
259 static enum grub_reiserfs_item_type
260 grub_reiserfs_get_key_v1_type (const struct grub_reiserfs_key *key)
262 switch (grub_le_to_cpu32 (key->u.v1.type))
264 case 0:
265 return GRUB_REISERFS_STAT;
266 case 555:
267 return GRUB_REISERFS_ANY;
268 case 500:
269 return GRUB_REISERFS_DIRECTORY;
270 case 0x20000000:
271 case 0xFFFFFFFF:
272 return GRUB_REISERFS_DIRECT;
273 case 0x10000000:
274 case 0xFFFFFFFE:
275 return GRUB_REISERFS_INDIRECT;
277 return GRUB_REISERFS_UNKNOWN;
280 /* Return 1 if the given key is version 1 key, 2 otherwise. */
281 static int
282 grub_reiserfs_get_key_version (const struct grub_reiserfs_key *key)
284 return grub_reiserfs_get_key_v1_type (key) == GRUB_REISERFS_UNKNOWN ? 2 : 1;
287 #ifdef GRUB_HEXDUMP
288 static void
289 grub_hexdump (char *buffer, grub_size_t len)
291 grub_size_t a;
292 for (a = 0; a < len; a++)
294 if (! (a & 0x0F))
295 grub_printf ("\n%08x ", a);
296 grub_printf ("%02x ",
297 ((unsigned int) ((unsigned char *) buffer)[a]) & 0xFF);
299 grub_printf ("\n");
301 #endif
303 #ifdef GRUB_REISERFS_DEBUG
304 static grub_uint64_t
305 grub_reiserfs_get_key_offset (const struct grub_reiserfs_key *key);
307 static enum grub_reiserfs_item_type
308 grub_reiserfs_get_key_type (const struct grub_reiserfs_key *key);
310 static void
311 grub_reiserfs_print_key (const struct grub_reiserfs_key *key)
313 unsigned int a;
314 char *reiserfs_type_strings[] = {
315 "stat ",
316 "directory",
317 "direct ",
318 "indirect ",
319 "any ",
320 "unknown "
323 for (a = 0; a < sizeof (struct grub_reiserfs_key); a++)
324 grub_printf ("%02x ", ((unsigned int) ((unsigned char *) key)[a]) & 0xFF);
325 grub_printf ("parent id = 0x%08x, self id = 0x%08x, type = %s, offset = ",
326 grub_le_to_cpu32 (key->directory_id),
327 grub_le_to_cpu32 (key->object_id),
328 reiserfs_type_strings [grub_reiserfs_get_key_type (key)]);
329 if (grub_reiserfs_get_key_version (key) == 1)
330 grub_printf("%08x", (unsigned int) grub_reiserfs_get_key_offset (key));
331 else
332 grub_printf("0x%07x%08x",
333 (unsigned) (grub_reiserfs_get_key_offset (key) >> 32),
334 (unsigned) (grub_reiserfs_get_key_offset (key) & 0xFFFFFFFF));
335 grub_printf ("\n");
337 #endif
339 /* Return the offset of given key. */
340 static grub_uint64_t
341 grub_reiserfs_get_key_offset (const struct grub_reiserfs_key *key)
343 if (grub_reiserfs_get_key_version (key) == 1)
344 return grub_le_to_cpu32 (key->u.v1.offset);
345 else
346 return grub_le_to_cpu64 (key->u.v2.offset_type) & (~0ULL >> 4);
349 /* Set the offset of given key. */
350 static void
351 grub_reiserfs_set_key_offset (struct grub_reiserfs_key *key,
352 grub_uint64_t value)
354 if (grub_reiserfs_get_key_version (key) == 1)
355 key->u.v1.offset = grub_cpu_to_le32 (value);
356 else
357 key->u.v2.offset_type \
358 = ((key->u.v2.offset_type & grub_cpu_to_le64 (15ULL << 60))
359 | grub_cpu_to_le64 (value & (~0ULL >> 4)));
362 /* Return the type of given key. */
363 static enum grub_reiserfs_item_type
364 grub_reiserfs_get_key_type (const struct grub_reiserfs_key *key)
366 if (grub_reiserfs_get_key_version (key) == 1)
367 return grub_reiserfs_get_key_v1_type (key);
368 else
369 return grub_reiserfs_get_key_v2_type (key);
372 /* Set the type of given key, with given version number. */
373 static void
374 grub_reiserfs_set_key_type (struct grub_reiserfs_key *key,
375 enum grub_reiserfs_item_type grub_type,
376 int version)
378 grub_uint32_t type;
380 switch (grub_type)
382 case GRUB_REISERFS_STAT:
383 type = 0;
384 break;
385 case GRUB_REISERFS_ANY:
386 type = (version == 1) ? 555 : 15;
387 break;
388 case GRUB_REISERFS_DIRECTORY:
389 type = (version == 1) ? 500 : 3;
390 break;
391 case GRUB_REISERFS_DIRECT:
392 type = (version == 1) ? 0xFFFFFFFF : 2;
393 break;
394 case GRUB_REISERFS_INDIRECT:
395 type = (version == 1) ? 0xFFFFFFFE : 1;
396 break;
397 default:
398 return;
401 if (version == 1)
402 key->u.v1.type = grub_cpu_to_le32 (type);
403 else
404 key->u.v2.offset_type
405 = ((key->u.v2.offset_type & grub_cpu_to_le64 (~0ULL >> 4))
406 | grub_cpu_to_le64 ((grub_uint64_t) type << 60));
408 assert (grub_reiserfs_get_key_type (key) == grub_type);
411 /* -1 if key 1 if lower than key 2.
412 0 if key 1 is equal to key 2.
413 1 if key 1 is higher than key 2. */
414 static int
415 grub_reiserfs_compare_keys (const struct grub_reiserfs_key *key1,
416 const struct grub_reiserfs_key *key2)
418 grub_uint64_t offset1, offset2;
419 enum grub_reiserfs_item_type type1, type2;
420 grub_uint32_t id1, id2;
422 if (! key1 || ! key2)
423 return -2;
425 id1 = grub_le_to_cpu32 (key1->directory_id);
426 id2 = grub_le_to_cpu32 (key2->directory_id);
427 if (id1 < id2)
428 return -1;
429 if (id1 > id2)
430 return 1;
432 id1 = grub_le_to_cpu32 (key1->object_id);
433 id2 = grub_le_to_cpu32 (key2->object_id);
434 if (id1 < id2)
435 return -1;
436 if (id1 > id2)
437 return 1;
439 offset1 = grub_reiserfs_get_key_offset (key1);
440 offset2 = grub_reiserfs_get_key_offset (key2);
441 if (offset1 < offset2)
442 return -1;
443 if (offset1 > offset2)
444 return 1;
446 type1 = grub_reiserfs_get_key_type (key1);
447 type2 = grub_reiserfs_get_key_type (key2);
448 if ((type1 == GRUB_REISERFS_ANY
449 && (type2 == GRUB_REISERFS_DIRECT
450 || type2 == GRUB_REISERFS_INDIRECT))
451 || (type2 == GRUB_REISERFS_ANY
452 && (type1 == GRUB_REISERFS_DIRECT
453 || type1 == GRUB_REISERFS_INDIRECT)))
454 return 0;
455 if (type1 < type2)
456 return -1;
457 if (type1 > type2)
458 return 1;
460 return 0;
463 /* Find the item identified by KEY in mounted filesystem DATA, and fill ITEM
464 accordingly to what was found. */
465 static grub_err_t
466 grub_reiserfs_get_item (struct grub_reiserfs_data *data,
467 const struct grub_reiserfs_key *key,
468 struct grub_fshelp_node *item)
470 grub_uint32_t block_number;
471 struct grub_reiserfs_block_header *block_header = 0;
472 struct grub_reiserfs_key *block_key = 0;
473 grub_uint16_t block_size, item_count, current_level;
474 grub_uint16_t i;
475 grub_uint16_t previous_level = ~0;
476 struct grub_reiserfs_item_header *item_headers = 0;
478 if (! data)
480 grub_error (GRUB_ERR_TEST_FAILURE, "data is NULL");
481 goto fail;
484 if (! key)
486 grub_error (GRUB_ERR_TEST_FAILURE, "key is NULL");
487 goto fail;
490 if (! item)
492 grub_error (GRUB_ERR_TEST_FAILURE, "item is NULL");
493 goto fail;
496 block_size = grub_le_to_cpu16 (data->superblock.block_size);
497 block_number = grub_le_to_cpu32 (data->superblock.root_block);
498 #ifdef GRUB_REISERFS_DEBUG
499 grub_printf("Searching for ");
500 grub_reiserfs_print_key (key);
501 #endif
502 block_header = grub_malloc (block_size);
503 if (! block_header)
504 goto fail;
506 item->next_offset = 0;
509 grub_disk_read (data->disk,
510 block_number * (block_size >> GRUB_DISK_SECTOR_BITS),
511 (((grub_off_t) block_number * block_size)
512 & (GRUB_DISK_SECTOR_SIZE - 1)),
513 block_size, block_header);
514 if (grub_errno)
515 goto fail;
516 current_level = grub_le_to_cpu16 (block_header->level);
517 grub_dprintf ("reiserfs_tree", " at level %d\n", current_level);
518 if (current_level >= previous_level)
520 grub_dprintf ("reiserfs_tree", "level loop detected, aborting\n");
521 grub_error (GRUB_ERR_FILE_READ_ERROR, "level loop");
522 goto fail;
524 previous_level = current_level;
525 item_count = grub_le_to_cpu16 (block_header->item_count);
526 grub_dprintf ("reiserfs_tree", " number of contained items : %d\n",
527 item_count);
528 if (current_level > 1)
530 /* Internal node. Navigate to the child that should contain
531 the searched key. */
532 struct grub_reiserfs_key *keys
533 = (struct grub_reiserfs_key *) (block_header + 1);
534 struct grub_reiserfs_disk_child *children
535 = ((struct grub_reiserfs_disk_child *)
536 (keys + item_count));
538 for (i = 0;
539 i < item_count
540 && grub_reiserfs_compare_keys (key, &(keys[i])) >= 0;
541 i++)
543 #ifdef GRUB_REISERFS_DEBUG
544 grub_printf("i %03d/%03d ", i + 1, item_count + 1);
545 grub_reiserfs_print_key (&(keys[i]));
546 #endif
548 block_number = grub_le_to_cpu32 (children[i].block_number);
549 if ((i < item_count) && (key->directory_id == keys[i].directory_id)
550 && (key->object_id == keys[i].object_id))
551 item->next_offset = grub_reiserfs_get_key_offset(&(keys[i]));
552 #ifdef GRUB_REISERFS_DEBUG
553 if (i == item_count
554 || grub_reiserfs_compare_keys (key, &(keys[i])) == 0)
555 grub_printf(">");
556 else
557 grub_printf("<");
558 if (i < item_count)
560 grub_printf (" %03d/%03d ", i + 1, item_count + 1);
561 grub_reiserfs_print_key (&(keys[i]));
562 if (i + 1 < item_count)
564 grub_printf ("+ %03d/%03d ", i + 2, item_count);
565 grub_reiserfs_print_key (&(keys[i + 1]));
568 else
569 grub_printf ("Accessing rightmost child at block %d.\n",
570 block_number);
571 #endif
573 else
575 /* Leaf node. Check that the key is actually present. */
576 item_headers
577 = (struct grub_reiserfs_item_header *) (block_header + 1);
578 for (i = 0;
579 i < item_count
580 && (grub_reiserfs_compare_keys (key, &(item_headers[i].key))
581 != 0);
582 i++)
584 #ifdef GRUB_REISERFS_DEBUG
585 if (key->directory_id == item_headers[i].key.directory_id && \
586 key->object_id == item_headers[i].key.object_id)
587 grub_printf("C");
588 else
589 grub_printf(" ");
590 grub_printf(" %03d/%03d ", i + 1, item_count);
591 grub_reiserfs_print_key (&(item_headers[i].key));
592 #endif
594 if (i < item_count)
595 block_key = &(item_headers[i].key);
598 while (current_level > 1);
600 item->data = data;
602 if (i == item_count || grub_reiserfs_compare_keys (key, block_key))
604 item->block_number = 0;
605 item->block_position = 0;
606 item->type = GRUB_REISERFS_UNKNOWN;
607 #ifdef GRUB_REISERFS_DEBUG
608 grub_printf("Not found.\n");
609 #endif
611 else
613 item->block_number = block_number;
614 item->block_position = i;
615 item->type = grub_reiserfs_get_key_type (block_key);
616 grub_memcpy (&(item->header), &(item_headers[i]),
617 sizeof (struct grub_reiserfs_item_header));
618 #ifdef GRUB_REISERFS_DEBUG
619 grub_printf ("F %03d/%03d ", i + 1, item_count);
620 grub_reiserfs_print_key (block_key);
621 #endif
624 assert (grub_errno == GRUB_ERR_NONE);
625 grub_free (block_header);
626 return GRUB_ERR_NONE;
628 fail:
629 assert (grub_errno != GRUB_ERR_NONE);
630 grub_free (block_header);
631 assert (grub_errno != GRUB_ERR_NONE);
632 return grub_errno;
635 /* Return the path of the file which is pointed at by symlink NODE. */
636 static char *
637 grub_reiserfs_read_symlink (grub_fshelp_node_t node)
639 char *symlink_buffer = 0;
640 grub_uint16_t block_size;
641 grub_disk_addr_t block;
642 grub_off_t offset;
643 grub_size_t len;
644 struct grub_fshelp_node found;
645 struct grub_reiserfs_key key;
647 grub_memcpy (&key, &(node->header.key), sizeof (key));
648 grub_reiserfs_set_key_offset (&key, 1);
649 grub_reiserfs_set_key_type (&key, GRUB_REISERFS_DIRECT,
650 grub_reiserfs_get_key_version (&key));
652 if (grub_reiserfs_get_item (node->data, &key, &found) != GRUB_ERR_NONE)
653 goto fail;
655 if (found.block_number == 0)
656 goto fail;
658 block_size = grub_le_to_cpu16 (node->data->superblock.block_size);
659 len = grub_le_to_cpu16 (found.header.item_size);
660 block = found.block_number * (block_size >> GRUB_DISK_SECTOR_BITS);
661 offset = grub_le_to_cpu16 (found.header.item_location);
663 symlink_buffer = grub_malloc (len + 1);
664 if (! symlink_buffer)
665 goto fail;
667 grub_disk_read (node->data->disk, block, offset, len, symlink_buffer);
668 if (grub_errno)
669 goto fail;
671 symlink_buffer[len] = 0;
672 return symlink_buffer;
674 fail:
675 grub_free (symlink_buffer);
676 return 0;
679 /* Fill the mounted filesystem structure and return it. */
680 static struct grub_reiserfs_data *
681 grub_reiserfs_mount (grub_disk_t disk)
683 struct grub_reiserfs_data *data = 0;
684 data = grub_malloc (sizeof (*data));
685 if (! data)
686 goto fail;
687 grub_disk_read (disk, REISERFS_SUPER_BLOCK_OFFSET / GRUB_DISK_SECTOR_SIZE,
688 0, sizeof (data->superblock), &(data->superblock));
689 if (grub_errno)
690 goto fail;
691 if (grub_memcmp (data->superblock.magic_string,
692 REISERFS_MAGIC_STRING, sizeof (REISERFS_MAGIC_STRING) - 1))
694 grub_error (GRUB_ERR_BAD_FS, "not a reiserfs filesystem");
695 goto fail;
697 data->disk = disk;
698 return data;
700 fail:
701 /* Disk is too small to contain a ReiserFS. */
702 if (grub_errno == GRUB_ERR_OUT_OF_RANGE)
703 grub_error (GRUB_ERR_BAD_FS, "not a reiserfs filesystem");
705 grub_free (data);
706 return 0;
709 /* Call HOOK for each file in directory ITEM. */
710 static int
711 grub_reiserfs_iterate_dir (grub_fshelp_node_t item,
712 int NESTED_FUNC_ATTR
713 (*hook) (const char *filename,
714 enum grub_fshelp_filetype filetype,
715 grub_fshelp_node_t node))
717 struct grub_reiserfs_data *data = item->data;
718 struct grub_reiserfs_block_header *block_header = 0;
719 grub_uint16_t block_size, block_position;
720 grub_uint32_t block_number;
721 grub_uint64_t next_offset = item->next_offset;
722 int ret = 0;
724 if (item->type != GRUB_REISERFS_DIRECTORY)
726 grub_error (GRUB_ERR_BAD_FILE_TYPE,
727 "grub_reiserfs_iterate_dir called on a non-directory item");
728 goto fail;
730 block_size = grub_le_to_cpu16 (data->superblock.block_size);
731 block_header = grub_malloc (block_size);
732 if (! block_header)
733 goto fail;
734 block_number = item->block_number;
735 block_position = item->block_position;
736 grub_dprintf ("reiserfs", "Iterating directory...\n");
739 struct grub_reiserfs_directory_header *directory_headers;
740 struct grub_fshelp_node directory_item;
741 grub_uint16_t entry_count, entry_number;
742 struct grub_reiserfs_item_header *item_headers;
744 grub_disk_read (data->disk,
745 block_number * (block_size >> GRUB_DISK_SECTOR_BITS),
746 (((grub_off_t) block_number * block_size)
747 & (GRUB_DISK_SECTOR_SIZE - 1)),
748 block_size, (char *) block_header);
749 if (grub_errno)
750 goto fail;
752 #if 0
753 if (grub_le_to_cpu16 (block_header->level) != 1)
755 grub_error (GRUB_ERR_TEST_FAILURE,
756 "reiserfs: block %d is not a leaf block",
757 block_number);
758 goto fail;
760 #endif
762 item_headers = (struct grub_reiserfs_item_header *) (block_header + 1);
763 directory_headers
764 = ((struct grub_reiserfs_directory_header *)
765 ((char *) block_header
766 + grub_le_to_cpu16 (item_headers[block_position].item_location)));
767 entry_count
768 = grub_le_to_cpu16 (item_headers[block_position].u.entry_count);
769 for (entry_number = 0; entry_number < entry_count; entry_number++)
771 struct grub_reiserfs_directory_header *directory_header
772 = &directory_headers[entry_number];
773 grub_uint16_t entry_state
774 = grub_le_to_cpu16 (directory_header->state);
776 if (entry_state & GRUB_REISERFS_VISIBLE_MASK)
778 grub_fshelp_node_t entry_item;
779 struct grub_reiserfs_key entry_key;
780 enum grub_reiserfs_item_type entry_type;
781 char *entry_name;
783 entry_name = (((char *) directory_headers)
784 + grub_le_to_cpu16 (directory_header->location));
785 entry_key.directory_id = directory_header->directory_id;
786 entry_key.object_id = directory_header->object_id;
787 entry_key.u.v2.offset_type = 0;
788 grub_reiserfs_set_key_type (&entry_key, GRUB_REISERFS_DIRECTORY,
790 grub_reiserfs_set_key_offset (&entry_key, 1);
792 entry_item = grub_malloc (sizeof (*entry_item));
793 if (! entry_item)
794 goto fail;
796 if (grub_reiserfs_get_item (data, &entry_key, entry_item)
797 != GRUB_ERR_NONE)
799 grub_free (entry_item);
800 goto fail;
803 if (entry_item->type == GRUB_REISERFS_DIRECTORY)
804 entry_type = GRUB_FSHELP_DIR;
805 else
807 grub_uint32_t entry_block_number;
808 /* Order is very important here.
809 First set the offset to 0 using current key version.
810 Then change the key type, which affects key version
811 detection. */
812 grub_reiserfs_set_key_offset (&entry_key, 0);
813 grub_reiserfs_set_key_type (&entry_key, GRUB_REISERFS_STAT,
815 if (grub_reiserfs_get_item (data, &entry_key, entry_item)
816 != GRUB_ERR_NONE)
818 grub_free (entry_item);
819 goto fail;
822 if (entry_item->block_number != 0)
824 grub_uint16_t entry_version;
825 entry_version
826 = grub_le_to_cpu16 (entry_item->header.version);
827 entry_block_number = entry_item->block_number;
828 #if 0
829 grub_dprintf ("reiserfs",
830 "version %04x block %08x (%08x) position %08x\n",
831 entry_version, entry_block_number,
832 ((grub_disk_addr_t) entry_block_number * block_size) / GRUB_DISK_SECTOR_SIZE,
833 grub_le_to_cpu16 (entry_item->header.item_location));
834 #endif
835 if (entry_version == 0) /* Version 1 stat item. */
837 struct grub_reiserfs_stat_item_v1 entry_v1_stat;
838 grub_disk_read (data->disk,
839 entry_block_number * (block_size >> GRUB_DISK_SECTOR_BITS),
840 grub_le_to_cpu16 (entry_item->header.item_location),
841 sizeof (entry_v1_stat),
842 (char *) &entry_v1_stat);
843 if (grub_errno)
844 goto fail;
845 #if 0
846 grub_dprintf ("reiserfs",
847 "%04x %04x %04x %04x %08x %08x | %08x %08x %08x %08x\n",
848 grub_le_to_cpu16 (entry_v1_stat.mode),
849 grub_le_to_cpu16 (entry_v1_stat.hardlink_count),
850 grub_le_to_cpu16 (entry_v1_stat.uid),
851 grub_le_to_cpu16 (entry_v1_stat.gid),
852 grub_le_to_cpu32 (entry_v1_stat.size),
853 grub_le_to_cpu32 (entry_v1_stat.atime),
854 grub_le_to_cpu32 (entry_v1_stat.mtime),
855 grub_le_to_cpu32 (entry_v1_stat.ctime),
856 grub_le_to_cpu32 (entry_v1_stat.rdev),
857 grub_le_to_cpu32 (entry_v1_stat.first_direct_byte));
858 grub_dprintf ("reiserfs",
859 "%04x %04x %04x %04x %08x %08x | %08x %08x %08x %08x\n",
860 entry_v1_stat.mode,
861 entry_v1_stat.hardlink_count,
862 entry_v1_stat.uid,
863 entry_v1_stat.gid,
864 entry_v1_stat.size,
865 entry_v1_stat.atime,
866 entry_v1_stat.mtime,
867 entry_v1_stat.ctime,
868 entry_v1_stat.rdev,
869 entry_v1_stat.first_direct_byte);
870 #endif
871 if ((grub_le_to_cpu16 (entry_v1_stat.mode) & S_IFLNK)
872 == S_IFLNK)
873 entry_type = GRUB_FSHELP_SYMLINK;
874 else
875 entry_type = GRUB_FSHELP_REG;
877 else
879 struct grub_reiserfs_stat_item_v2 entry_v2_stat;
880 grub_disk_read (data->disk,
881 entry_block_number * (block_size >> GRUB_DISK_SECTOR_BITS),
882 grub_le_to_cpu16 (entry_item->header.item_location),
883 sizeof (entry_v2_stat),
884 (char *) &entry_v2_stat);
885 if (grub_errno)
886 goto fail;
887 #if 0
888 grub_dprintf ("reiserfs",
889 "%04x %04x %08x %08x%08x | %08x %08x %08x %08x | %08x %08x %08x\n",
890 grub_le_to_cpu16 (entry_v2_stat.mode),
891 grub_le_to_cpu16 (entry_v2_stat.reserved),
892 grub_le_to_cpu32 (entry_v2_stat.hardlink_count),
893 (unsigned int) (grub_le_to_cpu64 (entry_v2_stat.size) >> 32),
894 (unsigned int) (grub_le_to_cpu64 (entry_v2_stat.size) && 0xFFFFFFFF),
895 grub_le_to_cpu32 (entry_v2_stat.uid),
896 grub_le_to_cpu32 (entry_v2_stat.gid),
897 grub_le_to_cpu32 (entry_v2_stat.atime),
898 grub_le_to_cpu32 (entry_v2_stat.mtime),
899 grub_le_to_cpu32 (entry_v2_stat.ctime),
900 grub_le_to_cpu32 (entry_v2_stat.blocks),
901 grub_le_to_cpu32 (entry_v2_stat.first_direct_byte));
902 grub_dprintf ("reiserfs",
903 "%04x %04x %08x %08x%08x | %08x %08x %08x %08x | %08x %08x %08x\n",
904 entry_v2_stat.mode,
905 entry_v2_stat.reserved,
906 entry_v2_stat.hardlink_count,
907 (unsigned int) (entry_v2_stat.size >> 32),
908 (unsigned int) (entry_v2_stat.size && 0xFFFFFFFF),
909 entry_v2_stat.uid,
910 entry_v2_stat.gid,
911 entry_v2_stat.atime,
912 entry_v2_stat.mtime,
913 entry_v2_stat.ctime,
914 entry_v2_stat.blocks,
915 entry_v2_stat.first_direct_byte);
916 #endif
917 if ((grub_le_to_cpu16 (entry_v2_stat.mode) & S_IFLNK)
918 == S_IFLNK)
919 entry_type = GRUB_FSHELP_SYMLINK;
920 else
921 entry_type = GRUB_FSHELP_REG;
924 else
926 /* Pseudo file ".." never has stat block. */
927 if (grub_strcmp (entry_name, ".."))
928 grub_dprintf ("reiserfs",
929 "Warning : %s has no stat block !\n",
930 entry_name);
931 grub_free (entry_item);
932 continue;
935 if (hook (entry_name, entry_type, entry_item))
937 grub_dprintf ("reiserfs", "Found : %s, type=%d\n",
938 entry_name, entry_type);
939 ret = 1;
940 goto found;
943 *entry_name = 0; /* Make sure next entry name (which is just
944 before this one in disk order) stops before
945 the current one. */
949 if (next_offset == 0)
950 break;
952 grub_reiserfs_set_key_offset (&(item_headers[block_position].key),
953 next_offset);
954 if (grub_reiserfs_get_item (data, &(item_headers[block_position].key),
955 &directory_item) != GRUB_ERR_NONE)
956 goto fail;
957 block_number = directory_item.block_number;
958 block_position = directory_item.block_position;
959 next_offset = directory_item.next_offset;
961 while (block_number);
963 found:
964 assert (grub_errno == GRUB_ERR_NONE);
965 grub_free (block_header);
966 return ret;
967 fail:
968 assert (grub_errno != GRUB_ERR_NONE);
969 grub_free (block_header);
970 return 0;
973 /****************************************************************************/
974 /* grub api functions */
975 /****************************************************************************/
977 /* Open a file named NAME and initialize FILE. */
978 static grub_err_t
979 grub_reiserfs_open (struct grub_file *file, const char *name)
981 struct grub_reiserfs_data *data = 0;
982 struct grub_fshelp_node root, *found = 0, info;
983 struct grub_reiserfs_key key;
984 grub_uint32_t block_number;
985 grub_uint16_t entry_version, block_size, entry_location;
987 grub_dl_ref (my_mod);
988 data = grub_reiserfs_mount (file->device->disk);
989 if (! data)
990 goto fail;
991 block_size = grub_le_to_cpu16 (data->superblock.block_size);
992 key.directory_id = grub_cpu_to_le32 (1);
993 key.object_id = grub_cpu_to_le32 (2);
994 key.u.v2.offset_type = 0;
995 grub_reiserfs_set_key_type (&key, GRUB_REISERFS_DIRECTORY, 2);
996 grub_reiserfs_set_key_offset (&key, 1);
997 if (grub_reiserfs_get_item (data, &key, &root) != GRUB_ERR_NONE)
998 goto fail;
999 if (root.block_number == 0)
1001 grub_error (GRUB_ERR_BAD_FS, "Unable to find root item");
1002 goto fail; /* Should never happen since checked at mount. */
1004 grub_fshelp_find_file (name, &root, &found,
1005 grub_reiserfs_iterate_dir,
1006 grub_reiserfs_read_symlink, GRUB_FSHELP_REG);
1007 if (grub_errno)
1008 goto fail;
1009 key.directory_id = found->header.key.directory_id;
1010 key.object_id = found->header.key.object_id;
1011 grub_reiserfs_set_key_type (&key, GRUB_REISERFS_STAT, 2);
1012 grub_reiserfs_set_key_offset (&key, 0);
1013 if (grub_reiserfs_get_item (data, &key, &info) != GRUB_ERR_NONE)
1014 goto fail;
1015 if (info.block_number == 0)
1017 grub_error (GRUB_ERR_BAD_FS, "Unable to find searched item");
1018 goto fail;
1020 entry_version = grub_le_to_cpu16 (info.header.version);
1021 entry_location = grub_le_to_cpu16 (info.header.item_location);
1022 block_number = info.block_number;
1023 if (entry_version == 0) /* Version 1 stat item. */
1025 struct grub_reiserfs_stat_item_v1 entry_v1_stat;
1026 grub_disk_read (data->disk,
1027 block_number * (block_size >> GRUB_DISK_SECTOR_BITS),
1028 entry_location
1029 + (((grub_off_t) block_number * block_size)
1030 & (GRUB_DISK_SECTOR_SIZE - 1)),
1031 sizeof (entry_v1_stat), &entry_v1_stat);
1032 if (grub_errno)
1033 goto fail;
1034 file->size = (grub_off_t) grub_le_to_cpu64 (entry_v1_stat.size);
1036 else
1038 struct grub_reiserfs_stat_item_v2 entry_v2_stat;
1039 grub_disk_read (data->disk,
1040 block_number * (block_size >> GRUB_DISK_SECTOR_BITS),
1041 entry_location
1042 + (((grub_off_t) block_number * block_size)
1043 & (GRUB_DISK_SECTOR_SIZE - 1)),
1044 sizeof (entry_v2_stat), &entry_v2_stat);
1045 if (grub_errno)
1046 goto fail;
1047 file->size = (grub_off_t) grub_le_to_cpu64 (entry_v2_stat.size);
1049 grub_dprintf ("reiserfs", "file size : %d (%08x%08x)\n",
1050 (unsigned int) file->size,
1051 (unsigned int) (file->size >> 32), (unsigned int) file->size);
1052 file->offset = 0;
1053 file->data = found;
1054 return GRUB_ERR_NONE;
1056 fail:
1057 assert (grub_errno != GRUB_ERR_NONE);
1058 grub_free (found);
1059 grub_free (data);
1060 grub_dl_unref (my_mod);
1061 return grub_errno;
1064 static grub_ssize_t
1065 grub_reiserfs_read (grub_file_t file, char *buf, grub_size_t len)
1067 unsigned int indirect_block, indirect_block_count;
1068 struct grub_reiserfs_key key;
1069 struct grub_fshelp_node *node = file->data;
1070 struct grub_reiserfs_data *data = node->data;
1071 struct grub_fshelp_node found;
1072 grub_uint16_t block_size = grub_le_to_cpu16 (data->superblock.block_size);
1073 grub_uint16_t item_size;
1074 grub_uint32_t *indirect_block_ptr = 0;
1075 grub_uint64_t current_key_offset = 1;
1076 grub_off_t initial_position, current_position, final_position, length;
1077 grub_disk_addr_t block;
1078 grub_off_t offset;
1080 key.directory_id = node->header.key.directory_id;
1081 key.object_id = node->header.key.object_id;
1082 key.u.v2.offset_type = 0;
1083 grub_reiserfs_set_key_type (&key, GRUB_REISERFS_ANY, 2);
1084 initial_position = file->offset;
1085 current_position = 0;
1086 final_position = MIN (len + initial_position, file->size);
1087 grub_dprintf ("reiserfs",
1088 "Reading from %lld to %lld (%lld instead of requested %ld)\n",
1089 (unsigned long long) initial_position,
1090 (unsigned long long) final_position,
1091 (unsigned long long) (final_position - initial_position),
1092 (unsigned long) len);
1093 while (current_position < final_position)
1095 grub_reiserfs_set_key_offset (&key, current_key_offset);
1097 if (grub_reiserfs_get_item (data, &key, &found) != GRUB_ERR_NONE)
1098 goto fail;
1099 if (found.block_number == 0)
1100 goto fail;
1101 item_size = grub_le_to_cpu16 (found.header.item_size);
1102 switch (found.type)
1104 case GRUB_REISERFS_DIRECT:
1105 block = found.block_number * (block_size >> GRUB_DISK_SECTOR_BITS);
1106 grub_dprintf ("reiserfs_blocktype", "D: %u\n", (unsigned) block);
1107 if (initial_position < current_position + item_size)
1109 offset = MAX ((signed) (initial_position - current_position), 0);
1110 length = (MIN (item_size, final_position - current_position)
1111 - offset);
1112 grub_dprintf ("reiserfs",
1113 "Reading direct block %u from %u to %u...\n",
1114 (unsigned) block, (unsigned) offset,
1115 (unsigned) (offset + length));
1116 found.data->disk->read_hook = file->read_hook;
1117 grub_disk_read (found.data->disk,
1118 block,
1119 offset
1120 + grub_le_to_cpu16 (found.header.item_location),
1121 length, buf);
1122 found.data->disk->read_hook = 0;
1123 if (grub_errno)
1124 goto fail;
1125 buf += length;
1126 current_position += offset + length;
1128 else
1129 current_position += item_size;
1130 break;
1131 case GRUB_REISERFS_INDIRECT:
1132 indirect_block_count = item_size / sizeof (*indirect_block_ptr);
1133 indirect_block_ptr = grub_malloc (item_size);
1134 if (! indirect_block_ptr)
1135 goto fail;
1136 grub_disk_read (found.data->disk,
1137 found.block_number * (block_size >> GRUB_DISK_SECTOR_BITS),
1138 grub_le_to_cpu16 (found.header.item_location),
1139 item_size, indirect_block_ptr);
1140 if (grub_errno)
1141 goto fail;
1142 found.data->disk->read_hook = file->read_hook;
1143 for (indirect_block = 0;
1144 indirect_block < indirect_block_count
1145 && current_position < final_position;
1146 indirect_block++)
1148 block = grub_le_to_cpu32 (indirect_block_ptr[indirect_block]) *
1149 (block_size >> GRUB_DISK_SECTOR_BITS);
1150 grub_dprintf ("reiserfs_blocktype", "I: %u\n", (unsigned) block);
1151 if (current_position + block_size >= initial_position)
1153 offset = MAX ((signed) (initial_position - current_position),
1155 length = (MIN (block_size, final_position - current_position)
1156 - offset);
1157 grub_dprintf ("reiserfs",
1158 "Reading indirect block %u from %u to %u...\n",
1159 (unsigned) block, (unsigned) offset,
1160 (unsigned) (offset + length));
1161 #if 0
1162 grub_dprintf ("reiserfs",
1163 "\nib=%04d/%04d, ip=%d, cp=%d, fp=%d, off=%d, l=%d, tl=%d\n",
1164 indirect_block + 1, indirect_block_count,
1165 initial_position, current_position,
1166 final_position, offset, length, len);
1167 #endif
1168 grub_disk_read (found.data->disk, block, offset, length, buf);
1169 if (grub_errno)
1170 goto fail;
1171 buf += length;
1172 current_position += offset + length;
1174 else
1175 current_position += block_size;
1177 found.data->disk->read_hook = 0;
1178 grub_free (indirect_block_ptr);
1179 indirect_block_ptr = 0;
1180 break;
1181 default:
1182 goto fail;
1184 current_key_offset = current_position + 1;
1187 grub_dprintf ("reiserfs",
1188 "Have successfully read %lld bytes (%ld requested)\n",
1189 (unsigned long long) (current_position - initial_position),
1190 (unsigned long) len);
1191 return current_position - initial_position;
1193 switch (found.type)
1195 case GRUB_REISERFS_DIRECT:
1196 read_length = MIN (len, item_size - file->offset);
1197 grub_disk_read (found.data->disk,
1198 (found.block_number * block_size) / GRUB_DISK_SECTOR_SIZE,
1199 grub_le_to_cpu16 (found.header.item_location) + file->offset,
1200 read_length, buf);
1201 if (grub_errno)
1202 goto fail;
1203 break;
1204 case GRUB_REISERFS_INDIRECT:
1205 indirect_block_count = item_size / sizeof (*indirect_block_ptr);
1206 indirect_block_ptr = grub_malloc (item_size);
1207 if (!indirect_block_ptr)
1208 goto fail;
1209 grub_disk_read (found.data->disk,
1210 (found.block_number * block_size) / GRUB_DISK_SECTOR_SIZE,
1211 grub_le_to_cpu16 (found.header.item_location),
1212 item_size, (char *) indirect_block_ptr);
1213 if (grub_errno)
1214 goto fail;
1215 len = MIN (len, file->size - file->offset);
1216 for (indirect_block = file->offset / block_size;
1217 indirect_block < indirect_block_count && read_length < len;
1218 indirect_block++)
1220 read = MIN (block_size, len - read_length);
1221 grub_disk_read (found.data->disk,
1222 (grub_le_to_cpu32 (indirect_block_ptr[indirect_block]) * block_size) / GRUB_DISK_SECTOR_SIZE,
1223 file->offset % block_size, read,
1224 ((void *) buf) + read_length);
1225 if (grub_errno)
1226 goto fail;
1227 read_length += read;
1229 grub_free (indirect_block_ptr);
1230 break;
1231 default:
1232 goto fail;
1235 return read_length;*/
1237 fail:
1238 grub_free (indirect_block_ptr);
1239 return 0;
1242 /* Close the file FILE. */
1243 static grub_err_t
1244 grub_reiserfs_close (grub_file_t file)
1246 struct grub_fshelp_node *node = file->data;
1247 struct grub_reiserfs_data *data = node->data;
1249 grub_free (data);
1250 grub_free (node);
1251 grub_dl_unref (my_mod);
1252 return GRUB_ERR_NONE;
1255 /* Call HOOK with each file under DIR. */
1256 static grub_err_t
1257 grub_reiserfs_dir (grub_device_t device, const char *path,
1258 int (*hook) (const char *filename,
1259 const struct grub_dirhook_info *info))
1261 struct grub_reiserfs_data *data = 0;
1262 struct grub_fshelp_node root, *found;
1263 struct grub_reiserfs_key root_key;
1265 auto int NESTED_FUNC_ATTR iterate (const char *filename,
1266 enum grub_fshelp_filetype filetype,
1267 grub_fshelp_node_t node);
1269 int NESTED_FUNC_ATTR iterate (const char *filename,
1270 enum grub_fshelp_filetype filetype,
1271 grub_fshelp_node_t node)
1273 struct grub_dirhook_info info;
1274 grub_memset (&info, 0, sizeof (info));
1275 info.dir = ((filetype & GRUB_FSHELP_TYPE_MASK) == GRUB_FSHELP_DIR);
1276 grub_free (node);
1277 return hook (filename, &info);
1279 grub_dl_ref (my_mod);
1280 data = grub_reiserfs_mount (device->disk);
1281 if (! data)
1282 goto fail;
1283 root_key.directory_id = grub_cpu_to_le32 (1);
1284 root_key.object_id = grub_cpu_to_le32 (2);
1285 root_key.u.v2.offset_type = 0;
1286 grub_reiserfs_set_key_type (&root_key, GRUB_REISERFS_DIRECTORY, 2);
1287 grub_reiserfs_set_key_offset (&root_key, 1);
1288 if (grub_reiserfs_get_item (data, &root_key, &root) != GRUB_ERR_NONE)
1289 goto fail;
1290 if (root.block_number == 0)
1292 grub_error(GRUB_ERR_BAD_FS, "Root not found");
1293 goto fail;
1295 grub_fshelp_find_file (path, &root, &found, grub_reiserfs_iterate_dir,
1296 grub_reiserfs_read_symlink, GRUB_FSHELP_DIR);
1297 if (grub_errno)
1298 goto fail;
1299 grub_reiserfs_iterate_dir (found, iterate);
1300 grub_free (data);
1301 grub_dl_unref (my_mod);
1302 return GRUB_ERR_NONE;
1304 fail:
1305 grub_free (data);
1306 grub_dl_unref (my_mod);
1307 return grub_errno;
1310 /* Return the label of the device DEVICE in LABEL. The label is
1311 returned in a grub_malloc'ed buffer and should be freed by the
1312 caller. */
1313 static grub_err_t
1314 grub_reiserfs_label (grub_device_t device, char **label)
1316 *label = grub_malloc (REISERFS_MAX_LABEL_LENGTH);
1317 if (*label)
1319 grub_disk_read (device->disk,
1320 REISERFS_SUPER_BLOCK_OFFSET / GRUB_DISK_SECTOR_SIZE,
1321 REISERFS_LABEL_OFFSET, REISERFS_MAX_LABEL_LENGTH,
1322 *label);
1324 return grub_errno;
1327 static grub_err_t
1328 grub_reiserfs_uuid (grub_device_t device, char **uuid)
1330 struct grub_reiserfs_data *data;
1331 grub_disk_t disk = device->disk;
1333 grub_dl_ref (my_mod);
1335 data = grub_reiserfs_mount (disk);
1336 if (data)
1338 *uuid = grub_malloc (sizeof ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"));
1339 grub_sprintf (*uuid, "%04x%04x-%04x-%04x-%04x-%04x%04x%04x",
1340 grub_be_to_cpu16 (data->superblock.uuid[0]), grub_be_to_cpu16 (data->superblock.uuid[1]),
1341 grub_be_to_cpu16 (data->superblock.uuid[2]), grub_be_to_cpu16 (data->superblock.uuid[3]),
1342 grub_be_to_cpu16 (data->superblock.uuid[4]), grub_be_to_cpu16 (data->superblock.uuid[5]),
1343 grub_be_to_cpu16 (data->superblock.uuid[6]), grub_be_to_cpu16 (data->superblock.uuid[7]));
1345 else
1346 *uuid = NULL;
1348 grub_dl_unref (my_mod);
1350 grub_free (data);
1352 return grub_errno;
1355 static struct grub_fs grub_reiserfs_fs =
1357 .name = "reiserfs",
1358 .dir = grub_reiserfs_dir,
1359 .open = grub_reiserfs_open,
1360 .read = grub_reiserfs_read,
1361 .close = grub_reiserfs_close,
1362 .label = grub_reiserfs_label,
1363 .uuid = grub_reiserfs_uuid,
1364 .next = 0
1367 GRUB_MOD_INIT(reiserfs)
1369 grub_fs_register (&grub_reiserfs_fs);
1370 my_mod = mod;
1373 GRUB_MOD_FINI(reiserfs)
1375 grub_fs_unregister (&grub_reiserfs_fs);