|
|
5593c8 |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
5593c8 |
From: Michael Chang <mchang@suse.com>
|
|
|
5593c8 |
Date: Thu, 21 Aug 2014 03:39:11 +0000
|
|
|
5593c8 |
Subject: [PATCH] grub2-btrfs-03-follow_default
|
|
|
5593c8 |
|
|
|
5593c8 |
---
|
|
|
5593c8 |
grub-core/fs/btrfs.c | 107 ++++++++++++++++++++++++++++++++++++---------------
|
|
|
5593c8 |
1 file changed, 76 insertions(+), 31 deletions(-)
|
|
|
5593c8 |
|
|
|
5593c8 |
diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
|
|
|
1c6ba0 |
index ad1b56b716..113c1f746c 100644
|
|
|
5593c8 |
--- a/grub-core/fs/btrfs.c
|
|
|
5593c8 |
+++ b/grub-core/fs/btrfs.c
|
|
|
5593c8 |
@@ -1256,6 +1256,7 @@ grub_btrfs_mount (grub_device_t dev)
|
|
|
5593c8 |
{
|
|
|
5593c8 |
struct grub_btrfs_data *data;
|
|
|
5593c8 |
grub_err_t err;
|
|
|
5593c8 |
+ const char *relpath = grub_env_get ("btrfs_relative_path");
|
|
|
5593c8 |
|
|
|
5593c8 |
if (!dev->disk)
|
|
|
5593c8 |
{
|
|
|
5593c8 |
@@ -1286,11 +1287,14 @@ grub_btrfs_mount (grub_device_t dev)
|
|
|
5593c8 |
data->devices_attached[0].dev = dev;
|
|
|
5593c8 |
data->devices_attached[0].id = data->sblock.this_device.device_id;
|
|
|
5593c8 |
|
|
|
5593c8 |
- err = btrfs_handle_subvol (data);
|
|
|
5593c8 |
- if (err)
|
|
|
5593c8 |
+ if (relpath && (relpath[0] == '1' || relpath[0] == 'y'))
|
|
|
5593c8 |
{
|
|
|
5593c8 |
- grub_free (data);
|
|
|
5593c8 |
- return NULL;
|
|
|
5593c8 |
+ err = btrfs_handle_subvol (data);
|
|
|
5593c8 |
+ if (err)
|
|
|
5593c8 |
+ {
|
|
|
5593c8 |
+ grub_free (data);
|
|
|
5593c8 |
+ return NULL;
|
|
|
5593c8 |
+ }
|
|
|
5593c8 |
}
|
|
|
5593c8 |
|
|
|
5593c8 |
return data;
|
|
|
5593c8 |
@@ -1855,24 +1859,39 @@ find_path (struct grub_btrfs_data *data,
|
|
|
5593c8 |
grub_size_t allocated = 0;
|
|
|
5593c8 |
struct grub_btrfs_dir_item *direl = NULL;
|
|
|
5593c8 |
struct grub_btrfs_key key_out;
|
|
|
5593c8 |
+ int follow_default;
|
|
|
5593c8 |
const char *ctoken;
|
|
|
5593c8 |
grub_size_t ctokenlen;
|
|
|
5593c8 |
char *path_alloc = NULL;
|
|
|
5593c8 |
char *origpath = NULL;
|
|
|
5593c8 |
unsigned symlinks_max = 32;
|
|
|
5593c8 |
+ const char *relpath = grub_env_get ("btrfs_relative_path");
|
|
|
5593c8 |
|
|
|
5593c8 |
+ follow_default = 0;
|
|
|
5593c8 |
origpath = grub_strdup (path);
|
|
|
5593c8 |
if (!origpath)
|
|
|
5593c8 |
return grub_errno;
|
|
|
5593c8 |
|
|
|
5593c8 |
- if (data->fs_tree)
|
|
|
5593c8 |
+ if (relpath && (relpath[0] == '1' || relpath[0] == 'y'))
|
|
|
5593c8 |
{
|
|
|
5593c8 |
- *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
|
|
|
5593c8 |
- *tree = data->fs_tree;
|
|
|
5593c8 |
- /* This is a tree root, so everything starts at objectid 256 */
|
|
|
5593c8 |
- key->object_id = grub_cpu_to_le64_compile_time (GRUB_BTRFS_OBJECT_ID_CHUNK);
|
|
|
5593c8 |
- key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
|
|
|
5593c8 |
- key->offset = 0;
|
|
|
5593c8 |
+ if (data->fs_tree)
|
|
|
5593c8 |
+ {
|
|
|
5593c8 |
+ *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
|
|
|
5593c8 |
+ *tree = data->fs_tree;
|
|
|
5593c8 |
+ /* This is a tree root, so everything starts at objectid 256 */
|
|
|
5593c8 |
+ key->object_id = grub_cpu_to_le64_compile_time (GRUB_BTRFS_OBJECT_ID_CHUNK);
|
|
|
5593c8 |
+ key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
|
|
|
5593c8 |
+ key->offset = 0;
|
|
|
5593c8 |
+ }
|
|
|
5593c8 |
+ else
|
|
|
5593c8 |
+ {
|
|
|
5593c8 |
+ *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
|
|
|
5593c8 |
+ *tree = data->sblock.root_tree;
|
|
|
5593c8 |
+ key->object_id = data->sblock.root_dir_objectid;
|
|
|
5593c8 |
+ key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
|
|
|
5593c8 |
+ key->offset = 0;
|
|
|
5593c8 |
+ follow_default = 1;
|
|
|
5593c8 |
+ }
|
|
|
5593c8 |
}
|
|
|
5593c8 |
else
|
|
|
5593c8 |
{
|
|
|
5593c8 |
@@ -1883,15 +1902,23 @@ find_path (struct grub_btrfs_data *data,
|
|
|
5593c8 |
|
|
|
5593c8 |
while (1)
|
|
|
5593c8 |
{
|
|
|
5593c8 |
- while (path[0] == '/')
|
|
|
5593c8 |
- path++;
|
|
|
5593c8 |
- if (!path[0])
|
|
|
5593c8 |
- break;
|
|
|
5593c8 |
- slash = grub_strchr (path, '/');
|
|
|
5593c8 |
- if (!slash)
|
|
|
5593c8 |
- slash = path + grub_strlen (path);
|
|
|
5593c8 |
- ctoken = path;
|
|
|
5593c8 |
- ctokenlen = slash - path;
|
|
|
5593c8 |
+ if (!follow_default)
|
|
|
5593c8 |
+ {
|
|
|
5593c8 |
+ while (path[0] == '/')
|
|
|
5593c8 |
+ path++;
|
|
|
5593c8 |
+ if (!path[0])
|
|
|
5593c8 |
+ break;
|
|
|
5593c8 |
+ slash = grub_strchr (path, '/');
|
|
|
5593c8 |
+ if (!slash)
|
|
|
5593c8 |
+ slash = path + grub_strlen (path);
|
|
|
5593c8 |
+ ctoken = path;
|
|
|
5593c8 |
+ ctokenlen = slash - path;
|
|
|
5593c8 |
+ }
|
|
|
5593c8 |
+ else
|
|
|
5593c8 |
+ {
|
|
|
5593c8 |
+ ctoken = "default";
|
|
|
5593c8 |
+ ctokenlen = sizeof ("default") - 1;
|
|
|
5593c8 |
+ }
|
|
|
5593c8 |
|
|
|
5593c8 |
if (*type != GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY)
|
|
|
5593c8 |
{
|
|
|
5593c8 |
@@ -1902,7 +1929,9 @@ find_path (struct grub_btrfs_data *data,
|
|
|
5593c8 |
|
|
|
5593c8 |
if (ctokenlen == 1 && ctoken[0] == '.')
|
|
|
5593c8 |
{
|
|
|
5593c8 |
- path = slash;
|
|
|
5593c8 |
+ if (!follow_default)
|
|
|
5593c8 |
+ path = slash;
|
|
|
5593c8 |
+ follow_default = 0;
|
|
|
5593c8 |
continue;
|
|
|
5593c8 |
}
|
|
|
5593c8 |
if (ctokenlen == 2 && ctoken[0] == '.' && ctoken[1] == '.')
|
|
|
5593c8 |
@@ -1933,8 +1962,9 @@ find_path (struct grub_btrfs_data *data,
|
|
|
5593c8 |
*type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
|
|
|
5593c8 |
key->object_id = key_out.offset;
|
|
|
5593c8 |
|
|
|
5593c8 |
- path = slash;
|
|
|
5593c8 |
-
|
|
|
5593c8 |
+ if (!follow_default)
|
|
|
5593c8 |
+ path = slash;
|
|
|
5593c8 |
+ follow_default = 0;
|
|
|
5593c8 |
continue;
|
|
|
5593c8 |
}
|
|
|
5593c8 |
|
|
|
5593c8 |
@@ -2003,7 +2033,9 @@ find_path (struct grub_btrfs_data *data,
|
|
|
5593c8 |
return err;
|
|
|
5593c8 |
}
|
|
|
5593c8 |
|
|
|
5593c8 |
- path = slash;
|
|
|
5593c8 |
+ if (!follow_default)
|
|
|
5593c8 |
+ path = slash;
|
|
|
5593c8 |
+ follow_default = 0;
|
|
|
5593c8 |
if (cdirel->type == GRUB_BTRFS_DIR_ITEM_TYPE_SYMLINK)
|
|
|
5593c8 |
{
|
|
|
5593c8 |
struct grub_btrfs_inode inode;
|
|
|
5593c8 |
@@ -2053,14 +2085,26 @@ find_path (struct grub_btrfs_data *data,
|
|
|
5593c8 |
path = path_alloc = tmp;
|
|
|
5593c8 |
if (path[0] == '/')
|
|
|
5593c8 |
{
|
|
|
5593c8 |
- if (data->fs_tree)
|
|
|
5593c8 |
+ if (relpath && (relpath[0] == '1' || relpath[0] == 'y'))
|
|
|
5593c8 |
{
|
|
|
5593c8 |
- *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
|
|
|
5593c8 |
- *tree = data->fs_tree;
|
|
|
5593c8 |
- /* This is a tree root, so everything starts at objectid 256 */
|
|
|
5593c8 |
- key->object_id = grub_cpu_to_le64_compile_time (GRUB_BTRFS_OBJECT_ID_CHUNK);
|
|
|
5593c8 |
- key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
|
|
|
5593c8 |
- key->offset = 0;
|
|
|
5593c8 |
+ if (data->fs_tree)
|
|
|
5593c8 |
+ {
|
|
|
5593c8 |
+ *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
|
|
|
5593c8 |
+ *tree = data->fs_tree;
|
|
|
5593c8 |
+ /* This is a tree root, so everything starts at objectid 256 */
|
|
|
5593c8 |
+ key->object_id = grub_cpu_to_le64_compile_time (GRUB_BTRFS_OBJECT_ID_CHUNK);
|
|
|
5593c8 |
+ key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
|
|
|
5593c8 |
+ key->offset = 0;
|
|
|
5593c8 |
+ }
|
|
|
5593c8 |
+ else
|
|
|
5593c8 |
+ {
|
|
|
5593c8 |
+ *type = GRUB_BTRFS_DIR_ITEM_TYPE_DIRECTORY;
|
|
|
5593c8 |
+ *tree = data->sblock.root_tree;
|
|
|
5593c8 |
+ key->object_id = data->sblock.root_dir_objectid;
|
|
|
5593c8 |
+ key->type = GRUB_BTRFS_ITEM_TYPE_DIR_ITEM;
|
|
|
5593c8 |
+ key->offset = 0;
|
|
|
5593c8 |
+ follow_default = 1;
|
|
|
5593c8 |
+ }
|
|
|
5593c8 |
}
|
|
|
5593c8 |
else
|
|
|
5593c8 |
{
|
|
|
5593c8 |
@@ -2716,6 +2760,7 @@ GRUB_MOD_INIT (btrfs)
|
|
|
5593c8 |
subvolid_set_env);
|
|
|
5593c8 |
grub_env_export ("btrfs_subvol");
|
|
|
5593c8 |
grub_env_export ("btrfs_subvolid");
|
|
|
5593c8 |
+ grub_env_export ("btrfs_relative_path");
|
|
|
5593c8 |
}
|
|
|
5593c8 |
|
|
|
5593c8 |
GRUB_MOD_FINI (btrfs)
|