fsdb.c (122621) | fsdb.c (136322) |
---|---|
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 122621 2003-11-13 19:08:43Z johan $"; | 33 "$FreeBSD: head/sbin/fsdb/fsdb.c 136322 2004-10-09 15:56:34Z le $"; |
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> --- 132 unchanged lines hidden (view full) --- 174 { "chflags", "Change flags of current inode to FLAGS", 2, 2, FL_WR, chaflags }, 175 { "chgen", "Change generation number of current inode to GEN", 2, 2, FL_WR, chgen }, 176 { "mtime", "Change mtime of current inode to MTIME", 2, 2, FL_WR, chmtime }, 177 { "ctime", "Change ctime of current inode to CTIME", 2, 2, FL_WR, chctime }, 178 { "atime", "Change atime of current inode to ATIME", 2, 2, FL_WR, chatime }, 179 { "quit", "Exit", 1, 1, FL_RO, quit }, 180 { "q", "Exit", 1, 1, FL_RO, quit }, 181 { "exit", "Exit", 1, 1, FL_RO, quit }, | 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> --- 132 unchanged lines hidden (view full) --- 174 { "chflags", "Change flags of current inode to FLAGS", 2, 2, FL_WR, chaflags }, 175 { "chgen", "Change generation number of current inode to GEN", 2, 2, FL_WR, chgen }, 176 { "mtime", "Change mtime of current inode to MTIME", 2, 2, FL_WR, chmtime }, 177 { "ctime", "Change ctime of current inode to CTIME", 2, 2, FL_WR, chctime }, 178 { "atime", "Change atime of current inode to ATIME", 2, 2, FL_WR, chatime }, 179 { "quit", "Exit", 1, 1, FL_RO, quit }, 180 { "q", "Exit", 1, 1, FL_RO, quit }, 181 { "exit", "Exit", 1, 1, FL_RO, quit }, |
182 { NULL, 0, 0, 0 }, | 182 { NULL, 0, 0, 0, 0, NULL }, |
183}; 184 185int 186helpfn(int argc, char *argv[]) 187{ 188 struct cmdtable *cmdtp; 189 190 printf("Commands are:\n%-10s %5s %5s %s\n", --- 155 unchanged lines hidden (view full) --- 346{ 347 return -1; 348} 349 350CMDFUNCSTART(uplink) 351{ 352 if (!checkactive()) 353 return 1; | 183}; 184 185int 186helpfn(int argc, char *argv[]) 187{ 188 struct cmdtable *cmdtp; 189 190 printf("Commands are:\n%-10s %5s %5s %s\n", --- 155 unchanged lines hidden (view full) --- 346{ 347 return -1; 348} 349 350CMDFUNCSTART(uplink) 351{ 352 if (!checkactive()) 353 return 1; |
354 DIP(curinode, di_nlink) += 1; | 354 DIP_SET(curinode, di_nlink, DIP(curinode, di_nlink) + 1); |
355 printf("inode %d link count now %d\n", curinum, DIP(curinode, di_nlink)); 356 inodirty(); 357 return 0; 358} 359 360CMDFUNCSTART(downlink) 361{ 362 if (!checkactive()) 363 return 1; | 355 printf("inode %d link count now %d\n", curinum, DIP(curinode, di_nlink)); 356 inodirty(); 357 return 0; 358} 359 360CMDFUNCSTART(downlink) 361{ 362 if (!checkactive()) 363 return 1; |
364 DIP(curinode, di_nlink) -= 1; | 364 DIP_SET(curinode, di_nlink, DIP(curinode, di_nlink) - 1); |
365 printf("inode %d link count now %d\n", curinum, DIP(curinode, di_nlink)); 366 inodirty(); 367 return 0; 368} 369 370const char *typename[] = { 371 "unknown", 372 "fifo", --- 257 unchanged lines hidden (view full) --- 630 break; 631 } 632 } 633 if (tp == &typenamemap[sizeof(typenamemap)/sizeof(*typenamemap)]) { 634 warnx("type `%s' not known", argv[1]); 635 warnx("try one of `file', `dir', `socket', `fifo'"); 636 return 1; 637 } | 365 printf("inode %d link count now %d\n", curinum, DIP(curinode, di_nlink)); 366 inodirty(); 367 return 0; 368} 369 370const char *typename[] = { 371 "unknown", 372 "fifo", --- 257 unchanged lines hidden (view full) --- 630 break; 631 } 632 } 633 if (tp == &typenamemap[sizeof(typenamemap)/sizeof(*typenamemap)]) { 634 warnx("type `%s' not known", argv[1]); 635 warnx("try one of `file', `dir', `socket', `fifo'"); 636 return 1; 637 } |
638 DIP(curinode, di_mode) &= ~IFMT; 639 DIP(curinode, di_mode) |= type; | 638 DIP_SET(curinode, di_mode, DIP(curinode, di_mode) & ~IFMT); 639 DIP_SET(curinode, di_mode, DIP(curinode, di_mode) | type); |
640 inodirty(); 641 printactive(0); 642 return 0; 643} 644 645CMDFUNCSTART(chlen) 646{ 647 int rval = 1; --- 4 unchanged lines hidden (view full) --- 652 return 1; 653 654 len = strtol(argv[1], &cp, 0); 655 if (cp == argv[1] || *cp != '\0' || len < 0) { 656 warnx("bad length `%s'", argv[1]); 657 return 1; 658 } 659 | 640 inodirty(); 641 printactive(0); 642 return 0; 643} 644 645CMDFUNCSTART(chlen) 646{ 647 int rval = 1; --- 4 unchanged lines hidden (view full) --- 652 return 1; 653 654 len = strtol(argv[1], &cp, 0); 655 if (cp == argv[1] || *cp != '\0' || len < 0) { 656 warnx("bad length `%s'", argv[1]); 657 return 1; 658 } 659 |
660 DIP(curinode, di_size) = len; | 660 DIP_SET(curinode, di_size, len); |
661 inodirty(); 662 printactive(0); 663 return rval; 664} 665 666CMDFUNCSTART(chmode) 667{ 668 int rval = 1; --- 4 unchanged lines hidden (view full) --- 673 return 1; 674 675 modebits = strtol(argv[1], &cp, 8); 676 if (cp == argv[1] || *cp != '\0' || (modebits & ~07777)) { 677 warnx("bad modebits `%s'", argv[1]); 678 return 1; 679 } 680 | 661 inodirty(); 662 printactive(0); 663 return rval; 664} 665 666CMDFUNCSTART(chmode) 667{ 668 int rval = 1; --- 4 unchanged lines hidden (view full) --- 673 return 1; 674 675 modebits = strtol(argv[1], &cp, 8); 676 if (cp == argv[1] || *cp != '\0' || (modebits & ~07777)) { 677 warnx("bad modebits `%s'", argv[1]); 678 return 1; 679 } 680 |
681 DIP(curinode, di_mode) &= ~07777; 682 DIP(curinode, di_mode) |= modebits; | 681 DIP_SET(curinode, di_mode, DIP(curinode, di_mode) & ~07777); 682 DIP_SET(curinode, di_mode, DIP(curinode, di_mode) | modebits); |
683 inodirty(); 684 printactive(0); 685 return rval; 686} 687 688CMDFUNCSTART(chaflags) 689{ 690 int rval = 1; --- 8 unchanged lines hidden (view full) --- 699 warnx("bad flags `%s'", argv[1]); 700 return 1; 701 } 702 703 if (flags > UINT_MAX) { 704 warnx("flags set beyond 32-bit range of field (%lx)\n", flags); 705 return(1); 706 } | 683 inodirty(); 684 printactive(0); 685 return rval; 686} 687 688CMDFUNCSTART(chaflags) 689{ 690 int rval = 1; --- 8 unchanged lines hidden (view full) --- 699 warnx("bad flags `%s'", argv[1]); 700 return 1; 701 } 702 703 if (flags > UINT_MAX) { 704 warnx("flags set beyond 32-bit range of field (%lx)\n", flags); 705 return(1); 706 } |
707 DIP(curinode, di_flags) = flags; | 707 DIP_SET(curinode, di_flags, flags); |
708 inodirty(); 709 printactive(0); 710 return rval; 711} 712 713CMDFUNCSTART(chgen) 714{ 715 int rval = 1; --- 8 unchanged lines hidden (view full) --- 724 warnx("bad gen `%s'", argv[1]); 725 return 1; 726 } 727 728 if (gen > INT_MAX || gen < INT_MIN) { 729 warnx("gen set beyond 32-bit range of field (%lx)\n", gen); 730 return(1); 731 } | 708 inodirty(); 709 printactive(0); 710 return rval; 711} 712 713CMDFUNCSTART(chgen) 714{ 715 int rval = 1; --- 8 unchanged lines hidden (view full) --- 724 warnx("bad gen `%s'", argv[1]); 725 return 1; 726 } 727 728 if (gen > INT_MAX || gen < INT_MIN) { 729 warnx("gen set beyond 32-bit range of field (%lx)\n", gen); 730 return(1); 731 } |
732 DIP(curinode, di_gen) = gen; | 732 DIP_SET(curinode, di_gen, gen); |
733 inodirty(); 734 printactive(0); 735 return rval; 736} 737 738CMDFUNCSTART(linkcount) 739{ 740 int rval = 1; --- 8 unchanged lines hidden (view full) --- 749 warnx("bad link count `%s'", argv[1]); 750 return 1; 751 } 752 if (lcnt > USHRT_MAX || lcnt < 0) { 753 warnx("max link count is %d\n", USHRT_MAX); 754 return 1; 755 } 756 | 733 inodirty(); 734 printactive(0); 735 return rval; 736} 737 738CMDFUNCSTART(linkcount) 739{ 740 int rval = 1; --- 8 unchanged lines hidden (view full) --- 749 warnx("bad link count `%s'", argv[1]); 750 return 1; 751 } 752 if (lcnt > USHRT_MAX || lcnt < 0) { 753 warnx("max link count is %d\n", USHRT_MAX); 754 return 1; 755 } 756 |
757 DIP(curinode, di_nlink) = lcnt; | 757 DIP_SET(curinode, di_nlink, lcnt); |
758 inodirty(); 759 printactive(0); 760 return rval; 761} 762 763CMDFUNCSTART(chowner) 764{ 765 int rval = 1; --- 10 unchanged lines hidden (view full) --- 776 if ((pwd = getpwnam(argv[1]))) { 777 uid = pwd->pw_uid; 778 } else { 779 warnx("bad uid `%s'", argv[1]); 780 return 1; 781 } 782 } 783 | 758 inodirty(); 759 printactive(0); 760 return rval; 761} 762 763CMDFUNCSTART(chowner) 764{ 765 int rval = 1; --- 10 unchanged lines hidden (view full) --- 776 if ((pwd = getpwnam(argv[1]))) { 777 uid = pwd->pw_uid; 778 } else { 779 warnx("bad uid `%s'", argv[1]); 780 return 1; 781 } 782 } 783 |
784 DIP(curinode, di_uid) = uid; | 784 DIP_SET(curinode, di_uid, uid); |
785 inodirty(); 786 printactive(0); 787 return rval; 788} 789 790CMDFUNCSTART(chgroup) 791{ 792 int rval = 1; --- 9 unchanged lines hidden (view full) --- 802 if ((grp = getgrnam(argv[1]))) { 803 gid = grp->gr_gid; 804 } else { 805 warnx("bad gid `%s'", argv[1]); 806 return 1; 807 } 808 } 809 | 785 inodirty(); 786 printactive(0); 787 return rval; 788} 789 790CMDFUNCSTART(chgroup) 791{ 792 int rval = 1; --- 9 unchanged lines hidden (view full) --- 802 if ((grp = getgrnam(argv[1]))) { 803 gid = grp->gr_gid; 804 } else { 805 warnx("bad gid `%s'", argv[1]); 806 return 1; 807 } 808 } 809 |
810 DIP(curinode, di_gid) = gid; | 810 DIP_SET(curinode, di_gid, gid); |
811 inodirty(); 812 printactive(0); 813 return rval; 814} 815 816int 817dotime(char *name, time_t *secp, int32_t *nsecp) 818{ --- 53 unchanged lines hidden (view full) --- 872 int32_t nsecs; 873 874 if (dotime(argv[1], &secs, &nsecs)) 875 return 1; 876 if (sblock.fs_magic == FS_UFS1_MAGIC) 877 curinode->dp1.di_mtime = _time_to_time32(secs); 878 else 879 curinode->dp2.di_mtime = _time_to_time64(secs); | 811 inodirty(); 812 printactive(0); 813 return rval; 814} 815 816int 817dotime(char *name, time_t *secp, int32_t *nsecp) 818{ --- 53 unchanged lines hidden (view full) --- 872 int32_t nsecs; 873 874 if (dotime(argv[1], &secs, &nsecs)) 875 return 1; 876 if (sblock.fs_magic == FS_UFS1_MAGIC) 877 curinode->dp1.di_mtime = _time_to_time32(secs); 878 else 879 curinode->dp2.di_mtime = _time_to_time64(secs); |
880 DIP(curinode, di_mtimensec) = nsecs; | 880 DIP_SET(curinode, di_mtimensec, nsecs); |
881 inodirty(); 882 printactive(0); 883 return 0; 884} 885 886CMDFUNCSTART(chatime) 887{ 888 time_t secs; 889 int32_t nsecs; 890 891 if (dotime(argv[1], &secs, &nsecs)) 892 return 1; 893 if (sblock.fs_magic == FS_UFS1_MAGIC) 894 curinode->dp1.di_atime = _time_to_time32(secs); 895 else 896 curinode->dp2.di_atime = _time_to_time64(secs); | 881 inodirty(); 882 printactive(0); 883 return 0; 884} 885 886CMDFUNCSTART(chatime) 887{ 888 time_t secs; 889 int32_t nsecs; 890 891 if (dotime(argv[1], &secs, &nsecs)) 892 return 1; 893 if (sblock.fs_magic == FS_UFS1_MAGIC) 894 curinode->dp1.di_atime = _time_to_time32(secs); 895 else 896 curinode->dp2.di_atime = _time_to_time64(secs); |
897 DIP(curinode, di_atimensec) = nsecs; | 897 DIP_SET(curinode, di_atimensec, nsecs); |
898 inodirty(); 899 printactive(0); 900 return 0; 901} 902 903CMDFUNCSTART(chctime) 904{ 905 time_t secs; 906 int32_t nsecs; 907 908 if (dotime(argv[1], &secs, &nsecs)) 909 return 1; 910 if (sblock.fs_magic == FS_UFS1_MAGIC) 911 curinode->dp1.di_ctime = _time_to_time32(secs); 912 else 913 curinode->dp2.di_ctime = _time_to_time64(secs); | 898 inodirty(); 899 printactive(0); 900 return 0; 901} 902 903CMDFUNCSTART(chctime) 904{ 905 time_t secs; 906 int32_t nsecs; 907 908 if (dotime(argv[1], &secs, &nsecs)) 909 return 1; 910 if (sblock.fs_magic == FS_UFS1_MAGIC) 911 curinode->dp1.di_ctime = _time_to_time32(secs); 912 else 913 curinode->dp2.di_ctime = _time_to_time64(secs); |
914 DIP(curinode, di_ctimensec) = nsecs; | 914 DIP_SET(curinode, di_ctimensec, nsecs); |
915 inodirty(); 916 printactive(0); 917 return 0; 918} | 915 inodirty(); 916 printactive(0); 917 return 0; 918} |