/*
|
/*
|
* mmap.c
|
* mmap.c
|
*
|
*
|
* Copyright (C) 1995, 1996 by Paal-Kr. Engstad and Volker Lendecke
|
* Copyright (C) 1995, 1996 by Paal-Kr. Engstad and 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/smb_fs.h>
|
#include <linux/smb_fs.h>
|
#include <linux/fcntl.h>
|
#include <linux/fcntl.h>
|
|
|
#include <asm/segment.h>
|
#include <asm/segment.h>
|
#include <asm/system.h>
|
#include <asm/system.h>
|
|
|
#ifndef NO_MM
|
#ifndef NO_MM
|
|
|
/*
|
/*
|
* Fill in the supplied page for mmap
|
* Fill in the supplied page for mmap
|
*/
|
*/
|
static unsigned long
|
static unsigned long
|
smb_file_mmap_nopage(struct vm_area_struct *area,
|
smb_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 n;
|
int n;
|
int i;
|
int i;
|
int pos;
|
int pos;
|
|
|
page = __get_free_page(GFP_KERNEL);
|
page = __get_free_page(GFP_KERNEL);
|
if (!page)
|
if (!page)
|
return 0;
|
return 0;
|
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 */
|
n = SMB_SERVER(inode)->max_xmit - SMB_HEADER_LEN - 5 * 2 - 3 - 10;
|
n = SMB_SERVER(inode)->max_xmit - SMB_HEADER_LEN - 5 * 2 - 3 - 10;
|
|
|
if (smb_make_open(inode, O_RDONLY) < 0)
|
if (smb_make_open(inode, O_RDONLY) < 0)
|
{
|
{
|
clear = PAGE_SIZE;
|
clear = PAGE_SIZE;
|
} else
|
} else
|
{
|
{
|
|
|
for (i = 0; i < (PAGE_SIZE - clear); i += n)
|
for (i = 0; i < (PAGE_SIZE - clear); i += n)
|
{
|
{
|
int hunk, result;
|
int hunk, result;
|
|
|
hunk = PAGE_SIZE - i;
|
hunk = PAGE_SIZE - i;
|
if (hunk > n)
|
if (hunk > n)
|
hunk = n;
|
hunk = n;
|
|
|
DDPRINTK("smb_file_mmap_nopage: reading\n");
|
DDPRINTK("smb_file_mmap_nopage: reading\n");
|
DDPRINTK("smb_file_mmap_nopage: pos = %d\n", pos);
|
DDPRINTK("smb_file_mmap_nopage: pos = %d\n", pos);
|
result = smb_proc_read(SMB_SERVER(inode),
|
result = smb_proc_read(SMB_SERVER(inode),
|
SMB_FINFO(inode), pos, hunk,
|
SMB_FINFO(inode), pos, hunk,
|
(char *) (page + i), 0);
|
(char *) (page + i), 0);
|
DDPRINTK("smb_file_mmap_nopage: result= %d\n", result);
|
DDPRINTK("smb_file_mmap_nopage: result= %d\n", result);
|
if (result < 0)
|
if (result < 0)
|
break;
|
break;
|
pos += result;
|
pos += result;
|
if (result < n)
|
if (result < n)
|
{
|
{
|
i += result;
|
i += result;
|
break;
|
break;
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
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 smb_file_mmap =
|
struct vm_operations_struct smb_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 */
|
smb_file_mmap_nopage, /* nopage */
|
smb_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 smb file */
|
/* This is used for a general mmap of a smb file */
|
int
|
int
|
smb_mmap(struct inode *inode, struct file *file, struct vm_area_struct *vma)
|
smb_mmap(struct inode *inode, struct file *file, struct vm_area_struct *vma)
|
{
|
{
|
DPRINTK("smb_mmap: called\n");
|
DPRINTK("smb_mmap: called\n");
|
|
|
/* 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 = &smb_file_mmap;
|
vma->vm_ops = &smb_file_mmap;
|
return 0;
|
return 0;
|
}
|
}
|
|
|
#else /* NO_MM */
|
#else /* NO_MM */
|
|
|
int
|
int
|
smb_mmap(struct inode *inode, struct file *file, struct vm_area_struct *vma)\
|
smb_mmap(struct inode *inode, struct file *file, struct vm_area_struct *vma)\
|
{
|
{
|
return -ENOSYS;
|
return -ENOSYS;
|
}
|
}
|
|
|
#endif /* NO_MM */
|
#endif /* NO_MM */
|
|
|