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/>.
21 #include <grub/file.h>
23 #include <grub/misc.h>
24 #include <grub/disk.h>
26 #include <grub/types.h>
27 #include <grub/charset.h>
28 #include <grub/i18n.h>
30 GRUB_MOD_LICENSE ("GPLv3+");
32 #define GRUB_JFS_MAX_SYMLNK_CNT 8
33 #define GRUB_JFS_FILETYPE_MASK 0170000
34 #define GRUB_JFS_FILETYPE_REG 0100000
35 #define GRUB_JFS_FILETYPE_LNK 0120000
36 #define GRUB_JFS_FILETYPE_DIR 0040000
38 #define GRUB_JFS_SBLOCK 64
39 #define GRUB_JFS_AGGR_INODE 2
40 #define GRUB_JFS_FS1_INODE_BLK 104
42 #define GRUB_JFS_TREE_LEAF 2
44 struct grub_jfs_sblock
46 /* The magic for JFS. It should contain the string "JFS1". */
47 grub_uint8_t magic
[4];
48 grub_uint32_t version
;
49 grub_uint64_t ag_size
;
51 /* The size of a filesystem block in bytes. XXX: currently only
54 grub_uint16_t log2_blksz
;
55 grub_uint8_t unused
[14];
57 grub_uint8_t unused3
[61];
59 grub_uint8_t unused2
[24];
60 grub_uint8_t uuid
[16];
64 struct grub_jfs_extent
66 /* The length of the extent in filesystem blocks. */
70 /* The physical offset of the first block on the disk. */
75 #define GRUB_JFS_IAG_INODES_OFFSET 3072
76 #define GRUB_JFS_IAG_INODES_COUNT 128
80 grub_uint8_t unused
[GRUB_JFS_IAG_INODES_OFFSET
];
81 struct grub_jfs_extent inodes
[GRUB_JFS_IAG_INODES_COUNT
];
85 /* The head of the tree used to find extents. */
86 struct grub_jfs_treehead
96 grub_uint8_t unused2
[10];
99 /* A node in the extent tree. */
100 struct grub_jfs_tree_extent
103 grub_uint16_t unused
;
105 /* The offset is the key used to lookup an extent. */
106 grub_uint8_t offset1
;
107 grub_uint32_t offset2
;
109 struct grub_jfs_extent extent
;
112 /* The tree of directory entries. */
113 struct grub_jfs_tree_dir
115 /* Pointers to the previous and next tree headers of other nodes on
122 /* The amount of dirents in this node. */
124 grub_uint8_t freecnt
;
125 grub_uint8_t freelist
;
126 grub_uint8_t maxslot
;
128 /* The location of the sorted array of pointers to dirents. */
130 grub_uint8_t unused
[10];
133 /* An internal node in the dirents tree. */
134 struct grub_jfs_internal_dirent
136 struct grub_jfs_extent ex
;
139 grub_uint16_t namepart
[11];
142 /* A leaf node in the dirents tree. */
143 struct grub_jfs_leaf_dirent
145 /* The inode for this dirent. */
149 /* The size of the name. */
151 grub_uint16_t namepart
[11];
155 /* A leaf in the dirents tree. This one is used if the previously
156 dirent was not big enough to store the name. */
157 struct grub_jfs_leaf_next_dirent
161 grub_uint16_t namepart
[15];
167 grub_int32_t nanosec
;
170 struct grub_jfs_inode
173 grub_uint32_t fileset
;
175 grub_uint8_t unused
[12];
177 grub_uint8_t unused2
[20];
179 struct grub_jfs_time atime
;
180 struct grub_jfs_time ctime
;
181 struct grub_jfs_time mtime
;
182 grub_uint8_t unused3
[48];
183 grub_uint8_t unused4
[96];
187 /* The tree describing the extents of the file. */
190 struct grub_jfs_treehead tree
;
191 struct grub_jfs_tree_extent extents
[16];
195 /* The tree describing the dirents. */
198 grub_uint8_t unused
[16];
201 /* Amount of dirents in this node. */
203 grub_uint8_t freecnt
;
204 grub_uint8_t freelist
;
205 grub_uint32_t idotdot
;
206 grub_uint8_t sorted
[8];
208 struct grub_jfs_leaf_dirent dirents
[8];
213 grub_uint8_t unused
[32];
214 grub_uint8_t path
[256];
221 struct grub_jfs_sblock sblock
;
223 struct grub_jfs_inode fileset
;
224 struct grub_jfs_inode currinode
;
228 int namecomponentlen
;
231 struct grub_jfs_diropen
236 struct grub_jfs_tree_dir header
;
237 struct grub_jfs_leaf_dirent dirent
[0];
238 struct grub_jfs_leaf_next_dirent next_dirent
[0];
239 grub_uint8_t sorted
[0];
240 } GRUB_PACKED
*dirpage
;
241 struct grub_jfs_data
*data
;
242 struct grub_jfs_inode
*inode
;
244 grub_uint8_t
*sorted
;
245 struct grub_jfs_leaf_dirent
*leaf
;
246 struct grub_jfs_leaf_next_dirent
*next_leaf
;
248 /* The filename and inode of the last read dirent. */
249 /* On-disk name is at most 255 UTF-16 codepoints.
250 Every UTF-16 codepoint is at most 4 UTF-8 bytes.
252 char name
[256 * GRUB_MAX_UTF8_PER_UTF16
+ 1];
257 static grub_dl_t my_mod
;
259 static grub_err_t
grub_jfs_lookup_symlink (struct grub_jfs_data
*data
, grub_uint32_t ino
);
262 getblk (struct grub_jfs_treehead
*treehead
,
263 struct grub_jfs_tree_extent
*extents
,
264 struct grub_jfs_data
*data
,
270 for (i
= 0; i
< grub_le_to_cpu16 (treehead
->count
) - 2; i
++)
272 if (treehead
->flags
& GRUB_JFS_TREE_LEAF
)
274 /* Read the leafnode. */
275 if (grub_le_to_cpu32 (extents
[i
].offset2
) <= blk
276 && ((grub_le_to_cpu16 (extents
[i
].extent
.length
))
277 + (extents
[i
].extent
.length2
<< 16)
278 + grub_le_to_cpu32 (extents
[i
].offset2
)) > blk
)
279 return (blk
- grub_le_to_cpu32 (extents
[i
].offset2
)
280 + grub_le_to_cpu32 (extents
[i
].extent
.blk2
));
283 if (blk
>= grub_le_to_cpu32 (extents
[i
].offset2
))
289 grub_int64_t ret
= -1;
292 struct grub_jfs_treehead treehead
;
293 struct grub_jfs_tree_extent extents
[254];
296 tree
= grub_zalloc (sizeof (*tree
));
300 if (!grub_disk_read (data
->disk
,
301 ((grub_disk_addr_t
) grub_le_to_cpu32 (extents
[found
].extent
.blk2
))
302 << (grub_le_to_cpu16 (data
->sblock
.log2_blksz
)
303 - GRUB_DISK_SECTOR_BITS
), 0,
304 sizeof (*tree
), (char *) tree
))
305 ret
= getblk (&tree
->treehead
, &tree
->extents
[0], data
, blk
);
313 /* Get the block number for the block BLK in the node INODE in the
314 mounted filesystem DATA. */
316 grub_jfs_blkno (struct grub_jfs_data
*data
, struct grub_jfs_inode
*inode
,
319 return getblk (&inode
->file
.tree
, &inode
->file
.extents
[0], data
, blk
);
324 grub_jfs_read_inode (struct grub_jfs_data
*data
, grub_uint32_t ino
,
325 struct grub_jfs_inode
*inode
)
327 struct grub_jfs_extent iag_inodes
[GRUB_JFS_IAG_INODES_COUNT
];
328 grub_uint32_t iagnum
= ino
/ 4096;
329 unsigned inoext
= (ino
% 4096) / 32;
330 unsigned inonum
= (ino
% 4096) % 32;
331 grub_uint64_t iagblk
;
332 grub_uint64_t inoblk
;
334 iagblk
= grub_jfs_blkno (data
, &data
->fileset
, iagnum
+ 1);
338 /* Read in the IAG. */
339 if (grub_disk_read (data
->disk
,
340 iagblk
<< (grub_le_to_cpu16 (data
->sblock
.log2_blksz
)
341 - GRUB_DISK_SECTOR_BITS
),
342 GRUB_JFS_IAG_INODES_OFFSET
,
343 sizeof (iag_inodes
), &iag_inodes
))
346 inoblk
= grub_le_to_cpu32 (iag_inodes
[inoext
].blk2
);
347 inoblk
<<= (grub_le_to_cpu16 (data
->sblock
.log2_blksz
)
348 - GRUB_DISK_SECTOR_BITS
);
351 if (grub_disk_read (data
->disk
, inoblk
, 0,
352 sizeof (struct grub_jfs_inode
), inode
))
359 static struct grub_jfs_data
*
360 grub_jfs_mount (grub_disk_t disk
)
362 struct grub_jfs_data
*data
= 0;
364 data
= grub_malloc (sizeof (struct grub_jfs_data
));
368 /* Read the superblock. */
369 if (grub_disk_read (disk
, GRUB_JFS_SBLOCK
, 0,
370 sizeof (struct grub_jfs_sblock
), &data
->sblock
))
373 if (grub_strncmp ((char *) (data
->sblock
.magic
), "JFS1", 4))
375 grub_error (GRUB_ERR_BAD_FS
, "not a JFS filesystem");
379 if (data
->sblock
.blksz
== 0
380 || grub_le_to_cpu32 (data
->sblock
.blksz
)
381 != (1U << grub_le_to_cpu16 (data
->sblock
.log2_blksz
))
382 || grub_le_to_cpu16 (data
->sblock
.log2_blksz
) < GRUB_DISK_SECTOR_BITS
)
384 grub_error (GRUB_ERR_BAD_FS
, "not a JFS filesystem");
392 /* Read the inode of the first fileset. */
393 if (grub_disk_read (data
->disk
, GRUB_JFS_FS1_INODE_BLK
, 0,
394 sizeof (struct grub_jfs_inode
), &data
->fileset
))
397 if (data
->sblock
.flags
& grub_cpu_to_le32_compile_time (0x00200000))
398 data
->namecomponentlen
= 11;
400 data
->namecomponentlen
= 13;
402 if (data
->sblock
.flags
& grub_cpu_to_le32_compile_time (0x40000000))
412 if (grub_errno
== GRUB_ERR_OUT_OF_RANGE
)
413 grub_error (GRUB_ERR_BAD_FS
, "not a JFS filesystem");
419 static struct grub_jfs_diropen
*
420 grub_jfs_opendir (struct grub_jfs_data
*data
, struct grub_jfs_inode
*inode
)
422 struct grub_jfs_internal_dirent
*de
;
423 struct grub_jfs_diropen
*diro
;
424 grub_disk_addr_t blk
;
426 de
= (struct grub_jfs_internal_dirent
*) inode
->dir
.dirents
;
428 if (!((grub_le_to_cpu32 (inode
->mode
)
429 & GRUB_JFS_FILETYPE_MASK
) == GRUB_JFS_FILETYPE_DIR
))
431 grub_error (GRUB_ERR_BAD_FILE_TYPE
, N_("not a directory"));
435 diro
= grub_zalloc (sizeof (struct grub_jfs_diropen
));
442 /* Check if the entire tree is contained within the inode. */
443 if (inode
->file
.tree
.flags
& GRUB_JFS_TREE_LEAF
)
445 diro
->leaf
= inode
->dir
.dirents
;
446 diro
->next_leaf
= (struct grub_jfs_leaf_next_dirent
*) de
;
447 diro
->sorted
= inode
->dir
.header
.sorted
;
448 diro
->count
= inode
->dir
.header
.count
;
453 diro
->dirpage
= grub_malloc (grub_le_to_cpu32 (data
->sblock
.blksz
));
460 blk
= grub_le_to_cpu32 (de
[inode
->dir
.header
.sorted
[0]].ex
.blk2
);
461 blk
<<= (grub_le_to_cpu16 (data
->sblock
.log2_blksz
) - GRUB_DISK_SECTOR_BITS
);
463 /* Read in the nodes until we are on the leaf node level. */
467 if (grub_disk_read (data
->disk
, blk
, 0,
468 grub_le_to_cpu32 (data
->sblock
.blksz
),
469 diro
->dirpage
->sorted
))
471 grub_free (diro
->dirpage
);
476 de
= (struct grub_jfs_internal_dirent
*) diro
->dirpage
->dirent
;
477 index
= diro
->dirpage
->sorted
[diro
->dirpage
->header
.sindex
* 32];
478 blk
= (grub_le_to_cpu32 (de
[index
].ex
.blk2
)
479 << (grub_le_to_cpu16 (data
->sblock
.log2_blksz
)
480 - GRUB_DISK_SECTOR_BITS
));
481 } while (!(diro
->dirpage
->header
.flags
& GRUB_JFS_TREE_LEAF
));
483 diro
->leaf
= diro
->dirpage
->dirent
;
484 diro
->next_leaf
= diro
->dirpage
->next_dirent
;
485 diro
->sorted
= &diro
->dirpage
->sorted
[diro
->dirpage
->header
.sindex
* 32];
486 diro
->count
= diro
->dirpage
->header
.count
;
493 grub_jfs_closedir (struct grub_jfs_diropen
*diro
)
497 grub_free (diro
->dirpage
);
502 le_to_cpu16_copy (grub_uint16_t
*out
, grub_uint16_t
*in
, grub_size_t len
)
505 *out
++ = grub_le_to_cpu16 (*in
++);
509 /* Read in the next dirent from the directory described by DIRO. */
511 grub_jfs_getent (struct grub_jfs_diropen
*diro
)
514 struct grub_jfs_leaf_dirent
*leaf
;
515 struct grub_jfs_leaf_next_dirent
*next_leaf
;
518 grub_uint16_t filename
[256];
520 /* The last node, read in more. */
521 if (diro
->index
== diro
->count
)
523 grub_disk_addr_t next
;
525 /* If the inode contains the entry tree or if this was the last
526 node, there is nothing to read. */
527 if ((diro
->inode
->file
.tree
.flags
& GRUB_JFS_TREE_LEAF
)
528 || !grub_le_to_cpu64 (diro
->dirpage
->header
.nextb
))
529 return GRUB_ERR_OUT_OF_RANGE
;
531 next
= grub_le_to_cpu64 (diro
->dirpage
->header
.nextb
);
532 next
<<= (grub_le_to_cpu16 (diro
->data
->sblock
.log2_blksz
)
533 - GRUB_DISK_SECTOR_BITS
);
535 if (grub_disk_read (diro
->data
->disk
, next
, 0,
536 grub_le_to_cpu32 (diro
->data
->sblock
.blksz
),
537 diro
->dirpage
->sorted
))
540 diro
->leaf
= diro
->dirpage
->dirent
;
541 diro
->next_leaf
= diro
->dirpage
->next_dirent
;
542 diro
->sorted
= &diro
->dirpage
->sorted
[diro
->dirpage
->header
.sindex
* 32];
543 diro
->count
= diro
->dirpage
->header
.count
;
547 leaf
= &diro
->leaf
[diro
->sorted
[diro
->index
]];
548 next_leaf
= &diro
->next_leaf
[diro
->index
];
554 return grub_jfs_getent (diro
);
557 le_to_cpu16_copy (filename
+ strpos
, leaf
->namepart
, len
< diro
->data
->namecomponentlen
? len
558 : diro
->data
->namecomponentlen
);
559 strpos
+= len
< diro
->data
->namecomponentlen
? len
560 : diro
->data
->namecomponentlen
;
561 diro
->ino
= grub_le_to_cpu32 (leaf
->inode
);
562 len
-= diro
->data
->namecomponentlen
;
564 /* Move down to the leaf level. */
565 nextent
= leaf
->next
;
566 if (leaf
->next
!= 255)
569 next_leaf
= &diro
->next_leaf
[nextent
];
570 le_to_cpu16_copy (filename
+ strpos
, next_leaf
->namepart
, len
< 15 ? len
: 15);
571 strpos
+= len
< 15 ? len
: 15;
574 nextent
= next_leaf
->next
;
575 } while (next_leaf
->next
!= 255 && len
> 0);
579 /* Convert the temporary UTF16 filename to UTF8. */
580 *grub_utf16_to_utf8 ((grub_uint8_t
*) (diro
->name
), filename
, strpos
) = '\0';
586 /* Read LEN bytes from the file described by DATA starting with byte
587 POS. Return the amount of read bytes in READ. */
589 grub_jfs_read_file (struct grub_jfs_data
*data
,
590 grub_disk_read_hook_t read_hook
, void *read_hook_data
,
591 grub_off_t pos
, grub_size_t len
, char *buf
)
596 blockcnt
= (len
+ pos
+ grub_le_to_cpu32 (data
->sblock
.blksz
) - 1)
597 >> grub_le_to_cpu16 (data
->sblock
.log2_blksz
);
599 for (i
= pos
>> grub_le_to_cpu16 (data
->sblock
.log2_blksz
); i
< blockcnt
; i
++)
601 grub_disk_addr_t blknr
;
602 grub_uint32_t blockoff
= pos
& (grub_le_to_cpu32 (data
->sblock
.blksz
) - 1);
603 grub_uint32_t blockend
= grub_le_to_cpu32 (data
->sblock
.blksz
);
605 grub_uint64_t skipfirst
= 0;
607 blknr
= grub_jfs_blkno (data
, &data
->currinode
, i
);
612 if (i
== blockcnt
- 1)
614 blockend
= (len
+ pos
) & (grub_le_to_cpu32 (data
->sblock
.blksz
) - 1);
617 blockend
= grub_le_to_cpu32 (data
->sblock
.blksz
);
621 if (i
== (pos
>> grub_le_to_cpu16 (data
->sblock
.log2_blksz
)))
623 skipfirst
= blockoff
;
624 blockend
-= skipfirst
;
627 data
->disk
->read_hook
= read_hook
;
628 data
->disk
->read_hook_data
= read_hook_data
;
629 grub_disk_read (data
->disk
,
630 blknr
<< (grub_le_to_cpu16 (data
->sblock
.log2_blksz
)
631 - GRUB_DISK_SECTOR_BITS
),
632 skipfirst
, blockend
, buf
);
634 data
->disk
->read_hook
= 0;
638 buf
+= grub_le_to_cpu32 (data
->sblock
.blksz
) - skipfirst
;
645 /* Find the file with the pathname PATH on the filesystem described by
648 grub_jfs_find_file (struct grub_jfs_data
*data
, const char *path
,
649 grub_uint32_t start_ino
)
652 const char *next
= path
;
653 struct grub_jfs_diropen
*diro
= NULL
;
655 if (grub_jfs_read_inode (data
, start_ino
, &data
->currinode
))
664 return GRUB_ERR_NONE
;
665 for (next
= name
; *next
&& *next
!= '/'; next
++);
667 if (name
[0] == '.' && name
+ 1 == next
)
670 if (name
[0] == '.' && name
[1] == '.' && name
+ 2 == next
)
672 grub_uint32_t ino
= grub_le_to_cpu32 (data
->currinode
.dir
.header
.idotdot
);
674 if (grub_jfs_read_inode (data
, ino
, &data
->currinode
))
680 diro
= grub_jfs_opendir (data
, &data
->currinode
);
686 if (grub_jfs_getent (diro
) == GRUB_ERR_OUT_OF_RANGE
)
688 grub_jfs_closedir (diro
);
689 return grub_error (GRUB_ERR_FILE_NOT_FOUND
, N_("file `%s' not found"), path
);
692 /* Check if the current direntry matches the current part of the
694 if ((data
->caseins
? grub_strncasecmp (name
, diro
->name
, next
- name
) == 0
695 : grub_strncmp (name
, diro
->name
, next
- name
) == 0) && !diro
->name
[next
- name
])
697 grub_uint32_t ino
= diro
->ino
;
698 grub_uint32_t dirino
= grub_le_to_cpu32 (data
->currinode
.inode
);
700 grub_jfs_closedir (diro
);
703 if (grub_jfs_read_inode (data
, ino
, &data
->currinode
))
706 /* Check if this is a symlink. */
707 if ((grub_le_to_cpu32 (data
->currinode
.mode
)
708 & GRUB_JFS_FILETYPE_MASK
) == GRUB_JFS_FILETYPE_LNK
)
710 grub_jfs_lookup_symlink (data
, dirino
);
723 grub_jfs_lookup_symlink (struct grub_jfs_data
*data
, grub_uint32_t ino
)
725 grub_size_t size
= grub_le_to_cpu64 (data
->currinode
.size
);
728 if (++data
->linknest
> GRUB_JFS_MAX_SYMLNK_CNT
)
729 return grub_error (GRUB_ERR_SYMLINK_LOOP
, N_("too deep nesting of symlinks"));
731 symlink
= grub_malloc (size
+ 1);
734 if (size
<= sizeof (data
->currinode
.symlink
.path
))
735 grub_memcpy (symlink
, (char *) (data
->currinode
.symlink
.path
), size
);
736 else if (grub_jfs_read_file (data
, 0, 0, 0, size
, symlink
) < 0)
742 symlink
[size
] = '\0';
744 /* The symlink is an absolute path, go back to the root inode. */
745 if (symlink
[0] == '/')
748 grub_jfs_find_file (data
, symlink
, ino
);
757 grub_jfs_dir (grub_device_t device
, const char *path
,
758 grub_fs_dir_hook_t hook
, void *hook_data
)
760 struct grub_jfs_data
*data
= 0;
761 struct grub_jfs_diropen
*diro
= 0;
763 grub_dl_ref (my_mod
);
765 data
= grub_jfs_mount (device
->disk
);
769 if (grub_jfs_find_file (data
, path
, GRUB_JFS_AGGR_INODE
))
772 diro
= grub_jfs_opendir (data
, &data
->currinode
);
776 /* Iterate over the dirents in the directory that was found. */
777 while (grub_jfs_getent (diro
) != GRUB_ERR_OUT_OF_RANGE
)
779 struct grub_jfs_inode inode
;
780 struct grub_dirhook_info info
;
781 grub_memset (&info
, 0, sizeof (info
));
783 if (grub_jfs_read_inode (data
, diro
->ino
, &inode
))
786 info
.dir
= (grub_le_to_cpu32 (inode
.mode
)
787 & GRUB_JFS_FILETYPE_MASK
) == GRUB_JFS_FILETYPE_DIR
;
789 info
.mtime
= grub_le_to_cpu32 (inode
.mtime
.sec
);
790 if (hook (diro
->name
, &info
, hook_data
))
794 /* XXX: GRUB_ERR_OUT_OF_RANGE is used for the last dirent. */
795 if (grub_errno
== GRUB_ERR_OUT_OF_RANGE
)
799 grub_jfs_closedir (diro
);
802 grub_dl_unref (my_mod
);
808 /* Open a file named NAME and initialize FILE. */
810 grub_jfs_open (struct grub_file
*file
, const char *name
)
812 struct grub_jfs_data
*data
;
814 grub_dl_ref (my_mod
);
816 data
= grub_jfs_mount (file
->device
->disk
);
820 grub_jfs_find_file (data
, name
, GRUB_JFS_AGGR_INODE
);
824 /* It is only possible for open regular files. */
825 if (! ((grub_le_to_cpu32 (data
->currinode
.mode
)
826 & GRUB_JFS_FILETYPE_MASK
) == GRUB_JFS_FILETYPE_REG
))
828 grub_error (GRUB_ERR_BAD_FILE_TYPE
, N_("not a regular file"));
833 file
->size
= grub_le_to_cpu64 (data
->currinode
.size
);
839 grub_dl_unref (my_mod
);
848 grub_jfs_read (grub_file_t file
, char *buf
, grub_size_t len
)
850 struct grub_jfs_data
*data
=
851 (struct grub_jfs_data
*) file
->data
;
853 return grub_jfs_read_file (data
, file
->read_hook
, file
->read_hook_data
,
854 file
->offset
, len
, buf
);
859 grub_jfs_close (grub_file_t file
)
861 grub_free (file
->data
);
863 grub_dl_unref (my_mod
);
865 return GRUB_ERR_NONE
;
869 grub_jfs_uuid (grub_device_t device
, char **uuid
)
871 struct grub_jfs_data
*data
;
872 grub_disk_t disk
= device
->disk
;
874 grub_dl_ref (my_mod
);
876 data
= grub_jfs_mount (disk
);
879 *uuid
= grub_xasprintf ("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-"
880 "%02x%02x%02x%02x%02x%02x",
881 data
->sblock
.uuid
[0], data
->sblock
.uuid
[1],
882 data
->sblock
.uuid
[2], data
->sblock
.uuid
[3],
883 data
->sblock
.uuid
[4], data
->sblock
.uuid
[5],
884 data
->sblock
.uuid
[6], data
->sblock
.uuid
[7],
885 data
->sblock
.uuid
[8], data
->sblock
.uuid
[9],
886 data
->sblock
.uuid
[10], data
->sblock
.uuid
[11],
887 data
->sblock
.uuid
[12], data
->sblock
.uuid
[13],
888 data
->sblock
.uuid
[14], data
->sblock
.uuid
[15]);
893 grub_dl_unref (my_mod
);
901 grub_jfs_label (grub_device_t device
, char **label
)
903 struct grub_jfs_data
*data
;
904 data
= grub_jfs_mount (device
->disk
);
908 if (data
->sblock
.volname2
[0] < ' ')
911 ptr
= data
->sblock
.volname
+ sizeof (data
->sblock
.volname
) - 1;
912 while (ptr
>= data
->sblock
.volname
&& *ptr
== ' ')
914 *label
= grub_strndup (data
->sblock
.volname
,
915 ptr
- data
->sblock
.volname
+ 1);
918 *label
= grub_strndup (data
->sblock
.volname2
,
919 sizeof (data
->sblock
.volname2
));
930 static struct grub_fs grub_jfs_fs
=
934 .open
= grub_jfs_open
,
935 .read
= grub_jfs_read
,
936 .close
= grub_jfs_close
,
937 .label
= grub_jfs_label
,
938 .uuid
= grub_jfs_uuid
,
940 .reserved_first_sector
= 1,
941 .blocklist_install
= 1,
948 grub_fs_register (&grub_jfs_fs
);
954 grub_fs_unregister (&grub_jfs_fs
);