/*-
* Copyright (c) 2001 Doug Rabson
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD: src/sys/boot/efi/libefi/efifs.c,v 1.8 2003/08/02 08:22:03 marcel Exp $
*/
/*
* We cannot blindly assume that f->f_devdata points to a
* efi_devdesc structure. Before we dereference 'dev', make
* sure that the underlying device is ours.
*/
if (f->f_dev != &devsw[0] || dev->d_handle == NULL)
return ENOENT;
status = BS->HandleProtocol(dev->d_handle, &sfsid, (VOID **)&sfs);
if (EFI_ERROR(status))
return ENOENT;
/*
* Find the root directory.
*/
status = sfs->OpenVolume(sfs, &root);
/*
* Convert path to CHAR16, skipping leading separators.
*/
while (*upath == '/')
upath++;
if (!*upath) {
/* Opening the root directory, */
f->f_fsdata = root;
return 0;
}
cp = path = alloc((strlen(upath) + 1) * sizeof(CHAR16));
if (path == NULL)
return ENOMEM;
while (*upath) {
if (*upath == '/')
*cp = '\\';
else
*cp = *upath;
upath++;
cp++;
}
*cp++ = 0;
/*
* Try to open it.
*/
status = root->Open(root, &file, path, EFI_FILE_MODE_READ, 0);
free(path);
if (EFI_ERROR(status)) {
root->Close(root);
return ENOENT;
}
sz = 0;
status = BS->LocateHandle(ByProtocol, &sfsid, 0, &sz, 0);
if (status != EFI_BUFFER_TOO_SMALL)
return ENOENT;
fs_handles = (EFI_HANDLE *) alloc(sz);
status = BS->LocateHandle(ByProtocol, &sfsid, 0,
&sz, fs_handles);
if (EFI_ERROR(status)) {
free(fs_handles);
return ENOENT;
}
fs_handle_count = sz / sizeof(EFI_HANDLE);
return 0;
}
/*
* Print information about disks
*/
void
efifs_dev_print(int verbose)
{
int i;
char line[80];
for (i = 0; i < fs_handle_count; i++) {
snprintf(line, sizeof(line), " fs%d: EFI filesystem", i);
pager_output(line);
/* XXX more detail? */
pager_output("\n");
}
}
/*
* Attempt to open the disk described by (dev) for use by (f).
*
* Note that the philosophy here is "give them exactly what
* they ask for". This is necessary because being too "smart"
* about what the user might want leads to complications.
* (eg. given no slice or partition value, with a disk that is
* sliced - are they after the first BSD slice, or the DOS
* slice before it?)
*/
int
efifs_dev_open(struct open_file *f, ...)
{
va_list args;
struct efi_devdesc *dev;
int unit;
va_start(args, f);
dev = va_arg(args, struct efi_devdesc*);
va_end(args);
unit = dev->d_kind.efidisk.unit;
if (unit < 0 || unit >= fs_handle_count) {
printf("attempt to open nonexistent EFI filesystem\n");
return(ENXIO);
}
dev->d_handle = fs_handles[unit];
return 0;
}
int
efifs_dev_close(struct open_file *f)
{
return 0;
}
int
efifs_dev_strategy(void *devdata, int rw, daddr_t dblk, size_t size, void *buf, size_t *rsize)
{
return 0;
}