path: root/lib/libufs/libufs.h
Commit message (Collapse)AuthorAgeFilesLines
* Consolodate four copies of the STDSB define into a single place.Kirk McKusick2021-11-151-6/+0
| | | | | | | | | | | | | The STDSB macro is passed to the ffs_sbget() routine to fetch a UFS/FFS superblock "from the stadard place". It was identically defined in lib/libufs/libufs.h, stand/libsa/ufs.c, sys/ufs/ffs/ffs_extern.h, and sys/ufs/ffs/ffs_subr.c. Delete it from these four files and define it instead in sys/ufs/ffs/fs.h. All existing uses of this macro already include sys/ufs/ffs/fs.h so no include changes need to be made. No functional change intended. Sponsored by: Netflix
* Update the libufs cgget() and cgput() interfaces to have a similarKirk McKusick2020-09-191-2/+2
| | | | | | | | | | | | | | API to the sbget() and sbput() interfaces. Specifically they take a file descriptor pointer rather than the struct uufsd *disk pointer used by the libufs cgread() and cgwrite() interfaces. Update fsck_ffs to use these revised interfaces. No functional changes intended. Sponsored by: Netflix Notes: svn path=/head/; revision=365919
* The libufs library needs to track and free the new fs_si structureKirk McKusick2020-06-231-1/+1
| | | | | | | | | | in addition to the fs_csp structure that it references. PR: 247425 Sponsored by: Netflix Notes: svn path=/head/; revision=362559
* Align comments in struct uufsd structure. No semantic change.Kirk McKusick2020-06-231-20/+18
| | | | | | | Sponsored by: Netflix Notes: svn path=/head/; revision=362558
* Continuing efforts to provide hardening of FFS. This change adds aKirk McKusick2018-12-111-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | check hash to the filesystem inodes. Access attempts to files associated with an inode with an invalid check hash will fail with EINVAL (Invalid argument). Access is reestablished after an fsck is run to find and validate the inodes with invalid check-hashes. This check avoids a class of filesystem panics related to corrupted inodes. The hash is done using crc32c. Note this check-hash is for the inode itself and not any of its indirect blocks. Check-hash validation may be extended to also cover indirect block pointers, but that will be a separate (and more costly) feature. Check hashes are added only to UFS2 and not to UFS1 as UFS1 is primarily used in embedded systems with small memories and low-powered processors which need as light-weight a filesystem as possible. Reviewed by: kib Tested by: Peter Holm Sponsored by: Netflix Notes: svn path=/head/; revision=341836
* Normally when an attempt is made to mount a UFS/FFS filesystem whoseKirk McKusick2018-12-061-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | superblock has a check-hash error, an error message noting the superblock check-hash failure is printed and the mount fails. The administrator then runs fsck to repair the filesystem and when successful, the filesystem can once again be mounted. This approach fails if the filesystem in question is a root filesystem from which you are trying to boot. Here, the loader fails when trying to access the filesystem to get the kernel to boot. So it is necessary to allow the loader to ignore the superblock check-hash error and make a best effort to read the kernel. The filesystem may be suffiently corrupted that the read attempt fails, but there is no harm in trying since the loader makes no attempt to write to the filesystem. Once the kernel is loaded and starts to run, it attempts to mount its root filesystem. Once again, failure means that it breaks to its prompt to ask where to get its root filesystem. Unless you have an alternate root filesystem, you are stuck. Since the root filesystem is initially mounted read-only, it is safe to make an attempt to mount the root filesystem with the failed superblock check-hash. Thus, when asked to mount a root filesystem with a failed superblock check-hash, the kernel prints a warning message that the root filesystem superblock check-hash needs repair, but notes that it is ignoring the error and proceeding. It does mark the filesystem as needing an fsck which prevents it from being enabled for writing until fsck has been run on it. The net effect is that the reboot fails to single user, but at least at that point the administrator has the tools at hand to fix the problem. Reported by: Rick Macklem (rmacklem@) Discussed with: Warner Losh (imp@) Sponsored by: Netflix Notes: svn path=/head/; revision=341608
* In preparation for adding inode check-hashes, clean up andKirk McKusick2018-11-131-2/+7
| | | | | | | | | | | | | | | | | | | document the libufs interface for fetching and storing inodes. The undocumented getino / putino interface has been replaced with a new getinode / putinode interface. Convert the utilities that had been using the undocumented interface to use the new documented interface. No functional change (as for now the libufs library does not do inode check-hashes). Reviewed by: kib Tested by: Peter Holm Sponsored by: Netflix Notes: svn path=/head/; revision=340411
* Refactoring of reading and writing of the UFS/FFS superblock.Kirk McKusick2018-01-261-10/+17
| | | | | | | | | | | | | | | Specifically reading is done if ffs_sbget() and writing is done in ffs_sbput(). These functions are exported to libufs via the sbget() and sbput() functions which then used in the various filesystem utilities. This work is in preparation for adding subperblock check hashes. No functional change intended. Reviewed by: kib Notes: svn path=/head/; revision=328426
* Correct fsck journal-recovery code to update a cylinder-groupKirk McKusick2018-01-171-0/+2
| | | | | | | | | | | | | | | | | | | check-hash after making changes to the cylinder group. The problem was that the journal-recovery code was calling the libufs bwrite() function instead of the cgput() function. The cgput() function updates the cylinder-group check-hash before writing the cylinder group. This change required the additions of the cgget() and cgput() functions to the libufs API to avoid a gratuitous bcopy of every cylinder group to be read or written. These new functions have been added to the libufs manual pages. This was the first opportunity that I have had to use and document the use of the EDOOFUS error code. Reviewed by: kib Reported by: emaste and others Notes: svn path=/head/; revision=328092
* lib: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-261-1/+3
| | | | | | | | | | | | | | | Mainly focus on files that use BSD 2-Clause license, however the tool I was using mis-identified many licenses so this was mostly a manual - error prone - task. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Notes: svn path=/head/; revision=326219
* Continuing efforts to provide hardening of FFS, this change adds aKirk McKusick2017-09-221-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | check hash to cylinder groups. If a check hash fails when a cylinder group is read, no further allocations are attempted in that cylinder group until it has been fixed by fsck. This avoids a class of filesystem panics related to corrupted cylinder group maps. The hash is done using crc32c. Check hases are added only to UFS2 and not to UFS1 as UFS1 is primarily used in embedded systems with small memories and low-powered processors which need as light-weight a filesystem as possible. Specifics of the changes: sys/sys/buf.h: Add BX_FSPRIV to reserve a set of eight b_xflags that may be used by individual filesystems for their own purpose. Their specific definitions are found in the header files for each filesystem that uses them. Also add fields to struct buf as noted below. sys/kern/vfs_bio.c: It is only necessary to compute a check hash for a cylinder group when it is actually read from disk. When calling bread, you do not know whether the buffer was found in the cache or read. So a new flag (GB_CKHASH) and a pointer to a function to perform the hash has been added to breadn_flags to say that the function should be called to calculate a hash if the data has been read. The check hash is placed in b_ckhash and the B_CKHASH flag is set to indicate that a read was done and a check hash calculated. Though a rather elaborate mechanism, it should also work for check hashing other metadata in the future. A kernel internal API change was to change breada into a static fucntion and add flags and a function pointer to a check-hash function. sys/ufs/ffs/fs.h: Add flags for types of check hashes; stored in a new word in the superblock. Define corresponding BX_ flags for the different types of check hashes. Add a check hash word in the cylinder group. sys/ufs/ffs/ffs_alloc.c: In ffs_getcg do the dance with breadn_flags to get a check hash and if one is provided, check it. sys/ufs/ffs/ffs_vfsops.c: Copy across the BX_FFSTYPES flags in background writes. Update the check hash when writing out buffers that need them. sys/ufs/ffs/ffs_snapshot.c: Recompute check hash when updating snapshot cylinder groups. sys/libkern/crc32.c: lib/libufs/Makefile: lib/libufs/libufs.h: lib/libufs/cgroup.c: Include libkern/crc32.c in libufs and use it to compute check hashes when updating cylinder groups. Four utilities are affected: sbin/newfs/mkfs.c: Add the check hashes when building the cylinder groups. sbin/fsck_ffs/fsck.h: sbin/fsck_ffs/fsutil.c: Verify and update check hashes when checking and writing cylinder groups. sbin/fsck_ffs/pass5.c: Offer to add check hashes to existing filesystems. Precompute check hashes when rebuilding cylinder group (although this will be done when it is written in fsutil.c it is necessary to do it early before comparing with the old cylinder group) sbin/dumpfs/dumpfs.c Print out the new check hash flag(s) sbin/fsdb/Makefile: Needs to add libufs now used by pass5.c imported from fsck_ffs. Reviewed by: kib Tested by: Peter Holm (pho) Notes: svn path=/head/; revision=323923
* Commit the 64-bit inode project.Konstantin Belousov2017-05-231-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Extend the ino_t, dev_t, nlink_t types to 64-bit ints. Modify struct dirent layout to add d_off, increase the size of d_fileno to 64-bits, increase the size of d_namlen to 16-bits, and change the required alignment. Increase struct statfs f_mntfromname[] and f_mntonname[] array length MNAMELEN to 1024. ABI breakage is mitigated by providing compatibility using versioned symbols, ingenious use of the existing padding in structures, and by employing other tricks. Unfortunately, not everything can be fixed, especially outside the base system. For instance, third-party APIs which pass struct stat around are broken in backward and forward incompatible ways. Kinfo sysctl MIBs ABI is changed in backward-compatible way, but there is no general mechanism to handle other sysctl MIBS which return structures where the layout has changed. It was considered that the breakage is either in the management interfaces, where we usually allow ABI slip, or is not important. Struct xvnode changed layout, no compat shims are provided. For struct xtty, dev_t tty device member was reduced to uint32_t. It was decided that keeping ABI compat in this case is more useful than reporting 64-bit dev_t, for the sake of pstat. Update note: strictly follow the instructions in UPDATING. Build and install the new kernel with COMPAT_FREEBSD11 option enabled, then reboot, and only then install new world. Credits: The 64-bit inode project, also known as ino64, started life many years ago as a project by Gleb Kurtsou (gleb). Kirk McKusick (mckusick) then picked up and updated the patch, and acted as a flag-waver. Feedback, suggestions, and discussions were carried by Ed Maste (emaste), John Baldwin (jhb), Jilles Tjoelker (jilles), and Rick Macklem (rmacklem). Kris Moore (kris) performed an initial ports investigation followed by an exp-run by Antoine Brodin (antoine). Essential and all-embracing testing was done by Peter Holm (pho). The heavy lifting of coordinating all these efforts and bringing the project to completion were done by Konstantin Belousov (kib). Sponsored by: The FreeBSD Foundation (emaste, kib) Differential revision: https://reviews.freebsd.org/D10439 Notes: svn path=/head/; revision=318736
* Replace ERROR() macro with inline function. In-tree gcc cannot tolerateKonstantin Belousov2011-02-121-28/+24
| | | | | | | | | | | | | the construct like printf("%\s", NULL) resulting from macroexpand of ERROR(u, NULL), making it impossible to use LIBUFS_DEBUGGING. With inline function, compiler cannot detect the NULL argument to known function and does not try to convert it into puts(). In collaboration with: pho Notes: svn path=/head/; revision=218601
* - Merge soft-updates journaling from projects/suj/head into head. ThisJeff Roberson2010-04-241-0/+16
| | | | | | | | | | | brings in support for an optional intent log which eliminates the need for background fsck on unclean shutdown. Sponsored by: iXsystems, Yahoo!, and Juniper. With help from: McKusick and Peter Holm Notes: svn path=/head/; revision=207141
* Add a berase() function which uses ioctl(DIOCGDELETE) to erase a slabPoul-Henning Kamp2007-12-161-0/+1
| | | | | | | of the disk. Notes: svn path=/head/; revision=174668
* Implement cgwrite1(3) function which stored a given cylinder group on disk.Pawel Jakub Dawidek2006-10-311-0/+1
| | | | | | | Sponsored by: home.pl Notes: svn path=/head/; revision=163835
* Remove ufs_disk_ctor and ufs_disk_dtor, they never came to fruition. I doJuli Mallett2003-06-091-2/+0
| | | | | | | | not know of any software using them, and there is no "published API" for libufs, as it were. Notes: svn path=/head/; revision=116086
* API for opening (and tracking) writable file descriptors per disk.Juli Mallett2003-01-291-0/+1
| | | | Notes: svn path=/head/; revision=110066
* API to fillout a blank disk. For e.g. newfs.Juli Mallett2003-01-231-0/+1
| | | | Notes: svn path=/head/; revision=109755
* Store not only the current cylinder group in the series (i.e. next that needsJuli Mallett2003-01-191-0/+1
| | | | | | | | to be read in) but also the last cylinder group in the series (i.e. what is stored in the structure). Notes: svn path=/head/; revision=109518
* Add facility to read one, or a string of, cylinger groups.Juli Mallett2003-01-191-0/+13
| | | | Notes: svn path=/head/; revision=109509
* Hunt for a disk to operate on, if we're passed a partition mountpoint, etc.Juli Mallett2003-01-191-0/+1
| | | | | | | Concept reviewed by: phk Notes: svn path=/head/; revision=109506
* Fix typo.Juli Mallett2003-01-181-1/+1
| | | | Notes: svn path=/head/; revision=109464
* Nuke dumb error reporting code, people can just use disk::d_error. Unify theJuli Mallett2003-01-181-7/+8
| | | | | | | | DEBUG and d_error initialisation into an ERROR macro, which can both trace and set the d_error field. Much a more meaningful thing, I should say. Notes: svn path=/head/; revision=109462
* Add the concept of a per-disk error string, and a function which prints itJuli Mallett2002-10-221-0/+6
| | | | | | | along with the errno, if one is set. Notes: svn path=/head/; revision=105737
* Wrap the header to prevent multiple inclusion, and mark the DECLS section.Juli Mallett2002-08-221-0/+9
| | | | | | | Reminded by: Rachel Hestilow <hestilow@ximian.com> Notes: svn path=/head/; revision=102296
* Add libufs, a library for dealing with UFS filesystems from userland toJuli Mallett2002-07-011-0/+104
the build. It is here to compartmentalise functionality currently duplicated in many notable programs in the base system. It currently handles block reads and writes, as well as reading and writing of the filesystem superblock, and the reading/lookup of inode data. It supports both UFS and UFS2. I will be maintaining it, and porting programs to use it, however for now, it is simply being built as part of world. Notes: svn path=/head/; revision=99193