From patchwork Wed Jun 15 06:36:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kazuya Mio X-Patchwork-Id: 100484 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 50704B6F8C for ; Wed, 15 Jun 2011 16:42:33 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753098Ab1FOGmc (ORCPT ); Wed, 15 Jun 2011 02:42:32 -0400 Received: from TYO202.gate.nec.co.jp ([202.32.8.206]:64731 "EHLO tyo202.gate.nec.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752939Ab1FOGmb (ORCPT ); Wed, 15 Jun 2011 02:42:31 -0400 Received: from mailgate3.nec.co.jp ([10.7.69.197]) by tyo202.gate.nec.co.jp (8.13.8/8.13.4) with ESMTP id p5F6gSVD000024; Wed, 15 Jun 2011 15:42:28 +0900 (JST) Received: (from root@localhost) by mailgate3.nec.co.jp (8.11.7/3.7W-MAILGATE-NEC) id p5F6gSM04649; Wed, 15 Jun 2011 15:42:28 +0900 (JST) Received: from mail03.kamome.nec.co.jp (mail03.kamome.nec.co.jp [10.25.43.7]) by mailsv3.nec.co.jp (8.13.8/8.13.4) with ESMTP id p5F6gSVj014750; Wed, 15 Jun 2011 15:42:28 +0900 (JST) Received: from shintaro.jp.nec.com ([10.26.220.11] [10.26.220.11]) by mail03.kamome.nec.co.jp with ESMTP id BT-MMP-1621865; Wed, 15 Jun 2011 15:36:42 +0900 Received: from [10.64.168.30] ([10.64.168.30] [10.64.168.30]) by mail.jp.nec.com with ESMTP; Wed, 15 Jun 2011 15:36:41 +0900 Message-ID: <4DF852F8.2020208@sx.jp.nec.com> Date: Wed, 15 Jun 2011 15:36:40 +0900 From: Kazuya Mio User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; ja; rv:1.9.2.18) Gecko/20110613 Thunderbird/3.1.11 MIME-Version: 1.0 To: ext4 , Theodore Tso Subject: [PATCH 06/11 RESEND] e4defrag: Allow user who has read+write access to defrag Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Anyone who has read+write access can defrag the file for this fix. Currently, non-root user needs owner authority to defrag the file. But non-root user who is not owner might have read+write access. Signed-off-by: Kazuya Mio --- misc/e4defrag.8.in | 3 +-- misc/e4defrag.c | 25 ++++--------------------- 2 files changed, 5 insertions(+), 23 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/misc/e4defrag.8.in b/misc/e4defrag.8.in index 81adc29..1159fd6 100644 --- a/misc/e4defrag.8.in +++ b/misc/e4defrag.8.in @@ -43,9 +43,8 @@ is a device or a mount point, .B e4defrag doesn't defragment files in mount point of other device. .PP -Non-privileged users can execute .B e4defrag -to their own file. +can be called for the file only if read and write access are allowed. .SH AUTHOR Written by Akira Fujita and Takashi Sato . diff --git a/misc/e4defrag.c b/misc/e4defrag.c index 417639d..f4ced9a 100644 --- a/misc/e4defrag.c +++ b/misc/e4defrag.c @@ -148,7 +148,6 @@ int block_size; int extents_before_defrag; int extents_after_defrag; int mode_flag; -unsigned int current_uid; unsigned int defraged_file_count; unsigned int frag_files_before_defrag; unsigned int frag_files_after_defrag; @@ -466,6 +465,7 @@ static int check_free_size(int fd, const char *file, ext4_fsblk_t blk_count) { ext4_fsblk_t free_blk_count; struct statfs64 fsbuf; + uid_t current_uid = getuid(); if (fstatfs64(fd, &fsbuf) < 0) { if (mode_flag & DETAIL) { @@ -517,13 +517,12 @@ static int file_frag_count(int fd) * file_check() - Check file's attributes. * * @fd: defrag target file's descriptor. - * @buf: a pointer of the struct stat64. * @file: file name. * @extents: file extents. * @blk_count: file blocks. */ -static int file_check(int fd, const struct stat64 *buf, const char *file, - int extents, ext4_fsblk_t blk_count) +static int file_check(int fd, const char *file, int extents, + ext4_fsblk_t blk_count) { int ret; struct flock lock; @@ -547,20 +546,6 @@ static int file_check(int fd, const struct stat64 *buf, const char *file, return -1; } - /* Access authority */ - if (current_uid != ROOT_UID && - buf->st_uid != current_uid) { - if (mode_flag & DETAIL) { - printf("\033[79;0H\033[K[%u/%u] \"%s\"\t\t" - " extents: %d -> %d\n", defraged_file_count, - total_count, file, extents, extents); - IN_FTW_PRINT_ERR_MSG( - "File is not current user's file" - " or current user is not root"); - } - return -1; - } - /* Lock status */ if (fcntl(fd, F_GETLK, &lock) < 0) { if (mode_flag & DETAIL) { @@ -1040,7 +1025,7 @@ static int file_defrag(const char *file, const struct stat64 *buf, file_frags_start = get_exts_count(orig_list); blk_count = get_file_blocks(orig_list); - if (file_check(fd, buf, file, file_frags_start, blk_count) < 0) + if (file_check(fd, file, file_frags_start, blk_count) < 0) goto out; if (fsync(fd) < 0) { @@ -1243,8 +1228,6 @@ int main(int argc, char *argv[]) if (argc == optind) goto out; - current_uid = getuid(); - /* Main process */ for (i = optind; i < argc; i++) { succeed_cnt = 0;