If you mmap a file in a region bigger than a the file, you will indeedQuote:>It appears that it is possible to provide roughly this type of
>functionality on UNIX using mmap(2) and lseek(2). In this case, you
>could mmap(2) a large chunk of virtual address space, without
>allocating any backing store in the corresponding file. SIGBUS should
>occur when a process accesses a portion of the address space that is
>not in backing store, and the signal handler could then extend the
get a SIGBUS when you touch a page at the end of the file.
Alternatively, you can create a large empty file (a file that
consists of a hole by just setting the size big enough) and use that.
In that case the SIGBUS is generated when the disk is full, storage
allocation is automatic. More modern versions of Mmap() come with
the MAP_NORESERVE (MAP_AUTORESERV) option. This allows you to map
anonymous memory (/dev/zero on Suns) without reserving the backing
store. Also some systems have MAP_AUTOGROW which will automatically
grow the object when needed.
Only when you want to grow an object and don't have MAP_AUTOGROW, you'll
get a SIGBUS signal when it is possible to perform an action to remedy
the problem. In all other cases SIGBUS means out of disk space or
out of swap space.
I've only used mmap with a "holey" file and in that case I usedQuote:>However, it seems that this approach is fraught with peril under UNIX
>since SIGBUS may mean other things besides "no backing store." Has
>anyone ever used this approach successful on UNIX?
SIGBUS to detect a full disk.
On many unixes it is possible to specify get more information about how
thw SIGBUS happened (which address, whether it was an allignement error
or an address error, etc).