clamav/libclamav/fmap.h

86 lines
2.4 KiB
C
Raw Normal View History

2009-08-20 01:34:03 +02:00
/*
* Copyright (C) 2009 Sourcefire, Inc.
*
* Authors: aCaB <acab@clamav.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
2009-08-20 02:19:57 +02:00
#ifndef __FMAP_H
#define __FMAP_H
2009-08-20 01:34:03 +02:00
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
2009-12-11 21:12:38 +02:00
#include <time.h>
2009-08-31 04:41:06 +02:00
#include "cltypes.h"
2009-10-02 18:09:31 +02:00
typedef struct {
int _fd;
2010-03-05 17:42:25 +01:00
unsigned short dumb;
unsigned short dont_cache_flag;
2009-08-31 04:41:06 +02:00
time_t mtime;
size_t offset;
size_t len;
unsigned int pages;
unsigned int hdrsz;
unsigned int pgsz;
unsigned int paged;
2009-10-10 20:46:05 +02:00
#ifdef _WIN32
2009-10-10 19:10:15 +02:00
HANDLE fh;
HANDLE mh;
void *data;
2009-09-10 03:19:43 +02:00
#endif
uint32_t placeholder_for_bitmap;
2009-10-02 18:09:31 +02:00
} fmap_t;
2009-08-20 01:34:03 +02:00
2009-10-02 18:09:31 +02:00
fmap_t *fmap(int fd, off_t offset, size_t len);
2010-05-04 18:48:11 +02:00
fmap_t *fmap_check_empty(int fd, off_t offset, size_t len, int *empty);
2009-10-02 18:09:31 +02:00
void funmap(fmap_t *m);
void *fmap_need_off(fmap_t *m, size_t at, size_t len);
void *fmap_need_off_once(fmap_t *m, size_t at, size_t len);
void *fmap_need_ptr(fmap_t *m, void *ptr, size_t len);
void *fmap_need_ptr_once(fmap_t *m, void *ptr, size_t len);
void fmap_unneed_off(fmap_t *m, size_t at, size_t len);
void fmap_unneed_ptr(fmap_t *m, void *ptr, size_t len);
int fmap_readn(fmap_t *m, void *dst, size_t at, size_t len);
void *fmap_need_str(fmap_t *m, void *ptr, size_t len_hint);
void *fmap_need_offstr(fmap_t *m, size_t at, size_t len_hint);
void *fmap_gets(fmap_t *m, char *dst, size_t *at, size_t max_len);
2011-06-10 17:02:10 +03:00
static inline const void *fmap_need_off_once_len(fmap_t *m, size_t at, size_t len, size_t *lenout)
{
2011-06-13 11:55:34 +03:00
const void *p;
2011-06-10 17:02:10 +03:00
if(at >= m->len) {
*lenout = 0;
return NULL;
}
if(len > m->len - at)
len = m->len - at;
2011-06-13 11:55:34 +03:00
p = fmap_need_off_once(m, at, len);
*lenout = p ? len : -1;
return p;
2011-06-10 17:02:10 +03:00
}
static inline const void *fmap_need_ptr_once_len(fmap_t *m, const void *ptr, size_t len, size_t *lenout)
{
return fmap_need_off_once_len(m, (char*)ptr - (char*)m - m->hdrsz, len, lenout);
}
int fmap_fd(fmap_t *m);
2009-08-20 02:19:57 +02:00
#endif