[Prev][Next][Index][Thread]

Linux ext2 filesystem




On Tue, 16 May 2000, Leigh Stoller wrote:

> > From: Yves Martin <ymartin@ensisun.imag.fr>
> > Subject: Linux ext2 filesystem
> > 
> >     I would like to report some problems
> >   with Linux FS library and Linux devices.
> 
> Well, how about posting your example code (with the initialization sequence
> included) so that someone on the list can take a look, or maybe provide
> some help on how to find the cause of the problem? Please include how you
> linked the kernel as well.

	So here is in attachment an extract from my
  project to demonstrate my problems.
  Compile it with either 20000202 or 20000505 snapshot
  of OSKit,
  modify information about IDE disk name and partition
  to suit to your system.

  Commands are

gcc -g -Wall -DOSKIT -I- -I/usr/local/include
    -I/usr/local/include/oskit/freebsd -nostdinc
    -c ext2mount.c -o ext2mount.o
ld -Ttext 100000  -L/usr/local/lib \
   -o ext2mount /usr/local/lib/oskit/multiboot.o ext2mount.o \
   -loskit_clientos \
   -loskit_memfs -loskit_freebsd_dev -loskit_fsnamespace \
   -loskit_linux_dev -loskit_linux_fs \
   -loskit_dev -loskit_diskpart  -loskit_kern -loskit_lmm \
   -loskit_freebsd_net -loskit_freebsd_c -loskit_com \
   /usr/local/lib/oskit/crtn.o


	And here is what I sent to descibe
  my problems

From ymartin@ensimag.imag.fr Tue May 16 18:23:28 2000
Date: Tue, 16 May 2000 15:05:05 +0200 (MET DST)
From: Yves Martin <ymartin@ensimag.imag.fr>
To: oskit users list <oskit-users@cs.utah.edu>
Subject: Linux ext2 filesystem


	Hello,

    I would like to report some problems
  with Linux FS library and Linux devices.

  First, my kernel code disables IRQs trought
    pic_set_irqmask( 0xFFFF ) ;
  before any initialization.

  Until I use oskit_linux_init_net,
  oskit_dev_probe  works correctly (i.e. devices
    are probed and network connection is OK)

  When I try oskit_linux_init_ide,
  oskit_dev_probe remains stuck after printing
  the identification string of my hard disk.

  So I guess that IDE device does not unmask PIC
  before probing devices, whereas network device does.
  Why ? It seems incorrect to me.

  I succeeded in detecting IDE drives and mounting
  ext2fs partition as READ ONLY filesystem.

  When I read files on this partition, I first do
  'lstat' on it (from FreeBSD C library) and I get the
  following message
'FS_LINUX_ll_rw_block: oskit_blkio_read: 0 expected 4096'
  with almost 50% of existing files on current directory.
  
  What should I understand, is there something to correct ?
  
  Then, I mounted ext2fs filesystem as a mount point
  of a memory filesystem,
  / is memfs and /disk is ext2fs mount point.
  
  if I remain on /disk directory,
   chdir("..") returns correctly to /
  but if I go to /disk/etc and do then chdir("..") twice,
  current directory remains '/disk'
  I have to do chdir("/") to return to root memfs.
  Has ext2fs filesystem COM object a bug to correct ?
  

  Thanks for having read 'til here,
  I always ask too many questions ;))

--------------------------------------------------------

	Now you could try to exec with
  pic_set_irqmask( 0xFFFF )  instead of 0
  and see if first IDE drive is probed.

  Now, with my mini-shell, try to do :

> ls
disk/       (to indicate directory)
> down1     (go to /disk)
> ls
  [...]
(first problem,
 your partition, with 'oskit_blkio_read' errors for some
 files, some directory are not read as directory !)

> ls
  [...]
(no more errors, fsnamespace cache is here, I think,
 but there are errors on some directory)

