2
* GRUB -- GRand Unified Bootloader
3
* Copyright (C) 1999,2000,2001,2002,2003,2006,2007,2008,2009,2010,2011,2012,2013 Free Software Foundation, Inc.
5
* GRUB is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* GRUB is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19
#include <config-util.h>
22
#include <sys/types.h>
29
#include <grub/util/misc.h>
30
#include <grub/emu/hostdisk.h>
31
#include <grub/emu/getroot.h>
34
/* This function never prints trailing slashes (so that its output
35
can be appended a slash unconditionally). */
37
grub_make_system_path_relative_to_its_root (const char *path)
40
char *p, *buf, *buf2, *buf3, *ret;
47
p = canonicalize_file_name (path);
49
grub_util_error (_("failed to get canonical path of `%s'"), path);
52
ret = grub_make_system_path_relative_to_its_root_os (p);
57
/* For ZFS sub-pool filesystems. */
61
grub_find_zpool_from_dir (p, &dummy, &poolfs);
69
if (stat (buf, &st) < 0)
70
grub_util_error (_("cannot stat `%s': %s"), buf, strerror (errno));
75
/* This loop sets offset to the number of chars of the root
76
directory we're inspecting. */
79
p = strrchr (buf, '/');
81
/* This should never happen. */
82
grub_util_error ("%s",
83
/* TRANSLATORS: canonical pathname is the
84
complete one e.g. /etc/fstab. It has
85
to contain `/' normally, if it doesn't
86
we're in trouble and throw this error. */
87
_("no `/' in canonical filename"));
93
if (stat (buf, &st) < 0)
94
grub_util_error (_("cannot stat `%s': %s"), buf, strerror (errno));
96
/* buf is another filesystem; we found it. */
99
/* offset == 0 means path given is the mount point.
100
This works around special-casing of "/" in Un*x. This function never
101
prints trailing slashes (so that its output can be appended a slash
102
unconditionally). Each slash in is considered a preceding slash, and
103
therefore the root directory is an empty string. */
109
return xasprintf ("/%s/@", poolfs);
117
/* offset == 1 means root directory. */
120
/* Include leading slash. */
126
buf3 = xstrdup (buf2 + offset);
131
/* Remove trailing slashes, return empty string if root directory. */
133
while (len > 0 && buf3[len - 1] == '/')
135
buf3[len - 1] = '\0';
141
ret = xasprintf ("/%s/@%s", poolfs, buf3);