From owner-freebsd-hackers@FreeBSD.ORG Wed Nov 5 22:51:23 2008 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C6112106567C for ; Wed, 5 Nov 2008 22:51:23 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from server.baldwin.cx (bigknife-pt.tunnel.tserv9.chi1.ipv6.he.net [IPv6:2001:470:1f10:75::2]) by mx1.freebsd.org (Postfix) with ESMTP id 4135C8FC19 for ; Wed, 5 Nov 2008 22:51:23 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from localhost.corp.yahoo.com (john@localhost [IPv6:::1]) (authenticated bits=0) by server.baldwin.cx (8.14.3/8.14.3) with ESMTP id mA5MpEQp015990; Wed, 5 Nov 2008 17:51:15 -0500 (EST) (envelope-from jhb@freebsd.org) From: John Baldwin To: freebsd-hackers@freebsd.org Date: Wed, 5 Nov 2008 17:17:34 -0500 User-Agent: KMail/1.9.7 References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200811051717.34933.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-2.0.2 (server.baldwin.cx [IPv6:::1]); Wed, 05 Nov 2008 17:51:15 -0500 (EST) X-Virus-Scanned: ClamAV 0.93.1/8576/Wed Nov 5 13:28:48 2008 on server.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=-2.6 required=4.2 tests=AWL,BAYES_00,NO_RELAYS autolearn=ham version=3.1.3 X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on server.baldwin.cx Cc: Jeremy Messenger Subject: Re: preallocate files without (posix_)fallocate or fcntl's F_PREALLOCATE? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Nov 2008 22:51:23 -0000 On Wednesday 05 November 2008 12:08:11 pm Jeremy Messenger wrote: > Hello folks, > > At first, I don't really know C that well so... It's more of request or > suggest if anyone is bored or interest to port on FreeBSD. :-) > > Recently, Transmission has added preallocate files to prevent disk > fragmentation but FreeBSD does not has any of (posix_)fallocate or fcntl's > F_PREALLOCATE (checked in RELENG_7's src/* and manpages). Here's what it > looks like: > > ---------------------------------------- > static int > preallocateFile( int fd UNUSED, uint64_t length UNUSED ) > { > #ifdef HAVE_FALLOCATE > > return fallocate( fd, 0, offset, length ); > > #elif defined(HAVE_POSIX_FALLOCATE) > > return posix_fallocate( fd, 0, length ); > > #elif defined(SYS_DARWIN) > > fstore_t fst; > fst.fst_flags = F_ALLOCATECONTIG; > fst.fst_posmode = F_PEOFPOSMODE; > fst.fst_offset = 0; > fst.fst_length = length; > fst.fst_bytesalloc = 0; > return fcntl( fd, F_PREALLOCATE, &fst ); > > #else > > #warning no known method to preallocate files on this platform > return -1; > > #endif > } > ---------------------------------------- > > You can see a bit more over at > http://trac.transmissionbt.com/changeset/7051 .. You can also point me to > some sources if it exists for I can try do it by myself, but with lacking > C knowledge is a bit hard for me at the most of time. I don't know if UFS > does not need or does need it. If anyone is interesting to write simple > one for FreeBSD will be cool. Thanks! UFS would benefit. See the notes on MAP_NOSYNC in mmap(2). Peter Wemm (peter@) probably can give a more detailed suggestion of what you would need to do. Doing it efficiently would probably require a new VOP_ALLOCATE() or some such. -- John Baldwin