Changes by: antona
Update of /cvsroot/linux-ntfs/linux-ntfs/ntfstools
In directory usw-pr-cvs1:/tmp/cvs-serv18456/ntfstools
Modified Files:
Makefile.am Makefile.in ntfslabel.c
Log Message:
Cleanup ntfslabel, write a man page for it, integrate it all in the distribution properly, silence output from ntfs_mount() (conditional on running configure with --enable-debug), update all docs accordingly. Add Rich and Matt to AUTHORS.
Index: Makefile.am
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/Makefile.am,v
retrieving revision 1.14
retrieving revision 1.15
diff -U2 -r1.14 -r1.15
--- Makefile.am 2 Aug 2001 01:44:57 -0000 1.14
+++ Makefile.am 12 Apr 2002 15:23:48 -0000 1.15
@@ -7,6 +7,6 @@
bin_PROGRAMS = ntfsfix #ntfsdump_logfile dumplog
-sbin_PROGRAMS = mkntfs
-man_MANS = mkntfs.8 ntfsfix.8
+sbin_PROGRAMS = mkntfs ntfslabel
+man_MANS = mkntfs.8 ntfsfix.8 ntfslabel.8
linux_ntfsincludedir = -I$(top_srcdir)/include
@@ -22,4 +22,8 @@
mkntfs_LDADD = $(top_srcdir)/libntfs/libntfs.la
mkntfs_LDFLAGS = $(all_libraries)
+
+ntfslabel_SOURCES = ntfslabel.c
+ntfslabel_LDADD = $(top_srcdir)/libntfs/libntfs.la
+ntfslabel_LDFLAGS = $(all_libraries)
# We don't distribute these as they are not really of any use to anyone except
Index: Makefile.in
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/Makefile.in,v
retrieving revision 1.18
retrieving revision 1.19
diff -U2 -r1.18 -r1.19
--- Makefile.in 26 Jan 2002 04:32:35 -0000 1.18
+++ Makefile.in 12 Apr 2002 15:23:48 -0000 1.19
@@ -93,6 +93,6 @@
bin_PROGRAMS = ntfsfix #ntfsdump_logfile dumplog
-sbin_PROGRAMS = mkntfs
-man_MANS = mkntfs.8 ntfsfix.8
+sbin_PROGRAMS = mkntfs ntfslabel
+man_MANS = mkntfs.8 ntfsfix.8 ntfslabel.8
linux_ntfsincludedir = -I$(top_srcdir)/include
@@ -108,9 +108,13 @@
mkntfs_LDADD = $(top_srcdir)/libntfs/libntfs.la
mkntfs_LDFLAGS = $(all_libraries)
+
+ntfslabel_SOURCES = ntfslabel.c
+ntfslabel_LDADD = $(top_srcdir)/libntfs/libntfs.la
+ntfslabel_LDFLAGS = $(all_libraries)
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_HEADER = ../config.h
-CONFIG_CLEAN_FILES = mkntfs.8 ntfsfix.8
+CONFIG_CLEAN_FILES = mkntfs.8 ntfsfix.8 ntfslabel.8
bin_PROGRAMS = ntfsfix$(EXEEXT)
-sbin_PROGRAMS = mkntfs$(EXEEXT)
+sbin_PROGRAMS = mkntfs$(EXEEXT) ntfslabel$(EXEEXT)
PROGRAMS = $(bin_PROGRAMS) $(sbin_PROGRAMS)
@@ -123,4 +127,6 @@
sd.$(OBJEXT) mkntfs.$(OBJEXT)
mkntfs_DEPENDENCIES = $(top_srcdir)/libntfs/libntfs.la
+ntfslabel_OBJECTS = ntfslabel.$(OBJEXT)
+ntfslabel_DEPENDENCIES = $(top_srcdir)/libntfs/libntfs.la
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
@@ -131,5 +137,6 @@
NROFF = nroff
-DIST_COMMON = Makefile.am Makefile.in mkntfs.8.in ntfsfix.8.in
+DIST_COMMON = Makefile.am Makefile.in mkntfs.8.in ntfsfix.8.in \
+ntfslabel.8.in
@@ -139,7 +146,7 @@
GZIP_ENV = --best
DEP_FILES = .deps/attrdef.P .deps/boot.P .deps/mkntfs.P .deps/ntfsfix.P \
-.deps/sd.P .deps/upcase.P
-SOURCES = $(ntfsfix_SOURCES) $(mkntfs_SOURCES)
-OBJECTS = $(ntfsfix_OBJECTS) $(mkntfs_OBJECTS)
+.deps/ntfslabel.P .deps/sd.P .deps/upcase.P
+SOURCES = $(ntfsfix_SOURCES) $(mkntfs_SOURCES) $(ntfslabel_SOURCES)
+OBJECTS = $(ntfsfix_OBJECTS) $(mkntfs_OBJECTS) $(ntfslabel_OBJECTS)
all: all-redirect
@@ -157,4 +164,6 @@
ntfsfix.8: $(top_builddir)/config.status ntfsfix.8.in
cd $(top_builddir) && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
+ntfslabel.8: $(top_builddir)/config.status ntfslabel.8.in
+ cd $(top_builddir) && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status
mostlyclean-binPROGRAMS:
@@ -253,4 +262,8 @@
@rm -f mkntfs$(EXEEXT)
$(LINK) $(mkntfs_LDFLAGS) $(mkntfs_OBJECTS) $(mkntfs_LDADD) $(LIBS)
+
+ntfslabel$(EXEEXT): $(ntfslabel_OBJECTS) $(ntfslabel_DEPENDENCIES)
+ @rm -f ntfslabel$(EXEEXT)
+ $(LINK) $(ntfslabel_LDFLAGS) $(ntfslabel_OBJECTS) $(ntfslabel_LDADD) $(LIBS)
install-man8:
Index: ntfslabel.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/ntfslabel.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -U2 -r1.1 -r1.2
--- ntfslabel.c 11 Apr 2002 23:11:00 -0000 1.1
+++ ntfslabel.c 12 Apr 2002 15:23:48 -0000 1.2
@@ -1,16 +1,20 @@
/*
- * ntfslabel.c - Change the label on an NTFS partition
+ * $Id$
+ *
+ * ntfslabel - Part of the Linux-NTFS project.
*
- * Copyright (c) 2002 Matthew J. Fanto <fan...@cm...>
- *
+ * Copyright (c) 2002 Matthew J. Fanto
+ * Copyright (c) 2002 Anton Altaparmakov
+ *
+ * This utility will display/change the label on an NTFS partition.
*
- * This program/include file is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
- * This program/include file is distributed in the hope that it will be
- * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
@@ -21,4 +25,5 @@
*/
+#include "config.h"
#include <stdio.h>
@@ -32,86 +37,49 @@
#include "volume.h"
+#define NTFS_MF_MOUNTED 1
-#define NTFS_MF_MOUNTED 1
-
-
-const char *EXEC_NAME = "ntfslabel";
-const char *AUTHOR = "Matthew Fanto";
-const char *VERSION = "1.0";
+const char *EXEC_NAME = "ntfslabel";
+const char *AUTHOR = "Matthew Fanto";
ntfs_volume *vol;
-void parse_options(int argc, char *argv[]);
-void change_label(const char *device);
-int check_mntent(const char *file);
-void display_syntax();
-void display_label(const char *device);
-
-int main(int argc, char **argv)
-{
- if(argc && *argv)
- fprintf(stderr, "%s v%s - %s\n",EXEC_NAME,VERSION,AUTHOR);
-
- parse_options(argc, argv);
-}
-
-
-void parse_options(int argc, char *argv[])
-{
- int c;
-
- if(argc < 2)
- display_syntax();
-
-
- while((c = getopt(argc, argv, "p:c:h")) != EOF)
- switch(c){
- case 'p':
- display_label(optarg);
- break;
- case 'c':
- change_label(optarg);
- break;
- case 'h':
- display_syntax();
- }
-}
-
+void change_label(const char *dev, const char *label);
-
-void display_syntax()
+void print_label(const char *dev)
{
- printf("Syntax: ntfslabel [options] device\n\n "
- " -p, print the current label\n "
- " -c, change the current label\n");
+ vol = ntfs_mount(dev, MS_RDONLY);
+ if (!vol) {
+ perror("ntfs_mount() failed");
+ exit(1);
+ }
+ printf("%s\n", vol->vol_name);
+ ntfs_umount(vol, 0);
}
-
-
-
-void display_label(const char *device)
+int main(int argc, char **argv)
{
- vol = ntfs_mount(device,0);
- if(!vol)
- {
- printf("Error: ntfs_mount() failed!");
- exit(1);
- }
- printf("Volume Label: %s\n",vol->vol_name);
+ if (argc && *argv)
+ EXEC_NAME = *argv;
+ if (argc == 2)
+ print_label(argv[1]);
+ else if (argc == 3)
+ change_label(argv[1], argv[2]);
+ else {
+ fprintf(stderr, "%s v%s - %s\n", EXEC_NAME, VERSION, AUTHOR);
+ fprintf(stderr, "Usage: ntfslabel device [newlabel]\n");
+ exit(1);
+ }
+ return 0;
}
+
+int check_mount(const char *file);
-
-void change_label(const char *device)
+void change_label(const char *dev, const char *label)
{
- printf("now changing label\n");
- /*First we need to make sure the device is not mounted*/
- check_mount(device);
-
+ printf("now changing label - FIXME: Not implemented yet!\n");
+ /*First we need to make sure the device is not mounted*/
+ check_mount(dev);
}
-
-
-
-
/* Only check if the mount is readonly when it's the root filesystem. */
int check_mntent(const char *file)
@@ -121,34 +89,34 @@
int m_fd;
- if ((m_f = setmntent(MOUNTED, "r")) == NULL)
- return -errno;
- while ((mnt = getmntent(m_f)) != NULL)
- if (strcmp(file, mnt->mnt_fsname) == 0)
- break;
- endmntent(m_f);
- if (mnt == 0)
- return 0;
-
- else
- return NTFS_MF_MOUNTED;
-
- }
+ if (!(m_f = setmntent(MOUNTED, "r")))
+ return -errno;
+ while ((mnt = getmntent(m_f)))
+ if (!strcmp(file, mnt->mnt_fsname))
+ break;
+ endmntent(m_f);
+ if (!mnt)
+ return 0;
+ else
+ return NTFS_MF_MOUNTED;
+
+}
-int check_mount(const char *device)
+int check_mount(const char *dev)
{
- int r;
+ int r;
struct stat sbuf;
- /*First verify we are dealing with a valid block device.*/
- if(stat(device,&sbuf)==-1)
- {
- fprintf(stderr,"Error: device %s is not a valid block device.\n",device);
- exit(1);
- }
-
- if(r = check_mntent(device))
- {
- printf("Error: device %s is currently mounted.\n",device);
- exit(1);
- }
-
+
+ /* First verify we are dealing with a valid block device. */
+ if (stat(dev, &sbuf) == -1) {
+ fprintf(stderr, "Error: device %s is not a valid block "
+ "device.\n", dev);
+ exit(1);
+ }
+
+ if (r = check_mntent(dev)) {
+ printf("Error: device %s is currently mounted.\n", dev);
+ exit(1);
+ }
+
}
+
|