2010-10-19 14:23:51 +00:00
|
|
|
/*
|
2011-07-19 18:32:58 +00:00
|
|
|
* virfile.h: safer file handling
|
2010-10-19 14:23:51 +00:00
|
|
|
*
|
2014-03-29 20:15:33 +00:00
|
|
|
* Copyright (C) 2010-2014 Red Hat, Inc.
|
2010-10-19 14:23:51 +00:00
|
|
|
* Copyright (C) 2010 IBM Corporation
|
|
|
|
* Copyright (C) 2010 Stefan Berger
|
|
|
|
* Copyright (C) 2010 Eric Blake
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2010-10-19 14:23:51 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-06-18 16:12:50 +00:00
|
|
|
#pragma once
|
2010-10-19 14:23:51 +00:00
|
|
|
|
2019-06-18 16:12:50 +00:00
|
|
|
#include <dirent.h>
|
2010-10-19 14:23:51 +00:00
|
|
|
|
2019-06-18 16:12:50 +00:00
|
|
|
#include "internal.h"
|
|
|
|
#include "virbitmap.h"
|
2021-01-06 11:56:11 +00:00
|
|
|
#include "virenum.h"
|
2010-10-19 14:23:51 +00:00
|
|
|
|
2014-04-27 00:15:22 +00:00
|
|
|
typedef enum {
|
2012-06-07 13:16:50 +00:00
|
|
|
VIR_FILE_CLOSE_PRESERVE_ERRNO = 1 << 0,
|
|
|
|
VIR_FILE_CLOSE_IGNORE_EBADF = 1 << 1,
|
|
|
|
VIR_FILE_CLOSE_DONT_LOG = 1 << 2,
|
|
|
|
} virFileCloseFlags;
|
2010-10-19 14:23:51 +00:00
|
|
|
|
2020-08-25 23:47:07 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
# define VIR_FILE_MODULE_EXT ".dylib"
|
|
|
|
#else
|
|
|
|
# define VIR_FILE_MODULE_EXT ".so"
|
|
|
|
#endif
|
|
|
|
|
2019-10-14 12:25:14 +00:00
|
|
|
ssize_t saferead(int fd, void *buf, size_t count) G_GNUC_WARN_UNUSED_RESULT;
|
2013-05-09 18:59:04 +00:00
|
|
|
ssize_t safewrite(int fd, const void *buf, size_t count)
|
2019-10-14 12:25:14 +00:00
|
|
|
G_GNUC_WARN_UNUSED_RESULT;
|
2015-01-07 15:49:00 +00:00
|
|
|
int safezero(int fd, off_t offset, off_t len)
|
2019-10-14 12:25:14 +00:00
|
|
|
G_GNUC_WARN_UNUSED_RESULT;
|
2017-09-25 14:29:34 +00:00
|
|
|
int virFileAllocate(int fd, off_t offset, off_t len)
|
2019-10-14 12:25:14 +00:00
|
|
|
G_GNUC_WARN_UNUSED_RESULT;
|
2013-05-09 18:59:04 +00:00
|
|
|
|
2010-11-17 02:13:29 +00:00
|
|
|
/* Don't call these directly - use the macros below */
|
2012-06-07 13:16:50 +00:00
|
|
|
int virFileClose(int *fdptr, virFileCloseFlags flags)
|
2019-10-14 12:25:14 +00:00
|
|
|
G_GNUC_WARN_UNUSED_RESULT;
|
|
|
|
int virFileFclose(FILE **file, bool preserve_errno) G_GNUC_WARN_UNUSED_RESULT;
|
|
|
|
FILE *virFileFdopen(int *fdptr, const char *mode) G_GNUC_WARN_UNUSED_RESULT;
|
2010-10-19 14:23:51 +00:00
|
|
|
|
2018-09-12 09:46:34 +00:00
|
|
|
static inline void virForceCloseHelper(int *fd)
|
|
|
|
{
|
|
|
|
ignore_value(virFileClose(fd, VIR_FILE_CLOSE_PRESERVE_ERRNO));
|
|
|
|
}
|
|
|
|
|
2010-10-19 14:23:51 +00:00
|
|
|
/* For use on normal paths; caller must check return value,
|
maint: reject raw close, popen in 'make syntax-check'
commit f1fe9671e was supposed to make sure we use files.h
macros to avoid double close, but it didn't work.
Meanwhile, virCommand is vastly superior to system(), fork(),
and popen() (also to virExec, but we haven't completed that
conversion), so enforce that, too.
* cfg.mk (sc_prohibit_close): Fix typo that excluded close, and
add pclose.
(sc_prohibit_fork_wrappers): New rule, for fork, system, and popen.
* .x-sc_prohibit_close: More exemptions.
* .x-sc_prohibit_fork_wrappers: New file.
* Makefile.am (syntax_check_exceptions): Ship new file.
* src/datatypes.c (virReleaseConnect): Tweak comment to avoid
false positive.
* src/util/files.h (VIR_CLOSE): Likewise.
2011-01-27 22:16:14 +00:00
|
|
|
and failure sets errno per close. */
|
2019-06-18 16:12:50 +00:00
|
|
|
#define VIR_CLOSE(FD) virFileClose(&(FD), 0)
|
|
|
|
#define VIR_FCLOSE(FILE) virFileFclose(&(FILE), false)
|
2010-11-17 02:13:29 +00:00
|
|
|
|
|
|
|
/* Wrapper around fdopen that consumes fd on success. */
|
2019-06-18 16:12:50 +00:00
|
|
|
#define VIR_FDOPEN(FD, MODE) virFileFdopen(&(FD), MODE)
|
2010-10-19 14:23:51 +00:00
|
|
|
|
|
|
|
/* For use on cleanup paths; errno is unaffected by close,
|
|
|
|
and no return value to worry about. */
|
2019-06-18 16:12:50 +00:00
|
|
|
#define VIR_FORCE_CLOSE(FD) virForceCloseHelper(&(FD))
|
|
|
|
#define VIR_FORCE_FCLOSE(FILE) ignore_value(virFileFclose(&(FILE), true))
|
2010-10-19 14:23:51 +00:00
|
|
|
|
2012-05-30 13:54:18 +00:00
|
|
|
/* Similar VIR_FORCE_CLOSE() but ignores EBADF errors since they are expected
|
|
|
|
* during mass close after fork(). */
|
2019-06-18 16:12:50 +00:00
|
|
|
#define VIR_MASS_CLOSE(FD) \
|
2017-11-03 12:09:47 +00:00
|
|
|
ignore_value(virFileClose(&(FD), \
|
|
|
|
VIR_FILE_CLOSE_PRESERVE_ERRNO | \
|
2012-06-07 13:16:50 +00:00
|
|
|
VIR_FILE_CLOSE_IGNORE_EBADF))
|
|
|
|
|
2019-06-18 16:12:50 +00:00
|
|
|
#define VIR_LOG_CLOSE(FD) \
|
2017-11-03 12:09:47 +00:00
|
|
|
ignore_value(virFileClose(&(FD), \
|
|
|
|
VIR_FILE_CLOSE_PRESERVE_ERRNO | \
|
2012-06-07 13:16:50 +00:00
|
|
|
VIR_FILE_CLOSE_DONT_LOG))
|
2012-05-30 13:54:18 +00:00
|
|
|
|
2018-09-12 09:46:34 +00:00
|
|
|
/**
|
|
|
|
* VIR_AUTOCLOSE:
|
|
|
|
*
|
|
|
|
* Macro to automatically force close the fd by calling virForceCloseHelper
|
|
|
|
* when the fd goes out of scope. It's used to eliminate VIR_FORCE_CLOSE
|
|
|
|
* in cleanup sections.
|
|
|
|
*/
|
2019-06-18 16:12:50 +00:00
|
|
|
#define VIR_AUTOCLOSE __attribute__((cleanup(virForceCloseHelper))) int
|
2018-09-12 09:46:34 +00:00
|
|
|
|
2020-03-31 23:01:27 +00:00
|
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(FILE, fclose);
|
2018-09-12 09:46:34 +00:00
|
|
|
|
2012-02-06 13:40:48 +00:00
|
|
|
/* Opaque type for managing a wrapper around a fd. */
|
|
|
|
struct _virFileWrapperFd;
|
2011-07-11 21:26:33 +00:00
|
|
|
|
2012-02-06 13:40:48 +00:00
|
|
|
typedef struct _virFileWrapperFd virFileWrapperFd;
|
2011-07-11 21:26:33 +00:00
|
|
|
|
|
|
|
int virFileDirectFdFlag(void);
|
|
|
|
|
2014-04-27 00:15:22 +00:00
|
|
|
typedef enum {
|
2012-02-06 13:40:48 +00:00
|
|
|
VIR_FILE_WRAPPER_BYPASS_CACHE = (1 << 0),
|
|
|
|
VIR_FILE_WRAPPER_NON_BLOCKING = (1 << 1),
|
2014-04-27 00:15:22 +00:00
|
|
|
} virFileWrapperFdFlags;
|
2012-02-06 13:40:48 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virFileWrapperFd *virFileWrapperFdNew(int *fd,
|
2012-02-06 13:40:48 +00:00
|
|
|
const char *name,
|
|
|
|
unsigned int flags)
|
2019-10-14 12:25:14 +00:00
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT;
|
2011-07-11 21:26:33 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
int virFileWrapperFdClose(virFileWrapperFd *dfd);
|
2011-07-11 21:26:33 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
void virFileWrapperFdFree(virFileWrapperFd *dfd);
|
2011-07-11 21:26:33 +00:00
|
|
|
|
2018-12-07 12:21:43 +00:00
|
|
|
int virFileLock(int fd, bool shared, off_t start, off_t len, bool waitForLock)
|
2019-10-15 11:24:34 +00:00
|
|
|
G_GNUC_NO_INLINE;
|
2018-12-07 12:21:43 +00:00
|
|
|
int virFileUnlock(int fd, off_t start, off_t len)
|
2019-10-15 11:24:34 +00:00
|
|
|
G_GNUC_NO_INLINE;
|
2011-07-06 16:06:58 +00:00
|
|
|
|
2016-11-28 08:00:55 +00:00
|
|
|
typedef int (*virFileRewriteFunc)(int fd, const void *opaque);
|
2011-10-13 10:17:12 +00:00
|
|
|
int virFileRewrite(const char *path,
|
|
|
|
mode_t mode,
|
|
|
|
virFileRewriteFunc rewrite,
|
2016-11-28 08:00:55 +00:00
|
|
|
const void *opaque);
|
|
|
|
int virFileRewriteStr(const char *path,
|
|
|
|
mode_t mode,
|
|
|
|
const char *str);
|
2011-10-13 10:17:12 +00:00
|
|
|
|
2020-12-07 11:04:04 +00:00
|
|
|
int virFileResize(const char *path,
|
|
|
|
unsigned long long capacity,
|
|
|
|
bool pre_allocate);
|
|
|
|
|
2012-01-11 09:58:59 +00:00
|
|
|
int virFileTouch(const char *path, mode_t mode);
|
|
|
|
|
2012-04-27 13:50:22 +00:00
|
|
|
int virFileUpdatePerm(const char *path,
|
|
|
|
mode_t mode_remove,
|
|
|
|
mode_t mode_add);
|
|
|
|
|
2012-07-03 14:06:27 +00:00
|
|
|
int virFileLoopDeviceAssociate(const char *file,
|
|
|
|
char **dev);
|
|
|
|
|
2013-04-22 14:06:16 +00:00
|
|
|
int virFileNBDDeviceAssociate(const char *file,
|
2021-01-06 12:02:38 +00:00
|
|
|
const char *fmtstr,
|
2013-04-22 14:06:16 +00:00
|
|
|
bool readonly,
|
|
|
|
char **dev);
|
|
|
|
|
2013-03-28 14:46:45 +00:00
|
|
|
int virFileDeleteTree(const char *dir);
|
|
|
|
|
2013-11-05 17:30:56 +00:00
|
|
|
int virFileReadHeaderFD(int fd, int maxlen, char **buf)
|
2019-10-14 12:25:14 +00:00
|
|
|
G_GNUC_WARN_UNUSED_RESULT ATTRIBUTE_NONNULL(3);
|
2017-12-12 15:23:40 +00:00
|
|
|
int virFileReadHeaderQuiet(const char *path, int maxlen, char **buf)
|
2019-10-14 12:25:14 +00:00
|
|
|
G_GNUC_WARN_UNUSED_RESULT ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
|
2013-11-05 17:30:56 +00:00
|
|
|
int virFileReadLimFD(int fd, int maxlen, char **buf)
|
2019-10-14 12:25:14 +00:00
|
|
|
G_GNUC_WARN_UNUSED_RESULT ATTRIBUTE_NONNULL(3);
|
2013-11-05 17:30:56 +00:00
|
|
|
int virFileReadAll(const char *path, int maxlen, char **buf)
|
2019-10-14 12:25:14 +00:00
|
|
|
G_GNUC_WARN_UNUSED_RESULT ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
|
2014-06-30 12:59:42 +00:00
|
|
|
int virFileReadAllQuiet(const char *path, int maxlen, char **buf)
|
2019-10-14 12:25:14 +00:00
|
|
|
G_GNUC_WARN_UNUSED_RESULT ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
|
2016-05-03 09:12:40 +00:00
|
|
|
int virFileReadBufQuiet(const char *file, char *buf, int len)
|
2019-10-14 12:25:14 +00:00
|
|
|
G_GNUC_WARN_UNUSED_RESULT ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
2013-05-09 18:59:04 +00:00
|
|
|
|
|
|
|
int virFileWriteStr(const char *path, const char *str, mode_t mode)
|
2019-10-14 12:25:14 +00:00
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT;
|
2013-05-09 18:59:04 +00:00
|
|
|
|
|
|
|
int virFileLinkPointsTo(const char *checkLink,
|
2014-04-10 23:36:06 +00:00
|
|
|
const char *checkDest)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
|
|
|
int virFileRelLinkPointsTo(const char *directory,
|
|
|
|
const char *checkLink,
|
|
|
|
const char *checkDest)
|
|
|
|
ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
|
2013-05-09 18:59:04 +00:00
|
|
|
|
|
|
|
int virFileResolveLink(const char *linkpath,
|
2019-10-14 12:25:14 +00:00
|
|
|
char **resultpath) G_GNUC_WARN_UNUSED_RESULT;
|
2013-05-09 18:59:04 +00:00
|
|
|
int virFileResolveAllLinks(const char *linkpath,
|
2019-10-14 12:25:14 +00:00
|
|
|
char **resultpath) G_GNUC_WARN_UNUSED_RESULT;
|
2013-05-09 18:59:04 +00:00
|
|
|
|
|
|
|
int virFileIsLink(const char *linkpath)
|
2019-10-14 12:25:14 +00:00
|
|
|
ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT;
|
2013-05-09 18:59:04 +00:00
|
|
|
|
|
|
|
char *virFindFileInPath(const char *file);
|
|
|
|
|
2014-04-24 14:05:42 +00:00
|
|
|
char *virFileFindResource(const char *filename,
|
|
|
|
const char *builddir,
|
|
|
|
const char *installdir)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
|
|
|
|
char *virFileFindResourceFull(const char *filename,
|
|
|
|
const char *prefix,
|
|
|
|
const char *suffix,
|
|
|
|
const char *builddir,
|
|
|
|
const char *installdir,
|
|
|
|
const char *envname)
|
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5);
|
2019-08-29 10:52:08 +00:00
|
|
|
void virFileActivateDirOverrideForProg(const char *argv0)
|
2014-04-24 14:05:42 +00:00
|
|
|
ATTRIBUTE_NONNULL(1);
|
2019-08-29 10:52:08 +00:00
|
|
|
void virFileActivateDirOverrideForLib(void);
|
2014-04-24 14:05:42 +00:00
|
|
|
|
2016-11-17 17:18:27 +00:00
|
|
|
off_t virFileLength(const char *path, int fd) ATTRIBUTE_NONNULL(1);
|
2013-05-09 18:59:04 +00:00
|
|
|
bool virFileIsDir (const char *file) ATTRIBUTE_NONNULL(1);
|
2019-10-15 11:24:34 +00:00
|
|
|
bool virFileExists(const char *file) ATTRIBUTE_NONNULL(1) G_GNUC_NO_INLINE;
|
2013-05-09 18:59:04 +00:00
|
|
|
bool virFileIsExecutable(const char *file) ATTRIBUTE_NONNULL(1);
|
2018-06-06 16:24:12 +00:00
|
|
|
bool virFileIsRegular(const char *file) ATTRIBUTE_NONNULL(1);
|
2013-05-09 18:59:04 +00:00
|
|
|
|
2014-03-29 20:15:33 +00:00
|
|
|
enum {
|
|
|
|
VIR_FILE_SHFS_NFS = (1 << 0),
|
|
|
|
VIR_FILE_SHFS_GFS2 = (1 << 1),
|
|
|
|
VIR_FILE_SHFS_OCFS = (1 << 2),
|
|
|
|
VIR_FILE_SHFS_AFS = (1 << 3),
|
|
|
|
VIR_FILE_SHFS_SMB = (1 << 4),
|
|
|
|
VIR_FILE_SHFS_CIFS = (1 << 5),
|
2019-01-24 08:52:42 +00:00
|
|
|
VIR_FILE_SHFS_CEPH = (1 << 6),
|
2019-02-25 18:19:03 +00:00
|
|
|
VIR_FILE_SHFS_GPFS = (1 << 7),
|
2019-05-28 12:55:29 +00:00
|
|
|
VIR_FILE_SHFS_QB = (1 << 8),
|
2019-11-26 16:29:47 +00:00
|
|
|
VIR_FILE_SHFS_ACFS = (1 << 9),
|
2014-03-29 20:15:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int virFileIsSharedFSType(const char *path, int fstypes) ATTRIBUTE_NONNULL(1);
|
|
|
|
int virFileIsSharedFS(const char *path) ATTRIBUTE_NONNULL(1);
|
2020-12-07 11:04:41 +00:00
|
|
|
int virFileIsClusterFS(const char *path) ATTRIBUTE_NONNULL(1);
|
2013-10-07 11:51:58 +00:00
|
|
|
int virFileIsMountPoint(const char *file) ATTRIBUTE_NONNULL(1);
|
2018-04-23 15:41:14 +00:00
|
|
|
int virFileIsCDROM(const char *path)
|
2019-10-14 12:25:14 +00:00
|
|
|
ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT;
|
2013-10-07 11:51:58 +00:00
|
|
|
|
2013-11-27 15:19:49 +00:00
|
|
|
int virFileGetMountSubtree(const char *mtabpath,
|
|
|
|
const char *prefix,
|
|
|
|
char ***mountsret,
|
2019-10-14 12:25:14 +00:00
|
|
|
size_t *nmountsret) G_GNUC_WARN_UNUSED_RESULT;
|
2013-11-27 15:19:49 +00:00
|
|
|
int virFileGetMountReverseSubtree(const char *mtabpath,
|
|
|
|
const char *prefix,
|
|
|
|
char ***mountsret,
|
2019-10-14 12:25:14 +00:00
|
|
|
size_t *nmountsret) G_GNUC_WARN_UNUSED_RESULT;
|
2013-11-27 15:19:49 +00:00
|
|
|
|
2013-05-09 18:59:04 +00:00
|
|
|
char *virFileSanitizePath(const char *path);
|
2019-10-15 11:24:34 +00:00
|
|
|
char *virFileCanonicalizePath(const char *path) G_GNUC_NO_INLINE;
|
2013-05-09 18:59:04 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
VIR_FILE_OPEN_NONE = 0,
|
|
|
|
VIR_FILE_OPEN_NOFORK = (1 << 0),
|
|
|
|
VIR_FILE_OPEN_FORK = (1 << 1),
|
|
|
|
VIR_FILE_OPEN_FORCE_MODE = (1 << 2),
|
|
|
|
VIR_FILE_OPEN_FORCE_OWNER = (1 << 3),
|
|
|
|
};
|
|
|
|
int virFileAccessibleAs(const char *path, int mode,
|
|
|
|
uid_t uid, gid_t gid)
|
2019-10-14 12:25:14 +00:00
|
|
|
ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT;
|
2013-05-09 18:59:04 +00:00
|
|
|
int virFileOpenAs(const char *path, int openflags, mode_t mode,
|
|
|
|
uid_t uid, gid_t gid,
|
|
|
|
unsigned int flags)
|
2019-10-14 12:25:14 +00:00
|
|
|
ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT;
|
2015-09-21 11:36:55 +00:00
|
|
|
int virFileRemove(const char *path, uid_t uid, gid_t gid);
|
2013-05-09 18:59:04 +00:00
|
|
|
|
2017-04-04 16:22:31 +00:00
|
|
|
int virFileChownFiles(const char *name, uid_t uid, gid_t gid)
|
2019-10-14 12:25:14 +00:00
|
|
|
ATTRIBUTE_NONNULL(1) G_GNUC_WARN_UNUSED_RESULT;
|
2017-04-04 16:22:31 +00:00
|
|
|
|
2013-05-09 18:59:04 +00:00
|
|
|
enum {
|
|
|
|
VIR_DIR_CREATE_NONE = 0,
|
|
|
|
VIR_DIR_CREATE_AS_UID = (1 << 0),
|
2015-05-05 16:22:08 +00:00
|
|
|
VIR_DIR_CREATE_ALLOW_EXIST = (1 << 1),
|
2013-05-09 18:59:04 +00:00
|
|
|
};
|
|
|
|
int virDirCreate(const char *path, mode_t mode, uid_t uid, gid_t gid,
|
2019-10-14 12:25:14 +00:00
|
|
|
unsigned int flags) G_GNUC_WARN_UNUSED_RESULT;
|
2016-06-21 14:33:36 +00:00
|
|
|
int virDirOpen(DIR **dirp, const char *dirname)
|
2019-10-14 12:25:14 +00:00
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT;
|
2016-06-21 14:43:16 +00:00
|
|
|
int virDirOpenIfExists(DIR **dirp, const char *dirname)
|
2019-10-14 12:25:14 +00:00
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT;
|
2016-06-21 14:52:11 +00:00
|
|
|
int virDirOpenQuiet(DIR **dirp, const char *dirname)
|
2019-10-14 12:25:14 +00:00
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT;
|
2014-04-20 11:53:45 +00:00
|
|
|
int virDirRead(DIR *dirp, struct dirent **ent, const char *dirname)
|
2019-10-14 12:25:14 +00:00
|
|
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT;
|
util: remove ATTRIBUTE_NONNULL from virDirClose declaration
Before commit 24d8968c, virDirClose took a DIR**, and that was never
NULL, so its declaration included ATTRIBUTE_NONNULL(1). Since that
commit, virDirClose takes a DIR*, and it may be NULL (e.g. if the DIR*
is initialized to NULL and was never closed).
Even though virDirClose() is currently only called implicitly (as the
cleanup for a g_autoptr(DIR)), and (as I've just newly learned) the
autocleanup function g_autoptr will only be called if the pointer in
question is non-null (see the definition of
_GLIB_AUTOPTR_CLEAR_FUNC_NAME in
/usr/include/glib-2.0/glib/gmacros.h), it does still cause Coverity to
complain that it *could* be called with a NULL, and it's also possible
that in the future someone might add code that explicitly calls
virDirClose.
To eliminate the Coverity complaints, and protect against the
hypothetical future where someone both explicitly calls virDirClose()
with a potentially NULL value, *and* re-enables the nonnull directive
when not building with Coverity (disabled by commit eefb881) this
patch removes the ATTRIBUTE_NONNULL(1) from the declaration of
virDirClose().
Fixes: 24d8968cd0a718af4badbbc858b1b449fea7205a
Reported-by: John Ferlan <jferlan@redhat.com>
Details-Research-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Laine Stump <laine@redhat.com>
2020-11-13 17:13:59 +00:00
|
|
|
void virDirClose(DIR *dirp);
|
2020-10-19 13:15:50 +00:00
|
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(DIR, virDirClose);
|
2014-04-20 11:53:45 +00:00
|
|
|
|
2019-10-14 12:25:14 +00:00
|
|
|
int virFileMakeParentPath(const char *path) G_GNUC_WARN_UNUSED_RESULT;
|
2013-05-09 18:59:04 +00:00
|
|
|
|
|
|
|
char *virFileBuildPath(const char *dir,
|
|
|
|
const char *name,
|
2019-10-14 12:25:14 +00:00
|
|
|
const char *ext) G_GNUC_WARN_UNUSED_RESULT;
|
2013-05-09 18:59:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
int virFileAbsPath(const char *path,
|
2019-10-14 12:25:14 +00:00
|
|
|
char **abspath) G_GNUC_WARN_UNUSED_RESULT;
|
2016-05-12 11:05:37 +00:00
|
|
|
void virFileRemoveLastComponent(char *path);
|
2013-05-09 18:59:04 +00:00
|
|
|
|
|
|
|
int virFileOpenTty(int *ttymaster,
|
|
|
|
char **ttyName,
|
|
|
|
int rawmode);
|
|
|
|
|
|
|
|
char *virFileFindMountPoint(const char *type);
|
|
|
|
|
|
|
|
/* NB: this should be combined with virFileBuildPath */
|
2019-06-18 16:12:50 +00:00
|
|
|
#define virBuildPath(path, ...) \
|
2013-05-09 18:59:04 +00:00
|
|
|
virBuildPathInternal(path, __VA_ARGS__, NULL)
|
2021-02-23 16:28:09 +00:00
|
|
|
void virBuildPathInternal(char **path, ...) G_GNUC_NULL_TERMINATED;
|
2013-05-09 18:59:04 +00:00
|
|
|
|
2014-07-23 15:37:17 +00:00
|
|
|
typedef struct _virHugeTLBFS virHugeTLBFS;
|
|
|
|
struct _virHugeTLBFS {
|
|
|
|
char *mnt_dir; /* Where the FS is mount to */
|
|
|
|
unsigned long long size; /* page size in kibibytes */
|
|
|
|
bool deflt; /* is this the default huge page size */
|
|
|
|
};
|
|
|
|
|
|
|
|
int virFileGetHugepageSize(const char *path,
|
|
|
|
unsigned long long *size);
|
2021-03-11 07:16:13 +00:00
|
|
|
int virFileFindHugeTLBFS(virHugeTLBFS **ret_fs,
|
2014-07-23 15:37:17 +00:00
|
|
|
size_t *ret_nfs);
|
2016-11-10 15:17:48 +00:00
|
|
|
|
2021-03-11 07:16:13 +00:00
|
|
|
virHugeTLBFS *virFileGetDefaultHugepage(virHugeTLBFS *fs,
|
2019-03-29 15:10:09 +00:00
|
|
|
size_t nfs);
|
|
|
|
|
2016-11-10 15:17:48 +00:00
|
|
|
int virFileSetupDev(const char *path,
|
|
|
|
const char *mount_options);
|
|
|
|
|
|
|
|
int virFileBindMountDevice(const char *src,
|
|
|
|
const char *dst);
|
2016-11-22 10:14:08 +00:00
|
|
|
|
2017-01-11 10:29:00 +00:00
|
|
|
int virFileMoveMount(const char *src,
|
|
|
|
const char *dst);
|
|
|
|
|
2016-11-22 10:14:08 +00:00
|
|
|
int virFileGetACLs(const char *file,
|
|
|
|
void **acl);
|
|
|
|
|
|
|
|
int virFileSetACLs(const char *file,
|
|
|
|
void *acl);
|
|
|
|
|
|
|
|
void virFileFreeACLs(void **acl);
|
|
|
|
|
|
|
|
int virFileCopyACLs(const char *src,
|
|
|
|
const char *dst);
|
2017-02-07 09:19:06 +00:00
|
|
|
|
|
|
|
int virFileComparePaths(const char *p1, const char *p2);
|
2017-03-07 09:36:54 +00:00
|
|
|
|
2017-04-05 14:13:52 +00:00
|
|
|
int virFileReadValueInt(int *value, const char *format, ...)
|
2019-10-15 11:35:07 +00:00
|
|
|
G_GNUC_PRINTF(2, 3);
|
2017-04-05 14:13:52 +00:00
|
|
|
int virFileReadValueUint(unsigned int *value, const char *format, ...)
|
2019-10-15 11:35:07 +00:00
|
|
|
G_GNUC_PRINTF(2, 3);
|
2020-01-02 10:45:04 +00:00
|
|
|
int virFileReadValueUllong(unsigned long long *value, const char *format, ...)
|
|
|
|
G_GNUC_PRINTF(2, 3);
|
2021-03-11 07:16:13 +00:00
|
|
|
int virFileReadValueBitmap(virBitmap **value, const char *format, ...)
|
2019-10-15 11:35:07 +00:00
|
|
|
G_GNUC_PRINTF(2, 3);
|
2017-04-05 14:13:52 +00:00
|
|
|
int virFileReadValueScaledInt(unsigned long long *value, const char *format, ...)
|
2019-10-15 11:35:07 +00:00
|
|
|
G_GNUC_PRINTF(2, 3);
|
2017-04-05 14:13:52 +00:00
|
|
|
int virFileReadValueString(char **value, const char *format, ...)
|
2019-10-15 11:35:07 +00:00
|
|
|
G_GNUC_PRINTF(2, 3);
|
2017-04-05 14:13:52 +00:00
|
|
|
|
2017-06-20 14:09:33 +00:00
|
|
|
int virFileWaitForExists(const char *path, size_t ms, size_t tries);
|
|
|
|
|
2017-03-07 09:36:54 +00:00
|
|
|
|
2016-06-16 08:42:47 +00:00
|
|
|
int virFileInData(int fd,
|
|
|
|
int *inData,
|
|
|
|
long long *length);
|
|
|
|
|
2019-10-15 12:47:50 +00:00
|
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virFileWrapperFd, virFileWrapperFdFree);
|
2018-07-13 17:54:46 +00:00
|
|
|
|
2018-08-06 08:50:03 +00:00
|
|
|
int virFileGetXAttr(const char *path,
|
|
|
|
const char *name,
|
2018-12-07 12:21:43 +00:00
|
|
|
char **value)
|
2019-10-15 11:24:34 +00:00
|
|
|
G_GNUC_NO_INLINE;
|
2018-08-06 08:50:03 +00:00
|
|
|
|
2019-03-22 14:08:36 +00:00
|
|
|
int virFileGetXAttrQuiet(const char *path,
|
|
|
|
const char *name,
|
|
|
|
char **value)
|
2019-10-15 11:24:34 +00:00
|
|
|
G_GNUC_NO_INLINE;
|
2019-03-22 14:08:36 +00:00
|
|
|
|
2018-08-06 08:50:03 +00:00
|
|
|
int virFileSetXAttr(const char *path,
|
|
|
|
const char *name,
|
2018-12-07 12:21:43 +00:00
|
|
|
const char *value)
|
2019-10-15 11:24:34 +00:00
|
|
|
G_GNUC_NO_INLINE;
|
2018-08-06 08:50:03 +00:00
|
|
|
|
|
|
|
int virFileRemoveXAttr(const char *path,
|
2018-12-07 12:21:43 +00:00
|
|
|
const char *name)
|
2019-10-15 11:24:34 +00:00
|
|
|
G_GNUC_NO_INLINE;
|
2019-12-24 15:14:13 +00:00
|
|
|
|
|
|
|
int virFileDataSync(int fd);
|
2020-07-17 18:16:27 +00:00
|
|
|
|
|
|
|
int virFileSetCOW(const char *path,
|
|
|
|
virTristateBool state);
|