Re: NTFS partition tried to mount as reiserfs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tuesday 08 January 2008, Peter Klotz wrote:
> Mike Frysinger wrote:
> > On Tuesday 08 January 2008, Peter Klotz wrote:
> >>> On Monday 07 January 2008, Peter Klotz wrote:
> >>>> When trying to mount one of my NTFS partitions without specifying the
> >>>> "-t" option mount uses reiserfs instead of NTFS.
> >>>>
> >>>> The mount command (util-linux-ng 2.13):
> >>>
> >>> with 2.13+, mount itself no longer does filesystem detection.  instead,
> >>> that job is left up to other (better) libraries which is a good thing
> >>> (people maintaining mount need not spend time on it).
> >>>
> >>> however, there are two different libraries util-linux will attempt to
> >>> use and the one is decided at build time.  please post the output of:
> >>> ldd $(which util-linux)
> >>> so that we can figure out what library you're using and so you can
> >>> figure out what library you should see if there is a newer version of
> >
> > hrm, i'm guessing you didnt build util-linux by yourself ?  what
> > distribution are you using and what version of the package ?  if you did
> > build util-linux, please post the config.log after running `./configure`.
>
> I am using Ubuntu 7.10 i386, the package version of util-linux is
> 2.13-8ubuntu1.

their control file says they force volume_id ... i wonder if they also forced 
static linking (which seems kind of dumb, but whatever).

i'm attaching code distilled from the version of util-linux that you're 
running.  try compiling it like so:
gcc fsprobe_volumeid.c -lvolume_id -Wall -o probe_test
this will of course require you to install the volume_id dev package as well 
as gcc and such ... unfortunately, there's no real way for us to know whether 
the dev package you installed exactly matched the version statically linked 
into util-linux ... but it's a start

then try running it like so (you must of course be root):
./probe_test /dev/sdh1
if volume_id is functioning correctly, it should return ntfs.  that means the 
problem may lie in util-linux's mount.  if it returns reiserfs, it means 
util-linux gets to wash its hand and redirect you to ubuntu's bug tracker as 
the problem appears to lie in volume_id (which is not part of util-linux).

on my system for example:
root@G5[ppc] 0:0 vapier # ./probe_test /dev/sda1
fsprobe_get_fstype_by_devname(/dev/sda1) = (null)
root@G5[ppc] 0:0 vapier # ./probe_test /dev/sda2
fsprobe_get_fstype_by_devname(/dev/sda2) = hfs
root@G5[ppc] 0:0 vapier # ./probe_test /dev/sda3
fsprobe_get_fstype_by_devname(/dev/sda3) = hfsplus
root@G5[ppc] 0:0 vapier # ./probe_test /dev/sda4
fsprobe_get_fstype_by_devname(/dev/sda4) = ext3
the volume_id code correctly detects the partition types for my disks on my 
ppc box
-mike

Attachment: signature.asc
Description: This is a digitally signed message part.

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stddef.h>
#include <sys/mount.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <libvolume_id.h>
#include <limits.h>

#define streq(s, t)  (strcmp ((s), (t)) == 0)
#define xstrdup(str) strdup(str)
#define xmalloc(size) malloc(size)
#define PATH_DEV_BYLABEL	"/dev/disk/by-label"
#define PATH_DEV_BYUUID		"/dev/disk/by-uuid"

#define resolve_symlinks
#ifndef MAXSYMLINKS
# define MAXSYMLINKS 256
#endif

char *
myrealpath(const char *path, char *resolved_path, int maxreslth) {
	int readlinks = 0;
	char *npath;
	char link_path[PATH_MAX+1];
	int n;
	char *buf = NULL;

	npath = resolved_path;

	/* If it's a relative pathname use getcwd for starters. */
	if (*path != '/') {
		if (!getcwd(npath, maxreslth-2))
			return NULL;
		npath += strlen(npath);
		if (npath[-1] != '/')
			*npath++ = '/';
	} else {
		*npath++ = '/';
		path++;
	}

	/* Expand each slash-separated pathname component. */
	while (*path != '\0') {
		/* Ignore stray "/" */
		if (*path == '/') {
			path++;
			continue;
		}
		if (*path == '.' && (path[1] == '\0' || path[1] == '/')) {
			/* Ignore "." */
			path++;
			continue;
		}
		if (*path == '.' && path[1] == '.' &&
		    (path[2] == '\0' || path[2] == '/')) {
			/* Backup for ".." */
			path += 2;
			while (npath > resolved_path+1 &&
			       (--npath)[-1] != '/')
				;
			continue;
		}
		/* Safely copy the next pathname component. */
		while (*path != '\0' && *path != '/') {
			if (npath-resolved_path > maxreslth-2) {
				errno = ENAMETOOLONG;
				goto err;
			}
			*npath++ = *path++;
		}

		/* Protect against infinite loops. */
		if (readlinks++ > MAXSYMLINKS) {
			errno = ELOOP;
			goto err;
		}

		/* See if last pathname component is a symlink. */
		*npath = '\0';
		n = readlink(resolved_path, link_path, PATH_MAX);
		if (n < 0) {
			/* EINVAL means the file exists but isn't a symlink. */
			if (errno != EINVAL)
				goto err;
		} else {
#ifdef resolve_symlinks		/* Richard Gooch dislikes sl resolution */
			int m;

			/* Note: readlink doesn't add the null byte. */
			link_path[n] = '\0';
			if (*link_path == '/')
				/* Start over for an absolute symlink. */
				npath = resolved_path;
			else
				/* Otherwise back up over this component. */
				while (*(--npath) != '/')
					;

			/* Insert symlink contents into path. */
			m = strlen(path);
			if (buf)
				free(buf);
			buf = xmalloc(m + n + 1);
			memcpy(buf, link_path, n);
			memcpy(buf + n, path, m + 1);
			path = buf;
#endif
		}
		*npath++ = '/';
	}
	/* Delete trailing slash but don't whomp a lone slash. */
	if (npath != resolved_path+1 && npath[-1] == '/')
		npath--;
	/* Make sure it's null terminated. */
	*npath = '\0';

	if (buf)
		free(buf);
	return resolved_path;

 err:
	if (buf)
		free(buf);
	return NULL;
}

