Skip to content

Commit b0d45ad

Browse files
committed
for mac os porting
1 parent d05de8e commit b0d45ad

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

GNUmakefile

+2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ all: $(PROGS)
88

99
distclean clean:
1010
rm -f $(PROGS)
11+
rm -rf *.o
12+
rm -rf *.dSYM
1113

1214
.PHONY: all clean

cramfsck.c

+16
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,17 @@
4747
#include <stdlib.h>
4848
#include <errno.h>
4949
#include <string.h>
50+
#ifdef LINUX
5051
#include <sys/sysmacros.h>
52+
#endif
5153
#include <utime.h>
5254
#include <sys/ioctl.h>
5355
#define _LINUX_STRING_H_
56+
#ifdef LINUX
5457
#include <linux/fs.h>
58+
#else
59+
#include <sys/disk.h>
60+
#endif
5561
#include <linux/cramfs_fs.h>
5662
#include <zlib.h>
5763

@@ -142,9 +148,15 @@ static void test_super(int *start, size_t *length) {
142148
die(FSCK_ERROR, 1, "open failed: %s", filename);
143149
}
144150
if (S_ISBLK(st.st_mode)) {
151+
#ifdef LINUX
145152
if (ioctl(fd, BLKGETSIZE, length) < 0) {
146153
die(FSCK_ERROR, 1, "ioctl failed: unable to determine device size: %s", filename);
147154
}
155+
#else
156+
if (ioctl(fd, DKIOCGETBLOCKCOUNT, length) < 0) {
157+
die(FSCK_ERROR, 1, "ioctl failed: unable to determine device size: %s", filename);
158+
}
159+
#endif
148160
*length = *length * 512;
149161
}
150162
else if (S_ISREG(st.st_mode)) {
@@ -218,7 +230,11 @@ static void test_crc(int start)
218230

219231
buf = mmap(NULL, super.size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
220232
if (buf == MAP_FAILED) {
233+
#ifdef LINUX
221234
buf = mmap(NULL, super.size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
235+
#else
236+
buf = mmap(NULL, super.size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
237+
#endif
222238
if (buf != MAP_FAILED) {
223239
lseek(fd, 0, SEEK_SET);
224240
read(fd, buf, super.size);

mkcramfs.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ static int cramsort (const void *a, const void *b)
223223
(*(const struct dirent **) b)->d_name);
224224
}
225225

226-
static unsigned int parse_directory(struct entry *root_entry, const char *name, struct entry **prev, loff_t *fslen_ub)
226+
static unsigned int parse_directory(struct entry *root_entry, const char *name, struct entry **prev, off_t *fslen_ub)
227227
{
228228
struct dirent **dirlist;
229229
int totalsize = 0, dircount, dirindex;
@@ -687,7 +687,7 @@ int main(int argc, char **argv)
687687
ssize_t offset, written;
688688
int fd;
689689
/* initial guess (upper-bound) of required filesystem size */
690-
loff_t fslen_ub = sizeof(struct cramfs_super);
690+
off_t fslen_ub = sizeof(struct cramfs_super);
691691
char const *dirname, *outfile;
692692
u32 crc;
693693
int c; /* for getopt */
@@ -787,8 +787,11 @@ int main(int argc, char **argv)
787787
RAM free. If the reason is to be able to write to
788788
un-mmappable block devices, then we could try shared mmap
789789
and revert to anonymous mmap if the shared mmap fails. */
790+
#ifdef LINUX
790791
rom_image = mmap(NULL, fslen_ub?fslen_ub:1, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
791-
792+
#else
793+
rom_image = mmap(NULL, fslen_ub?fslen_ub:1, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
794+
#endif
792795
if (rom_image == MAP_FAILED) {
793796
die(MKFS_ERROR, 1, "mmap failed");
794797
}

0 commit comments

Comments
 (0)