⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 misc.cxx

📁 开放源码实时操作系统源码.
💻 CXX
📖 第 1 页 / 共 2 页
字号:
                    if (len > best_len)
                        best = m, best_len = len;
                }
            }
        }

	// did we find a better match?
	if (best != *mte)
	  *dir = best->root;
    }
    else
    {
        // Otherwise search the mount table.
        for( m = &cyg_mtab[0]; m != &cyg_mtab_end; m++ )
        {
            if( m->name != NULL && m->valid )
            {
                int len = matchlen(*name,m->name);
                if( len > best_len )
                    best = m, best_len = len;
            }
        }

        // No match found, bad path name...
        if( best_len == 0 ) return -1;

	*dir = best->root;
    }

    *name += best_len;
    if( **name == '/' )
        (*name)++;
    *mte = best;

    return 0;
}

//==========================================================================
// mount filesystem

__externC int mount( const char *devname,
                     const char *dir,
                     const char *fsname)
{

    FILEIO_ENTRY();
    
    cyg_mtab_entry *m;
    cyg_fstab_entry *f;
    int result = ENOERR;

    // Search the mount table for an empty entry
    for( m = &cyg_mtab[0]; m != &cyg_mtab_end; m++ )
    {
        // stop if there are more than the configured maximum
        if( m-&cyg_mtab[0] >= CYGNUM_FILEIO_MTAB_MAX )
        {
            m = &cyg_mtab_end;
            break;
        }

         if( m->name == NULL ) break;
    }

    if( m == &cyg_mtab_end )
        FILEIO_RETURN(ENOMEM);

    // Now search the fstab for the filesystem implementation
    for( f = &cyg_fstab[0]; f != &cyg_fstab_end; f++ )
    {
        // stop if there are more than the configured maximum
        if( f-&cyg_fstab[0] >= CYGNUM_FILEIO_FSTAB_MAX )
            break;
            
        if( strcmp( fsname, f->name) == 0 )
            break;
    }

    if( f == &cyg_fstab_end )
        FILEIO_RETURN(ENODEV);
            
    // We have a match.

    m->name = dir;
    m->fsname = fsname;
    m->devname = devname;
    
    if( (result = f->mount( f, m )) == 0 )
    {
        m->valid    = true;
        m->fs       = f;
        // m->root installed by fs.
    }
    else
    {
        m->valid = false;
        m->name = NULL;
    }

    // Make sure that there is something to search (for open)

    if (cyg_cdir_mtab_entry == (cyg_mtab_entry *)NULL) {
        cyg_cdir_mtab_entry = m;
    }

    FILEIO_RETURN(result);
}

//==========================================================================
// unmount filesystem

__externC int umount( const char *name)
{
    int err = ENOERR;
    
    FILEIO_ENTRY();
    
    cyg_mtab_entry *m;

    // Search the mount table for a matching entry
    for( m = &cyg_mtab[0]; m != &cyg_mtab_end; m++ )
    {
        // stop if there are more than the configured maximum
        if( m-&cyg_mtab[0] >= CYGNUM_FILEIO_MTAB_MAX )
        {
            m = &cyg_mtab_end;
            break;
        }

        // Ignore empty or invalid entries
         if( m->name == NULL || !m->valid ) continue;

         // match names.
         if( strcmp(name,m->name) == 0 ) break;

         // Match device name too?
    }

    if( m == &cyg_mtab_end )
        FILEIO_RETURN(EINVAL);

    // We have a match, call the umount function

    err = m->fs->umount( m );

    if( err == ENOERR )
    {
        m->valid        = false;
        m->name         = NULL;
    }
    
    FILEIO_RETURN(err);
}

//==========================================================================
// Implement filesystem locking protocol. 

