diff options
| author | Richard Maw <richard.maw@codethink.co.uk> | 2014-06-12 12:04:01 +0100 |
|---|---|---|
| committer | Richard Maw <richard.maw@codethink.co.uk> | 2014-06-12 12:04:01 +0100 |
| commit | c5c1033c5c7deda8abe3448ec81bbb33c72219e0 (patch) | |
| tree | 6e5cef29b85161eea8a7488a029f5a32f982c6ab /include | |
| parent | 462008f79be9e195670b202cb43827b8aeb1e60b (diff) | |
| parent | 2fb567c080e1762ec6a2147564f03068f55d4f14 (diff) | |
| download | util-linux-baserock/morph.tar.gz | |
Merge branch 'baserock/richardmaw/yakshave/util-linux-blkid' into baserock/morphbaserock/morph
Reviewed-by: Lars Wirzenius
Reviewed-by: Sam Thursfield
Diffstat (limited to 'include')
| -rw-r--r-- | include/Makemodule.am | 6 | ||||
| -rw-r--r-- | include/blkdev.h | 2 | ||||
| -rw-r--r-- | include/c.h | 4 | ||||
| -rw-r--r-- | include/carefulputc.h | 4 | ||||
| -rw-r--r-- | include/closestream.h | 22 | ||||
| -rw-r--r-- | include/colors.h | 33 | ||||
| -rw-r--r-- | include/crc32.h | 1 | ||||
| -rw-r--r-- | include/crc64.h | 9 | ||||
| -rw-r--r-- | include/loopdev.h | 2 | ||||
| -rw-r--r-- | include/path.h | 2 | ||||
| -rw-r--r-- | include/pathnames.h | 5 | ||||
| -rw-r--r-- | include/pt-bsd.h | 156 | ||||
| -rw-r--r-- | include/pt-mbr-partnames.h | 105 | ||||
| -rw-r--r-- | include/pt-mbr.h | 178 | ||||
| -rw-r--r-- | include/pt-sgi.h | 108 | ||||
| -rw-r--r-- | include/strutils.h | 41 | ||||
| -rw-r--r-- | include/timeutils.h | 55 | ||||
| -rw-r--r-- | include/tt.h | 8 | ||||
| -rw-r--r-- | include/ttyutils.h | 9 | ||||
| -rw-r--r-- | include/xalloc.h | 6 |
20 files changed, 737 insertions, 19 deletions
diff --git a/include/Makemodule.am b/include/Makemodule.am index 7ba4593e4..369bacc27 100644 --- a/include/Makemodule.am +++ b/include/Makemodule.am @@ -11,6 +11,7 @@ dist_noinst_HEADERS += \ include/colors.h \ include/cpuset.h \ include/crc32.h \ + include/crc64.h \ include/env.h \ include/exec_shell.h \ include/exitcodes.h \ @@ -40,10 +41,15 @@ dist_noinst_HEADERS += \ include/swapheader.h \ include/sysfs.h \ include/timer.h \ + include/timeutils.h \ include/tt.h \ include/ttyutils.h \ include/wholedisk.h \ include/widechar.h \ include/xalloc.h \ include/xgetpass.h \ + include/pt-sgi.h \ + include/pt-bsd.h \ + include/pt-mbr.h \ + include/pt-mbr-partnames.h \ include/pt-sun.h diff --git a/include/blkdev.h b/include/blkdev.h index ade08878d..5a5777ba3 100644 --- a/include/blkdev.h +++ b/include/blkdev.h @@ -122,7 +122,7 @@ int blkdev_is_cdrom(int fd); 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/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=include/scsi/scsi.h */ + * 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 diff --git a/include/c.h b/include/c.h index a50e8a593..4a9bf3d42 100644 --- a/include/c.h +++ b/include/c.h @@ -56,7 +56,7 @@ */ #ifndef __ul_alloc_size # if __GNUC_PREREQ (4, 3) -# define __ul_alloc_size(s) __attribute__((alloc_size(s))) +# define __ul_alloc_size(s) __attribute__((alloc_size(s), warn_unused_result)) # else # define __ul_alloc_size(s) # endif @@ -64,7 +64,7 @@ #ifndef __ul_calloc_size # if __GNUC_PREREQ (4, 3) -# define __ul_calloc_size(n, s) __attribute__((alloc_size(n, s))) +# define __ul_calloc_size(n, s) __attribute__((alloc_size(n, s), warn_unused_result)) # else # define __ul_calloc_size(n, s) # endif diff --git a/include/carefulputc.h b/include/carefulputc.h index 2d857ebb0..d4d0ee4ea 100644 --- a/include/carefulputc.h +++ b/include/carefulputc.h @@ -10,7 +10,7 @@ #define iso8859x_iscntrl(c) \ (((c) & 0x7f) < 0x20 || (c) == 0x7f) -static inline int carefulputc(int c, FILE *fp) { +static inline int carefulputc(int c, FILE *fp, const char fail) { int ret; if (c == '\007' || c == '\t' || c == '\r' || c == '\n' || @@ -19,7 +19,7 @@ static inline int carefulputc(int c, FILE *fp) { else if ((c & 0x80) || !isprint(c^0x40)) ret = fprintf(fp, "\\%3o", (unsigned char) c); else { - ret = putc('^', fp); + ret = putc(fail, fp); if (ret != EOF) ret = putc(c^0x40, fp); } diff --git a/include/closestream.h b/include/closestream.h index d61b83b5e..7842456fb 100644 --- a/include/closestream.h +++ b/include/closestream.h @@ -24,8 +24,9 @@ close_stream(FILE * stream) const int some_pending = (__fpending(stream) != 0); const int prev_fail = (ferror(stream) != 0); const int fclose_fail = (fclose(stream) != 0); + if (prev_fail || (fclose_fail && (some_pending || errno != EBADF))) { - if (!fclose_fail) + if (!fclose_fail && !(errno == EPIPE)) errno = 0; return EOF; } @@ -48,4 +49,23 @@ close_stdout(void) _exit(EXIT_FAILURE); } +#ifndef HAVE_FSYNC +static inline int +fsync(int fd __attribute__((__unused__))) +{ + return 0; +} +#endif + +static inline int +close_fd(int fd) +{ + const int fsync_fail = (fsync(fd) != 0); + const int close_fail = (close(fd) != 0); + + if (fsync_fail || close_fail) + return EOF; + return 0; +} + #endif /* UTIL_LINUX_CLOSESTREAM_H */ diff --git a/include/colors.h b/include/colors.h index dd77bf6df..d2bd7b2aa 100644 --- a/include/colors.h +++ b/include/colors.h @@ -38,13 +38,40 @@ #define UL_COLOR_WHITE "\033[1;37m" +/* --color[=WHEN] */ +enum colortmode { + UL_COLORMODE_AUTO = 0, + UL_COLORMODE_NEVER, + UL_COLORMODE_ALWAYS, + + __UL_NCOLORMODES /* last */ +}; + +extern int colormode_from_string(const char *str); +extern int colormode_or_err(const char *str, const char *errmsg); + /* Initialize the global variable OUT_IS_TERM */ -extern int colors_init(void); +extern int colors_init(int mode); + +/* Returns 1 or 0 */ +extern int colors_wanted(void); /* Set the color to CLR_SCHEME */ -extern void color_enable(const char *clr_scheme); +extern void color_fenable(const char *clr_scheme, FILE *f); + +static inline void color_enable(const char *clr_scheme) +{ + color_fenable(clr_scheme, stdout); +} /* Reset colors to default */ -extern void color_disable(void); +extern void color_fdisable(FILE *f); + +static inline void color_disable(void) +{ + color_fdisable(stdout); +} + + #endif /* UTIL_LINUX_COLORS_H */ diff --git a/include/crc32.h b/include/crc32.h index b454be9fc..26169109e 100644 --- a/include/crc32.h +++ b/include/crc32.h @@ -1,6 +1,7 @@ #ifndef UL_NG_CRC32_H #define UL_NG_CRC32_H +#include <sys/types.h> #include <stdint.h> extern uint32_t crc32(uint32_t seed, const unsigned char *buf, size_t len); diff --git a/include/crc64.h b/include/crc64.h new file mode 100644 index 000000000..40475d56f --- /dev/null +++ b/include/crc64.h @@ -0,0 +1,9 @@ +#ifndef UTIL_LINUX_CRC64_H +#define UTIL_LINUX_CRC64_H + +#include <sys/types.h> +#include <stdint.h> + +extern uint64_t crc64(uint64_t seed, const unsigned char *data, size_t len); + +#endif diff --git a/include/loopdev.h b/include/loopdev.h index 9f199a086..793539935 100644 --- a/include/loopdev.h +++ b/include/loopdev.h @@ -99,6 +99,7 @@ struct loopdev_cxt { unsigned int extra_check:1; /* unusual stuff for iterator */ unsigned int debug:1; /* debug mode ON/OFF */ unsigned int info_failed:1; /* LOOP_GET_STATUS ioctl failed */ + unsigned int control_ok:1; /* /dev/loop-control success */ struct sysfs_cxt sysfs; /* pointer to /sys/dev/block/<maj:min>/ */ struct loop_info64 info; /* for GET/SET ioctl */ @@ -149,6 +150,7 @@ extern void loopcxt_enable_debug(struct loopdev_cxt *lc, int enable); extern int loopcxt_set_device(struct loopdev_cxt *lc, const char *device) __attribute__ ((warn_unused_result)); extern int loopcxt_has_device(struct loopdev_cxt *lc); +extern int loopcxt_add_device(struct loopdev_cxt *lc); extern char *loopcxt_strdup_device(struct loopdev_cxt *lc); extern const char *loopcxt_get_device(struct loopdev_cxt *lc); extern struct sysfs_cxt *loopcxt_get_sysfs(struct loopdev_cxt *lc); diff --git a/include/path.h b/include/path.h index 615d28491..45da692f8 100644 --- a/include/path.h +++ b/include/path.h @@ -4,6 +4,8 @@ #include <stdio.h> #include <stdint.h> +extern char *path_strdup(const char *path, ...) + __attribute__ ((__format__ (__printf__, 1, 2))); extern FILE *path_fopen(const char *mode, int exit_on_err, const char *path, ...) __attribute__ ((__format__ (__printf__, 3, 4))); extern void path_read_str(char *result, size_t len, const char *path, ...) diff --git a/include/pathnames.h b/include/pathnames.h index d7b36efcd..dce98d2a4 100644 --- a/include/pathnames.h +++ b/include/pathnames.h @@ -31,6 +31,8 @@ #define _PATH_HUSHLOGIN ".hushlogin" #define _PATH_HUSHLOGINS "/etc/hushlogins" +#define _PATH_NOLOGIN_TXT "/etc/nologin.txt" + #ifndef _PATH_MAILDIR #define _PATH_MAILDIR "/var/spool/mail" #endif @@ -63,6 +65,7 @@ /* used in term-utils/agetty.c */ #define _PATH_ISSUE "/etc/issue" +#define _PATH_OS_RELEASE "/etc/os-release" #define _PATH_NUMLOCK_ON _PATH_LOCALSTATEDIR "/numlock-on" #define _PATH_LOGINDEFS "/etc/login.defs" @@ -125,6 +128,8 @@ # define _PATH_DEV "/dev/" #endif +#define _PATH_DEV_MEM "/dev/mem" + #define _PATH_DEV_LOOP "/dev/loop" #define _PATH_DEV_LOOPCTL "/dev/loop-control" #define _PATH_DEV_TTY "/dev/tty" diff --git a/include/pt-bsd.h b/include/pt-bsd.h new file mode 100644 index 000000000..9bf47a576 --- /dev/null +++ b/include/pt-bsd.h @@ -0,0 +1,156 @@ +#ifndef UTIL_LINUX_PT_BSD_H +#define UTIL_LINUX_PT_BSD_H + +#define BSD_MAXPARTITIONS 16 +#define BSD_FS_UNUSED 0 + +#ifndef BSD_DISKMAGIC +# define BSD_DISKMAGIC ((uint32_t) 0x82564557) +#endif + +#define BSD_LINUX_BOOTDIR "/usr/ucb/mdec" + +#if defined (__alpha__) || defined (__powerpc__) || \ + defined (__ia64__) || defined (__hppa__) +# define BSD_LABELSECTOR 0 +# define BSD_LABELOFFSET 64 +#else +# define BSD_LABELSECTOR 1 +# define BSD_LABELOFFSET 0 +#endif + +#define BSD_BBSIZE 8192 /* size of boot area, with label */ +#define BSD_SBSIZE 8192 /* max size of fs superblock */ + +struct bsd_disklabel { + uint32_t d_magic; /* the magic number */ + int16_t d_type; /* drive type */ + int16_t d_subtype; /* controller/d_type specific */ + char d_typename[16]; /* type name, e.g. "eagle" */ + char d_packname[16]; /* pack identifier */ + + /* disk geometry: */ + uint32_t d_secsize; /* # of bytes per sector */ + uint32_t d_nsectors; /* # of data sectors per track */ + uint32_t d_ntracks; /* # of tracks per cylinder */ + uint32_t d_ncylinders; /* # of data cylinders per unit */ + uint32_t d_secpercyl; /* # of data sectors per cylinder */ + uint32_t d_secperunit; /* # of data sectors per unit */ + + /* + * Spares (bad sector replacements) below + * are not counted in d_nsectors or d_secpercyl. + * Spare sectors are assumed to be physical sectors + * which occupy space at the end of each track and/or cylinder. + */ + uint16_t d_sparespertrack; /* # of spare sectors per track */ + uint16_t d_sparespercyl; /* # of spare sectors per cylinder */ + + /* + * Alternate cylinders include maintenance, replacement, + * configuration description areas, etc. + */ + uint32_t d_acylinders; /* # of alt. cylinders per unit */ + + /* hardware characteristics: */ + /* + * d_interleave, d_trackskew and d_cylskew describe perturbations + * in the media format used to compensate for a slow controller. + * Interleave is physical sector interleave, set up by the formatter + * or controller when formatting. When interleaving is in use, + * logically adjacent sectors are not physically contiguous, + * but instead are separated by some number of sectors. + * It is specified as the ratio of physical sectors traversed + * per logical sector. Thus an interleave of 1:1 implies contiguous + * layout, while 2:1 implies that logical sector 0 is separated + * by one sector from logical sector 1. + * d_trackskew is the offset of sector 0 on track N + * relative to sector 0 on track N-1 on the same cylinder. + * Finally, d_cylskew is the offset of sector 0 on cylinder N + * relative to sector 0 on cylinder N-1. + */ + uint16_t d_rpm; /* rotational speed */ + uint16_t d_interleave; /* hardware sector interleave */ + uint16_t d_trackskew; /* sector 0 skew, per track */ + uint16_t d_cylskew; /* sector 0 skew, per cylinder */ + uint32_t d_headswitch; /* head switch time, usec */ + uint32_t d_trkseek; /* track-to-track seek, usec */ + uint32_t d_flags; /* generic flags */ + uint32_t d_drivedata[5]; /* drive-type specific information */ + uint32_t d_spare[5]; /* reserved for future use */ + uint32_t d_magic2; /* the magic number (again) */ + uint16_t d_checksum; /* xor of data incl. partitions */ + + /* filesystem and partition information: */ + uint16_t d_npartitions; /* number of partitions in following */ + uint32_t d_bbsize; /* size of boot area at sn0, bytes */ + uint32_t d_sbsize; /* max size of fs superblock, bytes */ + + struct bsd_partition { /* the partition table */ + uint32_t p_size; /* number of sectors in partition */ + uint32_t p_offset; /* starting sector */ + uint32_t p_fsize; /* filesystem basic fragment size */ + uint8_t p_fstype; /* filesystem type, see below */ + uint8_t p_frag; /* filesystem fragments per block */ + uint16_t p_cpg; /* filesystem cylinders per group */ + } __attribute__((packed)) d_partitions[BSD_MAXPARTITIONS]; /* actually may be more */ +} __attribute__((packed)); + + +/* d_type values: */ +#define BSD_DTYPE_SMD 1 /* SMD, XSMD; VAX hp/up */ +#define BSD_DTYPE_MSCP 2 /* MSCP */ +#define BSD_DTYPE_DEC 3 /* other DEC (rk, rl) */ +#define BSD_DTYPE_SCSI 4 /* SCSI */ +#define BSD_DTYPE_ESDI 5 /* ESDI interface */ +#define BSD_DTYPE_ST506 6 /* ST506 etc. */ +#define BSD_DTYPE_HPIB 7 /* CS/80 on HP-IB */ +#define BSD_DTYPE_HPFL 8 /* HP Fiber-link */ +#define BSD_DTYPE_FLOPPY 10 /* floppy */ + +/* d_subtype values: */ +#define BSD_DSTYPE_INDOSPART 0x8 /* is inside dos partition */ +#define BSD_DSTYPE_DOSPART(s) ((s) & 3) /* dos partition number */ +#define BSD_DSTYPE_GEOMETRY 0x10 /* drive params in label */ + +/* + * Filesystem type and version. + * Used to interpret other filesystem-specific + * per-partition information. + */ +#define BSD_FS_UNUSED 0 /* unused */ +#define BSD_FS_SWAP 1 /* swap */ +#define BSD_FS_V6 2 /* Sixth Edition */ +#define BSD_FS_V7 3 /* Seventh Edition */ +#define BSD_FS_SYSV 4 /* System V */ +#define BSD_FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */ +#define BSD_FS_V8 6 /* Eighth Edition, 4K blocks */ +#define BSD_FS_BSDFFS 7 /* 4.2BSD fast file system */ +#define BSD_FS_BSDLFS 9 /* 4.4BSD log-structured file system */ +#define BSD_FS_OTHER 10 /* in use, but unknown/unsupported */ +#define BSD_FS_HPFS 11 /* OS/2 high-performance file system */ +#define BSD_FS_ISO9660 12 /* ISO-9660 filesystem (cdrom) */ +#define BSD_FS_ISOFS BSD_FS_ISO9660 +#define BSD_FS_BOOT 13 /* partition contains bootstrap */ +#define BSD_FS_ADOS 14 /* AmigaDOS fast file system */ +#define BSD_FS_HFS 15 /* Macintosh HFS */ +#define BSD_FS_ADVFS 16 /* Digital Unix AdvFS */ + +/* this is annoying, but it's also the way it is :-( */ +#ifdef __alpha__ +#define BSD_FS_EXT2 8 /* ext2 file system */ +#else +#define BSD_FS_MSDOS 8 /* MS-DOS file system */ +#endif + +/* + * flags shared by various drives: + */ +#define BSD_D_REMOVABLE 0x01 /* removable media */ +#define BSD_D_ECC 0x02 /* supports ECC */ +#define BSD_D_BADSECT 0x04 /* supports bad sector forw. */ +#define BSD_D_RAMDISK 0x08 /* disk emulator */ +#define BSD_D_CHAIN 0x10 /* can do back-back transfers */ +#define BSD_D_DOSPART 0x20 /* within MSDOS partition */ + +#endif /* UTIL_LINUX_PT_BSD_H */ diff --git a/include/pt-mbr-partnames.h b/include/pt-mbr-partnames.h new file mode 100644 index 000000000..282adba91 --- /dev/null +++ b/include/pt-mbr-partnames.h @@ -0,0 +1,105 @@ + {0x00, N_("Empty")}, + {0x01, N_("FAT12")}, + {0x02, N_("XENIX root")}, + {0x03, N_("XENIX usr")}, + {0x04, N_("FAT16 <32M")}, + {0x05, N_("Extended")}, /* DOS 3.3+ extended partition */ + {0x06, N_("FAT16")}, /* DOS 16-bit >=32M */ + {0x07, N_("HPFS/NTFS/exFAT")}, /* OS/2 IFS, eg, HPFS or NTFS or QNX or exFAT */ + {0x08, N_("AIX")}, /* AIX boot (AIX -- PS/2 port) or SplitDrive */ + {0x09, N_("AIX bootable")}, /* AIX data or Coherent */ + {0x0a, N_("OS/2 Boot Manager")},/* OS/2 Boot Manager */ + {0x0b, N_("W95 FAT32")}, + {0x0c, N_("W95 FAT32 (LBA)")},/* LBA really is `Extended Int 13h' */ + {0x0e, N_("W95 FAT16 (LBA)")}, + {0x0f, N_("W95 Ext'd (LBA)")}, + {0x10, N_("OPUS")}, + {0x11, N_("Hidden FAT12")}, + {0x12, N_("Compaq diagnostics")}, + {0x14, N_("Hidden FAT16 <32M")}, + {0x16, N_("Hidden FAT16")}, + {0x17, N_("Hidden HPFS/NTFS")}, + {0x18, N_("AST SmartSleep")}, + {0x1b, N_("Hidden W95 FAT32")}, + {0x1c, N_("Hidden W95 FAT32 (LBA)")}, + {0x1e, N_("Hidden W95 FAT16 (LBA)")}, + {0x24, N_("NEC DOS")}, + {0x27, N_("Hidden NTFS WinRE")}, + {0x39, N_("Plan 9")}, + {0x3c, N_("PartitionMagic recovery")}, + {0x40, N_("Venix 80286")}, + {0x41, N_("PPC PReP Boot")}, + {0x42, N_("SFS")}, + {0x4d, N_("QNX4.x")}, + {0x4e, N_("QNX4.x 2nd part")}, + {0x4f, N_("QNX4.x 3rd part")}, + {0x50, N_("OnTrack DM")}, + {0x51, N_("OnTrack DM6 Aux1")}, /* (or Novell) */ + {0x52, N_("CP/M")}, /* CP/M or Microport SysV/AT */ + {0x53, N_("OnTrack DM6 Aux3")}, + {0x54, N_("OnTrackDM6")}, + {0x55, N_("EZ-Drive")}, + {0x56, N_("Golden Bow")}, + {0x5c, N_("Priam Edisk")}, + {0x61, N_("SpeedStor")}, + {0x63, N_("GNU HURD or SysV")}, /* GNU HURD or Mach or Sys V/386 (such as ISC UNIX) */ + {0x64, N_("Novell Netware 286")}, + {0x65, N_("Novell Netware 386")}, + {0x70, N_("DiskSecure Multi-Boot")}, + {0x75, N_("PC/IX")}, + {0x80, N_("Old Minix")}, /* Minix 1.4a and earlier */ + {0x81, N_("Minix / old Linux")},/* Minix 1.4b and later */ + {0x82, N_("Linux swap / Solaris")}, + {0x83, N_("Linux")}, + {0x84, N_("OS/2 hidden C: drive")}, + {0x85, N_("Linux extended")}, + {0x86, N_("NTFS volume set")}, + {0x87, N_("NTFS volume set")}, + {0x88, N_("Linux plaintext")}, + {0x8e, N_("Linux LVM")}, + {0x93, N_("Amoeba")}, + {0x94, N_("Amoeba BBT")}, /* (bad block table) */ + {0x9f, N_("BSD/OS")}, /* BSDI */ + {0xa0, N_("IBM Thinkpad hibernation")}, + {0xa5, N_("FreeBSD")}, /* various BSD flavours */ + {0xa6, N_("OpenBSD")}, + {0xa7, N_("NeXTSTEP")}, + {0xa8, N_("Darwin UFS")}, + {0xa9, N_("NetBSD")}, + {0xab, N_("Darwin boot")}, + {0xaf, N_("HFS / HFS+")}, + {0xb7, N_("BSDI fs")}, + {0xb8, N_("BSDI swap")}, + {0xbb, N_("Boot Wizard hidden")}, + {0xbe, N_("Solaris boot")}, + {0xbf, N_("Solaris")}, + {0xc1, N_("DRDOS/sec (FAT-12)")}, + {0xc4, N_("DRDOS/sec (FAT-16 < 32M)")}, + {0xc6, N_("DRDOS/sec (FAT-16)")}, + {0xc7, N_("Syrinx")}, + {0xda, N_("Non-FS data")}, + {0xdb, N_("CP/M / CTOS / ...")},/* CP/M or Concurrent CP/M or + Concurrent DOS or CTOS */ + {0xde, N_("Dell Utility")}, /* Dell PowerEdge Server utilities */ + {0xdf, N_("BootIt")}, /* BootIt EMBRM */ + {0xe1, N_("DOS access")}, /* DOS access or SpeedStor 12-bit FAT + extended partition */ + {0xe3, N_("DOS R/O")}, /* DOS R/O or SpeedStor */ + {0xe4, N_("SpeedStor")}, /* SpeedStor 16-bit FAT extended + partition < 1024 cyl. */ + {0xeb, N_("BeOS fs")}, + {0xee, N_("GPT")}, /* Intel EFI GUID Partition Table */ + {0xef, N_("EFI (FAT-12/16/32)")},/* Intel EFI System Partition */ + {0xf0, N_("Linux/PA-RISC boot")},/* Linux/PA-RISC boot loader */ + {0xf1, N_("SpeedStor")}, + {0xf4, N_("SpeedStor")}, /* SpeedStor large partition */ + {0xf2, N_("DOS secondary")}, /* DOS 3.3+ secondary */ + {0xfb, N_("VMware VMFS")}, + {0xfc, N_("VMware VMKCORE")}, /* VMware kernel dump partition */ + {0xfd, N_("Linux raid autodetect")},/* New (2.2.x) raid partition with + autodetect using persistent + superblock */ + {0xfe, N_("LANstep")}, /* SpeedStor >1024 cyl. or LANstep */ + {0xff, N_("BBT")}, /* Xenix Bad Block Table */ + + { 0, 0 } diff --git a/include/pt-mbr.h b/include/pt-mbr.h new file mode 100644 index 000000000..1279e3cf2 --- /dev/null +++ b/include/pt-mbr.h @@ -0,0 +1,178 @@ +#ifndef UTIL_LINUX_PT_MBR_H +#define UTIL_LINUX_PT_MBR_H + +struct dos_partition { + unsigned char boot_ind; /* 0x80 - active */ + unsigned char bh, bs, bc; /* begin CHS */ + unsigned char sys_ind; + unsigned char eh, es, ec; /* end CHS */ + unsigned char start_sect[4]; + unsigned char nr_sects[4]; +} __attribute__((packed)); + +#define MBR_PT_OFFSET 0x1be + +static inline struct dos_partition *mbr_get_partition(unsigned char *mbr, int i) +{ + return (struct dos_partition *) + (mbr + MBR_PT_OFFSET + (i * sizeof(struct dos_partition))); +} + +/* assemble badly aligned little endian integer */ +static inline unsigned int __dos_assemble_4le(const unsigned char *p) +{ + return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24); +} + +static inline void __dos_store_4le(unsigned char *p, unsigned int val) +{ + p[0] = (val & 0xff); + p[1] = ((val >> 8) & 0xff); + p[2] = ((val >> 16) & 0xff); + p[3] = ((val >> 24) & 0xff); +} + +static inline unsigned int dos_partition_get_start(struct dos_partition *p) +{ + return __dos_assemble_4le(&(p->start_sect[0])); +} + +static inline void dos_partition_set_start(struct dos_partition *p, unsigned int n) +{ + __dos_store_4le(p->start_sect, n); +} + +static inline unsigned int dos_partition_get_size(struct dos_partition *p) +{ + return __dos_assemble_4le(&(p->nr_sects[0])); +} + +static inline void dos_partition_set_size(struct dos_partition *p, unsigned int n) +{ + __dos_store_4le(p->nr_sects, n); +} + +static inline int mbr_is_valid_magic(const unsigned char *mbr) +{ + return mbr[510] == 0x55 && mbr[511] == 0xaa ? 1 : 0; +} + +static inline void mbr_set_magic(unsigned char *b) +{ + b[510] = 0x55; + b[511] = 0xaa; +} + +static inline unsigned int mbr_get_id(const unsigned char *mbr) +{ + return __dos_assemble_4le(&mbr[440]); +} + +static inline void mbr_set_id(unsigned char *b, unsigned int id) +{ + __dos_store_4le(&b[440], id); +} + +enum { + MBR_EMPTY_PARTITION = 0x00, + MBR_FAT12_PARTITION = 0x01, + MBR_XENIX_ROOT_PARTITION = 0x02, + MBR_XENIX_USR_PARTITION = 0x03, + MBR_FAT16_LESS32M_PARTITION = 0x04, + MBR_DOS_EXTENDED_PARTITION = 0x05, + MBR_FAT16_PARTITION = 0x06, /* DOS 16-bit >=32M */ + MBR_HPFS_NTFS_PARTITION = 0x07, /* OS/2 IFS, eg, HPFS or NTFS or QNX */ + MBR_AIX_PARTITION = 0x08, /* AIX boot (AIX -- PS/2 port) or SplitDrive */ + MBR_AIX_BOOTABLE_PARTITION = 0x09, /* AIX data or Coherent */ + MBR_OS2_BOOTMNGR_PARTITION = 0x0a, /* OS/2 Boot Manager */ + MBR_W95_FAT32_PARTITION = 0x0b, + MBR_W95_FAT32_LBA_PARTITION = 0x0c, /* LBA really is `Extended Int 13h' */ + MBR_W95_FAT16_LBA_PARTITION = 0x0e, + MBR_W95_EXTENDED_PARTITION = 0x0f, + MBR_OPUS_PARTITION = 0x10, + MBR_HIDDEN_FAT12_PARTITION = 0x11, + MBR_COMPAQ_DIAGNOSTICS_PARTITION = 0x12, + MBR_HIDDEN_FAT16_L32M_PARTITION = 0x14, + MBR_HIDDEN_FAT16_PARTITION = 0x16, + MBR_HIDDEN_HPFS_NTFS_PARTITION = 0x17, + MBR_AST_SMARTSLEEP_PARTITION = 0x18, + MBR_HIDDEN_W95_FAT32_PARTITION = 0x1b, + MBR_HIDDEN_W95_FAT32LBA_PARTITION = 0x1c, + MBR_HIDDEN_W95_FAT16LBA_PARTITION = 0x1e, + MBR_NEC_DOS_PARTITION = 0x24, + MBR_PLAN9_PARTITION = 0x39, + MBR_PARTITIONMAGIC_PARTITION = 0x3c, + MBR_VENIX80286_PARTITION = 0x40, + MBR_PPC_PREP_BOOT_PARTITION = 0x41, + MBR_SFS_PARTITION = 0x42, + MBR_QNX_4X_PARTITION = 0x4d, + MBR_QNX_4X_2ND_PARTITION = 0x4e, + MBR_QNX_4X_3RD_PARTITION = 0x4f, + MBR_DM_PARTITION = 0x50, + MBR_DM6_AUX1_PARTITION = 0x51, /* (or Novell) */ + MBR_CPM_PARTITION = 0x52, /* CP/M or Microport SysV/AT */ + MBR_DM6_AUX3_PARTITION = 0x53, + MBR_DM6_PARTITION = 0x54, + MBR_EZ_DRIVE_PARTITION = 0x55, + MBR_GOLDEN_BOW_PARTITION = 0x56, + MBR_PRIAM_EDISK_PARTITION = 0x5c, + MBR_SPEEDSTOR_PARTITION = 0x61, + MBR_GNU_HURD_PARTITION = 0x63, /* GNU HURD or Mach or Sys V/386 (such as ISC UNIX) */ + MBR_UNIXWARE_PARTITION = MBR_GNU_HURD_PARTITION, + MBR_NETWARE_286_PARTITION = 0x64, + MBR_NETWARE_386_PARTITION = 0x65, + MBR_DISKSECURE_MULTIBOOT_PARTITION = 0x70, + MBR_PC_IX_PARTITION = 0x75, + MBR_OLD_MINIX_PARTITION = 0x80, /* Minix 1.4a and earlier */ + MBR_MINIX_PARTITION = 0x81, /* Minix 1.4b and later */ + MBR_LINUX_SWAP_PARTITION = 0x82, + MBR_SOLARIS_X86_PARTITION = MBR_LINUX_SWAP_PARTITION, + MBR_LINUX_DATA_PARTITION = 0x83, + MBR_OS2_HIDDEN_DRIVE_PARTITION = 0x84, + MBR_LINUX_EXTENDED_PARTITION = 0x85, + MBR_NTFS_VOL_SET1_PARTITION = 0x86, + MBR_NTFS_VOL_SET2_PARTITION = 0x87, + MBR_LINUX_PLAINTEXT_PARTITION = 0x88, + MBR_LINUX_LVM_PARTITION = 0x8e, + MBR_AMOEBA_PARTITION = 0x93, + MBR_AMOEBA_BBT_PARTITION = 0x94, /* (bad block table) */ + MBR_BSD_OS_PARTITION = 0x9f, /* BSDI */ + MBR_THINKPAD_HIBERNATION_PARTITION = 0xa0, + MBR_FREEBSD_PARTITION = 0xa5, /* various BSD flavours */ + MBR_OPENBSD_PARTITION = 0xa6, + MBR_NEXTSTEP_PARTITION = 0xa7, + MBR_DARWIN_UFS_PARTITION = 0xa8, + MBR_NETBSD_PARTITION = 0xa9, + MBR_DARWIN_BOOT_PARTITION = 0xab, + MBR_HFS_HFS_PARTITION = 0xaf, + MBR_BSDI_FS_PARTITION = 0xb7, + MBR_BSDI_SWAP_PARTITION = 0xb8, + MBR_BOOTWIZARD_HIDDEN_PARTITION = 0xbb, + MBR_SOLARIS_BOOT_PARTITION = 0xbe, + MBR_SOLARIS_PARTITION = 0xbf, + MBR_DRDOS_FAT12_PARTITION = 0xc1, + MBR_DRDOS_FAT16_L32M_PARTITION = 0xc4, + MBR_DRDOS_FAT16_PARTITION = 0xc6, + MBR_SYRINX_PARTITION = 0xc7, + MBR_NONFS_DATA_PARTITION = 0xda, + MBR_CPM_CTOS_PARTITION = 0xdb, /* CP/M or Concurrent CP/M or Concurrent DOS or CTOS */ + MBR_DELL_UTILITY_PARTITION = 0xde, /* Dell PowerEdge Server utilities */ + MBR_BOOTIT_PARTITION = 0xdf, /* BootIt EMBRM */ + MBR_DOS_ACCESS_PARTITION = 0xe1, /* DOS access or SpeedStor 12-bit FAT extended partition */ + MBR_DOS_RO_PARTITION = 0xe3, /* DOS R/O or SpeedStor */ + MBR_SPEEDSTOR_EXTENDED_PARTITION = 0xe4, /* SpeedStor 16-bit FAT extended partition < 1024 cyl. */ + MBR_BEOS_FS_PARTITION = 0xeb, + MBR_GPT_PARTITION = 0xee, /* Intel EFI GUID Partition Table */ + MBR_EFI_SYSTEM_PARTITION = 0xef, /* Intel EFI System Partition */ + MBR_LINUX_PARISC_BOOT_PARTITION = 0xf0, /* Linux/PA-RISC boot loader */ + MBR_SPEEDSTOR1_PARTITION = 0xf1, + MBR_SPEEDSTOR2_PARTITION = 0xf4, /* SpeedStor large partition */ + MBR_DOS_SECONDARY_PARTITION = 0xf2, /* DOS 3.3+ secondary */ + MBR_VMWARE_VMFS_PARTITION = 0xfb, + MBR_VMWARE_VMKCORE_PARTITION = 0xfc, /* VMware kernel dump partition */ + MBR_LINUX_RAID_PARTITION = 0xfd, /* New (2.2.x) raid partition with autodetect using persistent superblock */ + MBR_LANSTEP_PARTITION = 0xfe, /* SpeedStor >1024 cyl. or LANstep */ + MBR_XENIX_BBT_PARTITION = 0xff, /* Xenix Bad Block Table */ +}; + +#endif /* UTIL_LINUX_PT_MBR_H */ diff --git a/include/pt-sgi.h b/include/pt-sgi.h new file mode 100644 index 000000000..15f355b84 --- /dev/null +++ b/include/pt-sgi.h @@ -0,0 +1,108 @@ +#ifndef UTIL_LINUX_PT_SUN_H +#define UTIL_LINUX_PT_SUN_H + +#include <stdint.h> + +#define SGI_LABEL_MAGIC 0x0be5a941 + +#define SGI_MAXPARTITIONS 16 +#define SGI_MAXVOLUMES 15 + +/* partition types */ +enum { + SGI_TYPE_VOLHDR = 0x00, + SGI_TYPE_TRKREPL = 0x01, + SGI_TYPE_SECREPL = 0x02, + SGI_TYPE_SWAP = 0x03, + SGI_TYPE_BSD = 0x04, + SGI_TYPE_SYSV = 0x05, + SGI_TYPE_ENTIRE_DISK = 0x06, + SGI_TYPE_EFS = 0x07, + SGI_TYPE_LVOL = 0x08, + SGI_TYPE_RLVOL = 0x09, + SGI_TYPE_XFS = 0x0a, + SGI_TYPE_XFSLOG = 0x0b, + SGI_TYPE_XLV = 0x0c, + SGI_TYPE_XVM = 0x0d +}; + +struct sgi_device_parameter { + unsigned char skew; + unsigned char gap1; + unsigned char gap2; + unsigned char sparecyl; + + uint16_t pcylcount; + uint16_t head_vol0; + uint16_t ntrks; /* tracks in cyl 0 or vol 0 */ + + unsigned char cmd_tag_queue_depth; + unsigned char unused0; + + uint16_t unused1; + uint16_t nsect; /* sectors/tracks in cyl 0 or vol 0 */ + uint16_t bytes; + uint16_t ilfact; + uint32_t flags; /* SGI_DEVPARAM_* controller flags */ + uint32_t datarate; + uint32_t retries_on_error; + uint32_t ms_per_word; + uint16_t xylogics_gap1; + uint16_t xylogics_syncdelay; + uint16_t xylogics_readdelay; + uint16_t xylogics_gap2; + uint16_t xylogics_readgate; + uint16_t xylogics_writecont; +} __attribute__((packed)); + +enum { + SGI_DEVPARAM_SECTOR_SLIP = 0x01, + SGI_DEVPARAM_SECTOR_FWD = 0x02, + SGI_DEVPARAM_TRACK_FWD = 0x04, + SGI_DEVPARAM_TRACK_MULTIVOL = 0x08, + SGI_DEVPARAM_IGNORE_ERRORS = 0x10, + SGI_DEVPARAM_RESEEK = 0x20, + SGI_DEVPARAM_CMDTAGQ_ENABLE = 0x40 +}; + + +struct sgi_disklabel { + uint32_t magic; /* magic number */ + uint16_t root_part_num; /* # root partition */ + uint16_t swap_part_num; /* # swap partition */ + unsigned char boot_file[16]; /* name of boot file */ + + struct sgi_device_parameter devparam; /* not used now */ + + struct sgi_volume { + unsigned char name[8]; /* name of volume */ + uint32_t block_num; /* logical block number */ + uint32_t num_bytes; /* how big, in bytes */ + } __attribute__((packed)) volume[SGI_MAXVOLUMES]; + + struct sgi_partition { + uint32_t num_blocks; /* size in logical blocks */ + uint32_t first_block; /* first logical block */ + uint32_t type; /* type of this partition */ + } __attribute__((packed)) partitions[SGI_MAXPARTITIONS]; + + /* checksum is the 32bit 2's complement sum of the disklabel */ + uint32_t csum; /* disk label checksum */ + uint32_t padding; /* padding */ +} __attribute__((packed)); + +static inline uint32_t sgi_pt_checksum(struct sgi_disklabel *label) +{ + int i; + uint32_t *ptr = (uint32_t *) label; + uint32_t sum = 0; + + i = sizeof(*label) / sizeof(*ptr); + + while (i--) + sum -= be32_to_cpu(ptr[i]); + + return sum; +} + +#endif /* UTIL_LINUX_PT_SUN_H */ diff --git a/include/strutils.h b/include/strutils.h index 709fcadc5..c7fe42a63 100644 --- a/include/strutils.h +++ b/include/strutils.h @@ -102,4 +102,45 @@ extern int parse_range(const char *str, int *lower, int *upper, int def); extern int streq_except_trailing_slash(const char *s1, const char *s2); +/* + * Match string beginning. + */ +static inline const char *startswith(const char *s, const char *prefix) +{ + size_t sz = prefix ? strlen(prefix) : 0; + + if (s && sz && strncmp(s, prefix, sz) == 0) + return s + sz; + return NULL; +} + +/* + * Case insensitive match string beginning. + */ +static inline const char *startswith_no_case(const char *s, const char *prefix) +{ + size_t sz = prefix ? strlen(prefix) : 0; + + if (s && sz && strncasecmp(s, prefix, sz) == 0) + return s + sz; + return NULL; +} + +/* + * Match string ending. + */ +static inline const char *endswith(const char *s, const char *postfix) +{ + size_t sl = s ? strlen(s) : 0; + size_t pl = postfix ? strlen(postfix) : 0; + + if (pl == 0) + return (char *)s + sl; + if (sl < pl) + return NULL; + if (memcmp(s + sl - pl, postfix, pl) != 0) + return NULL; + return (char *)s + sl - pl; +} + #endif diff --git a/include/timeutils.h b/include/timeutils.h new file mode 100644 index 000000000..bcae6137c --- /dev/null +++ b/include/timeutils.h @@ -0,0 +1,55 @@ +/*** + First set of functions in this file are part of systemd, and were + copied to util-linux at August 2013. + + Copyright 2010 Lennart Poettering + + systemd 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. + + systemd 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 License + along with systemd; If not, see <http://www.gnu.org/licenses/>. +***/ +#ifndef UTIL_LINUX_TIME_UTIL_H +#define UTIL_LINUX_TIME_UTIL_H + +#include <stdio.h> +#include <inttypes.h> + +typedef uint64_t usec_t; +typedef uint64_t nsec_t; + +#define MSEC_PER_SEC 1000ULL +#define USEC_PER_SEC 1000000ULL +#define USEC_PER_MSEC 1000ULL +#define NSEC_PER_SEC 1000000000ULL +#define NSEC_PER_MSEC 1000000ULL +#define NSEC_PER_USEC 1000ULL + +#define USEC_PER_MINUTE (60ULL*USEC_PER_SEC) +#define NSEC_PER_MINUTE (60ULL*NSEC_PER_SEC) +#define USEC_PER_HOUR (60ULL*USEC_PER_MINUTE) +#define NSEC_PER_HOUR (60ULL*NSEC_PER_MINUTE) +#define USEC_PER_DAY (24ULL*USEC_PER_HOUR) +#define NSEC_PER_DAY (24ULL*NSEC_PER_HOUR) +#define USEC_PER_WEEK (7ULL*USEC_PER_DAY) +#define NSEC_PER_WEEK (7ULL*NSEC_PER_DAY) +#define USEC_PER_MONTH (2629800ULL*USEC_PER_SEC) +#define NSEC_PER_MONTH (2629800ULL*NSEC_PER_SEC) +#define USEC_PER_YEAR (31557600ULL*USEC_PER_SEC) +#define NSEC_PER_YEAR (31557600ULL*NSEC_PER_SEC) + +#define FORMAT_TIMESTAMP_MAX ((4*4+1)+11+9+4+1) /* weekdays can be unicode */ +#define FORMAT_TIMESTAMP_RELATIVE_MAX 256 +#define FORMAT_TIMESPAN_MAX 64 + +int parse_timestamp(const char *t, usec_t *usec); + +#endif /* UTIL_LINUX_TIME_UTIL_H */ diff --git a/include/tt.h b/include/tt.h index 603844f66..0a16c2075 100644 --- a/include/tt.h +++ b/include/tt.h @@ -27,7 +27,9 @@ enum { TT_FL_TREE = (1 << 6), /* use tree "ascii art" */ TT_FL_RIGHT = (1 << 7), /* align to the right */ TT_FL_STRICTWIDTH = (1 << 8), /* don't reduce width if column is empty */ - TT_FL_NOEXTREMES = (1 << 9) /* ignore extreme fields when count column width*/ + TT_FL_NOEXTREMES = (1 << 9), /* ignore extreme fields when count column width*/ + + TT_FL_FREEDATA = (1 << 10), /* free() data in tt_free_table() */ }; struct tt { @@ -61,7 +63,7 @@ struct tt_column { struct tt_line { struct tt *table; - char const **data; + char **data; void *userdata; size_t data_sz; /* strlen of all data */ @@ -85,7 +87,7 @@ extern struct tt_column *tt_get_column(struct tt *tb, size_t colnum); extern struct tt_line *tt_add_line(struct tt *tb, struct tt_line *parent); -extern int tt_line_set_data(struct tt_line *ln, int colnum, const char *data); +extern int tt_line_set_data(struct tt_line *ln, int colnum, char *data); extern int tt_line_set_userdata(struct tt_line *ln, void *data); extern void tt_fputs_quoted(const char *data, FILE *out); diff --git a/include/ttyutils.h b/include/ttyutils.h index 8882af2cb..4f2fd8848 100644 --- a/include/ttyutils.h +++ b/include/ttyutils.h @@ -13,6 +13,9 @@ #ifdef HAVE_SYS_IOCTL_H #include <sys/ioctl.h> #endif +#ifdef HAVE_SYS_TTYDEFAULTS_H +#include <sys/ttydefaults.h> +#endif /* Some shorthands for control characters. */ #define CTL(x) ((x) ^ 0100) /* Assumes ASCII dialect */ @@ -76,8 +79,8 @@ static inline void reset_virtual_console(struct termios *tp, int flags) tp->c_oflag |= (OPOST | ONLCR | NL0 | CR0 | TAB0 | BS0 | VT0 | FF0); tp->c_oflag &= ~(OLCUC | OCRNL | ONOCR | ONLRET | OFILL | \ NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY); - tp->c_lflag |= (ISIG | ICANON | IEXTEN | ECHO|ECHOE|ECHOK|ECHOKE); - tp->c_lflag &= ~(ECHONL|ECHOCTL|ECHOPRT | NOFLSH | TOSTOP); + tp->c_lflag |= (ISIG | ICANON | IEXTEN | ECHO|ECHOE|ECHOK|ECHOKE|ECHOCTL); + tp->c_lflag &= ~(ECHONL|ECHOPRT | NOFLSH | TOSTOP); if ((flags & UL_TTY_KEEPCFLAGS) == 0) { tp->c_cflag |= (CREAD | CS8 | HUPCL); @@ -122,6 +125,4 @@ static inline void reset_virtual_console(struct termios *tp, int flags) tp->c_cc[VEOL2] = _POSIX_VDISABLE; } - - #endif /* UTIL_LINUX_TTYUTILS_H */ diff --git a/include/xalloc.h b/include/xalloc.h index 6342793e4..105d713b1 100644 --- a/include/xalloc.h +++ b/include/xalloc.h @@ -49,7 +49,7 @@ void *xcalloc(const size_t nelems, const size_t size) return ret; } -static inline char *xstrdup(const char *str) +static inline char __attribute__((warn_unused_result)) *xstrdup(const char *str) { char *ret; @@ -63,7 +63,7 @@ static inline char *xstrdup(const char *str) return ret; } -static inline char *xstrndup(const char *str, size_t size) +static inline char * __attribute__((warn_unused_result)) xstrndup(const char *str, size_t size) { char *ret; @@ -92,7 +92,7 @@ static inline int __attribute__ ((__format__(printf, 2, 3))) } -static inline char *xgethostname(void) +static inline char * __attribute__((warn_unused_result)) xgethostname(void) { char *name; size_t sz = get_hostname_max() + 1; |
