summaryrefslogtreecommitdiffstats
path: root/sbin/newfs
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/newfs')
-rw-r--r--sbin/newfs/mkfs.c2
-rw-r--r--sbin/newfs/newfs.83
-rw-r--r--sbin/newfs/newfs.c20
-rw-r--r--sbin/newfs/newfs.h2
4 files changed, 25 insertions, 2 deletions
diff --git a/sbin/newfs/mkfs.c b/sbin/newfs/mkfs.c
index 4b78f9b..de8140f 100644
--- a/sbin/newfs/mkfs.c
+++ b/sbin/newfs/mkfs.c
@@ -140,6 +140,8 @@ mkfs(struct partition *pp, char *fsys)
sblock.fs_flags = 0;
if (Uflag)
sblock.fs_flags |= FS_DOSOFTDEP;
+ if (Lflag)
+ strlcpy(sblock.fs_volname, volumelabel, MAXVOLLEN);
/*
* Validate the given file system size.
* Verify that its last block can actually be accessed.
diff --git a/sbin/newfs/newfs.8 b/sbin/newfs/newfs.8
index da0ff2a..7f10c72 100644
--- a/sbin/newfs/newfs.8
+++ b/sbin/newfs/newfs.8
@@ -40,6 +40,7 @@
.Nd construct a new file system
.Sh SYNOPSIS
.Nm
+.Op Fl L Ar volname
.Op Fl NU
.Op Fl O Ar filesystem-type
.Op Fl S Ar sector-size
@@ -82,6 +83,8 @@ The following options define the general layout policies:
.Bl -tag -width indent
.It Fl T Ar disktype
For backward compatibility.
+.It Fl L Ar volname
+Add a volume label to the new file system.
.It Fl N
Cause the file system parameters to be printed out
without really creating the file system.
diff --git a/sbin/newfs/newfs.c b/sbin/newfs/newfs.c
index 50034a2..75832b3 100644
--- a/sbin/newfs/newfs.c
+++ b/sbin/newfs/newfs.c
@@ -117,6 +117,7 @@ static const char rcsid[] =
*/
#define NFPI 4
+int Lflag; /* add a volume label */
int Nflag; /* run without writing file system */
int Oflag = 1; /* file system format (1 => UFS1, 2 => UFS2) */
int Rflag; /* regression test */
@@ -136,6 +137,7 @@ 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 */
int fso; /* filedescriptor to device */
+u_char *volumelabel = NULL; /* volume label for filesystem */
static char device[MAXPATHLEN];
static char *disktype;
@@ -153,12 +155,25 @@ main(int argc, char *argv[])
struct partition oldpartition;
struct stat st;
char *cp, *special;
- int ch;
+ int ch, i;
off_t mediasize;
while ((ch = getopt(argc, argv,
- "NO:RS:T:Ua:b:c:d:e:f:g:h:i:m:o:s:")) != -1)
+ "L:NO:RS:T:Ua:b:c:d:e:f:g:h:i:m:o:s:")) != -1)
switch (ch) {
+ 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;
case 'N':
Nflag = 1;
break;
@@ -390,6 +405,7 @@ usage()
getprogname(),
" [device-type]");
fprintf(stderr, "where fsoptions are:\n");
+ fprintf(stderr, "\t-L volume label to add to superblock\n");
fprintf(stderr,
"\t-N do not create file system, just print out parameters\n");
fprintf(stderr, "\t-O file system format: 1 => UFS1, 2 => UFS2\n");
diff --git a/sbin/newfs/newfs.h b/sbin/newfs/newfs.h
index fb32a62..60347f3 100644
--- a/sbin/newfs/newfs.h
+++ b/sbin/newfs/newfs.h
@@ -49,6 +49,7 @@
/*
* variables set up by front end.
*/
+extern int Lflag; /* add a volume label */
extern int Nflag; /* run mkfs without writing file system */
extern int Oflag; /* build UFS1 format file system */
extern int Rflag; /* regression test */
@@ -68,5 +69,6 @@ extern int maxbpg; /* maximum blocks per file in a cyl group */
extern int avgfilesize; /* expected average file size */
extern int avgfilesperdir; /* expected number of files per directory */
extern int fso; /* filedescriptor to device */
+extern u_char *volumelabel; /* volume label for filesystem */
void mkfs (struct partition *, char *);
OpenPOWER on IntegriCloud