void cyg_fs_lock( cyg_mtab_entry *mte, cyg_uint32 syncmode )
{
    CYG_ASSERT(mte != NULL, "Bad mount table entry");

    if( syncmode & CYG_SYNCMODE_FILE_FILESYSTEM ) {
        CYG_ASSERT(mte->fs-&cyg_fstab[0] < CYGNUM_FILEIO_FSTAB_MAX, "Bad file system");
        FILEIO_MUTEX_LOCK( fstab_lock[mte->fs-&cyg_fstab[0]] );
    }

    if( syncmode & CYG_SYNCMODE_FILE_MOUNTPOINT ) {
        CYG_ASSERT(mte-&cyg_mtab[0] < CYGNUM_FILEIO_MTAB_MAX, "Bad mount point");
        FILEIO_MUTEX_LOCK( mtab_lock[mte-&cyg_mtab[0]] );
    }
}

void cyg_fs_unlock( cyg_mtab_entry *mte, cyg_uint32 syncmode )
{
    CYG_ASSERT(mte != NULL, "Bad mount table entry");

    if( syncmode & CYG_SYNCMODE_FILE_FILESYSTEM ) {
        CYG_ASSERT(mte->fs-&cyg_fstab[0] < CYGNUM_FILEIO_FSTAB_MAX, "Bad file system");
        FILEIO_MUTEX_UNLOCK( fstab_lock[mte->fs-&cyg_fstab[0]] );
    }

    if( syncmode & CYG_SYNCMODE_FILE_MOUNTPOINT ) {
        CYG_ASSERT(mte-&cyg_mtab[0] < CYGNUM_FILEIO_MTAB_MAX, "Bad mount point");
        FILEIO_MUTEX_UNLOCK( mtab_lock[mte-&cyg_mtab[0]] );
    }
}

//==========================================================================
// Search mount table for a filesystems root. 

__externC cyg_mtab_entry * cyg_fs_root_lookup( cyg_dir *root ) 
{
     cyg_mtab_entry *m;

     for( m = &cyg_mtab[0]; m != &cyg_mtab_end; m++ ) 
     {
          if( (cyg_dir *)m->root == root )
          {
               return m;
          }
     }
     return NULL;
}

//==========================================================================
// Timestamp support
// This provides access to the current time/date, expressed as a
// time_t.  It uses a number of mechanisms to do this, selecting
// whichever is available in the current configuration.

__externC time_t cyg_timestamp()
{
#if defined(CYGPKG_IO_WALLCLOCK)

    // First, try to get the time from the wallclock device.
    
    return (time_t) Cyg_WallClock::wallclock->get_current_time();

#elif defined(CYGINT_ISO_POSIX_TIMERS)

    // If POSIX is present, use the current value of the realtime
    // clock.
    
    struct timespec tp;

    clock_gettime( CLOCK_REALTIME, &tp );

    return (time_t) tp.tv_sec;
    
#elif defined(CYGPKG_KERNEL) 

    // If all else fails, get the current realtime clock value and
    // convert it to seconds ourself.
    
    static struct Cyg_Clock::converter sec_converter;
    static cyg_bool initialized = false;
    cyg_tick_count ticks;
    
    if( !initialized )
    {
        Cyg_Clock::real_time_clock->get_clock_to_other_converter( 1000000000, &sec_converter );
        initialized = true;
    }

    ticks = Cyg_Clock::real_time_clock->current_value();
    
    return (time_t) Cyg_Clock::convert( ticks, &sec_converter );
#else    
    /* No clock support at all. */
    return (time_t) 0;
#endif    
    
}

//==========================================================================
// Default functions

__externC int cyg_fileio_enosys() { return ENOSYS; }
__externC int cyg_fileio_erofs() { return EROFS; }
__externC int cyg_fileio_enoerr() { return ENOERR; }
__externC int cyg_fileio_enotdir() { return ENOTDIR; }

__externC cyg_bool cyg_fileio_seltrue (struct CYG_FILE_TAG *fp, int which, CYG_ADDRWORD info)
{ return 1; }

// -------------------------------------------------------------------------
// EOF misc.cxx

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -