#include <errno.h>
#include <string.h>
#include <getopt.h>
-#include <utime.h>
#include <fcntl.h>
/* We don't use our include/crc32.h, but crc32 from zlib!
*
- * The zlib implemenation performs pre/post-conditioning. The util-linux
+ * The zlib implementation performs pre/post-conditioning. The util-linux
* imlemenation requires post-conditioning (xor) in the applications.
*/
#include <zlib.h>
+#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
fputs(_(" -b, --blocksize <size> use this blocksize, defaults to page size\n"), out);
fputs(_(" --extract[=<dir>] test uncompression, optionally extract into <dir>\n"), out);
fputs(USAGE_SEPARATOR, out);
- print_usage_help_options(26);
+ printf(USAGE_HELP_OPTIONS(26));
printf(USAGE_MAN_TAIL("fsck.cramfs(8)"));
exit(FSCK_EX_OK);
if (magic == CRAMFS_MAGIC) {
cramfs_is_big_endian = HOST_IS_BIG_ENDIAN;
return 0;
- } else if (magic ==
+ }
+
+ if (magic ==
u32_toggle_endianness(!HOST_IS_BIG_ENDIAN, CRAMFS_MAGIC)) {
cramfs_is_big_endian = !HOST_IS_BIG_ENDIAN;
return 0;
- } else
- return -1;
+ }
+
+ return -1;
}
static void test_super(int *start, size_t * length)
errx(FSCK_EX_ERROR, _("unsupported filesystem features"));
/* What are valid superblock sizes? */
- if (super.size < sizeof(struct cramfs_super))
+ if (super.size < *start + sizeof(struct cramfs_super))
errx(FSCK_EX_UNCORRECTED, _("superblock size (%d) too small"),
super.size);
mmap(NULL, super.size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (buf != MAP_FAILED) {
+ ssize_t tmp;
if (lseek(fd, 0, SEEK_SET) == (off_t) -1)
err(FSCK_EX_ERROR, _("seek on %s failed"), filename);
- if (read(fd, buf, super.size) != (ssize_t) super.size)
+ tmp = read(fd, buf, super.size);
+ if (tmp < 0)
err(FSCK_EX_ERROR, _("cannot read %s"), filename);
+ if (tmp != (ssize_t) super.size)
+ errx(FSCK_EX_ERROR, _("failed to read %"PRIu32" bytes from file %s"),
+ super.size, filename);
}
}
if (buf != MAP_FAILED) {
return stream.total_out;
}
-#if !HAVE_LCHOWN
+#ifndef HAVE_LCHOWN
#define lchown chown
#endif
curr = next;
} while (size);
}
-
static void change_file_status(char *path, struct cramfs_inode *i)
{
- struct utimbuf epoch = { 0, 0 };
+ const struct timeval epoch[] = { {0,0}, {0,0} };
if (euid == 0) {
if (lchown(path, i->uid, i->gid) < 0)
}
if (S_ISLNK(i->mode))
return;
- if (utime(path, &epoch) < 0)
- err(FSCK_EX_ERROR, _("utime failed: %s"), path);
+ if (utimes(path, epoch) < 0)
+ err(FSCK_EX_ERROR, _("utimes failed: %s"), path);
}
static void do_directory(char *path, struct cramfs_inode *i)
setlocale(LC_CTYPE, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
- atexit(close_stdout);
+ close_stdout_atexit();
strutils_set_exitcode(FSCK_EX_USAGE);
usage();
break;
case 'V':
- printf(UTIL_LINUX_VERSION);
- return FSCK_EX_OK;
+ print_version(FSCK_EX_OK);
case 'x':
opt_extract = 1;
if(optarg)