/* Copyright (c) 2007-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "ioloop.h"
#include "array.h"
#include "hex-dec.h"
#include "hex-binary.h"
#include "hostpid.h"
#include "istream.h"
#include "ostream.h"
#include "file-lock.h"
#include "file-set-size.h"
#include "mkdir-parents.h"
#include "fdatasync-path.h"
#include "eacces-error.h"
#include "str.h"
#include "mailbox-list-private.h"
#include "mdbox-storage.h"
#include "mdbox-map-private.h"
#include "mdbox-file.h"
#include <stdio.h>
#include <unistd.h>
#include <ctype.h>
#include <fcntl.h>
static struct mdbox_file *
{
unsigned int i, count;
for (i = 0; i < count; i++) {
return files[i];
}
return NULL;
}
{
unsigned int i, count;
for (i = 0; i < count; i++)
}
{
unsigned int i, count;
for (i = 0; i < count; i++) {
}
}
static void
{
unsigned int i, count;
for (i = 0; i < count;) {
if (--close_count == 0)
break;
} else {
i++;
}
}
}
static void
{
fname);
}
}
{
bool create_parents;
int ret;
return -1;
if (ret < 0) {
switch (errno) {
case ENOSPC:
case EDQUOT:
/* ignore */
break;
default:
i_error("file_preallocate(%s) failed: %m",
break;
}
} else if (ret == 0) {
/* not supported by filesystem, disable. */
}
}
return 0;
}
static struct dbox_file *
{
const char *fname;
unsigned int count;
}
if (count > MDBOX_MAX_OPEN_UNUSED_FILES) {
}
if (alt_dir)
if (file_id != 0)
else
(void)mdbox_file_create(file);
}
struct dbox_file *
{
}
struct dbox_file *
{
}
{
const char *old_path;
"mdbox: %s already exists, rebuilding index", new_path);
return -1;
}
"rename(%s, %s) failed: %m",
return -1;
}
return 0;
}
static struct mdbox_file *
unsigned int *idx_r)
{
unsigned int i, count;
for (i = 0; i < count; i++) {
if (oldest_file == NULL ||
oldest_file = files[i];
*idx_r = i;
}
}
}
return oldest_file;
}
{
unsigned int i;
break;
}
}
{
}
}
{
unsigned int i, count;
/* don't cache metadata seeks while file isn't being referenced */
if (count <= MDBOX_MAX_OPEN_UNUSED_FILES) {
/* we can leave this file open for now */
return;
}
/* close the oldest file with refcount=0 */
if (oldest_file != mfile) {
return;
}
/* have to close ourself */
}
}
{
const char *p, *dir;
int fd;
MAILBOX_LIST_PATH_TYPE_ALT_DIR) < 0) {
return -1;
}
/* try again */
}
if (fd == -1) {
"open(%s, O_CREAT) failed: %m", path);
/* no group change */
} else {
"fchown(%s, -1, %ld) failed: %m",
}
/* continue anyway */
}
return fd;
}