From: James S. <jsi...@us...> - 2001-10-19 21:19:43
|
Update of /cvsroot/linux-mips/linux/fs/proc In directory usw-pr-cvs1:/tmp/cvs-serv13849/fs/proc Modified Files: array.c proc_misc.c Log Message: Synced to 2.4.10. Index: array.c =================================================================== RCS file: /cvsroot/linux-mips/linux/fs/proc/array.c,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- array.c 2001/09/17 16:49:28 1.4 +++ array.c 2001/10/19 21:19:40 1.5 @@ -522,11 +522,8 @@ /* * For the /proc/<pid>/maps file, we use fixed length records, each containing * a single line. - */ -#define MAPS_LINE_LENGTH 4096 -#define MAPS_LINE_SHIFT 12 -/* - * f_pos = (number of the vma in the task->mm->mmap list) * MAPS_LINE_LENGTH + * + * f_pos = (number of the vma in the task->mm->mmap list) * PAGE_SIZE * + (index into the line) */ /* for systems with sizeof(void*) == 4: */ @@ -537,136 +534,142 @@ #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 +#define MAPS_LINE_FORMAT (sizeof(void*) == 4 ? MAPS_LINE_FORMAT4 : MAPS_LINE_FORMAT8) +#define MAPS_LINE_MAX (sizeof(void*) == 4 ? MAPS_LINE_MAX4 : MAPS_LINE_MAX8) + +static int proc_pid_maps_get_line (char *buf, struct vm_area_struct *map) +{ + /* produce the next line */ + char *line; + char str[5]; + int flags; + kdev_t dev; + unsigned long ino; + int len; + + flags = map->vm_flags; + + str[0] = flags & VM_READ ? 'r' : '-'; + str[1] = flags & VM_WRITE ? 'w' : '-'; + str[2] = flags & VM_EXEC ? 'x' : '-'; + str[3] = flags & VM_MAYSHARE ? 's' : 'p'; + str[4] = 0; + dev = 0; + ino = 0; + if (map->vm_file != NULL) { + dev = map->vm_file->f_dentry->d_inode->i_dev; + ino = map->vm_file->f_dentry->d_inode->i_ino; + line = d_path(map->vm_file->f_dentry, + map->vm_file->f_vfsmnt, + buf, PAGE_SIZE); + buf[PAGE_SIZE-1] = '\n'; + line -= MAPS_LINE_MAX; + if(line < buf) + line = buf; + } else + line = buf; + len = sprintf(line, + MAPS_LINE_FORMAT, + map->vm_start, map->vm_end, str, map->vm_pgoff << PAGE_SHIFT, + kdevname(dev), ino); + + if(map->vm_file) { + int i; + for(i = len; i < MAPS_LINE_MAX; i++) + line[i] = ' '; + len = buf + PAGE_SIZE - line; + memmove(buf, line, len); + } else + line[len++] = '\n'; + return len; +} + ssize_t proc_pid_read_maps (struct task_struct *task, struct file * file, char * buf, size_t count, loff_t *ppos) { struct mm_struct *mm; - struct vm_area_struct * map, * next; - char * destptr = buf, * buffer; - loff_t lineno; - ssize_t column, i; - int volatile_task; + struct vm_area_struct * map; + char *tmp, *kbuf; long retval; + int off, lineno, loff; + /* reject calls with out of range parameters immediately */ + retval = 0; + if (*ppos > LONG_MAX) + goto out; + if (count == 0) + goto out; + off = (long)*ppos; /* * We might sleep getting the page, so get it first. */ retval = -ENOMEM; - buffer = (char*)__get_free_page(GFP_KERNEL); - if (!buffer) + kbuf = (char*)__get_free_page(GFP_KERNEL); + if (!kbuf) goto out; - if (count == 0) - goto getlen_out; + tmp = (char*)__get_free_page(GFP_KERNEL); + if (!tmp) + goto out_free1; + task_lock(task); mm = task->mm; if (mm) atomic_inc(&mm->mm_users); task_unlock(task); + retval = 0; if (!mm) - goto getlen_out; - - /* Check whether the mmaps could change if we sleep */ - volatile_task = (task != current || atomic_read(&mm->mm_users) > 2); - - /* decode f_pos */ - lineno = *ppos >> MAPS_LINE_SHIFT; - column = *ppos & (MAPS_LINE_LENGTH-1); + goto out_free2; - /* quickly go to line lineno */ down_read(&mm->mmap_sem); - for (map = mm->mmap, i = 0; map && (i < lineno); map = map->vm_next, i++) - continue; - - for ( ; map ; map = next ) { - /* produce the next line */ - char *line; - char str[5], *cp = str; - int flags; - kdev_t dev; - unsigned long ino; - int maxlen = (sizeof(void*) == 4) ? - MAPS_LINE_MAX4 : MAPS_LINE_MAX8; + map = mm->mmap; + lineno = 0; + loff = 0; + if (count > PAGE_SIZE) + count = PAGE_SIZE; + while (map) { int len; - - /* - * Get the next vma now (but it won't be used if we sleep). - */ - next = map->vm_next; - flags = map->vm_flags; - - *cp++ = flags & VM_READ ? 'r' : '-'; - *cp++ = flags & VM_WRITE ? 'w' : '-'; - *cp++ = flags & VM_EXEC ? 'x' : '-'; - *cp++ = flags & VM_MAYSHARE ? 's' : 'p'; - *cp++ = 0; - - dev = 0; - ino = 0; - if (map->vm_file != NULL) { - dev = map->vm_file->f_dentry->d_inode->i_dev; - ino = map->vm_file->f_dentry->d_inode->i_ino; - line = d_path(map->vm_file->f_dentry, - map->vm_file->f_vfsmnt, - buffer, PAGE_SIZE); - buffer[PAGE_SIZE-1] = '\n'; - line -= maxlen; - if(line < buffer) - line = buffer; - } else - line = buffer; - - len = sprintf(line, - sizeof(void*) == 4 ? MAPS_LINE_FORMAT4 : MAPS_LINE_FORMAT8, - map->vm_start, map->vm_end, str, map->vm_pgoff << PAGE_SHIFT, - kdevname(dev), ino); - - if(map->vm_file) { - for(i = len; i < maxlen; i++) - line[i] = ' '; - len = buffer + PAGE_SIZE - line; - } else - line[len++] = '\n'; - if (column >= len) { - column = 0; /* continue with next line at column 0 */ - lineno++; - continue; /* we haven't slept */ + if (off > PAGE_SIZE) { + off -= PAGE_SIZE; + goto next; } - - i = len-column; - if (i > count) - i = count; - copy_to_user(destptr, line+column, i); /* may have slept */ - destptr += i; - count -= i; - column += i; - if (column >= len) { - column = 0; /* next time: next line at column 0 */ - lineno++; + len = proc_pid_maps_get_line(tmp, map); + len -= off; + if (len > 0) { + if (retval+len > count) { + /* only partial line transfer possible */ + len = count - retval; + /* save the offset where the next read + * must start */ + loff = len+off; + } + memcpy(kbuf+retval, tmp+off, len); + retval += len; } - - /* done? */ - if (count == 0) - break; - - /* By writing to user space, we might have slept. - * Stop the loop, to avoid a race condition. - */ - if (volatile_task) + off = 0; +next: + if (!loff) + lineno++; + if (retval >= count) break; + if (loff) BUG(); + map = map->vm_next; } up_read(&mm->mmap_sem); - - /* encode f_pos */ - *ppos = (lineno << MAPS_LINE_SHIFT) + column; mmput(mm); -getlen_out: - retval = destptr - buf; - free_page((unsigned long)buffer); + if (retval > count) BUG(); + if (copy_to_user(buf, kbuf, retval)) + retval = -EFAULT; + else + *ppos = (lineno << PAGE_SHIFT) + loff; + +out_free2: + free_page((unsigned long)tmp); +out_free1: + free_page((unsigned long)kbuf); out: return retval; } Index: proc_misc.c =================================================================== RCS file: /cvsroot/linux-mips/linux/fs/proc/proc_misc.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- proc_misc.c 2001/08/25 02:19:28 1.2 +++ proc_misc.c 2001/10/19 21:19:40 1.3 @@ -145,12 +145,12 @@ * display in kilobytes. */ #define K(x) ((x) << (PAGE_SHIFT - 10)) -#define B(x) ((x) << PAGE_SHIFT) +#define B(x) ((unsigned long long)(x) << PAGE_SHIFT) si_meminfo(&i); si_swapinfo(&i); len = sprintf(page, " total: used: free: shared: buffers: cached:\n" - "Mem: %8lu %8lu %8lu %8lu %8lu %8u\n" - "Swap: %8lu %8lu %8lu\n", + "Mem: %8Lu %8Lu %8Lu %8Lu %8Lu %8Lu\n" + "Swap: %8Lu %8Lu %8Lu\n", B(i.totalram), B(i.totalram-i.freeram), B(i.freeram), B(i.sharedram), B(i.bufferram), B(atomic_read(&page_cache_size)), B(i.totalswap), @@ -168,9 +168,7 @@ "Cached: %8lu kB\n" "SwapCached: %8lu kB\n" "Active: %8u kB\n" - "Inact_dirty: %8u kB\n" - "Inact_clean: %8u kB\n" - "Inact_target: %8lu kB\n" + "Inactive: %8u kB\n" "HighTotal: %8lu kB\n" "HighFree: %8lu kB\n" "LowTotal: %8lu kB\n" @@ -184,9 +182,7 @@ K(atomic_read(&page_cache_size) - swapper_space.nrpages), K(swapper_space.nrpages), K(nr_active_pages), - K(nr_inactive_dirty_pages), - K(nr_inactive_clean_pages()), - K(inactive_target), + K(nr_inactive_pages), K(i.totalhigh), K(i.freehigh), K(i.totalram-i.totalhigh), @@ -573,7 +569,7 @@ entry->size = (1+prof_len) * sizeof(unsigned int); } } -#ifdef __powerpc__ +#ifdef CONFIG_PPC32 { extern struct file_operations ppc_htab_operations; entry = create_proc_entry("ppc_htab", S_IRUGO|S_IWUSR, NULL); |