OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [rc203soc/] [sw/] [uClinux/] [fs/] [ncpfs/] [mmap.c] - Diff between revs 1628 and 1765

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 1628 Rev 1765
/*
/*
 *  mmap.c
 *  mmap.c
 *
 *
 *  Copyright (C) 1995, 1996 by Volker Lendecke
 *  Copyright (C) 1995, 1996 by Volker Lendecke
 *
 *
 */
 */
 
 
/*
/*
 * uClinux revisions for NO_MM
 * uClinux revisions for NO_MM
 * Copyright (C) 1998  Kenneth Albanowski <kjahds@kjahds.com>,
 * Copyright (C) 1998  Kenneth Albanowski <kjahds@kjahds.com>,
 *                     The Silver Hammer Group, Ltd.
 *                     The Silver Hammer Group, Ltd.
 */
 */
 
 
#include <linux/stat.h>
#include <linux/stat.h>
#include <linux/sched.h>
#include <linux/sched.h>
#include <linux/kernel.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/mm.h>
#include <linux/shm.h>
#include <linux/shm.h>
#include <linux/errno.h>
#include <linux/errno.h>
#include <linux/mman.h>
#include <linux/mman.h>
#include <linux/string.h>
#include <linux/string.h>
#include <linux/malloc.h>
#include <linux/malloc.h>
#include <linux/fcntl.h>
#include <linux/fcntl.h>
#include <linux/ncp_fs.h>
#include <linux/ncp_fs.h>
 
 
#include "ncplib_kernel.h"
#include "ncplib_kernel.h"
#include <asm/segment.h>
#include <asm/segment.h>
#include <asm/system.h>
#include <asm/system.h>
 
 
#ifndef NO_MM
#ifndef NO_MM
 
 
static inline int min(int a, int b)
static inline int min(int a, int b)
{
{
        return a<b ? a : b;
        return a<b ? a : b;
}
}
 
 
/*
/*
 * Fill in the supplied page for mmap
 * Fill in the supplied page for mmap
 */
 */
