fsdb.c (89826) | fsdb.c (89827) |
---|---|
1/* $NetBSD: fsdb.c,v 1.2 1995/10/08 23:18:10 thorpej Exp $ */ 2 3/* 4 * Copyright (c) 1995 John T. Kohl 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 16 unchanged lines hidden (view full) --- 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31#ifndef lint 32static const char rcsid[] = | 1/* $NetBSD: fsdb.c,v 1.2 1995/10/08 23:18:10 thorpej Exp $ */ 2 3/* 4 * Copyright (c) 1995 John T. Kohl 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions --- 16 unchanged lines hidden (view full) --- 25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 27 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31#ifndef lint 32static const char rcsid[] = |
33 "$FreeBSD: head/sbin/fsdb/fsdb.c 89826 2002-01-26 15:47:24Z joerg $"; | 33 "$FreeBSD: head/sbin/fsdb/fsdb.c 89827 2002-01-26 15:53:23Z joerg $"; |
34#endif /* not lint */ 35 36#include <sys/param.h> 37#include <sys/time.h> 38#include <ctype.h> 39#include <err.h> 40#include <grp.h> 41#include <histedit.h> --- 78 unchanged lines hidden (view full) --- 120#define CMDFUNC(func) int func __P((int argc, char *argv[])) 121#define CMDFUNCSTART(func) int func(argc, argv) \ 122 int argc; \ 123 char *argv[]; 124 125CMDFUNC(helpfn); 126CMDFUNC(focus); /* focus on inode */ 127CMDFUNC(active); /* print active inode */ | 34#endif /* not lint */ 35 36#include <sys/param.h> 37#include <sys/time.h> 38#include <ctype.h> 39#include <err.h> 40#include <grp.h> 41#include <histedit.h> --- 78 unchanged lines hidden (view full) --- 120#define CMDFUNC(func) int func __P((int argc, char *argv[])) 121#define CMDFUNCSTART(func) int func(argc, argv) \ 122 int argc; \ 123 char *argv[]; 124 125CMDFUNC(helpfn); 126CMDFUNC(focus); /* focus on inode */ 127CMDFUNC(active); /* print active inode */ |
128CMDFUNC(blocks); /* print blocks for active inode */ |
|
128CMDFUNC(focusname); /* focus by name */ 129CMDFUNC(zapi); /* clear inode */ 130CMDFUNC(uplink); /* incr link */ 131CMDFUNC(downlink); /* decr link */ 132CMDFUNC(linkcount); /* set link count */ 133CMDFUNC(quit); /* quit */ 134CMDFUNC(ls); /* list directory */ 135CMDFUNC(rm); /* remove name */ --- 17 unchanged lines hidden (view full) --- 153 { "?", "Print out help", 1, 1, FL_RO, helpfn }, 154 { "inode", "Set active inode to INUM", 2, 2, FL_RO, focus }, 155 { "clri", "Clear inode INUM", 2, 2, FL_WR, zapi }, 156 { "lookup", "Set active inode by looking up NAME", 2, 2, FL_RO, focusname }, 157 { "cd", "Set active inode by looking up NAME", 2, 2, FL_RO, focusname }, 158 { "back", "Go to previous active inode", 1, 1, FL_RO, back }, 159 { "active", "Print active inode", 1, 1, FL_RO, active }, 160 { "print", "Print active inode", 1, 1, FL_RO, active }, | 129CMDFUNC(focusname); /* focus by name */ 130CMDFUNC(zapi); /* clear inode */ 131CMDFUNC(uplink); /* incr link */ 132CMDFUNC(downlink); /* decr link */ 133CMDFUNC(linkcount); /* set link count */ 134CMDFUNC(quit); /* quit */ 135CMDFUNC(ls); /* list directory */ 136CMDFUNC(rm); /* remove name */ --- 17 unchanged lines hidden (view full) --- 154 { "?", "Print out help", 1, 1, FL_RO, helpfn }, 155 { "inode", "Set active inode to INUM", 2, 2, FL_RO, focus }, 156 { "clri", "Clear inode INUM", 2, 2, FL_WR, zapi }, 157 { "lookup", "Set active inode by looking up NAME", 2, 2, FL_RO, focusname }, 158 { "cd", "Set active inode by looking up NAME", 2, 2, FL_RO, focusname }, 159 { "back", "Go to previous active inode", 1, 1, FL_RO, back }, 160 { "active", "Print active inode", 1, 1, FL_RO, active }, 161 { "print", "Print active inode", 1, 1, FL_RO, active }, |
162 { "blocks", "Print block numbers of active inode", 1, 1, FL_RO, blocks }, |
|
161 { "uplink", "Increment link count", 1, 1, FL_WR, uplink }, 162 { "downlink", "Decrement link count", 1, 1, FL_WR, downlink }, 163 { "linkcount", "Set link count to COUNT", 2, 2, FL_WR, linkcount }, 164 { "ls", "List current inode as directory", 1, 1, FL_RO, ls }, 165 { "rm", "Remove NAME from current inode directory", 2, 2, FL_WR, rm }, 166 { "del", "Remove NAME from current inode directory", 2, 2, FL_WR, rm }, 167 { "ln", "Hardlink INO into current inode directory as NAME", 3, 3, FL_WR, ln }, 168 { "chinum", "Change dir entry number INDEX to INUM", 3, 3, FL_WR, chinum }, --- 50 unchanged lines hidden (view full) --- 219 char **cmd_argv; 220 struct cmdtable *cmdp; 221 History *hist; 222 EditLine *elptr; 223 HistEvent he; 224 225 curinode = ginode(ROOTINO); 226 curinum = ROOTINO; | 163 { "uplink", "Increment link count", 1, 1, FL_WR, uplink }, 164 { "downlink", "Decrement link count", 1, 1, FL_WR, downlink }, 165 { "linkcount", "Set link count to COUNT", 2, 2, FL_WR, linkcount }, 166 { "ls", "List current inode as directory", 1, 1, FL_RO, ls }, 167 { "rm", "Remove NAME from current inode directory", 2, 2, FL_WR, rm }, 168 { "del", "Remove NAME from current inode directory", 2, 2, FL_WR, rm }, 169 { "ln", "Hardlink INO into current inode directory as NAME", 3, 3, FL_WR, ln }, 170 { "chinum", "Change dir entry number INDEX to INUM", 3, 3, FL_WR, chinum }, --- 50 unchanged lines hidden (view full) --- 221 char **cmd_argv; 222 struct cmdtable *cmdp; 223 History *hist; 224 EditLine *elptr; 225 HistEvent he; 226 227 curinode = ginode(ROOTINO); 228 curinum = ROOTINO; |
227 printactive(); | 229 printactive(0); |
228 229 hist = history_init(); 230 history(hist, &he, H_EVENT, 100); /* 100 elt history buffer */ 231 232 elptr = el_init("fsdb", stdin, stdout, stderr); 233 el_set(elptr, EL_EDITOR, "emacs"); 234 el_set(elptr, EL_PROMPT, prompt); 235 el_set(elptr, EL_HIST, history, hist); --- 66 unchanged lines hidden (view full) --- 302{ 303 ino_t inum; 304 char *cp; 305 306 GETINUM(1,inum); 307 curinode = ginode(inum); 308 ocurrent = curinum; 309 curinum = inum; | 230 231 hist = history_init(); 232 history(hist, &he, H_EVENT, 100); /* 100 elt history buffer */ 233 234 elptr = el_init("fsdb", stdin, stdout, stderr); 235 el_set(elptr, EL_EDITOR, "emacs"); 236 el_set(elptr, EL_PROMPT, prompt); 237 el_set(elptr, EL_HIST, history, hist); --- 66 unchanged lines hidden (view full) --- 304{ 305 ino_t inum; 306 char *cp; 307 308 GETINUM(1,inum); 309 curinode = ginode(inum); 310 ocurrent = curinum; 311 curinum = inum; |
310 printactive(); | 312 printactive(0); |
311 return 0; 312} 313 314CMDFUNCSTART(back) 315{ 316 curinum = ocurrent; 317 curinode = ginode(curinum); | 313 return 0; 314} 315 316CMDFUNCSTART(back) 317{ 318 curinum = ocurrent; 319 curinode = ginode(curinum); |
318 printactive(); | 320 printactive(0); |
319 return 0; 320} 321 322CMDFUNCSTART(zapi) 323{ 324 ino_t inum; 325 struct dinode *dp; 326 char *cp; --- 4 unchanged lines hidden (view full) --- 331 inodirty(); 332 if (curinode) /* re-set after potential change */ 333 curinode = ginode(curinum); 334 return 0; 335} 336 337CMDFUNCSTART(active) 338{ | 321 return 0; 322} 323 324CMDFUNCSTART(zapi) 325{ 326 ino_t inum; 327 struct dinode *dp; 328 char *cp; --- 4 unchanged lines hidden (view full) --- 333 inodirty(); 334 if (curinode) /* re-set after potential change */ 335 curinode = ginode(curinum); 336 return 0; 337} 338 339CMDFUNCSTART(active) 340{ |
339 printactive(); | 341 printactive(0); |
340 return 0; 341} 342 | 342 return 0; 343} 344 |
345CMDFUNCSTART(blocks) 346{ 347 printactive(1); 348 return 0; 349} |
|
343 344CMDFUNCSTART(quit) 345{ 346 return -1; 347} 348 349CMDFUNCSTART(uplink) 350{ --- 75 unchanged lines hidden (view full) --- 426 idesc.id_number = curinum; 427 idesc.id_func = findino; 428 idesc.id_name = name; 429 idesc.id_type = DATA; 430 idesc.id_fix = IGNORE; 431 if (ckinode(curinode, &idesc) & FOUND) { 432 curinum = idesc.id_parent; 433 curinode = ginode(curinum); | 350 351CMDFUNCSTART(quit) 352{ 353 return -1; 354} 355 356CMDFUNCSTART(uplink) 357{ --- 75 unchanged lines hidden (view full) --- 433 idesc.id_number = curinum; 434 idesc.id_func = findino; 435 idesc.id_name = name; 436 idesc.id_type = DATA; 437 idesc.id_fix = IGNORE; 438 if (ckinode(curinode, &idesc) & FOUND) { 439 curinum = idesc.id_parent; 440 curinode = ginode(curinum); |
434 printactive(); | 441 printactive(0); |
435 return 1; 436 } else { 437 warnx("name `%s' not found in current inode directory", name); 438 return 0; 439 } 440} 441 442CMDFUNCSTART(focusname) --- 191 unchanged lines hidden (view full) --- 634 if (tp == &typenamemap[sizeof(typenamemap)/sizeof(*typenamemap)]) { 635 warnx("type `%s' not known", argv[1]); 636 warnx("try one of `file', `dir', `socket', `fifo'"); 637 return 1; 638 } 639 curinode->di_mode &= ~IFMT; 640 curinode->di_mode |= type; 641 inodirty(); | 442 return 1; 443 } else { 444 warnx("name `%s' not found in current inode directory", name); 445 return 0; 446 } 447} 448 449CMDFUNCSTART(focusname) --- 191 unchanged lines hidden (view full) --- 641 if (tp == &typenamemap[sizeof(typenamemap)/sizeof(*typenamemap)]) { 642 warnx("type `%s' not known", argv[1]); 643 warnx("try one of `file', `dir', `socket', `fifo'"); 644 return 1; 645 } 646 curinode->di_mode &= ~IFMT; 647 curinode->di_mode |= type; 648 inodirty(); |
642 printactive(); | 649 printactive(0); |
643 return 0; 644} 645 646CMDFUNCSTART(chlen) 647{ 648 int rval = 1; 649 long len; 650 char *cp; --- 4 unchanged lines hidden (view full) --- 655 len = strtol(argv[1], &cp, 0); 656 if (cp == argv[1] || *cp != '\0' || len < 0) { 657 warnx("bad length `%s'", argv[1]); 658 return 1; 659 } 660 661 curinode->di_size = len; 662 inodirty(); | 650 return 0; 651} 652 653CMDFUNCSTART(chlen) 654{ 655 int rval = 1; 656 long len; 657 char *cp; --- 4 unchanged lines hidden (view full) --- 662 len = strtol(argv[1], &cp, 0); 663 if (cp == argv[1] || *cp != '\0' || len < 0) { 664 warnx("bad length `%s'", argv[1]); 665 return 1; 666 } 667 668 curinode->di_size = len; 669 inodirty(); |
663 printactive(); | 670 printactive(0); |
664 return rval; 665} 666 667CMDFUNCSTART(chmode) 668{ 669 int rval = 1; 670 long modebits; 671 char *cp; --- 5 unchanged lines hidden (view full) --- 677 if (cp == argv[1] || *cp != '\0' || (modebits & ~07777)) { 678 warnx("bad modebits `%s'", argv[1]); 679 return 1; 680 } 681 682 curinode->di_mode &= ~07777; 683 curinode->di_mode |= modebits; 684 inodirty(); | 671 return rval; 672} 673 674CMDFUNCSTART(chmode) 675{ 676 int rval = 1; 677 long modebits; 678 char *cp; --- 5 unchanged lines hidden (view full) --- 684 if (cp == argv[1] || *cp != '\0' || (modebits & ~07777)) { 685 warnx("bad modebits `%s'", argv[1]); 686 return 1; 687 } 688 689 curinode->di_mode &= ~07777; 690 curinode->di_mode |= modebits; 691 inodirty(); |
685 printactive(); | 692 printactive(0); |
686 return rval; 687} 688 689CMDFUNCSTART(chaflags) 690{ 691 int rval = 1; 692 u_long flags; 693 char *cp; --- 8 unchanged lines hidden (view full) --- 702 } 703 704 if (flags > UINT_MAX) { 705 warnx("flags set beyond 32-bit range of field (%lx)\n", flags); 706 return(1); 707 } 708 curinode->di_flags = flags; 709 inodirty(); | 693 return rval; 694} 695 696CMDFUNCSTART(chaflags) 697{ 698 int rval = 1; 699 u_long flags; 700 char *cp; --- 8 unchanged lines hidden (view full) --- 709 } 710 711 if (flags > UINT_MAX) { 712 warnx("flags set beyond 32-bit range of field (%lx)\n", flags); 713 return(1); 714 } 715 curinode->di_flags = flags; 716 inodirty(); |
710 printactive(); | 717 printactive(0); |
711 return rval; 712} 713 714CMDFUNCSTART(chgen) 715{ 716 int rval = 1; 717 long gen; 718 char *cp; --- 8 unchanged lines hidden (view full) --- 727 } 728 729 if (gen > INT_MAX || gen < INT_MIN) { 730 warnx("gen set beyond 32-bit range of field (%lx)\n", gen); 731 return(1); 732 } 733 curinode->di_gen = gen; 734 inodirty(); | 718 return rval; 719} 720 721CMDFUNCSTART(chgen) 722{ 723 int rval = 1; 724 long gen; 725 char *cp; --- 8 unchanged lines hidden (view full) --- 734 } 735 736 if (gen > INT_MAX || gen < INT_MIN) { 737 warnx("gen set beyond 32-bit range of field (%lx)\n", gen); 738 return(1); 739 } 740 curinode->di_gen = gen; 741 inodirty(); |
735 printactive(); | 742 printactive(0); |
736 return rval; 737} 738 739CMDFUNCSTART(linkcount) 740{ 741 int rval = 1; 742 int lcnt; 743 char *cp; --- 8 unchanged lines hidden (view full) --- 752 } 753 if (lcnt > USHRT_MAX || lcnt < 0) { 754 warnx("max link count is %d\n", USHRT_MAX); 755 return 1; 756 } 757 758 curinode->di_nlink = lcnt; 759 inodirty(); | 743 return rval; 744} 745 746CMDFUNCSTART(linkcount) 747{ 748 int rval = 1; 749 int lcnt; 750 char *cp; --- 8 unchanged lines hidden (view full) --- 759 } 760 if (lcnt > USHRT_MAX || lcnt < 0) { 761 warnx("max link count is %d\n", USHRT_MAX); 762 return 1; 763 } 764 765 curinode->di_nlink = lcnt; 766 inodirty(); |
760 printactive(); | 767 printactive(0); |
761 return rval; 762} 763 764CMDFUNCSTART(chowner) 765{ 766 int rval = 1; 767 unsigned long uid; 768 char *cp; --- 10 unchanged lines hidden (view full) --- 779 } else { 780 warnx("bad uid `%s'", argv[1]); 781 return 1; 782 } 783 } 784 785 curinode->di_uid = uid; 786 inodirty(); | 768 return rval; 769} 770 771CMDFUNCSTART(chowner) 772{ 773 int rval = 1; 774 unsigned long uid; 775 char *cp; --- 10 unchanged lines hidden (view full) --- 786 } else { 787 warnx("bad uid `%s'", argv[1]); 788 return 1; 789 } 790 } 791 792 curinode->di_uid = uid; 793 inodirty(); |
787 printactive(); | 794 printactive(0); |
788 return rval; 789} 790 791CMDFUNCSTART(chgroup) 792{ 793 int rval = 1; 794 unsigned long gid; 795 char *cp; --- 9 unchanged lines hidden (view full) --- 805 } else { 806 warnx("bad gid `%s'", argv[1]); 807 return 1; 808 } 809 } 810 811 curinode->di_gid = gid; 812 inodirty(); | 795 return rval; 796} 797 798CMDFUNCSTART(chgroup) 799{ 800 int rval = 1; 801 unsigned long gid; 802 char *cp; --- 9 unchanged lines hidden (view full) --- 812 } else { 813 warnx("bad gid `%s'", argv[1]); 814 return 1; 815 } 816 } 817 818 curinode->di_gid = gid; 819 inodirty(); |
813 printactive(); | 820 printactive(0); |
814 return rval; 815} 816 817int 818dotime(name, rts) 819 char *name; 820 struct timespec *rts; 821{ --- 49 unchanged lines hidden (view full) --- 871 return 0; 872} 873 874CMDFUNCSTART(chmtime) 875{ 876 if (dotime(argv[1], &curinode->di_ctime)) 877 return 1; 878 inodirty(); | 821 return rval; 822} 823 824int 825dotime(name, rts) 826 char *name; 827 struct timespec *rts; 828{ --- 49 unchanged lines hidden (view full) --- 878 return 0; 879} 880 881CMDFUNCSTART(chmtime) 882{ 883 if (dotime(argv[1], &curinode->di_ctime)) 884 return 1; 885 inodirty(); |
879 printactive(); | 886 printactive(0); |
880 return 0; 881} 882 883CMDFUNCSTART(chatime) 884{ 885 if (dotime(argv[1], &curinode->di_ctime)) 886 return 1; 887 inodirty(); | 887 return 0; 888} 889 890CMDFUNCSTART(chatime) 891{ 892 if (dotime(argv[1], &curinode->di_ctime)) 893 return 1; 894 inodirty(); |
888 printactive(); | 895 printactive(0); |
889 return 0; 890} 891 892CMDFUNCSTART(chctime) 893{ 894 if (dotime(argv[1], &curinode->di_ctime)) 895 return 1; 896 inodirty(); | 896 return 0; 897} 898 899CMDFUNCSTART(chctime) 900{ 901 if (dotime(argv[1], &curinode->di_ctime)) 902 return 1; 903 inodirty(); |
897 printactive(); | 904 printactive(0); |
898 return 0; 899} | 905 return 0; 906} |