snapraid/cmdline/unix.h

74 lines
1.8 KiB
C
Raw Normal View History

// SPDX-License-Identifier: GPL-3.0-or-later
2026-04-02 16:25:49 +02:00
// Copyright (C) 2011 Andrea Mazzoleni
#ifndef __UNIX_H
#define __UNIX_H
#ifdef __linux__
#define HAVE_LINUX_DEVICE 1 /**< In Linux enables special device support. */
2016-05-15 14:18:44 +02:00
#define HAVE_DIRECT_IO 1 /**< Support O_DIRECT in open(). */
#endif
#define O_BINARY 0 /**< Not used in Unix. */
#define O_SEQUENTIAL 0 /**< In Unix posix_fadvise() shall be used. */
#if HAVE_POSIX_FADVISE
int posix_fadvise_wrapper(int fd, off_t offset, off_t len, int advice);
#endif
/**
* If nanoseconds are not supported, we report the special STAT_NSEC_INVALID value,
* to mark that it's undefined.
*/
#define STAT_NSEC_INVALID -1
/* Check if we have nanoseconds support */
#if HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC
#define STAT_NSEC(st) ((int)(st)->st_mtim.tv_nsec) /* Linux */
#elif HAVE_STRUCT_STAT_ST_MTIMENSEC
#define STAT_NSEC(st) ((int)(st)->st_mtimensec) /* NetBSD */
#elif HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC
#define STAT_NSEC(st) ((int)(st)->st_mtimespec.tv_nsec) /* FreeBSD, Mac OS X */
#else
#define STAT_NSEC(st) STAT_NSEC_INVALID
#endif
/**
2016-01-02 16:52:20 +01:00
* Open a file with the O_NOATIME flag to avoid to update the access time.
*/
int open_noatime(const char* file, int flags);
/**
* Check if the specified file is hidden.
*/
int dirent_hidden(struct dirent* dd);
/**
* Return a description of the file type.
*/
const char* stat_desc(struct stat* st);
2016-05-15 14:18:44 +02:00
/**
2020-05-02 14:21:40 +02:00
* Return the alignment requirement for direct IO.
2016-05-15 14:18:44 +02:00
*/
size_t direct_size(void);
2026-03-02 01:13:19 +01:00
/****************************************************************************/
/* thread */
#if HAVE_PTHREAD_H
#include <pthread.h>
#endif
2026-04-30 11:38:01 +02:00
#if HAVE_PTHREAD
2026-03-02 01:13:19 +01:00
#define HAVE_THREAD 1
typedef pthread_t thread_id_t;
typedef pthread_mutex_t thread_mutex_t;
typedef pthread_cond_t thread_cond_t;
typedef pthread_key_t thread_key_t;
2026-03-02 01:13:19 +01:00
#endif
#endif