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