On Sat, Feb 15, 2025 at 4:14 PM Cedric Blancher via Cygwin
<[email protected]> wrote:
> Could Cygwin 3.6 please support fcntl(...,F_FREESP,...) and
> cntl(...,F_FREESP64,...), as specified in
> https://docs.oracle.com/cd/E19253-01/816-5167/fcntl-2/index.html
>
> Lots of older software from Solaris, SUPER/UX, CrayOS use F_FREESP for
> punching a hole into a file, and IMO it'll be nice if this works for
> Cygwin out of the box.

1. Ced: Could you please check whether the prototype code works for
you ? If "yes" then I'll make a patch for cygwin.dll based on this...
2. Takashi: What do you think ? The API comes from Solaris, and is
implememted by at least FreeBSD, Unicos, SUPER/UX, etc. and is usually
used by database and HPC software.

Prototype patch:
---- snip ----
#ifndef F_FREESP
#define F_FREESP   15
#endif

#ifndef F_ALLOCSP
#define F_ALLOCSP  16
#endif

/* FIXME: This should use a |struct flock| like Solaris/FreeBSD |fnctl()| */
int fcntl_sparse_space_management_emulate(int fd, int cmd, off_t
offset, off_t len)
{
    off_t file_size;
    off_t end;

    file_size = lseek(fd, 0, SEEK_END);
    if (file_size == (off_t)-1)
        return -1;

    if (len == 0)
        end = file_size;
    else
        end = offset + len;

    switch (cmd) {

    case F_FREESP:
        if (offset >= file_size)
            return 0;

        if (end >= file_size) {
            return ftruncate(fd, offset);
        } else {
            if (fallocate(fd,
                          FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
                          offset,
                          end - offset) == -1) {
                return -1;
            }
        }
        return 0;

    case F_ALLOCSP:
        if (len == 0) {
            return 0;
        }

        if (fallocate(fd, 0, offset, len) == -1) {
            return -1;
        }

        return 0;

    default:
        errno = EINVAL;
        return -1;
    }
}
---- snip ----

----

Bye,
Roland
-- 
  __ .  . __
 (o.\ \/ /.o) [email protected]
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 3992797
 (;O/ \/ \O;)

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple

Reply via email to