Date: Sat, 15 Feb 2003 17:16:12 +1100 From: Peter Jeremy <peterjeremy@optushome.com.au> To: Terry Lambert <tlambert2@mindspring.com> Cc: arch@FreeBSD.ORG Subject: Controlling spaseness (was Re: syslog.conf syntax change ...) Message-ID: <20030215061612.GA60369@cirb503493.alcatel.com.au> In-Reply-To: <3E4DB9F1.83B7746D@mindspring.com> References: <20030210114930.GB90800@melusine.cuivre.fr.eu.org> <20030214220145.GM83215@roark.gnf.org> <3E4D7C2B.DDFC9DBE@mindspring.com> <200302141725.00421.wes@softweyr.com> <3E4DB9F1.83B7746D@mindspring.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Feb 14, 2003 at 07:54:25PM -0800, Terry Lambert wrote: >BTW: the SVR4 fcntl() that's the moral equivalent of ftruncate >supports exactly the syntax you want (e.g. free up space at the >start of the file for 60M-120K, replacing with sparseness -- it >can put sparse blocks in the middle of files). ... >If you do this, just implement the SVR4 fcntl(); it basically takes >an fcntl() lock structure, e.g.: > > > fcntl( fd, F_FREESP, struct flock *) > > l_whence SEEK_SET/SEEK_CUR/SEEK_END > l_start > l_len This triggered a line of thought: One problem for archivers that access through the filesystem is that they are unable to differentiate between a block of NULs and a sparse block. The best they can do is guess. Dump(8) avoids the problem by reading the underlying device - but this means it has to re-implement UFS (at least the read-only bits). A reasonably simple solution to this would be an fcntl(2) option that returned a bitmap of allocated blocks: fcntl(fd, F_GETBITMAP, struct bitmap *); struct bitmap { size_t bm_len; /* size of bm_bitmap - I (O?) */ u_int32_t bm_blksiz; /* blocksize of bitmap - O */ off_t bm_filsiz; /* file size in bytes - O */ char bm_bitmap[]; /* bm_len bytes - O */ } bm_bitmap could be a pointer to the bitmap rather than using a variable length struct. bm_filsiz allows you to determine whether the final block is a fragment (and the size thereof). A logical extension is then to provide a F_SETBITMAP function that alters the block allocation to match the passed bitmap - either releasing blocks or filling in the holes as requested. This makes it a superset of ftruncate(). Both these functions seem fairly trivial to implement - at least for UFS. I'm not sure which other local filesystems support sparse files or whether NFS gives the client access to sparseness information. Peter To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030215061612.GA60369>