diff options
author | Elliott Hughes <enh@google.com> | 2018-06-20 12:17:16 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2018-06-20 12:17:16 -0700 |
commit | 0163d9ee79315fa0801b3fc2377eb48247933086 (patch) | |
tree | 9f6fc8d078557c250654902f0f22cd6063833897 | |
parent | 93156a8e99fbd4794b3eb5bde5ddace2b9da9bbd (diff) | |
parent | 105322515de02a854d5dcecc1ab2c652c78bb348 (diff) | |
download | newfs_msdos-0163d9ee79315fa0801b3fc2377eb48247933086.tar.gz |
Build external/newfs_msdos. am: 5946c623c5
am: 105322515d
Change-Id: I6e7d87b4944e38bf3d4599f543f486ccad3e42cc
-rwxr-xr-x | Android.bp | 19 | ||||
-rw-r--r-- | mkfs_msdos.c | 71 | ||||
-rw-r--r-- | mkfs_msdos.h | 5 |
3 files changed, 95 insertions, 0 deletions
diff --git a/Android.bp b/Android.bp new file mode 100755 index 0000000..fcaffbc --- /dev/null +++ b/Android.bp @@ -0,0 +1,19 @@ +cc_binary { + name: "newfs_msdos", + cflags: [ + "-Wall", + "-Werror", + "-Wno-unused-function", + "-Wno-unused-parameter", + "-Wno-unused-variable", + "-D_FILE_OFFSET_BITS=64", + "-D_GNU_SOURCE", + "-DSIGINFO=SIGUSR2", + "-Dnitems(x)=(sizeof((x))/sizeof((x)[0]))", + ], + srcs: [ + "mkfs_msdos.c", + "newfs_msdos.c", + ], + host_supported: true, +} diff --git a/mkfs_msdos.c b/mkfs_msdos.c index a10f769..350b782 100644 --- a/mkfs_msdos.c +++ b/mkfs_msdos.c @@ -31,10 +31,18 @@ static const char rcsid[] = #endif /* not lint */ #include <sys/param.h> +#if defined(__linux__) +#include <linux/fs.h> +#include <linux/hdreg.h> +#include <sys/ioctl.h> +#elif defined(__APPLE__) +/* Nothing. */ +#else #include <sys/fdcio.h> #include <sys/disk.h> #include <sys/disklabel.h> #include <sys/mount.h> +#endif #include <sys/stat.h> #include <sys/time.h> @@ -53,6 +61,13 @@ static const char rcsid[] = #include "mkfs_msdos.h" +#if !defined(__packed) +#define __packed __attribute__((__packed__)) +#endif +#if !defined(__unused) +#define __unused __attribute__((__unused__)) +#endif + #define MAXU16 0xffff /* maximum unsigned 16-bit quantity */ #define BPN 4 /* bits per nibble */ #define NPB 2 /* nibbles per byte */ @@ -766,6 +781,7 @@ done: static int check_mounted(const char *fname, mode_t mode) { +#if 0 struct statfs *mp; const char *s1, *s2; size_t len; @@ -790,6 +806,7 @@ check_mounted(const char *fname, mode_t mode) return -1; } } +#endif return 0; } @@ -814,6 +831,59 @@ getstdfmt(const char *fmt, struct bpb *bpb) /* * Get disk slice, partition, and geometry information. */ +#if defined(__linux__) +static int getdiskinfo(int fd, const char *fname, const char *dtype, + __unused int oflag, struct bpb *bpb) +{ + if (ioctl(fd, BLKSSZGET, &bpb->bpbBytesPerSec)) { + err(1, "ioctl(BLKSSZGET) for bytes/sector failed"); + } + + if (ckgeom(fname, bpb->bpbBytesPerSec, "bytes/sector") == -1) return -1; + + u_long block_size; + if (ioctl(fd, BLKGETSIZE, &block_size)) { + err(1, "ioctl(BLKGETSIZE) failed"); + } + + if (block_size > UINT32_MAX) { + errx(1, "block size too large: %lu", block_size); + } + + bpb->bpbHugeSectors = (u_int)block_size; + + struct hd_geometry geom; + if (ioctl(fd, HDIO_GETGEO, &geom)) { + warn("ioctl(HDIO_GETGEO) failed, but will use sane values"); + geom.heads = 64; + geom.sectors = 63; + } + + if (!geom.heads) { + warnx("Bogus heads from kernel - setting sane value"); + geom.heads = 64; + } + + if (!geom.sectors) { + warnx("Bogus sectors from kernel - setting sane value"); + geom.sectors = 63; + } + + bpb->bpbSecPerTrack = geom.sectors; + if (ckgeom(fname, bpb->bpbSecPerTrack, "sectors/track") == -1) return -1; + + bpb->bpbHeads = geom.heads; + if (ckgeom(fname, bpb->bpbHeads, "drive heads") == -1) return -1; + + return 0; +} +#elif defined(__APPLE__) +static int +getdiskinfo(int fd, const char *fname, const char *dtype, __unused int oflag, + struct bpb *bpb) { + return 0; +} +#else static int getdiskinfo(int fd, const char *fname, const char *dtype, __unused int oflag, struct bpb *bpb) @@ -903,6 +973,7 @@ getdiskinfo(int fd, const char *fname, const char *dtype, __unused int oflag, bpb->bpbHiddenSecs = hs; return 0; } +#endif /* * Print out BPB values. diff --git a/mkfs_msdos.h b/mkfs_msdos.h index acd5615..b49a577 100644 --- a/mkfs_msdos.h +++ b/mkfs_msdos.h @@ -32,6 +32,7 @@ #include <sys/types.h> #include <stdbool.h> +#include <stdint.h> #define ALLOPTS \ AOPT('@', off_t, offset, 0, "Offset in device") \ AOPT('A', bool, align, -2, "Attempt to cluster align root directory") \ @@ -70,3 +71,7 @@ ALLOPTS }; int mkfs_msdos(const char *, const char *, const struct msdos_options *); + +#if defined(__GLIBC__) +static inline char* getprogname() { return program_invocation_short_name; } +#endif |