diff options
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/arp/arp.c | 32 | ||||
-rw-r--r-- | usr.sbin/arp/arp.h | 9 | ||||
-rw-r--r-- | usr.sbin/arp/arp_netlink.c | 20 | ||||
-rw-r--r-- | usr.sbin/bluetooth/rtlbtfw/main.c | 3 | ||||
-rw-r--r-- | usr.sbin/bluetooth/rtlbtfw/rtlbtfw.conf | 10 | ||||
-rw-r--r-- | usr.sbin/bsdinstall/partedit/part_wizard.c | 25 | ||||
-rw-r--r-- | usr.sbin/quot/Makefile | 8 | ||||
-rw-r--r-- | usr.sbin/quot/quot.8 | 9 | ||||
-rw-r--r-- | usr.sbin/quot/quot.c | 320 | ||||
-rw-r--r-- | usr.sbin/quot/tests/Makefile | 4 | ||||
-rw-r--r-- | usr.sbin/quot/tests/quot_test.sh | 102 | ||||
-rw-r--r-- | usr.sbin/unbound/Makefile.inc | 2 |
12 files changed, 287 insertions, 257 deletions
diff --git a/usr.sbin/arp/arp.c b/usr.sbin/arp/arp.c index ee4236b5299b..055ef2ffe225 100644 --- a/usr.sbin/arp/arp.c +++ b/usr.sbin/arp/arp.c @@ -81,7 +81,6 @@ static int get(char *host); static int file(char *name); static struct rt_msghdr *rtmsg(int cmd, struct sockaddr_in *dst, struct sockaddr_dl *sdl); -static int get_ether_addr(in_addr_t ipaddr, struct ether_addr *hwaddr); static int set_rtsock(struct sockaddr_in *dst, struct sockaddr_dl *sdl_m, char *host); @@ -143,7 +142,8 @@ main(int argc, char *argv[]) if (!func) func = F_GET; if (opts.rifname) { - if (func != F_GET && func != F_SET && !(func == F_DELETE && opts.aflag)) + if (func != F_GET && func != F_SET && func != F_REPLACE && + !(func == F_DELETE && opts.aflag)) xo_errx(1, "-i not applicable to this operation"); if ((opts.rifindex = if_nametoindex(opts.rifname)) == 0) { if (errno == ENXIO) @@ -273,7 +273,6 @@ getaddr(char *host) return (&reply); } -int valid_type(int type); /* * Returns true if the type is a valid one for ARP. */ @@ -357,11 +356,14 @@ set(int argc, char **argv) } ea = (struct ether_addr *)LLADDR(&sdl_m); if ((opts.flags & RTF_ANNOUNCE) && !strcmp(eaddr, "auto")) { - if (!get_ether_addr(dst->sin_addr.s_addr, ea)) { + uint32_t ifindex; + if (!get_ifinfo(dst->sin_addr.s_addr, ea, &ifindex)) { xo_warnx("no interface found for %s", - inet_ntoa(dst->sin_addr)); + inet_ntoa(dst->sin_addr)); return (1); } + if (opts.rifindex == 0) + opts.rifindex = ifindex; sdl_m.sdl_alen = ETHER_ADDR_LEN; } else { struct ether_addr *ea1 = ether_aton(eaddr); @@ -375,7 +377,7 @@ set(int argc, char **argv) } } #ifndef WITHOUT_NETLINK - return (set_nl(opts.rifindex, dst, &sdl_m, host)); + return (set_nl(dst, &sdl_m, host)); #else return (set_rtsock(dst, &sdl_m, host)); #endif @@ -522,7 +524,7 @@ delete(char *host) #ifdef WITHOUT_NETLINK return (delete_rtsock(host)); #else - return (delete_nl(0, host)); + return (delete_nl(host)); #endif } @@ -819,11 +821,11 @@ doit: } /* - * get_ether_addr - get the hardware address of an interface on the - * same subnet as ipaddr. + * get_ifinfo - get the hardware address and if_index of an interface + * on the same subnet as ipaddr. */ -static int -get_ether_addr(in_addr_t ipaddr, struct ether_addr *hwaddr) +int +get_ifinfo(in_addr_t ipaddr, struct ether_addr *hwaddr, uint32_t *pifindex) { struct ifaddrs *ifa, *ifd, *ifas = NULL; in_addr_t ina, mask; @@ -862,7 +864,13 @@ get_ether_addr(in_addr_t ipaddr, struct ether_addr *hwaddr) } if (ifa == NULL) goto done; - + if (pifindex != NULL) + *pifindex = if_nametoindex(ifa->ifa_name); + if (hwaddr == NULL) { + /* ether addr is not required */ + retval = ETHER_ADDR_LEN; + goto done; + } /* * Now scan through again looking for a link-level address * for this interface. diff --git a/usr.sbin/arp/arp.h b/usr.sbin/arp/arp.h index 487863be43e7..512a238df425 100644 --- a/usr.sbin/arp/arp.h +++ b/usr.sbin/arp/arp.h @@ -2,8 +2,8 @@ #define _USR_SBIN_ARP_ARP_H_ int valid_type(int type); +int get_ifinfo(in_addr_t ipaddr, struct ether_addr *hwaddr, uint32_t *pifindex); struct sockaddr_in *getaddr(char *host); -int print_entries_nl(uint32_t ifindex, struct in_addr addr); struct arp_opts { bool aflag; @@ -11,13 +11,12 @@ struct arp_opts { time_t expire_time; int flags; char *rifname; - unsigned int rifindex; + uint32_t rifindex; }; extern struct arp_opts opts; int print_entries_nl(uint32_t ifindex, struct in_addr addr); -int delete_nl(uint32_t ifindex, char *host); -int set_nl(uint32_t ifindex, struct sockaddr_in *dst, struct sockaddr_dl *sdl, - char *host); +int delete_nl(char *host); +int set_nl(struct sockaddr_in *dst, struct sockaddr_dl *sdl, char *host); #endif diff --git a/usr.sbin/arp/arp_netlink.c b/usr.sbin/arp/arp_netlink.c index db1ef775dea2..34f21cf96f4f 100644 --- a/usr.sbin/arp/arp_netlink.c +++ b/usr.sbin/arp/arp_netlink.c @@ -79,13 +79,15 @@ get_link_info(struct snl_state *ss, uint32_t ifindex, static bool -has_l2(struct snl_state *ss, uint32_t ifindex) +has_l2(struct snl_state *ss, uint32_t ifindex, uint32_t *pflags) { struct snl_parsed_link_simple link = {}; + *pflags = 0; if (!get_link_info(ss, ifindex, &link)) return (false); + *pflags = link.ifi_flags; return (valid_type(link.ifi_type) != 0); } @@ -104,6 +106,7 @@ static int guess_ifindex(struct snl_state *ss, uint32_t fibnum, struct in_addr addr) { struct snl_writer nw; + uint32_t ifindex, ifflags; snl_init_writer(ss, &nw); @@ -133,9 +136,16 @@ guess_ifindex(struct snl_state *ss, uint32_t fibnum, struct in_addr addr) return (0); /* Check if the interface is of supported type */ - if (has_l2(ss, r.rta_oif)) + if (has_l2(ss, r.rta_oif, &ifflags)) return (r.rta_oif); + /* Check if we are doing proxy arp for P2P interface */ + if (ifflags & IFF_POINTOPOINT) { + /* Guess interface by dst prefix */ + if (get_ifinfo(addr.s_addr, NULL, &ifindex)) + return (ifindex); + } + /* Check the case when we matched the loopback route for P2P */ snl_init_writer(ss, &nw); hdr = snl_create_msg_request(&nw, RTM_GETNEXTHOP); @@ -326,11 +336,12 @@ print_entries_nl(uint32_t ifindex, struct in_addr addr) } int -delete_nl(uint32_t ifindex, char *host) +delete_nl(char *host) { struct snl_state ss = {}; struct snl_writer nw; struct sockaddr_in *dst; + uint32_t ifindex = opts.rifindex; dst = getaddr(host); if (dst == NULL) @@ -375,10 +386,11 @@ delete_nl(uint32_t ifindex, char *host) } int -set_nl(uint32_t ifindex, struct sockaddr_in *dst, struct sockaddr_dl *sdl, char *host) +set_nl(struct sockaddr_in *dst, struct sockaddr_dl *sdl, char *host) { struct snl_state ss = {}; struct snl_writer nw; + uint32_t ifindex = opts.rifindex; nl_init_socket(&ss); diff --git a/usr.sbin/bluetooth/rtlbtfw/main.c b/usr.sbin/bluetooth/rtlbtfw/main.c index e87a98036265..280045a6aa25 100644 --- a/usr.sbin/bluetooth/rtlbtfw/main.c +++ b/usr.sbin/bluetooth/rtlbtfw/main.c @@ -64,9 +64,6 @@ static struct rtlbt_devid rtlbt_list[] = { { .vendor_id = 0x0bda, .product_id = 0xb00c }, { .vendor_id = 0x0bda, .product_id = 0xc822 }, - /* Realtek 8822CU Bluetooth devices */ - { .vendor_id = 0x13d3, .product_id = 0x3549 }, - /* Realtek 8851BE Bluetooth devices */ { .vendor_id = 0x13d3, .product_id = 0x3600 }, diff --git a/usr.sbin/bluetooth/rtlbtfw/rtlbtfw.conf b/usr.sbin/bluetooth/rtlbtfw/rtlbtfw.conf index 61ae53db8f39..2ef56d2af93a 100644 --- a/usr.sbin/bluetooth/rtlbtfw/rtlbtfw.conf +++ b/usr.sbin/bluetooth/rtlbtfw/rtlbtfw.conf @@ -36,16 +36,6 @@ notify 100 { action "/usr/sbin/rtlbtfw -d $cdev -f /usr/local/share/rtlbt-firmware"; }; -# Realtek 8822CU Bluetooth devices -notify 100 { - match "system" "USB"; - match "subsystem" "DEVICE"; - match "type" "ATTACH"; - match "vendor" "0x13d3"; - match "product" "0x3549"; - action "/usr/sbin/rtlbtfw -d $cdev -f /usr/local/share/rtlbt-firmware"; -}; - # Realtek 8851BE Bluetooth devices notify 100 { match "system" "USB"; diff --git a/usr.sbin/bsdinstall/partedit/part_wizard.c b/usr.sbin/bsdinstall/partedit/part_wizard.c index 90a8da1c3c9b..9146a2af782f 100644 --- a/usr.sbin/bsdinstall/partedit/part_wizard.c +++ b/usr.sbin/bsdinstall/partedit/part_wizard.c @@ -27,6 +27,7 @@ */ #include <sys/param.h> +#include <sys/sysctl.h> #include <errno.h> #include <inttypes.h> @@ -34,6 +35,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> #include <libgeom.h> #include <bsddialog.h> @@ -41,10 +43,29 @@ #include "partedit.h" #define MIN_FREE_SPACE (1023*1024*1024) /* Just under 1 GB */ -#define SWAP_SIZE(available) MIN(available/20, 4*1024*1024*1024LL) static char *wizard_partition(struct gmesh *mesh, const char *disk); +/* + * Determine default swap (partition) size in bytes for a given amount of free + * disk space in bytes. The algorithm should likely be revisited in light of + * contemporary memory and disk sizes. + */ +static intmax_t +swap_size(intmax_t available) +{ + intmax_t swapsize; + unsigned long swap_maxpages; + size_t sz; + + swapsize = MIN(available/20, 4*1024*1024*1024LL); + sz = sizeof(swap_maxpages); + if (sysctlbyname("vm.swap_maxpages", &swap_maxpages, &sz, NULL, 0) == 0) + swapsize = MIN(swapsize, (intmax_t)swap_maxpages * getpagesize()); + + return (swapsize); +} + int part_wizard(const char *fsreq) { @@ -383,7 +404,7 @@ wizard_makeparts(struct gmesh *mesh, const char *disk, const char *fstype, return (!retval); /* Editor -> return 0 */ } - swapsize = SWAP_SIZE(available); + swapsize = swap_size(available); humanize_number(swapsizestr, 7, swapsize, "B", HN_AUTOSCALE, HN_NOSPACE | HN_DECIMAL); humanize_number(rootsizestr, 7, available - swapsize - 1024*1024, diff --git a/usr.sbin/quot/Makefile b/usr.sbin/quot/Makefile index ed8360ae938e..2f32c8f2df8b 100644 --- a/usr.sbin/quot/Makefile +++ b/usr.sbin/quot/Makefile @@ -1,7 +1,9 @@ +.include <src.opts.mk> + PROG= quot MAN= quot.8 -LIBADD= ufs - -WARNS?= 2 +LIBADD= ufs util +HAS_TESTS= +SUBDIR.${MK_TESTS}= tests .include <bsd.prog.mk> diff --git a/usr.sbin/quot/quot.8 b/usr.sbin/quot/quot.8 index 81abe28b41d5..32e666e2a863 100644 --- a/usr.sbin/quot/quot.8 +++ b/usr.sbin/quot/quot.8 @@ -27,7 +27,7 @@ .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" -.Dd February 8, 1994 +.Dd October 15, 2025 .Dt QUOT 8 .Os .Sh NAME @@ -35,7 +35,7 @@ .Nd display disk space occupied by each user .Sh SYNOPSIS .Nm -.Op Fl cfhknv +.Op Fl cfknv .Op Fl a | Ar filesystem ... .Sh DESCRIPTION The @@ -53,11 +53,6 @@ number of files in this category, and aggregate total of blocks in files with this or lower size. .It Fl f For each user, display count of files and space occupied. -.It Fl h -Estimate the number of blocks in each file based on its size. -Despite that this does not give the correct results (it does not -account for the holes in files), this option is not any faster -and thus is discouraged. .It Fl k Force the numbers to be reported in kilobyte counts. By default, all sizes are reported in 512-byte block counts. diff --git a/usr.sbin/quot/quot.c b/usr.sbin/quot/quot.c index 4152c498371a..879580f649b9 100644 --- a/usr.sbin/quot/quot.c +++ b/usr.sbin/quot/quot.c @@ -32,19 +32,21 @@ */ #include <sys/param.h> -#include <sys/stdint.h> #include <sys/mount.h> #include <sys/disklabel.h> #include <ufs/ufs/dinode.h> #include <ufs/ffs/fs.h> #include <err.h> +#include <errno.h> #include <fcntl.h> #include <fstab.h> -#include <errno.h> #include <libufs.h> +#include <mntopts.h> #include <paths.h> #include <pwd.h> +#include <stdbool.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -52,16 +54,16 @@ #include <unistd.h> /* some flags of what to do: */ -static char estimate; -static char count; -static char unused; -static void (*func)(int, struct fs *, char *); +static bool all; +static bool count; +static bool noname; +static bool unused; +static void (*func)(int, struct fs *); static long blocksize; static char *header; static int headerlen; static union dinode *get_inode(int, struct fs *, ino_t); -static int virtualblocks(struct fs *, union dinode *); static int isfree(struct fs *, union dinode *); static void inituser(void); static void usrrehash(void); @@ -69,9 +71,9 @@ static struct user *user(uid_t); static int cmpusers(const void *, const void *); static void uses(uid_t, daddr_t, time_t); static void initfsizes(void); -static void dofsizes(int, struct fs *, char *); -static void douser(int, struct fs *, char *); -static void donames(int, struct fs *, char *); +static void dofsizes(int, struct fs *); +static void douser(int, struct fs *); +static void donames(int, struct fs *); static void usage(void); static void quot(char *, char *); @@ -86,11 +88,7 @@ static void quot(char *, char *); * Due to the size of modern disks, we must cast intermediate * values to 64 bits to prevent potential overflows. */ -#ifdef COMPAT -#define SIZE(n) (n) -#else -#define SIZE(n) ((int)(((quad_t)(n) * 512 + blocksize - 1)/blocksize)) -#endif +#define SIZE(n) ((int)(((intmax_t)(n) * 512 + blocksize - 1) / blocksize)) #define INOCNT(fs) ((fs)->fs_ipg) #define INOSZ(fs) \ @@ -104,29 +102,26 @@ static void quot(char *, char *); static union dinode * get_inode(int fd, struct fs *super, ino_t ino) { - static caddr_t ipbuf; + static union dinode *ipbuf; static struct cg *cgp; static ino_t last; - static int cg; + static unsigned long cg; struct ufs2_dinode *di2; + off_t off; if (fd < 0) { /* flush cache */ - if (ipbuf) { - free(ipbuf); - ipbuf = 0; - if (super != NULL && super->fs_magic == FS_UFS2_MAGIC) { - free(cgp); - cgp = 0; - } - } - return 0; + free(ipbuf); + ipbuf = NULL; + free(cgp); + cgp = NULL; + return (NULL); } - if (!ipbuf || ino < last || ino >= last + INOCNT(super)) { + if (ipbuf == NULL || ino < last || ino >= last + INOCNT(super)) { if (super->fs_magic == FS_UFS2_MAGIC && - (!cgp || cg != ino_to_cg(super, ino))) { + (cgp == NULL || cg != ino_to_cg(super, ino))) { cg = ino_to_cg(super, ino); - if (!cgp && !(cgp = malloc(super->fs_cgsize))) + if (cgp == NULL && (cgp = malloc(super->fs_cgsize)) == NULL) errx(1, "allocate cg"); if (lseek(fd, (off_t)cgtod(super, cg) << super->fs_fshift, 0) < 0) err(1, "lseek cg"); @@ -135,12 +130,12 @@ get_inode(int fd, struct fs *super, ino_t ino) if (!cg_chkmagic(cgp)) errx(1, "cg has bad magic"); } - if (!ipbuf - && !(ipbuf = malloc(INOSZ(super)))) + if (ipbuf == NULL && (ipbuf = malloc(INOSZ(super))) == NULL) errx(1, "allocate inodes"); last = rounddown(ino, INOCNT(super)); - if (lseek(fd, (off_t)ino_to_fsba(super, last) << super->fs_fshift, 0) < (off_t)0 - || read(fd, ipbuf, INOSZ(super)) != (ssize_t)INOSZ(super)) + off = (off_t)ino_to_fsba(super, last) << super->fs_fshift; + if (lseek(fd, off, SEEK_SET) != off || + read(fd, ipbuf, INOSZ(super)) != (ssize_t)INOSZ(super)) err(1, "read inodes"); } @@ -150,55 +145,13 @@ get_inode(int fd, struct fs *super, ino_t ino) di2 = &((struct ufs2_dinode *)ipbuf)[ino % INOCNT(super)]; /* If the inode is unused, it might be unallocated too, so zero it. */ if (isclr(cg_inosused(cgp), ino % super->fs_ipg)) - bzero(di2, sizeof (*di2)); + memset(di2, 0, sizeof(*di2)); return ((union dinode *)di2); } -#ifdef COMPAT -#define actualblocks(fs, dp) (DIP(fs, dp, di_blocks) / 2) -#else -#define actualblocks(fs, dp) DIP(fs, dp, di_blocks) -#endif - -static int virtualblocks(struct fs *super, union dinode *dp) -{ - off_t nblk, sz; - - sz = DIP(super, dp, di_size); -#ifdef COMPAT - if (lblkno(super,sz) >= UFS_NDADDR) { - nblk = blkroundup(super,sz); - if (sz == nblk) - nblk += super->fs_bsize; - } - - return sz / 1024; - -#else /* COMPAT */ - - if (lblkno(super,sz) >= UFS_NDADDR) { - nblk = blkroundup(super,sz); - sz = lblkno(super,nblk); - sz = (sz - UFS_NDADDR + NINDIR(super) - 1) / NINDIR(super); - while (sz > 0) { - nblk += sz * super->fs_bsize; - /* sz - 1 rounded up */ - sz = (sz - 1 + NINDIR(super) - 1) / NINDIR(super); - } - } else - nblk = fragroundup(super,sz); - - return nblk / 512; -#endif /* COMPAT */ -} - static int isfree(struct fs *super, union dinode *dp) { -#ifdef COMPAT - return (DIP(super, dp, di_mode) & IFMT) == 0; -#else /* COMPAT */ - switch (DIP(super, dp, di_mode) & IFMT) { case IFIFO: case IFLNK: /* should check FASTSYMLINK? */ @@ -214,7 +167,6 @@ isfree(struct fs *super, union dinode *dp) default: errx(1, "unknown IFMT 0%o", DIP(super, dp, di_mode) & IFMT); } -#endif } static struct user { @@ -234,10 +186,9 @@ inituser(void) int i; struct user *usr; - if (!nusers) { + if (nusers == 0) { nusers = 8; - if (!(users = - (struct user *)calloc(nusers,sizeof(struct user)))) + if ((users = calloc(nusers, sizeof(*users))) == NULL) errx(1, "allocate users"); } else { for (usr = users, i = nusers; --i >= 0; usr++) { @@ -255,14 +206,13 @@ usrrehash(void) struct user *svusr; svusr = users; - nusers <<= 1; - if (!(users = (struct user *)calloc(nusers,sizeof(struct user)))) + nusers *= 2; + if ((users = calloc(nusers, sizeof(*users))) == NULL) errx(1, "allocate users"); - for (usr = svusr, i = nusers >> 1; --i >= 0; usr++) { - for (usrn = users + (usr->uid&(nusers - 1)); usrn->name; - usrn--) { + for (usr = svusr, i = nusers / 2; --i >= 0; usr++) { + for (usrn = users + usr->uid % nusers; usrn->name; usrn--) { if (usrn <= users) - usrn = users + nusers; + usrn += nusers; } *usrn = *usr; } @@ -272,33 +222,24 @@ static struct user * user(uid_t uid) { struct user *usr; - int i; struct passwd *pwd; + int i; while (1) { - for (usr = users + (uid&(nusers - 1)), i = nusers; --i >= 0; - usr--) { - if (!usr->name) { + for (usr = users + uid % nusers, i = nusers; --i >= 0; usr--) { + if (usr->name == NULL) { usr->uid = uid; - - if (!(pwd = getpwuid(uid))) { - if ((usr->name = (char *)malloc(7))) - sprintf(usr->name,"#%d",uid); - } else { - if ((usr->name = (char *) - malloc(strlen(pwd->pw_name) + 1))) - strcpy(usr->name,pwd->pw_name); - } - if (!usr->name) + if (noname || (pwd = getpwuid(uid)) == NULL) + asprintf(&usr->name, "#%u", uid); + else + usr->name = strdup(pwd->pw_name); + if (usr->name == NULL) errx(1, "allocate users"); - - return usr; - - } else if (usr->uid == uid) - return usr; - + } + if (usr->uid == uid) + return (usr); if (usr <= users) - usr = users + nusers; + usr += nusers; } usrrehash(); } @@ -307,15 +248,16 @@ user(uid_t uid) static int cmpusers(const void *v1, const void *v2) { - const struct user *u1, *u2; - u1 = (const struct user *)v1; - u2 = (const struct user *)v2; + const struct user *u1 = v1, *u2 = v2; - return u2->space - u1->space; + return (u2->space > u1->space ? 1 : + u2->space < u1->space ? -1 : + u1->uid > u2->uid ? 1 : + u1->uid < u2->uid ? -1 : 0); } -#define sortusers(users) (qsort((users),nusers,sizeof(struct user), \ - cmpusers)) +#define sortusers(users) \ + qsort((users), nusers, sizeof(struct user), cmpusers) static void uses(uid_t uid, daddr_t blks, time_t act) @@ -338,12 +280,8 @@ uses(uid_t uid, daddr_t blks, time_t act) usr->spc30 += blks; } -#ifdef COMPAT -#define FSZCNT 500 -#else #define FSZCNT 512 -#endif -struct fsizes { +static struct fsizes { struct fsizes *fsz_next; daddr_t fsz_first, fsz_last; ino_t fsz_count[FSZCNT]; @@ -365,7 +303,7 @@ initfsizes(void) } static void -dofsizes(int fd, struct fs *super, char *name) +dofsizes(int fd, struct fs *super) { ino_t inode, maxino; union dinode *dp; @@ -374,39 +312,18 @@ dofsizes(int fd, struct fs *super, char *name) int i; maxino = super->fs_ncg * super->fs_ipg - 1; -#ifdef COMPAT - if (!(fsizes = (struct fsizes *)malloc(sizeof(struct fsizes)))) - errx(1, "allocate fsize structure"); -#endif /* COMPAT */ for (inode = 0; inode < maxino; inode++) { - errno = 0; - if ((dp = get_inode(fd,super,inode)) -#ifdef COMPAT - && ((DIP(super, dp, di_mode) & IFMT) == IFREG - || (DIP(super, dp, di_mode) & IFMT) == IFDIR) -#else /* COMPAT */ - && !isfree(super, dp) -#endif /* COMPAT */ + if ((dp = get_inode(fd, super, inode)) != NULL && + !isfree(super, dp) ) { - sz = estimate ? virtualblocks(super, dp) : - actualblocks(super, dp); -#ifdef COMPAT - if (sz >= FSZCNT) { - fsizes->fsz_count[FSZCNT-1]++; - fsizes->fsz_sz[FSZCNT-1] += sz; - } else { - fsizes->fsz_count[sz]++; - fsizes->fsz_sz[sz] += sz; - } -#else /* COMPAT */ + sz = DIP(super, dp, di_blocks); ksz = SIZE(sz); for (fsp = &fsizes; (fp = *fsp); fsp = &fp->fsz_next) { if (ksz < fp->fsz_last) break; } - if (!fp || ksz < fp->fsz_first) { - if (!(fp = (struct fsizes *) - malloc(sizeof(struct fsizes)))) + if (fp == NULL || ksz < fp->fsz_first) { + if ((fp = malloc(sizeof(*fp))) == NULL) errx(1, "allocate fsize structure"); fp->fsz_next = *fsp; *fsp = fp; @@ -419,25 +336,23 @@ dofsizes(int fd, struct fs *super, char *name) } fp->fsz_count[ksz % FSZCNT]++; fp->fsz_sz[ksz % FSZCNT] += sz; -#endif /* COMPAT */ - } else if (errno) { - err(1, "%s", name); } } sz = 0; - for (fp = fsizes; fp; fp = fp->fsz_next) { + for (fp = fsizes; fp != NULL; fp = fp->fsz_next) { for (i = 0; i < FSZCNT; i++) { - if (fp->fsz_count[i]) + if (fp->fsz_count[i] != 0) { printf("%jd\t%jd\t%d\n", (intmax_t)(fp->fsz_first + i), (intmax_t)fp->fsz_count[i], SIZE(sz += fp->fsz_sz[i])); + } } } } static void -douser(int fd, struct fs *super, char *name) +douser(int fd, struct fs *super) { ino_t inode, maxino; struct user *usr, *usrs; @@ -446,38 +361,35 @@ douser(int fd, struct fs *super, char *name) maxino = super->fs_ncg * super->fs_ipg - 1; for (inode = 0; inode < maxino; inode++) { - errno = 0; - if ((dp = get_inode(fd,super,inode)) - && !isfree(super, dp)) + if ((dp = get_inode(fd, super, inode)) != NULL && + !isfree(super, dp)) { uses(DIP(super, dp, di_uid), - estimate ? virtualblocks(super, dp) : - actualblocks(super, dp), + DIP(super, dp, di_blocks), DIP(super, dp, di_atime)); - else if (errno) { - err(1, "%s", name); } } - if (!(usrs = (struct user *)malloc(nusers * sizeof(struct user)))) + if ((usrs = malloc(nusers * sizeof(*usrs))) == NULL) errx(1, "allocate users"); - bcopy(users,usrs,nusers * sizeof(struct user)); + memcpy(usrs, users, nusers * sizeof(*usrs)); sortusers(usrs); for (usr = usrs, n = nusers; --n >= 0 && usr->count; usr++) { - printf("%5d",SIZE(usr->space)); + printf("%5d", SIZE(usr->space)); if (count) - printf("\t%5ld",usr->count); - printf("\t%-8s",usr->name); - if (unused) + printf("\t%5ld", usr->count); + printf("\t%-8s", usr->name); + if (unused) { printf("\t%5d\t%5d\t%5d", - SIZE(usr->spc30), - SIZE(usr->spc60), - SIZE(usr->spc90)); + SIZE(usr->spc30), + SIZE(usr->spc60), + SIZE(usr->spc90)); + } printf("\n"); } free(usrs); } static void -donames(int fd, struct fs *super, char *name) +donames(int fd, struct fs *super) { int c; ino_t maxino; @@ -488,18 +400,18 @@ donames(int fd, struct fs *super, char *name) /* first skip the name of the filesystem */ while ((c = getchar()) != EOF && (c < '0' || c > '9')) while ((c = getchar()) != EOF && c != '\n'); - ungetc(c,stdin); + ungetc(c, stdin); while (scanf("%ju", &inode) == 1) { if (inode > maxino) { warnx("illegal inode %ju", inode); return; } - errno = 0; - if ((dp = get_inode(fd,super,inode)) - && !isfree(super, dp)) { - printf("%s\t",user(DIP(super, dp, di_uid))->name); + if ((dp = get_inode(fd, super, inode)) != NULL && + !isfree(super, dp)) { + printf("%s\t", user(DIP(super, dp, di_uid))->name); /* now skip whitespace */ - while ((c = getchar()) == ' ' || c == '\t'); + while ((c = getchar()) == ' ' || c == '\t') + /* nothing */; /* and print out the remainder of the input line */ while (c != EOF && c != '\n') { putchar(c); @@ -507,11 +419,9 @@ donames(int fd, struct fs *super, char *name) } putchar('\n'); } else { - if (errno) { - err(1, "%s", name); - } /* skip this line */ - while ((c = getchar()) != EOF && c != '\n'); + while ((c = getchar()) != EOF && c != '\n') + /* nothing */; } if (c == EOF) break; @@ -521,11 +431,7 @@ donames(int fd, struct fs *super, char *name) static void usage(void) { -#ifdef COMPAT - fprintf(stderr, "usage: quot [-cfhnv] [-a | filesystem ...]\n"); -#else /* COMPAT */ - fprintf(stderr, "usage: quot [-cfhknv] [-a | filesystem ...]\n"); -#endif /* COMPAT */ + fprintf(stderr, "usage: quot [-cfknv] [-a | filesystem ...]\n"); exit(1); } @@ -538,7 +444,7 @@ quot(char *name, char *mp) get_inode(-1, NULL, 0); /* flush cache */ inituser(); initfsizes(); - if ((fd = open(name,0)) < 0) { + if ((fd = open(name, 0)) < 0) { warn("%s", name); close(fd); return; @@ -555,11 +461,11 @@ quot(char *name, char *mp) close(fd); return; } - printf("%s:",name); + printf("%s:", name); if (mp) - printf(" (%s)",mp); + printf(" (%s)", mp); putchar('\n'); - (*func)(fd, fs, name); + (*func)(fd, fs); free(fs); close(fd); } @@ -567,40 +473,36 @@ quot(char *name, char *mp) int main(int argc, char *argv[]) { - char all = 0; struct statfs *mp; - struct fstab *fs; - int cnt; - int ch; + int ch, cnt; func = douser; -#ifndef COMPAT - header = getbsize(&headerlen,&blocksize); -#endif - while ((ch = getopt(argc, argv, "acfhknv")) != -1) { + header = getbsize(&headerlen, &blocksize); + while ((ch = getopt(argc, argv, "acfhkNnv")) != -1) { switch (ch) { case 'a': - all = 1; + all = true; break; case 'c': func = dofsizes; break; case 'f': - count = 1; + count = true; break; case 'h': - estimate = 1; + /* ignored for backward compatibility */ break; -#ifndef COMPAT case 'k': blocksize = 1024; break; -#endif /* COMPAT */ + case 'N': + noname = true; + break; case 'n': func = donames; break; case 'v': - unused = 1; + unused = true; break; default: usage(); @@ -613,18 +515,16 @@ main(int argc, char *argv[]) usage(); if (all) { - cnt = getmntinfo(&mp,MNT_NOWAIT); - for (; --cnt >= 0; mp++) { - if (!strncmp(mp->f_fstypename, "ufs", MFSNAMELEN)) + for (cnt = getmntinfo(&mp, MNT_NOWAIT); --cnt >= 0; mp++) + if (strncmp(mp->f_fstypename, "ufs", MFSNAMELEN) == 0) quot(mp->f_mntfromname, mp->f_mntonname); - } } - while (--argc >= 0) { - if ((fs = getfsfile(*argv)) != NULL) - quot(fs->fs_spec, 0); + while (argc-- > 0) { + if ((mp = getmntpoint(*argv)) != NULL) + quot(mp->f_mntfromname, mp->f_mntonname); else - quot(*argv,0); + quot(*argv, 0); argv++; } - return 0; + return (0); } diff --git a/usr.sbin/quot/tests/Makefile b/usr.sbin/quot/tests/Makefile new file mode 100644 index 000000000000..d4e64691f905 --- /dev/null +++ b/usr.sbin/quot/tests/Makefile @@ -0,0 +1,4 @@ +PACKAGE= tests +ATF_TESTS_SH= quot_test + +.include <bsd.test.mk> diff --git a/usr.sbin/quot/tests/quot_test.sh b/usr.sbin/quot/tests/quot_test.sh new file mode 100644 index 000000000000..21088d162a53 --- /dev/null +++ b/usr.sbin/quot/tests/quot_test.sh @@ -0,0 +1,102 @@ +# +# Copyright (c) 2025 Dag-Erling Smørgrav <des@FreeBSD.org> +# +# SPDX-License-Identifier: BSD-2-Clause +# + +# Create and mount a UFS filesystem on a small memory disk +quot_setup() +{ + atf_check -o save:dev mdconfig -t malloc -s 16M + local dev=$(cat dev) + atf_check -o ignore newfs "$@" /dev/$dev + atf_check mkdir mnt + local mnt=$(realpath mnt) + atf_check mount /dev/$dev "$mnt" + echo "/dev/$dev: ($mnt)" >expect + printf "%5d\t%5d\t%-8s\n" 8 2 "#0" >>expect +} + +# Create a directory owned by a given UID +quot_adduid() +{ + local uid=$1 + atf_check install -d -o $uid -g 0 mnt/$uid + printf "%5d\t%5d\t%-8s\n" 4 1 "#$uid" >>expect +} + +# Perform the tests +quot_test() +{ + local dev=$(cat dev) + # Create inodes owned by a large number of users to exercise + # hash collisions and rehashing. The code uses an open hash + # table that starts out with only 8 entries and doubles every + # time it fills up. + local uid + for uid in $(seq 1 32); do + quot_adduid $uid + done + # Also create inodes owned by users with long UIDs, up to the + # highest possible value (2^32 - 2, because chown(2) and + # friends interpret 2^32 - 1 as “leave unchanged”). + local shift + for shift in $(seq 6 32); do + quot_adduid $(((1 << shift) - 2)) + done + # Since quot operates directly on the underlying device, not + # on the mounted filesystem, we remount read-only to ensure + # that everything gets flushed to the memory disk. + atf_check mount -ur /dev/$dev + atf_check -o file:expect quot -fkN /dev/$dev + atf_check -o file:expect quot -fkN $(realpath mnt) +} + +# Unmount and release the memory disk +quot_cleanup() +{ + if [ -d mnt ]; then + umount mnt || true + fi + if [ -f dev ]; then + mdconfig -d -u $(cat dev) || true + fi +} + +atf_test_case ufs1 cleanup +ufs1_head() +{ + atf_set descr "Test quot on UFS1" + atf_set require.user root +} +ufs1_body() +{ + quot_setup -O1 + quot_test +} +ufs1_cleanup() +{ + quot_cleanup +} + +atf_test_case ufs2 cleanup +ufs2_head() +{ + atf_set descr "Test quot on UFS2" + atf_set require.user root +} +ufs2_body() +{ + quot_setup -O2 + quot_test +} +ufs2_cleanup() +{ + quot_cleanup +} + +atf_init_test_cases() +{ + atf_add_test_case ufs1 + atf_add_test_case ufs2 +} diff --git a/usr.sbin/unbound/Makefile.inc b/usr.sbin/unbound/Makefile.inc index a28e388e47c0..84dfdbf736bd 100644 --- a/usr.sbin/unbound/Makefile.inc +++ b/usr.sbin/unbound/Makefile.inc @@ -1,6 +1,6 @@ MK_WERROR= no NO_WTHREAD_SAFETY= true -PACKAGE= unbound +PACKAGE= local-unbound .for man in ${MAN} ${man}: ${UNBOUNDDIR}/doc/${man:S/local-//} |