1994-05-26 06:35:07 +00:00
|
|
|
/*
|
2002-06-21 06:18:05 +00:00
|
|
|
* Copyright (c) 2002 Networks Associates Technology, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This software was developed for the FreeBSD Project by Marshall
|
|
|
|
* Kirk McKusick and Network Associates Laboratories, the Security
|
|
|
|
* Research Division of Network Associates, Inc. under DARPA/SPAWAR
|
|
|
|
* contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS
|
2003-02-14 21:08:14 +00:00
|
|
|
* research program.
|
2002-06-21 06:18:05 +00:00
|
|
|
*
|
1994-05-26 06:35:07 +00:00
|
|
|
* Copyright (c) 1983, 1989, 1993, 1994
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-05-03 18:41:59 +00:00
|
|
|
#if 0
|
1994-05-26 06:35:07 +00:00
|
|
|
#ifndef lint
|
1998-07-15 06:28:05 +00:00
|
|
|
static const char copyright[] =
|
|
|
|
"@(#) Copyright (c) 1983, 1989, 1993, 1994\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n";
|
1994-05-26 06:35:07 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1998-07-15 06:28:05 +00:00
|
|
|
static char sccsid[] = "@(#)newfs.c 8.13 (Berkeley) 5/1/95";
|
1994-05-26 06:35:07 +00:00
|
|
|
#endif /* not lint */
|
2003-05-03 18:41:59 +00:00
|
|
|
#endif
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* newfs: friendly front end to mkfs
|
|
|
|
*/
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/stat.h>
|
2002-04-24 11:44:02 +00:00
|
|
|
#include <sys/disk.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
|
1998-07-16 12:04:52 +00:00
|
|
|
#include <ufs/ufs/dir.h>
|
|
|
|
#include <ufs/ufs/dinode.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <ufs/ffs/fs.h>
|
1997-03-11 12:48:17 +00:00
|
|
|
#include <ufs/ufs/ufsmount.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
#include <ctype.h>
|
1998-07-15 06:28:05 +00:00
|
|
|
#include <err.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <errno.h>
|
2004-09-19 10:01:51 +00:00
|
|
|
#include <inttypes.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <paths.h>
|
2002-04-04 09:56:51 +00:00
|
|
|
#include <stdarg.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2010-03-03 19:25:28 +00:00
|
|
|
#include <libutil.h>
|
|
|
|
|
2002-03-19 20:01:38 +00:00
|
|
|
#include "newfs.h"
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2007-12-16 19:41:31 +00:00
|
|
|
int Eflag; /* Erase previous disk contents */
|
2003-02-01 04:17:10 +00:00
|
|
|
int Lflag; /* add a volume label */
|
2002-08-21 18:11:48 +00:00
|
|
|
int Nflag; /* run without writing file system */
|
2003-04-20 14:08:05 +00:00
|
|
|
int Oflag = 2; /* file system format (1 => UFS1, 2 => UFS2) */
|
2002-03-19 21:05:29 +00:00
|
|
|
int Rflag; /* regression test */
|
2002-08-21 18:11:48 +00:00
|
|
|
int Uflag; /* enable soft updates for file system */
|
2007-12-16 19:41:31 +00:00
|
|
|
int Xflag = 0; /* exit in middle of newfs for testing */
|
2006-10-31 21:52:28 +00:00
|
|
|
int Jflag; /* enable gjournal for file system */
|
2004-02-26 01:14:27 +00:00
|
|
|
int lflag; /* enable multilabel for file system */
|
2005-01-21 22:20:25 +00:00
|
|
|
int nflag; /* do not create .snap directory */
|
2010-12-29 12:31:18 +00:00
|
|
|
int tflag; /* enable TRIM */
|
2007-11-28 07:29:10 +00:00
|
|
|
intmax_t fssize; /* file system size */
|
2010-03-09 10:31:03 +00:00
|
|
|
int sectorsize; /* bytes/sector */
|
1994-05-26 06:35:07 +00:00
|
|
|
int realsectorsize; /* bytes/sector in hardware */
|
2010-03-09 19:31:08 +00:00
|
|
|
int fsize = 0; /* fragment size */
|
|
|
|
int bsize = 0; /* block size */
|
|
|
|
int maxbsize = 0; /* maximum clustering */
|
|
|
|
int maxblkspercg = MAXBLKSPERCG; /* maximum blocks per cylinder group */
|
1994-05-26 06:35:07 +00:00
|
|
|
int minfree = MINFREE; /* free space threshold */
|
|
|
|
int opt = DEFAULTOPT; /* optimization preference (space or time) */
|
2010-03-09 19:31:08 +00:00
|
|
|
int density; /* number of bytes per inode */
|
|
|
|
int maxcontig = 0; /* max contiguous blocks to allocate */
|
|
|
|
int maxbpg; /* maximum blocks per file in a cyl group */
|
|
|
|
int avgfilesize = AVFILESIZ;/* expected average file size */
|
|
|
|
int avgfilesperdir = AFPDIR;/* expected number of files per directory */
|
2003-02-01 04:17:10 +00:00
|
|
|
u_char *volumelabel = NULL; /* volume label for filesystem */
|
2003-02-11 03:06:45 +00:00
|
|
|
struct uufsd disk; /* libufs disk structure */
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2002-03-20 07:16:15 +00:00
|
|
|
static char device[MAXPATHLEN];
|
Enable operation of newfs on plain files, which is useful when you
want to prepare disk images for emulators (though 'makefs' in port
can do something similar).
This relies on:
+ minor changes to pass the consistency checks even when working on a file;
+ an additional option, '-p partition' , to specify the disk partition to
initialize;
+ some changes on the I/O routines to deal with partition offsets.
The latter was a bit tricky to implement, see the details in newfs.h:
in newfs, I/O is done through libufs which assumes that the file
descriptor refers to the whole partition. Introducing support for
the offset in libufs would require a non-backward compatible change
in the library, to be dealt with a version bump or with symbol
versioning.
I felt both approaches to be overkill for this specific application,
especially because there might be other changes to libufs that might
become necessary in the near future.
So I used the following trick:
- read access is always done by calling bread() directly, so we just add
the offset in the (few) places that call bread();
- write access is done through bwrite() and sbwrite(), which in turn
calls bwrite(). To avoid rewriting sbwrite(), we supply our own version
of bwrite() here, which takes precedence over the version in libufs.
MFC after: 4 weeks
2008-12-03 18:36:59 +00:00
|
|
|
static u_char bootarea[BBSIZE];
|
|
|
|
static int is_file; /* work on a file, not a device */
|
|
|
|
static char *dkname;
|
2002-04-04 09:56:51 +00:00
|
|
|
static char *disktype;
|
|
|
|
static int unlabeled;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2007-11-28 07:29:10 +00:00
|
|
|
static void getfssize(intmax_t *, const char *p, intmax_t, intmax_t);
|
2002-04-24 11:44:02 +00:00
|
|
|
static struct disklabel *getdisklabel(char *s);
|
|
|
|
static void rewritelabel(char *s, struct disklabel *lp);
|
2002-04-04 09:56:51 +00:00
|
|
|
static void usage(void);
|
2010-03-09 10:31:03 +00:00
|
|
|
static int expand_number_int(const char *buf, int *num);
|
1998-07-15 06:28:05 +00:00
|
|
|
|
Enable operation of newfs on plain files, which is useful when you
want to prepare disk images for emulators (though 'makefs' in port
can do something similar).
This relies on:
+ minor changes to pass the consistency checks even when working on a file;
+ an additional option, '-p partition' , to specify the disk partition to
initialize;
+ some changes on the I/O routines to deal with partition offsets.
The latter was a bit tricky to implement, see the details in newfs.h:
in newfs, I/O is done through libufs which assumes that the file
descriptor refers to the whole partition. Introducing support for
the offset in libufs would require a non-backward compatible change
in the library, to be dealt with a version bump or with symbol
versioning.
I felt both approaches to be overkill for this specific application,
especially because there might be other changes to libufs that might
become necessary in the near future.
So I used the following trick:
- read access is always done by calling bread() directly, so we just add
the offset in the (few) places that call bread();
- write access is done through bwrite() and sbwrite(), which in turn
calls bwrite(). To avoid rewriting sbwrite(), we supply our own version
of bwrite() here, which takes precedence over the version in libufs.
MFC after: 4 weeks
2008-12-03 18:36:59 +00:00
|
|
|
ufs2_daddr_t part_ofs; /* partition offset in blocks, used with files */
|
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
int
|
2002-03-19 17:20:02 +00:00
|
|
|
main(int argc, char *argv[])
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
2002-03-17 09:01:41 +00:00
|
|
|
struct partition *pp;
|
|
|
|
struct disklabel *lp;
|
1994-05-26 06:35:07 +00:00
|
|
|
struct partition oldpartition;
|
|
|
|
struct stat st;
|
2002-04-24 11:44:02 +00:00
|
|
|
char *cp, *special;
|
2007-11-28 07:29:10 +00:00
|
|
|
intmax_t reserved;
|
2010-03-03 02:05:09 +00:00
|
|
|
int ch, i, rval;
|
2002-04-24 11:44:02 +00:00
|
|
|
off_t mediasize;
|
Enable operation of newfs on plain files, which is useful when you
want to prepare disk images for emulators (though 'makefs' in port
can do something similar).
This relies on:
+ minor changes to pass the consistency checks even when working on a file;
+ an additional option, '-p partition' , to specify the disk partition to
initialize;
+ some changes on the I/O routines to deal with partition offsets.
The latter was a bit tricky to implement, see the details in newfs.h:
in newfs, I/O is done through libufs which assumes that the file
descriptor refers to the whole partition. Introducing support for
the offset in libufs would require a non-backward compatible change
in the library, to be dealt with a version bump or with symbol
versioning.
I felt both approaches to be overkill for this specific application,
especially because there might be other changes to libufs that might
become necessary in the near future.
So I used the following trick:
- read access is always done by calling bread() directly, so we just add
the offset in the (few) places that call bread();
- write access is done through bwrite() and sbwrite(), which in turn
calls bwrite(). To avoid rewriting sbwrite(), we supply our own version
of bwrite() here, which takes precedence over the version in libufs.
MFC after: 4 weeks
2008-12-03 18:36:59 +00:00
|
|
|
char part_name; /* partition name, default to full disk */
|
1994-05-26 06:35:07 +00:00
|
|
|
|
Enable operation of newfs on plain files, which is useful when you
want to prepare disk images for emulators (though 'makefs' in port
can do something similar).
This relies on:
+ minor changes to pass the consistency checks even when working on a file;
+ an additional option, '-p partition' , to specify the disk partition to
initialize;
+ some changes on the I/O routines to deal with partition offsets.
The latter was a bit tricky to implement, see the details in newfs.h:
in newfs, I/O is done through libufs which assumes that the file
descriptor refers to the whole partition. Introducing support for
the offset in libufs would require a non-backward compatible change
in the library, to be dealt with a version bump or with symbol
versioning.
I felt both approaches to be overkill for this specific application,
especially because there might be other changes to libufs that might
become necessary in the near future.
So I used the following trick:
- read access is always done by calling bread() directly, so we just add
the offset in the (few) places that call bread();
- write access is done through bwrite() and sbwrite(), which in turn
calls bwrite(). To avoid rewriting sbwrite(), we supply our own version
of bwrite() here, which takes precedence over the version in libufs.
MFC after: 4 weeks
2008-12-03 18:36:59 +00:00
|
|
|
part_name = 'c';
|
2007-11-28 07:29:10 +00:00
|
|
|
reserved = 0;
|
2002-03-19 20:01:38 +00:00
|
|
|
while ((ch = getopt(argc, argv,
|
2010-12-29 12:31:18 +00:00
|
|
|
"EJL:NO:RS:T:UXa:b:c:d:e:f:g:h:i:lm:no:p:r:s:t")) != -1)
|
1994-05-26 06:35:07 +00:00
|
|
|
switch (ch) {
|
2003-11-16 07:17:30 +00:00
|
|
|
case 'E':
|
2007-12-16 19:41:31 +00:00
|
|
|
Eflag = 1;
|
2003-11-16 07:17:30 +00:00
|
|
|
break;
|
2006-10-31 21:52:28 +00:00
|
|
|
case 'J':
|
|
|
|
Jflag = 1;
|
|
|
|
break;
|
2003-02-01 04:17:10 +00:00
|
|
|
case 'L':
|
|
|
|
volumelabel = optarg;
|
|
|
|
i = -1;
|
|
|
|
while (isalnum(volumelabel[++i]));
|
|
|
|
if (volumelabel[i] != '\0') {
|
|
|
|
errx(1, "bad volume label. Valid characters are alphanumerics.");
|
|
|
|
}
|
|
|
|
if (strlen(volumelabel) >= MAXVOLLEN) {
|
|
|
|
errx(1, "bad volume label. Length is longer than %d.",
|
|
|
|
MAXVOLLEN);
|
|
|
|
}
|
|
|
|
Lflag = 1;
|
|
|
|
break;
|
1994-05-26 06:35:07 +00:00
|
|
|
case 'N':
|
|
|
|
Nflag = 1;
|
|
|
|
break;
|
2002-06-21 06:18:05 +00:00
|
|
|
case 'O':
|
|
|
|
if ((Oflag = atoi(optarg)) < 1 || Oflag > 2)
|
2002-08-21 18:11:48 +00:00
|
|
|
errx(1, "%s: bad file system format value",
|
2002-06-21 06:18:05 +00:00
|
|
|
optarg);
|
|
|
|
break;
|
2002-03-19 21:05:29 +00:00
|
|
|
case 'R':
|
|
|
|
Rflag = 1;
|
|
|
|
break;
|
1994-05-26 06:35:07 +00:00
|
|
|
case 'S':
|
2010-03-09 10:31:03 +00:00
|
|
|
rval = expand_number_int(optarg, §orsize);
|
2010-03-03 02:05:09 +00:00
|
|
|
if (rval < 0 || sectorsize <= 0)
|
2002-04-24 11:44:02 +00:00
|
|
|
errx(1, "%s: bad sector size", optarg);
|
1994-05-26 06:35:07 +00:00
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
disktype = optarg;
|
|
|
|
break;
|
2001-04-02 01:25:55 +00:00
|
|
|
case 'U':
|
|
|
|
Uflag = 1;
|
|
|
|
break;
|
2007-12-16 19:41:31 +00:00
|
|
|
case 'X':
|
|
|
|
Xflag++;
|
|
|
|
break;
|
1994-05-26 06:35:07 +00:00
|
|
|
case 'a':
|
2010-03-09 19:31:08 +00:00
|
|
|
rval = expand_number_int(optarg, &maxcontig);
|
2010-03-03 02:05:09 +00:00
|
|
|
if (rval < 0 || maxcontig <= 0)
|
2002-04-24 11:44:02 +00:00
|
|
|
errx(1, "%s: bad maximum contiguous blocks",
|
1994-05-26 06:35:07 +00:00
|
|
|
optarg);
|
|
|
|
break;
|
|
|
|
case 'b':
|
2010-03-09 19:31:08 +00:00
|
|
|
rval = expand_number_int(optarg, &bsize);
|
2010-03-03 02:05:09 +00:00
|
|
|
if (rval < 0)
|
|
|
|
errx(1, "%s: bad block size",
|
|
|
|
optarg);
|
|
|
|
if (bsize < MINBSIZE)
|
2002-11-30 18:28:26 +00:00
|
|
|
errx(1, "%s: block size too small, min is %d",
|
|
|
|
optarg, MINBSIZE);
|
|
|
|
if (bsize > MAXBSIZE)
|
|
|
|
errx(1, "%s: block size too large, max is %d",
|
|
|
|
optarg, MAXBSIZE);
|
1994-05-26 06:35:07 +00:00
|
|
|
break;
|
|
|
|
case 'c':
|
2010-03-09 19:31:08 +00:00
|
|
|
rval = expand_number_int(optarg, &maxblkspercg);
|
2010-03-03 02:05:09 +00:00
|
|
|
if (rval < 0 || maxblkspercg <= 0)
|
2002-06-21 06:18:05 +00:00
|
|
|
errx(1, "%s: bad blocks per cylinder group",
|
|
|
|
optarg);
|
|
|
|
break;
|
|
|
|
case 'd':
|
2010-03-09 19:31:08 +00:00
|
|
|
rval = expand_number_int(optarg, &maxbsize);
|
2010-03-03 02:05:09 +00:00
|
|
|
if (rval < 0 || maxbsize < MINBSIZE)
|
2002-06-21 06:18:05 +00:00
|
|
|
errx(1, "%s: bad extent block size", optarg);
|
1994-05-26 06:35:07 +00:00
|
|
|
break;
|
|
|
|
case 'e':
|
2010-03-09 19:31:08 +00:00
|
|
|
rval = expand_number_int(optarg, &maxbpg);
|
2010-03-03 02:05:09 +00:00
|
|
|
if (rval < 0 || maxbpg <= 0)
|
2002-06-21 06:18:05 +00:00
|
|
|
errx(1, "%s: bad blocks per file in a cylinder group",
|
1994-05-26 06:35:07 +00:00
|
|
|
optarg);
|
|
|
|
break;
|
|
|
|
case 'f':
|
2010-03-09 19:31:08 +00:00
|
|
|
rval = expand_number_int(optarg, &fsize);
|
2010-03-03 02:05:09 +00:00
|
|
|
if (rval < 0 || fsize <= 0)
|
2002-04-24 11:44:02 +00:00
|
|
|
errx(1, "%s: bad fragment size", optarg);
|
1994-05-26 06:35:07 +00:00
|
|
|
break;
|
Directory layout preference improvements from Grigoriy Orlov <gluk@ptci.ru>.
His description of the problem and solution follow. My own tests show
speedups on typical filesystem intensive workloads of 5% to 12% which
is very impressive considering the small amount of code change involved.
------
One day I noticed that some file operations run much faster on
small file systems then on big ones. I've looked at the ffs
algorithms, thought about them, and redesigned the dirpref algorithm.
First I want to describe the results of my tests. These results are old
and I have improved the algorithm after these tests were done. Nevertheless
they show how big the perfomance speedup may be. I have done two file/directory
intensive tests on a two OpenBSD systems with old and new dirpref algorithm.
The first test is "tar -xzf ports.tar.gz", the second is "rm -rf ports".
The ports.tar.gz file is the ports collection from the OpenBSD 2.8 release.
It contains 6596 directories and 13868 files. The test systems are:
1. Celeron-450, 128Mb, two IDE drives, the system at wd0, file system for
test is at wd1. Size of test file system is 8 Gb, number of cg=991,
size of cg is 8m, block size = 8k, fragment size = 1k OpenBSD-current
from Dec 2000 with BUFCACHEPERCENT=35
2. PIII-600, 128Mb, two IBM DTLA-307045 IDE drives at i815e, the system
at wd0, file system for test is at wd1. Size of test file system is 40 Gb,
number of cg=5324, size of cg is 8m, block size = 8k, fragment size = 1k
OpenBSD-current from Dec 2000 with BUFCACHEPERCENT=50
You can get more info about the test systems and methods at:
http://www.ptci.ru/gluk/dirpref/old/dirpref.html
Test Results
tar -xzf ports.tar.gz rm -rf ports
mode old dirpref new dirpref speedup old dirprefnew dirpref speedup
First system
normal 667 472 1.41 477 331 1.44
async 285 144 1.98 130 14 9.29
sync 768 616 1.25 477 334 1.43
softdep 413 252 1.64 241 38 6.34
Second system
normal 329 81 4.06 263.5 93.5 2.81
async 302 25.7 11.75 112 2.26 49.56
sync 281 57.0 4.93 263 90.5 2.9
softdep 341 40.6 8.4 284 4.76 59.66
"old dirpref" and "new dirpref" columns give a test time in seconds.
speedup - speed increasement in times, ie. old dirpref / new dirpref.
------
Algorithm description
The old dirpref algorithm is described in comments:
/*
* Find a cylinder to place a directory.
*
* The policy implemented by this algorithm is to select from
* among those cylinder groups with above the average number of
* free inodes, the one with the smallest number of directories.
*/
A new directory is allocated in a different cylinder groups than its
parent directory resulting in a directory tree that is spreaded across
all the cylinder groups. This spreading out results in a non-optimal
access to the directories and files. When we have a small filesystem
it is not a problem but when the filesystem is big then perfomance
degradation becomes very apparent.
What I mean by a big file system ?
1. A big filesystem is a filesystem which occupy 20-30 or more percent
of total drive space, i.e. first and last cylinder are physically
located relatively far from each other.
2. It has a relatively large number of cylinder groups, for example
more cylinder groups than 50% of the buffers in the buffer cache.
The first results in long access times, while the second results in
many buffers being used by metadata operations. Such operations use
cylinder group blocks and on-disk inode blocks. The cylinder group
block (fs->fs_cblkno) contains struct cg, inode and block bit maps.
It is 2k in size for the default filesystem parameters. If new and
parent directories are located in different cylinder groups then the
system performs more input/output operations and uses more buffers.
On filesystems with many cylinder groups, lots of cache buffers are
used for metadata operations.
My solution for this problem is very simple. I allocate many directories
in one cylinder group. I also do some things, so that the new allocation
method does not cause excessive fragmentation and all directory inodes
will not be located at a location far from its file's inodes and data.
The algorithm is:
/*
* Find a cylinder group to place a directory.
*
* The policy implemented by this algorithm is to allocate a
* directory inode in the same cylinder group as its parent
* directory, but also to reserve space for its files inodes
* and data. Restrict the number of directories which may be
* allocated one after another in the same cylinder group
* without intervening allocation of files.
*
* If we allocate a first level directory then force allocation
* in another cylinder group.
*/
My early versions of dirpref give me a good results for a wide range of
file operations and different filesystem capacities except one case:
those applications that create their entire directory structure first
and only later fill this structure with files.
My solution for such and similar cases is to limit a number of
directories which may be created one after another in the same cylinder
group without intervening file creations. For this purpose, I allocate
an array of counters at mount time. This array is linked to the superblock
fs->fs_contigdirs[cg]. Each time a directory is created the counter
increases and each time a file is created the counter decreases. A 60Gb
filesystem with 8mb/cg requires 10kb of memory for the counters array.
The maxcontigdirs is a maximum number of directories which may be created
without an intervening file creation. I found in my tests that the best
performance occurs when I restrict the number of directories in one cylinder
group such that all its files may be located in the same cylinder group.
There may be some deterioration in performance if all the file inodes
are in the same cylinder group as its containing directory, but their
data partially resides in a different cylinder group. The maxcontigdirs
value is calculated to try to prevent this condition. Since there is
no way to know how many files and directories will be allocated later
I added two optimization parameters in superblock/tunefs. They are:
int32_t fs_avgfilesize; /* expected average file size */
int32_t fs_avgfpdir; /* expected # of files per directory */
These parameters have reasonable defaults but may be tweeked for special
uses of a filesystem. They are only necessary in rare cases like better
tuning a filesystem being used to store a squid cache.
I have been using this algorithm for about 3 months. I have done
a lot of testing on filesystems with different capacities, average
filesize, average number of files per directory, and so on. I think
this algorithm has no negative impact on filesystem perfomance. It
works better than the default one in all cases. The new dirpref
will greatly improve untarring/removing/coping of big directories,
decrease load on cvs servers and much more. The new dirpref doesn't
speedup a compilation process, but also doesn't slow it down.
Obtained from: Grigoriy Orlov <gluk@ptci.ru>
2001-04-10 08:38:59 +00:00
|
|
|
case 'g':
|
2010-03-09 19:31:08 +00:00
|
|
|
rval = expand_number_int(optarg, &avgfilesize);
|
2010-03-03 02:05:09 +00:00
|
|
|
if (rval < 0 || avgfilesize <= 0)
|
2002-04-24 11:44:02 +00:00
|
|
|
errx(1, "%s: bad average file size", optarg);
|
Directory layout preference improvements from Grigoriy Orlov <gluk@ptci.ru>.
His description of the problem and solution follow. My own tests show
speedups on typical filesystem intensive workloads of 5% to 12% which
is very impressive considering the small amount of code change involved.
------
One day I noticed that some file operations run much faster on
small file systems then on big ones. I've looked at the ffs
algorithms, thought about them, and redesigned the dirpref algorithm.
First I want to describe the results of my tests. These results are old
and I have improved the algorithm after these tests were done. Nevertheless
they show how big the perfomance speedup may be. I have done two file/directory
intensive tests on a two OpenBSD systems with old and new dirpref algorithm.
The first test is "tar -xzf ports.tar.gz", the second is "rm -rf ports".
The ports.tar.gz file is the ports collection from the OpenBSD 2.8 release.
It contains 6596 directories and 13868 files. The test systems are:
1. Celeron-450, 128Mb, two IDE drives, the system at wd0, file system for
test is at wd1. Size of test file system is 8 Gb, number of cg=991,
size of cg is 8m, block size = 8k, fragment size = 1k OpenBSD-current
from Dec 2000 with BUFCACHEPERCENT=35
2. PIII-600, 128Mb, two IBM DTLA-307045 IDE drives at i815e, the system
at wd0, file system for test is at wd1. Size of test file system is 40 Gb,
number of cg=5324, size of cg is 8m, block size = 8k, fragment size = 1k
OpenBSD-current from Dec 2000 with BUFCACHEPERCENT=50
You can get more info about the test systems and methods at:
http://www.ptci.ru/gluk/dirpref/old/dirpref.html
Test Results
tar -xzf ports.tar.gz rm -rf ports
mode old dirpref new dirpref speedup old dirprefnew dirpref speedup
First system
normal 667 472 1.41 477 331 1.44
async 285 144 1.98 130 14 9.29
sync 768 616 1.25 477 334 1.43
softdep 413 252 1.64 241 38 6.34
Second system
normal 329 81 4.06 263.5 93.5 2.81
async 302 25.7 11.75 112 2.26 49.56
sync 281 57.0 4.93 263 90.5 2.9
softdep 341 40.6 8.4 284 4.76 59.66
"old dirpref" and "new dirpref" columns give a test time in seconds.
speedup - speed increasement in times, ie. old dirpref / new dirpref.
------
Algorithm description
The old dirpref algorithm is described in comments:
/*
* Find a cylinder to place a directory.
*
* The policy implemented by this algorithm is to select from
* among those cylinder groups with above the average number of
* free inodes, the one with the smallest number of directories.
*/
A new directory is allocated in a different cylinder groups than its
parent directory resulting in a directory tree that is spreaded across
all the cylinder groups. This spreading out results in a non-optimal
access to the directories and files. When we have a small filesystem
it is not a problem but when the filesystem is big then perfomance
degradation becomes very apparent.
What I mean by a big file system ?
1. A big filesystem is a filesystem which occupy 20-30 or more percent
of total drive space, i.e. first and last cylinder are physically
located relatively far from each other.
2. It has a relatively large number of cylinder groups, for example
more cylinder groups than 50% of the buffers in the buffer cache.
The first results in long access times, while the second results in
many buffers being used by metadata operations. Such operations use
cylinder group blocks and on-disk inode blocks. The cylinder group
block (fs->fs_cblkno) contains struct cg, inode and block bit maps.
It is 2k in size for the default filesystem parameters. If new and
parent directories are located in different cylinder groups then the
system performs more input/output operations and uses more buffers.
On filesystems with many cylinder groups, lots of cache buffers are
used for metadata operations.
My solution for this problem is very simple. I allocate many directories
in one cylinder group. I also do some things, so that the new allocation
method does not cause excessive fragmentation and all directory inodes
will not be located at a location far from its file's inodes and data.
The algorithm is:
/*
* Find a cylinder group to place a directory.
*
* The policy implemented by this algorithm is to allocate a
* directory inode in the same cylinder group as its parent
* directory, but also to reserve space for its files inodes
* and data. Restrict the number of directories which may be
* allocated one after another in the same cylinder group
* without intervening allocation of files.
*
* If we allocate a first level directory then force allocation
* in another cylinder group.
*/
My early versions of dirpref give me a good results for a wide range of
file operations and different filesystem capacities except one case:
those applications that create their entire directory structure first
and only later fill this structure with files.
My solution for such and similar cases is to limit a number of
directories which may be created one after another in the same cylinder
group without intervening file creations. For this purpose, I allocate
an array of counters at mount time. This array is linked to the superblock
fs->fs_contigdirs[cg]. Each time a directory is created the counter
increases and each time a file is created the counter decreases. A 60Gb
filesystem with 8mb/cg requires 10kb of memory for the counters array.
The maxcontigdirs is a maximum number of directories which may be created
without an intervening file creation. I found in my tests that the best
performance occurs when I restrict the number of directories in one cylinder
group such that all its files may be located in the same cylinder group.
There may be some deterioration in performance if all the file inodes
are in the same cylinder group as its containing directory, but their
data partially resides in a different cylinder group. The maxcontigdirs
value is calculated to try to prevent this condition. Since there is
no way to know how many files and directories will be allocated later
I added two optimization parameters in superblock/tunefs. They are:
int32_t fs_avgfilesize; /* expected average file size */
int32_t fs_avgfpdir; /* expected # of files per directory */
These parameters have reasonable defaults but may be tweeked for special
uses of a filesystem. They are only necessary in rare cases like better
tuning a filesystem being used to store a squid cache.
I have been using this algorithm for about 3 months. I have done
a lot of testing on filesystems with different capacities, average
filesize, average number of files per directory, and so on. I think
this algorithm has no negative impact on filesystem perfomance. It
works better than the default one in all cases. The new dirpref
will greatly improve untarring/removing/coping of big directories,
decrease load on cvs servers and much more. The new dirpref doesn't
speedup a compilation process, but also doesn't slow it down.
Obtained from: Grigoriy Orlov <gluk@ptci.ru>
2001-04-10 08:38:59 +00:00
|
|
|
break;
|
|
|
|
case 'h':
|
2010-03-09 19:31:08 +00:00
|
|
|
rval = expand_number_int(optarg, &avgfilesperdir);
|
2010-03-03 02:05:09 +00:00
|
|
|
if (rval < 0 || avgfilesperdir <= 0)
|
2002-06-21 06:18:05 +00:00
|
|
|
errx(1, "%s: bad average files per dir", optarg);
|
Directory layout preference improvements from Grigoriy Orlov <gluk@ptci.ru>.
His description of the problem and solution follow. My own tests show
speedups on typical filesystem intensive workloads of 5% to 12% which
is very impressive considering the small amount of code change involved.
------
One day I noticed that some file operations run much faster on
small file systems then on big ones. I've looked at the ffs
algorithms, thought about them, and redesigned the dirpref algorithm.
First I want to describe the results of my tests. These results are old
and I have improved the algorithm after these tests were done. Nevertheless
they show how big the perfomance speedup may be. I have done two file/directory
intensive tests on a two OpenBSD systems with old and new dirpref algorithm.
The first test is "tar -xzf ports.tar.gz", the second is "rm -rf ports".
The ports.tar.gz file is the ports collection from the OpenBSD 2.8 release.
It contains 6596 directories and 13868 files. The test systems are:
1. Celeron-450, 128Mb, two IDE drives, the system at wd0, file system for
test is at wd1. Size of test file system is 8 Gb, number of cg=991,
size of cg is 8m, block size = 8k, fragment size = 1k OpenBSD-current
from Dec 2000 with BUFCACHEPERCENT=35
2. PIII-600, 128Mb, two IBM DTLA-307045 IDE drives at i815e, the system
at wd0, file system for test is at wd1. Size of test file system is 40 Gb,
number of cg=5324, size of cg is 8m, block size = 8k, fragment size = 1k
OpenBSD-current from Dec 2000 with BUFCACHEPERCENT=50
You can get more info about the test systems and methods at:
http://www.ptci.ru/gluk/dirpref/old/dirpref.html
Test Results
tar -xzf ports.tar.gz rm -rf ports
mode old dirpref new dirpref speedup old dirprefnew dirpref speedup
First system
normal 667 472 1.41 477 331 1.44
async 285 144 1.98 130 14 9.29
sync 768 616 1.25 477 334 1.43
softdep 413 252 1.64 241 38 6.34
Second system
normal 329 81 4.06 263.5 93.5 2.81
async 302 25.7 11.75 112 2.26 49.56
sync 281 57.0 4.93 263 90.5 2.9
softdep 341 40.6 8.4 284 4.76 59.66
"old dirpref" and "new dirpref" columns give a test time in seconds.
speedup - speed increasement in times, ie. old dirpref / new dirpref.
------
Algorithm description
The old dirpref algorithm is described in comments:
/*
* Find a cylinder to place a directory.
*
* The policy implemented by this algorithm is to select from
* among those cylinder groups with above the average number of
* free inodes, the one with the smallest number of directories.
*/
A new directory is allocated in a different cylinder groups than its
parent directory resulting in a directory tree that is spreaded across
all the cylinder groups. This spreading out results in a non-optimal
access to the directories and files. When we have a small filesystem
it is not a problem but when the filesystem is big then perfomance
degradation becomes very apparent.
What I mean by a big file system ?
1. A big filesystem is a filesystem which occupy 20-30 or more percent
of total drive space, i.e. first and last cylinder are physically
located relatively far from each other.
2. It has a relatively large number of cylinder groups, for example
more cylinder groups than 50% of the buffers in the buffer cache.
The first results in long access times, while the second results in
many buffers being used by metadata operations. Such operations use
cylinder group blocks and on-disk inode blocks. The cylinder group
block (fs->fs_cblkno) contains struct cg, inode and block bit maps.
It is 2k in size for the default filesystem parameters. If new and
parent directories are located in different cylinder groups then the
system performs more input/output operations and uses more buffers.
On filesystems with many cylinder groups, lots of cache buffers are
used for metadata operations.
My solution for this problem is very simple. I allocate many directories
in one cylinder group. I also do some things, so that the new allocation
method does not cause excessive fragmentation and all directory inodes
will not be located at a location far from its file's inodes and data.
The algorithm is:
/*
* Find a cylinder group to place a directory.
*
* The policy implemented by this algorithm is to allocate a
* directory inode in the same cylinder group as its parent
* directory, but also to reserve space for its files inodes
* and data. Restrict the number of directories which may be
* allocated one after another in the same cylinder group
* without intervening allocation of files.
*
* If we allocate a first level directory then force allocation
* in another cylinder group.
*/
My early versions of dirpref give me a good results for a wide range of
file operations and different filesystem capacities except one case:
those applications that create their entire directory structure first
and only later fill this structure with files.
My solution for such and similar cases is to limit a number of
directories which may be created one after another in the same cylinder
group without intervening file creations. For this purpose, I allocate
an array of counters at mount time. This array is linked to the superblock
fs->fs_contigdirs[cg]. Each time a directory is created the counter
increases and each time a file is created the counter decreases. A 60Gb
filesystem with 8mb/cg requires 10kb of memory for the counters array.
The maxcontigdirs is a maximum number of directories which may be created
without an intervening file creation. I found in my tests that the best
performance occurs when I restrict the number of directories in one cylinder
group such that all its files may be located in the same cylinder group.
There may be some deterioration in performance if all the file inodes
are in the same cylinder group as its containing directory, but their
data partially resides in a different cylinder group. The maxcontigdirs
value is calculated to try to prevent this condition. Since there is
no way to know how many files and directories will be allocated later
I added two optimization parameters in superblock/tunefs. They are:
int32_t fs_avgfilesize; /* expected average file size */
int32_t fs_avgfpdir; /* expected # of files per directory */
These parameters have reasonable defaults but may be tweeked for special
uses of a filesystem. They are only necessary in rare cases like better
tuning a filesystem being used to store a squid cache.
I have been using this algorithm for about 3 months. I have done
a lot of testing on filesystems with different capacities, average
filesize, average number of files per directory, and so on. I think
this algorithm has no negative impact on filesystem perfomance. It
works better than the default one in all cases. The new dirpref
will greatly improve untarring/removing/coping of big directories,
decrease load on cvs servers and much more. The new dirpref doesn't
speedup a compilation process, but also doesn't slow it down.
Obtained from: Grigoriy Orlov <gluk@ptci.ru>
2001-04-10 08:38:59 +00:00
|
|
|
break;
|
1994-05-26 06:35:07 +00:00
|
|
|
case 'i':
|
2010-03-09 19:31:08 +00:00
|
|
|
rval = expand_number_int(optarg, &density);
|
2010-03-03 02:05:09 +00:00
|
|
|
if (rval < 0 || density <= 0)
|
2002-04-24 11:44:02 +00:00
|
|
|
errx(1, "%s: bad bytes per inode", optarg);
|
1994-05-26 06:35:07 +00:00
|
|
|
break;
|
2004-02-26 01:14:27 +00:00
|
|
|
case 'l':
|
|
|
|
lflag = 1;
|
|
|
|
break;
|
1994-05-26 06:35:07 +00:00
|
|
|
case 'm':
|
|
|
|
if ((minfree = atoi(optarg)) < 0 || minfree > 99)
|
2002-04-24 11:44:02 +00:00
|
|
|
errx(1, "%s: bad free space %%", optarg);
|
1994-05-26 06:35:07 +00:00
|
|
|
break;
|
2005-01-21 22:20:25 +00:00
|
|
|
case 'n':
|
|
|
|
nflag = 1;
|
|
|
|
break;
|
1994-05-26 06:35:07 +00:00
|
|
|
case 'o':
|
2001-05-29 19:40:39 +00:00
|
|
|
if (strcmp(optarg, "space") == 0)
|
|
|
|
opt = FS_OPTSPACE;
|
|
|
|
else if (strcmp(optarg, "time") == 0)
|
|
|
|
opt = FS_OPTTIME;
|
|
|
|
else
|
2002-04-24 11:44:02 +00:00
|
|
|
errx(1,
|
2002-03-18 03:04:58 +00:00
|
|
|
"%s: unknown optimization preference: use `space' or `time'",
|
|
|
|
optarg);
|
1994-05-26 06:35:07 +00:00
|
|
|
break;
|
2007-11-28 07:29:10 +00:00
|
|
|
case 'r':
|
|
|
|
errno = 0;
|
|
|
|
reserved = strtoimax(optarg, &cp, 0);
|
|
|
|
if (errno != 0 || cp == optarg ||
|
|
|
|
*cp != '\0' || reserved < 0)
|
|
|
|
errx(1, "%s: bad reserved size", optarg);
|
|
|
|
break;
|
Enable operation of newfs on plain files, which is useful when you
want to prepare disk images for emulators (though 'makefs' in port
can do something similar).
This relies on:
+ minor changes to pass the consistency checks even when working on a file;
+ an additional option, '-p partition' , to specify the disk partition to
initialize;
+ some changes on the I/O routines to deal with partition offsets.
The latter was a bit tricky to implement, see the details in newfs.h:
in newfs, I/O is done through libufs which assumes that the file
descriptor refers to the whole partition. Introducing support for
the offset in libufs would require a non-backward compatible change
in the library, to be dealt with a version bump or with symbol
versioning.
I felt both approaches to be overkill for this specific application,
especially because there might be other changes to libufs that might
become necessary in the near future.
So I used the following trick:
- read access is always done by calling bread() directly, so we just add
the offset in the (few) places that call bread();
- write access is done through bwrite() and sbwrite(), which in turn
calls bwrite(). To avoid rewriting sbwrite(), we supply our own version
of bwrite() here, which takes precedence over the version in libufs.
MFC after: 4 weeks
2008-12-03 18:36:59 +00:00
|
|
|
case 'p':
|
|
|
|
is_file = 1;
|
|
|
|
part_name = optarg[0];
|
|
|
|
break;
|
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
case 's':
|
2004-09-19 10:01:51 +00:00
|
|
|
errno = 0;
|
2007-11-28 07:29:10 +00:00
|
|
|
fssize = strtoimax(optarg, &cp, 0);
|
|
|
|
if (errno != 0 || cp == optarg ||
|
|
|
|
*cp != '\0' || fssize < 0)
|
|
|
|
errx(1, "%s: bad file system size", optarg);
|
1994-05-26 06:35:07 +00:00
|
|
|
break;
|
2010-12-29 12:31:18 +00:00
|
|
|
case 't':
|
|
|
|
tflag = 1;
|
|
|
|
break;
|
1994-05-26 06:35:07 +00:00
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
2002-04-24 11:44:02 +00:00
|
|
|
if (argc != 1)
|
1994-05-26 06:35:07 +00:00
|
|
|
usage();
|
|
|
|
|
|
|
|
special = argv[0];
|
Enable operation of newfs on plain files, which is useful when you
want to prepare disk images for emulators (though 'makefs' in port
can do something similar).
This relies on:
+ minor changes to pass the consistency checks even when working on a file;
+ an additional option, '-p partition' , to specify the disk partition to
initialize;
+ some changes on the I/O routines to deal with partition offsets.
The latter was a bit tricky to implement, see the details in newfs.h:
in newfs, I/O is done through libufs which assumes that the file
descriptor refers to the whole partition. Introducing support for
the offset in libufs would require a non-backward compatible change
in the library, to be dealt with a version bump or with symbol
versioning.
I felt both approaches to be overkill for this specific application,
especially because there might be other changes to libufs that might
become necessary in the near future.
So I used the following trick:
- read access is always done by calling bread() directly, so we just add
the offset in the (few) places that call bread();
- write access is done through bwrite() and sbwrite(), which in turn
calls bwrite(). To avoid rewriting sbwrite(), we supply our own version
of bwrite() here, which takes precedence over the version in libufs.
MFC after: 4 weeks
2008-12-03 18:36:59 +00:00
|
|
|
if (!special[0])
|
|
|
|
err(1, "empty file/special name");
|
1997-03-11 12:48:17 +00:00
|
|
|
cp = strrchr(special, '/');
|
1994-05-26 06:35:07 +00:00
|
|
|
if (cp == 0) {
|
|
|
|
/*
|
2002-03-18 03:04:58 +00:00
|
|
|
* No path prefix; try prefixing _PATH_DEV.
|
1994-05-26 06:35:07 +00:00
|
|
|
*/
|
2002-03-18 03:04:58 +00:00
|
|
|
snprintf(device, sizeof(device), "%s%s", _PATH_DEV, special);
|
1994-05-26 06:35:07 +00:00
|
|
|
special = device;
|
|
|
|
}
|
|
|
|
|
Enable operation of newfs on plain files, which is useful when you
want to prepare disk images for emulators (though 'makefs' in port
can do something similar).
This relies on:
+ minor changes to pass the consistency checks even when working on a file;
+ an additional option, '-p partition' , to specify the disk partition to
initialize;
+ some changes on the I/O routines to deal with partition offsets.
The latter was a bit tricky to implement, see the details in newfs.h:
in newfs, I/O is done through libufs which assumes that the file
descriptor refers to the whole partition. Introducing support for
the offset in libufs would require a non-backward compatible change
in the library, to be dealt with a version bump or with symbol
versioning.
I felt both approaches to be overkill for this specific application,
especially because there might be other changes to libufs that might
become necessary in the near future.
So I used the following trick:
- read access is always done by calling bread() directly, so we just add
the offset in the (few) places that call bread();
- write access is done through bwrite() and sbwrite(), which in turn
calls bwrite(). To avoid rewriting sbwrite(), we supply our own version
of bwrite() here, which takes precedence over the version in libufs.
MFC after: 4 weeks
2008-12-03 18:36:59 +00:00
|
|
|
if (is_file) {
|
|
|
|
/* bypass ufs_disk_fillout_blank */
|
|
|
|
bzero( &disk, sizeof(disk));
|
|
|
|
disk.d_bsize = 1;
|
|
|
|
disk.d_name = special;
|
|
|
|
disk.d_fd = open(special, O_RDONLY);
|
|
|
|
if (disk.d_fd < 0 ||
|
|
|
|
(!Nflag && ufs_disk_write(&disk) == -1))
|
|
|
|
errx(1, "%s: ", special);
|
|
|
|
} else if (ufs_disk_fillout_blank(&disk, special) == -1 ||
|
2003-02-11 03:06:45 +00:00
|
|
|
(!Nflag && ufs_disk_write(&disk) == -1)) {
|
|
|
|
if (disk.d_error != NULL)
|
|
|
|
errx(1, "%s: %s", special, disk.d_error);
|
|
|
|
else
|
|
|
|
err(1, "%s", special);
|
|
|
|
}
|
|
|
|
if (fstat(disk.d_fd, &st) < 0)
|
2002-04-24 11:44:02 +00:00
|
|
|
err(1, "%s", special);
|
Enable operation of newfs on plain files, which is useful when you
want to prepare disk images for emulators (though 'makefs' in port
can do something similar).
This relies on:
+ minor changes to pass the consistency checks even when working on a file;
+ an additional option, '-p partition' , to specify the disk partition to
initialize;
+ some changes on the I/O routines to deal with partition offsets.
The latter was a bit tricky to implement, see the details in newfs.h:
in newfs, I/O is done through libufs which assumes that the file
descriptor refers to the whole partition. Introducing support for
the offset in libufs would require a non-backward compatible change
in the library, to be dealt with a version bump or with symbol
versioning.
I felt both approaches to be overkill for this specific application,
especially because there might be other changes to libufs that might
become necessary in the near future.
So I used the following trick:
- read access is always done by calling bread() directly, so we just add
the offset in the (few) places that call bread();
- write access is done through bwrite() and sbwrite(), which in turn
calls bwrite(). To avoid rewriting sbwrite(), we supply our own version
of bwrite() here, which takes precedence over the version in libufs.
MFC after: 4 weeks
2008-12-03 18:36:59 +00:00
|
|
|
if ((st.st_mode & S_IFMT) != S_IFCHR) {
|
|
|
|
warn("%s: not a character-special device", special);
|
|
|
|
is_file = 1; /* assume it is a file */
|
|
|
|
dkname = special;
|
|
|
|
if (sectorsize == 0)
|
|
|
|
sectorsize = 512;
|
|
|
|
mediasize = st.st_size;
|
|
|
|
/* set fssize from the partition */
|
|
|
|
} else {
|
|
|
|
if (sectorsize == 0)
|
2007-11-28 07:54:42 +00:00
|
|
|
if (ioctl(disk.d_fd, DIOCGSECTORSIZE, §orsize) == -1)
|
Enable operation of newfs on plain files, which is useful when you
want to prepare disk images for emulators (though 'makefs' in port
can do something similar).
This relies on:
+ minor changes to pass the consistency checks even when working on a file;
+ an additional option, '-p partition' , to specify the disk partition to
initialize;
+ some changes on the I/O routines to deal with partition offsets.
The latter was a bit tricky to implement, see the details in newfs.h:
in newfs, I/O is done through libufs which assumes that the file
descriptor refers to the whole partition. Introducing support for
the offset in libufs would require a non-backward compatible change
in the library, to be dealt with a version bump or with symbol
versioning.
I felt both approaches to be overkill for this specific application,
especially because there might be other changes to libufs that might
become necessary in the near future.
So I used the following trick:
- read access is always done by calling bread() directly, so we just add
the offset in the (few) places that call bread();
- write access is done through bwrite() and sbwrite(), which in turn
calls bwrite(). To avoid rewriting sbwrite(), we supply our own version
of bwrite() here, which takes precedence over the version in libufs.
MFC after: 4 weeks
2008-12-03 18:36:59 +00:00
|
|
|
sectorsize = 0; /* back out on error for safety */
|
|
|
|
if (sectorsize && ioctl(disk.d_fd, DIOCGMEDIASIZE, &mediasize) != -1)
|
2007-11-28 07:29:10 +00:00
|
|
|
getfssize(&fssize, special, mediasize / sectorsize, reserved);
|
Enable operation of newfs on plain files, which is useful when you
want to prepare disk images for emulators (though 'makefs' in port
can do something similar).
This relies on:
+ minor changes to pass the consistency checks even when working on a file;
+ an additional option, '-p partition' , to specify the disk partition to
initialize;
+ some changes on the I/O routines to deal with partition offsets.
The latter was a bit tricky to implement, see the details in newfs.h:
in newfs, I/O is done through libufs which assumes that the file
descriptor refers to the whole partition. Introducing support for
the offset in libufs would require a non-backward compatible change
in the library, to be dealt with a version bump or with symbol
versioning.
I felt both approaches to be overkill for this specific application,
especially because there might be other changes to libufs that might
become necessary in the near future.
So I used the following trick:
- read access is always done by calling bread() directly, so we just add
the offset in the (few) places that call bread();
- write access is done through bwrite() and sbwrite(), which in turn
calls bwrite(). To avoid rewriting sbwrite(), we supply our own version
of bwrite() here, which takes precedence over the version in libufs.
MFC after: 4 weeks
2008-12-03 18:36:59 +00:00
|
|
|
}
|
2002-04-24 11:44:02 +00:00
|
|
|
pp = NULL;
|
|
|
|
lp = getdisklabel(special);
|
|
|
|
if (lp != NULL) {
|
2008-12-12 15:56:38 +00:00
|
|
|
if (!is_file) /* already set for files */
|
|
|
|
part_name = special[strlen(special) - 1];
|
|
|
|
if ((part_name < 'a' || part_name - 'a' >= MAXPARTITIONS) &&
|
|
|
|
!isdigit(part_name))
|
|
|
|
errx(1, "%s: can't figure out file system partition",
|
|
|
|
special);
|
Enable operation of newfs on plain files, which is useful when you
want to prepare disk images for emulators (though 'makefs' in port
can do something similar).
This relies on:
+ minor changes to pass the consistency checks even when working on a file;
+ an additional option, '-p partition' , to specify the disk partition to
initialize;
+ some changes on the I/O routines to deal with partition offsets.
The latter was a bit tricky to implement, see the details in newfs.h:
in newfs, I/O is done through libufs which assumes that the file
descriptor refers to the whole partition. Introducing support for
the offset in libufs would require a non-backward compatible change
in the library, to be dealt with a version bump or with symbol
versioning.
I felt both approaches to be overkill for this specific application,
especially because there might be other changes to libufs that might
become necessary in the near future.
So I used the following trick:
- read access is always done by calling bread() directly, so we just add
the offset in the (few) places that call bread();
- write access is done through bwrite() and sbwrite(), which in turn
calls bwrite(). To avoid rewriting sbwrite(), we supply our own version
of bwrite() here, which takes precedence over the version in libufs.
MFC after: 4 weeks
2008-12-03 18:36:59 +00:00
|
|
|
cp = &part_name;
|
2002-04-24 12:27:03 +00:00
|
|
|
if (isdigit(*cp))
|
|
|
|
pp = &lp->d_partitions[RAW_PART];
|
2002-04-24 11:44:02 +00:00
|
|
|
else
|
|
|
|
pp = &lp->d_partitions[*cp - 'a'];
|
|
|
|
oldpartition = *pp;
|
|
|
|
if (pp->p_size == 0)
|
|
|
|
errx(1, "%s: `%c' partition is unavailable",
|
|
|
|
special, *cp);
|
|
|
|
if (pp->p_fstype == FS_BOOT)
|
|
|
|
errx(1, "%s: `%c' partition overlaps boot program",
|
|
|
|
special, *cp);
|
2007-11-28 07:29:10 +00:00
|
|
|
getfssize(&fssize, special, pp->p_size, reserved);
|
2002-04-24 11:44:02 +00:00
|
|
|
if (sectorsize == 0)
|
|
|
|
sectorsize = lp->d_secsize;
|
|
|
|
if (fsize == 0)
|
|
|
|
fsize = pp->p_fsize;
|
|
|
|
if (bsize == 0)
|
|
|
|
bsize = pp->p_frag * pp->p_fsize;
|
Enable operation of newfs on plain files, which is useful when you
want to prepare disk images for emulators (though 'makefs' in port
can do something similar).
This relies on:
+ minor changes to pass the consistency checks even when working on a file;
+ an additional option, '-p partition' , to specify the disk partition to
initialize;
+ some changes on the I/O routines to deal with partition offsets.
The latter was a bit tricky to implement, see the details in newfs.h:
in newfs, I/O is done through libufs which assumes that the file
descriptor refers to the whole partition. Introducing support for
the offset in libufs would require a non-backward compatible change
in the library, to be dealt with a version bump or with symbol
versioning.
I felt both approaches to be overkill for this specific application,
especially because there might be other changes to libufs that might
become necessary in the near future.
So I used the following trick:
- read access is always done by calling bread() directly, so we just add
the offset in the (few) places that call bread();
- write access is done through bwrite() and sbwrite(), which in turn
calls bwrite(). To avoid rewriting sbwrite(), we supply our own version
of bwrite() here, which takes precedence over the version in libufs.
MFC after: 4 weeks
2008-12-03 18:36:59 +00:00
|
|
|
if (is_file)
|
|
|
|
part_ofs = pp->p_offset;
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
2002-04-24 11:44:02 +00:00
|
|
|
if (sectorsize <= 0)
|
|
|
|
errx(1, "%s: no default sector size", special);
|
|
|
|
if (fsize <= 0)
|
|
|
|
fsize = MAX(DFL_FRAGSIZE, sectorsize);
|
|
|
|
if (bsize <= 0)
|
|
|
|
bsize = MIN(DFL_BLKSIZE, 8 * fsize);
|
1994-05-26 06:35:07 +00:00
|
|
|
if (minfree < MINFREE && opt != FS_OPTSPACE) {
|
|
|
|
fprintf(stderr, "Warning: changing optimization to space ");
|
|
|
|
fprintf(stderr, "because minfree is less than %d%%\n", MINFREE);
|
|
|
|
opt = FS_OPTSPACE;
|
|
|
|
}
|
1996-12-01 11:25:38 +00:00
|
|
|
realsectorsize = sectorsize;
|
|
|
|
if (sectorsize != DEV_BSIZE) { /* XXX */
|
|
|
|
int secperblk = sectorsize / DEV_BSIZE;
|
|
|
|
|
|
|
|
sectorsize = DEV_BSIZE;
|
|
|
|
fssize *= secperblk;
|
2002-10-01 17:31:28 +00:00
|
|
|
if (pp != NULL)
|
2002-04-24 11:44:02 +00:00
|
|
|
pp->p_size *= secperblk;
|
|
|
|
}
|
|
|
|
mkfs(pp, special);
|
|
|
|
if (!unlabeled) {
|
|
|
|
if (realsectorsize != DEV_BSIZE)
|
2002-06-21 06:18:05 +00:00
|
|
|
pp->p_size /= realsectorsize / DEV_BSIZE;
|
2002-04-24 11:44:02 +00:00
|
|
|
if (!Nflag && bcmp(pp, &oldpartition, sizeof(oldpartition)))
|
|
|
|
rewritelabel(special, lp);
|
1996-12-01 11:25:38 +00:00
|
|
|
}
|
2003-02-11 03:06:45 +00:00
|
|
|
ufs_disk_close(&disk);
|
1994-05-26 06:35:07 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2007-11-28 07:29:10 +00:00
|
|
|
void
|
|
|
|
getfssize(intmax_t *fsz, const char *s, intmax_t disksize, intmax_t reserved)
|
|
|
|
{
|
|
|
|
intmax_t available;
|
|
|
|
|
|
|
|
available = disksize - reserved;
|
|
|
|
if (available <= 0)
|
|
|
|
errx(1, "%s: reserved not less than device size %jd",
|
|
|
|
s, disksize);
|
|
|
|
if (*fsz == 0)
|
|
|
|
*fsz = available;
|
|
|
|
else if (*fsz > available)
|
|
|
|
errx(1, "%s: maximum file system size is %jd",
|
|
|
|
s, available);
|
|
|
|
}
|
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
struct disklabel *
|
2002-04-24 11:44:02 +00:00
|
|
|
getdisklabel(char *s)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
|
|
|
static struct disklabel lab;
|
2002-04-24 11:44:02 +00:00
|
|
|
struct disklabel *lp;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
Enable operation of newfs on plain files, which is useful when you
want to prepare disk images for emulators (though 'makefs' in port
can do something similar).
This relies on:
+ minor changes to pass the consistency checks even when working on a file;
+ an additional option, '-p partition' , to specify the disk partition to
initialize;
+ some changes on the I/O routines to deal with partition offsets.
The latter was a bit tricky to implement, see the details in newfs.h:
in newfs, I/O is done through libufs which assumes that the file
descriptor refers to the whole partition. Introducing support for
the offset in libufs would require a non-backward compatible change
in the library, to be dealt with a version bump or with symbol
versioning.
I felt both approaches to be overkill for this specific application,
especially because there might be other changes to libufs that might
become necessary in the near future.
So I used the following trick:
- read access is always done by calling bread() directly, so we just add
the offset in the (few) places that call bread();
- write access is done through bwrite() and sbwrite(), which in turn
calls bwrite(). To avoid rewriting sbwrite(), we supply our own version
of bwrite() here, which takes precedence over the version in libufs.
MFC after: 4 weeks
2008-12-03 18:36:59 +00:00
|
|
|
if (is_file) {
|
|
|
|
if (read(disk.d_fd, bootarea, BBSIZE) != BBSIZE)
|
|
|
|
err(4, "cannot read bootarea");
|
|
|
|
if (bsd_disklabel_le_dec(
|
|
|
|
bootarea + (0 /* labeloffset */ +
|
|
|
|
1 /* labelsoffset */ * sectorsize),
|
|
|
|
&lab, MAXPARTITIONS))
|
|
|
|
errx(1, "no valid label found");
|
|
|
|
|
|
|
|
lp = &lab;
|
|
|
|
return &lab;
|
|
|
|
}
|
|
|
|
|
2007-11-28 07:54:42 +00:00
|
|
|
if (ioctl(disk.d_fd, DIOCGDINFO, (char *)&lab) != -1)
|
2002-04-24 11:44:02 +00:00
|
|
|
return (&lab);
|
|
|
|
unlabeled++;
|
|
|
|
if (disktype) {
|
|
|
|
lp = getdiskbyname(disktype);
|
|
|
|
if (lp != NULL)
|
1994-05-26 06:35:07 +00:00
|
|
|
return (lp);
|
|
|
|
}
|
2002-04-24 11:44:02 +00:00
|
|
|
return (NULL);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
|
2001-05-29 19:40:39 +00:00
|
|
|
void
|
2002-04-24 11:44:02 +00:00
|
|
|
rewritelabel(char *s, struct disklabel *lp)
|
1998-07-20 12:04:42 +00:00
|
|
|
{
|
|
|
|
if (unlabeled)
|
|
|
|
return;
|
|
|
|
lp->d_checksum = 0;
|
|
|
|
lp->d_checksum = dkcksum(lp);
|
Enable operation of newfs on plain files, which is useful when you
want to prepare disk images for emulators (though 'makefs' in port
can do something similar).
This relies on:
+ minor changes to pass the consistency checks even when working on a file;
+ an additional option, '-p partition' , to specify the disk partition to
initialize;
+ some changes on the I/O routines to deal with partition offsets.
The latter was a bit tricky to implement, see the details in newfs.h:
in newfs, I/O is done through libufs which assumes that the file
descriptor refers to the whole partition. Introducing support for
the offset in libufs would require a non-backward compatible change
in the library, to be dealt with a version bump or with symbol
versioning.
I felt both approaches to be overkill for this specific application,
especially because there might be other changes to libufs that might
become necessary in the near future.
So I used the following trick:
- read access is always done by calling bread() directly, so we just add
the offset in the (few) places that call bread();
- write access is done through bwrite() and sbwrite(), which in turn
calls bwrite(). To avoid rewriting sbwrite(), we supply our own version
of bwrite() here, which takes precedence over the version in libufs.
MFC after: 4 weeks
2008-12-03 18:36:59 +00:00
|
|
|
if (is_file) {
|
|
|
|
bsd_disklabel_le_enc(bootarea + 0 /* labeloffset */ +
|
|
|
|
1 /* labelsoffset */ * sectorsize, lp);
|
|
|
|
lseek(disk.d_fd, 0, SEEK_SET);
|
|
|
|
if (write(disk.d_fd, bootarea, BBSIZE) != BBSIZE)
|
|
|
|
errx(1, "cannot write label");
|
|
|
|
return;
|
|
|
|
}
|
2007-11-28 07:54:42 +00:00
|
|
|
if (ioctl(disk.d_fd, DIOCWDINFO, (char *)lp) == -1)
|
2002-09-22 09:41:41 +00:00
|
|
|
warn("ioctl (WDINFO): %s: can't rewrite disk label", s);
|
1998-07-20 12:04:42 +00:00
|
|
|
}
|
|
|
|
|
1998-07-15 06:28:05 +00:00
|
|
|
static void
|
2003-01-29 22:52:27 +00:00
|
|
|
usage()
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
2001-05-29 19:40:39 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"usage: %s [ -fsoptions ] special-device%s\n",
|
2002-04-24 11:44:02 +00:00
|
|
|
getprogname(),
|
2001-05-29 19:40:39 +00:00
|
|
|
" [device-type]");
|
1994-05-26 06:35:07 +00:00
|
|
|
fprintf(stderr, "where fsoptions are:\n");
|
2010-02-06 00:25:46 +00:00
|
|
|
fprintf(stderr, "\t-E Erase previous disk content\n");
|
2007-03-02 20:07:59 +00:00
|
|
|
fprintf(stderr, "\t-J Enable journaling via gjournal\n");
|
2003-02-01 04:17:10 +00:00
|
|
|
fprintf(stderr, "\t-L volume label to add to superblock\n");
|
1994-05-26 06:35:07 +00:00
|
|
|
fprintf(stderr,
|
2002-08-21 18:11:48 +00:00
|
|
|
"\t-N do not create file system, just print out parameters\n");
|
|
|
|
fprintf(stderr, "\t-O file system format: 1 => UFS1, 2 => UFS2\n");
|
2010-02-06 00:25:46 +00:00
|
|
|
fprintf(stderr, "\t-R regression test, suppress random factors\n");
|
1994-05-26 06:35:07 +00:00
|
|
|
fprintf(stderr, "\t-S sector size\n");
|
|
|
|
fprintf(stderr, "\t-T disktype\n");
|
2001-04-02 01:25:55 +00:00
|
|
|
fprintf(stderr, "\t-U enable soft updates\n");
|
1994-05-26 06:35:07 +00:00
|
|
|
fprintf(stderr, "\t-a maximum contiguous blocks\n");
|
|
|
|
fprintf(stderr, "\t-b block size\n");
|
2002-06-21 06:18:05 +00:00
|
|
|
fprintf(stderr, "\t-c blocks per cylinders group\n");
|
|
|
|
fprintf(stderr, "\t-d maximum extent size\n");
|
1994-05-26 06:35:07 +00:00
|
|
|
fprintf(stderr, "\t-e maximum blocks per file in a cylinder group\n");
|
|
|
|
fprintf(stderr, "\t-f frag size\n");
|
Directory layout preference improvements from Grigoriy Orlov <gluk@ptci.ru>.
His description of the problem and solution follow. My own tests show
speedups on typical filesystem intensive workloads of 5% to 12% which
is very impressive considering the small amount of code change involved.
------
One day I noticed that some file operations run much faster on
small file systems then on big ones. I've looked at the ffs
algorithms, thought about them, and redesigned the dirpref algorithm.
First I want to describe the results of my tests. These results are old
and I have improved the algorithm after these tests were done. Nevertheless
they show how big the perfomance speedup may be. I have done two file/directory
intensive tests on a two OpenBSD systems with old and new dirpref algorithm.
The first test is "tar -xzf ports.tar.gz", the second is "rm -rf ports".
The ports.tar.gz file is the ports collection from the OpenBSD 2.8 release.
It contains 6596 directories and 13868 files. The test systems are:
1. Celeron-450, 128Mb, two IDE drives, the system at wd0, file system for
test is at wd1. Size of test file system is 8 Gb, number of cg=991,
size of cg is 8m, block size = 8k, fragment size = 1k OpenBSD-current
from Dec 2000 with BUFCACHEPERCENT=35
2. PIII-600, 128Mb, two IBM DTLA-307045 IDE drives at i815e, the system
at wd0, file system for test is at wd1. Size of test file system is 40 Gb,
number of cg=5324, size of cg is 8m, block size = 8k, fragment size = 1k
OpenBSD-current from Dec 2000 with BUFCACHEPERCENT=50
You can get more info about the test systems and methods at:
http://www.ptci.ru/gluk/dirpref/old/dirpref.html
Test Results
tar -xzf ports.tar.gz rm -rf ports
mode old dirpref new dirpref speedup old dirprefnew dirpref speedup
First system
normal 667 472 1.41 477 331 1.44
async 285 144 1.98 130 14 9.29
sync 768 616 1.25 477 334 1.43
softdep 413 252 1.64 241 38 6.34
Second system
normal 329 81 4.06 263.5 93.5 2.81
async 302 25.7 11.75 112 2.26 49.56
sync 281 57.0 4.93 263 90.5 2.9
softdep 341 40.6 8.4 284 4.76 59.66
"old dirpref" and "new dirpref" columns give a test time in seconds.
speedup - speed increasement in times, ie. old dirpref / new dirpref.
------
Algorithm description
The old dirpref algorithm is described in comments:
/*
* Find a cylinder to place a directory.
*
* The policy implemented by this algorithm is to select from
* among those cylinder groups with above the average number of
* free inodes, the one with the smallest number of directories.
*/
A new directory is allocated in a different cylinder groups than its
parent directory resulting in a directory tree that is spreaded across
all the cylinder groups. This spreading out results in a non-optimal
access to the directories and files. When we have a small filesystem
it is not a problem but when the filesystem is big then perfomance
degradation becomes very apparent.
What I mean by a big file system ?
1. A big filesystem is a filesystem which occupy 20-30 or more percent
of total drive space, i.e. first and last cylinder are physically
located relatively far from each other.
2. It has a relatively large number of cylinder groups, for example
more cylinder groups than 50% of the buffers in the buffer cache.
The first results in long access times, while the second results in
many buffers being used by metadata operations. Such operations use
cylinder group blocks and on-disk inode blocks. The cylinder group
block (fs->fs_cblkno) contains struct cg, inode and block bit maps.
It is 2k in size for the default filesystem parameters. If new and
parent directories are located in different cylinder groups then the
system performs more input/output operations and uses more buffers.
On filesystems with many cylinder groups, lots of cache buffers are
used for metadata operations.
My solution for this problem is very simple. I allocate many directories
in one cylinder group. I also do some things, so that the new allocation
method does not cause excessive fragmentation and all directory inodes
will not be located at a location far from its file's inodes and data.
The algorithm is:
/*
* Find a cylinder group to place a directory.
*
* The policy implemented by this algorithm is to allocate a
* directory inode in the same cylinder group as its parent
* directory, but also to reserve space for its files inodes
* and data. Restrict the number of directories which may be
* allocated one after another in the same cylinder group
* without intervening allocation of files.
*
* If we allocate a first level directory then force allocation
* in another cylinder group.
*/
My early versions of dirpref give me a good results for a wide range of
file operations and different filesystem capacities except one case:
those applications that create their entire directory structure first
and only later fill this structure with files.
My solution for such and similar cases is to limit a number of
directories which may be created one after another in the same cylinder
group without intervening file creations. For this purpose, I allocate
an array of counters at mount time. This array is linked to the superblock
fs->fs_contigdirs[cg]. Each time a directory is created the counter
increases and each time a file is created the counter decreases. A 60Gb
filesystem with 8mb/cg requires 10kb of memory for the counters array.
The maxcontigdirs is a maximum number of directories which may be created
without an intervening file creation. I found in my tests that the best
performance occurs when I restrict the number of directories in one cylinder
group such that all its files may be located in the same cylinder group.
There may be some deterioration in performance if all the file inodes
are in the same cylinder group as its containing directory, but their
data partially resides in a different cylinder group. The maxcontigdirs
value is calculated to try to prevent this condition. Since there is
no way to know how many files and directories will be allocated later
I added two optimization parameters in superblock/tunefs. They are:
int32_t fs_avgfilesize; /* expected average file size */
int32_t fs_avgfpdir; /* expected # of files per directory */
These parameters have reasonable defaults but may be tweeked for special
uses of a filesystem. They are only necessary in rare cases like better
tuning a filesystem being used to store a squid cache.
I have been using this algorithm for about 3 months. I have done
a lot of testing on filesystems with different capacities, average
filesize, average number of files per directory, and so on. I think
this algorithm has no negative impact on filesystem perfomance. It
works better than the default one in all cases. The new dirpref
will greatly improve untarring/removing/coping of big directories,
decrease load on cvs servers and much more. The new dirpref doesn't
speedup a compilation process, but also doesn't slow it down.
Obtained from: Grigoriy Orlov <gluk@ptci.ru>
2001-04-10 08:38:59 +00:00
|
|
|
fprintf(stderr, "\t-g average file size\n");
|
|
|
|
fprintf(stderr, "\t-h average files per directory\n");
|
1994-05-26 06:35:07 +00:00
|
|
|
fprintf(stderr, "\t-i number of bytes per inode\n");
|
2005-01-22 14:37:57 +00:00
|
|
|
fprintf(stderr, "\t-l enable multilabel MAC\n");
|
|
|
|
fprintf(stderr, "\t-n do not create .snap directory\n");
|
1994-05-26 06:35:07 +00:00
|
|
|
fprintf(stderr, "\t-m minimum free space %%\n");
|
|
|
|
fprintf(stderr, "\t-o optimization preference (`space' or `time')\n");
|
Enable operation of newfs on plain files, which is useful when you
want to prepare disk images for emulators (though 'makefs' in port
can do something similar).
This relies on:
+ minor changes to pass the consistency checks even when working on a file;
+ an additional option, '-p partition' , to specify the disk partition to
initialize;
+ some changes on the I/O routines to deal with partition offsets.
The latter was a bit tricky to implement, see the details in newfs.h:
in newfs, I/O is done through libufs which assumes that the file
descriptor refers to the whole partition. Introducing support for
the offset in libufs would require a non-backward compatible change
in the library, to be dealt with a version bump or with symbol
versioning.
I felt both approaches to be overkill for this specific application,
especially because there might be other changes to libufs that might
become necessary in the near future.
So I used the following trick:
- read access is always done by calling bread() directly, so we just add
the offset in the (few) places that call bread();
- write access is done through bwrite() and sbwrite(), which in turn
calls bwrite(). To avoid rewriting sbwrite(), we supply our own version
of bwrite() here, which takes precedence over the version in libufs.
MFC after: 4 weeks
2008-12-03 18:36:59 +00:00
|
|
|
fprintf(stderr, "\t-p partition name (a..h)\n");
|
2007-11-28 07:29:10 +00:00
|
|
|
fprintf(stderr, "\t-r reserved sectors at the end of device\n");
|
|
|
|
fprintf(stderr, "\t-s file system size (sectors)\n");
|
2010-12-29 12:31:18 +00:00
|
|
|
fprintf(stderr, "\t-t enable TRIM\n");
|
1994-05-26 06:35:07 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2010-03-09 10:31:03 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
expand_number_int(const char *buf, int *num)
|
|
|
|
{
|
|
|
|
int64_t num64;
|
|
|
|
int rval;
|
|
|
|
|
|
|
|
rval = expand_number(buf, &num64);
|
2010-03-09 19:31:08 +00:00
|
|
|
if (rval < 0)
|
2010-03-09 10:31:03 +00:00
|
|
|
return (rval);
|
2010-03-09 19:31:08 +00:00
|
|
|
if (num64 > INT_MAX || num64 < INT_MIN) {
|
2010-03-09 10:31:03 +00:00
|
|
|
errno = ERANGE;
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
*num = (int)num64;
|
|
|
|
return (0);
|
|
|
|
}
|