fsys_minix.c revision 1b8adde7ba7d5e04395c141c5400dc2cffd7d809
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 1999,2000,2001,2002 Free Software Foundation, Inc.
*
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* Restrictions:
This is MINIX V1 only (yet)
Disk creation is like:
mkfs.minix -c DEVICE
*/
#ifdef FSYS_MINIX
#include "shared.h"
#include "filesys.h"
/* #define DEBUG_MINIX */
/* indirect blocks */
/* sizes are always in bytes, BLOCK values are always in DEV_BSIZE (sectors) */
#define DEV_BSIZE 512
#define BLOCK_SIZE_BITS 10
/* made up, defaults to 1 but can be passed via mount_opts */
#define WHICH_SUPER 1
typedef __signed__ char __s8;
typedef unsigned char __u8;
typedef __signed__ short __s16;
typedef unsigned short __u16;
typedef __signed__ int __s32;
typedef unsigned int __u32;
/* include/linux/minix_fs.h */
#define MINIX_ROOT_INO 1
#define MINIX_LINK_MAX 250
#define MINIX2_LINK_MAX 65530
#define MINIX_I_MAP_SLOTS 8
#define MINIX_Z_MAP_SLOTS 64
/* originally this is :
#define INODE_VERSION(inode) inode->i_sb->u.minix_sb.s_version
here we have */
/*
* This is the original minix inode layout on disk.
* Note the 8-bit gid and atime and ctime.
*/
struct minix_inode {
};
/*
* The new minix inode has all the time entries, as well as
* long block numbers and a third indirect block (7+1+1+1
* instead of 7+1+1). Also, some previously 8-bit values are
* now 16-bit. The inode is now 64 bytes instead of 32.
*/
struct minix2_inode {
};
/*
* minix super-block data on disk
*/
struct minix_super_block {
};
struct minix_dir_entry {
char name[0];
};
/* made up, these are pointers into FSYS_BUF */
/* read once, always stays there: */
#define SUPERBLOCK \
((struct minix_super_block *)(FSYS_BUF))
#define INODE \
#define DATABLOCK1 \
((int)((int)INODE + sizeof(struct minix_inode)))
#define DATABLOCK2 \
((int)((int)DATABLOCK1 + BLOCK_SIZE))
#define S_IFMT 00170000
#define S_IFLNK 0120000
#define S_IFREG 0100000
#define S_IFDIR 0040000
/* check filesystem types and read superblock into memory buffer */
int
minix_mount (void)
{
return 0; /* The partition is not of MINIX type */
if (part_length < (SBLOCK +
(sizeof (struct minix_super_block) / DEV_BSIZE)))
return 0; /* The partition is too short */
(char *) SUPERBLOCK))
return 0; /* Cannot read superblock */
switch (SUPERBLOCK->s_magic)
{
case MINIX_SUPER_MAGIC:
namelen = 14;
break;
case MINIX_SUPER_MAGIC2:
namelen = 30;
break;
default:
return 0; /* Unsupported type */
}
return 1;
}
/* Takes a file system block number and reads it into BUFFER. */
static int
{
BLOCK_SIZE, (char *) buffer);
}
/* Maps LOGICAL_BLOCK (the file offset divided by the blocksize) into
a physical block (the location in the file system) via an inode. */
static int
minix_block_map (int logical_block)
{
int i;
if (logical_block < 7)
logical_block -= 7;
if (logical_block < 512)
{
if (!i || ((mapblock1 != 1)
&& !minix_rdfsb (i, DATABLOCK1)))
{
return -1;
}
mapblock1 = 1;
}
logical_block -= 512;
if (!i || ((mapblock1 != 2)
&& !minix_rdfsb (i, DATABLOCK1)))
{
return -1;
}
mapblock1 = 2;
if (!i || ((mapblock2 != i)
&& !minix_rdfsb (i, DATABLOCK2)))
{
return -1;
}
mapblock2 = i;
}
/* read from INODE into BUF */
int
{
int logical_block;
int offset;
int map;
int ret = 0;
int size = 0;
while (len > 0)
{
/* find the (logical) block component of our location */
#ifdef DEBUG_MINIX
#endif
if (map < 0)
break;
size = BLOCK_SIZE;
}
if (errnum)
ret = 0;
return ret;
}
/* preconditions: minix_mount already executed, therefore supblk in buffer
known as SUPERBLOCK
returns: 0 if error, nonzero iff we were able to find the file successfully
postconditions: on a nonzero return, buffer known as INODE contains the
inode of the file we were trying to look up
side effects: none yet */
int
{
int ino_blk; /* fs pointer of the inode's info */
int str_chk = 0; /* used ot hold the results of a string
compare */
int link_count = 0;
char * rest;
char ch;
int off; /* offset within block of directory
entry */
int loc; /* location within a directory */
int blk; /* which data blk within dir entry */
long map; /* fs pointer of a particular block from
dir entry */
/* loop invariants:
current_ino = inode to lookup
dirname = pointer to filename component we are cur looking up within
the directory known pointed to by current_ino (if any) */
#ifdef DEBUG_MINIX
printf ("\n");
#endif
while (1)
{
#ifdef DEBUG_MINIX
#endif
return 0;
/* reset indirect blocks! */
/* copy inode to fixed location */
sizeof (struct minix_inode));
/* If we've got a symbolic link, then chase it. */
{
int len;
if (++link_count > MAX_LINK_COUNT)
{
return 0;
}
#ifdef DEBUG_MINIX
#endif
/* Find out how long our remaining name is. */
len = 0;
len++;
/* Get the symlink size. */
{
return 0;
}
if (len)
{
/* Copy the remaining name to the end of the symlink data.
Note that DIRNAME and LINKBUF may overlap! */
}
/* Read the necessary blocks, and reset the file pointer. */
filepos = 0;
if (!len)
return 0;
#ifdef DEBUG_MINIX
#endif
if (*dirname == '/')
{
/* It's an absolute link, so look it up in root. */
}
else
{
/* Relative, so look it up in our parent directory. */
}
/* Try again using the new name. */
continue;
}
/* If end of filename, INODE points to the file's inode */
{
{
return 0;
}
return 1;
}
/* else we have to traverse a directory */
/* skip over slashes */
while (*dirname == '/')
dirname++;
/* if this isn't a directory of sufficient size to hold our file,
abort */
{
return 0;
}
/* skip to next slash or end of filename (space) */
rest++);
/* look through this directory and find the next filename component */
/* invariant: rest points to slash after the next filename component */
*rest = 0;
loc = 0;
do
{
#ifdef DEBUG_MINIX
#endif
give up */
{
if (print_possibilities < 0)
{
#if 0
putchar ('\n');
#endif
}
else
{
}
return (print_possibilities < 0);
}
/* else, find the (logical) block component of our location */
/* we know which logical block of the directory entry we are looking
for, now we have to translate that to the physical (fs) block on
the disk */
#ifdef DEBUG_MINIX
#endif
mapblock2 = -1;
{
return 0;
}
/* advance loc prematurely to next on-disk directory entry */
/* NOTE: minix filenames are NULL terminated if < NAMELEN
else exact */
#ifdef DEBUG_MINIX
#endif
{
# ifndef STAGE1_5
{
if (print_possibilities > 0)
}
# endif
}
}
}
/* never get here */
}
#endif /* FSYS_MINIX */