Annotation of researchv10no/cmd/setpart.c, revision 1.1.1.1

1.1       root        1: #include <stdio.h>
                      2: #include <ctype.h>
                      3: #include <sys/diskio.h>
                      4: 
                      5: main(argc, argv)
                      6: int argc;
                      7: char **argv;
                      8: {
                      9: 
                     10:        if (argc > 2 && strcmp(argv[1], "-f") == 0)
                     11:                exit(filepart(argv[2]));
                     12:        if (argc < 2) {
                     13:                fprintf(stderr, "usage: setpart device firstblock [size]\n");
                     14:                fprintf(stderr, "\tor setpart -f file\n");
                     15:                exit(1);
                     16:        }
                     17:        exit(setpart(argc-1, argv+1));
                     18: }
                     19: 
                     20: filepart(file)
                     21: char *file;
                     22: {
                     23:        FILE *fp;
                     24:        char line[100];         /* arbitrarily large */
                     25:        char *args[4];
                     26:        int nargs;
                     27:        int status;
                     28: 
                     29:        if ((fp = fopen(file, "r")) == NULL) {
                     30:                fprintf(stderr, "%s: cannot open\n");
                     31:                return (1);
                     32:        }
                     33:        status = 0;
                     34:        while (fgets(line, sizeof(line), fp) != NULL) {
                     35:                if (line[0] == '#')
                     36:                        continue;
                     37:                if ((nargs = getmfields(line, args, 4)) < 2)
                     38:                        continue;
                     39:                if (setpart(nargs, args))
                     40:                        status = 1;
                     41:        }
                     42:        fclose(fp);
                     43:        return (status);
                     44: }
                     45: 
                     46: setpart(n, arg)
                     47: int n;
                     48: char **arg;
                     49: {
                     50:        int fd;
                     51:        long parts[2];
                     52:        long atol();
                     53: 
                     54:        if (n < 1) {
                     55:                fprintf(stderr, "internal: too few args\n");
                     56:                return (1);
                     57:        }
                     58:        if ((fd = open(arg[0], 1)) < 0) {
                     59:                perror(arg[0]);
                     60:                return (1);
                     61:        }
                     62:        if (n < 2) {
                     63:                if (ioctl(fd, DIOGSIZ, parts) < 0) {
                     64:                        perror(arg[0]);
                     65:                        close(fd);
                     66:                        return (1);
                     67:                }
                     68:                printf("%s\t%ld\t\%ld\n", arg[0], parts[0], parts[1]);
                     69:        } else {
                     70:                if (!isdigit(arg[1][0])) {
                     71:                        fprintf(stderr, "%s: bad firstblock %s\n", arg[0], arg[1]);
                     72:                        close(fd);
                     73:                        return (1);
                     74:                }
                     75:                if (n > 2 && !isdigit(arg[2][0])) {
                     76:                        fprintf(stderr, "%s: bad nblock %s\n", arg[0], arg[2]);
                     77:                        close(fd);
                     78:                        return (1);
                     79:                }
                     80:                parts[0] = atol(arg[1]);
                     81:                if (n > 2)
                     82:                        parts[1] = atoi(arg[2]);
                     83:                else
                     84:                        parts[1] = 0x7fffffff;  /* huge */
                     85:                if (ioctl(fd, DIOSSIZ, parts) < 0) {
                     86:                        perror(arg[0]);
                     87:                        close(fd);
                     88:                        return (1);
                     89:                }
                     90:        }
                     91:        close(fd);
                     92:        return (0);
                     93: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.