GRUB-1.98 changes
[grub2/jjazz.git] / fs / jfs.c
blobc9839a22f9ba2a5b38b2e28677424da2df8c94a4
1 /* jfs.c - JFS. */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2004,2005,2006,2007,2008,2009 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/>.
20 #include <grub/err.h>
21 #include <grub/file.h>
22 #include <grub/mm.h>
23 #include <grub/misc.h>
24 #include <grub/disk.h>
25 #include <grub/dl.h>
26 #include <grub/types.h>
27 #include <grub/charset.h>
29 #define GRUB_JFS_MAX_SYMLNK_CNT 8
30 #define GRUB_JFS_FILETYPE_MASK 0170000
31 #define GRUB_JFS_FILETYPE_REG 0100000
32 #define GRUB_JFS_FILETYPE_LNK 0120000
33 #define GRUB_JFS_FILETYPE_DIR 0040000
35 #define GRUB_JFS_SBLOCK 64
36 #define GRUB_JFS_AGGR_INODE 2
37 #define GRUB_JFS_FS1_INODE_BLK 104
39 #define GRUB_JFS_TREE_LEAF 2
41 struct grub_jfs_sblock
43 /* The magic for JFS. It should contain the string "JFS1". */
44 grub_uint8_t magic[4];
45 grub_uint32_t version;
46 grub_uint64_t ag_size;
48 /* The size of a filesystem block in bytes. XXX: currently only
49 4096 was tested. */
50 grub_uint32_t blksz;
51 grub_uint16_t log2_blksz;
53 grub_uint8_t unused[71];
54 grub_uint8_t volname[11];
55 grub_uint8_t unused2[32];
56 grub_uint8_t uuid[16];
59 struct grub_jfs_extent
61 /* The length of the extent in filesystem blocks. */
62 grub_uint16_t length;
63 grub_uint8_t length2;
65 /* The physical offset of the first block on the disk. */
66 grub_uint8_t blk1;
67 grub_uint32_t blk2;
68 } __attribute__ ((packed));
70 struct grub_jfs_iag
72 grub_uint8_t unused[3072];
73 struct grub_jfs_extent inodes[128];
74 } __attribute__ ((packed));
77 /* The head of the tree used to find extents. */
78 struct grub_jfs_treehead
80 grub_uint64_t next;
81 grub_uint64_t prev;
83 grub_uint8_t flags;
84 grub_uint8_t unused;
86 grub_uint16_t count;
87 grub_uint16_t max;
88 grub_uint8_t unused2[10];
89 } __attribute__ ((packed));
91 /* A node in the extent tree. */
92 struct grub_jfs_tree_extent
94 grub_uint8_t flags;
95 grub_uint16_t unused;
97 /* The offset is the key used to lookup an extent. */
98 grub_uint8_t offset1;
99 grub_uint32_t offset2;
101 struct grub_jfs_extent extent;
102 } __attribute__ ((packed));
104 /* The tree of directory entries. */
105 struct grub_jfs_tree_dir
107 /* Pointers to the previous and next tree headers of other nodes on
108 this level. */
109 grub_uint64_t nextb;
110 grub_uint64_t prevb;
112 grub_uint8_t flags;
114 /* The amount of dirents in this node. */
115 grub_uint8_t count;
116 grub_uint8_t freecnt;
117 grub_uint8_t freelist;
118 grub_uint8_t maxslot;
120 /* The location of the sorted array of pointers to dirents. */
121 grub_uint8_t sindex;
122 grub_uint8_t unused[10];
123 } __attribute__ ((packed));
125 /* An internal node in the dirents tree. */
126 struct grub_jfs_internal_dirent
128 struct grub_jfs_extent ex;
129 grub_uint8_t next;
130 grub_uint8_t len;
131 grub_uint16_t namepart[11];
132 } __attribute__ ((packed));
134 /* A leaf node in the dirents tree. */
135 struct grub_jfs_leaf_dirent
137 /* The inode for this dirent. */
138 grub_uint32_t inode;
139 grub_uint8_t next;
141 /* The size of the name. */
142 grub_uint8_t len;
143 grub_uint16_t namepart[11];
144 grub_uint32_t index;
145 } __attribute__ ((packed));
147 /* A leaf in the dirents tree. This one is used if the previously
148 dirent was not big enough to store the name. */
149 struct grub_jfs_leaf_next_dirent
151 grub_uint8_t next;
152 grub_uint8_t len;
153 grub_uint16_t namepart[15];
154 } __attribute__ ((packed));
156 struct grub_jfs_inode
158 grub_uint32_t stamp;
159 grub_uint32_t fileset;
160 grub_uint32_t inode;
161 grub_uint8_t unused[12];
162 grub_uint64_t size;
163 grub_uint8_t unused2[20];
164 grub_uint32_t mode;
165 grub_uint8_t unused3[72];
166 grub_uint8_t unused4[96];
168 union
170 /* The tree describing the extents of the file. */
171 struct __attribute__ ((packed))
173 struct grub_jfs_treehead tree;
174 struct grub_jfs_tree_extent extents[16];
175 } file;
176 union
178 /* The tree describing the dirents. */
179 struct
181 grub_uint8_t unused[16];
182 grub_uint8_t flags;
184 /* Amount of dirents in this node. */
185 grub_uint8_t count;
186 grub_uint8_t freecnt;
187 grub_uint8_t freelist;
188 grub_uint32_t idotdot;
189 grub_uint8_t sorted[8];
190 } header;
191 struct grub_jfs_leaf_dirent dirents[8];
192 } dir __attribute__ ((packed));
193 /* Fast symlink. */
194 struct
196 grub_uint8_t unused[32];
197 grub_uint8_t path[128];
198 } symlink;
199 } __attribute__ ((packed));
200 } __attribute__ ((packed));
202 struct grub_jfs_data
204 struct grub_jfs_sblock sblock;
205 grub_disk_t disk;
206 struct grub_jfs_inode fileset;
207 struct grub_jfs_inode currinode;
208 int pos;
209 int linknest;
210 } __attribute__ ((packed));
212 struct grub_jfs_diropen
214 int index;
215 union
217 struct grub_jfs_tree_dir header;
218 struct grub_jfs_leaf_dirent dirent[0];
219 struct grub_jfs_leaf_next_dirent next_dirent[0];
220 char sorted[0];
221 } *dirpage __attribute__ ((packed));
222 struct grub_jfs_data *data;
223 struct grub_jfs_inode *inode;
224 int count;
225 char *sorted;
226 struct grub_jfs_leaf_dirent *leaf;
227 struct grub_jfs_leaf_next_dirent *next_leaf;
229 /* The filename and inode of the last read dirent. */
230 char name[255];
231 grub_uint32_t ino;
232 } __attribute__ ((packed));
235 static grub_dl_t my_mod;
237 static grub_err_t grub_jfs_lookup_symlink (struct grub_jfs_data *data, int ino);
239 /* Get the block number for the block BLK in the node INODE in the
240 mounted filesystem DATA. */
241 static int
242 grub_jfs_blkno (struct grub_jfs_data *data, struct grub_jfs_inode *inode,
243 unsigned int blk)
245 auto int getblk (struct grub_jfs_treehead *treehead,
246 struct grub_jfs_tree_extent *extents);
248 int getblk (struct grub_jfs_treehead *treehead,
249 struct grub_jfs_tree_extent *extents)
251 int found = -1;
252 int i;
254 for (i = 0; i < grub_le_to_cpu16 (treehead->count) - 2; i++)
256 if (treehead->flags & GRUB_JFS_TREE_LEAF)
258 /* Read the leafnode. */
259 if (grub_le_to_cpu32 (extents[i].offset2) <= blk
260 && ((grub_le_to_cpu16 (extents[i].extent.length))
261 + (extents[i].extent.length2 << 8)
262 + grub_le_to_cpu32 (extents[i].offset2)) > blk)
263 return (blk - grub_le_to_cpu32 (extents[i].offset2)
264 + grub_le_to_cpu32 (extents[i].extent.blk2));
266 else
267 if (blk >= grub_le_to_cpu32 (extents[i].offset2))
268 found = i;
271 if (found != -1)
273 struct
275 struct grub_jfs_treehead treehead;
276 struct grub_jfs_tree_extent extents[254];
277 } tree;
279 if (grub_disk_read (data->disk,
280 grub_le_to_cpu32 (extents[found].extent.blk2)
281 << (grub_le_to_cpu16 (data->sblock.log2_blksz)
282 - GRUB_DISK_SECTOR_BITS), 0,
283 sizeof (tree), (char *) &tree))
284 return -1;
286 return getblk (&tree.treehead, &tree.extents[0]);
289 return -1;
292 return getblk (&inode->file.tree, &inode->file.extents[0]);
296 static grub_err_t
297 grub_jfs_read_inode (struct grub_jfs_data *data, int ino,
298 struct grub_jfs_inode *inode)
300 struct grub_jfs_iag iag;
301 int iagnum = ino / 4096;
302 int inoext = (ino % 4096) / 32;
303 int inonum = (ino % 4096) % 32;
304 grub_uint32_t iagblk;
305 grub_uint32_t inoblk;
307 iagblk = grub_jfs_blkno (data, &data->fileset, iagnum + 1);
308 if (grub_errno)
309 return grub_errno;
311 /* Read in the IAG. */
312 if (grub_disk_read (data->disk,
313 iagblk << (grub_le_to_cpu16 (data->sblock.log2_blksz)
314 - GRUB_DISK_SECTOR_BITS), 0,
315 sizeof (struct grub_jfs_iag), &iag))
316 return grub_errno;
318 inoblk = grub_le_to_cpu32 (iag.inodes[inoext].blk2);
319 inoblk <<= (grub_le_to_cpu16 (data->sblock.log2_blksz)
320 - GRUB_DISK_SECTOR_BITS);
321 inoblk += inonum;
323 if (grub_disk_read (data->disk, inoblk, 0,
324 sizeof (struct grub_jfs_inode), inode))
325 return grub_errno;
327 return 0;
331 static struct grub_jfs_data *
332 grub_jfs_mount (grub_disk_t disk)
334 struct grub_jfs_data *data = 0;
336 data = grub_malloc (sizeof (struct grub_jfs_data));
337 if (!data)
338 return 0;
340 /* Read the superblock. */
341 if (grub_disk_read (disk, GRUB_JFS_SBLOCK, 0,
342 sizeof (struct grub_jfs_sblock), &data->sblock))
343 goto fail;
345 if (grub_strncmp ((char *) (data->sblock.magic), "JFS1", 4))
347 grub_error (GRUB_ERR_BAD_FS, "not a JFS filesystem");
348 goto fail;
351 data->disk = disk;
352 data->pos = 0;
353 data->linknest = 0;
355 /* Read the inode of the first fileset. */
356 if (grub_disk_read (data->disk, GRUB_JFS_FS1_INODE_BLK, 0,
357 sizeof (struct grub_jfs_inode), &data->fileset))
358 goto fail;
360 return data;
362 fail:
363 grub_free (data);
365 if (grub_errno == GRUB_ERR_OUT_OF_RANGE)
366 grub_error (GRUB_ERR_BAD_FS, "not a JFS filesystem");
368 return 0;
372 static struct grub_jfs_diropen *
373 grub_jfs_opendir (struct grub_jfs_data *data, struct grub_jfs_inode *inode)
375 struct grub_jfs_internal_dirent *de;
376 struct grub_jfs_diropen *diro;
377 int blk;
379 de = (struct grub_jfs_internal_dirent *) inode->dir.dirents;
381 if (!((grub_le_to_cpu32 (inode->mode)
382 & GRUB_JFS_FILETYPE_MASK) == GRUB_JFS_FILETYPE_DIR))
384 grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a directory");
385 return 0;
388 diro = grub_zalloc (sizeof (struct grub_jfs_diropen));
389 if (!diro)
390 return 0;
392 diro->data = data;
393 diro->inode = inode;
395 /* Check if the entire tree is contained within the inode. */
396 if (inode->file.tree.flags & GRUB_JFS_TREE_LEAF)
398 diro->leaf = inode->dir.dirents;
399 diro->next_leaf = (struct grub_jfs_leaf_next_dirent *) de;
400 diro->sorted = (char *) (inode->dir.header.sorted);
401 diro->count = inode->dir.header.count;
403 return diro;
406 diro->dirpage = grub_malloc (grub_le_to_cpu32 (data->sblock.blksz));
407 if (!diro->dirpage)
409 grub_free (diro);
410 return 0;
413 blk = grub_le_to_cpu32 (de[inode->dir.header.sorted[0]].ex.blk2);
414 blk <<= (grub_le_to_cpu16 (data->sblock.log2_blksz) - GRUB_DISK_SECTOR_BITS);
416 /* Read in the nodes until we are on the leaf node level. */
419 int index;
420 if (grub_disk_read (data->disk, blk, 0,
421 grub_le_to_cpu32 (data->sblock.blksz),
422 diro->dirpage->sorted))
424 grub_free (diro->dirpage);
425 grub_free (diro);
426 return 0;
429 de = (struct grub_jfs_internal_dirent *) diro->dirpage->dirent;
430 index = diro->dirpage->sorted[diro->dirpage->header.sindex * 32];
431 blk = (grub_le_to_cpu32 (de[index].ex.blk2)
432 << (grub_le_to_cpu16 (data->sblock.log2_blksz)
433 - GRUB_DISK_SECTOR_BITS));
434 } while (!(diro->dirpage->header.flags & GRUB_JFS_TREE_LEAF));
436 diro->leaf = diro->dirpage->dirent;
437 diro->next_leaf = diro->dirpage->next_dirent;
438 diro->sorted = &diro->dirpage->sorted[diro->dirpage->header.sindex * 32];
439 diro->count = diro->dirpage->header.count;
441 return diro;
445 static void
446 grub_jfs_closedir (struct grub_jfs_diropen *diro)
448 if (!diro)
449 return;
450 grub_free (diro->dirpage);
451 grub_free (diro);
455 /* Read in the next dirent from the directory described by DIRO. */
456 static grub_err_t
457 grub_jfs_getent (struct grub_jfs_diropen *diro)
459 int strpos = 0;
460 struct grub_jfs_leaf_dirent *leaf;
461 struct grub_jfs_leaf_next_dirent *next_leaf;
462 int len;
463 int nextent;
464 grub_uint16_t filename[255];
466 auto void addstr (grub_uint16_t *uname, int ulen);
468 /* Add the unicode string to the utf16 filename buffer. */
469 void addstr (grub_uint16_t *name, int ulen)
471 while (ulen--)
472 filename[strpos++] = *(name++);
475 /* The last node, read in more. */
476 if (diro->index == diro->count)
478 unsigned int next;
480 /* If the inode contains the entry tree or if this was the last
481 node, there is nothing to read. */
482 if ((diro->inode->file.tree.flags & GRUB_JFS_TREE_LEAF)
483 || !grub_le_to_cpu64 (diro->dirpage->header.nextb))
484 return GRUB_ERR_OUT_OF_RANGE;
486 next = grub_le_to_cpu64 (diro->dirpage->header.nextb);
487 next <<= (grub_le_to_cpu16 (diro->data->sblock.log2_blksz)
488 - GRUB_DISK_SECTOR_BITS);
490 if (grub_disk_read (diro->data->disk, next, 0,
491 grub_le_to_cpu32 (diro->data->sblock.blksz),
492 diro->dirpage->sorted))
493 return grub_errno;
495 diro->leaf = diro->dirpage->dirent;
496 diro->next_leaf = diro->dirpage->next_dirent;
497 diro->sorted = &diro->dirpage->sorted[diro->dirpage->header.sindex * 32];
498 diro->count = diro->dirpage->header.count;
499 diro->index = 0;
502 leaf = &diro->leaf[(int) diro->sorted[diro->index]];
503 next_leaf = &diro->next_leaf[diro->index];
505 len = leaf->len;
506 if (!len)
508 diro->index++;
509 return grub_jfs_getent (diro);
512 addstr (leaf->namepart, len < 11 ? len : 11);
513 diro->ino = grub_le_to_cpu32 (leaf->inode);
514 len -= 11;
516 /* Move down to the leaf level. */
517 nextent = leaf->next;
518 if (leaf->next != 255)
521 next_leaf = &diro->next_leaf[nextent];
522 addstr (next_leaf->namepart, len < 15 ? len : 15 );
524 len -= 15;
525 nextent = next_leaf->next;
526 } while (next_leaf->next != 255 && len > 0);
528 diro->index++;
530 /* Convert the temporary UTF16 filename to UTF8. */
531 *grub_utf16_to_utf8 ((grub_uint8_t *) (diro->name), filename, strpos) = '\0';
533 return 0;
537 /* Read LEN bytes from the file described by DATA starting with byte
538 POS. Return the amount of read bytes in READ. */
539 static grub_ssize_t
540 grub_jfs_read_file (struct grub_jfs_data *data,
541 void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector,
542 unsigned offset, unsigned length),
543 int pos, grub_size_t len, char *buf)
545 int i;
546 int blockcnt;
548 blockcnt = ((len + pos + grub_le_to_cpu32 (data->sblock.blksz) - 1)
549 / grub_le_to_cpu32 (data->sblock.blksz));
551 for (i = pos / grub_le_to_cpu32 (data->sblock.blksz); i < blockcnt; i++)
553 int blknr;
554 int blockoff = pos % grub_le_to_cpu32 (data->sblock.blksz);
555 int blockend = grub_le_to_cpu32 (data->sblock.blksz);
557 int skipfirst = 0;
559 blknr = grub_jfs_blkno (data, &data->currinode, i);
560 if (grub_errno)
561 return -1;
563 /* Last block. */
564 if (i == blockcnt - 1)
566 blockend = (len + pos) % grub_le_to_cpu32 (data->sblock.blksz);
568 if (!blockend)
569 blockend = grub_le_to_cpu32 (data->sblock.blksz);
572 /* First block. */
573 if (i == (pos / (int) grub_le_to_cpu32 (data->sblock.blksz)))
575 skipfirst = blockoff;
576 blockend -= skipfirst;
579 data->disk->read_hook = read_hook;
580 grub_disk_read (data->disk,
581 blknr << (grub_le_to_cpu16 (data->sblock.log2_blksz)
582 - GRUB_DISK_SECTOR_BITS),
583 skipfirst, blockend, buf);
585 data->disk->read_hook = 0;
586 if (grub_errno)
587 return -1;
589 buf += grub_le_to_cpu32 (data->sblock.blksz) - skipfirst;
592 return len;
596 /* Find the file with the pathname PATH on the filesystem described by
597 DATA. */
598 static grub_err_t
599 grub_jfs_find_file (struct grub_jfs_data *data, const char *path)
601 char fpath[grub_strlen (path)];
602 char *name = fpath;
603 char *next;
604 unsigned int pos = 0;
605 struct grub_jfs_diropen *diro;
607 grub_strncpy (fpath, path, grub_strlen (path) + 1);
609 if (grub_jfs_read_inode (data, GRUB_JFS_AGGR_INODE, &data->currinode))
610 return grub_errno;
612 /* Skip the first slashes. */
613 while (*name == '/')
615 name++;
616 if (!*name)
617 return 0;
620 /* Extract the actual part from the pathname. */
621 next = grub_strchr (name, '/');
622 if (next)
624 while (*next == '/')
626 next[0] = '\0';
627 next++;
630 diro = grub_jfs_opendir (data, &data->currinode);
631 if (!diro)
632 return grub_errno;
634 for (;;)
636 if (grub_strlen (name) == 0)
637 return GRUB_ERR_NONE;
639 if (grub_jfs_getent (diro) == GRUB_ERR_OUT_OF_RANGE)
640 break;
642 /* Check if the current direntry matches the current part of the
643 pathname. */
644 if (!grub_strcmp (name, diro->name))
646 int ino = diro->ino;
647 int dirino = grub_le_to_cpu32 (data->currinode.inode);
649 grub_jfs_closedir (diro);
650 diro = 0;
652 if (grub_jfs_read_inode (data, ino, &data->currinode))
653 break;
655 /* Check if this is a symlink. */
656 if ((grub_le_to_cpu32 (data->currinode.mode)
657 & GRUB_JFS_FILETYPE_MASK) == GRUB_JFS_FILETYPE_LNK)
659 grub_jfs_lookup_symlink (data, dirino);
660 if (grub_errno)
661 return grub_errno;
664 if (!next)
665 return 0;
667 pos = 0;
669 name = next;
670 next = grub_strchr (name, '/');
671 if (next)
673 next[0] = '\0';
674 next++;
677 /* Open this directory for reading dirents. */
678 diro = grub_jfs_opendir (data, &data->currinode);
679 if (!diro)
680 return grub_errno;
682 continue;
686 grub_jfs_closedir (diro);
687 grub_error (GRUB_ERR_FILE_NOT_FOUND, "file not found");
688 return grub_errno;
692 static grub_err_t
693 grub_jfs_lookup_symlink (struct grub_jfs_data *data, int ino)
695 int size = grub_le_to_cpu64 (data->currinode.size);
696 char symlink[size + 1];
698 if (++data->linknest > GRUB_JFS_MAX_SYMLNK_CNT)
699 return grub_error (GRUB_ERR_SYMLINK_LOOP, "too deep nesting of symlinks");
701 if (size <= 128)
702 grub_strncpy (symlink, (char *) (data->currinode.symlink.path), 128);
703 else if (grub_jfs_read_file (data, 0, 0, size, symlink) < 0)
704 return grub_errno;
706 symlink[size] = '\0';
708 /* The symlink is an absolute path, go back to the root inode. */
709 if (symlink[0] == '/')
710 ino = 2;
712 /* Now load in the old inode. */
713 if (grub_jfs_read_inode (data, ino, &data->currinode))
714 return grub_errno;
716 grub_jfs_find_file (data, symlink);
717 if (grub_errno)
718 grub_error (grub_errno, "cannot follow symlink `%s'", symlink);
720 return grub_errno;
724 static grub_err_t
725 grub_jfs_dir (grub_device_t device, const char *path,
726 int (*hook) (const char *filename,
727 const struct grub_dirhook_info *info))
729 struct grub_jfs_data *data = 0;
730 struct grub_jfs_diropen *diro = 0;
732 grub_dl_ref (my_mod);
734 data = grub_jfs_mount (device->disk);
735 if (!data)
736 goto fail;
738 if (grub_jfs_find_file (data, path))
739 goto fail;
741 diro = grub_jfs_opendir (data, &data->currinode);
742 if (!diro)
743 goto fail;
745 /* Iterate over the dirents in the directory that was found. */
746 while (grub_jfs_getent (diro) != GRUB_ERR_OUT_OF_RANGE)
748 struct grub_jfs_inode inode;
749 struct grub_dirhook_info info;
750 grub_memset (&info, 0, sizeof (info));
752 if (grub_jfs_read_inode (data, diro->ino, &inode))
753 goto fail;
755 info.dir = (grub_le_to_cpu32 (inode.mode)
756 & GRUB_JFS_FILETYPE_MASK) == GRUB_JFS_FILETYPE_DIR;
757 if (hook (diro->name, &info))
758 goto fail;
761 /* XXX: GRUB_ERR_OUT_OF_RANGE is used for the last dirent. */
762 if (grub_errno == GRUB_ERR_OUT_OF_RANGE)
763 grub_errno = 0;
765 fail:
766 grub_jfs_closedir (diro);
767 grub_free (data);
769 grub_dl_unref (my_mod);
771 return grub_errno;
775 /* Open a file named NAME and initialize FILE. */
776 static grub_err_t
777 grub_jfs_open (struct grub_file *file, const char *name)
779 struct grub_jfs_data *data;
781 grub_dl_ref (my_mod);
783 data = grub_jfs_mount (file->device->disk);
784 if (!data)
785 goto fail;
787 grub_jfs_find_file (data, name);
788 if (grub_errno)
789 goto fail;
791 /* It is only possible for open regular files. */
792 if (! ((grub_le_to_cpu32 (data->currinode.mode)
793 & GRUB_JFS_FILETYPE_MASK) == GRUB_JFS_FILETYPE_REG))
795 grub_error (GRUB_ERR_BAD_FILE_TYPE, "not a regular file");
796 goto fail;
799 file->data = data;
800 file->size = grub_le_to_cpu64 (data->currinode.size);
802 return 0;
804 fail:
806 grub_dl_unref (my_mod);
808 grub_free (data);
810 return grub_errno;
814 static grub_ssize_t
815 grub_jfs_read (grub_file_t file, char *buf, grub_size_t len)
817 struct grub_jfs_data *data =
818 (struct grub_jfs_data *) file->data;
820 return grub_jfs_read_file (data, file->read_hook, file->offset, len, buf);
824 static grub_err_t
825 grub_jfs_close (grub_file_t file)
827 grub_free (file->data);
829 grub_dl_unref (my_mod);
831 return GRUB_ERR_NONE;
834 static grub_err_t
835 grub_jfs_uuid (grub_device_t device, char **uuid)
837 struct grub_jfs_data *data;
838 grub_disk_t disk = device->disk;
840 grub_dl_ref (my_mod);
842 data = grub_jfs_mount (disk);
843 if (data)
845 *uuid = grub_xasprintf ("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
846 "%02x%02x%02x%02x%02x%02x",
847 data->sblock.uuid[0], data->sblock.uuid[1],
848 data->sblock.uuid[2], data->sblock.uuid[3],
849 data->sblock.uuid[4], data->sblock.uuid[5],
850 data->sblock.uuid[6], data->sblock.uuid[7],
851 data->sblock.uuid[8], data->sblock.uuid[9],
852 data->sblock.uuid[10], data->sblock.uuid[11],
853 data->sblock.uuid[12], data->sblock.uuid[13],
854 data->sblock.uuid[14], data->sblock.uuid[15]);
856 else
857 *uuid = NULL;
859 grub_dl_unref (my_mod);
861 grub_free (data);
863 return grub_errno;
866 static grub_err_t
867 grub_jfs_label (grub_device_t device, char **label)
869 struct grub_jfs_data *data;
870 data = grub_jfs_mount (device->disk);
872 if (data)
873 *label = grub_strndup ((char *) (data->sblock.volname), 11);
874 else
875 *label = 0;
877 return grub_errno;
881 static struct grub_fs grub_jfs_fs =
883 .name = "jfs",
884 .dir = grub_jfs_dir,
885 .open = grub_jfs_open,
886 .read = grub_jfs_read,
887 .close = grub_jfs_close,
888 .label = grub_jfs_label,
889 .uuid = grub_jfs_uuid,
890 .next = 0
893 GRUB_MOD_INIT(jfs)
895 grub_fs_register (&grub_jfs_fs);
896 my_mod = mod;
899 GRUB_MOD_FINI(jfs)
901 grub_fs_unregister (&grub_jfs_fs);