3 |
* PUPA -- Preliminary Universal Programming Architecture for GRUB |
* PUPA -- Preliminary Universal Programming Architecture for GRUB |
4 |
* Copyright (C) 2000,2001 Free Software Foundation, Inc. |
* Copyright (C) 2000,2001 Free Software Foundation, Inc. |
5 |
* Copyright (C) 2002 Yoshinori K. Okuji <okuji@enbug.org> |
* Copyright (C) 2002 Yoshinori K. Okuji <okuji@enbug.org> |
6 |
|
* Copyright (C) 2003 Marco Gerards <metgerards@student.han.nl>. |
7 |
* |
* |
8 |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
772 |
return pupa_errno; |
return pupa_errno; |
773 |
} |
} |
774 |
|
|
775 |
|
static pupa_err_t |
776 |
|
pupa_fat_label (pupa_device_t device, char **label) |
777 |
|
{ |
778 |
|
struct pupa_fat_data *data; |
779 |
|
pupa_disk_t disk = device->disk; |
780 |
|
pupa_ssize_t offset = -sizeof(struct pupa_fat_dir_entry); |
781 |
|
|
782 |
|
|
783 |
|
#ifndef PUPA_UTIL |
784 |
|
pupa_dl_ref (my_mod); |
785 |
|
#endif |
786 |
|
|
787 |
|
data = pupa_fat_mount (disk); |
788 |
|
if (! data) |
789 |
|
goto fail; |
790 |
|
|
791 |
|
if (! (data->attr & PUPA_FAT_ATTR_DIRECTORY)) |
792 |
|
{ |
793 |
|
pupa_error (PUPA_ERR_BAD_FILE_TYPE, "not a directory"); |
794 |
|
return 0; |
795 |
|
} |
796 |
|
|
797 |
|
while (1) |
798 |
|
{ |
799 |
|
struct pupa_fat_dir_entry dir; |
800 |
|
|
801 |
|
/* Adjust the offset. */ |
802 |
|
offset += sizeof (dir); |
803 |
|
|
804 |
|
/* Read a directory entry. */ |
805 |
|
if ((pupa_fat_read_data (disk, data, 0, |
806 |
|
offset, sizeof (dir), (char *) &dir) |
807 |
|
!= sizeof (dir)) |
808 |
|
|| dir.name[0] == 0) |
809 |
|
{ |
810 |
|
if (pupa_errno != PUPA_ERR_NONE) |
811 |
|
goto fail; |
812 |
|
else |
813 |
|
{ |
814 |
|
*label = 0; |
815 |
|
return PUPA_ERR_NONE; |
816 |
|
} |
817 |
|
} |
818 |
|
|
819 |
|
if (dir.attr == PUPA_FAT_ATTR_VOLUME_ID) |
820 |
|
{ |
821 |
|
*label = pupa_strndup (dir.name, 11); |
822 |
|
return PUPA_ERR_NONE; |
823 |
|
} |
824 |
|
} |
825 |
|
|
826 |
|
*label = 0; |
827 |
|
|
828 |
|
fail: |
829 |
|
|
830 |
|
#ifndef PUPA_UTIL |
831 |
|
pupa_dl_unref (my_mod); |
832 |
|
#endif |
833 |
|
|
834 |
|
pupa_free (data); |
835 |
|
|
836 |
|
return pupa_errno; |
837 |
|
} |
838 |
|
|
839 |
static struct pupa_fs pupa_fat_fs = |
static struct pupa_fs pupa_fat_fs = |
840 |
{ |
{ |
841 |
.name = "fat", |
.name = "fat", |
843 |
.open = pupa_fat_open, |
.open = pupa_fat_open, |
844 |
.read = pupa_fat_read, |
.read = pupa_fat_read, |
845 |
.close = pupa_fat_close, |
.close = pupa_fat_close, |
846 |
|
.label = pupa_fat_label, |
847 |
.next = 0 |
.next = 0 |
848 |
}; |
}; |
849 |
|
|