Commit 4bf84f6d authored by mincheol's avatar mincheol
Browse files

Simple fsfreeze

parent 95aeab3d
dist_noinst_HEADERS += \
include/all-io.h \
include/at.h \
include/bitops.h \
include/blkdev.h \
include/canonicalize.h \
include/carefulputc.h \
include/c.h \
include/closestream.h \
include/colors.h \
include/color-names.h \
include/cpuset.h \
include/crc32.h \
include/crc64.h \
include/debug.h \
include/env.h \
include/exec_shell.h \
include/exitcodes.h \
include/fileutils.h \
include/ismounted.h \
include/linux_reboot.h \
include/linux_version.h \
include/list.h \
include/loopdev.h \
include/mangle.h \
include/match.h \
include/mbsalign.h \
include/md5.h \
include/minix.h \
include/monotonic.h \
include/namespace.h \
include/nls.h \
include/optutils.h \
include/pager.h \
include/pamfail.h \
include/path.h \
include/pathnames.h \
include/procutils.h \
include/pt-bsd.h \
include/pt-mbr.h \
include/pt-mbr-partnames.h \
include/pt-sgi.h \
include/pt-sun.h \
include/randutils.h \
include/rpmatch.h \
include/setproctitle.h \
include/statfs_magic.h \
include/strutils.h \
include/strv.h \
include/swapheader.h \
include/swapprober.h \
include/sysfs.h \
include/timer.h \
include/timeutils.h \
include/ttyutils.h \
include/widechar.h \
include/xalloc.h
/*
* No copyright is claimed. This code is in the public domain; do with
* it what you wish.
*
* Written by Karel Zak <kzak@redhat.com>
* Petr Uzel <petr.uzel@suse.cz>
*/
#ifndef UTIL_LINUX_ALL_IO_H
#define UTIL_LINUX_ALL_IO_H
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include "c.h"
static inline int write_all(int fd, const void *buf, size_t count)
{
while (count) {
ssize_t tmp;
errno = 0;
tmp = write(fd, buf, count);
if (tmp > 0) {
count -= tmp;
if (count)
buf = (void *) ((char *) buf + tmp);
} else if (errno != EINTR && errno != EAGAIN)
return -1;
if (errno == EAGAIN) /* Try later, *sigh* */
xusleep(250000);
}
return 0;
}
static inline int fwrite_all(const void *ptr, size_t size,
size_t nmemb, FILE *stream)
{
while (nmemb) {
size_t tmp;
errno = 0;
tmp = fwrite(ptr, size, nmemb, stream);
if (tmp > 0) {
nmemb -= tmp;
if (nmemb)
ptr = (void *) ((char *) ptr + (tmp * size));
} else if (errno != EINTR && errno != EAGAIN)
return -1;
if (errno == EAGAIN) /* Try later, *sigh* */
xusleep(250000);
}
return 0;
}
static inline ssize_t read_all(int fd, char *buf, size_t count)
{
ssize_t ret;
ssize_t c = 0;
int tries = 0;
memset(buf, 0, count);
while (count > 0) {
ret = read(fd, buf, count);
if (ret <= 0) {
if (ret < 0 && (errno == EAGAIN || errno == EINTR) && (tries++ < 5)) {
xusleep(250000);
continue;
}
return c ? c : -1;
}
if (ret > 0)
tries = 0;
count -= ret;
buf += ret;
c += ret;
}
return c;
}
#endif /* UTIL_LINUX_ALL_IO_H */
/*
* wrappers for "at" functions.
*
* Copyright (C) 2010 Karel Zak <kzak@redhat.com>
*
* This file may be redistributed under the terms of the
* GNU Lesser General Public License.
*/
#ifndef UTIL_LINUX_AT_H
#define UTIL_LINUX_AT_H
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "c.h"
extern int fstat_at(int dir, const char *dirname,
const char *filename, struct stat *st, int nofollow);
extern int open_at(int dir, const char *dirname,
const char *filename, int flags);
extern FILE *fopen_at(int dir, const char *dirname, const char *filename,
int flags, const char *mode);
extern ssize_t readlink_at(int dir, const char *dirname, const char *pathname,
char *buf, size_t bufsiz);
#endif /* UTIL_LINUX_AT_H */
/*
* No copyright is claimed. This code is in the public domain; do with
* it what you wish.
*
* Written by Karel Zak <kzak@redhat.com>
*/
#ifndef BITOPS_H
#define BITOPS_H
#include <stdint.h>
#include <sys/param.h>
#if defined(HAVE_BYTESWAP_H)
# include <byteswap.h>
#endif
#if defined(HAVE_ENDIAN_H)
# include <endian.h>
#elif defined(HAVE_SYS_ENDIAN_H) /* BSDs have them here */
# include <sys/endian.h>
#endif
#if defined(__OpenBSD__)
# include <sys/types.h>
# define be16toh(x) betoh16(x)
# define be32toh(x) betoh32(x)
# define be64toh(x) betoh64(x)
#endif
/*
* Fallbacks
*/
#ifndef bswap_16
# define bswap_16(x) ((((x) & 0x00FF) << 8) | \
(((x) & 0xFF00) >> 8))
#endif
#ifndef bswap_32
# define bswap_32(x) ((((x) & 0x000000FF) << 24) | \
(((x) & 0x0000FF00) << 8) | \
(((x) & 0x00FF0000) >> 8) | \
(((x) & 0xFF000000) >> 24))
#endif
#ifndef bswap_64
# define bswap_64(x) ((((x) & 0x00000000000000FFULL) << 56) | \
(((x) & 0x000000000000FF00ULL) << 40) | \
(((x) & 0x0000000000FF0000ULL) << 24) | \
(((x) & 0x00000000FF000000ULL) << 8) | \
(((x) & 0x000000FF00000000ULL) >> 8) | \
(((x) & 0x0000FF0000000000ULL) >> 24) | \
(((x) & 0x00FF000000000000ULL) >> 40) | \
(((x) & 0xFF00000000000000ULL) >> 56))
#endif
#ifndef htobe16
# if !defined(WORDS_BIGENDIAN)
# define htobe16(x) bswap_16 (x)
# define htole16(x) (x)
# define be16toh(x) bswap_16 (x)
# define le16toh(x) (x)
# define htobe32(x) bswap_32 (x)
# define htole32(x) (x)
# define be32toh(x) bswap_32 (x)
# define le32toh(x) (x)
# define htobe64(x) bswap_64 (x)
# define htole64(x) (x)
# define be64toh(x) bswap_64 (x)
# define le64toh(x) (x)
# else
# define htobe16(x) (x)
# define htole16(x) bswap_16 (x)
# define be16toh(x) (x)
# define le16toh(x) bswap_16 (x)
# define htobe32(x) (x)
# define htole32(x) bswap_32 (x)
# define be32toh(x) (x)
# define le32toh(x) bswap_32 (x)
# define htobe64(x) (x)
# define htole64(x) bswap_64 (x)
# define be64toh(x) (x)
# define le64toh(x) bswap_64 (x)
# endif
#endif
/*
* Byte swab macros (based on linux/byteorder/swab.h)
*/
#define swab16(x) bswap_16(x)
#define swab32(x) bswap_32(x)
#define swab64(x) bswap_64(x)
#define cpu_to_le16(x) ((uint16_t) htole16(x))
#define cpu_to_le32(x) ((uint32_t) htole32(x))
#define cpu_to_le64(x) ((uint64_t) htole64(x))
#define cpu_to_be16(x) ((uint16_t) htobe16(x))
#define cpu_to_be32(x) ((uint32_t) htobe32(x))
#define cpu_to_be64(x) ((uint64_t) htobe64(x))
#define le16_to_cpu(x) ((uint16_t) le16toh(x))
#define le32_to_cpu(x) ((uint32_t) le32toh(x))
#define le64_to_cpu(x) ((uint64_t) le64toh(x))
#define be16_to_cpu(x) ((uint16_t) be16toh(x))
#define be32_to_cpu(x) ((uint32_t) be32toh(x))
#define be64_to_cpu(x) ((uint64_t) be64toh(x))
/*
* Bit map related macros. Usually provided by libc.
*/
#ifndef NBBY
# define NBBY CHAR_BIT
#endif
#ifndef setbit
# define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
# define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
# define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
# define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
#endif
#endif /* BITOPS_H */
/*
* No copyright is claimed. This code is in the public domain; do with
* it what you wish.
*
* Written by Karel Zak <kzak@redhat.com>
*/
#ifndef BLKDEV_H
#define BLKDEV_H
#include <sys/types.h>
#include <sys/ioctl.h>
#ifdef HAVE_SYS_IOCCOM_H
# include <sys/ioccom.h> /* for _IO macro on e.g. Solaris */
#endif
#include <fcntl.h>
#include <unistd.h>
#ifdef HAVE_SYS_MKDEV_H
# include <sys/mkdev.h> /* major and minor on Solaris */
#endif
#define DEFAULT_SECTOR_SIZE 512
#ifdef __linux__
/* very basic ioctls, should be available everywhere */
# ifndef BLKROSET
# define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */
# define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */
# define BLKRRPART _IO(0x12,95) /* re-read partition table */
# define BLKGETSIZE _IO(0x12,96) /* return device size /512 (long *arg) */
# define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */
# define BLKRASET _IO(0x12,98) /* set read ahead for block device */
# define BLKRAGET _IO(0x12,99) /* get current read ahead setting */
# define BLKFRASET _IO(0x12,100) /* set filesystem (mm/filemap.c) read-ahead */
# define BLKFRAGET _IO(0x12,101) /* get filesystem (mm/filemap.c) read-ahead */
# define BLKSECTSET _IO(0x12,102) /* set max sectors per request (ll_rw_blk.c) */
# define BLKSECTGET _IO(0x12,103) /* get max sectors per request (ll_rw_blk.c) */
# define BLKSSZGET _IO(0x12,104) /* get block device sector size */
/* ioctls introduced in 2.2.16, removed in 2.5.58 */
# define BLKELVGET _IOR(0x12,106,size_t) /* elevator get */
# define BLKELVSET _IOW(0x12,107,size_t) /* elevator set */
# define BLKBSZGET _IOR(0x12,112,size_t)
# define BLKBSZSET _IOW(0x12,113,size_t)
# endif /* !BLKROSET */
# ifndef BLKGETSIZE64
# define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */
# endif
/* block device topology ioctls, introduced in 2.6.32 (commit ac481c20) */
# ifndef BLKIOMIN
# define BLKIOMIN _IO(0x12,120)
# define BLKIOOPT _IO(0x12,121)
# define BLKALIGNOFF _IO(0x12,122)
# define BLKPBSZGET _IO(0x12,123)
# endif
/* discard zeroes support, introduced in 2.6.33 (commit 98262f27) */
# ifndef BLKDISCARDZEROES
# define BLKDISCARDZEROES _IO(0x12,124)
# endif
/* filesystem freeze, introduced in 2.6.29 (commit fcccf502) */
# ifndef FIFREEZE
# define FIFREEZE _IOWR('X', 119, int) /* Freeze */
# define FITHAW _IOWR('X', 120, int) /* Thaw */
# endif
/* uniform CD-ROM information */
# ifndef CDROM_GET_CAPABILITY
# define CDROM_GET_CAPABILITY 0x5331
# endif
#endif /* __linux */
#ifdef APPLE_DARWIN
# define BLKGETSIZE DKIOCGETBLOCKCOUNT32
#endif
#ifndef HDIO_GETGEO
# ifdef __linux__
# define HDIO_GETGEO 0x0301
# endif
struct hd_geometry {
unsigned char heads;
unsigned char sectors;
unsigned short cylinders; /* truncated */
unsigned long start;
};
#endif /* HDIO_GETGEO */
/* are we working with block device? */
int is_blkdev(int fd);
/* Determine size in bytes */
off_t blkdev_find_size (int fd);
/* get size in bytes */
int blkdev_get_size(int fd, unsigned long long *bytes);
/* get 512-byte sector count */
int blkdev_get_sectors(int fd, unsigned long long *sectors);
/* get hardware sector size */
int blkdev_get_sector_size(int fd, int *sector_size);
/* specifies whether or not the device is misaligned */
int blkdev_is_misaligned(int fd);
/* get physical block device size */
int blkdev_get_physector_size(int fd, int *sector_size);
/* is the device cdrom capable? */
int blkdev_is_cdrom(int fd);
/* get device's geometry - legacy */
int blkdev_get_geometry(int fd, unsigned int *h, unsigned int *s);
/* SCSI device types. Copied almost as-is from kernel header.
* http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/scsi/scsi.h */
#define SCSI_TYPE_DISK 0x00
#define SCSI_TYPE_TAPE 0x01
#define SCSI_TYPE_PRINTER 0x02
#define SCSI_TYPE_PROCESSOR 0x03 /* HP scanners use this */
#define SCSI_TYPE_WORM 0x04 /* Treated as ROM by our system */
#define SCSI_TYPE_ROM 0x05
#define SCSI_TYPE_SCANNER 0x06
#define SCSI_TYPE_MOD 0x07 /* Magneto-optical disk - treated as SCSI_TYPE_DISK */
#define SCSI_TYPE_MEDIUM_CHANGER 0x08
#define SCSI_TYPE_COMM 0x09 /* Communications device */
#define SCSI_TYPE_RAID 0x0c
#define SCSI_TYPE_ENCLOSURE 0x0d /* Enclosure Services Device */
#define SCSI_TYPE_RBC 0x0e
#define SCSI_TYPE_OSD 0x11
#define SCSI_TYPE_NO_LUN 0x7f
/* convert scsi type code to name */
const char *blkdev_scsi_type_to_name(int type);
#endif /* BLKDEV_H */
/*
* Fundamental C definitions.
*/
#ifndef UTIL_LINUX_C_H
#define UTIL_LINUX_C_H
#include <limits.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
#ifdef HAVE_ERR_H
# include <err.h>
#endif
/*
* Compiler-specific stuff
*/
#ifndef __GNUC_PREREQ
# if defined __GNUC__ && defined __GNUC_MINOR__
# define __GNUC_PREREQ(maj, min) \
((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
# else
# define __GNUC_PREREQ(maj, min) 0
# endif
#endif
#ifdef __GNUC__
/* &a[0] degrades to a pointer: a different type from an array */
# define __must_be_array(a) \
UL_BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(__typeof__(a), __typeof__(&a[0])))
# define ignore_result(x) __extension__ ({ \
__typeof__(x) __dummy __attribute__((__unused__)) = (x); (void) __dummy; \
})
#else /* !__GNUC__ */
# define __must_be_array(a) 0
# define __attribute__(_arg_)
# define ignore_result(x) ((void) (x))
#endif /* !__GNUC__ */
/*
* Function attributes
*/
#ifndef __ul_alloc_size
# if __GNUC_PREREQ (4, 3)
# define __ul_alloc_size(s) __attribute__((alloc_size(s), warn_unused_result))
# else
# define __ul_alloc_size(s)
# endif
#endif
#ifndef __ul_calloc_size
# if __GNUC_PREREQ (4, 3)
# define __ul_calloc_size(n, s) __attribute__((alloc_size(n, s), warn_unused_result))
# else
# define __ul_calloc_size(n, s)
# endif
#endif
/*
* Force a compilation error if condition is true, but also produce a
* result (of value 0 and type size_t), so the expression can be used
* e.g. in a structure initializer (or wherever else comma expressions
* aren't permitted).
*/
#define UL_BUILD_BUG_ON_ZERO(e) __extension__ (sizeof(struct { int:-!!(e); }))
#define BUILD_BUG_ON_NULL(e) ((void *)sizeof(struct { int:-!!(e); }))
#ifndef ARRAY_SIZE
# define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
#endif
#ifndef PATH_MAX
# define PATH_MAX 4096
#endif
#ifndef TRUE
# define TRUE 1
#endif
#ifndef FALSE
# define FALSE 0
#endif
#ifndef min
# define min(x, y) __extension__ ({ \
__typeof__(x) _min1 = (x); \
__typeof__(y) _min2 = (y); \
(void) (&_min1 == &_min2); \
_min1 < _min2 ? _min1 : _min2; })
#endif
#ifndef max
# define max(x, y) __extension__ ({ \
__typeof__(x) _max1 = (x); \
__typeof__(y) _max2 = (y); \
(void) (&_max1 == &_max2); \
_max1 > _max2 ? _max1 : _max2; })
#endif
#ifndef cmp_numbers
# define cmp_numbers(x, y) __extension__ ({ \
__typeof__(x) _a = (x); \
__typeof__(y) _b = (y); \
(void) (&_a == &_b); \
_a == _b ? 0 : _a > _b ? 1 : -1; })
#endif
#ifndef offsetof
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif
#ifndef container_of
#define container_of(ptr, type, member) __extension__ ({ \
const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
#endif
#ifndef HAVE_PROGRAM_INVOCATION_SHORT_NAME
# ifdef HAVE___PROGNAME
extern char *__progname;
# define program_invocation_short_name __progname
# else
# ifdef HAVE_GETEXECNAME
# define program_invocation_short_name \
prog_inv_sh_nm_from_file(getexecname(), 0)
# else
# define program_invocation_short_name \
prog_inv_sh_nm_from_file(__FILE__, 1)
# endif
static char prog_inv_sh_nm_buf[256];
static inline char *
prog_inv_sh_nm_from_file(char *f, char stripext)
{
char *t;
if ((t = strrchr(f, '/')) != NULL)
t++;
else
t = f;
strncpy(prog_inv_sh_nm_buf, t, sizeof(prog_inv_sh_nm_buf) - 1);
prog_inv_sh_nm_buf[sizeof(prog_inv_sh_nm_buf) - 1] = '\0';
if (stripext && (t = strrchr(prog_inv_sh_nm_buf, '.')) != NULL)
*t = '\0';
return prog_inv_sh_nm_buf;
}
# endif
#endif
#ifndef HAVE_ERR_H
static inline void
errmsg(char doexit, int excode, char adderr, const char *fmt, ...)
{
fprintf(stderr, "%s: ", program_invocation_short_name);
if (fmt != NULL) {
va_list argp;
va_start(argp, fmt);
vfprintf(stderr, fmt, argp);
va_end(argp);
if (adderr)
fprintf(stderr, ": ");
}
if (adderr)
fprintf(stderr, "%m");
fprintf(stderr, "\n");
if (doexit)