Hi!
This changes internal meaning of RLIMIT_SIZE from maximum file size in bytes
to maximum size in blocks (= 512B) and keeps binary compatibility on the
setrlimit/getrlimit calls. Like this, glibc can implement LFS
getrlimit64/setrlimit64 on top of the normal getrlimit/setrlimit system call
and allow users to set up limits up to 2TB (on i386) for maximum file size
below RLIM_INFINITY while keeping rlim_t 32bit in the kernel for 32bit
archs.
glibc is expected to use RLIMIT_FBSIZE internally in [gs]etrlimit64 to work
with RLIMIT_FSIZE resource.
--- linux/arch/sparc64/kernel/sys_sparc32.c.jj Fri Jan 14 10:40:07 2000
+++ linux/arch/sparc64/kernel/sys_sparc32.c Fri Jan 14 16:09:38 2000
@@ -2194,7 +2194,7 @@ asmlinkage long sys32_times(struct tms32
return ret;
}
-#define RLIM_INFINITY32 0x7fffffff
+#define RLIM_INFINITY32 0x7fffffffU
#define RESOURCE32(x) ((x > RLIM_INFINITY32) ? RLIM_INFINITY32 : x)
struct rlimit32 {
@@ -2228,7 +2228,8 @@ asmlinkage int sys32_setrlimit(unsigned
int ret;
mm_segment_t old_fs = get_fs ();
- if (resource >= RLIM_NLIMITS) return -EINVAL;
+ if (resource >= RLIM_NLIMITS && resource != RLIMIT_FBSIZE)
+ return -EINVAL;
if (get_user (r.rlim_cur, &rlim->rlim_cur) ||
__get_user (r.rlim_max, &rlim->rlim_max))
return -EFAULT;
--- linux/fs/ext2/inode.c.jj Tue Jan 11 12:06:05 2000
+++ linux/fs/ext2/inode.c Fri Jan 14 16:32:22 2000
@@ -219,7 +219,7 @@ repeat:
{
unsigned long limit = current->rlim[RLIMIT_FSIZE].rlim_cur;
if (limit < RLIM_INFINITY) {
- limit >>= EXT2_BLOCK_SIZE_BITS(inode->i_sb);
+ limit >>= EXT2_BLOCK_SIZE_BITS(inode->i_sb) - 9;
if (new_block >= limit) {
send_sig(SIGXFSZ, current, 0);
*err = -EFBIG;
@@ -342,7 +342,7 @@ repeat:
limit = current->rlim[RLIMIT_FSIZE].rlim_cur;
if (limit < RLIM_INFINITY) {
- limit >>= EXT2_BLOCK_SIZE_BITS(inode->i_sb);
+ limit >>= EXT2_BLOCK_SIZE_BITS(inode->i_sb) - 9;
if (new_block >= limit) {
send_sig(SIGXFSZ, current, 0);
goto out;
--- linux/fs/minix/inode.c.jj Tue Jan 11 12:06:06 2000
+++ linux/fs/minix/inode.c Fri Jan 14 16:34:04 2000
@@ -521,8 +521,7 @@ repeat:
{
unsigned long limit = current->rlim[RLIMIT_FSIZE].rlim_cur;
if (limit < RLIM_INFINITY) {
- limit >>= BLOCK_SIZE_BITS;
- if (new_block >= limit) {
+ if (new_block >= (limit >> 1)) {
send_sig(SIGXFSZ, current, 0);
*err = -EFBIG;
return NULL;
@@ -604,8 +603,7 @@ repeat:
limit = current->rlim[RLIMIT_FSIZE].rlim_cur;
if (limit < RLIM_INFINITY) {
- limit >>= BLOCK_SIZE_BITS;
- if (new_block >= limit) {
+ if (new_block >= (limit >> 1)) {
send_sig(SIGXFSZ, current, 0);
goto out;
}
@@ -757,8 +755,7 @@ repeat:
{
unsigned long limit = current->rlim[RLIMIT_FSIZE].rlim_cur;
if (limit < RLIM_INFINITY) {
- limit >>= BLOCK_SIZE_BITS;
- if (new_block >= limit) {
+ if (new_block >= (limit >> 1)) {
send_sig(SIGXFSZ, current, 0);
*err = -EFBIG;
return NULL;
@@ -840,8 +837,7 @@ repeat:
limit = current->rlim[RLIMIT_FSIZE].rlim_cur;
if (limit < RLIM_INFINITY) {
- limit >>= BLOCK_SIZE_BITS;
- if (new_block >= limit) {
+ if (new_block >= (limit >> 1)) {
send_sig(SIGXFSZ, current, 0);
goto out;
}
--- linux/fs/sysv/inode.c.jj Tue Jan 11 12:06:06 2000
+++ linux/fs/sysv/inode.c Fri Jan 14 16:35:03 2000
@@ -711,7 +711,7 @@ repeat:
{
unsigned long limit = current->rlim[RLIMIT_FSIZE].rlim_cur;
if (limit < RLIM_INFINITY) {
- limit >>= sb->sv_block_size_bits;
+ limit >>= sb->sv_block_size_bits - 9;
if (new_block >= limit) {
send_sig(SIGXFSZ, current, 0);
*err = -EFBIG;
@@ -795,7 +795,7 @@ repeat:
limit = current->rlim[RLIMIT_FSIZE].rlim_cur;
if (limit < RLIM_INFINITY) {
- limit >>= sb->sv_block_size_bits;
+ limit >>= sb->sv_block_size_bits - 9;
if (new_block >= limit) {
send_sig(SIGXFSZ, current, 0);
goto out;
--- linux/fs/udf/inode.c.jj Fri Jan 7 15:38:52 2000
+++ linux/fs/udf/inode.c Fri Jan 14 16:33:03 2000
@@ -468,7 +468,7 @@ static struct buffer_head * inode_getblk
unsigned long limit = current->rlim[RLIMIT_FSIZE].rlim_cur;
if (limit < RLIM_INFINITY)
{
- limit >>= inode->i_sb->s_blocksize_bits;
+ limit >>= inode->i_sb->s_blocksize_bits - 9;
if (block >= limit)
{
send_sig(SIGXFSZ, current, 0);
--- linux/fs/ufs/inode.c.jj Tue Jan 11 12:06:06 2000
+++ linux/fs/ufs/inode.c Fri Jan 14 16:32:48 2000
@@ -224,7 +224,7 @@ repeat:
limit = current->rlim[RLIMIT_FSIZE].rlim_cur;
if (limit < RLIM_INFINITY) {
- limit >>= sb->s_blocksize_bits;
+ limit >>= sb->s_blocksize_bits - 9;
if (new_fragment >= limit) {
send_sig(SIGXFSZ, current, 0);
return NULL;
@@ -352,7 +352,7 @@ repeat:
{
unsigned long limit = current->rlim[RLIMIT_FSIZE].rlim_cur;
if (limit < RLIM_INFINITY) {
- limit >>= sb->s_blocksize_bits;
+ limit >>= sb->s_blocksize_bits - 9;
if (new_fragment >= limit) {
brelse (bh);
send_sig(SIGXFSZ, current, 0);
--- linux/include/asm-alpha/resource.h.jj Wed Dec 15 18:14:09 1999
+++ linux/include/asm-alpha/resource.h Fri Jan 14 15:32:59 2000
@@ -15,6 +15,10 @@
#define RLIMIT_AS 7 /* address space limit(?) */
#define RLIMIT_NPROC 8 /* max number of processes */
#define RLIMIT_MEMLOCK 9 /* max locked-in-memory address space */
+#define RLIMIT_FBSIZE 0x101 /* Maximum filesize in blocks */
+#ifdef __KERNEL__
+#define RLIMIT_MASK 0xff
+#endif
#define RLIM_NLIMITS 10
--- linux/include/asm-arm/resource.h.jj Wed Dec 15 18:14:09 1999
+++ linux/include/asm-arm/resource.h Fri Jan 14 15:33:10 2000
@@ -15,6 +15,10 @@
#define RLIMIT_NOFILE 7 /* max number of open files */
#define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */
#define RLIMIT_AS 9 /* address space limit */
+#define RLIMIT_FBSIZE 0x101 /* Maximum filesize in blocks */
+#ifdef __KERNEL__
+#define RLIMIT_MASK 0xff
+#endif
#define RLIM_NLIMITS 10
--- linux/include/asm-i386/resource.h.jj Wed Dec 15 18:14:09 1999
+++ linux/include/asm-i386/resource.h Fri Jan 14 15:33:20 2000
@@ -15,6 +15,10 @@
#define RLIMIT_NOFILE 7 /* max number of open files */
#define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */
#define RLIMIT_AS 9 /* address space limit */
+#define RLIMIT_FBSIZE 0x101 /* Maximum filesize in blocks */
+#ifdef __KERNEL__
+#define RLIMIT_MASK 0xff
+#endif
#define RLIM_NLIMITS 10
--- linux/include/asm-m68k/resource.h.jj Wed Dec 15 18:14:09 1999
+++ linux/include/asm-m68k/resource.h Fri Jan 14 15:33:57 2000
@@ -15,6 +15,10 @@
#define RLIMIT_NOFILE 7 /* max number of open files */
#define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space*/
#define RLIMIT_AS 9 /* address space limit */
+#define RLIMIT_FBSIZE 0x101 /* Maximum filesize in blocks */
+#ifdef __KERNEL__
+#define RLIMIT_MASK 0xff
+#endif
#define RLIM_NLIMITS 10
--- linux/include/asm-mips/resource.h.jj Wed Dec 15 18:14:09 1999
+++ linux/include/asm-mips/resource.h Fri Jan 14 15:34:14 2000
@@ -22,6 +22,10 @@
#define RLIMIT_RSS 7 /* max resident set size */
#define RLIMIT_NPROC 8 /* max number of processes */
#define RLIMIT_MEMLOCK 9 /* max locked-in-memory address space */
+#define RLIMIT_FBSIZE 0x101 /* Maximum filesize in blocks */
+#ifdef __KERNEL__
+#define RLIMIT_MASK 0xff
+#endif
#define RLIM_NLIMITS 10 /* Number of limit flavors. */
--- linux/include/asm-ppc/resource.h.jj Mon Dec 20 09:30:08 1999
+++ linux/include/asm-ppc/resource.h Fri Jan 14 15:33:50 2000
@@ -11,6 +11,10 @@
#define RLIMIT_NOFILE 7 /* max number of open files */
#define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */
#define RLIMIT_AS 9 /* address space limit(?) */
+#define RLIMIT_FBSIZE 0x101 /* Maximum filesize in blocks */
+#ifdef __KERNEL__
+#define RLIMIT_MASK 0xff
+#endif
#define RLIM_NLIMITS 10
--- linux/include/asm-sh/resource.h.jj Wed Dec 15 18:14:09 1999
+++ linux/include/asm-sh/resource.h Fri Jan 14 15:34:08 2000
@@ -15,6 +15,10 @@
#define RLIMIT_NOFILE 7 /* max number of open files */
#define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */
#define RLIMIT_AS 9 /* address space limit */
+#define RLIMIT_FBSIZE 0x101 /* Maximum filesize in blocks */
+#ifdef __KERNEL__
+#define RLIMIT_MASK 0xff
+#endif
#define RLIM_NLIMITS 10
--- linux/include/asm-sparc/resource.h.jj Wed Dec 15 18:45:53 1999
+++ linux/include/asm-sparc/resource.h Fri Jan 14 16:10:05 2000
@@ -21,6 +21,10 @@
#define RLIMIT_NPROC 7 /* max number of processes */
#define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */
#define RLIMIT_AS 9 /* address space limit */
+#define RLIMIT_FBSIZE 0x101 /* Maximum filesize in blocks */
+#ifdef __KERNEL__
+#define RLIMIT_MASK 0xff
+#endif
#define RLIM_NLIMITS 10
@@ -29,7 +33,7 @@
* We make this unsigned, but keep the
* old value.
*/
-#define RLIM_INFINITY 0x7fffffff
+#define RLIM_INFINITY 0x7fffffffU
#ifdef __KERNEL__
#define INIT_RLIMITS \
--- linux/include/asm-sparc64/resource.h.jj Wed Dec 15 18:46:04 1999
+++ linux/include/asm-sparc64/resource.h Fri Jan 14 15:34:03 2000
@@ -21,6 +21,10 @@
#define RLIMIT_NPROC 7 /* max number of processes */
#define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */
#define RLIMIT_AS 9 /* address space limit */
+#define RLIMIT_FBSIZE 0x101 /* Maximum filesize in blocks */
+#ifdef __KERNEL__
+#define RLIMIT_MASK 0xff
+#endif
#define RLIM_NLIMITS 10
--- linux/kernel/sys.c.jj Fri Jan 14 09:44:36 2000
+++ linux/kernel/sys.c Fri Jan 14 18:21:35 2000
@@ -900,10 +900,23 @@ asmlinkage long sys_setdomainname(char *
asmlinkage long sys_getrlimit(unsigned int resource, struct rlimit *rlim)
{
- if (resource >= RLIM_NLIMITS)
+ struct rlimit x;
+ if (resource == RLIMIT_FSIZE) {
+ x = current->rlim[resource];
+ if (x.rlim_cur > (RLIM_INFINITY >> 9))
+ x.rlim_cur = RLIM_INFINITY;
+ else
+ x.rlim_cur <<= 9;
+ if (x.rlim_max > (RLIM_INFINITY >> 9))
+ x.rlim_max = RLIM_INFINITY;
+ else
+ x.rlim_max <<= 9;
+ return copy_to_user(rlim, &x, sizeof(x)) ? -EFAULT : 0;
+ }
+ if (resource >= RLIM_NLIMITS && resource != RLIMIT_FBSIZE)
return -EINVAL;
else
- return copy_to_user(rlim, current->rlim + resource, sizeof(*rlim))
+ return copy_to_user(rlim, current->rlim + (resource & RLIMIT_MASK), sizeof(*rlim))
? -EFAULT : 0;
}
@@ -914,10 +927,23 @@ asmlinkage long sys_getrlimit(unsigned i
asmlinkage long sys_old_getrlimit(unsigned int resource, struct rlimit *rlim)
{
struct rlimit x;
- if (resource >= RLIM_NLIMITS)
+
+ if (resource == RLIMIT_FSIZE) {
+ x = current->rlim[resource];
+ if (x.rlim_cur > (0x7FFFFFFF >> 9))
+ x.rlim_cur = 0x7FFFFFFF;
+ else
+ x.rlim_cur <<= 9;
+ if (x.rlim_max > (0x7FFFFFFF >> 9))
+ x.rlim_max = 0x7FFFFFFF;
+ else
+ x.rlim_max <<= 9;
+ return copy_to_user(rlim, &x, sizeof(x)) ? -EFAULT : 0;
+ }
+ if (resource >= RLIM_NLIMITS && resource != RLIMIT_FBSIZE)
return -EINVAL;
- memcpy(&x, current->rlim + resource, sizeof(*rlim));
+ x = current->rlim[resource & RLIMIT_MASK];
if(x.rlim_cur > 0x7FFFFFFF)
x.rlim_cur = 0x7FFFFFFF;
if(x.rlim_max > 0x7FFFFFFF)
@@ -930,13 +956,17 @@ asmlinkage long sys_setrlimit(unsigned i
{
struct rlimit new_rlim, *old_rlim;
- if (resource >= RLIM_NLIMITS)
+ if (resource >= RLIM_NLIMITS && resource != RLIMIT_FBSIZE)
return -EINVAL;
if(copy_from_user(&new_rlim, rlim, sizeof(*rlim)))
return -EFAULT;
- if (new_rlim.rlim_cur < 0 || new_rlim.rlim_max < 0)
- return -EINVAL;
- old_rlim = current->rlim + resource;
+ old_rlim = current->rlim + (resource & RLIMIT_MASK);
+ if (resource == RLIMIT_FSIZE) {
+ if (new_rlim.rlim_cur != RLIM_INFINITY)
+ new_rlim.rlim_cur = (new_rlim.rlim_cur + 511) >> 9;
+ if (new_rlim.rlim_max != RLIM_INFINITY)
+ new_rlim.rlim_max = (new_rlim.rlim_max + 511) >> 9;
+ }
if (((new_rlim.rlim_cur > old_rlim->rlim_max) ||
(new_rlim.rlim_max > old_rlim->rlim_max)) &&
!capable(CAP_SYS_RESOURCE))
--- linux/mm/filemap.c.jj Fri Jan 14 09:44:37 2000
+++ linux/mm/filemap.c Fri Jan 14 16:38:07 2000
@@ -1846,7 +1846,7 @@ generic_file_write(struct file *file, co
{
struct dentry *dentry = file->f_dentry;
struct inode *inode = dentry->d_inode;
- unsigned long limit = current->rlim[RLIMIT_FSIZE].rlim_cur;
+ unsigned long long limit = current->rlim[RLIMIT_FSIZE].rlim_cur;
loff_t pos;
struct page *page, *cached_page;
unsigned long written;
@@ -1878,6 +1878,7 @@ generic_file_write(struct file *file, co
*/
err = -EFBIG;
if (limit != RLIM_INFINITY) {
+ limit <<= 9;
if (pos >= limit) {
send_sig(SIGXFSZ, current, 0);
goto out;
Cheers,
Jakub
___________________________________________________________________
Jakub Jelinek | jakub@redhat.com | http://sunsite.mff.cuni.cz/~jj
Linux version 2.3.39 on a sparc64 machine (1343.49 BogoMips)
___________________________________________________________________
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/
This archive was generated by hypermail 2b29 : Sat Jan 15 2000 - 21:00:26 EST