/* grub-mount.c - FUSE driver for filesystems that GRUB understands */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2008,2009,2010 Free Software Foundation, Inc.
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include "progname.h"
#include "argp.h"
static int fuse_argc = 0;
static int num_disks = 0;
static int mount_crypt = 0;
static grub_err_t
{
if (! cmd)
}
/* Translate GRUB error numbers into OS error numbers. Print any unexpected
errors. */
static int
translate_error (void)
{
int ret;
switch (grub_errno)
{
case GRUB_ERR_NONE:
ret = 0;
break;
case GRUB_ERR_OUT_OF_MEMORY:
grub_print_error ();
break;
case GRUB_ERR_BAD_FILE_TYPE:
/* This could also be EISDIR. Take a guess. */
break;
case GRUB_ERR_FILE_NOT_FOUND:
break;
case GRUB_ERR_FILE_READ_ERROR:
case GRUB_ERR_READ_ERROR:
case GRUB_ERR_IO:
grub_print_error ();
break;
case GRUB_ERR_SYMLINK_LOOP:
break;
default:
grub_print_error ();
break;
}
/* Any previous errors were handled. */
return ret;
}
static int
{
const char *pathname_t;
int file_exists = 0;
/* A hook for iterating directories. */
auto int find_file (const char *cur_filename,
const struct grub_dirhook_info *info);
const struct grub_dirhook_info *info)
{
{
file_exists = 1;
return 1;
}
return 0;
}
{
return 0;
}
file_exists = 0;
if (! pathname_t)
pathname_t = path;
else
pathname_t++;
/* Remove trailing '/'. */
/* Split into path and filename. */
if (! filename)
{
}
else
{
filename++;
}
/* It's the whole device. */
if (!file_exists)
{
return -ENOENT;
}
{
if (! file)
return translate_error ();
}
else
return 0;
}
static int
{
return 0;
}
/* FIXME */
static int
{
if (! file)
return translate_error ();
return 0;
}
static int
struct fuse_file_info *fi)
{
return -EINVAL;
if (size < 0)
return translate_error ();
else
{
return size;
}
}
static int
{
return 0;
}
static int
{
char *pathname;
const struct grub_dirhook_info *info);
{
{
char *tmp;
if (! file)
return translate_error ();
}
return 0;
}
/* Remove trailing '/'. */
return 0;
}
.getattr = fuse_getattr,
.release = fuse_release,
.opendir = fuse_opendir,
.readdir = fuse_readdir,
};
static grub_err_t
fuse_init (void)
{
int i;
for (i = 0; i < num_disks; i++)
{
char *host_file;
char *loop_name;
if (!loop_name)
if (!host_file)
grub_util_error (_("loopback command fails"));
}
if (mount_crypt)
{
}
grub_lvm_fini ();
grub_raid_fini ();
grub_raid_init ();
grub_lvm_init ();
dev = grub_device_open (0);
if (! dev)
return grub_errno;
if (! fs)
{
return grub_errno;
}
for (i = 0; i < num_disks; i++)
{
char *loop_name;
if (!loop_name)
argv[0] = "-d";
}
return GRUB_ERR_NONE;
}
{0, 0, 0, 0, 0, 0}
};
/* Print the version information. */
static void
{
}
{
char *p;
switch (key)
{
case 'r':
return 0;
case 'K':
{
{
}
}
else
{
FILE *f;
if (!f)
{
return 0;
}
if (real_size < 0)
{
fclose (f);
return 0;
}
}
return 0;
case 'C':
mount_crypt = 1;
return 0;
case 'd':
return 0;
case 'v':
verbosity++;
return 0;
case ARGP_KEY_ARG:
if (arg[0] != '-')
break;
default:
if (!arg)
return 0;
fuse_argc++;
return 0;
}
num_disks++;
return 0;
}
N_("Debug tool for filesystem driver."),
};
int
{
set_program_name (argv[0]);
fuse_argc++;
/* Run single-threaded. */
fuse_argc++;
if (num_disks < 2)
grub_util_error (_("need an image and mountpoint"));
fuse_argc++;
num_disks--;
/* Initialize all modules. */
grub_init_all ();
if (debug_str)
alloc_root = 0;
if (root)
{
{
root = alloc_root;
}
}
else
root = default_root;
if (alloc_root)
free (alloc_root);
/* Do it. */
fuse_init ();
if (grub_errno)
{
grub_print_error ();
return 1;
}
/* Free resources. */
grub_fini_all ();
return 0;
}