From: Ben Gras Date: Mon, 21 Sep 2009 14:24:29 +0000 (+0000) Subject: - added 'datasizes' script that shows you the size allocated X-Git-Tag: v3.1.5~138 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=36e935fe0f06d8db40ef844e32024eed8fd217f5;p=minix.git - added 'datasizes' script that shows you the size allocated for each symbol, usually answering those "why is does my binary have such a lot of BSS" questions. - stop binpackage looking in /var/spool for package files. - let makewhatis recognize .Sh as heading name - setup, fsck, df: allow >4kB block sizes painlessly - mkfs: new #-of-inodes heuristic that depends on kb, not on blocks; i've run out of inodes on my /usr - asmconv: don't silently truncate .aligns to 16 bytes - ipc* commands for shared memory support --- diff --git a/commands/i386/asmconv/emit_gnu.c b/commands/i386/asmconv/emit_gnu.c index 7456aff8f..4ec8ec867 100755 --- a/commands/i386/asmconv/emit_gnu.c +++ b/commands/i386/asmconv/emit_gnu.c @@ -521,7 +521,7 @@ void gnu_emit_instruction(asm86_t *a) assert(a->args->operator == 'W' && isanumber(a->args->name)); n= strtoul(a->args->name, nil, 0); - for (s= 0; s <= 4 && (1 << s) < n; s++) {} + for (s= 0; s <= 16 && (1 << s) < n; s++) {} gnu_printf(".align\t%u", s); } else if ((p= opcode2name(a->opcode)) != nil) { diff --git a/commands/mdb/decode.c b/commands/mdb/decode.c index 7d373735b..c66e1877f 100644 --- a/commands/mdb/decode.c +++ b/commands/mdb/decode.c @@ -99,7 +99,7 @@ struct decode_system { BRK, M1_P1, M2_P1, "BRK", STAT, M1_NAME1, NOP, "STAT", LSEEK, M1_I1, NOP, "LSEEK", - GETPID, NOP, NOP, "GETPID", + MINIX_GETPID, NOP, NOP, "MINIX_GETPID", MOUNT, M1_2NAMES, NOP, "MOUNT", UMOUNT, M3_LOAD, NOP, "UMOUNT", SETUID, M1_I1, NOP, "SETUID", diff --git a/commands/scripts/Makefile b/commands/scripts/Makefile index b2b55a2e4..af33fcc11 100755 --- a/commands/scripts/Makefile +++ b/commands/scripts/Makefile @@ -42,6 +42,7 @@ usr: \ /bin/setup \ /bin/netconf \ /usr/bin/binsizes \ + /usr/bin/datasizes \ /usr/bin/rotate \ /usr/bin/floppysetup \ /usr/bin/packit \ @@ -149,6 +150,9 @@ clean: /usr/bin/binsizes: binsizes.sh install -m 755 -c -o bin $? $@ +/usr/bin/datasizes: datasizes.sh + install -m 755 -c -o bin $? $@ + /usr/bin/packit: packit.sh install -m 755 -c -o bin $? $@ diff --git a/commands/scripts/binpackage.sh b/commands/scripts/binpackage.sh index ac9a6326f..2ad2e1867 100644 --- a/commands/scripts/binpackage.sh +++ b/commands/scripts/binpackage.sh @@ -60,7 +60,7 @@ fi echo " * Building package" echo "Minix package $dir built `date`." >$INFO -( echo $INFO ; if [ -f $PI ]; then echo $PI; fi; find / -cnewer $packagestart | egrep -v "^($srcdir|/(dev|tmp)|/usr/(src|tmp|log|adm|run)|/home|/etc/utmp|/var/(run|log))" ) | pax -w -d | bzip2 >$tarbz +( echo $INFO ; if [ -f $PI ]; then echo $PI; fi; find / -cnewer $packagestart | egrep -v "^($srcdir|/(dev|tmp)|/usr/(src|tmp|log|adm|run)|/home|/etc/utmp|/var/(run|log|spool))" ) | pax -w -d | bzip2 >$tarbz rm -f $packagestart $findlist $tarcmd binsizes normal mv $tarbz $pdir diff --git a/commands/scripts/datasizes.sh b/commands/scripts/datasizes.sh new file mode 100644 index 000000000..e85661998 --- /dev/null +++ b/commands/scripts/datasizes.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +if [ $# -ne 1 ] +then echo "Usage: $0 " + exit 1 +fi + +nm -d -n $1 | grep ' [bBdD] ' | awk '{ printf "%10ld kB %s\n", ($1-lastpos)/1024, lastname; lastpos=$1; lastname=$3 }' | sort -n diff --git a/commands/scripts/makewhatis.sh b/commands/scripts/makewhatis.sh index df7f76d93..bf6f16fbb 100755 --- a/commands/scripts/makewhatis.sh +++ b/commands/scripts/makewhatis.sh @@ -29,6 +29,7 @@ cd $1 || exit sed -e 's/ / /g s/"NAME"/NAME/g + s/^\.Sh/\.SH/g /^\.SH NAME/,/^\.SH /!d /^\.SH /d s/\\f.//g diff --git a/commands/scripts/setup.sh b/commands/scripts/setup.sh index 9d6f6f23e..1231771d2 100755 --- a/commands/scripts/setup.sh +++ b/commands/scripts/setup.sh @@ -436,7 +436,7 @@ installboot -m /dev/$primary /usr/mdec/masterboot >/dev/null || exit partition /dev/$primary 1 81:${ROOTSECTS}* 81:$homesize 81:0+ > /dev/null || exit echo "Creating /dev/$root for / .." -mkfs -B $blocksizebytes /dev/$root || exit +mkfs /dev/$root || exit if [ "$nohome" = 0 ] then diff --git a/commands/simple/Makefile b/commands/simple/Makefile index 226c7f279..cd38b9c12 100755 --- a/commands/simple/Makefile +++ b/commands/simple/Makefile @@ -104,6 +104,8 @@ ALL = \ in.rshd \ installx \ intr \ + ipcs \ + ipcrm \ irdpd \ isoread \ join \ @@ -470,6 +472,14 @@ intr: intr.c $(CCLD) -o $@ intr.c @install -S 4kw $@ +ipcs: ipcs.c + $(CCLD) -o $@ ipcs.c + @install -S 4kw $@ + +ipcrm: ipcrm.c + $(CCLD) -o $@ ipcrm.c + @install -S 4kw $@ + irdpd: irdpd.c $(CCLD) -o $@ $< @install -S 4kw $@ @@ -983,6 +993,8 @@ install: \ /bin/install \ /usr/bin/install \ /usr/bin/intr \ + /usr/bin/ipcs \ + /usr/bin/ipcrm \ /usr/bin/irdpd \ /usr/bin/isoread \ /usr/bin/isodir \ @@ -1338,6 +1350,12 @@ install: \ /usr/bin/intr: intr install -cs -o bin $< $@ +/usr/bin/ipcs: ipcs + install -cs -o bin $< $@ + +/usr/bin/ipcrm: ipcrm + install -cs -o bin $< $@ + /usr/bin/irdpd: irdpd install -cs -o bin $< $@ diff --git a/commands/simple/df.c b/commands/simple/df.c index ec921936f..5379e94e1 100755 --- a/commands/simple/df.c +++ b/commands/simple/df.c @@ -302,7 +302,7 @@ int df(const struct mtab *mt) if(sp->s_magic != SUPER_V3) block_size = _STATIC_BLOCK_SIZE; else block_size = super.s_block_size; - if(block_size < _MIN_BLOCK_SIZE || block_size > _MAX_BLOCK_SIZE) { + if(block_size < _MIN_BLOCK_SIZE) { fprintf(stderr, "df: %s: funny block size (%d)\n", mt->devname, block_size); close(fd); @@ -402,8 +402,18 @@ bit_t bit_count(unsigned blocks, bit_t bits, int fd, int block_size) int i, b; bit_t busy; char *wlim; - static char buf[_MAX_BLOCK_SIZE]; + static char *buf = NULL; static char bits_in_char[1 << CHAR_BIT]; + static int bufsize = 0; + + if(bufsize < block_size) { + if(buf) free(buf); + if(!(buf = malloc(block_size))) { + fprintf(stderr, "df: malloc failed\n"); + exit(1); + } + bufsize = block_size; + } /* Precalculate bitcount for each char. */ if (bits_in_char[1] != 1) { diff --git a/commands/simple/fsck.c b/commands/simple/fsck.c index 73361def3..a2c81fcaf 100755 --- a/commands/simple/fsck.c +++ b/commands/simple/fsck.c @@ -1551,7 +1551,7 @@ char *f, **clist, **ilist, **zlist; getsuper(); - if(block_size < _MIN_BLOCK_SIZE || block_size > _MAX_BLOCK_SIZE) + if(block_size < _MIN_BLOCK_SIZE) fatal("funny block size"); if(!(rwbuf = malloc(block_size))) fatal("couldn't allocate fs buf (1)"); diff --git a/commands/simple/ipcrm.c b/commands/simple/ipcrm.c new file mode 100644 index 000000000..d04df67ab --- /dev/null +++ b/commands/simple/ipcrm.c @@ -0,0 +1,282 @@ +/* + * krishna balasubramanian 1993 + * + * 1999-02-22 Arkadiusz Mi秌iewicz + * - added Native Language Support + * + * 1999-04-02 frank zago + * - can now remove several id's in the same call + * + */ + +#include +#include +#include +#include + +#include +#include +#include +#include + +/* for getopt */ +#include +/* for tolower and isupper */ +#include + +#define _(a) a + +#if defined (__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED) +/* union semun is defined by including */ +#else +/* according to X/OPEN we have to define it ourselves */ +union semun { + int val; + struct semid_ds *buf; + unsigned short int *array; + struct seminfo *__buf; +}; +#endif + +static void usage(char *); + +char *execname; + +typedef enum type_id { + SHM, + SEM, + MSG +} type_id; + +static int +remove_ids(type_id type, int argc, char **argv) { + int id; + int ret = 0; /* for gcc */ + char *end; + int nb_errors = 0; + union semun arg; + + arg.val = 0; + + while(argc) { + + id = strtoul(argv[0], &end, 10); + + if (*end != 0) { + printf (_("invalid id: %s\n"), argv[0]); + nb_errors ++; + } else { + switch(type) { + case SEM: +#if 0 + ret = semctl (id, 0, IPC_RMID, arg); +#endif + break; + + case MSG: +#if 0 + ret = msgctl (id, IPC_RMID, NULL); +#endif + break; + + case SHM: + ret = shmctl (id, IPC_RMID, NULL); + break; + } + + if (ret) { + printf (_("cannot remove id %s (%s)\n"), + argv[0], strerror(errno)); + nb_errors ++; + } + } + argc--; + argv++; + } + + return(nb_errors); +} + +static void deprecate_display_usage(void) +{ + usage(execname); + printf (_("deprecated usage: %s {shm | msg | sem} id ...\n"), + execname); +} + +static int deprecated_main(int argc, char **argv) +{ + execname = argv[0]; + + if (argc < 3) { + deprecate_display_usage(); + exit(1); + } + + if (!strcmp(argv[1], "shm")) { + if (remove_ids(SHM, argc-2, &argv[2])) + exit(1); + } + else if (!strcmp(argv[1], "msg")) { + if (remove_ids(MSG, argc-2, &argv[2])) + exit(1); + } + else if (!strcmp(argv[1], "sem")) { + if (remove_ids(SEM, argc-2, &argv[2])) + exit(1); + } + else { + deprecate_display_usage(); + printf (_("unknown resource type: %s\n"), argv[1]); + exit(1); + } + + printf (_("resource(s) deleted\n")); + return 0; +} + + +/* print the new usage */ +static void +usage(char *progname) +{ + fprintf(stderr, + _("usage: %s [ [-q msqid] [-m shmid] [-s semid]\n" + " [-Q msgkey] [-M shmkey] [-S semkey] ... ]\n"), + progname); +} + +int main(int argc, char **argv) +{ + int c; + int error = 0; + char *prog = argv[0]; + + /* if the command is executed without parameters, do nothing */ + if (argc == 1) + return 0; + + /* check to see if the command is being invoked in the old way if so + then run the old code */ + if (strcmp(argv[1], "shm") == 0 || + strcmp(argv[1], "msg") == 0 || + strcmp(argv[1], "sem") == 0) + return deprecated_main(argc, argv); + + /* process new syntax to conform with SYSV ipcrm */ + while ((c = getopt(argc, argv, "q:m:s:Q:M:S:")) != -1) { + int result; + int id = 0; + int iskey = isupper(c); + + /* needed to delete semaphores */ + union semun arg; + arg.val = 0; + + /* we don't need case information any more */ + c = tolower(c); + + /* make sure the option is in range */ + if (c != 'q' && c != 'm' && c != 's') { + fprintf(stderr, _("%s: illegal option -- %c\n"), + prog, c); + usage(prog); + error++; + return error; + } + + if (iskey) { + /* keys are in hex or decimal */ + key_t key = strtoul(optarg, NULL, 0); + if (key == IPC_PRIVATE) { + error++; + fprintf(stderr, _("%s: illegal key (%s)\n"), + prog, optarg); + continue; + } + + /* convert key to id */ +#if 0 + id = ((c == 'q') ? msgget(key, 0) : + (c == 'm') ? shmget(key, 0, 0) : + semget(key, 0, 0)); +#endif + id = (c == 'm') ? shmget(key, 0, 0) : + ((c == 's') ? semget(key, 0, 0) : -1); + + if (id < 0) { + char *errmsg; + error++; + switch(errno) { + case EACCES: + errmsg = _("permission denied for key"); + break; + case EIDRM: + errmsg = _("already removed key"); + break; + case ENOENT: + errmsg = _("invalid key"); + break; + default: + errmsg = _("unknown error in key"); + break; + } + fprintf(stderr, "%s: %s (%s)\n", + prog, errmsg, optarg); + continue; + } + } else { + /* ids are in decimal */ + id = strtoul(optarg, NULL, 10); + } + +#if 0 + result = ((c == 'q') ? msgctl(id, IPC_RMID, NULL) : + (c == 'm') ? shmctl(id, IPC_RMID, NULL) : + semctl(id, 0, IPC_RMID, arg)); +#endif + result = (c == 'm') ? shmctl(id, IPC_RMID, NULL) : + ((c == 's') ? semctl(id, 0, IPC_RMID) : -1); + + if (result < 0) { + char *errmsg; + error++; + switch(errno) { + case EACCES: + case EPERM: + errmsg = iskey + ? _("permission denied for key") + : _("permission denied for id"); + break; + case EINVAL: + errmsg = iskey + ? _("invalid key") + : _("invalid id"); + break; + case EIDRM: + errmsg = iskey + ? _("already removed key") + : _("already removed id"); + break; + default: + errmsg = iskey + ? _("unknown error in key") + : _("unknown error in id"); + break; + } + fprintf(stderr, _("%s: %s (%s)\n"), + prog, errmsg, optarg); + continue; + } + } + + /* print usage if we still have some arguments left over */ + if (optind != argc) { + fprintf(stderr, _("%s: unknown argument: %s\n"), + prog, argv[optind]); + usage(prog); + } + + /* exit value reflects the number of errors encountered */ + return error; +} diff --git a/commands/simple/ipcs.c b/commands/simple/ipcs.c new file mode 100644 index 000000000..ebb9c6ef0 --- /dev/null +++ b/commands/simple/ipcs.c @@ -0,0 +1,691 @@ +/* Original author unknown, may be "krishna balasub@cis.ohio-state.edu" */ +/* + + Modified Sat Oct 9 10:55:28 1993 for 0.99.13 + + Patches from Mike Jagdis (jaggy@purplet.demon.co.uk) applied Wed Feb + 8 12:12:21 1995 by faith@cs.unc.edu to print numeric uids if no + passwd file entry. + + Patch from arnolds@ifns.de (Heinz-Ado Arnolds) applied Mon Jul 1 + 19:30:41 1996 by janl@math.uio.no to add code missing in case PID: + clauses. + + Patched to display the key field -- hy@picksys.com 12/18/96 + + 1999-02-22 Arkadiusz Mi秌iewicz + - added Native Language Support + +*/ + +#define __USE_MISC + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* remove _() stuff */ +#define _(a) a +typedef unsigned long ulong; +void err(int eval, const char *fmt, ...) +{ + va_list ap; + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + exit(eval); +} + +/*-------------------------------------------------------------------*/ +/* SHM_DEST and SHM_LOCKED are defined in kernel headers, + but inside #ifdef __KERNEL__ ... #endif */ +#ifndef SHM_DEST +/* shm_mode upper byte flags */ +#define SHM_DEST 01000 /* segment will be destroyed on last detach */ +#define SHM_LOCKED 02000 /* segment will not be swapped */ +#endif + +/* For older kernels the same holds for the defines below */ +#ifndef MSG_STAT +#define MSG_STAT 11 +#define MSG_INFO 12 +#endif + +#ifndef SHM_STAT +#define SHM_STAT 13 +#define SHM_INFO 14 +struct shm_info { + int used_ids; + ulong shm_tot; /* total allocated shm */ + ulong shm_rss; /* total resident shm */ + ulong shm_swp; /* total swapped shm */ + ulong swap_attempts; + ulong swap_successes; +}; +#endif + +#ifndef SEM_STAT +#define SEM_STAT 18 +#define SEM_INFO 19 +#endif + +/* Some versions of libc only define IPC_INFO when __USE_GNU is defined. */ +#ifndef IPC_INFO +#define IPC_INFO 3 +#endif +/*-------------------------------------------------------------------*/ + +/* The last arg of semctl is a union semun, but where is it defined? + X/OPEN tells us to define it ourselves, but until recently + Linux include files would also define it. */ +#if defined (__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED) +/* union semun is defined by including */ +#else +/* according to X/OPEN we have to define it ourselves */ +union semun { + int val; + struct semid_ds *buf; + unsigned short int *array; + struct seminfo *__buf; +}; +#endif + +/* X/OPEN (Jan 1987) does not define fields key, seq in struct ipc_perm; + libc 4/5 does not mention struct ipc_term at all, but includes + , which defines a struct ipc_perm with such fields. + glibc-1.09 has no support for sysv ipc. + glibc 2 uses __key, __seq */ +#if defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1 +#define KEY __key +#else +#define KEY key +#endif + +#define LIMITS 1 +#define STATUS 2 +#define CREATOR 3 +#define TIME 4 +#define PID 5 + +void do_shm (char format); +void do_sem (char format); +void do_msg (char format); +void print_shm (int id); +void print_msg (int id); +void print_sem (int id); + +static char *progname; + +static void +usage(int rc) { + printf (_("usage : %s -asmq -tclup \n"), progname); + printf (_("\t%s [-s -m -q] -i id\n"), progname); + printf (_("\t%s -h for help.\n"), progname); + exit(rc); +} + +static void +help (int rc) { + printf (_("%s provides information on ipc facilities for" + " which you have read access.\n"), progname); + printf (_("Resource Specification:\n\t-m : shared_mem\n\t-q : messages\n")); + printf (_("\t-s : semaphores\n\t-a : all (default)\n")); + printf (_("Output Format:\n\t-t : time\n\t-p : pid\n\t-c : creator\n")); + printf (_("\t-l : limits\n\t-u : summary\n")); + printf (_("-i id [-s -q -m] : details on resource identified by id\n")); + usage(rc); +} + +int +main (int argc, char **argv) { + int opt, msg = 0, sem = 0, shm = 0, id=0, print=0; + char format = 0; + char options[] = "atcluphsmqi:"; + + progname = argv[0]; + while ((opt = getopt (argc, argv, options)) != -1) { + switch (opt) { + case 'i': + id = atoi (optarg); + print = 1; + break; + case 'a': + msg = shm = sem = 1; + break; + case 'q': + msg = 1; + break; + case 's': + sem = 1; + break; + case 'm': + shm = 1; + break; + case 't': + format = TIME; + break; + case 'c': + format = CREATOR; + break; + case 'p': + format = PID; + break; + case 'l': + format = LIMITS; + break; + case 'u': + format = STATUS; + break; + case 'h': + help(EXIT_SUCCESS); + case '?': + usage(EXIT_SUCCESS); + } + } + + if (print) { + if (shm) + print_shm (id); + else if (sem) + print_sem (id); + else if (msg) + print_msg (id); + else + usage (EXIT_FAILURE); + } else { + if ( !shm && !msg && !sem) + msg = sem = shm = 1; + printf ("\n"); + + if (shm) { + do_shm (format); + printf ("\n"); + } + if (sem) { + do_sem (format); + printf ("\n"); + } + if (msg) { + do_msg (format); + printf ("\n"); + } + } + return EXIT_SUCCESS; +} + + +static void +print_perms (int id, struct ipc_perm *ipcp) { + struct passwd *pw; + struct group *gr; + + printf ("%-10d %-10o", id, ipcp->mode & 0777); + + if ((pw = getpwuid(ipcp->cuid))) + printf(" %-10s", pw->pw_name); + else + printf(" %-10d", ipcp->cuid); + if ((gr = getgrgid(ipcp->cgid))) + printf(" %-10s", gr->gr_name); + else + printf(" %-10d", ipcp->cgid); + + if ((pw = getpwuid(ipcp->uid))) + printf(" %-10s", pw->pw_name); + else + printf(" %-10d", ipcp->uid); + if ((gr = getgrgid(ipcp->gid))) + printf(" %-10s\n", gr->gr_name); + else + printf(" %-10d\n", ipcp->gid); +} + + +void do_shm (char format) +{ + int maxid, shmid, id; + struct shmid_ds shmseg; + struct shm_info shm_info; + struct shminfo shminfo; + struct ipc_perm *ipcp = &shmseg.shm_perm; + struct passwd *pw; + + maxid = shmctl (0, SHM_INFO, (struct shmid_ds *) (void *) &shm_info); + if (maxid < 0 && errno == ENOSYS) { + printf (_("kernel not configured for shared memory\n")); + return; + } + + switch (format) { + case LIMITS: + printf (_("------ Shared Memory Limits --------\n")); + if ((shmctl (0, IPC_INFO, (struct shmid_ds *) (void *) &shminfo)) < 0 ) + return; + /* glibc 2.1.3 and all earlier libc's have ints as fields + of struct shminfo; glibc 2.1.91 has unsigned long; ach */ + printf (_("max number of segments = %lu\n"), + (unsigned long) shminfo.shmmni); + printf (_("max seg size (kbytes) = %lu\n"), + (unsigned long) (shminfo.shmmax >> 10)); + printf (_("max total shared memory (kbytes) = %lu\n"), + getpagesize() / 1024 * (unsigned long) shminfo.shmall); + printf (_("min seg size (bytes) = %lu\n"), + (unsigned long) shminfo.shmmin); + return; + + case STATUS: + printf (_("------ Shared Memory Status --------\n")); + printf (_("segments allocated %d\n"), shm_info.used_ids); + printf (_("pages allocated %ld\n"), shm_info.shm_tot); + printf (_("pages resident %ld\n"), shm_info.shm_rss); + printf (_("pages swapped %ld\n"), shm_info.shm_swp); + printf (_("Swap performance: %ld attempts\t %ld successes\n"), + shm_info.swap_attempts, shm_info.swap_successes); + return; + + case CREATOR: + printf (_("------ Shared Memory Segment Creators/Owners --------\n")); + printf ("%-10s %-10s %-10s %-10s %-10s %-10s\n", + _("shmid"),_("perms"),_("cuid"),_("cgid"),_("uid"),_("gid")); + break; + + case TIME: + printf (_("------ Shared Memory Attach/Detach/Change Times --------\n")); + printf ("%-10s %-10s %-20s %-20s %-20s\n", + _("shmid"),_("owner"),_("attached"),_("detached"), + _("changed")); + break; + + case PID: + printf (_("------ Shared Memory Creator/Last-op --------\n")); + printf ("%-10s %-10s %-10s %-10s\n", + _("shmid"),_("owner"),_("cpid"),_("lpid")); + break; + + default: + printf (_("------ Shared Memory Segments --------\n")); + printf ("%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n", + _("key"),_("shmid"),_("owner"),_("perms"),_("bytes"), + _("nattch"),_("status")); + break; + } + + for (id = 0; id <= maxid; id++) { + shmid = shmctl (id, SHM_STAT, &shmseg); + if (shmid < 0) + continue; + if (format == CREATOR) { + print_perms (shmid, ipcp); + continue; + } + pw = getpwuid(ipcp->uid); + switch (format) { + case TIME: + if (pw) + printf ("%-10d %-10.10s", shmid, pw->pw_name); + else + printf ("%-10d %-10d", shmid, ipcp->uid); + /* ctime uses static buffer: use separate calls */ + printf(" %-20.16s", shmseg.shm_atime + ? ctime(&shmseg.shm_atime) + 4 : _("Not set")); + printf(" %-20.16s", shmseg.shm_dtime + ? ctime(&shmseg.shm_dtime) + 4 : _("Not set")); + printf(" %-20.16s\n", shmseg.shm_ctime + ? ctime(&shmseg.shm_ctime) + 4 : _("Not set")); + break; + case PID: + if (pw) + printf ("%-10d %-10.10s", shmid, pw->pw_name); + else + printf ("%-10d %-10d", shmid, ipcp->uid); + printf (" %-10d %-10d\n", + shmseg.shm_cpid, shmseg.shm_lpid); + break; + + default: + printf("0x%08x ",ipcp->KEY ); + if (pw) + printf ("%-10d %-10.10s", shmid, pw->pw_name); + else + printf ("%-10d %-10d", shmid, ipcp->uid); + printf (" %-10o %-10lu %-10ld %-6s %-6s\n", + ipcp->mode & 0777, + /* + * earlier: int, Austin has size_t + */ + (unsigned long) shmseg.shm_segsz, + /* + * glibc-2.1.3 and earlier has unsigned short; + * Austin has shmatt_t + */ + (long) shmseg.shm_nattch, + ipcp->mode & SHM_DEST ? _("dest") : " ", + ipcp->mode & SHM_LOCKED ? _("locked") : " "); + break; + } + } + return; +} + + +void do_sem (char format) +{ + int maxid, semid, id; + struct semid_ds semary; + struct seminfo seminfo; + struct ipc_perm *ipcp = &semary.sem_perm; + struct passwd *pw; + union semun arg; + + arg.array = (unsigned short *) (void *) &seminfo; + maxid = semctl (0, 0, SEM_INFO, arg); + if (maxid < 0) { + printf (_("kernel not configured for semaphores\n")); + return; + } + + switch (format) { + case LIMITS: + printf (_("------ Semaphore Limits --------\n")); + arg.array = (unsigned short *) (void *) &seminfo; /* damn union */ + if ((semctl (0, 0, IPC_INFO, arg)) < 0 ) + return; + printf (_("max number of arrays = %d\n"), seminfo.semmni); + printf (_("max semaphores per array = %d\n"), seminfo.semmsl); + printf (_("max semaphores system wide = %d\n"), seminfo.semmns); + printf (_("max ops per semop call = %d\n"), seminfo.semopm); + printf (_("semaphore max value = %d\n"), seminfo.semvmx); + return; + + case STATUS: + printf (_("------ Semaphore Status --------\n")); + printf (_("used arrays = %d\n"), seminfo.semusz); + printf (_("allocated semaphores = %d\n"), seminfo.semaem); + return; + + case CREATOR: + printf (_("------ Semaphore Arrays Creators/Owners --------\n")); + printf ("%-10s %-10s %-10s %-10s %-10s %-10s\n", + _("semid"),_("perms"),_("cuid"),_("cgid"),_("uid"),_("gid")); + break; + + case TIME: + printf (_("------ Semaphore Operation/Change Times --------\n")); + printf ("%-8s %-10s %-26.24s %-26.24s\n", + _("semid"),_("owner"),_("last-op"),_("last-changed")); + break; + + case PID: + break; + + default: + printf (_("------ Semaphore Arrays --------\n")); + printf ("%-10s %-10s %-10s %-10s %-10s\n", + _("key"),_("semid"),_("owner"),_("perms"),_("nsems")); + break; + } + + for (id = 0; id <= maxid; id++) { + arg.buf = (struct semid_ds *) &semary; + semid = semctl (id, 0, SEM_STAT, arg); + if (semid < 0) + continue; + if (format == CREATOR) { + print_perms (semid, ipcp); + continue; + } + pw = getpwuid(ipcp->uid); + switch (format) { + case TIME: + if (pw) + printf ("%-8d %-10.10s", semid, pw->pw_name); + else + printf ("%-8d %-10d", semid, ipcp->uid); + printf (" %-26.24s", semary.sem_otime + ? ctime(&semary.sem_otime) : _("Not set")); + printf (" %-26.24s\n", semary.sem_ctime + ? ctime(&semary.sem_ctime) : _("Not set")); + break; + case PID: + break; + + default: + printf("0x%08x ", ipcp->KEY); + if (pw) + printf ("%-10d %-10.10s", semid, pw->pw_name); + else + printf ("%-10d %-10d", semid, ipcp->uid); + printf (" %-10o %-10ld\n", + ipcp->mode & 0777, + /* + * glibc-2.1.3 and earlier has unsigned short; + * glibc-2.1.91 has variation between + * unsigned short and unsigned long + * Austin prescribes unsigned short. + */ + (long) semary.sem_nsems); + break; + } + } +} + + +void do_msg (char format) +{ +#if 0 + int maxid, msqid, id; + struct msqid_ds msgque; + struct msginfo msginfo; + struct ipc_perm *ipcp = &msgque.msg_perm; + struct passwd *pw; + + maxid = msgctl (0, MSG_INFO, (struct msqid_ds *) (void *) &msginfo); + if (maxid < 0) { + printf (_("kernel not configured for message queues\n")); + return; + } + + switch (format) { + case LIMITS: + if ((msgctl (0, IPC_INFO, (struct msqid_ds *) (void *) &msginfo)) < 0 ) + return; + printf (_("------ Messages: Limits --------\n")); + printf (_("max queues system wide = %d\n"), msginfo.msgmni); + printf (_("max size of message (bytes) = %d\n"), msginfo.msgmax); + printf (_("default max size of queue (bytes) = %d\n"), msginfo.msgmnb); + return; + + case STATUS: + printf (_("------ Messages: Status --------\n")); + printf (_("allocated queues = %d\n"), msginfo.msgpool); + printf (_("used headers = %d\n"), msginfo.msgmap); + printf (_("used space = %d bytes\n"), msginfo.msgtql); + return; + + case CREATOR: + printf (_("------ Message Queues: Creators/Owners --------\n")); + printf ("%-10s %-10s %-10s %-10s %-10s %-10s\n", + _("msqid"),_("perms"),_("cuid"),_("cgid"),_("uid"),_("gid")); + break; + + case TIME: + printf (_("------ Message Queues Send/Recv/Change Times --------\n")); + printf ("%-8s %-10s %-20s %-20s %-20s\n", + _("msqid"),_("owner"),_("send"),_("recv"),_("change")); + break; + + case PID: + printf (_("------ Message Queues PIDs --------\n")); + printf ("%-10s %-10s %-10s %-10s\n", + _("msqid"),_("owner"),_("lspid"),_("lrpid")); + break; + + default: + printf (_("------ Message Queues --------\n")); + printf ("%-10s %-10s %-10s %-10s %-12s %-12s\n", + _("key"), _("msqid"), _("owner"), _("perms"), + _("used-bytes"), _("messages")); + break; + } + + for (id = 0; id <= maxid; id++) { + msqid = msgctl (id, MSG_STAT, &msgque); + if (msqid < 0) + continue; + if (format == CREATOR) { + print_perms (msqid, ipcp); + continue; + } + pw = getpwuid(ipcp->uid); + switch (format) { + case TIME: + if (pw) + printf ("%-8d %-10.10s", msqid, pw->pw_name); + else + printf ("%-8d %-10d", msqid, ipcp->uid); + printf (" %-20.16s", msgque.msg_stime + ? ctime(&msgque.msg_stime) + 4 : _("Not set")); + printf (" %-20.16s", msgque.msg_rtime + ? ctime(&msgque.msg_rtime) + 4 : _("Not set")); + printf (" %-20.16s\n", msgque.msg_ctime + ? ctime(&msgque.msg_ctime) + 4 : _("Not set")); + break; + case PID: + if (pw) + printf ("%-8d %-10.10s", msqid, pw->pw_name); + else + printf ("%-8d %-10d", msqid, ipcp->uid); + printf (" %5d %5d\n", + msgque.msg_lspid, msgque.msg_lrpid); + break; + + default: + printf( "0x%08x ",ipcp->KEY ); + if (pw) + printf ("%-10d %-10.10s", msqid, pw->pw_name); + else + printf ("%-10d %-10d", msqid, ipcp->uid); + printf (" %-10o %-12ld %-12ld\n", + ipcp->mode & 0777, + /* + * glibc-2.1.3 and earlier has unsigned short; + * glibc-2.1.91 has variation between + * unsigned short, unsigned long + * Austin has msgqnum_t + */ + (long) msgque.msg_cbytes, + (long) msgque.msg_qnum); + break; + } + } + return; +#endif +} + + +void print_shm (int shmid) +{ + struct shmid_ds shmds; + struct ipc_perm *ipcp = &shmds.shm_perm; + + if (shmctl (shmid, IPC_STAT, &shmds) == -1) + err(EXIT_FAILURE, _("shmctl failed")); + + printf (_("\nShared memory Segment shmid=%d\n"), shmid); + printf (_("uid=%d\tgid=%d\tcuid=%d\tcgid=%d\n"), + ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid); + printf (_("mode=%#o\taccess_perms=%#o\n"), + ipcp->mode, ipcp->mode & 0777); + printf (_("bytes=%ld\tlpid=%d\tcpid=%d\tnattch=%ld\n"), + (long) shmds.shm_segsz, shmds.shm_lpid, shmds.shm_cpid, + (long) shmds.shm_nattch); + printf (_("att_time=%-26.24s\n"), + shmds.shm_atime ? ctime (&shmds.shm_atime) : _("Not set")); + printf (_("det_time=%-26.24s\n"), + shmds.shm_dtime ? ctime (&shmds.shm_dtime) : _("Not set")); + printf (_("change_time=%-26.24s\n"), ctime (&shmds.shm_ctime)); + printf ("\n"); + return; +} + + +void print_msg (int msqid) +{ +#if 0 + struct msqid_ds buf; + struct ipc_perm *ipcp = &buf.msg_perm; + + if (msgctl (msqid, IPC_STAT, &buf) == -1) + err(EXIT_FAILURE, _("msgctl failed")); + + printf (_("\nMessage Queue msqid=%d\n"), msqid); + printf (_("uid=%d\tgid=%d\tcuid=%d\tcgid=%d\tmode=%#o\n"), + ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid, ipcp->mode); + printf (_("cbytes=%ld\tqbytes=%ld\tqnum=%ld\tlspid=%d\tlrpid=%d\n"), + /* + * glibc-2.1.3 and earlier has unsigned short; + * glibc-2.1.91 has variation between + * unsigned short, unsigned long + * Austin has msgqnum_t (for msg_qbytes) + */ + (long) buf.msg_cbytes, (long) buf.msg_qbytes, + (long) buf.msg_qnum, buf.msg_lspid, buf.msg_lrpid); + printf (_("send_time=%-26.24s\n"), + buf.msg_stime ? ctime (&buf.msg_stime) : _("Not set")); + printf (_("rcv_time=%-26.24s\n"), + buf.msg_rtime ? ctime (&buf.msg_rtime) : _("Not set")); + printf (_("change_time=%-26.24s\n"), + buf.msg_ctime ? ctime (&buf.msg_ctime) : _("Not set")); + printf ("\n"); + return; +#endif +} + +void print_sem (int semid) +{ + struct semid_ds semds; + struct ipc_perm *ipcp = &semds.sem_perm; + union semun arg; + int i; + + arg.buf = &semds; + if (semctl (semid, 0, IPC_STAT, arg) < 0) + err(EXIT_FAILURE, _("semctl failed")); + + printf (_("\nSemaphore Array semid=%d\n"), semid); + printf (_("uid=%d\t gid=%d\t cuid=%d\t cgid=%d\n"), + ipcp->uid, ipcp->gid, ipcp->cuid, ipcp->cgid); + printf (_("mode=%#o, access_perms=%#o\n"), + ipcp->mode, ipcp->mode & 0777); + printf (_("nsems = %ld\n"), (long) semds.sem_nsems); + printf (_("otime = %-26.24s\n"), + semds.sem_otime ? ctime (&semds.sem_otime) : _("Not set")); + printf (_("ctime = %-26.24s\n"), ctime (&semds.sem_ctime)); + + printf ("%-10s %-10s %-10s %-10s %-10s\n", + _("semnum"),_("value"),_("ncount"),_("zcount"),_("pid")); + arg.val = 0; + for (i=0; i< semds.sem_nsems; i++) { + int val, ncnt, zcnt, pid; + val = semctl (semid, i, GETVAL, arg); + ncnt = semctl (semid, i, GETNCNT, arg); + zcnt = semctl (semid, i, GETZCNT, arg); + pid = semctl (semid, i, GETPID, arg); + if (val < 0 || ncnt < 0 || zcnt < 0 || pid < 0) + err(EXIT_FAILURE, _("semctl failed")); + + printf ("%-10d %-10d %-10d %-10d %-10d\n", + i, val, ncnt, zcnt, pid); + } + printf ("\n"); + return; +} diff --git a/commands/simple/mkfs.c b/commands/simple/mkfs.c index 7fb72f5aa..39a04410f 100755 --- a/commands/simple/mkfs.c +++ b/commands/simple/mkfs.c @@ -266,12 +266,9 @@ char *argv[]; if (blocks == 0) pexit("Can't open prototype file"); } if (i == 0) { - i = blocks / 2; - if (blocks >= 20000) i = blocks / 3; - if (blocks >= 40000) i = blocks / 4; - if (blocks >= 60000) i = blocks / 5; - if (blocks >= 80000) i = blocks / 6; - if (blocks >= 100000) i = blocks / 7; + u32_t kb = div64u(mul64u(blocks, block_size), 1024); + i = kb / 2; + if (kb >= 100000) i = kb / 4; /* round up to fill inode block */ i += inodes_per_block - 1;