> up        (now it's / )
> ls
disk/       ( OK )
> down1
> ls
  [...]
> down2     (now it's /disk/etc)
> ls
  [...]  ( new read errors )
> up        ( now /disk )
> ls
  [...]     ( OK )
> up        ( should be / )
> ls
  [...]     ( it's still /disk )
> up
> ls
  [...]     ( it's still /disk )
> root
> ls
disk/	    ( OK it's / )


	I think I've given you all keys to be
  able to find out where causes of problems
  could be.
  For chdir problem, it may be ext2fs com object,
  For PIC problem, it may be linux IDE device code
  or glue code.

  Good luck, jim.

-- Yves Martin --- Elève-ingénieur ENSIMAG - 3e année ---
  Adr : R.H.B. Ch. 765     Yves.Martin@ensimag.imag.fr   
  2 av. J. O.  GRENOBLE      Tél: 04 76 44 20 01         
---------------------------- ICQ: 53379907 --------------
#include <oskit/freebsd/stdio.h>
#include <oskit/freebsd/stdlib.h>
#include <oskit/freebsd/sys/stat.h>
#include <oskit/freebsd/unistd.h>
#include <oskit/freebsd/dirent.h>
#include <oskit/freebsd/string.h>
#include <oskit/freebsd/errno.h>

#include <oskit/clientos.h>

#include <oskit/dev/osenv_log.h>
#include <oskit/dev/osenv_mem.h>
#include <oskit/dev/osenv_timer.h>
#include <oskit/net/socket.h>

#include <oskit/dev/linux.h>
#include <oskit/principal.h>

#include <oskit/fs/linux.h>
#include <oskit/fs/memfs.h>
#include <oskit/fs/dir.h>

#include <oskit/io/blkio.h>
#include <oskit/diskpart/diskpart.h>

#include <oskit/x86/pc/pic.h>
#include <oskit/x86/pc/phys_lmm.h>
#include <oskit/debug.h>




/* Some memory in heap */

#define ALIGNED(x) __attribute__((__aligned__(x)))

#define MEMORY_HEAP_SIZE (4096*1024)
char ALIGNED(32) memory_heap[MEMORY_HEAP_SIZE] ;


void base_multiboot_init_mem( void )
{
    
    phys_lmm_init() ;
    phys_lmm_add( (oskit_addr_t)memory_heap, MEMORY_HEAP_SIZE ) ;
}


/* General OSenv */

oskit_osenv_t * myosenv ;


/* Identity of current client process. */

static oskit_principal_t *cur_principal;

oskit_error_t
oskit_get_call_context(const struct oskit_guid *iid, void **out_if)
{
    if (memcmp(iid, &oskit_iunknown_iid, sizeof(*iid)) == 0 ||
	memcmp(iid, &oskit_principal_iid, sizeof(*iid)) == 0) {
	*out_if = cur_principal;
	oskit_principal_addref(cur_principal);
	return 0;
    }

    *out_if = 0;
    return OSKIT_E_NOINTERFACE;
}


static void create_identity( void )
{
    oskit_identity_t id;

    id.uid = 0 ;
    id.gid = 0 ;
    id.ngroups = 0 ;
    id.groups = 0 ;

    if ( oskit_principal_create( &id, &cur_principal ) )
        panic( "Process identity creation failed.\n" ) ;
}



/* Quick writen shell */    
static void read_command( void )
{    
    char buffer[256] ;
    const char * prompt = "> " ;
    
    int pos = 0 ;
    int i, valid = 0, noquit = 1 ;


    /* Current directory  = for ls */
    DIR * dir ;
    
    struct dirent * file ;
    int infoflag = 0 ;

    /* for lstat in ls */

    struct stat filestat ;
    char filetype ;
    int err ;


    while( noquit ) {

        pos = 0 ;
        valid = 0 ;
        printf( "%s", prompt ) ;
    
        while ( ! valid ) {
            char c = getchar() ;

            switch ( c ) {

                case -1 :     /* nothing */
                    break ;

                case '\b' :   /* Backspace */
                    if ( pos ) pos-- ;
                    break ;

                case '\n' :
                    buffer[pos] = 0 ;
                    valid++ ;
                    break ;

                case '\t' :
                    for ( i = 0 ; i < 8 ; i++ )
                        buffer[pos++] = ' ' ;
                    break ;

                default :
                    buffer[pos++] = c ;
            }

            if ( valid ) {
                /* ugly interpreter !  enough to demonstrate */

                if ( strcmp( buffer, "quit" ) == 0 )
                    noquit = 0 ;

                if ( strcmp( buffer, "down1" ) == 0 ) {
                    chdir( "/disk" ) ;
                }

                if ( strcmp( buffer, "down2" ) == 0 ) {
                    chdir( "etc" ) ;
                }

                if ( strcmp( buffer, "up" ) == 0 ) {
                    chdir( ".." ) ;
                }

                if ( strcmp( buffer, "root" ) == 0 ) {
                    chdir( "/" ) ;
                }

                if ( strcmp( buffer, "ls" ) == 0 ) {

                    dir = opendir( "." ) ;

                    file = readdir( dir ) ;

                    while ( file != 0 ) {

                        err = lstat( file->d_name, &filestat ) ;

                        if ( err ) {
                            printf( " Error on '%s' : %s\n",
                                file->d_name, strerror( errno ) ) ;
                            continue ;
                        }

                        filetype = ' ' ;
                        if ( S_ISDIR( filestat.st_mode ) )  filetype = '/' ;
                        if ( S_ISFIFO( filestat.st_mode ) ) filetype = '|' ;
                        if ( S_ISLNK( filestat.st_mode ) )  filetype = '@' ;

                        if ( infoflag )
                            printf( "rw  %4d %s%c\n", (int)filestat.st_size,
                                (char *)file->d_name, (char)filetype ) ;
                        else
                            printf( "%s%c ", file->d_name, filetype ) ;

                        file = readdir( dir ) ;
                    }

                    closedir( dir ) ;
                    
                    printf("\n") ;

                }

            }
        
        }
    }
}





/*  Mount disk ext2 file system
*/

void disk_mount( oskit_fsnamespace_t * fsns )
{
    oskit_error_t err ;
    oskit_filesystem_t * ext2fs ;
    oskit_dir_t * disk_root ;
    oskit_blkio_t * disk, * disk_part ;
    
    char * disk_dir = "/disk" ;
    char * disk_hd = "hda" ;
    int nparts ;

#define MAX_PARTS 10

    struct diskpart table[ MAX_PARTS ] ;
    struct diskpart * part ;


    create_identity() ;

    err = fs_linux_init() ;
    if ( err ) panic( "Cannot initialize Linux fs library.\n" ) ;

    /* Open hda disk */

    err = oskit_linux_block_open( disk_hd, OSKIT_DEV_OPEN_READ, &disk ) ;
    if ( err ) panic( "Cannot open %s. error %d : %s\n", disk_hd, err,
        strerror( err ) ) ;
    
    nparts = diskpart_blkio_get_partition( disk, table, MAX_PARTS ) ;
    
    if ( nparts == 0 )
        panic( "No partion found.\n" ) ;
    
    diskpart_dump( table, 0, 'a' ) ;
    
    /* Mount ext2 partition : hda / s2  ==  hda2 */
    
    part = diskpart_blkio_lookup_bsd_string( table, "s2", disk, &disk_part ) ;
    if ( ! part ) panic( "Unexistant partition.\n" ) ;
    
    err = fs_linux_mount( disk_part,
        OSKIT_FS_RDONLY | OSKIT_FS_NOEXEC | OSKIT_FS_NOSUID | OSKIT_FS_NODEV,
        &ext2fs ) ;

    if ( err ) panic( "Cannot initialize ext2 filesystem.\n" ) ;

    err = mkdir( disk_dir, 0777 ) ;
    if ( err ) panic( "Can't create %s directory.", disk_dir ) ;

    err = oskit_filesystem_getroot( ext2fs, &disk_root ) ;
    if ( err ) panic( "Can't get disk part root directory." ) ;

    err = oskit_fsnamespace_mount( fsns, disk_dir, (oskit_file_t *) disk_root ) ;
    if ( err ) panic( "Can't mount hd file system.\nError %#x\n", err ) ;

    oskit_filesystem_release( ext2fs ) ;

    printf( "done.\n" ) ;
    
    return ;
}


int main( int argc, char * argv[] )
{
    oskit_osenv_mem_t * mem ;
    oskit_osenv_log_t * log;

    oskit_filesystem_t * memfs ;
    oskit_dir_t * mem_root ;
    oskit_fsnamespace_t * fsns ;

    oskit_error_t err ;


/* Beginning of initialization sequence */

    pic_set_irqmask( 0x0 ) ;
    
    oskit_clientos_init() ;

    myosenv = oskit_osenv_create_default() ;

    oskit_register( &oskit_osenv_iid, (void *) myosenv ) ;


    printf( "Initializing device drivers." ) ;

    oskit_dev_init( myosenv ) ;


    /* Init linux devices */

    oskit_linux_init_osenv( myosenv ) ;

    oskit_linux_init_ide() ;
    oskit_linux_init_net() ;

#if 0
    oskit_dump_drivers() ;
#endif

    printf("Probing devices...\n");
    oskit_dev_probe();
    printf("Dumping devices...\n");
    oskit_dump_devices();
    

    log = oskit_create_osenv_log() ;
    assert( log ) ;

    oskit_osenv_lookup( myosenv, &oskit_osenv_mem_iid, (void *) &mem ) ;


    /* Setup a memory filesystem for the linker. */

    printf( "Creating a memory filesystem..." ) ;
    fflush( stdout ) ;

    err = oskit_memfs_init_ex( mem, log, &memfs ) ;
    if ( err ) panic( "Can't create memfs." ) ;

    err = oskit_filesystem_getroot( memfs, &mem_root ) ;
    if ( err ) panic( "Can't get memfs root directory." ) ;

    err = oskit_create_fsnamespace( mem_root, mem_root, &fsns ) ;
    if ( err ) panic( "Can't create fsnamespace." ) ;

    err = oskit_clientos_setfsnamespace( fsns ) ;
    if ( err ) panic( "Can't set fsnamespace." ) ;

    oskit_filesystem_release( memfs ) ;

    printf( "done.\n" ) ;
    
    disk_mount( fsns ) ;
    
    read_command() ;
   
    return 0 ;
}

References: