From acf6ab6f676b1ce91f438518d21fd6fa7b671f2b Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 14 Oct 2009 01:13:18 +0200 Subject: lib: import whole ismounted.c code from e2fsprogs Signed-off-by: Karel Zak --- include/ismounted.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'include') diff --git a/include/ismounted.h b/include/ismounted.h index 2b7cca02..57918cb3 100644 --- a/include/ismounted.h +++ b/include/ismounted.h @@ -1,6 +1,14 @@ #ifndef IS_MOUNTED_H #define IS_MOUNTED_H +#define MF_MOUNTED 1 +#define MF_ISROOT 2 +#define MF_READONLY 4 +#define MF_SWAP 8 +#define MF_BUSY 16 + extern int is_mounted(const char *file); +extern int check_mount_point(const char *device, int *mount_flags, + char *mtpt, int mtlen); #endif /* IS_MOUNTED_H */ -- cgit v1.2.3 From d965d63f6414b27c04acee860cc5357887b2e788 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 15 Oct 2009 01:22:42 +0200 Subject: blockdev: add topology ioctls support new options: --getpbsz get physical block (sector) size --getiomin get minimum I/O size --getioopt get optimal I/O size --getalignoff get alignment offset --getmaxsect get max sectors per request Signed-off-by: Karel Zak --- disk-utils/blockdev.c | 32 +++++++++++++++++++++++++++++++- include/blkdev.h | 6 ++++++ 2 files changed, 37 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/disk-utils/blockdev.c b/disk-utils/blockdev.c index b6c6415f..b0ae37d9 100644 --- a/disk-utils/blockdev.c +++ b/disk-utils/blockdev.c @@ -78,7 +78,37 @@ struct bdc bdcms[] = .name = "--getss", .argtype = ARG_INT, .argval = -1, - .help = N_("get sectorsize") + .help = N_("get logical block (sector) size") + },{ + IOCTL_ENTRY(BLKPBSZGET), + .name = "--getpbsz", + .argtype = ARG_UINT, + .argval = -1, + .help = N_("get physical block (sector) size") + },{ + IOCTL_ENTRY(BLKIOMIN), + .name = "--getiomin", + .argtype = ARG_UINT, + .argval = -1, + .help = N_("get minimum I/O size") + },{ + IOCTL_ENTRY(BLKIOOPT), + .name = "--getioopt", + .argtype = ARG_UINT, + .argval = -1, + .help = N_("get optimal I/O size") + },{ + IOCTL_ENTRY(BLKALIGNOFF), + .name = "--getalignoff", + .argtype = ARG_INT, + .argtype = -1, + .help = N_("get alignment offset") + },{ + IOCTL_ENTRY(BLKSECTGET), + .name = "--getmaxsect", + .argtype = ARG_USHRT, + .argval = -1, + .help = N_("get max sectors per request") },{ IOCTL_ENTRY(BLKBSZGET), .name = "--getbsz", diff --git a/include/blkdev.h b/include/blkdev.h index 9d9453bc..57ef40d4 100644 --- a/include/blkdev.h +++ b/include/blkdev.h @@ -34,6 +34,12 @@ #define BLKBSZSET _IOW(0x12,113,size_t) #define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */ +/* block device topology ioctls, introduced in 2.6.32 */ +#define BLKIOMIN _IO(0x1,120) +#define BLKIOOPT _IO(0x12,121) +#define BLKALIGNOFF _IO(0x12,122) +#define BLKPBSZGET _IO(0x12,123) + #endif /* BLKROSET */ #ifndef HDIO_GETGEO -- cgit v1.2.3 From ed98508a1cf5ebe67948b6c2ec7a65f4ddd110f8 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 15 Oct 2009 02:32:03 +0200 Subject: blockdev: fix topology ioctls kernel 2.6.32-rc4 (kvm): # blockdev -v --getss --getpbsz --getiomin --getioopt --getmaxsect --getalignoff /dev/sda get logical block (sector) size: 512 get physical block (sector) size: 512 get minimum I/O size: 512 get optimal I/O size: 0 get max sectors per request: 1024 get alignment offset: 0 Signed-off-by: Karel Zak --- disk-utils/blockdev.c | 2 +- include/blkdev.h | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/disk-utils/blockdev.c b/disk-utils/blockdev.c index b0ae37d9..b20c052f 100644 --- a/disk-utils/blockdev.c +++ b/disk-utils/blockdev.c @@ -101,7 +101,7 @@ struct bdc bdcms[] = IOCTL_ENTRY(BLKALIGNOFF), .name = "--getalignoff", .argtype = ARG_INT, - .argtype = -1, + .argval = -1, .help = N_("get alignment offset") },{ IOCTL_ENTRY(BLKSECTGET), diff --git a/include/blkdev.h b/include/blkdev.h index 57ef40d4..56a9c1f4 100644 --- a/include/blkdev.h +++ b/include/blkdev.h @@ -34,13 +34,15 @@ #define BLKBSZSET _IOW(0x12,113,size_t) #define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */ +#endif /* BLKROSET */ + /* block device topology ioctls, introduced in 2.6.32 */ -#define BLKIOMIN _IO(0x1,120) +#ifndef BLKIOMIN +#define BLKIOMIN _IO(0x12,120) #define BLKIOOPT _IO(0x12,121) #define BLKALIGNOFF _IO(0x12,122) #define BLKPBSZGET _IO(0x12,123) - -#endif /* BLKROSET */ +#endif #ifndef HDIO_GETGEO # ifdef __linux__ -- cgit v1.2.3 From e98754d6bbd277902f4e5e8190b29ece5d4376ec Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 15 Oct 2009 14:14:32 +0200 Subject: fsck.minix: fix broken zone checking This bug has been introduced by commit 95356e8b744439336925eeb36f01399f1ee8a5e9. The fsck.minix code assumes that isset() macro returns boolean, unfortunately the generic implementation from libc returns integer. This patch also add a fallback for the bitmap macros to include/bitops.h. Reported-by: "Andries E. Brouwer" Signed-off-by: Karel Zak --- disk-utils/fsck.minix.c | 6 +++--- disk-utils/mkfs.minix.c | 5 ++--- include/bitops.h | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/disk-utils/fsck.minix.c b/disk-utils/fsck.minix.c index c9bd6535..31b5ef6c 100644 --- a/disk-utils/fsck.minix.c +++ b/disk-utils/fsck.minix.c @@ -100,12 +100,12 @@ #include #include #include -#include #include #include "minix.h" #include "nls.h" #include "pathnames.h" +#include "bitops.h" #define ROOT_INO 1 @@ -166,8 +166,8 @@ static unsigned char * zone_count = NULL; static void recursive_check(unsigned int ino); static void recursive_check2(unsigned int ino); -#define inode_in_use(x) (isset(inode_map,(x))) -#define zone_in_use(x) (isset(zone_map,(x)-FIRSTZONE+1)) +#define inode_in_use(x) (isset(inode_map,(x)) != 0) +#define zone_in_use(x) (isset(zone_map,(x)-FIRSTZONE+1) != 0) #define mark_inode(x) (setbit(inode_map,(x)),changed=1) #define unmark_inode(x) (clrbit(inode_map,(x)),changed=1) diff --git a/disk-utils/mkfs.minix.c b/disk-utils/mkfs.minix.c index ebef5188..391f09b8 100644 --- a/disk-utils/mkfs.minix.c +++ b/disk-utils/mkfs.minix.c @@ -68,7 +68,6 @@ #include #include #include -#include #include #include @@ -76,6 +75,7 @@ #include "minix.h" #include "nls.h" #include "pathnames.h" +#include "bitops.h" #define MINIX_ROOT_INO 1 #define MINIX_BAD_INO 2 @@ -131,8 +131,7 @@ static unsigned short good_blocks_table[MAX_GOOD_BLOCKS]; static int used_good_blocks = 0; static unsigned long req_nr_inodes = 0; -#define inode_in_use(x) (isset(inode_map,(x))) -#define zone_in_use(x) (isset(zone_map,(x)-FIRSTZONE+1)) +#define zone_in_use(x) (isset(zone_map,(x)-FIRSTZONE+1) != 0) #define mark_inode(x) (setbit(inode_map,(x))) #define unmark_inode(x) (clrbit(inode_map,(x))) diff --git a/include/bitops.h b/include/bitops.h index e6eaff18..e283b835 100644 --- a/include/bitops.h +++ b/include/bitops.h @@ -4,6 +4,22 @@ #include #include +/* + * Bit map related macros. Usually provided by libc. + */ +#include + +#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 + #if !defined __BYTE_ORDER || !(__BYTE_ORDER == __LITTLE_ENDIAN) && !(__BYTE_ORDER == __BIG_ENDIAN) #error missing __BYTE_ORDER #endif -- cgit v1.2.3 From 4d0dbb8b634ab0ec833348502aff284598858696 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 16 Oct 2009 00:42:22 +0200 Subject: include: add c.h with fundamental C definitions Add: * ARRAY_SIZE with array type check * PATH_MAX, TRUE and FALSE macros * dummy __attribute__ for non-gcc compilers Signed-off-by: Karel Zak --- include/Makefile.am | 1 + include/c.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 include/c.h (limited to 'include') diff --git a/include/Makefile.am b/include/Makefile.am index 9f581fda..525e3d2e 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -1,6 +1,7 @@ include $(top_srcdir)/config/include-Makefile.am dist_noinst_HEADERS = \ + c.h \ bitops.h \ blkdev.h \ canonicalize.h \ diff --git a/include/c.h b/include/c.h new file mode 100644 index 00000000..413366b2 --- /dev/null +++ b/include/c.h @@ -0,0 +1,49 @@ +/* + * Fundamental C definitions. + */ + +#ifndef UTIL_LINUX_C_H +#define UTIL_LINUX_C_H + +#include + +/* + * Compiler specific stuff + */ +#ifdef __GNUC__ + +/* &a[0] degrades to a pointer: a different type from an array */ +# define __must_be_array(a) \ + BUILD_BUG_ON_ZERO(__builtin_types_compatible_p(typeof(a), typeof(&a[0]))) + +#else /* !__GNUC__ */ +# define __must_be_array(a) 0 +# define __attribute__(_arg_) +#endif /* !__GNUC__ */ + + +/* 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 where-ever else comma expressions + * aren't permitted). + */ +#define BUILD_BUG_ON_ZERO(e) (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 + +#endif /* UTIL_LINUX_C_H */ -- cgit v1.2.3 From 45bda5c8dda9273d7ce0479a1931bfd9766717f7 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 16 Oct 2009 01:45:42 +0200 Subject: include: use c.h in canonicalize.h Signed-off-by: Karel Zak --- include/canonicalize.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'include') diff --git a/include/canonicalize.h b/include/canonicalize.h index b8906d43..b04510c7 100644 --- a/include/canonicalize.h +++ b/include/canonicalize.h @@ -1,10 +1,7 @@ #ifndef CANONICALIZE_H #define CANONICALIZE_H -#include -#ifndef PATH_MAX -# define PATH_MAX 4096 -#endif +#include "c.h" /* for PATH_MAX */ extern char *canonicalize_path(const char *path); -- cgit v1.2.3