Changes by: antona
Update of /cvsroot/linux-ntfs/linux-ntfs/ntfstools
In directory usw-pr-cvs1:/tmp/cvs-serv8638/ntfstools
Modified Files:
Makefile.in mkntfs.8.in mkntfs.c
Log Message:
Linux-NTFS 1.0.0-pre-1 - FEATURE FREEZE
=======================================
mkntfs complete with option parsing and more cool things.
mkntfs man page complete.
info files updated.
TODO Before 1.0.0 final:
- Test mkntfs options & mkntfs itself.
- Test tar ball generation.
- Test rpm generation.
Index: Makefile.in
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/Makefile.in,v
retrieving revision 1.6
retrieving revision 1.7
diff -U2 -r1.6 -r1.7
--- Makefile.in 2001/06/10 18:30:17 1.6
+++ Makefile.in 2001/06/11 04:02:09 1.7
@@ -1,3 +1,3 @@
-# Makefile.in generated automatically by automake 1.4-p1 from Makefile.am
+# Makefile.in generated automatically by automake 1.4-p2 from Makefile.am
# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc.
Index: mkntfs.8.in
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/mkntfs.8.in,v
retrieving revision 1.1
retrieving revision 1.2
diff -U2 -r1.1 -r1.2
--- mkntfs.8.in 2001/06/10 18:30:17 1.1
+++ mkntfs.8.in 2001/06/11 04:02:09 1.2
@@ -10,27 +10,23 @@
.B mkntfs
[
-.B \-c
-|
-.\" .B \-t
-.\" .I test
-.\" |
-.B \-l
-.I filename
+.B \-s
+.I sector-size
]
[
-.B \-b
-.I block-size
+.B \-c
+.I cluster-size
]
[
-.B \-f
-.I fragment-size
+.B \-L
+.I volume-label
]
[
-.B \-i
-.I bytes-per-inode
+.B \-z
+.I mft-zone-multiplier
]
[
-.B \-N
-.I number-of-inodes
+.B \-f
+|
+.B \-Q
]
[
@@ -38,57 +34,20 @@
]
[
-.B \-m
-.I reserved-blocks-percentage
-]
-[
-.B \-o
-.I creator-os
-]
-[
-.B \-O
-.IR feature [,...]
-]
-[
.B \-q
]
[
-.B \-r
-.I fs-revision-level
-]
-[
-.B \-R
-.I raid_options
-]
-[
-.B \-s
-.I sparse-super-flag
-]
+.B \-v
[
.B \-v
-]
+]]
[
.B \-F
]
[
-.B \-L
-.I volume-label
-]
-[
-.B \-M
-.I last-mounted-directory
-]
-[
-.B \-S
-]
-[
-.B \-T
-.I filesystem-type
-]
-[
.B \-V
]
.I device
[
-.I blocks-count
+.I number-of-sectors
]
.SH DESCRIPTION
@@ -99,5 +58,5 @@
is the special file corresponding to the device (e.g
.IR /dev/hdXX ).
-.I blocks-count
+.I number-of-sectors
is the number of blocks on the device. If omitted,
.B mkntfs
@@ -105,141 +64,97 @@
.SH OPTIONS
.TP
-.BI \-b " block-size"
-Specify the size of blocks in bytes. Valid block size vales are 1024,
-2048 and 4096 bytes per block. If omitted,
-.B mkntfs
-block-size is determined by the file system size and the expected usage
-of the filesystem (see the
-.B \-T
-option).
+.BI \-s " sector-size"
+Specify the size of sectors in bytes. Valid sector size values are 256, 512,
+1024, 2048 and 4096 bytes per sector. If omitted,
+.B mkntfs
+.I sector-size
+is determined automatically and if that fails a default of 512
+bytes per sector is used.
+.TP
+.BI \-c " cluster-size"
+Specify the size of clusters in bytes. Valid cluster size values are powers of
+two, with at least 256, and at most 65536 bytes per cluster. If omitted,
+.B mkntfs
+.I cluster-size
+is determined by the volume size. The value is determined as
+follows:
+.br
+.B \tVolume size\tDefault cluster size (in bytes)
+.br
+ \<= 512MB 512
+.br
+ \]512MB-1GB\] 1024
+.br
+ \]1GB-2GB\] 2048
+.br
+ \> 2GB 4096
+.br
+Note that values greater than 4096 have the side effect that compression is
+disabled on the volume (due to limitations in the NTFS compression algorithm
+currently in use by Windows).
.TP
-.B \-c
-Check the device for bad blocks before creating the file system, using a
-fast read-only test.
+.BI \-L " volume-label"
+Set the volume label for the filesystem.
+.TP
+.BI \-z " mft-zone-multiplier"
+Set the MFT zone multiplier, which determines the size of the MFT zone to use
+on the volume. The MFT zone is the area at the beginning of the volume reserved
+for the master file table (MFT), which stores the on disk inodes (MFT records).
+It is noteworthy that small files are stored entirely within the inode;
+thus, if you expect to use the volume for storing large numbers of very small
+files, it is useful to set the zone multiplier to a higher value. Note, that
+the MFT zone is resized on the fly as required during operation of the NTFS
+driver but choosing a good value will reduce fragmentation. Valid values
+are 1, 2, 3 and 4. The values have the following meaning:
+.br
+.B \tMFT zone\t\tMFT zone size
+.br
+.B \tmultiplier\t(in % of volume size)
+.br
+ 1 12.5% (default)
+.br
+ 2 25%
+.br
+ 3 37.5%
+.br
+ 4 50%
.TP
-.BI \-f " fragment-size"
-Specify the size of fragments in bytes.
+.B \-f
+Same as
+.BR \-Q .
.TP
-.BI \-i " bytes-per-inode"
-Specify the bytes/inode ratio.
-.B mkntfs
-creates an inode for every
-.I bytes-per-inode
-bytes of space on the disk.
-The larger the
-.I bytes-per-inode
-ratio, the fewer inodes will be created.
-This value generally shouldn't be smaller than
-the blocksize of the filesystem, since then too many inodes will be made.
-Be warned that is not possible to expand the number of inodes on a
-filesystem after it is created, so be careful decided the correct
-value for this parameter.
+.B \-Q
+Perform quick format. This will skip both zeroing of the volume and bad sector
+checking.
.TP
.B \-n
-causes mkntfs to not actually create a filesystem, but display what it
-would do if it were to create a filesystem.
-.TP
-.BI \-N " number-of-inodes"
-overrides the default calculation of the number of inodes that should be
-reserved for the filesystem (which is based on the number of blocks and
-the
-.I bytes-per-inode
-ratio). This allows the user to specify the number
-of desired inodes directly.
-.TP
-.BI \-O " feature\fR[,...]"
-Create the filesystem with the listed set of features
-(filesystem options). The following features are supported:
-.IR sparse_super ,
-which cause the filesystem to use sparse superblocks, and
-.IR filetype ,
-which will cause the filesystem to store file type information in
-directory entries. Currently, both features are turned on by default
-unless
-.B mkntfs
-is run on a system with a pre-2.2 Linux kernel.
-.B Warning:
-Pre-2.2 Linux kernels do not properly
-support the filesystems that use either of these two features. Filesystems
-that may need to mounted on pre-2.2 kernels should be created with
-.B -O
-.I none
-which will disable both of these features, even if
-.B mkntfs
-is run on a system which can support these features.
-.TP
-.BI \-l " filename"
-Read the bad blocks list from
-.I filename.
-\.
-.TP
-.BI -m " reserved-blocks-percentage"
-Specify the percentage of reserved blocks for the super-user. This value
-defaults to 5%.
-.\" .TP
-.\" .BI \-t " test"
-.\" Check the device for bad blocks before creating the file system
-.\" using the specified test.
-.TP
-.B \-o
-Manually override the default value of the "creator os" field of the
-filesystem. Normally the creator field is set by default to the native OS
-of the
+Causes
.B mkntfs
-executable.
+to not actually create a filesystem, but display what it would do if it were
+to create a filesystem. All steps of the format are carried out except the
+actual writing to the device.
.TP
.B \-q
-Quiet execution. Useful if
+Quiet execution; only errors are written to stderr, no output to stdout
+occurs at all. Useful if
.B mkntfs
is run in a script.
.TP
-.BI \-s " sparse-super-flag"
-If
-.I sparse-super-flag
-is 1, then turn on the sparse superblock flag in the superblock.
-.B Note:
-This option is deprecated; use the
-.B \-O
-option instead.
-.TP
.B \-v
Verbose execution.
.TP
+.B \-vv
+Really verbose execution; includes the verbose output from the
+.B \-v
+option as well as additional output useful for debugging
+.B mkntfs.
+.TP
.B \-F
Force
.B mkntfs
-to run, even if the specified device is not a
-block special device, or appears to be mounted.
-.TP
-.B \-L
-Set the volume label for the filesystem.
-.TP
-.B \-M
-Set the last mounted directory for the filesystem. This might be useful
-for the sake of utilities that key off of the last mounted directory to
-determine where the filesytem should be mounted.
-.TP
-.BI -r " revision"
-Set the filesystem revision for the new filesystem. Note that 1.2
-kernels only support revision 0 filesystems.
-.TP
-.BI \-R " raid_options"
-Set raid-related options for the filesystem. Raid options are comma
-separated, and may take an argument using the equals ('=') sign.
-Currently the only supported argument is
-.I stride
-which takes as its argument the number of blocks in a RAID stripe.
-.TP
-.B \-S
-Write superblock and group descriptors only. This is useful if all of
-the superblock and backup superblocks are corrupted, and a last-ditch
-recovery method is desired. It causes
-.B mkntfs
-to reinitialize the
-superblock and group descriptors, while not touching the inode table
-and the block and inode bitmaps. The
-.B e2fsck
-program should be run immediately after this option is used, and there
-is no guarantee that any data will be salvageable.
+to run, even if the specified
+.I device
+is not a block special device, or
+appears to be mounted.
.TP
.B \-V
@@ -250,23 +165,28 @@
This version of
.B mkntfs
-has been written by Anton Altaparmakov <ai...@ca...> or if that fails
-<an...@us...>.
+has been written by Anton Altaparmakov <ai...@ca...> (if that fails, use
+<an...@us...>).
.SH BUGS
.B mkntfs
-writes the backup boot sector to the last sector of the block device. However,
-current versions of the Linux kernel (all versions up to today's 2.4.5) only
-report an even number of sectors when the sector size is below 1024 bytes,
+writes the backup boot sector to the last sector of the block
+.I device
+\. However, current versions of the Linux kernel (all versions up to and
+including todays 2.4.5) only report an even number of sectors when the sector
+size is below 1024 bytes,
which is the case for most hard drives today (512 bytes sector size). This
means that when a partition has an odd number of 512-byte sectors, the last
sector is not reported to us and hence the created NTFS volume will have the
backup boot sector placed one sector ahead of where it should be. For this
-reason, mkntfs marks the NTFS volume dirty so that when you reboot into
-Windows, check disk runs automatically and creates a copy of the backup boot
-sector in the correct location. This also has the benefit of catching any bugs
-in mkntfs as check disk would find any corrupt on disk structures and repair
-them as well as report them. - If you do see any problems reported, please
-report the messages to the author (see below). Thank you.
+reason,
+.B mkntfs
+marks the NTFS volume dirty, so that when you reboot into Windows, checkdisk
+runs automatically and creates a copy of the backup boot sector in the correct
+location. This also has the benefit of catching any bugs in
+.B mkntfs
+as checkdisk would find any corrupt structures and repair them, as well as
+report them. - If you do see any problems reported, please report the messages
+to the author.
.br
-There may be others. Please, report them to the author.
+There may be other bugs. Please, report them to the author.
.SH AVAILABILITY
.B mkntfs
Index: mkntfs.c
===================================================================
RCS file: /cvsroot/linux-ntfs/linux-ntfs/ntfstools/mkntfs.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -U2 -r1.22 -r1.23
--- mkntfs.c 2001/06/10 15:54:20 1.22
+++ mkntfs.c 2001/06/11 04:02:09 1.23
@@ -6,6 +6,11 @@
* Copyright (c) 2000,2001 Anton Altaparmakov.
*
- * This utility will create an NTFS volume on a user specified block device.
+ * This utility will create an NTFS 1.2 (Windows NT 4.0) volume on a user
+ * specified (block) device.
*
+ * Some things (option handling and determination of mount status) have been
+ * adapted from e2fsprogs-1.19 and lib/ext2fs/ismounted.c and misc/mke2fs.c in
+ * particular.
+ *
* Anton Altaparmakov <ai...@ca...>
*
@@ -41,14 +46,49 @@
*/
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/stat.h>
+#include "config.h"
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+#ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+#endif
+#ifdef HAVE_STDIO_H
+# include <stdio.h>
+#endif
+#ifdef HAVE_STDARG_H
+# include <stdarg.h>
+#endif
+#ifdef HAVE_STRING_H
+# include <string.h>
+#endif
+#ifdef HAVE_ERRNO_H
+# include <errno.h>
+#endif
#include <fcntl.h>
#include <sys/ioctl.h>
#include <time.h>
+#ifdef HAVE_GETOPT_H
+# include <getopt.h>
+#else
+ extern char *optarg;
+ extern int optind;
+#endif
+#include <sys/stat.h>
+#ifdef HAVE_LINUX_MAJOR_H
+# include <linux/major.h>
+#endif
+#ifndef MAJOR
+# define MAJOR(dev) ((dev) >> 8)
+# define MINOR(dev) ((dev) & 0xff)
+#endif
+#ifndef SCSI_BLK_MAJOR
+# define SCSI_BLK_MAJOR(m) ((m) == SCSI_DISK_MAJOR || \
+ (m) == SCSI_CDROM_MAJOR)
+#endif
+#ifdef HAVE_MNTENT_H
+# include <mntent.h>
+#endif
+#include <limits.h>
#include "types.h"
@@ -71,4 +111,6 @@
#define NTFS_PAGE_SIZE 4096
+const char *EXEC_NAME = "mkntfs";
+
/* Need these global so mkntfs_exit can access them. */
int f;
@@ -91,12 +133,12 @@
int sector_size; /* -s, in bytes, power of 2, default is
512 bytes. */
- long long nr_sectors; /* -ns, size of device in sectors */
+ long long nr_sectors; /* size of device in sectors */
int cluster_size; /* -c, in bytes, 512*1024 max,
power of 2, if not specified
determined by volume size. Minimum
is 512bytes, maximum is 64kB. */
- long long nr_clusters; /* -nc, Note: Win2k treats clusters as
+ long long nr_clusters; /* Note: Win2k treats clusters as
32-bit entities! */
- long long volume_size; /* -vs, in bytes, or suffixed
+ long long volume_size; /* in bytes, or suffixed
with k for kB, m or M for MB, or
g or G for GB, or t or T for TB */
@@ -104,30 +146,32 @@
int index_block_size; /* in bytes. */
int mft_size; /* The smaller of 16kB & one cluster. */
- long long mft_lcn; /* -ml, lcn of $MFT, $DATA attribute. */
- long long mftmirr_lcn; /* -mml, lcn of $MFTMirr, $DATA. */
- long long logfile_lcn; /* -ll, lcn of $LogFile, $DATA. */
- int logfile_size; /* -ls, in bytes, determined from
+ long long mft_lcn; /* lcn of $MFT, $DATA attribute. */
+ long long mftmirr_lcn; /* lcn of $MFTMirr, $DATA. */
+ long long logfile_lcn; /* lcn of $LogFile, $DATA. */
+ int logfile_size; /* in bytes, determined from
volume_size. */
- char mft_zone_multiplier; /* Value from 1 to 4. Default is 1. */
- long long mft_zone_end; /* -z, determined from volume_size and
+ char mft_zone_multiplier; /* -z, value from 1 to 4. Default is
+ 1. */
+ long long mft_zone_end; /* Determined from volume_size and
mft_zone_multiplier, in clusters. */
char no_action; /* -n, do not write to device, only
display what would be done. */
- char check_bad_blocks; /* -c, read-only test for bad
+ char check_bad_blocks; /* read-only test for bad
clusters. */
long long *bad_blocks; /* Array of bad clusters. */
long long nr_bad_blocks; /* Number of bad clusters. */
- char *bad_blocks_filename; /* -l filename, file to read list of
+ char *bad_blocks_filename; /* filename, file to read list of
bad clusters from. */
- ATTR_DEF *attr_defs; /* -a filename, attribute defs. */
+ ATTR_DEF *attr_defs; /* filename, attribute defs. */
int attr_defs_len; /* in bytes */
- uchar_t *upcase; /* -u filename, upcase table. */
+ uchar_t *upcase; /* filename, upcase table. */
__u32 upcase_len; /* Determined automatically. */
char quiet; /* -q, quiet execution. */
- char verbose; /* -v, verbose execution, -vv really
- * verbose execution (debug mode). */
+ char verbose; /* -v, verbose execution, given twice,
+ * really verbose execution (debug
+ * mode). */
char force; /* -F, force fs creation. */
char *volume_label; /* -L, set the volume label. */
- union { /* -r, revision of ntfs, 1.2 or 3.0 */
+ union { /* revision of ntfs, 1.2 or 3.0 */
unsigned short ntfs_version;
struct {
@@ -136,8 +180,7 @@
};
};
- char version_only; /* -V, print the version number and
- exit */
- char quick_format; /* -f, fast format, don't zero the
- volume first. */
+ char quick_format; /* -f or -Q, fast format, don't zero
+ the volume first. */
+ /* -V, print version and exit. */
} opt;
@@ -2312,8 +2355,71 @@
}
-void init_options(void)
+#define NTFS_MF_MOUNTED 1
+#define NTFS_MF_ISROOT 2
+#define NTFS_MF_READONLY 4
+
+#ifdef HAVE_MNTENT_H
+/* Only check if the mount is readonly when it's the root filesystem. */
+int check_mntent(const char *file, int *mnt_flags)
+{
+ FILE *m_f;
+ struct mntent *mnt;
+ int m_fd;
+
+ *mnt_flags = 0;
+ 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;
+ *mnt_flags = NTFS_MF_MOUNTED;
+ if (!strcmp(mnt->mnt_dir, "/")) {
+ *mnt_flags |= NTFS_MF_ISROOT;
+ m_fd = open(MOUNTED, O_RDWR);
+ if (m_fd < 0) {
+ if (errno == EROFS)
+ *mnt_flags |= NTFS_MF_READONLY;
+ } else
+ close(m_fd);
+ }
+ return 0;
+}
+#endif
+
+/* Return 0 on success or -errno on error. */
+int ntfs_check_if_mounted(const char *file, int *mnt_flags)
+{
+#ifdef HAVE_MNTENT_H
+ return check_mntent(file, mnt_flags);
+#else
+ *mnt_flags = 0;
+ return 0;
+#endif
+}
+
+void check_mount(void)
{
+ int r, mnt_flags;
+
+ r = ntfs_check_if_mounted(opt.dev_name, &mnt_flags);
+ if (r) {
+ Eprintf("Failed to determine whether %s is mounted: %s\n",
+ opt.dev_name, strerror(-r));
+ return;
+ }
+ if (!(mnt_flags & NTFS_MF_MOUNTED))
+ return;
+ Eprintf("%s is mounted.\n", opt.dev_name);
+ if (!opt.force)
+ err_exit("Refusing to make a filesystem here!\n");
+ fprintf(stderr, "mkntfs forced anyway. Hope /etc/mtab is incorrect.\n");
+}
+
+void init_options()
+{
memset(&opt, 0, sizeof(opt));
- opt.verbose = 2;
opt.ntfs_major_ver = 1;
opt.ntfs_minor_ver = 2;
@@ -2322,6 +2428,6 @@
opt.attr_defs = (ATTR_DEF*)&attrdef_ntfs12_array;
opt.attr_defs_len = sizeof(attrdef_ntfs12_array);
- Dprintf("Attr_defs table length = %u\n", opt.attr_defs_len);
- /* Length is in characters. */
+ //Dprintf("Attr_defs table length = %u\n", opt.attr_defs_len);
+ /* Length is in unicode characters. */
opt.upcase_len = 65536;
opt.upcase = (uchar_t*)malloc(opt.upcase_len * sizeof(uchar_t));
@@ -2329,7 +2435,97 @@
err_exit("Could not allocate memory for internal buffer.\n");
init_upcase_table(opt.upcase, opt.upcase_len * sizeof(uchar_t));
- opt.volume_label = NULL;
}
+void usage(void) __attribute__ ((noreturn));
+
+void usage(void)
+{
+ fprintf(stderr, "Copyright (c) 2001 Anton Altaparmakov.\n"
+ "Create an NTFS volume on a user specified (block) device.\n"
+ "%s is free software, released under the GNU General Public "
+ "License\nand you are welcome to redistribute it under "
+ "certain conditions.\n%s comes with ABSOLUTELY NO WARRANTY; "
+ "for details read the GNU\nGeneral Public License to be found "
+ "in the file COPYING in the main\nLinux-NTFS distribution "
+ "directory.\nUsage: %s [-s sector-size] [-c cluster-size] "
+ "[-L volume-label]\n\t[-z mft-zone-multiplier] "
+ "[-fnqvvFQV] device [numer-of-sectors]\n",
+ EXEC_NAME, EXEC_NAME, EXEC_NAME);
+ exit(1);
+}
+
+void parse_options(int argc, char *argv[])
+{
+ int c;
+ long l;
+ unsigned long u;
+ char *s;
+
+// Need to have: mft record size, index record size, ntfs version, mft size,
+// logfile size, list of bad blocks, check for bad blocks, ...
+ if (argc && *argv)
+ EXEC_NAME = *argv;
+ fprintf(stderr, "%s v%s\n", EXEC_NAME, EXEC_VERSION);
+ while ((c = getopt(argc, argv, "c:nqs:vz:L:V")) != EOF)
+ switch (c) {
+ case 'n':
+ opt.no_action = 1;
+ break;
+ case 'c':
+ l = strtol(optarg, &s, 0);
+ if (!l || l > INT_MAX || *s)
+ err_exit("Invalid cluster size.\n");
+ opt.cluster_size = l;
+ break;
+ case 'f':
+ case 'Q':
+ opt.quick_format = 1;
+ break;
+ case 'q':
+ opt.quiet = 1;
+ break;
+ case 's':
+ l = strtol(optarg, &s, 0);
+ if (!l || l > INT_MAX || *s)
+ err_exit("Invalid sector size.\n");
+ opt.sector_size = l;
+ break;
+ case 'v':
+ opt.verbose++;
+ break;
+ case 'z':
+ l = strtol(optarg, &s, 0);
+ if (l < 1 || l > 4 || *s)
+ err_exit("Invalid MFT zone multiplier.\n");
+ opt.mft_zone_multiplier = l;
+ break;
+ case 'F':
+ opt.force = 1;
+ break;
+ case 'L':
+ opt.volume_label = optarg;
+ break;
+ case 'V':
+ /* Print version number and exit. */
+ printf("\tUsing Linux-NTFS Library version %s\n",
+ VERSION);
+ exit(0);
+ default:
+ usage();
+ }
+ if (optind == argc)
+ usage();
+ opt.dev_name = argv[optind++];
+ if (optind < argc) {
+ u = strtoul(argv[optind++], &s, 0);
+ if (*s || !u || (u >= ULONG_MAX && errno == ERANGE))
+ err_exit("Invalid number of sectors: %s\n",
+ argv[optind - 1]);
+ opt.nr_sectors = u;
+ }
+ if (optind < argc)
+ usage();
+}
+
void mkntfs_exit(void)
{
@@ -2387,5 +2583,4 @@
int main(int argc, char **argv)
{
- const char *EXEC_NAME = "mkNtfs";
const char *OK="OK";
const char *FAILED = "FAILED";
@@ -2404,38 +2599,40 @@
EXEC_VERSION = EXEC_REVISION + 11;
EXEC_VERSION[strlen(EXEC_VERSION) - 2] = '\0';
- printf("\n");
- if (argc < 2) {
- printf("%s v%s - Create an NTFS volume on a user specified "
- "block device.\n\n"
- /* Generic copyright / disclaimer. */
- "Copyright (c) 2001 Anton Altaparmakov.\n\n"
- "%s is free software, released under the GNU "
- "General Public License\nand you are welcome to "
- "redistribute it under certain conditions.\n"
- "%s comes with ABSOLUTELY NO WARRANTY; for details "
- "read the GNU\nGeneral Public License to be found "
- "in the file COPYING in the main Linux-NTFS\n"
- "distribution directory.\n\n"
- /* Generic part ends here. */
- "Syntax: mkntfs block_device\n"
- " e.g. mkntfs /dev/hda6\n\n",
- EXEC_NAME, EXEC_VERSION, EXEC_NAME, EXEC_NAME);
- err_exit("Error: incorrect syntax\n");
- }
+ /* Initialize the random number generator with the current time. */
srandom(time(NULL));
+ /* Initialize opt to zero / required values. */
init_options();
-// parse_options(&opt);
- opt.dev_name = argv[argc - 1]; /* Last parameter is the device. */
-// Parse command line options.
-// Need to have: block size, device size / number of blocks to use, cluster
-// size, mft record size, index record size, ntfs version, mft
-// size, logfile size, volume label, list of bad blocks, quick-
-// format, verbose, check for bad blocks, ...
+ /* Parse command line options. */
+ parse_options(argc, argv);
/* Verify we are dealing with a block device. */
- if (stat(opt.dev_name, &sbuf))
+ if (stat(opt.dev_name, &sbuf) == -1) {
+ if (errno == ENOENT)
+ err_exit("The device doesn't exist; did you specify "
+ "it correctly?\n");
err_exit("Error getting information about %s: %s\n",
opt.dev_name, strerror(errno));
- if (!S_ISBLK(sbuf.st_mode))
- err_exit("Error: %s is not a block device.\n", opt.dev_name);
+ }
+ if (!S_ISBLK(sbuf.st_mode)) {
+ Eprintf("%s is not a block device.\n", opt.dev_name);
+ if (!opt.force)
+ err_exit("Refusing to make a filesystem here!\n");
+ if (!opt.nr_sectors)
+ err_exit("You must specify the number of sectors if "
+ "you want to force creation on non-"
+ "block device.\n");
+ fprintf(stderr, "mkntfs forced anyway.\n");
+ }
+#ifdef HAVE_LINUX_MAJOR_H
+ else if ((MAJOR(sbuf.st_rdev) == HD_MAJOR &&
+ MINOR(sbuf.st_rdev) % 64 == 0) ||
+ (SCSI_BLK_MAJOR(MAJOR(sbuf.st_rdev)) &&
+ MINOR(sbuf.st_rdev) % 16 == 0)) {
+ err_exit("%s is entire device, not just one partition!\n",
+ opt.dev_name);
+ }
+#endif
+ /* Make sure the file system is not mounted. */
+ check_mount();
+ /* Open the device for reading or reading and writing. */
if (opt.no_action) {
Qprintf("Running in READ-ONLY mode!");
@@ -2443,5 +2640,4 @@
} else
i = O_RDWR;
- /* Open the device for reading or reading and writing. */
f = open(opt.dev_name, i);
if (f == -1)
|