summaryrefslogtreecommitdiffstats
path: root/sbin/newfs/newfs.h
diff options
context:
space:
mode:
authorluigi <luigi@FreeBSD.org>2008-12-03 18:36:59 +0000
committerluigi <luigi@FreeBSD.org>2008-12-03 18:36:59 +0000
commit25cd12c1b2ca0757ebe329ef77becf7d56711cd2 (patch)
treec4b9b5c278df89601572732efb3483d2b101edfd /sbin/newfs/newfs.h
parent18b0226daa640e115ac2c6c817f884b4729095df (diff)
downloadFreeBSD-src-25cd12c1b2ca0757ebe329ef77becf7d56711cd2.zip
FreeBSD-src-25cd12c1b2ca0757ebe329ef77becf7d56711cd2.tar.gz
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
Diffstat (limited to 'sbin/newfs/newfs.h')
-rw-r--r--sbin/newfs/newfs.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/sbin/newfs/newfs.h b/sbin/newfs/newfs.h
index 5c428c4..0d7cb62 100644
--- a/sbin/newfs/newfs.h
+++ b/sbin/newfs/newfs.h
@@ -70,4 +70,20 @@ extern int avgfilesperdir; /* expected number of files per directory */
extern u_char *volumelabel; /* volume label for filesystem */
extern struct uufsd disk; /* libufs disk structure */
+/*
+ * To override a limitation in libufs, export the offset (in sectors) of the
+ * partition on the underlying media (file or disk). The value is used as
+ * an offset for all accesses to the media through bread(), which is only
+ * invoked directly in this program.
+ * For bwrite() we need a different approach, namely override the library
+ * version with one defined here. This is because bwrite() is called also
+ * by the library function sbwrite() which we cannot intercept nor want to
+ * rewrite. As a consequence, the internal version of bwrite() adds the
+ * partition offset itself when calling the underlying function, pwrite().
+ *
+ * XXX This info really ought to go into the struct uufsd, at which point
+ * we can remove the above hack.
+ */
+extern ufs2_daddr_t part_ofs; /* partition offset in blocks */
+
void mkfs (struct partition *, char *);
OpenPOWER on IntegriCloud