2008-02-01 21:29:19 +01:00
|
|
|
Index: misc/Makefile.in
|
|
|
|
===================================================================
|
|
|
|
--- misc/Makefile.in.orig
|
2006-12-19 00:15:45 +01:00
|
|
|
+++ misc/Makefile.in
|
2008-02-01 21:29:19 +01:00
|
|
|
@@ -40,7 +40,7 @@ UUIDD_OBJS= uuidd.o
|
2006-12-19 00:15:45 +01:00
|
|
|
DUMPE2FS_OBJS= dumpe2fs.o
|
|
|
|
BADBLOCKS_OBJS= badblocks.o
|
|
|
|
E2IMAGE_OBJS= e2image.o
|
|
|
|
-FSCK_OBJS= fsck.o base_device.o
|
|
|
|
+FSCK_OBJS= fsck.o base_device.o fsck_udev.o
|
|
|
|
BLKID_OBJS= blkid.o
|
|
|
|
FILEFRAG_OBJS= filefrag.o
|
|
|
|
|
2008-02-01 21:29:19 +01:00
|
|
|
@@ -62,6 +62,9 @@ STATIC_DEPLIBS= $(STATIC_LIBEXT2FS) $(ST
|
2006-12-19 00:15:45 +01:00
|
|
|
LIBS_BLKID= $(LIBBLKID) $(LIBUUID)
|
2008-02-01 21:29:19 +01:00
|
|
|
DEPLIBS_BLKID= $(DEPLIBBLKID) $(DEPLIBUUID)
|
2006-12-19 00:15:45 +01:00
|
|
|
|
|
|
|
+LIBS_VOLID= -lvolume_id
|
|
|
|
+DEPLIBS_VOLID=
|
|
|
|
+
|
|
|
|
LIBS_E2P= $(LIBE2P) $(LIBCOM_ERR)
|
|
|
|
DEPLIBS_E2P= $(LIBE2P) $(LIBCOM_ERR)
|
|
|
|
|
2008-02-01 21:29:19 +01:00
|
|
|
@@ -117,10 +120,6 @@ base_device: base_device.c
|
2006-12-19 00:15:45 +01:00
|
|
|
@$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) $(srcdir)/base_device.c \
|
|
|
|
-DDEBUG -o base_device
|
|
|
|
|
|
|
|
-check:: base_device
|
|
|
|
- ./base_device < $(srcdir)/base_device.tst > base_device.out
|
|
|
|
- cmp $(srcdir)/base_device.tst base_device.out
|
|
|
|
-
|
|
|
|
mklost+found: $(MKLPF_OBJS)
|
|
|
|
@echo " LD $@"
|
|
|
|
@$(CC) $(ALL_LDFLAGS) -o mklost+found $(MKLPF_OBJS) $(LIBINTL)
|
2008-02-01 21:29:19 +01:00
|
|
|
@@ -157,9 +156,9 @@ dumpe2fs: $(DUMPE2FS_OBJS) $(DEPLIBS) $(
|
2006-12-19 00:15:45 +01:00
|
|
|
@$(CC) $(ALL_LDFLAGS) -o dumpe2fs $(DUMPE2FS_OBJS) $(LIBS) \
|
|
|
|
$(LIBS_E2P) $(LIBUUID) $(LIBINTL)
|
|
|
|
|
|
|
|
-fsck: $(FSCK_OBJS) $(DEBLIBS_BLKID)
|
|
|
|
+fsck: $(FSCK_OBJS) $(DEBLIBS_VOLID)
|
|
|
|
@echo " LD $@"
|
|
|
|
- @$(CC) $(ALL_LDFLAGS) -o fsck $(FSCK_OBJS) $(LIBS_BLKID) $(LIBINTL)
|
|
|
|
+ @$(CC) $(ALL_LDFLAGS) -o fsck $(FSCK_OBJS) $(LIBS_VOLID) $(LIBINTL)
|
|
|
|
|
|
|
|
badblocks: $(BADBLOCKS_OBJS) $(DEPLIBS)
|
|
|
|
@echo " LD $@"
|
2008-02-01 21:29:19 +01:00
|
|
|
Index: misc/base_device.c
|
|
|
|
===================================================================
|
|
|
|
--- misc/base_device.c.orig
|
2006-12-19 00:15:45 +01:00
|
|
|
+++ misc/base_device.c
|
|
|
|
@@ -27,6 +27,8 @@
|
|
|
|
#endif
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
+#include <sys/stat.h>
|
|
|
|
+#include <errno.h>
|
|
|
|
|
|
|
|
#include "fsck.h"
|
|
|
|
|
2008-02-01 21:29:19 +01:00
|
|
|
Index: misc/fsck.8.in
|
|
|
|
===================================================================
|
|
|
|
--- misc/fsck.8.in.orig
|
2006-12-19 00:15:45 +01:00
|
|
|
+++ misc/fsck.8.in
|
2008-02-01 21:29:19 +01:00
|
|
|
@@ -8,7 +8,7 @@ fsck \- check and repair a Linux file sy
|
2006-12-19 00:15:45 +01:00
|
|
|
.SH SYNOPSIS
|
|
|
|
.B fsck
|
|
|
|
[
|
|
|
|
-.B \-sAVRTNP
|
|
|
|
+.B \-sAVRTMNP
|
|
|
|
]
|
|
|
|
[
|
|
|
|
.B \-C
|
2008-02-01 21:29:19 +01:00
|
|
|
@@ -236,6 +236,14 @@ in which case the progress bar informati
|
2006-12-19 00:15:45 +01:00
|
|
|
.B \-N
|
|
|
|
Don't execute, just show what would be done.
|
|
|
|
.TP
|
|
|
|
+.B \-M
|
|
|
|
+Emulate
|
|
|
|
+.BR mount (1)
|
|
|
|
+behaviour; do not check the filesystem if it's not listed in
|
|
|
|
+/etc/fstab or if
|
|
|
|
+.I fs_pass_no
|
|
|
|
+of the corresponding entry is zero.
|
|
|
|
+.TP
|
|
|
|
.B \-P
|
|
|
|
When the
|
|
|
|
.B \-A
|
2008-02-01 21:29:19 +01:00
|
|
|
Index: misc/fsck.c
|
|
|
|
===================================================================
|
|
|
|
--- misc/fsck.c.orig
|
2006-12-19 00:15:45 +01:00
|
|
|
+++ misc/fsck.c
|
|
|
|
@@ -59,7 +59,6 @@
|
|
|
|
#include "../version.h"
|
|
|
|
#include "nls-enable.h"
|
|
|
|
#include "fsck.h"
|
|
|
|
-#include "blkid/blkid.h"
|
|
|
|
|
|
|
|
#ifndef _PATH_MNTTAB
|
|
|
|
#define _PATH_MNTTAB "/etc/fstab"
|
2008-02-01 21:29:19 +01:00
|
|
|
@@ -118,7 +117,6 @@ struct fs_info *filesys_info = NULL, *fi
|
2006-12-19 00:15:45 +01:00
|
|
|
struct fsck_instance *instance_list;
|
|
|
|
const char *fsck_prefix_path = "/sbin:/sbin/fs.d:/sbin/fs:/etc/fs:/etc";
|
|
|
|
char *fsck_path = 0;
|
|
|
|
-blkid_cache cache = NULL;
|
|
|
|
|
|
|
|
static char *string_copy(const char *s)
|
|
|
|
{
|
2008-02-01 21:29:19 +01:00
|
|
|
@@ -294,7 +292,7 @@ static int parse_fstab_line(char *line,
|
2006-12-19 00:15:45 +01:00
|
|
|
parse_escape(freq);
|
|
|
|
parse_escape(passno);
|
|
|
|
|
|
|
|
- dev = blkid_get_devname(cache, device, NULL);
|
|
|
|
+ dev = fsck_get_devname(device);
|
|
|
|
if (dev)
|
|
|
|
device = dev;
|
|
|
|
|
2008-02-01 21:29:19 +01:00
|
|
|
@@ -319,7 +317,7 @@ static void interpret_type(struct fs_inf
|
2006-12-19 00:15:45 +01:00
|
|
|
|
|
|
|
if (strcmp(fs->type, "auto") != 0)
|
|
|
|
return;
|
|
|
|
- t = blkid_get_tag_value(cache, "TYPE", fs->device);
|
|
|
|
+ t = fsck_get_fstype(fs->device);
|
|
|
|
if (t) {
|
|
|
|
free(fs->type);
|
|
|
|
fs->type = t;
|
2008-02-01 21:29:19 +01:00
|
|
|
@@ -1058,7 +1056,7 @@ static int check_all(NOARGS)
|
2006-12-19 00:15:45 +01:00
|
|
|
|
|
|
|
static void usage(NOARGS)
|
|
|
|
{
|
|
|
|
- fputs(_("Usage: fsck [-ANPRTV] [ -C [ fd ] ] [-t fstype] [fs-options] [filesys ...]\n"), stderr);
|
|
|
|
+ fputs(_("Usage: fsck [-AMNPRTV] [ -C [ fd ] ] [-t fstype] [fs-options] [filesys ...]\n"), stderr);
|
|
|
|
exit(EXIT_USAGE);
|
|
|
|
}
|
|
|
|
|
2008-02-01 21:29:19 +01:00
|
|
|
@@ -1104,7 +1102,7 @@ static void PRS(int argc, char *argv[])
|
2006-12-19 00:15:45 +01:00
|
|
|
progname);
|
|
|
|
exit(EXIT_ERROR);
|
|
|
|
}
|
|
|
|
- dev = blkid_get_devname(cache, arg, NULL);
|
|
|
|
+ dev = fsck_get_devname(arg);
|
|
|
|
if (!dev && strchr(arg, '=')) {
|
|
|
|
/*
|
|
|
|
* Check to see if we failed because
|
2008-02-01 21:29:19 +01:00
|
|
|
@@ -1250,7 +1248,7 @@ int main(int argc, char *argv[])
|
2006-12-19 00:15:45 +01:00
|
|
|
bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
|
|
|
|
textdomain(NLS_CAT_NAME);
|
|
|
|
#endif
|
2008-02-01 21:29:19 +01:00
|
|
|
- blkid_get_cache(&cache, NULL);
|
|
|
|
+ fsck_get_cache(NULL);
|
2006-12-19 00:15:45 +01:00
|
|
|
PRS(argc, argv);
|
|
|
|
|
|
|
|
if (!notitle)
|
2008-02-01 21:29:19 +01:00
|
|
|
@@ -1297,6 +1295,16 @@ int main(int argc, char *argv[])
|
2006-12-19 00:15:45 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
fs = lookup(devices[i]);
|
|
|
|
+ if (like_mount) {
|
|
|
|
+ /*
|
|
|
|
+ * Emulate mount behaviour:
|
|
|
|
+ * Do not check device if not found
|
|
|
|
+ * in /etc/fstab or if the passno
|
|
|
|
+ * is set to '0'
|
|
|
|
+ */
|
|
|
|
+ if (!fs || ignore(fs))
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
if (!fs) {
|
|
|
|
fs = create_fs_device(devices[i], 0, "auto",
|
|
|
|
0, -1, -1);
|
2008-02-01 21:29:19 +01:00
|
|
|
@@ -1319,6 +1327,6 @@ int main(int argc, char *argv[])
|
2006-12-19 00:15:45 +01:00
|
|
|
}
|
|
|
|
status |= wait_many(FLAG_WAIT_ALL);
|
|
|
|
free(fsck_path);
|
|
|
|
- blkid_put_cache(cache);
|
|
|
|
+ fsck_put_cache();
|
|
|
|
return status;
|
|
|
|
}
|
2008-02-01 21:29:19 +01:00
|
|
|
Index: misc/fsck.h
|
|
|
|
===================================================================
|
|
|
|
--- misc/fsck.h.orig
|
2006-12-19 00:15:45 +01:00
|
|
|
+++ misc/fsck.h
|
2008-02-01 21:29:19 +01:00
|
|
|
@@ -68,3 +68,9 @@ struct fsck_instance {
|
2006-12-19 00:15:45 +01:00
|
|
|
|
|
|
|
extern dev_t base_devt(const char *device);
|
|
|
|
extern int match_device(const char *dev1, const char *dev2);
|
|
|
|
+
|
|
|
|
+extern int fsck_get_cache(const char *filename);
|
|
|
|
+extern void fsck_put_cache(void);
|
|
|
|
+extern char *fsck_get_devname(const char *device);
|
|
|
|
+extern char *fsck_get_fstype(const char *device);
|
|
|
|
+
|
2008-02-01 21:29:19 +01:00
|
|
|
Index: misc/fsck_blkid.c
|
|
|
|
===================================================================
|
|
|
|
--- /dev/null
|
2006-12-19 00:15:45 +01:00
|
|
|
+++ misc/fsck_blkid.c
|
|
|
|
@@ -0,0 +1,29 @@
|
|
|
|
+/*
|
|
|
|
+ * Wrapper for libblkid
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+#include <stdio.h>
|
|
|
|
+#include "blkid/blkid.h"
|
|
|
|
+
|
|
|
|
+static blkid_cache cache = NULL;
|
|
|
|
+
|
|
|
|
+int fsck_get_cache(const char *filename)
|
|
|
|
+{
|
|
|
|
+ return blkid_get_cache(&cache, name);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void fsck_put_cache(void)
|
|
|
|
+{
|
|
|
|
+ blkid_put_cache(cache);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+char *fsck_get_devname(const char *device)
|
|
|
|
+{
|
|
|
|
+ return blkid_get_devname(cache, device, NULL);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+char *fsck_get_fstype(const char *device)
|
|
|
|
+{
|
|
|
|
+ return blkid_get_tag_value(cache, "TYPE", device);
|
|
|
|
+}
|
|
|
|
+
|
2008-02-01 21:29:19 +01:00
|
|
|
Index: misc/fsck_udev.c
|
|
|
|
===================================================================
|
|
|
|
--- /dev/null
|
2006-12-19 00:15:45 +01:00
|
|
|
+++ misc/fsck_udev.c
|
|
|
|
@@ -0,0 +1,188 @@
|
|
|
|
+/*
|
|
|
|
+ * Wrapper for libvolume_id
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+#include <stdio.h>
|
|
|
|
+#include <stdlib.h>
|
|
|
|
+#include <unistd.h>
|
|
|
|
+#include <string.h>
|
|
|
|
+#include <sys/mount.h>
|
|
|
|
+#include <sys/ioctl.h>
|
|
|
|
+#include <stddef.h>
|
|
|
|
+#include <libvolume_id.h>
|
|
|
|
+
|
|
|
|
+#include "fsck.h"
|
|
|
|
+
|
|
|
|
+int fsck_get_cache(const char *filename)
|
|
|
|
+{
|
|
|
|
+ return 0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void fsck_put_cache(void)
|
|
|
|
+{
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+char *fsck_get_devname_by_uuid(const char *uuid)
|
|
|
|
+{
|
|
|
|
+ char *dev = NULL;
|
|
|
|
+
|
|
|
|
+ if (!uuid)
|
|
|
|
+ return NULL;
|
|
|
|
+
|
|
|
|
+ dev = malloc(19 + strlen(uuid));
|
|
|
|
+ if (dev) {
|
|
|
|
+ strcpy(dev,"/dev/disk/by-uuid/");
|
|
|
|
+ strcat(dev,uuid);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return dev;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+char *fsck_get_devname_by_label(const char *label)
|
|
|
|
+{
|
|
|
|
+ char *dev = NULL;
|
|
|
|
+
|
|
|
|
+ if (!label)
|
|
|
|
+ return NULL;
|
|
|
|
+
|
|
|
|
+ dev = malloc(20 + strlen(label));
|
|
|
|
+ if (dev) {
|
|
|
|
+ strcpy(dev,"/dev/disk/by-label/");
|
|
|
|
+ strcat(dev,label);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return dev;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+char *fsck_get_devname(const char *spec)
|
|
|
|
+{
|
|
|
|
+ char *token, *cp, *value;
|
|
|
|
+ char *nspec = NULL;
|
|
|
|
+
|
|
|
|
+ if (!spec)
|
|
|
|
+ return NULL;
|
|
|
|
+
|
|
|
|
+ token = strdup(spec);
|
|
|
|
+ if (!token)
|
|
|
|
+ return NULL;
|
|
|
|
+
|
|
|
|
+ /* We have to return an allocated string */
|
|
|
|
+ if (!(cp = strchr(token, '=')))
|
|
|
|
+ return token;
|
|
|
|
+
|
|
|
|
+ value = token + (cp - token);
|
|
|
|
+ *value++ = '\0';
|
|
|
|
+
|
|
|
|
+ if (*value == '"' || *value == '\'') {
|
|
|
|
+ char c = *value++;
|
|
|
|
+ if (!(cp = strrchr(value, c)))
|
|
|
|
+ goto errout; /* missing closing quote */
|
|
|
|
+ *cp = '\0';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!strcmp(token,"LABEL")) {
|
|
|
|
+ nspec = fsck_get_devname_by_label(value);
|
|
|
|
+ } else if (!strcmp(token,"UUID")) {
|
|
|
|
+ nspec = fsck_get_devname_by_uuid(value);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ free(token);
|
|
|
|
+
|
|
|
|
+ errout:
|
|
|
|
+ return nspec;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+struct volume_id_types_t {
|
|
|
|
+ int id;
|
|
|
|
+ char *token;
|
|
|
|
+ char *env;
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+enum {
|
|
|
|
+ VOLUME_ID_NONE=0,
|
|
|
|
+ VOLUME_ID_TYPE,
|
|
|
|
+ VOLUME_ID_LABEL,
|
|
|
|
+ VOLUME_ID_UUID
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+#define volume_id_offset(member) (unsigned long)offsetof(struct volume_id,member)
|
|
|
|
+
|
|
|
|
+struct volume_id_types_t volume_id_types[] = {
|
|
|
|
+ { VOLUME_ID_TYPE, "TYPE", "ID_FS_TYPE" },
|
|
|
|
+ { VOLUME_ID_LABEL, "LABEL", "ID_FS_LABEL" },
|
|
|
|
+ { VOLUME_ID_UUID, "UUID", "ID_FS_UUID" },
|
|
|
|
+ { VOLUME_ID_NONE, NULL, NULL },
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+char *volume_id_get_tag(const char *spec, const char *token)
|
|
|
|
+{
|
|
|
|
+ struct volume_id *vid;
|
|
|
|
+ uint64_t size;
|
|
|
|
+ struct volume_id_types_t *volume_id_ptr = volume_id_types;
|
|
|
|
+ char *var, *value;
|
|
|
|
+
|
|
|
|
+ value = malloc(VOLUME_ID_LABEL_SIZE);
|
|
|
|
+ if (!value)
|
|
|
|
+ return NULL;
|
|
|
|
+
|
|
|
|
+ if (!spec)
|
|
|
|
+ return NULL;
|
|
|
|
+
|
|
|
|
+ while (volume_id_ptr->token && strcmp(volume_id_ptr->token,token))
|
|
|
|
+ volume_id_ptr++;
|
|
|
|
+
|
|
|
|
+ if (!volume_id_ptr->token) {
|
|
|
|
+ free(value);
|
|
|
|
+ value = NULL;
|
|
|
|
+ goto out;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /* Quick exit if ID_FS_* variables are set */
|
|
|
|
+ if ((var = getenv(volume_id_ptr->env))) {
|
|
|
|
+ strcpy(value,var);
|
|
|
|
+ goto out;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ vid = volume_id_open_node(spec);
|
|
|
|
+ if (!vid) {
|
|
|
|
+ free(value);
|
|
|
|
+ value = NULL;
|
|
|
|
+ goto out;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (ioctl(vid->fd, BLKGETSIZE64, &size) != 0)
|
|
|
|
+ size = 0;
|
|
|
|
+
|
|
|
|
+ if (volume_id_probe_all(vid, 0, size) == 0) {
|
|
|
|
+ switch(volume_id_ptr->id) {
|
|
|
|
+ case VOLUME_ID_TYPE:
|
|
|
|
+ strcpy(value, vid->type);
|
|
|
|
+ break;
|
|
|
|
+ case VOLUME_ID_LABEL:
|
|
|
|
+ strcpy(value, vid->label);
|
|
|
|
+ break;
|
|
|
|
+ case VOLUME_ID_UUID:
|
|
|
|
+ strcpy(value, vid->uuid);
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ free(value);
|
|
|
|
+ value = NULL;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ free(value);
|
|
|
|
+ volume_id_close(vid);
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ volume_id_close(vid);
|
|
|
|
+
|
|
|
|
+ out:
|
|
|
|
+ return value;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+char *fsck_get_fstype(const char *device)
|
|
|
|
+{
|
|
|
|
+ return volume_id_get_tag(device, "TYPE");
|
|
|
|
+}
|
|
|
|
+
|