static unsigned long
static unsigned long
ncp_file_mmap_nopage(struct vm_area_struct * area,
ncp_file_mmap_nopage(struct vm_area_struct * area,
                     unsigned long address, int no_share)
                     unsigned long address, int no_share)
{
{
        struct inode * inode = area->vm_inode;
        struct inode * inode = area->vm_inode;
        unsigned long page;
        unsigned long page;
        unsigned int clear;
        unsigned int clear;
        unsigned long tmp;
        unsigned long tmp;
        int bufsize;
        int bufsize;
        int pos;
        int pos;
        unsigned short fs;
        unsigned short fs;
 
 
        page = __get_free_page(GFP_KERNEL);
        page = __get_free_page(GFP_KERNEL);
        if (!page)
        if (!page)
                return page;
                return page;
        address &= PAGE_MASK;
        address &= PAGE_MASK;
        pos = address - area->vm_start + area->vm_offset;
        pos = address - area->vm_start + area->vm_offset;
 
 
        clear = 0;
        clear = 0;
        if (address + PAGE_SIZE > area->vm_end)
        if (address + PAGE_SIZE > area->vm_end)
        {
        {
                clear = address + PAGE_SIZE - area->vm_end;
                clear = address + PAGE_SIZE - area->vm_end;
        }
        }
 
 
        /* what we can read in one go */
        /* what we can read in one go */
        bufsize = NCP_SERVER(inode)->buffer_size;
        bufsize = NCP_SERVER(inode)->buffer_size;
 
 
        fs = get_fs();
        fs = get_fs();
        set_fs(get_ds());
        set_fs(get_ds());
 
 
        if (ncp_make_open(inode, O_RDONLY) < 0)
        if (ncp_make_open(inode, O_RDONLY) < 0)
        {
        {
                clear = PAGE_SIZE;
                clear = PAGE_SIZE;
        }
        }
        else
        else
        {
        {
                int already_read = 0;
                int already_read = 0;
                int count = PAGE_SIZE - clear;
                int count = PAGE_SIZE - clear;
                int to_read;
                int to_read;
 
 
                while (already_read < count)
                while (already_read < count)
                {
                {
                        int read_this_time;
                        int read_this_time;
 
 
                        if ((pos % bufsize) != 0)
                        if ((pos % bufsize) != 0)
                        {
                        {
                                to_read = bufsize - (pos % bufsize);
                                to_read = bufsize - (pos % bufsize);
                        }
                        }
                        else
                        else
                        {
                        {
                                to_read = bufsize;
                                to_read = bufsize;
                        }
                        }
 
 
                        to_read = min(to_read, count - already_read);
                        to_read = min(to_read, count - already_read);
 
 
                        if (ncp_read(NCP_SERVER(inode),
                        if (ncp_read(NCP_SERVER(inode),
                                     NCP_FINFO(inode)->file_handle,
                                     NCP_FINFO(inode)->file_handle,
                                     pos, to_read,
                                     pos, to_read,
                                     (char *)(page + already_read),
                                     (char *)(page + already_read),
                                     &read_this_time) != 0)
                                     &read_this_time) != 0)
                        {
                        {
                               read_this_time = 0;
                               read_this_time = 0;
                        }
                        }
 
 
                        pos += read_this_time;
                        pos += read_this_time;
                        already_read += read_this_time;
                        already_read += read_this_time;
 
 
                        if (read_this_time < to_read)
                        if (read_this_time < to_read)
                        {
                        {
                                break;
                                break;
                        }
                        }
                }
                }
 
 
        }
        }
 
 
        set_fs(fs);
        set_fs(fs);
 
 
        tmp = page + PAGE_SIZE;
        tmp = page + PAGE_SIZE;
        while (clear--) {
        while (clear--) {
                *(char *)--tmp = 0;
                *(char *)--tmp = 0;
        }
        }
        return page;
        return page;
}
}
 
 
struct vm_operations_struct ncp_file_mmap = {
struct vm_operations_struct ncp_file_mmap = {
        NULL,                   /* open */
        NULL,                   /* open */
        NULL,                   /* close */
        NULL,                   /* close */
        NULL,                   /* unmap */
        NULL,                   /* unmap */
        NULL,                   /* protect */
        NULL,                   /* protect */
        NULL,                   /* sync */
        NULL,                   /* sync */
        NULL,                   /* advise */
        NULL,                   /* advise */
        ncp_file_mmap_nopage,   /* nopage */
        ncp_file_mmap_nopage,   /* nopage */
        NULL,                   /* wppage */
        NULL,                   /* wppage */
        NULL,                   /* swapout */
        NULL,                   /* swapout */
        NULL,                   /* swapin */
        NULL,                   /* swapin */
};
};
 
 
 
 
/* This is used for a general mmap of a ncp file */
/* This is used for a general mmap of a ncp file */
int
int
ncp_mmap(struct inode * inode, struct file * file, struct vm_area_struct * vma)
ncp_mmap(struct inode * inode, struct file * file, struct vm_area_struct * vma)
{
{
        DPRINTK("ncp_mmap: called\n");
        DPRINTK("ncp_mmap: called\n");
 
 
        if (!ncp_conn_valid(NCP_SERVER(inode)))
        if (!ncp_conn_valid(NCP_SERVER(inode)))
        {
        {
                return -EIO;
                return -EIO;
        }
        }
 
 
        /* only PAGE_COW or read-only supported now */
        /* only PAGE_COW or read-only supported now */
        if (vma->vm_flags & VM_SHARED)
        if (vma->vm_flags & VM_SHARED)
                return -EINVAL;
                return -EINVAL;
        if (!inode->i_sb || !S_ISREG(inode->i_mode))
        if (!inode->i_sb || !S_ISREG(inode->i_mode))
                return -EACCES;
                return -EACCES;
        if (!IS_RDONLY(inode)) {
        if (!IS_RDONLY(inode)) {
                inode->i_atime = CURRENT_TIME;
                inode->i_atime = CURRENT_TIME;
                inode->i_dirt = 1;
                inode->i_dirt = 1;
        }
        }
 
 
        vma->vm_inode = inode;
        vma->vm_inode = inode;
        inode->i_count++;
        inode->i_count++;
        vma->vm_ops = &ncp_file_mmap;
        vma->vm_ops = &ncp_file_mmap;
        return 0;
        return 0;
}
}
 
 
#else /* !NO_MM */
#else /* !NO_MM */
 
 
int
int
ncp_mmap(struct inode * inode, struct file * file, struct vm_area_struct * vma)
ncp_mmap(struct inode * inode, struct file * file, struct vm_area_struct * vma)
{
{
        return -ENOSYS;
        return -ENOSYS;
}
}
 
 
#endif /* !NO_MM */
#endif /* !NO_MM */
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.