diff -urN ref/arch/i386/kernel/entry.S lfs/arch/i386/kernel/entry.S --- ref/arch/i386/kernel/entry.S Sat Apr 8 19:56:02 2000 +++ lfs/arch/i386/kernel/entry.S Sat Apr 8 19:56:12 2000 @@ -564,6 +564,14 @@ .long SYMBOL_NAME(sys_ni_syscall) /* streams1 */ .long SYMBOL_NAME(sys_ni_syscall) /* streams2 */ .long SYMBOL_NAME(sys_vfork) /* 190 */ + .long SYMBOL_NAME(sys_ni_syscall) + .long SYMBOL_NAME(sys_mmap2) + .long SYMBOL_NAME(sys_truncate64) + .long SYMBOL_NAME(sys_ftruncate64) + .long SYMBOL_NAME(sys_stat64) /* 195 */ + .long SYMBOL_NAME(sys_lstat64) + .long SYMBOL_NAME(sys_fstat64) + /* * NOTE!! This doesn't have to be exact - we just have @@ -571,6 +579,6 @@ * entries. Don't panic if you notice that this hasn't * been shrunk every time we add a new system call. */ - .rept NR_syscalls-190 + .rept NR_syscalls-197 .long SYMBOL_NAME(sys_ni_syscall) .endr diff -urN ref/arch/i386/kernel/sys_i386.c lfs/arch/i386/kernel/sys_i386.c --- ref/arch/i386/kernel/sys_i386.c Sat Apr 8 19:56:02 2000 +++ lfs/arch/i386/kernel/sys_i386.c Sat Apr 8 19:56:12 2000 @@ -41,6 +41,43 @@ return error; } +/* common code for old and new mmaps */ +static inline long do_mmap2( + unsigned long addr, unsigned long len, + unsigned long prot, unsigned long flags, + unsigned long fd, unsigned long pgoff) +{ + int error = -EBADF; + struct file * file = NULL; + + flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); + if (!(flags & MAP_ANONYMOUS)) { + file = fget(fd); + if (!file) + goto out; + } + + down(¤t->mm->mmap_sem); + lock_kernel(); + + error = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); + + unlock_kernel(); + up(¤t->mm->mmap_sem); + + if (file) + fput(file); +out: + return error; +} + +asmlinkage long sys_mmap2(unsigned long addr, unsigned long len, + unsigned long prot, unsigned long flags, + unsigned long fd, unsigned long pgoff) +{ + return do_mmap2(addr, len, prot, flags, fd, pgoff); +} + /* * Perform the select(nd, in, out, ex, tv) and mmap() system * calls. Linux/i386 didn't use to be able to handle more than @@ -59,30 +96,19 @@ asmlinkage int old_mmap(struct mmap_arg_struct *arg) { - int error = -EFAULT; - struct file * file = NULL; struct mmap_arg_struct a; + int err = -EFAULT; if (copy_from_user(&a, arg, sizeof(a))) - return -EFAULT; + goto out; - down(¤t->mm->mmap_sem); - lock_kernel(); - if (!(a.flags & MAP_ANONYMOUS)) { - error = -EBADF; - file = fget(a.fd); - if (!file) - goto out; - } - a.flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); + err = -EINVAL; + if (a.offset & ~PAGE_MASK) + goto out; - error = do_mmap(file, a.addr, a.len, a.prot, a.flags, a.offset); - if (file) - fput(file); + err = do_mmap2(a.addr, a.len, a.prot, a.flags, a.fd, a.offset >> PAGE_SHIFT); out: - unlock_kernel(); - up(¤t->mm->mmap_sem); - return error; + return err; } extern asmlinkage int sys_select(int, fd_set *, fd_set *, fd_set *, struct timeval *); diff -urN ref/arch/sparc/kernel/sys_sparc.c lfs/arch/sparc/kernel/sys_sparc.c --- ref/arch/sparc/kernel/sys_sparc.c Sat Apr 8 19:56:02 2000 +++ lfs/arch/sparc/kernel/sys_sparc.c Sat Apr 8 19:56:12 2000 @@ -176,9 +176,9 @@ } /* Linux version of mmap */ -asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len, +asmlinkage unsigned long do_mmap2(unsigned long addr, unsigned long len, unsigned long prot, unsigned long flags, unsigned long fd, - unsigned long off) + unsigned long pgoff) { struct file * file = NULL; unsigned long retval = -EBADF; @@ -211,7 +211,7 @@ goto out_putf; flags &= ~(MAP_EXECUTABLE | MAP_DENYWRITE); - retval = do_mmap(file, addr, len, prot, flags, off); + retval = do_mmap_pgoff(file, addr, len, prot, flags, pgoff); out_putf: if (file) @@ -220,6 +220,22 @@ unlock_kernel(); up(¤t->mm->mmap_sem); return retval; +} + +asmlinkage unsigned long sys_mmap2(unsigned long addr, unsigned long len, + unsigned long prot, unsigned long flags, unsigned long fd, + unsigned long pgoff) +{ + /* Make sure the shift for mmap2 is constant (12), no matter what PAGE_SIZE + we have. */ + return do_mmap2(addr, len, prot, flags, fd, pgoff >> (PAGE_SHIFT - 12)); +} + +asmlinkage unsigned long sys_mmap(unsigned long addr, unsigned long len, + unsigned long prot, unsigned long flags, unsigned long fd, + unsigned long off) +{ + return do_mmap2(addr, len, prot, flags, fd, off >> PAGE_SHIFT); } /* we come to here via sys_nis_syscall so it can setup the regs argument */ diff -urN ref/arch/sparc/kernel/systbls.S lfs/arch/sparc/kernel/systbls.S --- ref/arch/sparc/kernel/systbls.S Sat Apr 8 19:56:02 2000 +++ lfs/arch/sparc/kernel/systbls.S Sat Apr 8 19:56:12 2000 @@ -29,12 +29,12 @@ /*40*/ .long sys_newlstat, sys_dup, sys_pipe, sys_times, sys_nis_syscall /*45*/ .long sys_umount, sys_setgid, sys_getgid, sys_signal, sys_geteuid /*50*/ .long sys_getegid, sys_acct, sys_nis_syscall, sys_nis_syscall, sys_ioctl -/*55*/ .long sys_reboot, sys_lfs_syscall, sys_symlink, sys_readlink, sys_execve -/*60*/ .long sys_umask, sys_chroot, sys_newfstat, sys_lfs_syscall, sys_getpagesize +/*55*/ .long sys_reboot, sys_mmap2, sys_symlink, sys_readlink, sys_execve +/*60*/ .long sys_umask, sys_chroot, sys_newfstat, sys_fstat64, sys_getpagesize /*65*/ .long sys_msync, sys_vfork, sys_pread, sys_pwrite, sys_nis_syscall /*70*/ .long sys_nis_syscall, sys_mmap, sys_nis_syscall, sys_munmap, sys_mprotect -/*75*/ .long sys_nis_syscall, sys_vhangup, sys_lfs_syscall, sys_nis_syscall, sys_getgroups -/*80*/ .long sys_setgroups, sys_getpgrp, sys_nis_syscall, sys_setitimer, sys_lfs_syscall +/*75*/ .long sys_nis_syscall, sys_vhangup, sys_truncate64, sys_nis_syscall, sys_getgroups +/*80*/ .long sys_setgroups, sys_getpgrp, sys_nis_syscall, sys_setitimer, sys_ftruncate64 /*85*/ .long sys_swapon, sys_getitimer, sys_nis_syscall, sys_sethostname, sys_nis_syscall /*90*/ .long sys_dup2, sys_nis_syscall, sys_fcntl, sys_select, sys_nis_syscall /*95*/ .long sys_fsync, sys_setpriority, sys_nis_syscall, sys_nis_syscall, sys_nis_syscall @@ -44,8 +44,8 @@ /*115*/ .long sys_nis_syscall, sys_gettimeofday, sys_getrusage, sys_nis_syscall, sys_getcwd /*120*/ .long sys_readv, sys_writev, sys_settimeofday, sys_fchown, sys_fchmod /*125*/ .long sys_nis_syscall, sys_setreuid, sys_setregid, sys_rename, sys_truncate -/*130*/ .long sys_ftruncate, sys_flock, sys_lfs_syscall, sys_nis_syscall, sys_nis_syscall -/*135*/ .long sys_nis_syscall, sys_mkdir, sys_rmdir, sys_utimes, sys_lfs_syscall +/*130*/ .long sys_ftruncate, sys_flock, sys_lstat64, sys_nis_syscall, sys_nis_syscall +/*135*/ .long sys_nis_syscall, sys_mkdir, sys_rmdir, sys_utimes, sys_stat64 /*140*/ .long sys_nis_syscall, sys_nis_syscall, sys_nis_syscall, sys_nis_syscall, sys_getrlimit /*145*/ .long sys_setrlimit, sys_nis_syscall, sys_prctl, sys_pciconfig_read, sys_pciconfig_write /*150*/ .long sys_nis_syscall, sys_nis_syscall, sys_nis_syscall, sys_poll, sys_nis_syscall diff -urN ref/arch/sparc64/kernel/sparc64_ksyms.c lfs/arch/sparc64/kernel/sparc64_ksyms.c --- ref/arch/sparc64/kernel/sparc64_ksyms.c Sat Apr 8 19:56:02 2000 +++ lfs/arch/sparc64/kernel/sparc64_ksyms.c Sat Apr 8 19:56:12 2000 @@ -81,6 +81,7 @@ extern int sys_ioctl(unsigned int fd, unsigned int cmd, unsigned long arg); extern int sys32_ioctl(unsigned int fd, unsigned int cmd, u32 arg); extern int (*handle_mathemu)(struct pt_regs *, struct fpustate *); +extern long sparc32_open(const char * filename, int flags, int mode); extern void bcopy (const char *, char *, int); extern int __ashrdi3(int, int); @@ -267,6 +268,7 @@ EXPORT_SYMBOL(prom_cpu_nodes); EXPORT_SYMBOL(sys_ioctl); EXPORT_SYMBOL(sys32_ioctl); +EXPORT_SYMBOL(sparc32_open); EXPORT_SYMBOL(move_addr_to_kernel); EXPORT_SYMBOL(move_addr_to_user); #endif diff -urN ref/arch/sparc64/kernel/sys32.S lfs/arch/sparc64/kernel/sys32.S --- ref/arch/sparc64/kernel/sys32.S Sat Apr 8 19:56:02 2000 +++ lfs/arch/sparc64/kernel/sys32.S Sat Apr 8 19:56:12 2000 @@ -60,3 +60,12 @@ sethi %hi(sys_bdflush), %g1 jmpl %g1 + %lo(sys_bdflush), %g0 sra %o1, 0, %o1 + + .align 32 + .globl sys32_mmap2 +sys32_mmap2: + srl %o4, 0, %o4 + sethi %hi(sys_mmap), %g1 + srl %o5, 0, %o5 + jmpl %g1 + %lo(sys_mmap), %g0 + sllx %o5, 12, %o5 diff -urN ref/arch/sparc64/kernel/sys_sparc32.c lfs/arch/sparc64/kernel/sys_sparc32.c --- ref/arch/sparc64/kernel/sys_sparc32.c Sat Apr 8 19:56:02 2000 +++ lfs/arch/sparc64/kernel/sys_sparc32.c Sat Apr 8 19:56:12 2000 @@ -579,6 +579,30 @@ return err; } +static inline int get_flock64(struct flock *kfl, struct flock32_64 *ufl) +{ + int err; + + err = get_user(kfl->l_type, &ufl->l_type); + err |= __get_user(kfl->l_whence, &ufl->l_whence); + err |= __get_user(kfl->l_start, &ufl->l_start); + err |= __get_user(kfl->l_len, &ufl->l_len); + err |= __get_user(kfl->l_pid, &ufl->l_pid); + return err; +} + +static inline int put_flock64(struct flock *kfl, struct flock32_64 *ufl) +{ + int err; + + err = __put_user(kfl->l_type, &ufl->l_type); + err |= __put_user(kfl->l_whence, &ufl->l_whence); + err |= __put_user(kfl->l_start, &ufl->l_start); + err |= __put_user(kfl->l_len, &ufl->l_len); + err |= __put_user(kfl->l_pid, &ufl->l_pid); + return err; +} + extern asmlinkage long sys_fcntl(unsigned int fd, unsigned int cmd, unsigned long arg); asmlinkage long sys32_fcntl(unsigned int fd, unsigned int cmd, unsigned long arg) @@ -597,10 +621,31 @@ old_fs = get_fs(); set_fs (KERNEL_DS); ret = sys_fcntl(fd, cmd, (unsigned long)&f); set_fs (old_fs); + if (f.l_start >= 0x7fffffffUL || + f.l_len >= 0x7fffffffUL || + f.l_start + f.l_len >= 0x7fffffffUL) + return -EOVERFLOW; if(put_flock(&f, (struct flock32 *)arg)) return -EFAULT; return ret; } + case F_GETLK64: + case F_SETLK64: + case F_SETLKW64: + { + struct flock f; + mm_segment_t old_fs; + long ret; + + if(get_flock64(&f, (struct flock32_64 *)arg)) + return -EFAULT; + old_fs = get_fs(); set_fs (KERNEL_DS); + ret = sys_fcntl(fd, cmd + F_GETLK - F_GETLK64, (unsigned long)&f); + set_fs (old_fs); + if(put_flock64(&f, (struct flock32_64 *)arg)) + return -EFAULT; + return ret; + } default: return sys_fcntl(fd, cmd, (unsigned long)arg); } @@ -717,6 +762,25 @@ return ret; } +extern asmlinkage long sys_truncate(const char * path, unsigned long length); +extern asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length); + +asmlinkage int sys32_truncate64(const char * path, unsigned long high, unsigned long low) +{ + if ((int)high < 0) + return -EINVAL; + else + return sys_truncate(path, (high << 32) | low); +} + +asmlinkage int sys32_ftruncate64(unsigned int fd, unsigned long high, unsigned long low) +{ + if ((int)high < 0) + return -EINVAL; + else + return sys_ftruncate(fd, (high << 32) | low); +} + extern asmlinkage int sys_utime(char * filename, struct utimbuf * times); struct utimbuf32 { @@ -4018,4 +4082,37 @@ ret = -EFAULT; return ret; +} + +/* This is just a version for 32-bit applications which does + * not force O_LARGEFILE on. + */ + +asmlinkage long sparc32_open(const char * filename, int flags, int mode) +{ + char * tmp; + int fd, error; + + tmp = getname(filename); + fd = PTR_ERR(tmp); + if (!IS_ERR(tmp)) { + lock_kernel(); + fd = get_unused_fd(); + if (fd >= 0) { + struct file * f = filp_open(tmp, flags, mode); + error = PTR_ERR(f); + if (IS_ERR(f)) + goto out_error; + fd_install(fd, f); + } +out: + unlock_kernel(); + putname(tmp); + } + return fd; + +out_error: + put_unused_fd(fd); + fd = error; + goto out; } diff -urN ref/arch/sparc64/kernel/sys_sunos32.c lfs/arch/sparc64/kernel/sys_sunos32.c --- ref/arch/sparc64/kernel/sys_sunos32.c Sat Apr 8 19:56:02 2000 +++ lfs/arch/sparc64/kernel/sys_sunos32.c Sat Apr 8 19:56:12 2000 @@ -1296,13 +1296,15 @@ return rval; } +extern asmlinkage long sparc32_open(const char * filename, int flags, int mode); + asmlinkage int sunos_open(u32 filename, int flags, int mode) { int ret; lock_kernel(); current->personality |= PER_BSD; - ret = sys_open ((char *)A(filename), flags, mode); + ret = sparc32_open ((char *)A(filename), flags, mode); unlock_kernel(); return ret; } diff -urN ref/arch/sparc64/kernel/systbls.S lfs/arch/sparc64/kernel/systbls.S --- ref/arch/sparc64/kernel/systbls.S Sat Apr 8 19:56:02 2000 +++ lfs/arch/sparc64/kernel/systbls.S Sat Apr 8 19:56:12 2000 @@ -20,7 +20,7 @@ .globl sys_call_table32 sys_call_table32: /*0*/ .word sys_nis_syscall, sparc_exit, sys_fork, sys_read, sys_write -/*5*/ .word sys_open, sys_close, sys32_wait4, sys_creat, sys_link +/*5*/ .word sparc32_open, sys_close, sys32_wait4, sys_creat, sys_link /*10*/ .word sys_unlink, sunos_execv, sys_chdir, sys32_chown16, sys32_mknod /*15*/ .word sys32_chmod, sys32_lchown16, sparc_brk, sys_perfctr, sys32_lseek /*20*/ .word sys_getpid, sys_capget, sys_capset, sys_setuid, sys_getuid @@ -30,12 +30,12 @@ /*40*/ .word sys32_newlstat, sys_dup, sys_pipe, sys32_times, sys_nis_syscall .word sys_umount, sys_setgid, sys_getgid, sys_signal, sys_geteuid /*50*/ .word sys_getegid, sys_acct, sys_nis_syscall, sys_nis_syscall, sys32_ioctl - .word sys_reboot, sys_lfs_syscall, sys_symlink, sys_readlink, sys32_execve -/*60*/ .word sys_umask, sys_chroot, sys32_newfstat, sys_lfs_syscall, sys_getpagesize + .word sys_reboot, sys32_mmap2, sys_symlink, sys_readlink, sys32_execve +/*60*/ .word sys_umask, sys_chroot, sys32_newfstat, sys_fstat64, sys_getpagesize .word sys_msync, sys_vfork, sys32_pread, sys32_pwrite, sys_nis_syscall /*70*/ .word sys_nis_syscall, sys32_mmap, sys_nis_syscall, sys_munmap, sys_mprotect - .word sys_nis_syscall, sys_vhangup, sys_lfs_syscall, sys_nis_syscall, sys32_getgroups -/*80*/ .word sys32_setgroups, sys_getpgrp, sys_nis_syscall, sys32_setitimer, sys_lfs_syscall + .word sys_nis_syscall, sys_vhangup, sys32_truncate64, sys_nis_syscall, sys32_getgroups +/*80*/ .word sys32_setgroups, sys_getpgrp, sys_nis_syscall, sys32_setitimer, sys32_ftruncate64 .word sys_swapon, sys32_getitimer, sys_nis_syscall, sys_sethostname, sys_nis_syscall /*90*/ .word sys_dup2, sys_nis_syscall, sys32_fcntl, sys32_select, sys_nis_syscall .word sys_fsync, sys_setpriority, sys_nis_syscall, sys_nis_syscall, sys_nis_syscall @@ -45,8 +45,8 @@ .word sys_nis_syscall, sys32_gettimeofday, sys32_getrusage, sys_nis_syscall, sys_getcwd /*120*/ .word sys32_readv, sys32_writev, sys32_settimeofday, sys32_fchown16, sys_fchmod .word sys_nis_syscall, sys32_setreuid, sys32_setregid, sys_rename, sys_truncate -/*130*/ .word sys_ftruncate, sys_flock, sys_lfs_syscall, sys_nis_syscall, sys_nis_syscall - .word sys_nis_syscall, sys_mkdir, sys_rmdir, sys32_utimes, sys_lfs_syscall +/*130*/ .word sys_ftruncate, sys_flock, sys_lstat64, sys_nis_syscall, sys_nis_syscall + .word sys_nis_syscall, sys_mkdir, sys_rmdir, sys32_utimes, sys_stat64 /*140*/ .word sys_nis_syscall, sys_nis_syscall, sys_nis_syscall, sys_nis_syscall, sys32_getrlimit .word sys32_setrlimit, sys_nis_syscall, sys32_prctl, sys32_pciconfig_read, sys32_pciconfig_write /*150*/ .word sys_nis_syscall, sys_nis_syscall, sys_nis_syscall, sys_poll, sys_nis_syscall @@ -114,15 +114,15 @@ .word sys_quotactl, sys_nis_syscall, sys_mount, sys_ustat, sys_nis_syscall /*170*/ .word sys_nis_syscall, sys_nis_syscall, sys_nis_syscall, sys_nis_syscall, sys_getdents .word sys_setsid, sys_fchdir, sys_nis_syscall, sys_nis_syscall, sys_nis_syscall -/*180*/ .word sys_nis_syscall, sys_nis_syscall, sys_nis_syscall, sys_sigpending, sys_query_module +/*180*/ .word sys_nis_syscall, sys_nis_syscall, sys_nis_syscall, sys_nis_syscall, sys_query_module .word sys_setpgid, sys_nis_syscall, sys_nis_syscall, sys_nis_syscall, sys_newuname /*190*/ .word sys_init_module, sys_personality, sys_nis_syscall, sys_nis_syscall, sys_nis_syscall - .word sys_nis_syscall, sys_nis_syscall, sys_getppid, sys_sigaction, sys_sgetmask -/*200*/ .word sys_ssetmask, sys_sigsuspend, sys_newlstat, sys_uselib, sys_nis_syscall + .word sys_nis_syscall, sys_nis_syscall, sys_getppid, sys_nis_syscall, sys_sgetmask +/*200*/ .word sys_ssetmask, sys_nis_syscall, sys_newlstat, sys_uselib, sys_nis_syscall .word sys_nis_syscall, sys_socketcall, sys_syslog, sys_nis_syscall, sys_nis_syscall /*210*/ .word sys_idle, sys_nis_syscall, sys_waitpid, sys_swapoff, sys_sysinfo - .word sys_ipc, sys_sigreturn, sys_clone, sys_nis_syscall, sys_adjtimex -/*220*/ .word sys_sigprocmask, sys_create_module, sys_delete_module, sys_get_kernel_syms, sys_getpgid + .word sys_ipc, sys_nis_syscall, sys_clone, sys_nis_syscall, sys_adjtimex +/*220*/ .word sys_nis_syscall, sys_create_module, sys_delete_module, sys_get_kernel_syms, sys_getpgid .word sys_bdflush, sys_sysfs, sys_nis_syscall, sys_setfsuid, sys_setfsgid /*230*/ .word sys_select, sys_time, sys_nis_syscall, sys_stime, sys_nis_syscall .word sys_nis_syscall, sys_llseek, sys_mlock, sys_munlock, sys_mlockall diff -urN ref/arch/sparc64/solaris/fs.c lfs/arch/sparc64/solaris/fs.c --- ref/arch/sparc64/solaris/fs.c Sat Apr 8 19:56:02 2000 +++ lfs/arch/sparc64/solaris/fs.c Sat Apr 8 19:56:12 2000 @@ -572,20 +572,20 @@ return error; } +extern asmlinkage long sparc32_open(const char * filename, int flags, int mode); + asmlinkage int solaris_open(u32 filename, int flags, u32 mode) { - int (*sys_open)(const char *,int,int) = - (int (*)(const char *,int,int))SYS(open); int fl = flags & 0xf; -/* if (flags & 0x2000) - allow LFS */ + if (flags & 0x2000) fl |= O_LARGEFILE; if (flags & 0x8050) fl |= O_SYNC; if (flags & 0x80) fl |= O_NONBLOCK; if (flags & 0x100) fl |= O_CREAT; if (flags & 0x200) fl |= O_TRUNC; if (flags & 0x400) fl |= O_EXCL; if (flags & 0x800) fl |= O_NOCTTY; - return sys_open((const char *)A(filename), fl, mode); + return sparc32_open((const char *)A(filename), fl, mode); } #define SOL_F_SETLK 6 diff -urN ref/drivers/block/loop.c lfs/drivers/block/loop.c --- ref/drivers/block/loop.c Sat Apr 8 19:56:02 2000 +++ lfs/drivers/block/loop.c Sat Apr 8 19:56:12 2000 @@ -143,12 +143,12 @@ int size; if (S_ISREG(lo->lo_dentry->d_inode->i_mode)) - size = (lo->lo_dentry->d_inode->i_size - lo->lo_offset) / BLOCK_SIZE; + size = (lo->lo_dentry->d_inode->i_size - lo->lo_offset) >> BLOCK_SIZE_BITS; else { kdev_t lodev = lo->lo_device; if (blk_size[MAJOR(lodev)]) size = blk_size[MAJOR(lodev)][MINOR(lodev)] - - lo->lo_offset / BLOCK_SIZE; + (lo->lo_offset >> BLOCK_SIZE_BITS); else size = MAX_DISK_SIZE; } diff -urN ref/fs/adfs/inode.c lfs/fs/adfs/inode.c --- ref/fs/adfs/inode.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/adfs/inode.c Sat Apr 8 19:56:12 2000 @@ -181,7 +181,7 @@ inode->i_nlink = 2; inode->i_size = ADFS_NEWDIR_SIZE; inode->i_blksize = PAGE_SIZE; - inode->i_blocks = inode->i_size / sb->s_blocksize; + inode->i_blocks = inode->i_size >> sb->s_blocksize_bits; inode->i_mtime = inode->i_atime = inode->i_ctime = 0; diff -urN ref/fs/affs/file.c lfs/fs/affs/file.c --- ref/fs/affs/file.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/affs/file.c Sat Apr 8 19:56:12 2000 @@ -580,17 +580,17 @@ affs_file_write(struct file *filp, const char *buf, size_t count, loff_t *ppos) { struct inode *inode = filp->f_dentry->d_inode; - off_t pos; + loff_t pos; ssize_t written; ssize_t c; - ssize_t blocksize; + ssize_t blocksize, blockshift; struct buffer_head *bh; char *p; if (!count) return 0; - pr_debug("AFFS: file_write(ino=%lu,pos=%lu,count=%d)\n",inode->i_ino, - (unsigned long)*ppos,count); + pr_debug("AFFS: file_write(ino=%lu,pos=%Lu,count=%d)\n",inode->i_ino, + *ppos,count); if (!inode) { affs_error(inode->i_sb,"file_write","Inode = NULL"); @@ -609,16 +609,22 @@ else pos = *ppos; written = 0; - blocksize = AFFS_I2BSIZE(inode); + blocksize = AFFS_I2BSIZE(inode); + blockshift = AFFS_I2BITS(inode); + + if (pos >= 0x7fffffff) /* Max size: 2G-1 */ + return -EFBIG; + if ((pos + count) > 0x7fffffff) + count = 0x7fffffff - pos; while (written < count) { - bh = affs_getblock(inode,pos / blocksize); + bh = affs_getblock(inode, pos >> blockshift); if (!bh) { if (!written) written = -ENOSPC; break; } - c = blocksize - (pos % blocksize); + c = blocksize - (pos & (blocksize -1)); if (c > count - written) c = count - written; if (c != blocksize && !buffer_uptodate(bh)) { @@ -631,7 +637,7 @@ break; } } - p = (pos % blocksize) + bh->b_data; + p = (pos & (blocksize -1)) + bh->b_data; c -= copy_from_user(p,buf,c); if (!c) { affs_brelse(bh); @@ -662,7 +668,7 @@ off_t pos; ssize_t written; ssize_t c; - ssize_t blocksize; + ssize_t blocksize, blockshift; struct buffer_head *bh; char *p; @@ -690,15 +696,16 @@ bh = NULL; blocksize = AFFS_I2BSIZE(inode) - 24; + blockshift = AFFS_I2BITS(inode); written = 0; while (written < count) { - bh = affs_getblock(inode,pos / blocksize); + bh = affs_getblock(inode,pos >> blockshift); if (!bh) { if (!written) written = -ENOSPC; break; } - c = blocksize - (pos % blocksize); + c = blocksize - (pos & (blocksize -1)); if (c > count - written) c = count - written; if (c != blocksize && !buffer_uptodate(bh)) { @@ -711,7 +718,7 @@ break; } } - p = (pos % blocksize) + bh->b_data + 24; + p = (pos & (blocksize -1)) + bh->b_data + 24; c -= copy_from_user(p,buf,c); if (!c) { affs_brelse(bh); @@ -780,10 +787,10 @@ int rem; int ext; - pr_debug("AFFS: truncate(inode=%ld,size=%lu)\n",inode->i_ino,inode->i_size); + pr_debug("AFFS: truncate(inode=%ld,size=%Lu)\n",inode->i_ino,inode->i_size); net_blocksize = blocksize - ((inode->i_sb->u.affs_sb.s_flags & SF_OFS) ? 24 : 0); - first = (inode->i_size + net_blocksize - 1) / net_blocksize; + first = (u_long)(inode->i_size + net_blocksize - 1) / net_blocksize; if (inode->u.affs_i.i_lastblock < first - 1) { /* There has to be at least one new block to be allocated */ if (!inode->u.affs_i.i_ec && alloc_ext_cache(inode)) { @@ -793,9 +800,9 @@ bh = affs_getblock(inode,first - 1); if (!bh) { affs_warning(inode->i_sb,"truncate","Cannot extend file"); - inode->i_size = net_blocksize * (inode->u.affs_i.i_lastblock + 1); + inode->i_size = (inode->u.affs_i.i_lastblock + 1) * net_blocksize; } else if (inode->i_sb->u.affs_sb.s_flags & SF_OFS) { - rem = inode->i_size % net_blocksize; + rem = ((u_long)inode->i_size) & (net_blocksize -1); DATA_FRONT(bh)->data_size = cpu_to_be32(rem ? rem : net_blocksize); affs_fix_checksum(blocksize,bh->b_data,5); mark_buffer_dirty(bh,0); @@ -862,7 +869,7 @@ affs_free_block(inode->i_sb,ekey); ekey = key; } - block = ((inode->i_size + net_blocksize - 1) / net_blocksize) - 1; + block = (((u_long)inode->i_size + net_blocksize - 1) / net_blocksize) - 1; inode->u.affs_i.i_lastblock = block; /* If the file is not truncated to a block boundary, @@ -870,7 +877,7 @@ * so it cannot become accessible again. */ - rem = inode->i_size % net_blocksize; + rem = inode->i_size & (net_blocksize -1); if (rem) { if ((inode->i_sb->u.affs_sb.s_flags & SF_OFS)) rem += 24; diff -urN ref/fs/affs/inode.c lfs/fs/affs/inode.c --- ref/fs/affs/inode.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/affs/inode.c Sat Apr 8 19:56:12 2000 @@ -146,7 +146,7 @@ block = AFFS_I2BSIZE(inode) - 24; else block = AFFS_I2BSIZE(inode); - inode->u.affs_i.i_lastblock = ((inode->i_size + block - 1) / block) - 1; + inode->u.affs_i.i_lastblock = (((u_long)inode->i_size + block - 1) / block) - 1; break; case ST_SOFTLINK: inode->i_mode |= S_IFLNK; diff -urN ref/fs/buffer.c lfs/fs/buffer.c --- ref/fs/buffer.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/buffer.c Sat Apr 8 19:56:12 2000 @@ -1208,7 +1208,7 @@ #endif } if (test_and_clear_bit(PG_swap_unlock_after, &page->flags)) - swap_after_unlock_page(page->offset); + swap_after_unlock_page(pgoff2ulong(page->index)); if (test_and_clear_bit(PG_free_after, &page->flags)) __free_page(page); } @@ -1654,15 +1654,46 @@ set_bit(PG_locked, &page->flags); set_bit(PG_free_after, &page->flags); + /* Blocks within a page */ i = PAGE_SIZE >> inode->i_sb->s_blocksize_bits; - block = page->offset >> inode->i_sb->s_blocksize_bits; - p = nr; - do { - *p = inode->i_op->bmap(inode, block); - i--; - block++; - p++; - } while (i > 0); + + block = pgoff2ulong(page->index); + /* Scaled already by PAGE_SHIFT, which said shift should + be same or larger, than that of any filesystem in + this system -- that is, at i386 with 4k pages one + can't use 8k (primitive) blocks at the filesystems... */ + + if (i > 0) { + /* Filesystem blocksize is same, or smaller than CPU + page size, we can easily process this.. */ + + if (i > 1) + block *= i; + /* Scale by FS blocks per page, presuming FS-blocks are smaller + than the processor page... */ + + p = nr; + do { + *p = inode->i_op->bmap(inode, block); + i--; + block++; + p++; + } while (i > 0); + } else { + /* Filesystem blocksize is larger than CPU page size, + but if the underlying storage system block size is + smaller than CPU page size, all is well, else we + are in deep trouble -- for direct paging in at least.. */ + /* Nobody needs such monsterous fs block sizes ? + Well, it is the only way to get files in terabyte + range.. Nobody needs them ? You are for a surprise.. + However EXT2 (at least) needs access to internal + blocks and there it needs allocations of 8k/16k (or + whatever the block size is) for internal uses.. + Fixing this function alone isn't enough, although + perhaps fairly trivial.. */ + /* FIXME: WRITE THE CODE HERE !!! */ + } /* IO start */ brw_page(READ, page, inode->i_dev, nr, inode->i_sb->s_blocksize, 1); diff -urN ref/fs/coda/file.c lfs/fs/coda/file.c --- ref/fs/coda/file.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/coda/file.c Sat Apr 8 19:56:12 2000 @@ -99,7 +99,7 @@ &cont_file, &cont_dentry); CDEBUG(D_INODE, "coda ino: %ld, cached ino %ld, page offset: %lx\n", - coda_inode->i_ino, cii->c_ovp->i_ino, page->offset); + coda_inode->i_ino, cii->c_ovp->i_ino, pgoff2ulong(page->index)); generic_readpage(&cont_file, page); EXIT; diff -urN ref/fs/ext2/file.c lfs/fs/ext2/file.c --- ref/fs/ext2/file.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/ext2/file.c Sat Apr 8 19:56:12 2000 @@ -39,10 +39,6 @@ static long long ext2_file_lseek(struct file *, long long, int); static ssize_t ext2_file_write (struct file *, const char *, size_t, loff_t *); static int ext2_release_file (struct inode *, struct file *); -#if BITS_PER_LONG < 64 -static int ext2_open_file (struct inode *, struct file *); - -#else #define EXT2_MAX_SIZE(bits) \ (((EXT2_NDIR_BLOCKS + (1LL << (bits - 2)) + \ @@ -55,8 +51,6 @@ EXT2_MAX_SIZE(10), EXT2_MAX_SIZE(11), EXT2_MAX_SIZE(12), EXT2_MAX_SIZE(13) }; -#endif - /* * We have mostly NULL's here: the current defaults are ok for * the ext2 filesystem. @@ -69,11 +63,7 @@ NULL, /* poll - default */ ext2_ioctl, /* ioctl */ generic_file_mmap, /* mmap */ -#if BITS_PER_LONG == 64 NULL, /* no special open is needed */ -#else - ext2_open_file, -#endif NULL, /* flush */ ext2_release_file, /* release */ ext2_sync_file, /* fsync */ @@ -121,12 +111,8 @@ offset += file->f_pos; } if (((unsigned long long) offset >> 32) != 0) { -#if BITS_PER_LONG < 64 - return -EINVAL; -#else if (offset > ext2_max_sizes[EXT2_BLOCK_SIZE_BITS(inode->i_sb)]) return -EINVAL; -#endif } if (offset != file->f_pos) { file->f_pos = offset; @@ -155,7 +141,7 @@ size_t count, loff_t *ppos) { struct inode * inode = filp->f_dentry->d_inode; - off_t pos; + loff_t pos; long block; int offset; int written, c; @@ -202,24 +188,18 @@ /* Check for overflow.. */ -#if BITS_PER_LONG < 64 - /* If the fd's pos is already greater than or equal to the file - * descriptor's offset maximum, then we need to return EFBIG for - * any non-zero count (and we already tested for zero above). */ - if (((unsigned) pos) >= 0x7FFFFFFFUL) - return -EFBIG; - - /* If we are about to overflow the maximum file size, we also - * need to return the error, but only if no bytes can be written - * successfully. */ - if (((unsigned) pos + count) > 0x7FFFFFFFUL) { - count = 0x7FFFFFFFL - pos; - if (((signed) count) < 0) + /* L-F-S spec 2.2.1.27: */ + if (!(filp->f_flags & O_LARGEFILE)) { + if (pos >= 0x7ffffffeULL) /* pos@2G forbidden */ return -EFBIG; + + if (pos + count >= 0x7fffffffULL) + /* Write only until end of allowed region */ + count = 0x7fffffffULL - pos; } -#else + { - off_t max = ext2_max_sizes[EXT2_BLOCK_SIZE_BITS(sb)]; + loff_t max = ext2_max_sizes[EXT2_BLOCK_SIZE_BITS(sb)]; if (pos >= max) return -EFBIG; @@ -239,7 +219,6 @@ mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1); } } -#endif /* From SUS: We must generate a SIGXFSZ for file size overflow * only if no bytes were actually written to the file. --sct */ @@ -382,15 +361,3 @@ return 0; } -#if BITS_PER_LONG < 64 -/* - * Called when an inode is about to be open. - * We use this to disallow opening RW large files on 32bit systems. - */ -static int ext2_open_file (struct inode * inode, struct file * filp) -{ - if (inode->u.ext2_i.i_high_size && (filp->f_mode & FMODE_WRITE)) - return -EFBIG; - return 0; -} -#endif diff -urN ref/fs/ext2/inode.c lfs/fs/ext2/inode.c --- ref/fs/ext2/inode.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/ext2/inode.c Sat Apr 8 19:56:12 2000 @@ -533,15 +533,8 @@ inode->u.ext2_i.i_dir_acl = le32_to_cpu(raw_inode->i_dir_acl); else { inode->u.ext2_i.i_dir_acl = 0; - inode->u.ext2_i.i_high_size = - le32_to_cpu(raw_inode->i_size_high); -#if BITS_PER_LONG < 64 - if (raw_inode->i_size_high) - inode->i_size = (__u32)-1; -#else - inode->i_size |= ((__u64)le32_to_cpu(raw_inode->i_size_high)) - << 32; -#endif + inode->i_size = ((__u64)(inode->i_size & 0xFFFFFFFFUL)) | + (((__u64)le32_to_cpu(raw_inode->i_size_high)) << 32); } inode->u.ext2_i.i_version = le32_to_cpu(raw_inode->i_version); inode->i_generation = inode->u.ext2_i.i_version; @@ -667,12 +660,7 @@ if (S_ISDIR(inode->i_mode)) raw_inode->i_dir_acl = cpu_to_le32(inode->u.ext2_i.i_dir_acl); else { -#if BITS_PER_LONG < 64 - raw_inode->i_size_high = - cpu_to_le32(inode->u.ext2_i.i_high_size); -#else raw_inode->i_size_high = cpu_to_le32(inode->i_size >> 32); -#endif } raw_inode->i_version = cpu_to_le32(inode->u.ext2_i.i_version); if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) @@ -728,21 +716,18 @@ } if (iattr->ia_valid & ATTR_SIZE) { - off_t size = iattr->ia_size; + loff_t size = iattr->ia_size; unsigned long limit = current->rlim[RLIMIT_FSIZE].rlim_cur; if (size < 0) return -EINVAL; -#if BITS_PER_LONG == 64 if (size > ext2_max_sizes[EXT2_BLOCK_SIZE_BITS(inode->i_sb)]) return -EFBIG; -#endif if (limit < RLIM_INFINITY && size > limit) { send_sig(SIGXFSZ, current, 0); return -EFBIG; } -#if BITS_PER_LONG == 64 if (size >> 33) { struct super_block *sb = inode->i_sb; struct ext2_super_block *es = sb->u.ext2_sb.s_es; @@ -755,7 +740,6 @@ mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1); } } -#endif } retval = inode_change_ok(inode, iattr); diff -urN ref/fs/ext2/truncate.c lfs/fs/ext2/truncate.c --- ref/fs/ext2/truncate.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/ext2/truncate.c Sat Apr 8 19:56:12 2000 @@ -53,9 +53,10 @@ * Currently we always hold the inode semaphore during truncate, so * there's no need to test for changes during the operation. */ -#define DIRECT_BLOCK(inode) \ - ((inode->i_size + inode->i_sb->s_blocksize - 1) / \ - inode->i_sb->s_blocksize) +#define DIRECT_BLOCK(inode) \ + ((long) \ + ((inode->i_size + inode->i_sb->s_blocksize - 1) >> \ + inode->i_sb->s_blocksize_bits)) #define INDIRECT_BLOCK(inode,offset) ((int)DIRECT_BLOCK(inode) - offset) #define DINDIRECT_BLOCK(inode,offset) \ (INDIRECT_BLOCK(inode,offset) / addr_per_block) diff -urN ref/fs/fat/file.c lfs/fs/fat/file.c --- ref/fs/fat/file.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/fat/file.c Sat Apr 8 19:56:12 2000 @@ -227,7 +227,7 @@ Each time we process one block in bhlist, we replace it by a new prefetch block if needed. */ - PRINTK (("#### ino %ld pos %ld size %ld count %d\n",inode->i_ino,*ppos,inode->i_size,count)); + PRINTK (("#### ino %ld pos %ld size %ld count %d\n",inode->i_ino,*ppos,(u_long)inode->i_size,count)); { /* We must prefetch complete block, so we must @@ -253,7 +253,7 @@ } pre.nolist = 0; PRINTK (("count %d ahead %d nblist %d\n",count,read_ahead[MAJOR(inode->i_dev)],pre.nblist)); - while ((left_in_file = inode->i_size - *ppos) > 0 + while ((left_in_file = (u_long)inode->i_size - *ppos) > 0 && buf < end){ struct buffer_head *bh = pre.bhlist[pre.nolist]; char *data; @@ -451,7 +451,7 @@ void fat_truncate(struct inode *inode) { - int cluster; + int cluster_bytes, cluster_shift; /* Why no return value? Surely the disk could fail... */ if (IS_IMMUTABLE(inode)) @@ -460,8 +460,10 @@ printk("FAT: fat_truncate called though fs is read-only, uhh...\n"); return /* -EROFS */; } - cluster = SECTOR_SIZE*MSDOS_SB(inode->i_sb)->cluster_size; - (void) fat_free(inode,(inode->i_size+(cluster-1))/cluster); + cluster_bytes = SECTOR_SIZE * MSDOS_SB(inode->i_sb)->cluster_size; + cluster_shift = fslog2(cluster_bytes); + (void) fat_free(inode, + (inode->i_size+(cluster_bytes-1)) >> cluster_shift); MSDOS_I(inode)->i_attrs |= ATTR_ARCH; mark_inode_dirty(inode); } diff -urN ref/fs/fat/inode.c lfs/fs/fat/inode.c --- ref/fs/fat/inode.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/fat/inode.c Sat Apr 8 19:56:12 2000 @@ -392,8 +392,9 @@ sizeof(struct msdos_dir_entry); } inode->i_blksize = MSDOS_SB(sb)->cluster_size* SECTOR_SIZE; - inode->i_blocks = (inode->i_size+inode->i_blksize-1)/ - inode->i_blksize*MSDOS_SB(sb)->cluster_size; + inode->i_blocks = (((inode->i_size+inode->i_blksize-1) >> + fslog2(inode->i_blksize)) * + MSDOS_SB(sb)->cluster_size); MSDOS_I(inode)->i_logstart = 0; MSDOS_I(inode)->i_attrs = 0; @@ -823,8 +824,9 @@ MSDOS_I(inode)->i_attrs = de->attr & ATTR_UNUSED; /* this is as close to the truth as we can get ... */ inode->i_blksize = MSDOS_SB(sb)->cluster_size*SECTOR_SIZE; - inode->i_blocks = (inode->i_size+inode->i_blksize-1)/ - inode->i_blksize*MSDOS_SB(sb)->cluster_size; + inode->i_blocks = (((inode->i_size+inode->i_blksize-1) >> + fslog2(inode->i_blksize)) * + MSDOS_SB(sb)->cluster_size); inode->i_mtime = inode->i_atime = date_dos2unix(CF_LE_W(de->time),CF_LE_W(de->date)); inode->i_ctime = diff -urN ref/fs/fcntl.c lfs/fs/fcntl.c --- ref/fs/fcntl.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/fcntl.c Sat Apr 8 19:56:12 2000 @@ -182,6 +182,19 @@ case F_SETLKW: err = fcntl_setlk(fd, cmd, (struct flock *) arg); break; + +#if BITS_PER_LONG == 32 + case F_GETLK64: + err = fcntl_getlk64(fd, (struct flock64 *) arg); + break; + case F_SETLK64: + err = fcntl_setlk64(fd, cmd, (struct flock64 *) arg); + break; + case F_SETLKW64: + err = fcntl_setlk64(fd, cmd, (struct flock64 *) arg); + break; +#endif + case F_GETOWN: /* * XXX If f_owner is a process group, the diff -urN ref/fs/isofs/inode.c lfs/fs/isofs/inode.c --- ref/fs/isofs/inode.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/isofs/inode.c Sat Apr 8 19:56:12 2000 @@ -877,7 +877,8 @@ int isofs_bmap(struct inode * inode,int block) { - off_t b_off, offset, size; + loff_t b_off; + unsigned offset, size; struct inode *ino; unsigned int firstext; unsigned long nextino; @@ -888,7 +889,7 @@ return 0; } - b_off = block << ISOFS_BUFFER_BITS(inode); + b_off = (loff_t)block << ISOFS_BUFFER_BITS(inode); /* * If we are beyond the end of this file, don't give out any @@ -896,7 +897,7 @@ */ if( b_off > inode->i_size ) { - off_t max_legal_read_offset; + loff_t max_legal_read_offset; /* * If we are *way* beyond the end of the file, print a message. @@ -907,20 +908,21 @@ * I/O errors. */ max_legal_read_offset = (inode->i_size + PAGE_SIZE - 1) - & ~(PAGE_SIZE - 1); + & ~(loff_t)(PAGE_SIZE - 1); if( b_off >= max_legal_read_offset ) { printk("_isofs_bmap: block>= EOF(%d, %ld)\n", block, - inode->i_size); + (u_long)((inode->i_size >> ISOFS_BUFFER_BITS(inode)) + + ((inode->i_size & ((1 << ISOFS_BUFFER_BITS(inode))-1)) != 0))); } return 0; } offset = 0; firstext = inode->u.isofs_i.i_first_extent; - size = inode->u.isofs_i.i_section_size; - nextino = inode->u.isofs_i.i_next_section_ino; + size = inode->u.isofs_i.i_section_size; + nextino = inode->u.isofs_i.i_next_section_ino; #ifdef DEBUG printk("first inode: inode=%x nextino=%x firstext=%u size=%lu\n", inode->i_ino, nextino, firstext, size); @@ -1159,7 +1161,7 @@ #ifdef DEBUG printk("Get inode %x: %d %d: %d\n",inode->i_ino, block, - ((int)pnt) & 0x3ff, inode->i_size); + ((int)pnt) & 0x3ff, (u_long)inode->i_size); #endif inode->i_mtime = inode->i_atime = inode->i_ctime = diff -urN ref/fs/lockd/svclock.c lfs/fs/lockd/svclock.c --- ref/fs/lockd/svclock.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/lockd/svclock.c Sat Apr 8 19:56:12 2000 @@ -94,13 +94,15 @@ struct file_lock *fl; dprintk("lockd: nlmsvc_lookup_block f=%p pd=%d %ld-%ld ty=%d\n", - file, lock->fl.fl_pid, lock->fl.fl_start, - lock->fl.fl_end, lock->fl.fl_type); + file, lock->fl.fl_pid, + (u_long)lock->fl.fl_start, (u_long)lock->fl.fl_end, + lock->fl.fl_type); for (head = &nlm_blocked; (block = *head); head = &block->b_next) { fl = &block->b_call.a_args.lock.fl; dprintk(" check f=%p pd=%d %ld-%ld ty=%d\n", - block->b_file, fl->fl_pid, fl->fl_start, - fl->fl_end, fl->fl_type); + block->b_file, fl->fl_pid, + (u_long)fl->fl_start, (u_long)fl->fl_end, + fl->fl_type); if (block->b_file == file && nlm_compare_locks(fl, &lock->fl)) { if (remove) *head = block->b_next; @@ -286,8 +288,8 @@ file->f_file.f_dentry->d_inode->i_dev, file->f_file.f_dentry->d_inode->i_ino, lock->fl.fl_type, lock->fl.fl_pid, - lock->fl.fl_start, - lock->fl.fl_end, + (u_long)lock->fl.fl_start, + (u_long)lock->fl.fl_end, wait); /* Lock file against concurrent access */ @@ -359,12 +361,13 @@ file->f_file.f_dentry->d_inode->i_dev, file->f_file.f_dentry->d_inode->i_ino, lock->fl.fl_type, - lock->fl.fl_start, - lock->fl.fl_end); + (u_long)lock->fl.fl_start, + (u_long)lock->fl.fl_end); if ((fl = posix_test_lock(&file->f_file, &lock->fl)) != NULL) { dprintk("lockd: conflicting lock(ty=%d, %ld-%ld)\n", - fl->fl_type, fl->fl_start, fl->fl_end); + fl->fl_type, + (u_long)fl->fl_start, (u_long)fl->fl_end); conflock->caller = "somehost"; /* FIXME */ conflock->oh.len = 0; /* don't return OH info */ conflock->fl = *fl; @@ -390,8 +393,8 @@ file->f_file.f_dentry->d_inode->i_dev, file->f_file.f_dentry->d_inode->i_ino, lock->fl.fl_pid, - lock->fl.fl_start, - lock->fl.fl_end); + (u_long)lock->fl.fl_start, + (u_long)lock->fl.fl_end); /* First, cancel any lock that might be there */ nlmsvc_cancel_blocked(file, lock); @@ -418,8 +421,8 @@ file->f_file.f_dentry->d_inode->i_dev, file->f_file.f_dentry->d_inode->i_ino, lock->fl.fl_pid, - lock->fl.fl_start, - lock->fl.fl_end); + (u_long)lock->fl.fl_start, + (u_long)lock->fl.fl_end); down(&file->f_sema); if ((block = nlmsvc_lookup_block(file, lock, 1)) != NULL) diff -urN ref/fs/lockd/xdr.c lfs/fs/lockd/xdr.c --- ref/fs/lockd/xdr.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/lockd/xdr.c Sat Apr 8 19:56:12 2000 @@ -142,7 +142,7 @@ fl->fl_pid = ntohl(*p++); fl->fl_flags = FL_POSIX; fl->fl_type = F_RDLCK; /* as good as anything else */ - fl->fl_start = ntohl(*p++); + fl->fl_start = (u_long)ntohl(*p++); len = ntohl(*p++); if (len == 0 || (fl->fl_end = fl->fl_start + len - 1) < 0) fl->fl_end = NLM_OFFSET_MAX; @@ -163,11 +163,11 @@ return NULL; *p++ = htonl(fl->fl_pid); - *p++ = htonl(lock->fl.fl_start); + *p++ = htonl((u_long)lock->fl.fl_start); if (lock->fl.fl_end == NLM_OFFSET_MAX) *p++ = xdr_zero; else - *p++ = htonl(lock->fl.fl_end - lock->fl.fl_start + 1); + *p++ = htonl((u_long)(lock->fl.fl_end - lock->fl.fl_start + 1)); return p; } @@ -192,11 +192,11 @@ if (!(p = xdr_encode_netobj(p, &resp->lock.oh))) return 0; - *p++ = htonl(fl->fl_start); + *p++ = htonl((u_long)fl->fl_start); if (fl->fl_end == NLM_OFFSET_MAX) *p++ = xdr_zero; else - *p++ = htonl(fl->fl_end - fl->fl_start + 1); + *p++ = htonl((u_long)(fl->fl_end - fl->fl_start + 1)); } return p; @@ -425,7 +425,7 @@ fl->fl_flags = FL_POSIX; fl->fl_type = excl? F_WRLCK : F_RDLCK; - fl->fl_start = ntohl(*p++); + fl->fl_start = (u_long)ntohl(*p++); len = ntohl(*p++); if (len == 0 || (fl->fl_end = fl->fl_start + len - 1) < 0) fl->fl_end = NLM_OFFSET_MAX; diff -urN ref/fs/locks.c lfs/fs/locks.c --- ref/fs/locks.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/locks.c Sat Apr 8 19:56:12 2000 @@ -111,12 +111,12 @@ #include -#define OFFSET_MAX ((off_t)LONG_MAX) /* FIXME: move elsewhere? */ +#define OFFSET_MAX ((loff_t)((~0ULL)>>1)) /* FIXME: move elsewhere? */ static int flock_make_lock(struct file *filp, struct file_lock *fl, unsigned int cmd); static int posix_make_lock(struct file *filp, struct file_lock *fl, - struct flock *l); + struct flock64 *l); static int flock_locks_conflict(struct file_lock *caller_fl, struct file_lock *sys_fl); static int posix_locks_conflict(struct file_lock *caller_fl, @@ -195,7 +195,7 @@ if (waiter->fl_prevblock) { printk(KERN_ERR "locks_insert_block: remove duplicated lock " - "(pid=%d %ld-%ld type=%d)\n", + "(pid=%d %Ld-%Ld type=%d)\n", waiter->fl_pid, waiter->fl_start, waiter->fl_end, waiter->fl_type); locks_delete_block(waiter->fl_prevblock, waiter); @@ -323,11 +323,15 @@ { struct file *filp; struct file_lock *fl,file_lock; - struct flock flock; - int error; + int error = -EFAULT; + struct flock64 flock; - error = -EFAULT; - if (copy_from_user(&flock, l, sizeof(flock))) + if (verify_area(VERIFY_READ, l, sizeof(*l)) + || __get_user(flock.l_type, &l->l_type) + || __get_user(flock.l_whence, &l->l_whence) + || __get_user(flock.l_start, &l->l_start) + || __get_user(flock.l_len, &l->l_len) + || __get_user(flock.l_pid, &l->l_pid)) goto out; error = -EINVAL; if ((flock.l_type != F_RDLCK) && (flock.l_type != F_WRLCK)) @@ -367,9 +371,24 @@ flock.l_whence = 0; flock.l_type = fl->fl_type; } - error = -EFAULT; - if (!copy_to_user(l, &flock, sizeof(flock))) - error = 0; + + /* Convert to 32-bit offsets (at 32-bit systems) */ + + if (!off_t_presentable(flock.l_start) || + !off_t_presentable(flock.l_len) || + !off_t_presentable(flock.l_start + flock.l_len)) { + error = -EOVERFLOW; + goto out_putf; + } + + error = 0; + if (verify_area(VERIFY_WRITE, l, sizeof(*l)) + || __put_user(flock.l_type, &l->l_type) + || __put_user(flock.l_whence, &l->l_whence) + || __put_user(flock.l_start, &l->l_start) + || __put_user(flock.l_len, &l->l_len) + || __put_user(flock.l_pid, &l->l_pid)) + error = -EFAULT; out_putf: fput(filp); @@ -384,7 +403,7 @@ { struct file *filp; struct file_lock file_lock; - struct flock flock; + struct flock64 flock; struct dentry * dentry; struct inode *inode; int error; @@ -393,7 +412,12 @@ * This might block, so we do it before checking the inode. */ error = -EFAULT; - if (copy_from_user(&flock, l, sizeof(flock))) + if (verify_area(VERIFY_READ, l, sizeof(*l)) + || __get_user(flock.l_type, &l->l_type) + || __get_user(flock.l_whence, &l->l_whence) + || __get_user(flock.l_start, &l->l_start) + || __get_user(flock.l_len, &l->l_len) + || __get_user(flock.l_pid, &l->l_pid)) goto out; /* Get arguments and validate them ... @@ -475,6 +499,152 @@ return error; } +#if BITS_PER_LONG == 32 +/* Report the first existing lock that would conflict with l. + * This implements the F_GETLK command of fcntl(). + */ +int fcntl_getlk64(unsigned int fd, struct flock64 *l) +{ + struct file *filp; + struct file_lock *fl,file_lock; + struct flock64 flock; + int error; + + error = -EFAULT; + if (copy_from_user(&flock, l, sizeof(flock))) + goto out; + error = -EINVAL; + if ((flock.l_type != F_RDLCK) && (flock.l_type != F_WRLCK)) + goto out; + + error = -EBADF; + filp = fget(fd); + if (!filp) + goto out; + + error = -EINVAL; + if (!filp->f_dentry || !filp->f_dentry->d_inode) + goto out_putf; + + if (!posix_make_lock(filp, &file_lock, &flock)) + goto out_putf; + + if (filp->f_op->lock) { + error = filp->f_op->lock(filp, F_GETLK, &file_lock); + if (error < 0) + goto out_putf; + else if (error == LOCK_USE_CLNT) + /* Bypass for NFS with no locking - 2.0.36 compat */ + fl = posix_test_lock(filp, &file_lock); + else + fl = (file_lock.fl_type == F_UNLCK ? NULL : &file_lock); + } else { + fl = posix_test_lock(filp, &file_lock); + } + + flock.l_type = F_UNLCK; + if (fl != NULL) { + flock.l_pid = fl->fl_pid; + flock.l_start = fl->fl_start; + flock.l_len = fl->fl_end == OFFSET_MAX ? 0 : + fl->fl_end - fl->fl_start + 1; + flock.l_whence = 0; + flock.l_type = fl->fl_type; + } + error = -EFAULT; + if (!copy_to_user(l, &flock, sizeof(flock))) + error = 0; + +out_putf: + fput(filp); +out: + return error; +} + +/* Apply the lock described by l to an open file descriptor. + * This implements both the F_SETLK and F_SETLKW commands of fcntl(). + */ +int fcntl_setlk64(unsigned int fd, unsigned int cmd, struct flock64 *l) +{ + struct file *filp; + struct file_lock file_lock; + struct flock64 flock; + struct dentry * dentry; + struct inode *inode; + int error; + + /* + * This might block, so we do it before checking the inode. + */ + error = -EFAULT; + if (copy_from_user(&flock, l, sizeof(flock))) + goto out; + + /* Get arguments and validate them ... + */ + + error = -EBADF; + filp = fget(fd); + if (!filp) + goto out; + + error = -EINVAL; + if (!(dentry = filp->f_dentry)) + goto out_putf; + if (!(inode = dentry->d_inode)) + goto out_putf; + + /* Don't allow mandatory locks on files that may be memory mapped + * and shared. + */ + if (IS_MANDLOCK(inode) && + (inode->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID && + inode->i_mmap) { + struct vm_area_struct *vma = inode->i_mmap; + error = -EAGAIN; + do { + if (vma->vm_flags & VM_MAYSHARE) + goto out_putf; + } while ((vma = vma->vm_next_share) != NULL); + } + + error = -EINVAL; + if (!posix_make_lock(filp, &file_lock, &flock)) + goto out_putf; + + error = -EBADF; + switch (flock.l_type) { + case F_RDLCK: + if (!(filp->f_mode & FMODE_READ)) + goto out_putf; + break; + case F_WRLCK: + if (!(filp->f_mode & FMODE_WRITE)) + goto out_putf; + break; + case F_UNLCK: + break; + case F_SHLCK: + case F_EXLCK: + default: + error = -EINVAL; + goto out_putf; + } + + if (filp->f_op->lock != NULL) { + error = filp->f_op->lock(filp, cmd, &file_lock); + if (error < 0) + goto out_putf; + } + error = posix_lock_file(filp, &file_lock, cmd == F_SETLKW); + +out_putf: + fput(filp); +out: + return error; +} +#endif /* BITS_PER_LONG == 32 */ + /* * This function is called when the file is being removed * from the task's fd array. @@ -654,9 +824,9 @@ * style lock. */ static int posix_make_lock(struct file *filp, struct file_lock *fl, - struct flock *l) + struct flock64 *l) { - off_t start; + loff_t start; memset(fl, 0, sizeof(*fl)); @@ -1209,8 +1379,9 @@ p += sprintf(p, "%s ", (fl->fl_type == F_RDLCK) ? "READ " : "WRITE"); p += sprintf(p, "%d %s:%ld %ld %ld ", fl->fl_pid, - kdevname(inode->i_dev), inode->i_ino, fl->fl_start, - fl->fl_end); + kdevname(inode->i_dev), inode->i_ino, + (u_long)fl->fl_start, + (u_long)fl->fl_end); sprintf(p, "%08lx %08lx %08lx %08lx %08lx\n", (long)fl, (long)fl->fl_prevlink, (long)fl->fl_nextlink, (long)fl->fl_next, (long)fl->fl_nextblock); @@ -1271,6 +1442,3 @@ *start = buffer; return (q - buffer); } - - - diff -urN ref/fs/minix/file.c lfs/fs/minix/file.c --- ref/fs/minix/file.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/minix/file.c Sat Apr 8 19:56:12 2000 @@ -70,7 +70,7 @@ size_t count, loff_t *ppos) { struct inode * inode = filp->f_dentry->d_inode; - off_t pos; + loff_t pos; ssize_t written, c; struct buffer_head * bh; char * p; @@ -87,6 +87,24 @@ pos = inode->i_size; else pos = *ppos; + + /* L-F-S spec 2.2.1.27: */ + if (!(filp->f_flags & O_LARGEFILE)) { + if (pos >= 0x7ffffffeULL) /* pos@2G forbidden */ + return -EFBIG; + + if (pos + count >= 0x7fffffffULL) + /* Write only until end of allowed region */ + count = 0x7fffffffULL - pos; + } + /* MINIX i-node file-size can't exceed 4G-1 */ + /* With 1k blocks and triple indirection MINIX can have files + up to 16 GB in size -- filesystem maximum is then 4G*1k = 4T */ + if (pos >= 0xffffffffULL) + return -EFBIG; /* Absolutely too much! */ + if ((pos + count) >= 0x100000000ULL) /* too much to write! */ + count = 0xffffffffULL - pos; + written = 0; while (written < count) { bh = minix_getblk(inode,pos/BLOCK_SIZE,1); diff -urN ref/fs/ncpfs/file.c lfs/fs/ncpfs/file.c --- ref/fs/ncpfs/file.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/ncpfs/file.c Sat Apr 8 19:56:12 2000 @@ -17,6 +17,7 @@ #include #include #include +#include #include #include "ncplib_kernel.h" @@ -161,7 +162,7 @@ /* First read in as much as possible for each bufsize. */ while (already_read < count) { int read_this_time; - size_t to_read = min(bufsize - (pos % bufsize), + size_t to_read = min(bufsize - (pos & (bufsize-1)), count - already_read); error = ncp_read_bounce(NCP_SERVER(inode), @@ -201,7 +202,7 @@ struct dentry *dentry = file->f_dentry; struct inode *inode = dentry->d_inode; size_t already_written = 0; - off_t pos; + loff_t pos; size_t bufsize; int errno; void* bouncebuffer; @@ -238,12 +239,18 @@ already_written = 0; + /* Maximum file size: 2G-1 */ + if (pos >= 0x7fffffffULL) + return -EFBIG; + if ((pos + count) >= 0x7fffffffULL) + count = 0x7fffffffULL - pos; + bouncebuffer = kmalloc(bufsize, GFP_NFS); if (!bouncebuffer) return -EIO; /* -ENOMEM */ while (already_written < count) { int written_this_time; - size_t to_write = min(bufsize - (pos % bufsize), + size_t to_write = min(bufsize - (pos & (bufsize-1)), count - already_written); if (copy_from_user(bouncebuffer, buf, to_write)) { diff -urN ref/fs/ncpfs/inode.c lfs/fs/ncpfs/inode.c --- ref/fs/ncpfs/inode.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/ncpfs/inode.c Sat Apr 8 19:56:12 2000 @@ -132,7 +132,7 @@ } inode->i_blocks = 0; if ((inode->i_size)&&(inode->i_blksize)) { - inode->i_blocks = (inode->i_size-1)/(inode->i_blksize)+1; + inode->i_blocks = ((inode->i_size-1) >> fslog2(inode->i_blksize)) +1; } inode->i_mtime = ncp_date_dos2unix(le16_to_cpu(nwi->modifyTime), @@ -203,8 +203,7 @@ inode->i_blocks = 0; if ((inode->i_blksize != 0) && (inode->i_size != 0)) { - inode->i_blocks = - (inode->i_size - 1) / inode->i_blksize + 1; + inode->i_blocks = ((inode->i_size - 1) >> fslog2(inode->i_blksize)) + 1; } inode->i_mtime = ncp_date_dos2unix(le16_to_cpu(nwi->modifyTime), diff -urN ref/fs/nfs/file.c lfs/fs/nfs/file.c --- ref/fs/nfs/file.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/nfs/file.c Sat Apr 8 19:56:12 2000 @@ -114,6 +114,11 @@ dentry->d_parent->d_name.name, dentry->d_name.name, (unsigned long) count, (unsigned long) *ppos); + /* Unconditionally allow only up to 2G files */ + /* FIXME: NFSv3 could allow 64-bit file offsets! */ + if (*ppos >= 0x7ffffffeULL) + return -EOVERFLOW; + result = nfs_revalidate_inode(NFS_DSERVER(dentry), dentry); if (!result) result = generic_file_read(file, buf, count, ppos); @@ -178,6 +183,13 @@ if (result) goto out; + /* Unconditionally allow only up to 2G files */ + /* FIXME: NFSv3 could allow 64-bit file offsets! */ + if (*ppos >= 0x7ffffffeULL) { + result = -EOVERFLOW; + goto out; + } + result = count; if (!count) goto out; @@ -203,7 +215,7 @@ dprintk("NFS: nfs_lock(f=%4x/%ld, t=%x, fl=%x, r=%ld:%ld)\n", inode->i_dev, inode->i_ino, fl->fl_type, fl->fl_flags, - fl->fl_start, fl->fl_end); + (u_long)fl->fl_start, (u_long)fl->fl_end); if (!inode) return -EINVAL; diff -urN ref/fs/nfs/inode.c lfs/fs/nfs/inode.c --- ref/fs/nfs/inode.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/nfs/inode.c Sat Apr 8 19:56:12 2000 @@ -700,7 +700,7 @@ */ if (sattr.size != (u32) -1) { if (sattr.size != fattr.size) - printk("nfs_notify_change: sattr=%d, fattr=%d??\n", + printk("nfs_notify_change: sattr=%Ld, fattr=%Ld??\n", sattr.size, fattr.size); inode->i_size = sattr.size; inode->i_mtime = fattr.mtime.seconds; diff -urN ref/fs/nfs/proc.c lfs/fs/nfs/proc.c --- ref/fs/nfs/proc.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/nfs/proc.c Sat Apr 8 19:56:12 2000 @@ -110,14 +110,14 @@ int nfs_proc_read(struct nfs_server *server, struct nfs_fh *fhandle, int swap, - unsigned long offset, unsigned int count, - void *buffer, struct nfs_fattr *fattr) + loff_t offset, unsigned int count, + void *buffer, struct nfs_fattr *fattr) { struct nfs_readargs arg = { fhandle, offset, count, buffer }; struct nfs_readres res = { fattr, count }; int status; - dprintk("NFS call read %d @ %ld\n", count, offset); + dprintk("NFS call read %d @ %Ld\n", count, offset); status = rpc_call(server->client, NFSPROC_READ, &arg, &res, swap? NFS_RPC_SWAPFLAGS : 0); dprintk("NFS reply read: %d\n", status); @@ -126,13 +126,13 @@ int nfs_proc_write(struct nfs_server *server, struct nfs_fh *fhandle, int swap, - unsigned long offset, unsigned int count, - const void *buffer, struct nfs_fattr *fattr) + loff_t offset, unsigned int count, + const void *buffer, struct nfs_fattr *fattr) { struct nfs_writeargs arg = { fhandle, offset, count, buffer }; int status; - dprintk("NFS call write %d @ %ld\n", count, offset); + dprintk("NFS call write %d @ %Ld\n", count, offset); status = rpc_call(server->client, NFSPROC_WRITE, &arg, fattr, swap? (RPC_TASK_SWAPPER|RPC_TASK_ROOTCREDS) : 0); dprintk("NFS reply read: %d\n", status); diff -urN ref/fs/nfs/read.c lfs/fs/nfs/read.c --- ref/fs/nfs/read.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/nfs/read.c Sat Apr 8 19:56:12 2000 @@ -52,7 +52,7 @@ */ static inline void nfs_readreq_setup(struct nfs_rreq *req, struct nfs_fh *fh, - unsigned long offset, void *buffer, unsigned int rsize) + loff_t offset, void *buffer, unsigned int rsize) { req->ra_args.fh = fh; req->ra_args.offset = offset; @@ -70,12 +70,12 @@ nfs_readpage_sync(struct dentry *dentry, struct inode *inode, struct page *page) { struct nfs_rreq rqst; - unsigned long offset = page->offset; - char *buffer = (char *) page_address(page); - int rsize = NFS_SERVER(inode)->rsize; - int result, refresh = 0; - int count = PAGE_SIZE; - int flags = IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0; + loff_t offset = pgoff2loff(page->index); + char *buffer = (char *) page_address(page); + int rsize = NFS_SERVER(inode)->rsize; + int result = 0, refresh = 0; + int count = PAGE_SIZE; + int flags = IS_SWAPFILE(inode)? NFS_RPC_SWAPFLAGS : 0; dprintk("NFS: nfs_readpage_sync(%p)\n", page); clear_bit(PG_error, &page->flags); @@ -84,13 +84,28 @@ if (count < rsize) rsize = count; - dprintk("NFS: nfs_proc_read(%s, (%s/%s), %ld, %d, %p)\n", + dprintk("NFS: nfs_proc_read(%s, (%s/%s), %Ld, %d, %p)\n", NFS_SERVER(inode)->hostname, dentry->d_parent->d_name.name, dentry->d_name.name, offset, rsize, buffer); + /* FIXME: NFSv3 could allow 64-bit offsets! ... */ + + if (offset > 0x7ffffffeULL) { + if (result) + break; + result = -EOVERFLOW; + goto io_error; + } + if ((offset + rsize) > 0x7fffffffULL) /* 2G-1 */ + rsize = 0x7fffffffULL - offset; + + /* ... END FIXME! */ + /* Set up arguments and perform rpc call */ - nfs_readreq_setup(&rqst, NFS_FH(dentry), offset, buffer, rsize); + nfs_readreq_setup(&rqst, NFS_FH(dentry), offset, + buffer, rsize); + result = rpc_call(NFS_CLIENT(inode), NFSPROC_READ, &rqst.ra_args, &rqst.ra_res, flags); @@ -173,8 +188,16 @@ unsigned long address = page_address(page); struct nfs_rreq *req; int result = -1, flags; + loff_t loffset = pgoff2loff(page->index); dprintk("NFS: nfs_readpage_async(%p)\n", page); + + /* FIXME: NFSv3 allows 64-bit offsets.. */ + if ((loffset + PAGE_SIZE) >= 0x7fffffffULL) { + dprintk("NFS: Async read beyond 2G-1 marker!\n"); + return -EOVERFLOW; + } + if (NFS_CONGESTED(inode)) goto out_defer; @@ -186,8 +209,9 @@ /* Initialize request */ /* N.B. Will the dentry remain valid for life of request? */ - nfs_readreq_setup(req, NFS_FH(dentry), page->offset, - (void *) address, PAGE_SIZE); + nfs_readreq_setup(req, NFS_FH(dentry), loffset, + (void *) address, PAGE_SIZE); + req->ra_inode = inode; req->ra_page = page; /* count has been incremented by caller */ @@ -230,8 +254,8 @@ struct inode *inode = dentry->d_inode; int error; - dprintk("NFS: nfs_readpage (%p %ld@%ld)\n", - page, PAGE_SIZE, page->offset); + dprintk("NFS: nfs_readpage (%p %ld@%Ld)\n", + page, PAGE_SIZE, pgoff2loff(page->index)); atomic_inc(&page->count); set_bit(PG_locked, &page->flags); diff -urN ref/fs/nfs/write.c lfs/fs/nfs/write.c --- ref/fs/nfs/write.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/nfs/write.c Sat Apr 8 19:56:12 2000 @@ -86,26 +86,43 @@ */ static int nfs_writepage_sync(struct dentry *dentry, struct inode *inode, - struct page *page, unsigned long offset, unsigned int count) + struct page *page, unsigned int offset, unsigned int count) { unsigned int wsize = NFS_SERVER(inode)->wsize; int result, refresh = 0, written = 0; u8 *buffer; struct nfs_fattr fattr; + loff_t loffset = pgoff2loff(page->index)+offset; - dprintk("NFS: nfs_writepage_sync(%s/%s %d@%ld)\n", + dprintk("NFS: nfs_writepage_sync(%s/%s %d@%Ld)\n", dentry->d_parent->d_name.name, dentry->d_name.name, - count, page->offset + offset); + count, loffset); buffer = (u8 *) page_address(page) + offset; - offset += page->offset; + + /* FIXME: NFSv3 !!! */ +#if 1 + if (loffset >= 0x7ffffffeULL) + return -EFBIG; + if (loffset + count >= 0x7fffffffULL) { + /* At MOST this much! */ + count = 0x7fffffffULL - loffset; + } +#else + if (S_ISREG(inode->i_flags) && + !(dentry->d_file->f_flags & O_LARGEFILE) && + (loffset >= 0x7ffffffeULL || + loffset + count >= 0x7fffffffULL) { + /* Writing beyond LargeFile maximums without O_LARGEFILE */ + } +#endif do { if (count < wsize && !IS_SWAPFILE(inode)) wsize = count; result = nfs_proc_write(NFS_DSERVER(dentry), NFS_FH(dentry), - IS_SWAPFILE(inode), offset, wsize, + IS_SWAPFILE(inode), loffset, wsize, buffer, &fattr); if (result < 0) { @@ -118,15 +135,15 @@ wsize, result); refresh = 1; buffer += wsize; - offset += wsize; + loffset += wsize; written += wsize; count -= wsize; /* * If we've extended the file, update the inode * now so we don't invalidate the cache. */ - if (offset > inode->i_size) - inode->i_size = offset; + if (loffset > inode->i_size) + inode->i_size = loffset; } while (count); io_error: @@ -271,7 +288,7 @@ dprintk("NFS: create_write_request(%s/%s, %ld+%d)\n", dentry->d_parent->d_name.name, dentry->d_name.name, - page->offset + offset, bytes); + (u_long)pgoff2loff(page->index) + offset, bytes); /* FIXME: Enforce hard limit on number of concurrent writes? */ wreq = (struct nfs_wreq *) kmalloc(sizeof(*wreq), GFP_KERNEL); @@ -417,7 +434,7 @@ dprintk("NFS: nfs_updatepage(%s/%s %d@%ld, sync=%d)\n", dentry->d_parent->d_name.name, dentry->d_name.name, - count, page->offset+offset, sync); + count, (u_long)pgoff2loff(page->index)+offset, sync); /* * Try to find a corresponding request on the writeback queue. @@ -603,7 +620,7 @@ /* Setup the task struct for a writeback call */ req->wb_flags |= NFS_WRITE_INPROGRESS; req->wb_args.fh = NFS_FH(dentry); - req->wb_args.offset = page->offset + req->wb_offset; + req->wb_args.offset = pgoff2loff(page->index) + req->wb_offset; req->wb_args.count = req->wb_bytes; req->wb_args.buffer = (void *) (page_address(page) + req->wb_offset); diff -urN ref/fs/nfsd/vfs.c lfs/fs/nfsd/vfs.c --- ref/fs/nfsd/vfs.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/nfsd/vfs.c Sat Apr 8 19:56:12 2000 @@ -503,8 +503,9 @@ /* Write back readahead params */ if (ra != NULL) { dprintk("nfsd: raparms %ld %ld %ld %ld %ld\n", - file.f_reada, file.f_ramax, file.f_raend, - file.f_ralen, file.f_rawin); + (u_long)file.f_reada, (u_long)file.f_ramax, + (u_long)file.f_raend, (u_long)file.f_ralen, + (u_long)file.f_rawin); ra->p_reada = file.f_reada; ra->p_ramax = file.f_ramax; ra->p_raend = file.f_raend; diff -urN ref/fs/ntfs/fs.c lfs/fs/ntfs/fs.c --- ref/fs/ntfs/fs.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/ntfs/fs.c Sat Apr 8 19:56:12 2000 @@ -818,6 +818,7 @@ struct statfs fs; struct inode *mft; ntfs_volume *vol; + ntfs_u64 size; int error; ntfs_debug(DEBUG_OTHER, "ntfs_statfs\n"); @@ -826,16 +827,17 @@ fs.f_type=NTFS_SUPER_MAGIC; fs.f_bsize=vol->clustersize; - error = ntfs_get_volumesize( NTFS_SB2VOL( sb ), &fs.f_blocks ); + error = ntfs_get_volumesize( NTFS_SB2VOL( sb ), &size ); if( error ) return -error; + fs.f_blocks = size; fs.f_bfree=ntfs_get_free_cluster_count(vol->bitmap); fs.f_bavail=fs.f_bfree; /* Number of files is limited by free space only, so we lie here */ fs.f_ffree=0; mft=iget(sb,FILE_MFT); - fs.f_files=mft->i_size/vol->mft_recordsize; + fs.f_files = (long)mft->i_size / vol->mft_recordsize; iput(mft); /* should be read from volume */ diff -urN ref/fs/ntfs/super.c lfs/fs/ntfs/super.c --- ref/fs/ntfs/super.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/ntfs/super.c Sat Apr 8 19:56:12 2000 @@ -253,7 +253,7 @@ * Writes the volume size into vol_size. Returns 0 if successful * or error. */ -int ntfs_get_volumesize(ntfs_volume *vol, long *vol_size ) +int ntfs_get_volumesize(ntfs_volume *vol, ntfs_u64 *vol_size ) { ntfs_io io; ntfs_u64 size; @@ -274,9 +274,7 @@ ntfs_getput_clusters(vol,0,0,&io); size=NTFS_GETU64(cluster0+0x28); ntfs_free(cluster0); - /* FIXME: more than 2**32 cluster */ - /* FIXME: gcc will emit udivdi3 if we don't truncate it */ - *vol_size = ((unsigned long)size)/vol->clusterfactor; + *vol_size = size; return 0; } diff -urN ref/fs/ntfs/super.h lfs/fs/ntfs/super.h --- ref/fs/ntfs/super.h Sat Apr 8 19:56:02 2000 +++ lfs/fs/ntfs/super.h Sat Apr 8 19:56:12 2000 @@ -10,7 +10,7 @@ #define ALLOC_REQUIRE_SIZE 2 int ntfs_get_free_cluster_count(ntfs_inode *bitmap); -int ntfs_get_volumesize(ntfs_volume *vol, long *vol_size ); +int ntfs_get_volumesize(ntfs_volume *vol, ntfs_u64 *vol_size ); int ntfs_init_volume(ntfs_volume *vol,char *boot); int ntfs_load_special_files(ntfs_volume *vol); int ntfs_release_volume(ntfs_volume *vol); diff -urN ref/fs/open.c lfs/fs/open.c --- ref/fs/open.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/open.c Sat Apr 8 19:56:12 2000 @@ -12,7 +12,7 @@ #include -asmlinkage int sys_statfs(const char * path, struct statfs * buf) +asmlinkage long sys_statfs(const char * path, struct statfs * buf) { struct dentry * dentry; int error; @@ -34,7 +34,7 @@ return error; } -asmlinkage int sys_fstatfs(unsigned int fd, struct statfs * buf) +asmlinkage long sys_fstatfs(unsigned int fd, struct statfs * buf) { struct file * file; struct inode * inode; @@ -63,15 +63,16 @@ return error; } -int do_truncate(struct dentry *dentry, unsigned long length) +int do_truncate(struct dentry *dentry, loff_t length) { struct inode *inode = dentry->d_inode; int error; struct iattr newattrs; - /* Not pretty: "inode->i_size" shouldn't really be "off_t". But it is. */ - if ((off_t) length < 0) - return -EINVAL; + /* Not pretty: "inode->i_size" shouldn't really be signed. But it is. */ + error = -EINVAL; + if (length < 0) + goto out; down(&inode->i_sem); newattrs.ia_size = length; @@ -84,15 +85,20 @@ inode->i_op->truncate(inode); } up(&inode->i_sem); +out: return error; } -asmlinkage int sys_truncate(const char * path, unsigned long length) +static inline long do_sys_truncate(const char * path, loff_t length) { struct dentry * dentry; struct inode * inode; int error; + error = -EINVAL; + if (length < 0) + goto out_nolock; + lock_kernel(); dentry = namei(path); @@ -133,10 +139,16 @@ dput(dentry); out: unlock_kernel(); +out_nolock: return error; } -asmlinkage int sys_ftruncate(unsigned int fd, unsigned long length) +asmlinkage long sys_truncate(const char * path, unsigned long length) +{ + return do_sys_truncate(path, length); +} + +static inline long do_sys_ftruncate(unsigned int fd, loff_t length) { struct inode * inode; struct dentry *dentry; @@ -171,6 +183,24 @@ return error; } +asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length) +{ + return do_sys_ftruncate(fd, length); +} + +/* LFS versions of truncate are only needed on 32 bit machines */ +#if BITS_PER_LONG == 32 +asmlinkage long sys_truncate64(const char * path, loff_t length) +{ + return do_sys_truncate(path, length); +} + +asmlinkage long sys_ftruncate64(unsigned int fd, loff_t length) +{ + return do_sys_ftruncate(fd, length); +} +#endif + #ifndef __alpha__ /* @@ -184,7 +214,7 @@ * must be owner or have write permission. * Else, update from *times, must be owner or super user. */ -asmlinkage int sys_utime(char * filename, struct utimbuf * times) +asmlinkage long sys_utime(char * filename, struct utimbuf * times) { int error; struct dentry * dentry; @@ -232,7 +262,7 @@ * must be owner or have write permission. * Else, update from *times, must be owner or super user. */ -asmlinkage int sys_utimes(char * filename, struct timeval * utimes) +asmlinkage long sys_utimes(char * filename, struct timeval * utimes) { int error; struct dentry * dentry; @@ -278,7 +308,7 @@ * We do this by temporarily clearing all FS-related capabilities and * switching the fsuid/fsgid around to the real ones. */ -asmlinkage int sys_access(const char * filename, int mode) +asmlinkage long sys_access(const char * filename, int mode) { struct dentry * dentry; int old_fsuid, old_fsgid; @@ -319,7 +349,7 @@ return res; } -asmlinkage int sys_chdir(const char * filename) +asmlinkage long sys_chdir(const char * filename) { int error; struct inode *inode; @@ -354,7 +384,7 @@ return error; } -asmlinkage int sys_fchdir(unsigned int fd) +asmlinkage long sys_fchdir(unsigned int fd) { struct file *file; struct dentry *dentry; @@ -391,7 +421,7 @@ return error; } -asmlinkage int sys_chroot(const char * filename) +asmlinkage long sys_chroot(const char * filename) { int error; struct inode *inode; @@ -431,7 +461,7 @@ return error; } -asmlinkage int sys_fchmod(unsigned int fd, mode_t mode) +asmlinkage long sys_fchmod(unsigned int fd, mode_t mode) { struct inode * inode; struct dentry * dentry; @@ -469,7 +499,7 @@ return err; } -asmlinkage int sys_chmod(const char * filename, mode_t mode) +asmlinkage long sys_chmod(const char * filename, mode_t mode) { struct dentry * dentry; struct inode * inode; @@ -565,7 +595,7 @@ return error; } -asmlinkage int sys_chown(const char * filename, uid_t user, gid_t group) +asmlinkage long sys_chown(const char * filename, uid_t user, gid_t group) { struct dentry * dentry; int error; @@ -582,7 +612,7 @@ return error; } -asmlinkage int sys_lchown(const char * filename, uid_t user, gid_t group) +asmlinkage long sys_lchown(const char * filename, uid_t user, gid_t group) { struct dentry * dentry; int error; @@ -600,7 +630,7 @@ } -asmlinkage int sys_fchown(unsigned int fd, uid_t user, gid_t group) +asmlinkage long sys_fchown(unsigned int fd, uid_t user, gid_t group) { struct dentry * dentry; struct file * file; @@ -760,6 +790,9 @@ char * tmp; int fd, error; +#if BITS_PER_LONG != 32 + flags |= O_LARGEFILE; +#endif tmp = getname(filename); fd = PTR_ERR(tmp); if (!IS_ERR(tmp)) { @@ -790,7 +823,7 @@ * For backward compatibility? Maybe this should be moved * into arch/i386 instead? */ -asmlinkage int sys_creat(const char * pathname, int mode) +asmlinkage long sys_creat(const char * pathname, int mode) { return sys_open(pathname, O_CREAT | O_WRONLY | O_TRUNC, mode); } @@ -863,7 +896,7 @@ * This routine simulates a hangup on the tty, to arrange that users * are given clean terminals at login time. */ -asmlinkage int sys_vhangup(void) +asmlinkage long sys_vhangup(void) { int ret = -EPERM; diff -urN ref/fs/proc/array.c lfs/fs/proc/array.c --- ref/fs/proc/array.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/proc/array.c Sat Apr 8 19:56:12 2000 @@ -1155,11 +1155,11 @@ * + (index into the line) */ /* for systems with sizeof(void*) == 4: */ -#define MAPS_LINE_FORMAT4 "%08lx-%08lx %s %08lx %s %lu" -#define MAPS_LINE_MAX4 49 /* sum of 8 1 8 1 4 1 8 1 5 1 10 1 */ +#define MAPS_LINE_FORMAT4 "%08lx-%08lx %s %016Lx %s %lu" +#define MAPS_LINE_MAX4 57 /* sum of 8 1 8 1 4 1 16 1 5 1 10 1 */ /* for systems with sizeof(void*) == 8: */ -#define MAPS_LINE_FORMAT8 "%016lx-%016lx %s %016lx %s %lu" +#define MAPS_LINE_FORMAT8 "%016lx-%016lx %s %016Lx %s %lu" #define MAPS_LINE_MAX8 73 /* sum of 16 1 16 1 4 1 16 1 5 1 10 1 */ #define MAPS_LINE_MAX MAPS_LINE_MAX8 diff -urN ref/fs/read_write.c lfs/fs/read_write.c --- ref/fs/read_write.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/read_write.c Sat Apr 8 19:56:12 2000 @@ -39,6 +39,10 @@ static inline loff_t llseek(struct file *file, loff_t offset, int origin) { loff_t (*fn)(struct file *, loff_t, int); + umode_t mode = file->f_dentry->d_inode->i_mode; + + if (S_ISFIFO(mode) || S_ISSOCK(mode)) + return -ESPIPE; fn = default_llseek; if (file->f_op && file->f_op->llseek) @@ -48,7 +52,7 @@ asmlinkage off_t sys_lseek(unsigned int fd, off_t offset, unsigned int origin) { - off_t retval; + off_t retval, oldpos; struct file * file; struct dentry * dentry; struct inode * inode; @@ -62,9 +66,19 @@ if (!(dentry = file->f_dentry) || !(inode = dentry->d_inode)) goto out_putf; + oldpos = file->f_pos; retval = -EINVAL; if (origin <= 2) retval = llseek(file, offset, origin); + + /* Demand L-F-S compliance only from normal files, + thus raw devices can do whatever they please.. */ + if (retval >= 0 && S_ISREG(inode->i_mode) && + !(file->f_flags & O_LARGEFILE) && + file->f_pos >= 0x7ffffffeULL) { + file->f_pos = oldpos; + retval = -EOVERFLOW; + } out_putf: fput(file); bad: @@ -81,7 +95,7 @@ struct file * file; struct dentry * dentry; struct inode * inode; - loff_t offset; + loff_t offset, oldpos; lock_kernel(); retval = -EBADF; @@ -96,6 +110,7 @@ if (origin > 2) goto out_putf; + oldpos = file->f_pos; offset = llseek(file, ((loff_t) offset_high << 32) | offset_low, origin); @@ -105,6 +120,14 @@ if (!copy_to_user(result, &offset, sizeof(offset))) retval = 0; } + if (!(file->f_flags & O_LARGEFILE) && S_ISREG(inode->i_mode) && + file->f_pos >= 0x7ffffffeULL) { + /* The target position isn't presentable without + O_LARGEFILE flag being set --> yield error, and + restore the file position. */ + file->f_pos = oldpos; + retval = -EOVERFLOW; + } out_putf: fput(file); bad: @@ -325,6 +348,7 @@ ssize_t ret; struct file * file; ssize_t (*read)(struct file *, char *, size_t, loff_t *); + struct inode * inode; lock_kernel(); @@ -332,10 +356,30 @@ file = fget(fd); if (!file) goto bad_file; + + inode = file->f_dentry->d_inode; + if (!(file->f_mode & FMODE_READ)) goto out; - ret = locks_verify_area(FLOCK_VERIFY_READ, file->f_dentry->d_inode, - file, pos, count); + + /* Start position must be non-negative! */ + if (pos < 0) { + ret = -EINVAL; + goto out; + } + /* Read starting from beyond the end of file ? */ + if (inode->i_size <= pos) { + ret = -EOVERFLOW; + goto out; + } + + if (!(file->f_flags & O_LARGEFILE) && S_ISREG(inode->i_mode) && + file->f_pos >= 0x7ffffffeULL) { + ret = -EOVERFLOW; + goto out; + } + + ret = locks_verify_area(FLOCK_VERIFY_READ, inode, file, pos, count); if (ret) goto out; ret = -EINVAL; @@ -357,6 +401,7 @@ ssize_t ret; struct file * file; ssize_t (*write)(struct file *, const char *, size_t, loff_t *); + struct inode * inode; lock_kernel(); @@ -366,8 +411,21 @@ goto bad_file; if (!(file->f_mode & FMODE_WRITE)) goto out; - ret = locks_verify_area(FLOCK_VERIFY_WRITE, file->f_dentry->d_inode, - file, pos, count); + /* Start position must be non-negative! */ + if (pos < 0) { + ret = -EINVAL; + goto out; + } + + inode = file->f_dentry->d_inode; + + if (!(file->f_flags & O_LARGEFILE) && S_ISREG(inode->i_mode) && + file->f_pos >= 0x7ffffffeULL) { + ret = -EOVERFLOW; + goto out; + } + + ret = locks_verify_area(FLOCK_VERIFY_WRITE, inode, file, pos, count); if (ret) goto out; ret = -EINVAL; @@ -376,9 +434,9 @@ if (pos < 0) goto out; - down(&file->f_dentry->d_inode->i_sem); + down(&inode->i_sem); ret = write(file, buf, count, &pos); - up(&file->f_dentry->d_inode->i_sem); + up(&inode->i_sem); out: fput(file); diff -urN ref/fs/romfs/inode.c lfs/fs/romfs/inode.c --- ref/fs/romfs/inode.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/romfs/inode.c Sat Apr 8 19:56:12 2000 @@ -396,7 +396,7 @@ buf = page_address(page); clear_bit(PG_uptodate, &page->flags); clear_bit(PG_error, &page->flags); - offset = page->offset; + offset = pgoff2loff(page->index); if (offset < inode->i_size) { avail = inode->i_size-offset; readlen = min(avail, PAGE_SIZE); diff -urN ref/fs/smbfs/cache.c lfs/fs/smbfs/cache.c --- ref/fs/smbfs/cache.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/smbfs/cache.c Sat Apr 8 19:56:12 2000 @@ -41,14 +41,13 @@ printk("smb_get_dircache: finding cache for %s/%s\n", dentry->d_parent->d_name.name, dentry->d_name.name); #endif - cachep = (struct cache_head *) get_cached_page(inode, 0, 1); + cachep = (struct cache_head *) get_cached_page(inode,ulong2pgoff(0),1); if (!cachep) goto out; if (cachep->valid) { struct cache_index * index = cachep->index; struct cache_block * block; - unsigned long offset; int i; cachep->valid = 0; @@ -62,9 +61,10 @@ printk("smb_get_dircache: cache %s/%s has existing block!\n", dentry->d_parent->d_name.name, dentry->d_name.name); #endif - offset = PAGE_SIZE + (i << PAGE_SHIFT); - block = (struct cache_block *) get_cached_page(inode, - offset, 0); + /* byte_offset = PAGE_SIZE + (i << PAGE_SHIFT); */ + /* --> page_offset = 1 + i */ + block = (struct cache_block *) + get_cached_page(inode, ulong2pgoff(i+1), 0); if (!block) goto out; index->block = block; @@ -135,7 +135,7 @@ struct inode * inode = get_cache_inode(cachep); struct cache_index * index; struct cache_block * block; - unsigned long page_off; + pgoff_t page_off; unsigned int nent, offset, len = entry->len; unsigned int needed = len + sizeof(struct cache_entry); @@ -191,7 +191,8 @@ */ get_block: cachep->pages++; - page_off = PAGE_SIZE + (cachep->idx << PAGE_SHIFT); + /* page_byte_off = PAGE_SIZE + (cachep->idx << PAGE_SHIFT); */ + page_off = ulong2pgoff(1 + cachep->idx); block = (struct cache_block *) get_cached_page(inode, page_off, 1); if (block) { @@ -199,7 +200,7 @@ index->space = PAGE_SIZE; #ifdef SMBFS_DEBUG_VERBOSE printk("smb_add_to_cache: inode=%p, pages=%d, block at %ld\n", -inode, cachep->pages, page_off); +inode, cachep->pages, (u_long)pgoff2loff(page_off)); #endif goto add_entry; } diff -urN ref/fs/smbfs/file.c lfs/fs/smbfs/file.c --- ref/fs/smbfs/file.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/smbfs/file.c Sat Apr 8 19:56:12 2000 @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -56,7 +57,7 @@ smb_readpage_sync(struct dentry *dentry, struct page *page) { char *buffer = (char *) page_address(page); - unsigned long offset = page->offset; + loff_t loffset = pgoff2loff(page->index); int rsize = smb_get_rsize(server_from_dentry(dentry)); int count = PAGE_SIZE; int result; @@ -64,8 +65,8 @@ clear_bit(PG_error, &page->flags); #ifdef SMBFS_DEBUG_VERBOSE -printk("smb_readpage_sync: file %s/%s, count=%d@%ld, rsize=%d\n", -dentry->d_parent->d_name.name, dentry->d_name.name, count, offset, rsize); +printk("smb_readpage_sync: file %s/%s, count=%d@%Ld, rsize=%d\n", +dentry->d_parent->d_name.name, dentry->d_name.name, count, loffset, rsize); #endif result = smb_open(dentry, SMB_O_RDONLY); if (result < 0) @@ -81,12 +82,12 @@ if (count < rsize) rsize = count; - result = smb_proc_read(dentry, offset, rsize, buffer); + result = smb_proc_read(dentry, loffset, rsize, buffer); if (result < 0) goto io_error; count -= result; - offset += result; + loffset += result; buffer += result; dentry->d_inode->i_atime = CURRENT_TIME; if (result < rsize) @@ -126,25 +127,40 @@ * Offset is the data offset within the page. */ static int -smb_writepage_sync(struct dentry *dentry, struct page *page, +smb_writepage_sync(struct file *file, struct page *page, unsigned long offset, unsigned int count) { + struct dentry * dentry = file->f_dentry; struct inode *inode = dentry->d_inode; u8 *buffer = (u8 *) page_address(page) + offset; int wsize = smb_get_wsize(server_from_dentry(dentry)); int result, written = 0; + loff_t loffset = pgoff2loff(page->index) + offset; - offset += page->offset; #ifdef SMBFS_DEBUG_VERBOSE printk("smb_writepage_sync: file %s/%s, count=%d@%ld, wsize=%d\n", -dentry->d_parent->d_name.name, dentry->d_name.name, count, offset, wsize); + dentry->d_parent->d_name.name, dentry->d_name.name, count, + loffset, wsize); #endif + if (!(file->f_flags & O_LARGEFILE) && + loffset >= 0x7ffffffeULL) + return -EFBIG; + + if (!(file->f_flags & O_LARGEFILE) && + loffset + count >= 0x7fffffffULL) + count = LONG_MAX - loffset; + + if (loffset >= 0xffffffffULL) /* 4G-1 ??? Or 2G-1 ??? */ + return -EFBIG; + if ((loffset + count) >= 0xffffffffULL) + count = 0xffffffffULL - loffset; + do { if (count < wsize) wsize = count; - result = smb_proc_write(dentry, offset, wsize, buffer); + result = smb_proc_write(dentry, loffset, wsize, buffer); if (result < 0) break; /* N.B. what if result < wsize?? */ @@ -152,29 +168,27 @@ if (result < wsize) printk("smb_writepage_sync: short write, wsize=%d, result=%d\n", wsize, result); #endif - buffer += wsize; - offset += wsize; + buffer += wsize; + loffset += wsize; written += wsize; - count -= wsize; + count -= wsize; /* * Update the inode now rather than waiting for a refresh. */ inode->i_mtime = inode->i_atime = CURRENT_TIME; - if (offset > inode->i_size) - inode->i_size = offset; + if (loffset > inode->i_size) + inode->i_size = loffset; inode->u.smbfs_i.cache_valid |= SMB_F_LOCALWRITE; } while (count); return written ? written : result; } /* - * Write a page to the server. This will be used for NFS swapping only - * (for now), and we currently do this synchronously only. + * Write a page to the server. */ static int smb_writepage(struct file *file, struct page *page) { - struct dentry *dentry = file->f_dentry; int result; #ifdef SMBFS_PARANOIA @@ -183,7 +197,7 @@ #endif set_bit(PG_locked, &page->flags); atomic_inc(&page->count); - result = smb_writepage_sync(dentry, page, 0, PAGE_SIZE); + result = smb_writepage_sync(file, page, 0, PAGE_SIZE); smb_unlock_page(page); free_page(page_address(page)); return result; @@ -194,11 +208,11 @@ { struct dentry *dentry = file->f_dentry; - pr_debug("SMBFS: smb_updatepage(%s/%s %d@%ld, sync=%d)\n", + pr_debug("SMBFS: smb_updatepage(%s/%s %d@%Ld, sync=%d)\n", dentry->d_parent->d_name.name, dentry->d_name.name, - count, page->offset+offset, sync); + count, pgoff2loff(page->index)+offset, sync); - return smb_writepage_sync(dentry, page, offset, count); + return smb_writepage_sync(file, page, offset, count); } static ssize_t @@ -208,9 +222,9 @@ ssize_t status; #ifdef SMBFS_DEBUG_VERBOSE -printk("smb_file_read: file %s/%s, count=%lu@%lu\n", -dentry->d_parent->d_name.name, dentry->d_name.name, -(unsigned long) count, (unsigned long) *ppos); +printk("smb_file_read: file %s/%s, count=%lu@%Lu\n", + dentry->d_parent->d_name.name, dentry->d_name.name, + (unsigned long) count, *ppos); #endif status = smb_revalidate_inode(dentry); @@ -241,7 +255,8 @@ #ifdef SMBFS_DEBUG_VERBOSE printk("smb_file_mmap: file %s/%s, address %lu - %lu\n", -dentry->d_parent->d_name.name, dentry->d_name.name, vma->vm_start, vma->vm_end); + dentry->d_parent->d_name.name, dentry->d_name.name, + vma->vm_start, vma->vm_end); #endif status = smb_revalidate_inode(dentry); @@ -249,7 +264,7 @@ { #ifdef SMBFS_PARANOIA printk("smb_file_mmap: %s/%s validation failed, error=%d\n", -dentry->d_parent->d_name.name, dentry->d_name.name, status); + dentry->d_parent->d_name.name, dentry->d_name.name, status); #endif goto out; } @@ -268,9 +283,9 @@ ssize_t result; #ifdef SMBFS_DEBUG_VERBOSE -printk("smb_file_write: file %s/%s, count=%lu@%lu, pages=%ld\n", -dentry->d_parent->d_name.name, dentry->d_name.name, -(unsigned long) count, (unsigned long) *ppos, dentry->d_inode->i_nrpages); +printk("smb_file_write: file %s/%s, count=%lu@%Lu, pages=%ld\n", + dentry->d_parent->d_name.name, dentry->d_name.name, + (unsigned long) count, *ppos, dentry->d_inode->i_nrpages); #endif result = smb_revalidate_inode(dentry); @@ -278,7 +293,7 @@ { #ifdef SMBFS_PARANOIA printk("smb_file_write: %s/%s validation failed, error=%d\n", -dentry->d_parent->d_name.name, dentry->d_name.name, result); + dentry->d_parent->d_name.name, dentry->d_name.name, result); #endif goto out; } @@ -291,9 +306,9 @@ { result = generic_file_write(file, buf, count, ppos); #ifdef SMBFS_DEBUG_VERBOSE -printk("smb_file_write: pos=%ld, size=%ld, mtime=%ld, atime=%ld\n", -(long) file->f_pos, dentry->d_inode->i_size, dentry->d_inode->i_mtime, -dentry->d_inode->i_atime); +printk("smb_file_write: pos=%Ld, size=%ld, mtime=%ld, atime=%ld\n", + file->f_pos, dentry->d_inode->i_size, dentry->d_inode->i_mtime, + dentry->d_inode->i_atime); #endif } out: diff -urN ref/fs/smbfs/proc.c lfs/fs/smbfs/proc.c --- ref/fs/smbfs/proc.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/smbfs/proc.c Sat Apr 8 19:56:12 2000 @@ -1008,13 +1008,16 @@ file-id would not be valid after a reconnection. */ int -smb_proc_read(struct dentry *dentry, off_t offset, int count, char *data) +smb_proc_read(struct dentry *dentry, loff_t offset, int count, char *data) { struct smb_sb_info *server = server_from_dentry(dentry); __u16 returned_count, data_len; char *buf; int result; + if (offset > 0xffffffff) + return -EIO; + smb_lock_server(server); smb_setup_header(server, SMBread, 5, 0); buf = server->packet; @@ -1050,14 +1053,17 @@ } int -smb_proc_write(struct dentry *dentry, off_t offset, int count, const char *data) +smb_proc_write(struct dentry *dentry, loff_t offset, int count, const char *data) { struct smb_sb_info *server = server_from_dentry(dentry); int result; __u8 *p; + if (offset > 0xffffffff) + return -EIO; + #if SMBFS_DEBUG_VERBOSE -printk("smb_proc_write: file %s/%s, count=%d@%ld, packet_size=%d\n", +printk("smb_proc_write: file %s/%s, count=%d@%Ld, packet_size=%d\n", DENTRY_PATH(dentry), count, offset, server->packet_size); #endif smb_lock_server(server); @@ -1805,7 +1811,7 @@ fattr->f_mtime = date_dos2unix(server, date, time); #ifdef SMBFS_DEBUG_VERBOSE printk("smb_proc_getattr_ff: name=%s, date=%x, time=%x, mtime=%ld\n", -mask, date, time, fattr->f_mtime); + mask, date, time, fattr->f_mtime); #endif fattr->f_size = DVAL(resp_data, 12); /* ULONG allocation size */ @@ -2063,7 +2069,7 @@ WSET(server->packet, smb_vwv6, time); #ifdef SMBFS_DEBUG_TIMESTAMP printk("smb_proc_setattr_ext: date=%d, time=%d, mtime=%ld\n", -date, time, fattr->f_mtime); + date, time, fattr->f_mtime); #endif result = smb_request_ok(server, SMBsetattrE, 0, 0); diff -urN ref/fs/stat.c lfs/fs/stat.c --- ref/fs/stat.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/stat.c Sat Apr 8 19:56:12 2000 @@ -280,3 +280,124 @@ unlock_kernel(); return error; } + + +/* ---------- LFS-64 ----------- */ +#if !defined(__alpha__) + +static long cp_new_stat64(struct inode * inode, struct stat64 * statbuf) +{ + struct stat64 tmp; + unsigned int blocks, indirect; + + memset(&tmp, 0, sizeof(tmp)); + tmp.st_dev = kdev_t_to_nr(inode->i_dev); + tmp.st_ino = inode->i_ino; + tmp.st_mode = inode->i_mode; + tmp.st_nlink = inode->i_nlink; + tmp.st_uid = inode->i_uid; + tmp.st_gid = inode->i_gid; + tmp.st_rdev = kdev_t_to_nr(inode->i_rdev); + tmp.st_atime = inode->i_atime; + tmp.st_mtime = inode->i_mtime; + tmp.st_ctime = inode->i_ctime; + tmp.st_size = inode->i_size; +/* + * st_blocks and st_blksize are approximated with a simple algorithm if + * they aren't supported directly by the filesystem. The minix and msdos + * filesystems don't keep track of blocks, so they would either have to + * be counted explicitly (by delving into the file itself), or by using + * this simple algorithm to get a reasonable (although not 100% accurate) + * value. + */ + +/* + * Use minix fs values for the number of direct and indirect blocks. The + * count is now exact for the minix fs except that it counts zero blocks. + * Everything is in units of BLOCK_SIZE until the assignment to + * tmp.st_blksize. + */ +#define D_B 7 +#define I_B (BLOCK_SIZE / sizeof(unsigned short)) + + if (!inode->i_blksize) { + blocks = (tmp.st_size + BLOCK_SIZE - 1) >> BLOCK_SIZE_BITS; + if (blocks > D_B) { + indirect = (blocks - D_B + I_B - 1) / I_B; + blocks += indirect; + if (indirect > 1) { + indirect = (indirect - 1 + I_B - 1) / I_B; + blocks += indirect; + if (indirect > 1) + blocks++; + } + } + tmp.st_blocks = (BLOCK_SIZE / 512) * blocks; + tmp.st_blksize = BLOCK_SIZE; + } else { + tmp.st_blocks = inode->i_blocks; + tmp.st_blksize = inode->i_blksize; + } + return copy_to_user(statbuf,&tmp,sizeof(tmp)) ? -EFAULT : 0; +} + +asmlinkage long sys_stat64(char * filename, struct stat64 * statbuf, long flags) +{ + struct dentry * dentry; + int error; + + lock_kernel(); + dentry = namei(filename); + + error = PTR_ERR(dentry); + if (!IS_ERR(dentry)) { + error = do_revalidate(dentry); + if (!error) + error = cp_new_stat64(dentry->d_inode, statbuf); + + dput(dentry); + } + unlock_kernel(); + return error; +} + +asmlinkage long sys_lstat64(char * filename, struct stat64 * statbuf, long flags) +{ + struct dentry * dentry; + int error; + + lock_kernel(); + dentry = lnamei(filename); + + error = PTR_ERR(dentry); + if (!IS_ERR(dentry)) { + error = do_revalidate(dentry); + if (!error) + error = cp_new_stat64(dentry->d_inode, statbuf); + + dput(dentry); + } + unlock_kernel(); + return error; +} + +asmlinkage long sys_fstat64(unsigned long fd, struct stat64 * statbuf, long flags) +{ + struct file * f; + int err = -EBADF; + + lock_kernel(); + f = fget(fd); + if (f) { + struct dentry * dentry = f->f_dentry; + + err = do_revalidate(dentry); + if (!err) + err = cp_new_stat64(dentry->d_inode, statbuf); + fput(f); + } + unlock_kernel(); + return err; +} + +#endif /* LFS-64 */ diff -urN ref/fs/sysv/file.c lfs/fs/sysv/file.c --- ref/fs/sysv/file.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/sysv/file.c Sat Apr 8 19:56:12 2000 @@ -207,7 +207,7 @@ { struct inode * inode = filp->f_dentry->d_inode; struct super_block * sb = inode->i_sb; - off_t pos; + loff_t pos; ssize_t written, c; struct buffer_head * bh; char * p; @@ -232,6 +232,21 @@ else pos = *ppos; written = 0; + + /* L-F-S spec 2.2.1.27: */ + if (!(filp->f_flags & O_LARGEFILE)) { + if (pos >= 0x7ffffffeULL) /* pos@2G forbidden */ + return -EFBIG; + + if (pos + count >= 0x7fffffffULL) + /* Write only until end of allowed region */ + count = 0x7fffffffULL - pos; + } + if (pos >= 0xffffffffULL) + return -EFBIG; /* Only up to 4G-1! */ + if ((pos + count) > 0xffffffffULL) + count = 0xffffffffULL - pos; + while (written> sb->sv_block_size_bits, 1); if (!bh) { diff -urN ref/fs/ufs/balloc.c lfs/fs/ufs/balloc.c --- ref/fs/ufs/balloc.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/ufs/balloc.c Sat Apr 8 19:56:12 2000 @@ -660,9 +660,9 @@ struct ufs_sb_private_info * uspi; struct ufs_super_block_first * usb1; struct ufs_cylinder_group * ucg; - unsigned start, length, location, result; - unsigned possition, fragsize, blockmap, mask; - unsigned swab; + unsigned int start, length, location, result; + unsigned int possition, fragsize, blockmap, mask; + unsigned int swab; UFSD(("ENTER, cg %u, goal %u, count %u\n", ucpi->c_cgx, goal, count)) @@ -676,7 +676,7 @@ else start = ucpi->c_frotor >> 3; - length = howmany(uspi->s_fpg, 8) - start; + length = ((uspi->s_fpg + 7) >> 3) - start; location = ubh_scanc(UCPI_UBH, ucpi->c_freeoff + start, length, (uspi->s_fpb == 8) ? ufs_fragtable_8fpb : ufs_fragtable_other, 1 << (count - 1 + (uspi->s_fpb & 7))); diff -urN ref/fs/ufs/dir.c lfs/fs/ufs/dir.c --- ref/fs/ufs/dir.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/ufs/dir.c Sat Apr 8 19:56:12 2000 @@ -15,6 +15,7 @@ #include #include +#include #include "swab.h" #include "util.h" @@ -170,7 +171,7 @@ error_msg = "inode out of bounds"; if (error_msg != NULL) - ufs_error (sb, function, "bad entry in directory #%lu, size %lu: %s - " + ufs_error (sb, function, "bad entry in directory #%lu, size %Lu: %s - " "offset=%lu, inode=%lu, reclen=%d, namlen=%d", dir->i_ino, dir->i_size, error_msg, offset, (unsigned long) SWAB32(de->d_ino), diff -urN ref/fs/ufs/file.c lfs/fs/ufs/file.c --- ref/fs/ufs/file.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/ufs/file.c Sat Apr 8 19:56:12 2000 @@ -140,7 +140,7 @@ loff_t *ppos ) { struct inode * inode = filp->f_dentry->d_inode; - __u32 pos; + loff_t pos; long block; int offset; int written, c; @@ -177,11 +177,14 @@ return -EINVAL; } - /* Check for overflow.. */ - if (pos > (__u32) (pos + count)) { - count = ~pos; /* == 0xFFFFFFFF - pos */ - if (!count) + /* L-F-S spec 2.2.1.27: */ + if (!(filp->f_flags & O_LARGEFILE)) { + if (pos >= 0x7ffffffeULL) /* pos@2G forbidden */ return -EFBIG; + + if (pos + count >= 0x7fffffffULL) + /* Write only until end of allowed region */ + count = 0x7fffffffULL - pos; } /* diff -urN ref/fs/ufs/inode.c lfs/fs/ufs/inode.c --- ref/fs/ufs/inode.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/ufs/inode.c Sat Apr 8 19:56:12 2000 @@ -54,7 +54,7 @@ { unsigned swab = inode->i_sb->u.ufs_sb.s_swab; printk("ino %lu mode 0%6.6o nlink %d uid %d uid32 %u" - " gid %d gid32 %u size %lu blocks %lu\n", + " gid %d gid32 %u size %Lu blocks %lu\n", inode->i_ino, inode->i_mode, inode->i_nlink, inode->i_uid, inode->u.ufs_i.i_uid, inode->i_gid, inode->u.ufs_i.i_gid, inode->i_size, inode->i_blocks); @@ -213,13 +213,14 @@ if (!create) return NULL; limit = current->rlim[RLIMIT_FSIZE].rlim_cur; - if (limit < RLIM_INFINITY) { + if (limit != RLIM_INFINITY) { limit >>= sb->s_blocksize_bits; if (new_fragment >= limit) { send_sig(SIGXFSZ, current, 0); return NULL; } } + lastblock = ufs_fragstoblks (lastfrag); lastblockoff = ufs_fragnum (lastfrag); /* @@ -321,7 +322,8 @@ brelse (result); goto repeat; } - if (!create || new_fragment >= (current->rlim[RLIMIT_FSIZE].rlim_cur >> sb->s_blocksize)) { + if (!create || (current->rlim[RLIMIT_FSIZE].rlim_cur != RLIM_INFINITY && + new_fragment >= (current->rlim[RLIMIT_FSIZE].rlim_cur >> sb->s_blocksize))) { brelse (bh); *err = -EFBIG; return NULL; @@ -496,13 +498,10 @@ } /* - * Linux i_size can be 32 on some architectures. We will mark - * big files as read only and let user access first 32 bits. + * Linux i_size used to be 32 bits on some architectures. + * These days we allow access to the entire file as is.. */ - inode->u.ufs_i.i_size = SWAB64(ufs_inode->ui_size); - inode->i_size = (off_t) inode->u.ufs_i.i_size; - if (sizeof(off_t) == 4 && (inode->u.ufs_i.i_size >> 32)) - inode->i_size = (__u32)-1; + inode->i_size = SWAB64(ufs_inode->ui_size); inode->i_atime = SWAB32(ufs_inode->ui_atime.tv_sec); inode->i_ctime = SWAB32(ufs_inode->ui_ctime.tv_sec); @@ -515,7 +514,7 @@ inode->u.ufs_i.i_gen = SWAB32(ufs_inode->ui_gen); inode->u.ufs_i.i_shadow = SWAB32(ufs_inode->ui_u3.ui_sun.ui_shadow); inode->u.ufs_i.i_oeftflag = SWAB32(ufs_inode->ui_u3.ui_sun.ui_oeftflag); - inode->u.ufs_i.i_lastfrag = howmany (inode->i_size, uspi->s_fsize); + inode->u.ufs_i.i_lastfrag = (inode->i_size + uspi->s_fsize -1) >> uspi->s_fshift; if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) inode->i_rdev = to_kdev_t(SWAB32(ufs_inode->ui_u2.ui_addr.ui_db[0])); diff -urN ref/fs/ufs/super.c lfs/fs/ufs/super.c --- ref/fs/ufs/super.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/ufs/super.c Sat Apr 8 19:56:12 2000 @@ -328,7 +328,7 @@ * on the device. */ size = uspi->s_cssize; - blks = howmany(size, uspi->s_fsize); + blks = (size + uspi->s_fsize-1) >> uspi->s_fshift; base = space = kmalloc(size, GFP_KERNEL); if (!base) goto failed; @@ -405,7 +405,7 @@ uspi = sb->u.ufs_sb.s_uspi; size = uspi->s_cssize; - blks = howmany(size, uspi->s_fsize); + blks = (size + uspi->s_fsize-1) >> uspi->s_fshift; base = space = (char*) sb->u.ufs_sb.s_csp[0]; for (i = 0; i < blks; i += uspi->s_fpb) { size = uspi->s_bsize; diff -urN ref/fs/ufs/truncate.c lfs/fs/ufs/truncate.c --- ref/fs/ufs/truncate.c Sat Apr 8 19:56:02 2000 +++ lfs/fs/ufs/truncate.c Sat Apr 8 19:56:12 2000 @@ -59,8 +59,8 @@ * Linus */ -#define DIRECT_BLOCK howmany (inode->i_size, uspi->s_bsize) -#define DIRECT_FRAGMENT howmany (inode->i_size, uspi->s_fsize) +#define DIRECT_BLOCK ((inode->i_size + uspi->s_bsize -1) >> uspi->s_bshift) +#define DIRECT_FRAGMENT ((inode->i_size + uspi->s_fsize -1) >> uspi->s_fshift) static int ufs_trunc_direct (struct inode * inode) { @@ -194,7 +194,7 @@ } -static int ufs_trunc_indirect (struct inode * inode, unsigned offset, u32 * p) +static int ufs_trunc_indirect (struct inode * inode, u_long offset, u32 * p) { struct super_block * sb; struct ufs_sb_private_info * uspi; @@ -297,7 +297,7 @@ struct super_block * sb; struct ufs_sb_private_info * uspi; struct ufs_buffer_head * dind_bh; - unsigned i, tmp, dindirect_block; + unsigned int i, tmp, dindirect_block; u32 * dind; int retry = 0; unsigned swab; @@ -308,8 +308,8 @@ swab = sb->u.ufs_sb.s_swab; uspi = sb->u.ufs_sb.s_uspi; - dindirect_block = (DIRECT_BLOCK > offset) - ? ((DIRECT_BLOCK - offset) / uspi->s_apb) : 0; + dindirect_block = ((DIRECT_BLOCK > offset) ? + ((DIRECT_BLOCK - offset) >> uspi->s_apbshift) : 0); retry = 0; tmp = SWAB32(*p); @@ -379,7 +379,7 @@ retry = 0; tindirect_block = (DIRECT_BLOCK > (UFS_NDADDR + uspi->s_apb + uspi->s_2apb)) - ? ((DIRECT_BLOCK - UFS_NDADDR - uspi->s_apb - uspi->s_2apb) / uspi->s_2apb) : 0; + ? ((DIRECT_BLOCK - UFS_NDADDR - uspi->s_apb - uspi->s_2apb) >> uspi->s_2apbshift) : 0; p = inode->u.ufs_i.i_u1.i_data + UFS_TIND_BLOCK; if (!(tmp = SWAB32(*p))) return 0; @@ -467,7 +467,8 @@ } } inode->i_mtime = inode->i_ctime = CURRENT_TIME; - inode->u.ufs_i.i_lastfrag = howmany (inode->i_size, uspi->s_fsize); + inode->u.ufs_i.i_lastfrag = + (inode->i_size + uspi->s_fsize -1) >> uspi->s_fshift; mark_inode_dirty(inode); UFSD(("EXIT\n")) } diff -urN ref/fs/ufs/util.h lfs/fs/ufs/util.h --- ref/fs/ufs/util.h Sat Apr 8 19:56:02 2000 +++ lfs/fs/ufs/util.h Sat Apr 8 19:56:12 2000 @@ -14,7 +14,6 @@ * some useful macros */ #define in_range(b,first,len) ((b)>=(first)&&(b)<(first)+(len)) -#define howmany(x,y) (((x)+(y)-1)/(y)) #define min(x,y) ((x)<(y)?(x):(y)) #define max(x,y) ((x)>(y)?(x):(y)) diff -urN ref/include/asm-alpha/fcntl.h lfs/include/asm-alpha/fcntl.h --- ref/include/asm-alpha/fcntl.h Sat Apr 8 19:56:02 2000 +++ lfs/include/asm-alpha/fcntl.h Sat Apr 8 19:56:12 2000 @@ -20,6 +20,7 @@ #define O_DIRECT 040000 /* direct disk access - should check with OSF/1 */ #define O_DIRECTORY 0100000 /* must be a directory */ #define O_NOFOLLOW 0200000 /* don't follow links */ +#define O_LARGEFILE 0400000 /* will be set by the kernel on every open */ #define F_DUPFD 0 /* dup */ #define F_GETFD 1 /* get f_flags */ @@ -61,5 +62,9 @@ __kernel_off_t l_len; __kernel_pid_t l_pid; }; + +#ifdef __KERNEL__ +#define flock64 flock +#endif #endif diff -urN ref/include/asm-arm/fcntl.h lfs/include/asm-arm/fcntl.h --- ref/include/asm-arm/fcntl.h Sat Apr 8 19:56:02 2000 +++ lfs/include/asm-arm/fcntl.h Sat Apr 8 19:56:12 2000 @@ -18,6 +18,8 @@ #define FASYNC 020000 /* fcntl, for BSD compatibility */ #define O_DIRECTORY 040000 /* must be a directory */ #define O_NOFOLLOW 0100000 /* don't follow links */ +#define O_DIRECT 0200000 /* direct disk access hint - currently ignored */ +#define O_LARGEFILE 0400000 #define F_DUPFD 0 /* dup */ #define F_GETFD 1 /* get f_flags */ @@ -33,6 +35,10 @@ #define F_SETSIG 10 /* for sockets. */ #define F_GETSIG 11 /* for sockets. */ +#define F_GETLK64 12 /* using 'struct flock64' */ +#define F_SETLK64 13 +#define F_SETLKW64 14 + /* for F_[GET|SET]FL */ #define FD_CLOEXEC 1 /* actually anything with low bit set goes */ @@ -58,6 +64,14 @@ off_t l_start; off_t l_len; pid_t l_pid; +}; + +struct flock64 { + short l_type; + short l_whence; + loff_t l_start; + loff_t l_len; + pid_t l_pid; }; #endif diff -urN ref/include/asm-arm/stat.h lfs/include/asm-arm/stat.h --- ref/include/asm-arm/stat.h Sat Apr 8 19:56:02 2000 +++ lfs/include/asm-arm/stat.h Sat Apr 8 19:56:12 2000 @@ -38,4 +38,5 @@ unsigned long __unused5; }; +/* Someone please add a glibc/arm compatible stat64 struct here. */ #endif diff -urN ref/include/asm-arm/unistd.h lfs/include/asm-arm/unistd.h --- ref/include/asm-arm/unistd.h Sat Apr 8 19:56:02 2000 +++ lfs/include/asm-arm/unistd.h Sat Apr 8 19:56:12 2000 @@ -198,6 +198,13 @@ /* 188 reserved */ /* 189 reserved */ #define __NR_vfork (__NR_SYSCALL_BASE+190) +/* #define __NR_getrlimit (__NR_SYSCALL_BASE+191) */ +#define __NR_mmap2 (__NR_SYSCALL_BASE+192) +#define __NR_truncate64 (__NR_SYSCALL_BASE+193) +#define __NR_ftruncate64 (__NR_SYSCALL_BASE+194) +#define __NR_stat64 (__NR_SYSCALL_BASE+195) +#define __NR_lstat64 (__NR_SYSCALL_BASE+196) +#define __NR_fstat64 (__NR_SYSCALL_BASE+197) #define __sys2(x) #x #define __sys1(x) __sys2(x) diff -urN ref/include/asm-i386/fcntl.h lfs/include/asm-i386/fcntl.h --- ref/include/asm-i386/fcntl.h Sat Apr 8 19:56:02 2000 +++ lfs/include/asm-i386/fcntl.h Sat Apr 8 19:56:12 2000 @@ -35,6 +35,10 @@ #define F_SETSIG 10 /* for sockets. */ #define F_GETSIG 11 /* for sockets. */ +#define F_GETLK64 12 /* using 'struct flock64' */ +#define F_SETLK64 13 +#define F_SETLKW64 14 + /* for F_[GET|SET]FL */ #define FD_CLOEXEC 1 /* actually anything with low bit set goes */ @@ -60,6 +64,14 @@ off_t l_start; off_t l_len; pid_t l_pid; +}; + +struct flock64 { + short l_type; + short l_whence; + loff_t l_start; + loff_t l_len; + pid_t l_pid; }; #endif diff -urN ref/include/asm-i386/stat.h lfs/include/asm-i386/stat.h --- ref/include/asm-i386/stat.h Sat Apr 8 19:56:02 2000 +++ lfs/include/asm-i386/stat.h Sat Apr 8 19:56:12 2000 @@ -38,4 +38,40 @@ unsigned long __unused5; }; +/* This matches struct stat64 in glibc2.1, hence the absolutely + * insane amounts of padding around dev_t's. + */ +struct stat64 { + unsigned short st_dev; + unsigned char __pad0[10]; + + unsigned long st_ino; + unsigned int st_mode; + unsigned int st_nlink; + + unsigned long st_uid; + unsigned long st_gid; + + unsigned short st_rdev; + unsigned char __pad3[10]; + + long long st_size; + unsigned long st_blksize; + + unsigned long st_blocks; /* Number 512-byte blocks allocated. */ + unsigned long __pad4; /* future possible st_blocks high bits */ + + unsigned long st_atime; + unsigned long __pad5; + + unsigned long st_mtime; + unsigned long __pad6; + + unsigned long st_ctime; + unsigned long __pad7; /* will be high 32 bits of ctime someday */ + + unsigned long __unused1; + unsigned long __unused2; +}; + #endif diff -urN ref/include/asm-i386/unistd.h lfs/include/asm-i386/unistd.h --- ref/include/asm-i386/unistd.h Sat Apr 8 19:56:02 2000 +++ lfs/include/asm-i386/unistd.h Sat Apr 8 19:56:12 2000 @@ -80,7 +80,7 @@ #define __NR_sigpending 73 #define __NR_sethostname 74 #define __NR_setrlimit 75 -#define __NR_getrlimit 76 +#define __NR_getrlimit 76 /* Back compatible 2Gig limited rlimit */ #define __NR_getrusage 77 #define __NR_gettimeofday 78 #define __NR_settimeofday 79 @@ -195,8 +195,15 @@ #define __NR_getpmsg 188 /* some people actually want streams */ #define __NR_putpmsg 189 /* some people actually want streams */ #define __NR_vfork 190 +/* #define __NR_ugetrlimit 191 SuS compliant getrlimit */ +#define __NR_mmap2 192 +#define __NR_truncate64 193 +#define __NR_ftruncate64 194 +#define __NR_stat64 195 +#define __NR_lstat64 196 +#define __NR_fstat64 197 -/* user-visible error numbers are in the range -1 - -122: see */ +/* user-visible error numbers are in the range -1 - -124: see */ #define __syscall_return(type, res) \ do { \ @@ -269,6 +276,19 @@ : "=a" (__res) \ : "0" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \ "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5))); \ +__syscall_return(type,__res); \ +} + +#define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4, \ + type5,arg5,type6,arg6) \ +type name (type1 arg1,type2 arg2,type3 arg3,type4 arg4,type5 arg5,type6 arg6) \ +{ \ +long __res; \ +__asm__ volatile ("push %%ebp ; movl %%eax,%%ebp ; movl %1,%%eax ; int $0x80 ; pop %%ebp" \ + : "=a" (__res) \ + : "i" (__NR_##name),"b" ((long)(arg1)),"c" ((long)(arg2)), \ + "d" ((long)(arg3)),"S" ((long)(arg4)),"D" ((long)(arg5)), \ + "0" ((long)(arg6))); \ __syscall_return(type,__res); \ } diff -urN ref/include/asm-m68k/fcntl.h lfs/include/asm-m68k/fcntl.h --- ref/include/asm-m68k/fcntl.h Sat Apr 8 19:56:02 2000 +++ lfs/include/asm-m68k/fcntl.h Sat Apr 8 19:56:12 2000 @@ -33,6 +33,10 @@ #define F_SETSIG 10 /* for sockets. */ #define F_GETSIG 11 /* for sockets. */ +#define F_GETLK64 12 /* using 'struct flock64' */ +#define F_SETLK64 13 +#define F_SETLKW64 14 + /* for F_[GET|SET]FL */ #define FD_CLOEXEC 1 /* actually anything with low bit set goes */ @@ -58,6 +62,14 @@ off_t l_start; off_t l_len; pid_t l_pid; +}; + +struct flock64 { + short l_type; + short l_whence; + loff_t l_start; + loff_t l_len; + pid_t l_pid; }; #endif /* _M68K_FCNTL_H */ diff -urN ref/include/asm-m68k/stat.h lfs/include/asm-m68k/stat.h --- ref/include/asm-m68k/stat.h Sat Apr 8 19:56:02 2000 +++ lfs/include/asm-m68k/stat.h Sat Apr 8 19:56:12 2000 @@ -38,4 +38,8 @@ unsigned long __unused5; }; +/* stat64 struct goes here -- someone please make + * it mesh with whatever glibc does in userland on + * m68k's. + */ #endif /* _M68K_STAT_H */ diff -urN ref/include/asm-m68k/unistd.h lfs/include/asm-m68k/unistd.h --- ref/include/asm-m68k/unistd.h Sat Apr 8 19:56:02 2000 +++ lfs/include/asm-m68k/unistd.h Sat Apr 8 19:56:12 2000 @@ -80,7 +80,7 @@ #define __NR_sigpending 73 #define __NR_sethostname 74 #define __NR_setrlimit 75 -#define __NR_getrlimit 76 +#define __NR_getrlimit 76 #define __NR_getrusage 77 #define __NR_gettimeofday 78 #define __NR_settimeofday 79 @@ -194,6 +194,13 @@ #define __NR_getpmsg 188 /* some people actually want streams */ #define __NR_putpmsg 189 /* some people actually want streams */ #define __NR_vfork 190 +/* #define __NR_getrlimit 191 */ +#define __NR_mmap2 192 +#define __NR_truncate64 193 +#define __NR_ftruncate64 194 +#define __NR_stat64 195 +#define __NR_lstat64 196 +#define __NR_fstat64 197 /* user-visible error numbers are in the range -1 - -122: see */ diff -urN ref/include/asm-mips/fcntl.h lfs/include/asm-mips/fcntl.h --- ref/include/asm-mips/fcntl.h Sat Apr 8 19:56:02 2000 +++ lfs/include/asm-mips/fcntl.h Sat Apr 8 19:56:42 2000 @@ -44,6 +44,10 @@ #define F_SETSIG 10 /* for sockets. */ #define F_GETSIG 11 /* for sockets. */ +#define F_GETLK64 33 /* using 'struct flock64' */ +#define F_SETLK64 34 +#define F_SETLKW64 35 + /* for F_[GET|SET]FL */ #define FD_CLOEXEC 1 /* actually anything with low bit set goes */ @@ -72,5 +76,13 @@ __kernel_pid_t l_pid; long pad[4]; /* ZZZZZZZZZZZZZZZZZZZZZZZZZZ */ } flock_t; + +typedef struct flock64 { + short l_type; + short l_whence; + loff_t l_start; + loff_t l_len; + pid_t l_pid; +} flock64_t; #endif /* __ASM_MIPS_FCNTL_H */ diff -urN ref/include/asm-ppc/fcntl.h lfs/include/asm-ppc/fcntl.h --- ref/include/asm-ppc/fcntl.h Sat Apr 8 19:56:02 2000 +++ lfs/include/asm-ppc/fcntl.h Sat Apr 8 19:56:12 2000 @@ -18,6 +18,8 @@ #define FASYNC 020000 /* fcntl, for BSD compatibility */ #define O_DIRECTORY 040000 /* must be a directory */ #define O_NOFOLLOW 0100000 /* don't follow links */ +#define O_LARGEFILE 0200000 +#define O_DIRECT 0400000 /* direct disk access hint - currently ignored */ #define F_DUPFD 0 /* dup */ #define F_GETFD 1 /* get f_flags */ @@ -33,6 +35,10 @@ #define F_SETSIG 10 /* for sockets. */ #define F_GETSIG 11 /* for sockets. */ +#define F_GETLK64 12 /* using 'struct flock64' */ +#define F_SETLK64 13 +#define F_SETLKW64 14 + /* for F_[GET|SET]FL */ #define FD_CLOEXEC 1 /* actually anything with low bit set goes */ @@ -64,6 +70,14 @@ off_t l_start; off_t l_len; pid_t l_pid; +}; + +struct flock64 { + short l_type; + short l_whence; + loff_t l_start; + loff_t l_len; + pid_t l_pid; }; #endif diff -urN ref/include/asm-sparc/fcntl.h lfs/include/asm-sparc/fcntl.h --- ref/include/asm-sparc/fcntl.h Sat Apr 8 19:56:02 2000 +++ lfs/include/asm-sparc/fcntl.h Sat Apr 8 19:56:12 2000 @@ -19,6 +19,7 @@ #define O_NOCTTY 0x8000 /* not fcntl */ #define O_DIRECTORY 0x10000 /* must be a directory */ #define O_NOFOLLOW 0x20000 /* don't follow links */ +#define O_LARGEFILE 0x40000 /* LFS */ #define F_DUPFD 0 /* dup */ #define F_GETFD 1 /* get f_flags */ @@ -32,6 +33,9 @@ #define F_SETLKW 9 #define F_SETSIG 10 /* for sockets. */ #define F_GETSIG 11 /* for sockets. */ +#define F_GETLK64 12 +#define F_SETLK64 13 +#define F_SETLKW64 14 /* for F_[GET|SET]FL */ #define FD_CLOEXEC 1 /* actually anything with low bit set goes */ @@ -57,6 +61,15 @@ short l_whence; off_t l_start; off_t l_len; + pid_t l_pid; + short __unused; +}; + +struct flock64 { + short l_type; + short l_whence; + loff_t l_start; + loff_t l_len; pid_t l_pid; short __unused; }; diff -urN ref/include/asm-sparc/stat.h lfs/include/asm-sparc/stat.h --- ref/include/asm-sparc/stat.h Sat Apr 8 19:56:02 2000 +++ lfs/include/asm-sparc/stat.h Sat Apr 8 19:56:12 2000 @@ -1,4 +1,4 @@ -/* $Id: stat.h,v 1.9 1998/07/26 05:24:39 davem Exp $ */ +/* $Id: stat.h,v 1.10 1999/12/21 14:09:41 jj Exp $ */ #ifndef _SPARC_STAT_H #define _SPARC_STAT_H @@ -36,6 +36,42 @@ off_t st_blksize; off_t st_blocks; unsigned long __unused4[2]; +}; + +struct stat64 { + unsigned char __pad0[6]; + unsigned short st_dev; + unsigned char __pad1[4]; + + unsigned int st_ino; + unsigned int st_mode; + unsigned int st_nlink; + + unsigned int st_uid; + unsigned int st_gid; + + unsigned char __pad2[6]; + unsigned short st_rdev; + + unsigned char __pad3[8]; + + long long st_size; + unsigned int st_blksize; + + unsigned char __pad4[8]; + unsigned int st_blocks; + + unsigned int st_atime; + unsigned int __unused1; + + unsigned int st_mtime; + unsigned int __unused2; + + unsigned int st_ctime; + unsigned int __unused3; + + unsigned int __unused4; + unsigned int __unused5; }; #endif diff -urN ref/include/asm-sparc/unistd.h lfs/include/asm-sparc/unistd.h --- ref/include/asm-sparc/unistd.h Sat Apr 8 19:56:02 2000 +++ lfs/include/asm-sparc/unistd.h Sat Apr 8 19:56:12 2000 @@ -71,14 +71,14 @@ /* #define __NR_mctl 53 SunOS specific */ #define __NR_ioctl 54 /* Common */ #define __NR_reboot 55 /* Common */ -/* #define __NR_ni_syscall 56 ENOSYS under SunOS */ +#define __NR_mmap2 56 /* Linux sparc32 Specific */ #define __NR_symlink 57 /* Common */ #define __NR_readlink 58 /* Common */ #define __NR_execve 59 /* Common */ #define __NR_umask 60 /* Common */ #define __NR_chroot 61 /* Common */ #define __NR_fstat 62 /* Common */ -/* #define __NR_ni_syscall 63 ENOSYS under SunOS */ +#define __NR_fstat64 63 /* Linux sparc32 Specific */ #define __NR_getpagesize 64 /* Common */ #define __NR_msync 65 /* Common in newer 1.3.x revs... */ #define __NR_vfork 66 /* Common */ @@ -92,14 +92,14 @@ #define __NR_mprotect 74 /* Common */ /* #define __NR_madvise 75 SunOS Specific */ #define __NR_vhangup 76 /* Common */ -/* #define __NR_ni_syscall 77 ENOSYS under SunOS */ +#define __NR_truncate64 77 /* Linux sparc32 Specific */ /* #define __NR_mincore 78 SunOS Specific */ #define __NR_getgroups 79 /* Common */ #define __NR_setgroups 80 /* Common */ #define __NR_getpgrp 81 /* Common */ /* #define __NR_setpgrp 82 setpgid, same difference... */ #define __NR_setitimer 83 /* Common */ -/* #define __NR_ni_syscall 84 ENOSYS under SunOS */ +#define __NR_ftruncate64 84 /* Linux sparc32 Specific */ #define __NR_swapon 85 /* Common */ #define __NR_getitimer 86 /* Common */ /* #define __NR_gethostname 87 SunOS Specific */ @@ -147,14 +147,14 @@ #define __NR_truncate 129 /* Common */ #define __NR_ftruncate 130 /* Common */ #define __NR_flock 131 /* Common */ -/* #define __NR_ni_syscall 132 ENOSYS under SunOS */ +#define __NR_lstat64 132 /* Linux sparc32 Specific */ #define __NR_sendto 133 /* Common */ #define __NR_shutdown 134 /* Common */ #define __NR_socketpair 135 /* Common */ #define __NR_mkdir 136 /* Common */ #define __NR_rmdir 137 /* Common */ #define __NR_utimes 138 /* SunOS Specific */ -/* #define __NR_ni_syscall 139 ENOSYS under SunOS */ +#define __NR_stat64 139 /* Linux sparc32 Specific */ /* #define __NR_adjtime 140 SunOS Specific */ #define __NR_getpeername 141 /* Common */ /* #define __NR_gethostid 142 SunOS Specific */ diff -urN ref/include/asm-sparc64/fcntl.h lfs/include/asm-sparc64/fcntl.h --- ref/include/asm-sparc64/fcntl.h Sat Apr 8 19:56:02 2000 +++ lfs/include/asm-sparc64/fcntl.h Sat Apr 8 19:56:12 2000 @@ -19,6 +19,7 @@ #define O_NOCTTY 0x8000 /* not fcntl */ #define O_DIRECTORY 0x10000 /* must be a directory */ #define O_NOFOLLOW 0x20000 /* don't follow links */ +#define O_LARGEFILE 0x40000 #define F_DUPFD 0 /* dup */ #define F_GETFD 1 /* get f_flags */ @@ -32,6 +33,11 @@ #define F_SETLKW 9 #define F_SETSIG 10 /* for sockets. */ #define F_GETSIG 11 /* for sockets. */ +#ifdef __KERNEL__ +#define F_GETLK64 12 +#define F_SETLK64 13 +#define F_SETLKW64 14 +#endif /* for F_[GET|SET]FL */ #define FD_CLOEXEC 1 /* actually anything with low bit set goes */ @@ -58,7 +64,6 @@ off_t l_start; off_t l_len; pid_t l_pid; - short __unused; }; #ifdef __KERNEL__ @@ -70,6 +75,17 @@ __kernel_pid_t32 l_pid; short __unused; }; + +struct flock32_64 { + short l_type; + short l_whence; + __kernel_loff_t32 l_start; + __kernel_loff_t32 l_len; + __kernel_pid_t32 l_pid; + short __unused; +}; + +#define flock64 flock #endif #endif /* !(_SPARC64_FCNTL_H) */ diff -urN ref/include/asm-sparc64/stat.h lfs/include/asm-sparc64/stat.h --- ref/include/asm-sparc64/stat.h Sat Apr 8 19:56:02 2000 +++ lfs/include/asm-sparc64/stat.h Sat Apr 8 19:56:12 2000 @@ -1,4 +1,4 @@ -/* $Id: stat.h,v 1.5 1998/07/26 05:24:41 davem Exp $ */ +/* $Id: stat.h,v 1.6 1999/12/21 14:09:48 jj Exp $ */ #ifndef _SPARC64_STAT_H #define _SPARC64_STAT_H @@ -41,5 +41,46 @@ off_t st_blocks; unsigned long __unused4[2]; }; + +#ifdef __KERNEL__ +/* This is sparc32 stat64 structure. */ + +struct stat64 { + unsigned char __pad0[6]; + unsigned short st_dev; + unsigned char __pad1[4]; + + unsigned int st_ino; + unsigned int st_mode; + unsigned int st_nlink; + + unsigned int st_uid; + unsigned int st_gid; + + unsigned char __pad2[6]; + unsigned short st_rdev; + + unsigned char __pad3[8]; + + long long st_size; + unsigned int st_blksize; + + unsigned char __pad4[8]; + unsigned int st_blocks; + + unsigned int st_atime; + unsigned int __unused1; + + unsigned int st_mtime; + unsigned int __unused2; + + unsigned int st_ctime; + unsigned int __unused3; + + unsigned int __unused4; + unsigned int __unused5; +}; + +#endif #endif diff -urN ref/include/asm-sparc64/unistd.h lfs/include/asm-sparc64/unistd.h --- ref/include/asm-sparc64/unistd.h Sat Apr 8 19:56:02 2000 +++ lfs/include/asm-sparc64/unistd.h Sat Apr 8 19:56:12 2000 @@ -71,14 +71,14 @@ /* #define __NR_mctl 53 SunOS specific */ #define __NR_ioctl 54 /* Common */ #define __NR_reboot 55 /* Common */ -/* #define __NR_ni_syscall 56 ENOSYS under SunOS */ +/* #define __NR_mmap2 56 Linux sparc32 Specific */ #define __NR_symlink 57 /* Common */ #define __NR_readlink 58 /* Common */ #define __NR_execve 59 /* Common */ #define __NR_umask 60 /* Common */ #define __NR_chroot 61 /* Common */ #define __NR_fstat 62 /* Common */ -/* #define __NR_ni_syscall 63 ENOSYS under SunOS */ +/* #define __NR_fstat64 63 Linux sparc32 Specific */ #define __NR_getpagesize 64 /* Common */ #define __NR_msync 65 /* Common in newer 1.3.x revs... */ #define __NR_vfork 66 /* Common */ @@ -92,14 +92,14 @@ #define __NR_mprotect 74 /* Common */ /* #define __NR_madvise 75 SunOS Specific */ #define __NR_vhangup 76 /* Common */ -/* #define __NR_ni_syscall 77 ENOSYS under SunOS */ +/* #define __NR_truncate64 77 Linux sparc32 Specific */ /* #define __NR_mincore 78 SunOS Specific */ #define __NR_getgroups 79 /* Common */ #define __NR_setgroups 80 /* Common */ #define __NR_getpgrp 81 /* Common */ /* #define __NR_setpgrp 82 setpgid, same difference... */ #define __NR_setitimer 83 /* Common */ -/* #define __NR_ni_syscall 84 ENOSYS under SunOS */ +/* #define __NR_ftruncate64 84 Linux sparc32 Specific */ #define __NR_swapon 85 /* Common */ #define __NR_getitimer 86 /* Common */ /* #define __NR_gethostname 87 SunOS Specific */ @@ -147,19 +147,19 @@ #define __NR_truncate 129 /* Common */ #define __NR_ftruncate 130 /* Common */ #define __NR_flock 131 /* Common */ -/* #define __NR_ni_syscall 132 ENOSYS under SunOS */ +/* #define __NR_lstat64 132 Linux sparc32 Specific */ #define __NR_sendto 133 /* Common */ #define __NR_shutdown 134 /* Common */ #define __NR_socketpair 135 /* Common */ #define __NR_mkdir 136 /* Common */ #define __NR_rmdir 137 /* Common */ #define __NR_utimes 138 /* SunOS Specific */ -/* #define __NR_ni_syscall 139 ENOSYS under SunOS */ +/* #define __NR_stat64 139 Linux sparc32 Specific */ /* #define __NR_adjtime 140 SunOS Specific */ #define __NR_getpeername 141 /* Common */ /* #define __NR_gethostid 142 SunOS Specific */ /* #define __NR_ni_syscall 143 ENOSYS under SunOS */ -#define __NR_getrlimit 144 /* Common */ +#define __NR_getrlimit 144 /* Common */ #define __NR_setrlimit 145 /* Common */ /* #define __NR_killpg 146 SunOS Specific */ #define __NR_prctl 147 /* ENOSYS under SunOS */ diff -urN ref/include/linux/ext2_fs_i.h lfs/include/linux/ext2_fs_i.h --- ref/include/linux/ext2_fs_i.h Sat Apr 8 19:56:02 2000 +++ lfs/include/linux/ext2_fs_i.h Sat Apr 8 19:56:12 2000 @@ -35,7 +35,6 @@ __u32 i_next_alloc_goal; __u32 i_prealloc_block; __u32 i_prealloc_count; - __u32 i_high_size; int i_new_inode:1; /* Is a freshly allocated inode */ }; diff -urN ref/include/linux/fs.h lfs/include/linux/fs.h --- ref/include/linux/fs.h Sat Apr 8 19:56:02 2000 +++ lfs/include/linux/fs.h Sat Apr 8 19:56:12 2000 @@ -260,6 +260,25 @@ #define buffer_page(bh) (mem_map + MAP_NR((bh)->b_data)) #define touch_buffer(bh) set_bit(PG_referenced, &buffer_page(bh)->flags) +/* log of base-2 for filesystem uses, in case their super-blocks + don't have the shift counts readily calculated.. -- presuming + the divisors in question are power-of-two values! */ +static int fslog2(unsigned long val) __attribute__ ((const)); +static __inline__ int fslog2(unsigned long val) +{ + int i; + for (i = 0; val != 0; ++i, val >>= 1) { + if (val & 1) return i; + } + return 0; +} + +static int off_t_presentable(loff_t) __attribute((const)); +static __inline__ int off_t_presentable(loff_t loff) +{ + return loff > 0 && loff <= (~0UL >> 1); +} + #include #include #include @@ -310,7 +329,7 @@ umode_t ia_mode; uid_t ia_uid; gid_t ia_gid; - off_t ia_size; + loff_t ia_size; time_t ia_atime; time_t ia_mtime; time_t ia_ctime; @@ -345,7 +364,7 @@ uid_t i_uid; gid_t i_gid; kdev_t i_rdev; - off_t i_size; + loff_t i_size; time_t i_atime; time_t i_mtime; time_t i_ctime; @@ -422,7 +441,7 @@ mode_t f_mode; loff_t f_pos; unsigned int f_count, f_flags; - unsigned long f_reada, f_ramax, f_raend, f_ralen, f_rawin; + loff_t f_reada, f_ramax, f_raend, f_ralen, f_rawin; struct fown_struct f_owner; unsigned int f_uid, f_gid; int f_error; @@ -462,8 +481,8 @@ struct file *fl_file; unsigned char fl_flags; unsigned char fl_type; - off_t fl_start; - off_t fl_end; + loff_t fl_start; + loff_t fl_end; void (*fl_notify)(struct file_lock *); /* unblock callback */ @@ -479,6 +498,9 @@ extern int fcntl_getlk(unsigned int fd, struct flock *l); extern int fcntl_setlk(unsigned int fd, unsigned int cmd, struct flock *l); +extern int fcntl_getlk64(unsigned int fd, struct flock64 *l); +extern int fcntl_setlk64(unsigned int fd, unsigned int cmd, struct flock64 *l); + /* fs/locks.c */ extern void locks_remove_posix(struct file *, fl_owner_t id); extern void locks_remove_flock(struct file *); @@ -700,7 +722,7 @@ asmlinkage int sys_open(const char *, int, int); asmlinkage int sys_close(unsigned int); /* yes, it's really unsigned */ -extern int do_truncate(struct dentry *, unsigned long); +extern int do_truncate(struct dentry *, loff_t); extern int get_unused_fd(void); extern void put_unused_fd(unsigned int); diff -urN ref/include/linux/mm.h lfs/include/linux/mm.h --- ref/include/linux/mm.h Sat Apr 8 19:56:02 2000 +++ lfs/include/linux/mm.h Sat Apr 8 19:56:12 2000 @@ -54,7 +54,7 @@ struct vm_area_struct **vm_pprev_share; struct vm_operations_struct * vm_ops; - unsigned long vm_offset; + loff_t vm_offset; struct file * vm_file; unsigned long vm_pte; /* shared mem */ }; @@ -106,9 +106,46 @@ unsigned long (*wppage)(struct vm_area_struct * area, unsigned long address, unsigned long page); int (*swapout)(struct vm_area_struct *, struct page *); - pte_t (*swapin)(struct vm_area_struct *, unsigned long, unsigned long); + pte_t (*swapin)(struct vm_area_struct *, loff_t, unsigned long); }; + +/* + * pgoff_t type -- a complex one, and its simple alternate. + * The complex one has type that compiler can trap at compile + * time, but the simple one does simpler code (?) + */ + +#if 0 +typedef struct pgoff_t { + unsigned long pgoff; +} pgoff_t; + +#define pgoff2ulong(pgof) ((pgof).pgoff) +extern __inline__ pgoff_t ulong2pgoff(unsigned long ul) { + pgoff_t up; + up.pgoff = ul; + return up; +} + +#define pgoff2loff(pgof) (((loff_t)(pgof).pgoff) << PAGE_SHIFT) +#define loff2pgoff(loff) ulong2pgoff((loff) >> PAGE_SHIFT) + +#else /* Integer scalars -- simpler code.. */ + +typedef unsigned long pgoff_t; + +#define pgoff2ulong(pgof) (pgof) +#define ulong2pgoff(pgof) (pgof) + +#define pgoff2loff(pgof) (((loff_t)(pgof)) << PAGE_SHIFT) +#define loff2pgoff(loff) ulong2pgoff((loff) >> PAGE_SHIFT) + +#endif + +#define PAGE_MASK_loff ((loff_t)(long)(PAGE_MASK)) + + /* * Try to keep the most commonly accessed fields in single cache lines * here (16 bytes or greater). This ordering should be particularly @@ -117,12 +154,13 @@ * The first line is data used in page cache lookup, the second line * is used for linear searches (eg. clock algorithm scans). */ + typedef struct page { /* these must be first (free area handling) */ struct page *next; struct page *prev; + pgoff_t index; struct inode *inode; - unsigned long offset; struct page *next_hash; atomic_t count; unsigned long flags; /* atomic flags, some possibly updated asynchronously */ @@ -297,7 +335,7 @@ extern int remap_page_range(unsigned long from, unsigned long to, unsigned long size, pgprot_t prot); extern int zeromap_page_range(unsigned long from, unsigned long size, pgprot_t prot); -extern void vmtruncate(struct inode * inode, unsigned long offset); +extern void vmtruncate(struct inode * inode, loff_t offset); extern int handle_mm_fault(struct task_struct *tsk,struct vm_area_struct *vma, unsigned long address, int write_access); extern int make_pages_present(unsigned long addr, unsigned long end); @@ -317,16 +355,31 @@ extern void exit_mmap(struct mm_struct *); extern unsigned long get_unmapped_area(unsigned long, unsigned long); -extern unsigned long do_mmap(struct file *, unsigned long, unsigned long, - unsigned long, unsigned long, unsigned long); +extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr, + unsigned long len, unsigned long prot, + unsigned long flag, unsigned long pgoff); + +extern inline unsigned long do_mmap(struct file *file, unsigned long addr, + unsigned long len, unsigned long prot, + unsigned long flag, unsigned long offset) +{ + unsigned long ret = -EINVAL; + if ((offset + PAGE_ALIGN(len)) < offset) + goto out; + if (!(offset & ~PAGE_MASK)) + ret = do_mmap_pgoff(file, addr, len, prot, flag, offset >> PAGE_SHIFT); +out: + return ret; +} + extern int do_munmap(unsigned long, size_t); /* filemap.c */ extern void remove_inode_page(struct page *); extern unsigned long page_unuse(struct page *); extern int shrink_mmap(int, int); -extern void truncate_inode_pages(struct inode *, unsigned long); -extern unsigned long get_cached_page(struct inode *, unsigned long, int); +extern void truncate_inode_pages(struct inode *, loff_t); +extern unsigned long get_cached_page(struct inode *, pgoff_t, int); extern void put_cached_page(unsigned long); /* diff -urN ref/include/linux/nfs.h lfs/include/linux/nfs.h --- ref/include/linux/nfs.h Sat Apr 8 19:56:02 2000 +++ lfs/include/linux/nfs.h Sat Apr 8 19:56:12 2000 @@ -111,7 +111,7 @@ __u32 nlink; __u32 uid; __u32 gid; - __u32 size; + __u64 size; __u32 blocksize; __u32 rdev; __u32 blocks; @@ -126,7 +126,7 @@ __u32 mode; __u32 uid; __u32 gid; - __u32 size; + __u64 size; struct nfs_time atime; struct nfs_time mtime; }; @@ -141,7 +141,7 @@ struct nfs_writeargs { struct nfs_fh * fh; - __u32 offset; + __u64 offset; __u32 count; const void * buffer; }; @@ -160,7 +160,7 @@ struct nfs_readargs { struct nfs_fh * fh; - __u32 offset; + __u64 offset; __u32 count; void * buffer; }; diff -urN ref/include/linux/nfs_fs.h lfs/include/linux/nfs_fs.h --- ref/include/linux/nfs_fs.h Sat Apr 8 19:56:02 2000 +++ lfs/include/linux/nfs_fs.h Sat Apr 8 19:56:12 2000 @@ -143,10 +143,10 @@ void **p0, char **string, unsigned int *len, unsigned int maxlen); extern int nfs_proc_read(struct nfs_server *server, struct nfs_fh *fhandle, - int swap, unsigned long offset, unsigned int count, + int swap, loff_t offset, unsigned int count, void *buffer, struct nfs_fattr *fattr); extern int nfs_proc_write(struct nfs_server *server, struct nfs_fh *fhandle, - int swap, unsigned long offset, unsigned int count, + int swap, loff_t offset, unsigned int count, const void *buffer, struct nfs_fattr *fattr); extern int nfs_proc_create(struct nfs_server *server, struct nfs_fh *dir, const char *name, struct nfs_sattr *sattr, diff -urN ref/include/linux/pagemap.h lfs/include/linux/pagemap.h --- ref/include/linux/pagemap.h Sat Apr 8 19:56:02 2000 +++ lfs/include/linux/pagemap.h Sat Apr 8 19:56:12 2000 @@ -28,6 +28,7 @@ #define PAGE_CACHE_SHIFT PAGE_SHIFT #define PAGE_CACHE_SIZE PAGE_SIZE #define PAGE_CACHE_MASK PAGE_MASK +#define PAGE_CACHE_MASK_loff PAGE_MASK_loff #define page_cache_alloc() __get_free_page(GFP_USER) #define page_cache_free(x) free_page(x) @@ -54,10 +55,10 @@ * inode pointer and offsets are distributed (ie, we * roughly know which bits are "significant") */ -static inline unsigned long _page_hashfn(struct inode * inode, unsigned long offset) +static inline unsigned long _page_hashfn(struct inode * inode, pgoff_t index) { #define i (((unsigned long) inode)/(sizeof(struct inode) & ~ (sizeof(struct inode) - 1))) -#define o ((offset >> PAGE_SHIFT) + (offset & ~PAGE_MASK)) +#define o ((pgoff2ulong(index) >> PAGE_SHIFT) + (pgoff2ulong(index) & ~PAGE_MASK)) return ((i+o) & PAGE_HASH_MASK); #undef i #undef o @@ -65,7 +66,7 @@ #define page_hash(inode,offset) (page_hash_table+_page_hashfn(inode,offset)) -static inline struct page * __find_page(struct inode * inode, unsigned long offset, struct page *page) +static inline struct page * __find_page(struct inode * inode, pgoff_t index, struct page *page) { goto inside; for (;;) { @@ -75,7 +76,7 @@ goto not_found; if (page->inode != inode) continue; - if (page->offset == offset) + if (pgoff2ulong(page->index) == pgoff2ulong(index)) break; } /* Found the page. */ @@ -85,9 +86,9 @@ return page; } -static inline struct page *find_page(struct inode * inode, unsigned long offset) +static inline struct page *find_page(struct inode * inode, pgoff_t poffset) { - return __find_page(inode, offset, *page_hash(inode, offset)); + return __find_page(inode, poffset, *page_hash(inode, poffset)); } static inline void remove_page_from_hash_queue(struct page * page) @@ -110,9 +111,9 @@ page->pprev_hash = p; } -static inline void add_page_to_hash_queue(struct page * page, struct inode * inode, unsigned long offset) +static inline void add_page_to_hash_queue(struct page * page, struct inode * inode, pgoff_t poffset) { - __add_page_to_hash_queue(page, page_hash(inode,offset)); + __add_page_to_hash_queue(page, page_hash(inode,poffset)); } static inline void remove_page_from_inode_queue(struct page * page) @@ -150,7 +151,7 @@ __wait_on_page(page); } -extern void update_vm_cache_conditional(struct inode *, unsigned long, const char *, int, unsigned long); -extern void update_vm_cache(struct inode *, unsigned long, const char *, int); +extern void update_vm_cache_conditional(struct inode *, loff_t, const char *, int, unsigned long); +extern void update_vm_cache(struct inode *, loff_t, const char *, int); #endif diff -urN ref/include/linux/sched.h lfs/include/linux/sched.h --- ref/include/linux/sched.h Sat Apr 8 19:56:02 2000 +++ lfs/include/linux/sched.h Sat Apr 8 19:56:12 2000 @@ -301,7 +301,7 @@ kernel_cap_t cap_effective, cap_inheritable, cap_permitted; struct user_struct *user; /* limits */ - struct rlimit rlim[RLIM_NLIMITS]; + struct rlimit rlim[RLIM_NLIMITS]; unsigned short used_math; char comm[16]; /* file system info */ diff -urN ref/include/linux/smb_fs.h lfs/include/linux/smb_fs.h --- ref/include/linux/smb_fs.h Sat Apr 8 19:56:02 2000 +++ lfs/include/linux/smb_fs.h Sat Apr 8 19:56:12 2000 @@ -128,8 +128,8 @@ void smb_close_dentry(struct dentry *); int smb_close_fileid(struct dentry *, __u16); int smb_open(struct dentry *, int); -int smb_proc_read(struct dentry *, off_t, int, char *); -int smb_proc_write(struct dentry *, off_t, int, const char *); +int smb_proc_read(struct dentry *, loff_t, int, char *); +int smb_proc_write(struct dentry *, loff_t, int, const char *); int smb_proc_create(struct dentry *, __u16, time_t, __u16 *); int smb_proc_mv(struct dentry *, struct dentry *); int smb_proc_mkdir(struct dentry *); diff -urN ref/include/linux/swap.h lfs/include/linux/swap.h --- ref/include/linux/swap.h Sat Apr 8 19:56:02 2000 +++ lfs/include/linux/swap.h Sat Apr 8 19:56:12 2000 @@ -114,7 +114,7 @@ extern unsigned int nr_swapfiles; extern struct swap_info_struct swap_info[]; void si_swapinfo(struct sysinfo *); -unsigned long get_swap_page(void); +extern unsigned long get_swap_page(void); extern void FASTCALL(swap_free(unsigned long)); struct swap_list_t { int head; /* head of priority-ordered swapfile list */ @@ -147,7 +147,7 @@ extern inline unsigned long in_swap_cache(struct page *page) { if (PageSwapCache(page)) - return page->offset; + return pgoff2ulong(page->index); return 0; } @@ -164,7 +164,7 @@ return 1; count = atomic_read(&page->count); if (PageSwapCache(page)) - count += swap_count(page->offset) - 2; + count += swap_count(pgoff2ulong(page->index)) - 2; if (PageFreeAfter(page)) count--; return count > 1; diff -urN ref/include/linux/ufs_fs_i.h lfs/include/linux/ufs_fs_i.h --- ref/include/linux/ufs_fs_i.h Sat Apr 8 19:56:02 2000 +++ lfs/include/linux/ufs_fs_i.h Sat Apr 8 19:56:12 2000 @@ -18,7 +18,6 @@ __u32 i_data[15]; __u8 i_symlink[4*15]; } i_u1; - __u64 i_size; __u32 i_flags; __u32 i_gen; __u32 i_shadow; diff -urN ref/kernel/ksyms.c lfs/kernel/ksyms.c --- ref/kernel/ksyms.c Sat Apr 8 19:56:02 2000 +++ lfs/kernel/ksyms.c Sat Apr 8 19:56:12 2000 @@ -91,7 +91,7 @@ EXPORT_SYMBOL(get_options); /* process memory management */ -EXPORT_SYMBOL(do_mmap); +EXPORT_SYMBOL(do_mmap_pgoff); EXPORT_SYMBOL(do_munmap); EXPORT_SYMBOL(exit_mm); EXPORT_SYMBOL(exit_files); diff -urN ref/lib/vsprintf.c lfs/lib/vsprintf.c --- ref/lib/vsprintf.c Sat Apr 8 19:56:02 2000 +++ lfs/lib/vsprintf.c Sat Apr 8 19:56:12 2000 @@ -67,10 +67,106 @@ #define LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */ #define do_div(n,base) ({ \ -int __res; \ -__res = ((unsigned long) n) % (unsigned) base; \ -n = ((unsigned long) n) / (unsigned) base; \ -__res; }) + int __res; \ + __res = ((unsigned long) n) % (unsigned) base; \ + n = ((unsigned long) n) / (unsigned) base; \ + __res; }) + +#if BITS_PER_LONG < 64 + +/* Note: do_ldiv assumes that unsigned long long is a 64 bit long + * and unsigned long is at least a 32 bits long. + */ +#define do_ldiv(n, base) \ +({ \ + unsigned long long value = n; \ + unsigned long long leftover; \ + unsigned long temp; \ + unsigned long result_div1, result_div2, result_div3, result_mod; \ +\ + temp = value >> 32; \ + result_div1 = temp/(base); \ + result_mod = temp%(base); \ +\ + temp = (result_mod << 24) | ((value >> 8) & 0xFFFFFF); \ + result_div2 = temp/(base); \ + result_mod = temp%(base); \ +\ + temp = (result_mod << 8) | (value & 0xFF); \ + result_div3 = temp/(base); \ + result_mod = temp%(base);\ +\ + leftover = ((unsigned long long)result_div1 << 32) | \ + ((unsigned long long)result_div2 << 8) | (result_div3); \ +\ + n = leftover; \ + result_mod; \ +}) + + +static char * lnumber(char * str, long long num, int base, int size, + int precision, int type) +{ + char c,sign,tmp[66]; + const char *digits="0123456789abcdef"; + int i; + + if (type & LARGE) + digits = "0123456789ABCDEF"; + if (type & LEFT) + type &= ~ZEROPAD; + if (base < 2 || base > 36) + return 0; + c = (type & ZEROPAD) ? '0' : ' '; + sign = 0; + if (type & SIGN) { + if (num < 0) { + sign = '-'; + num = -num; + size--; + } else if (type & PLUS) { + sign = '+'; + size--; + } else if (type & SPACE) { + sign = ' '; + size--; + } + } + if (type & SPECIAL) { + if (base == 16) + size -= 2; + } + i = 0; + if (num == 0) + tmp[i++]='0'; + else while (num != 0) + tmp[i++] = digits[do_ldiv(num,base)]; + if (i > precision) + precision = i; + size -= precision; + if (!(type&(ZEROPAD+LEFT))) + while(size-->0) + *str++ = ' '; + if (sign) + *str++ = sign; + if (type & SPECIAL) { + if (base==16) { + *str++ = '0'; + *str++ = digits[33]; + } + } + if (!(type & LEFT)) + while (size-- > 0) + *str++ = c; + while (i < precision--) + *str++ = '0'; + while (i-- > 0) + *str++ = tmp[i]; + while (size-- > 0) + *str++ = ' '; + return str; +} +#endif static char * number(char * str, long num, int base, int size, int precision ,int type) @@ -207,7 +303,10 @@ /* get the conversion qualifier */ qualifier = -1; if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L') { - qualifier = *fmt; + if (*fmt == 'l' && qualifier == 'l') + qualifier = 'L'; + else + qualifier = *fmt; ++fmt; } @@ -290,7 +389,22 @@ --fmt; continue; } - if (qualifier == 'l') + if (qualifier == 'L') { + +#if BITS_PER_LONG < 64 + /* 64-bit printout in 32-bit systems !! + Needed at some point for 64-bit file offsets and + mmap() reporting functions. */ + + unsigned long long lnum; + lnum = va_arg(args, unsigned long long); + str = lnumber(str, lnum, base, field_width, + precision, flags); + continue; +#else + num = va_arg(args, unsigned long); /* 64-bit longs..*/ +#endif + } else if (qualifier == 'l') num = va_arg(args, unsigned long); else if (qualifier == 'h') { num = (unsigned short) va_arg(args, int); diff -urN ref/mm/bigmem.c lfs/mm/bigmem.c --- ref/mm/bigmem.c Sat Apr 8 19:56:02 2000 +++ lfs/mm/bigmem.c Sat Apr 8 19:56:12 2000 @@ -60,7 +60,7 @@ kunmap(vaddr, KM_WRITE); /* Preserve the caching of the swap_entry. */ - bigmem_page->offset = page->offset; + bigmem_page->index = page->index; /* We can just forget the old page since we stored its data into the new diff -urN ref/mm/filemap.c lfs/mm/filemap.c --- ref/mm/filemap.c Sat Apr 8 19:56:02 2000 +++ lfs/mm/filemap.c Sat Apr 8 19:56:12 2000 @@ -89,7 +89,7 @@ * Truncate the page cache at a set offset, removing the pages * that are beyond that offset (and zeroing out partial pages). */ -void truncate_inode_pages(struct inode * inode, unsigned long start) +void truncate_inode_pages(struct inode * inode, loff_t start) { struct page ** p; struct page * page; @@ -97,10 +97,10 @@ repeat: p = &inode->i_pages; while ((page = *p) != NULL) { - unsigned long offset = page->offset; + loff_t loffset = pgoff2loff(page->index); /* page wholly truncated - free it */ - if (offset >= start) { + if (loffset >= start) { if (PageLocked(page)) { wait_on_page(page); goto repeat; @@ -116,9 +116,10 @@ continue; } p = &page->next; - offset = start - offset; + loffset = start - loffset; /* partial truncate, clear end of page */ - if (offset < PAGE_CACHE_SIZE) { + if (loffset < PAGE_CACHE_SIZE) { + unsigned int offset = loffset; /* truncate ok */ unsigned long address = page_address(page); memset((void *) (offset + address), 0, PAGE_CACHE_SIZE - offset); flush_page_to_ram(address); @@ -196,7 +197,8 @@ * were to be marked referenced.. */ if (PageSwapCache(page)) { - if (referenced && swap_count(page->offset) != 1) + if (referenced && + swap_count(pgoff2ulong(page->index)) != 1) continue; delete_from_swap_cache(page); return 1; @@ -247,11 +249,12 @@ * memory maps. --sct */ -void update_vm_cache_conditional(struct inode * inode, unsigned long pos, const char * buf, int count, unsigned long source_address) +void update_vm_cache_conditional(struct inode * inode, loff_t pos, const char * buf, int count, unsigned long source_address) { unsigned long offset, len; + pgoff_t pgoff = loff2pgoff(pos); - offset = (pos & ~PAGE_CACHE_MASK); + offset = ((unsigned long)pos & ~PAGE_CACHE_MASK); pos = pos & PAGE_CACHE_MASK; len = PAGE_CACHE_SIZE - offset; do { @@ -259,7 +262,7 @@ if (len > count) len = count; - page = find_page(inode, pos); + page = find_page(inode, pgoff); if (page) { char *dest = (char*) (offset + page_address(page)); @@ -278,19 +281,20 @@ } while (count); } -void update_vm_cache(struct inode * inode, unsigned long pos, const char * buf, int count) +void update_vm_cache(struct inode * inode, loff_t pos, const char * buf, int count) { update_vm_cache_conditional(inode, pos, buf, count, 0); } static inline void add_to_page_cache(struct page * page, - struct inode * inode, unsigned long offset, - struct page **hash) + struct inode * inode, + pgoff_t pgoff, + struct page **hash) { atomic_inc(&page->count); page->flags = (page->flags & ~((1 << PG_uptodate) | (1 << PG_error))) | (1 << PG_referenced); - page->offset = offset; + page->index = pgoff; add_page_to_inode_queue(inode, page); __add_page_to_hash_queue(page, hash); } @@ -301,29 +305,32 @@ * this is all overlapped with the IO on the previous page finishing anyway) */ static unsigned long try_to_read_ahead(struct file * file, - unsigned long offset, unsigned long page_cache) + pgoff_t pgoff, unsigned long page_cache) { struct inode *inode = file->f_dentry->d_inode; - struct page * page; - struct page ** hash; + pgoff_t pg_size; + + /* Calculate file size in 'pages' -- if even one byte (according to + the 'i_size') exceeds the final page-size block, round up. */ + pg_size = loff2pgoff(inode->i_size+(PAGE_SIZE-1)); - offset &= PAGE_CACHE_MASK; - switch (page_cache) { - case 0: + if (!page_cache) { page_cache = page_cache_alloc(); if (!page_cache) - break; - default: - if (offset >= inode->i_size) - break; - hash = page_hash(inode, offset); - page = __find_page(inode, offset, *hash); + return 0; /* Can't allocate! */ + } + /* Ok, we have a page, make sure it is in the page cache */ + if (pgoff2ulong(pgoff) < pgoff2ulong(pg_size)) { + struct page * page; + struct page ** hash; + hash = page_hash(inode, pgoff); + page = __find_page(inode, pgoff, *hash); if (!page) { /* * Ok, add the new page to the hash-queues... */ page = page_cache_entry(page_cache); - add_to_page_cache(page, inode, offset, hash); + add_to_page_cache(page, inode, pgoff, hash); inode->i_op->readpage(file, page); page_cache = 0; } @@ -378,11 +385,11 @@ #define PROFILE_MAXREADCOUNT 1000 -static unsigned long total_reada; -static unsigned long total_async; -static unsigned long total_ramax; -static unsigned long total_ralen; -static unsigned long total_rawin; +static u_long total_reada; +static u_long total_async; +static u_long total_ramax; +static u_long total_ralen; +static u_long total_rawin; static void profile_readahead(int async, struct file *filp) { @@ -490,13 +497,13 @@ static inline unsigned long generic_file_readahead(int reada_ok, struct file * filp, struct inode * inode, - unsigned long ppos, struct page * page, unsigned long page_cache) + loff_t ppos, struct page * page, unsigned long page_cache) { - unsigned long max_ahead, ahead; - unsigned long raend; + loff_t max_ahead, ahead; + loff_t raend; int max_readahead = get_max_readahead(inode); - raend = filp->f_raend & PAGE_CACHE_MASK; + raend = filp->f_raend & PAGE_CACHE_MASK_loff; max_ahead = 0; /* @@ -554,7 +561,7 @@ ahead = 0; while (ahead < max_ahead) { ahead += PAGE_CACHE_SIZE; - page_cache = try_to_read_ahead(filp, raend + ahead, + page_cache = try_to_read_ahead(filp, loff2pgoff(raend + ahead), page_cache); } /* @@ -620,14 +627,17 @@ { struct dentry *dentry = filp->f_dentry; struct inode *inode = dentry->d_inode; - size_t pos, pgpos, page_cache; + size_t page_cache; + pgoff_t pgpos; + loff_t pos, posp; int reada_ok; int max_readahead = get_max_readahead(inode); page_cache = 0; pos = *ppos; - pgpos = pos & PAGE_CACHE_MASK; + posp = pos & PAGE_CACHE_MASK_loff; + pgpos = loff2pgoff(pos); /* * If the current position is outside the previous read-ahead window, * we reset the current read-ahead context and set read ahead max to zero @@ -635,7 +645,7 @@ * otherwise, we assume that the file accesses are sequential enough to * continue read-ahead. */ - if (pgpos > filp->f_raend || pgpos + filp->f_rawin < filp->f_raend) { + if (posp > filp->f_raend || posp + filp->f_rawin < filp->f_raend) { reada_ok = 0; filp->f_raend = 0; filp->f_ralen = 0; @@ -651,12 +661,12 @@ * Then, at least MIN_READAHEAD if read ahead is ok, * and at most MAX_READAHEAD in all cases. */ - if (pos + desc->count <= (PAGE_CACHE_SIZE >> 1)) { + if (pos + desc->count <= (loff_t)(PAGE_CACHE_SIZE >> 1)) { filp->f_ramax = 0; } else { - unsigned long needed; + loff_t needed; - needed = ((pos + desc->count) & PAGE_CACHE_MASK) - pgpos; + needed = ((pos + desc->count) & PAGE_CACHE_MASK) - posp; if (filp->f_ramax < needed) filp->f_ramax = needed; @@ -669,6 +679,7 @@ for (;;) { struct page *page, **hash; + pgoff_t pgoff; if (pos >= inode->i_size) break; @@ -676,8 +687,9 @@ /* * Try to find the data in the page cache.. */ - hash = page_hash(inode, pos & PAGE_CACHE_MASK); - page = __find_page(inode, pos & PAGE_CACHE_MASK, *hash); + pgoff = loff2pgoff(pos); + hash = page_hash(inode, pgoff); + page = __find_page(inode, pgoff, *hash); if (!page) goto no_cached_page; @@ -690,7 +702,7 @@ * the page has been rewritten. */ if (PageUptodate(page) || PageLocked(page)) - page_cache = generic_file_readahead(reada_ok, filp, inode, pos & PAGE_CACHE_MASK, page, page_cache); + page_cache = generic_file_readahead(reada_ok, filp, inode, pos & PAGE_CACHE_MASK_loff, page, page_cache); else if (reada_ok && filp->f_ramax > MIN_READAHEAD) filp->f_ramax = MIN_READAHEAD; @@ -708,8 +720,8 @@ unsigned long offset, nr; offset = pos & ~PAGE_CACHE_MASK; - nr = PAGE_CACHE_SIZE - offset; - if (nr > inode->i_size - pos) + nr = PAGE_CACHE_SIZE - offset; /* small value */ + if ((loff_t)nr > (inode->i_size - pos)) nr = inode->i_size - pos; /* @@ -749,7 +761,7 @@ */ page = page_cache_entry(page_cache); page_cache = 0; - add_to_page_cache(page, inode, pos & PAGE_CACHE_MASK, hash); + add_to_page_cache(page, inode, pgoff, hash); /* * Error handling is tricky. If we get a read error, @@ -830,10 +842,26 @@ ssize_t generic_file_read(struct file * filp, char * buf, size_t count, loff_t *ppos) { ssize_t retval; + struct inode *inode = filp->f_dentry->d_inode; retval = -EFAULT; if (access_ok(VERIFY_WRITE, buf, count)) { retval = 0; + + /* L-F-S spec 2.2.1.25: */ + if (count && !(filp->f_flags & O_LARGEFILE) && + S_ISREG(inode->i_mode) && + (*ppos < inode->i_size) && + (*ppos >= 0x7ffffffeULL)) /* pos@2G forbidden */ + return -EOVERFLOW; + if (count && !(filp->f_flags & O_LARGEFILE) && + S_ISREG(inode->i_mode) && + (*ppos < inode->i_size) && + (*ppos + count >= 0x7fffffffULL)) { + /* Read only until end of allowed region */ + count = LONG_MAX - *ppos; + } + if (count) { read_descriptor_t desc; @@ -975,20 +1003,25 @@ struct file * file = area->vm_file; struct dentry * dentry = file->f_dentry; struct inode * inode = dentry->d_inode; - unsigned long offset, reada, i; + loff_t offset; + pgoff_t pgoff, reada; + int i; struct page * page, **hash; unsigned long old_page, new_page; new_page = 0; - offset = (address & PAGE_MASK) - area->vm_start + area->vm_offset; + offset = ((loff_t)((address & PAGE_MASK) - area->vm_start) + + area->vm_offset); + if (offset >= inode->i_size && (area->vm_flags & VM_SHARED) && area->vm_mm == current->mm) goto no_page; /* * Do we have something in the page cache already? */ - hash = page_hash(inode, offset); - page = __find_page(inode, offset, *hash); + pgoff = loff2pgoff(offset); + hash = page_hash(inode, pgoff); + page = __find_page(inode, pgoff, *hash); if (!page) goto no_cached_page; @@ -1039,11 +1072,12 @@ /* * Try to read in an entire cluster at once. */ - reada = offset; - reada >>= PAGE_CACHE_SHIFT + page_cluster; - reada <<= PAGE_CACHE_SHIFT + page_cluster; + reada = loff2pgoff(offset); + /* Mask lowest 'page_cluster' worth of the lowest bits */ + reada = ulong2pgoff(pgoff2ulong(reada) & ((~(0UL)) << page_cluster)); - for (i = 1 << page_cluster; i > 0; --i, reada += PAGE_CACHE_SIZE) + for (i = 1 << page_cluster; i > 0; + --i, reada = ulong2pgoff(pgoff2ulong(reada)+1)) new_page = try_to_read_ahead(file, reada, new_page); if (!new_page) @@ -1057,7 +1091,7 @@ * cache.. The page we just got may be useful if we * can't share, so don't get rid of it here. */ - page = find_page(inode, offset); + page = find_page(inode, pgoff); if (page) goto found_page; @@ -1066,7 +1100,7 @@ */ page = page_cache_entry(new_page); new_page = 0; - add_to_page_cache(page, inode, offset, hash); + add_to_page_cache(page, inode, pgoff, hash); if (inode->i_op->readpage(file, page) != 0) goto failure; @@ -1115,10 +1149,10 @@ * if the disk is full. */ static inline int do_write_page(struct inode * inode, struct file * file, - const char * page, unsigned long offset) + const char * page, loff_t offset) { int retval; - unsigned long size; + loff_t size; loff_t loff = offset; mm_segment_t old_fs; @@ -1142,7 +1176,7 @@ } static int filemap_write_page(struct vm_area_struct * vma, - unsigned long offset, + loff_t offset, unsigned long page, int wait) { @@ -1188,7 +1222,7 @@ */ int filemap_swapout(struct vm_area_struct * vma, struct page * page) { - return filemap_write_page(vma, page->offset, page_address(page), 0); + return filemap_write_page(vma, pgoff2loff(page->index), page_address(page), 0); } static inline int filemap_sync_pte(pte_t * ptep, struct vm_area_struct *vma, @@ -1487,7 +1521,7 @@ { struct dentry *dentry = file->f_dentry; struct inode *inode = dentry->d_inode; - unsigned long pos = *ppos; + loff_t pos = *ppos; unsigned long limit = current->rlim[RLIMIT_FSIZE].rlim_cur; struct page *page, **hash; unsigned long page_cache = 0; @@ -1513,7 +1547,7 @@ * Check whether we've reached the file size limit. */ status = -EFBIG; - if (pos >= limit) { + if (limit != RLIM_INFINITY && pos >= limit) { send_sig(SIGXFSZ, current, 0); goto out; } @@ -1523,21 +1557,21 @@ * Check whether to truncate the write, * and send the signal if we do. */ - if (count > limit - pos) { + if (limit != RLIM_INFINITY && count > limit - pos) { send_sig(SIGXFSZ, current, 0); count = limit - pos; } while (count) { - unsigned long bytes, pgpos, offset; + unsigned long bytes, offset; + pgoff_t pgpos = loff2pgoff(pos); char * dest; /* * Try to find the page in the cache. If it isn't there, * allocate a free page. */ - offset = (pos & ~PAGE_CACHE_MASK); - pgpos = pos & PAGE_CACHE_MASK; + offset = ((unsigned long)pos & ~PAGE_CACHE_MASK); bytes = PAGE_CACHE_SIZE - offset; if (bytes > count) bytes = count; @@ -1609,15 +1643,14 @@ * Note: we don't have to worry about races here, as the caller * is holding the inode semaphore. */ -unsigned long get_cached_page(struct inode * inode, unsigned long offset, - int new) +unsigned long get_cached_page(struct inode * inode, pgoff_t pgoff, int new) { struct page * page; struct page ** hash; unsigned long page_cache = 0; - hash = page_hash(inode, offset); - page = __find_page(inode, offset, *hash); + hash = page_hash(inode, pgoff); + page = __find_page(inode, pgoff, *hash); if (!page) { if (!new) goto out; @@ -1626,7 +1659,7 @@ goto out; clear_page(page_cache); page = page_cache_entry(page_cache); - add_to_page_cache(page, inode, offset, hash); + add_to_page_cache(page, inode, pgoff, hash); } if (atomic_read(&page->count) != 2) printk(KERN_ERR "get_cached_page: page count=%d\n", diff -urN ref/mm/memory.c lfs/mm/memory.c --- ref/mm/memory.c Sat Apr 8 19:56:02 2000 +++ lfs/mm/memory.c Sat Apr 8 19:56:12 2000 @@ -822,7 +822,7 @@ case 2: if (!PageSwapCache(page_map)) break; - if (swap_count(page_map->offset) != 1) + if (swap_count(pgoff2ulong(page_map->index)) != 1) break; delete_from_swap_cache(page_map); /* FallThrough */ @@ -913,7 +913,7 @@ * between the file and the memory map for a potential last * incomplete page. Ugly, but necessary. */ -void vmtruncate(struct inode * inode, unsigned long offset) +void vmtruncate(struct inode * inode, loff_t offset) { struct vm_area_struct * mpnt; diff -urN ref/mm/mmap.c lfs/mm/mmap.c --- ref/mm/mmap.c Sat Apr 8 19:56:02 2000 +++ lfs/mm/mmap.c Sat Apr 8 19:56:12 2000 @@ -169,11 +169,12 @@ #undef _trans } -unsigned long do_mmap(struct file * file, unsigned long addr, unsigned long len, - unsigned long prot, unsigned long flags, unsigned long off) +unsigned long do_mmap_pgoff(struct file * file, unsigned long addr, unsigned long len, + unsigned long prot, unsigned long flags, unsigned long pg_off) { struct mm_struct * mm = current->mm; struct vm_area_struct * vma; + loff_t off = (loff_t)pg_off << PAGE_SHIFT; int error; if (file && (!file->f_op || !file->f_op->mmap)) @@ -837,7 +838,8 @@ * the offsets must be contiguous.. */ if ((mpnt->vm_file != NULL) || (mpnt->vm_flags & VM_SHM)) { - unsigned long off = prev->vm_offset+prev->vm_end-prev->vm_start; + loff_t off = (prev->vm_offset + + (loff_t)(prev->vm_end - prev->vm_start)); if (off != mpnt->vm_offset) continue; } diff -urN ref/mm/page_io.c lfs/mm/page_io.c --- ref/mm/page_io.c Sat Apr 8 19:56:02 2000 +++ lfs/mm/page_io.c Sat Apr 8 19:56:12 2000 @@ -112,7 +112,7 @@ * as if it were: we are not allowed to manipulate the inode * hashing for locked pages. */ - if (page->offset != entry) { + if (pgoff2ulong(page->index) != entry) { printk ("swap entry mismatch"); return; } @@ -265,8 +265,8 @@ printk("VM: swap page is not in swap cache\n"); return; } - if (page->offset != entry) { - printk ("swap entry mismatch"); + if (pgoff2ulong(page->index) != entry) { + printk ("VM: swap entry mismatch"); return; } rw_swap_page_base(rw, entry, page, wait); @@ -291,12 +291,12 @@ printk ("VM: read_swap_page: page already in page cache!\n"); return; } - page->inode = &swapper_inode; - page->offset = entry; + page->inode = &swapper_inode; + page->index = ulong2pgoff(entry); atomic_inc(&page->count); /* Protect from shrink_mmap() */ rw_swap_page(rw, entry, buffer, 1); atomic_dec(&page->count); - page->inode = 0; + page->inode = 0; clear_bit(PG_swap_cache, &page->flags); } diff -urN ref/mm/swap_state.c lfs/mm/swap_state.c --- ref/mm/swap_state.c Sat Apr 8 19:56:02 2000 +++ lfs/mm/swap_state.c Sat Apr 8 19:56:12 2000 @@ -54,7 +54,7 @@ if (PageTestandSetSwapCache(page)) { printk(KERN_ERR "swap_cache: replacing non-empty entry %08lx " "on page %08lx\n", - page->offset, page_address(page)); + pgoff2ulong(page->index), page_address(page)); return 0; } if (page->inode) { @@ -64,8 +64,8 @@ } atomic_inc(&page->count); page->inode = &swapper_inode; - page->offset = entry; - add_page_to_hash_queue(page, &swapper_inode, entry); + page->index = ulong2pgoff(entry); + add_page_to_hash_queue(page, &swapper_inode, ulong2pgoff(entry)); add_page_to_inode_queue(&swapper_inode, page); return 1; } @@ -203,7 +203,7 @@ */ void delete_from_swap_cache(struct page *page) { - long entry = page->offset; + long entry = pgoff2ulong(page->index); #ifdef SWAP_CACHE_INFO swap_cache_del_total++; @@ -251,7 +251,7 @@ swap_cache_find_total++; #endif while (1) { - found = find_page(&swapper_inode, entry); + found = find_page(&swapper_inode, ulong2pgoff(entry)); if (!found) return 0; if (found->inode != &swapper_inode || !PageSwapCache(found)) diff -urN ref/mm/vmscan.c lfs/mm/vmscan.c --- ref/mm/vmscan.c Sat Apr 8 19:56:02 2000 +++ lfs/mm/vmscan.c Sat Apr 8 19:56:12 2000 @@ -74,7 +74,7 @@ * memory, and we should just continue our scan. */ if (PageSwapCache(page_map)) { - entry = page_map->offset; + entry = pgoff2ulong(page_map->index); swap_duplicate(entry); set_pte(page_table, __pte(entry)); drop_pte: