/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Basic file system reading code for standalone I/O system.
* Simulates a primitive UNIX I/O system (read(), write(), open(), etc).
* Does not support writes.
*/
/*
* WARNING:
* This is currently used by installgrub for creating bootable floppy.
* The special part is diskread_callback/fileread_callback for gathering
* fileblock list.
*/
#include <sys/sysmacros.h>
#include "pcfilep.h"
#if defined(_BOOT)
#else
#include <stdio.h>
#include <strings.h>
#include <ctype.h>
#endif
#if defined(_BOOT)
/* PRINTLIKE */
extern void kobj_printf(char *, ...);
#else
#endif
extern int bootrd_debug;
extern void *bkmem_alloc(size_t);
extern void bkmem_free(void *, size_t);
/*
* NOTE: The fileread_callback is set by the calling program
* during a file read. diskread_callback is set to fileread_callback
* only if reading a file block. It needs to be NULL while reading
* cluster blocks.
*/
extern int (*diskread_callback)(int, int);
extern int (*fileread_callback)(int, int);
/*
* Local prototypes
*/
static int lookuppn(char *, _dir_entry_p);
static void *readblock(int, int);
static int fat_map(int, int);
static int cluster_valid(long, int);
static int fat_ctodb(int, int);
static int bpcfs_mountroot(char *str);
static int bpcfs_unmountroot(void);
static int bpcfs_close(int fd);
static void bpcfs_closeall(void);
/* cache the cluster */
static int nsec_cache;
static int nsec_start;
static char *cluster_cache;
/*ARGSUSED*/
static int
{
int ncluster;
return (0); /* already mounted */
head->fi_filedes = 0;
/* read of first floppy sector */
head->fi_blocknum = 0;
printf("failed to read first sector\n");
return (-1);
}
printf("invalid bios paramet block\n");
return (-1);
}
sizeof (_dir_entry_t) / SECSIZ;
/* figure out the number of clusters in this partition */
/* cache the cluster */
else
if (cluster_cache == NULL) {
printf("bpcfs_mountroot: out of memory\n");
return (-1);
}
printf("bpcfs_mountroot: failed to read cluster\n");
return (-1);
}
dprintf("read cluster sectors %d starting at %d\n",
return (0);
}
static int
bpcfs_unmountroot(void)
{
return (-1);
(void) bpcfs_closeall();
return (0);
}
/*
* Open a file.
*/
/*ARGSUSED*/
int
{
_dir_entry_t d;
return (-1);
}
return (filep->fi_filedes);
}
int
{
return (-1);
return (-1);
}
/* unlink and deallocate node */
dprintf("close done\n");
return (0);
}
static void
bpcfs_closeall(void)
{
printf("Filesystem may be inconsistent.\n");
}
static ssize_t
{
char *block;
dprintf("bpcfs_read: fd = %d, buf = %p, size = %d\n",
fd, (void *)b, c);
return (-1);
}
return (0);
printf("bpcfs_read: invalid cluster: %ld, %d\n",
return (-1);
}
}
while (count < c) {
if (xfer == 0)
break; /* last sector done */
return (-1);
}
if (diskread_callback == NULL)
b += xfer;
}
if (count < c) {
printf("bpcfs_read: invalid cluster: %ld, %d\n",
break;
}
}
}
return (count);
}
/*
* This version of seek() only performs absolute seeks (whence == 0).
*/
static off_t
{
return (-1);
switch (whence) {
case SEEK_CUR:
break;
case SEEK_SET:
break;
default:
case SEEK_END:
break;
}
return (0);
}
static fileid_t *
{
if (fd >= 0) {
}
return (0);
}
static int
{
}
static int
{
uint_t s;
return (s);
}
static int
{
if (rootdir) {
}
/* ---- Find out what sector this cluster is in ---- */
/*
* Read two sectors so that if our fat_index points at the last byte
* byte we'll have the data needed. This is only a problem for fat12
* entries.
*/
printf("fat_map: bad cluster\n");
return (CLUSTER_BAD_16);
}
else {
if (blk & 1)
else
/*
* This makes compares easier because we can just compare
* against one value instead of two.
*/
if (blk >= CLUSTER_RES_12_0)
blk |= CLUSTER_RES_16_0;
}
return (blk);
}
static int
{
/* starting char must match */
--cs;
return (1);
}
/* remainder should be either ~# or all spaces */
return (0);
while (cs > 0) {
if (*dn++ != ' ')
return (1);
--cs;
}
return (0);
}
static int
{
int ret;
if (sep) {
*sep = '\0';
} else
ext = " ";
ret = 1;
else
ret = 0;
if (sep)
*sep = '.';
return (ret);
}
static int
{
int j, sector;
dprintf("lookup: name = %s\n", n);
return (0);
dprintf("lookup: dir entry %s.%s;\n",
return (0);
dprintf("lookup: match found\n");
return (1);
}
}
/* next cluster */
}
return (0);
}
static int
{
long dir_blk;
char *p, *ep;
dprintf("lookuppn: path = %s\n", n);
if ((*n == '\\') || (*n == '/')) {
while ((*n == '\\') || (*n == '/'))
n++;
if (*n == '\0') {
return (0);
}
}
while (*n) {
p = &name[0];
while (*n && (*n != '\\') && (*n != '/'))
if (p != ep)
*p++ = *n++;
else {
return (-1); /* name is too long */
}
while ((*n == '\\') || (*n == '/'))
n++;
return (-1);
}
dprintf("dd = %x:%x:%x attr = %x\n",
dprintf("return, not a directory\n");
return (-1);
}
}
return (0);
}
static void *
{
/* read disk sectors */
return (NULL);
}
}
"boot_pcfs",
};