2009-11-21 Samuel Thibault <samuel.thibault@ens-lyon.org>
[grub2.git] / normal / misc.c
blob0a1a2f052de3b03cf13bdc533be211b39425ce95
1 /* misc.c - miscellaneous functions */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 2005,2007,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/>.
20 #include <grub/normal.h>
21 #include <grub/disk.h>
22 #include <grub/fs.h>
23 #include <grub/err.h>
24 #include <grub/misc.h>
25 #include <grub/mm.h>
26 #include <grub/datetime.h>
28 /* Print the information on the device NAME. */
29 grub_err_t
30 grub_normal_print_device_info (const char *name)
32 grub_device_t dev;
33 char *p;
35 p = grub_strchr (name, ',');
36 if (p)
37 grub_printf ("\tPartition %s: ", name);
38 else
39 grub_printf ("Device %s: ", name);
41 dev = grub_device_open (name);
42 if (! dev)
43 grub_printf ("Filesystem cannot be accessed");
44 else if (dev->disk)
46 grub_fs_t fs;
48 fs = grub_fs_probe (dev);
49 /* Ignore all errors. */
50 grub_errno = 0;
52 if (fs)
54 grub_printf ("Filesystem type %s", fs->name);
55 if (fs->label)
57 char *label;
58 (fs->label) (dev, &label);
59 if (grub_errno == GRUB_ERR_NONE)
61 if (label && grub_strlen (label))
62 grub_printf (", Label %s", label);
63 grub_free (label);
65 grub_errno = GRUB_ERR_NONE;
67 if (fs->mtime)
69 grub_int32_t tm;
70 struct grub_datetime datetime;
71 (fs->mtime) (dev, &tm);
72 if (grub_errno == GRUB_ERR_NONE)
74 grub_unixtime2datetime (tm, &datetime);
75 grub_printf (", Last modification time %d-%02d-%02d "
76 "%02d:%02d:%02d %s",
77 datetime.year, datetime.month, datetime.day,
78 datetime.hour, datetime.minute, datetime.second,
79 grub_get_weekday_name (&datetime));
82 grub_errno = GRUB_ERR_NONE;
84 if (fs->uuid)
86 char *uuid;
87 (fs->uuid) (dev, &uuid);
88 if (grub_errno == GRUB_ERR_NONE)
90 if (uuid && grub_strlen (uuid))
91 grub_printf (", UUID %s", uuid);
92 grub_free (uuid);
94 grub_errno = GRUB_ERR_NONE;
97 else if (! dev->disk->has_partitions || dev->disk->partition)
98 grub_printf ("Unknown filesystem");
99 else
100 grub_printf ("Partition table");
102 grub_device_close (dev);
105 grub_printf ("\n");
106 return grub_errno;