char *
canonicalize (const char *path) {
	char canonical[PATH_MAX+2];

	if (path == NULL)
		return NULL;

#if 1
	if (streq(path, "none") ||
	    streq(path, "proc") ||
	    streq(path, "devpts"))
		return xstrdup(path);
#endif
	if (myrealpath (path, canonical, PATH_MAX+1))
		return xstrdup(canonical);

	return xstrdup(path);
}

enum probe_type {
	VOLUME_ID_NONE,
	VOLUME_ID_LABEL,
	VOLUME_ID_UUID,
	VOLUME_ID_TYPE,
};

static char
*probe(const char *device, enum probe_type type)
{
	int fd;
	uint64_t size;
	struct volume_id *id;
	const char *val;
	char *value = NULL;

	fd = open(device, O_RDONLY);
	if (fd < 0)
		return NULL;

	id = volume_id_open_fd(fd);
	if (!id) {
		close(fd);
		return NULL;
	}

	/* TODO: use blkdev_get_size() */
	if (ioctl(fd, BLKGETSIZE64, &size) != 0)
		size = 0;

	if (volume_id_probe_all(id, 0, size) == 0) {
		switch(type) {
		case VOLUME_ID_LABEL:
			if (volume_id_get_label(id, &val))
				value  = xstrdup(val);
			break;
		case VOLUME_ID_UUID:
			if (volume_id_get_uuid(id, &val))
				value  = xstrdup(val);
			break;
		case VOLUME_ID_TYPE:
			if (volume_id_get_type(id, &val))
				value  = xstrdup(val);
			break;
		default:
			break;
		}
	}

	volume_id_close(id);
	close(fd);
	return value;
}

void
fsprobe_init(void)
{
}

void
fsprobe_exit(void)
{
}

int
fsprobe_known_fstype(const char *fstype)
{
	if (volume_id_get_prober_by_type(fstype) != NULL)
		return 1;
	return 0;
}

const char *
fsprobe_get_uuid_by_devname(const char *devname)
{
	return probe(devname, VOLUME_ID_UUID);
}

const char *
fsprobe_get_label_by_devname(const char *devname)
{
	return probe(devname, VOLUME_ID_LABEL);
}

const char *
fsprobe_get_fstype_by_devname(const char *devname)
{
	return probe(devname, VOLUME_ID_TYPE);
}

const char *
fsprobe_get_devname_by_uuid(const char *uuid)
{
	char dev[PATH_MAX];
	size_t len;

	if (!uuid)
		return NULL;

	strcpy(dev, PATH_DEV_BYUUID "/");
	len = strlen(PATH_DEV_BYUUID "/");
	if (!volume_id_encode_string(uuid, &dev[len], sizeof(dev) - len) != 0)
		return NULL;
	return canonicalize(dev);
}

const char *
fsprobe_get_devname_by_label(const char *label)
{
	char dev[PATH_MAX];
	size_t len;

	if (!label)
		return NULL;
	strcpy(dev, PATH_DEV_BYLABEL "/");
	len = strlen(PATH_DEV_BYLABEL "/");
	if (!volume_id_encode_string(label, &dev[len], sizeof(dev) - len) != 0)
		return NULL;
	return canonicalize(dev);
}

int main(int argc, char *argv[])
{
	if (argc != 2) {
		printf("Usage: %s <device node>\n", argv[0]);
		return 1;
	}

	printf("fsprobe_get_fstype_by_devname(%s) = %s\n", argv[1], fsprobe_get_fstype_by_devname(argv[1]));

	return 0;
}

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux