See question in gpt.c (and others).

On Nov 30,  2:59pm, "Christos Zoulas" wrote:
}
} This is a multi-part message in MIME format.
} 
} --_----------=_1448913574208280
} Content-Disposition: inline
} Content-Transfer-Encoding: 8bit
} Content-Type: text/plain; charset="US-ASCII"
} 
} Module Name:  src
} Committed By: christos
} Date:         Mon Nov 30 19:59:34 UTC 2015
} 
} Modified Files:
}       src/sbin/gpt: Makefile add.c gpt.8 gpt.c gpt.h resize.c
} Added Files:
}       src/sbin/gpt: main.c
} 
} Log Message:
} - automatically sync the wedge information unless -n is specified.
} - document the general options in the traditional way.
} - split the main program into a separate file.
} 
} 
} To generate a diff of this commit:
} cvs rdiff -u -r1.15 -r1.16 src/sbin/gpt/Makefile
} cvs rdiff -u -r1.28 -r1.29 src/sbin/gpt/add.c
} cvs rdiff -u -r1.37 -r1.38 src/sbin/gpt/gpt.8
} cvs rdiff -u -r1.45 -r1.46 src/sbin/gpt/gpt.c
} cvs rdiff -u -r1.21 -r1.22 src/sbin/gpt/gpt.h
} cvs rdiff -u -r0 -r1.1 src/sbin/gpt/main.c
} cvs rdiff -u -r1.12 -r1.13 src/sbin/gpt/resize.c
} 
} Please note that diffs are not public domain; they are subject to the
} copyright notices on the relevant files.
} 
} 
} --_----------=_1448913574208280
} Content-Disposition: inline
} Content-Length: 17047
} Content-Transfer-Encoding: binary
} Content-Type: text/x-diff; charset=us-ascii
} 
} Modified files:
} 
} Index: src/sbin/gpt/add.c
} diff -u src/sbin/gpt/add.c:1.28 src/sbin/gpt/add.c:1.29
} --- src/sbin/gpt/add.c:1.28   Sat Nov 28 19:14:46 2015
} +++ src/sbin/gpt/add.c        Mon Nov 30 14:59:34 2015
} @@ -33,7 +33,7 @@
}  __FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp 
$");
}  #endif
}  #ifdef __RCSID
} -__RCSID("$NetBSD: add.c,v 1.28 2015/11/29 00:14:46 christos Exp $");
} +__RCSID("$NetBSD: add.c,v 1.29 2015/11/30 19:59:34 christos Exp $");
}  #endif
}  
}  #include <sys/types.h>
} @@ -180,10 +180,9 @@ add(int fd)
}       gpt_write(fd, lbt);
}       gpt_write(fd, tpg);
}  
} -     printf("Partition %d added, use:\n", i + 1);
} -     printf("\tdkctl %s addwedge <wedgename> %" PRIu64 " %" PRIu64
} -         " <type>\n", device_arg, map->map_start, map->map_size);
} -     printf("to create a wedge for it\n");
} +     printf("Partition %d added on %s: ", i + 1, device_arg);
} +     printf("%s %" PRIu64 " %" PRIu64 "\n", type, map->map_start,
} +         map->map_size);

     This message needs to depend on the new -n flag, otherwise it
may give incorrect information.

}  }
}  
}  int
} 
} Index: src/sbin/gpt/gpt.c
} diff -u src/sbin/gpt/gpt.c:1.45 src/sbin/gpt/gpt.c:1.46
} --- src/sbin/gpt/gpt.c:1.45   Sun Nov 29 09:03:35 2015
} +++ src/sbin/gpt/gpt.c        Mon Nov 30 14:59:34 2015
} @@ -35,7 +35,7 @@
}  __FBSDID("$FreeBSD: src/sbin/gpt/gpt.c,v 1.16 2006/07/07 02:44:23 marcel Exp 
$");
}  #endif
}  #ifdef __RCSID
} -__RCSID("$NetBSD: gpt.c,v 1.45 2015/11/29 14:03:35 christos Exp $");
} +__RCSID("$NetBSD: gpt.c,v 1.46 2015/11/30 19:59:34 christos Exp $");
}  #endif
}  
}  #include <sys/param.h>
} @@ -68,7 +68,9 @@ off_t       mediasz;
}  u_int        parts;
}  u_int        secsz;
}  
} -int  readonly, verbose, quiet;
} +int  readonly, verbose, quiet, nosync;
} +
} +static int modified;
}  
}  static uint32_t crc32_tab[] = {
}       0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
} @@ -269,10 +271,11 @@ gpt_write(int fd, map_t *map)
}  
}       count = map->map_size * secsz;
}       ofs = map->map_start * secsz;
} -     if (lseek(fd, ofs, SEEK_SET) == ofs &&
} -         write(fd, map->map_data, count) == (ssize_t)count)
} -             return (0);
} -     return (-1);
} +     if (lseek(fd, ofs, SEEK_SET) != ofs ||

     Why did you change the "&&" to "||"?  If the lseek() fails,
you will now be writing data to the wrong place on the disk.

} +         write(fd, map->map_data, count) != (ssize_t)count)
} +             return -1;
} +     modified = 1;
} +     return 0;
}  }
}  
}  static int
} @@ -569,6 +572,12 @@ gpt_open(const char *dev, int flags)
}  void
}  gpt_close(int fd)
}  {
} +     int bits;
} +
} +     if (modified && !nosync)
} +             if (ioctl(fd, DIOCMWEDGES, &bits) == -1)
} +                     warn("Can't update wedge information");
} +
}       /* XXX post processing? */
}       close(fd);
}  }
} @@ -583,172 +592,3 @@ gpt_msg(const char *fmt, ...)
}       va_end(ap);
}       printf("\n");
}  }
} -
} -static struct {
} -     int (*fptr)(int, char *[]);
} -     const char *name;
} -} cmdsw[] = {
} -     { cmd_add, "add" },
} -#ifndef HAVE_NBTOOL_CONFIG_H
} -     { cmd_backup, "backup" },
} -#endif
} -     { cmd_biosboot, "biosboot" },
} -     { cmd_create, "create" },
} -     { cmd_destroy, "destroy" },
} -     { cmd_header, "header" },
} -     { NULL, "help" },
} -     { cmd_label, "label" },
} -     { cmd_migrate, "migrate" },
} -     { cmd_recover, "recover" },
} -     { cmd_remove, "remove" },
} -     { NULL, "rename" },
} -     { cmd_resize, "resize" },
} -     { cmd_resizedisk, "resizedisk" },
} -#ifndef HAVE_NBTOOL_CONFIG_H
} -     { cmd_restore, "restore" },
} -#endif
} -     { cmd_set, "set" },
} -     { cmd_show, "show" },
} -     { cmd_type, "type" },
} -     { cmd_unset, "unset" },
} -     { NULL, "verify" },
} -     { NULL, NULL }
} -};
} -
} -__dead static void
} -usage(void)
} -{
} -     extern const char addmsg1[], addmsg2[], biosbootmsg[];
} -     extern const char createmsg[], destroymsg[], headermsg[], labelmsg1[];
} -     extern const char labelmsg2[], labelmsg3[], migratemsg[], recovermsg[];
} -     extern const char removemsg1[], removemsg2[], resizemsg[];
} -     extern const char resizediskmsg[], setmsg[], showmsg[], typemsg1[];
} -     extern const char typemsg2[], typemsg3[], unsetmsg[];
} -#ifndef HAVE_NBTOOL_CONFIG_H
} -     extern const char backupmsg[], restoremsg[];
} -#endif
} -     const char *p = getprogname();
} -     const char *f =
} -         "[-rv] [-m <mediasize>] [-p <partitionnum>] [-s <sectorsize>]";
} -
} -     fprintf(stderr,
} -         "Usage: %s %s <command> [<args>]\n", p, f);
} -     fprintf(stderr, 
} -         "Commands:\n"
} -#ifndef HAVE_NBTOOL_CONFIG_H
} -         "       %s\n"
} -         "       %s\n"
} -#endif
} -         "       %s\n"
} -         "       %s\n"
} -         "       %s\n"
} -         "       %s\n"
} -         "       %s\n"
} -         "       %s\n"
} -         "       %s\n"
} -         "       %s\n"
} -         "       %s\n"
} -         "       %s\n"
} -         "       %s\n"
} -         "       %s\n"
} -         "       %s\n"
} -         "       %s\n"
} -         "       %s\n"
} -         "       %s\n"
} -         "       %s\n"
} -         "       %s\n"
} -         "       %s\n"
} -         "       %s\n"
} -         "       %s\n",
} -         addmsg1, addmsg2,
} -#ifndef HAVE_NBTOOL_CONFIG_H
} -         backupmsg,
} -#endif
} -         biosbootmsg, createmsg, destroymsg,
} -         headermsg, labelmsg1, labelmsg2, labelmsg3,
} -         migratemsg, recovermsg,
} -         removemsg1, removemsg2,
} -         resizemsg, resizediskmsg,
} -#ifndef HAVE_NBTOOL_CONFIG_H
} -         restoremsg,
} -#endif
} -         setmsg, showmsg,
} -         typemsg1, typemsg2, typemsg3,
} -         unsetmsg);
} -     exit(1);
} -}
} -
} -static void
} -prefix(const char *cmd)
} -{
} -     char *pfx;
} -     const char *prg;
} -
} -     prg = getprogname();
} -     pfx = malloc(strlen(prg) + strlen(cmd) + 2);
} -     /* Don't bother failing. It's not important */
} -     if (pfx == NULL)
} -             return;
} -
} -     sprintf(pfx, "%s %s", prg, cmd);
} -     setprogname(pfx);
} -}
} -
} -int
} -main(int argc, char *argv[])
} -{
} -     char *cmd, *p;
} -     int ch, i;
} -
} -     /* Get the generic options */
} -     while ((ch = getopt(argc, argv, "m:p:qrs:v")) != -1) {
} -             switch(ch) {
} -             case 'm':
} -                     if (mediasz > 0)
} -                             usage();
} -                     mediasz = strtoul(optarg, &p, 10);
} -                     if (*p != 0 || mediasz < 1)
} -                             usage();
} -                     break;
} -             case 'p':
} -                     if (parts > 0)
} -                             usage();
} -                     parts = strtoul(optarg, &p, 10);
} -                     if (*p != 0 || parts < 1)
} -                             usage();
} -                     break;
} -             case 'r':
} -                     readonly = 1;
} -                     break;
} -             case 'q':
} -                     quiet = 1;
} -                     break;
} -             case 's':
} -                     if (secsz > 0)
} -                             usage();
} -                     secsz = strtoul(optarg, &p, 10);
} -                     if (*p != 0 || secsz < 1)
} -                             usage();
} -                     break;
} -             case 'v':
} -                     verbose++;
} -                     break;
} -             default:
} -                     usage();
} -             }
} -     }
} -     if (!parts)
} -             parts = 128;
} -
} -     if (argc == optind)
} -             usage();
} -
} -     cmd = argv[optind++];
} -     for (i = 0; cmdsw[i].name != NULL && strcmp(cmd, cmdsw[i].name); i++);
} -
} -     if (cmdsw[i].fptr == NULL)
} -             errx(1, "unknown command: %s", cmd);
} -
} -     prefix(cmd);
} -     return ((*cmdsw[i].fptr)(argc, argv));
} -}
} 
} Index: src/sbin/gpt/resize.c
} diff -u src/sbin/gpt/resize.c:1.12 src/sbin/gpt/resize.c:1.13
} --- src/sbin/gpt/resize.c:1.12        Sat Nov 28 19:14:46 2015
} +++ src/sbin/gpt/resize.c     Mon Nov 30 14:59:34 2015
} @@ -33,7 +33,7 @@
}  __FBSDID("$FreeBSD: src/sbin/gpt/add.c,v 1.14 2006/06/22 22:05:28 marcel Exp 
$");
}  #endif
}  #ifdef __RCSID
} -__RCSID("$NetBSD: resize.c,v 1.12 2015/11/29 00:14:46 christos Exp $");
} +__RCSID("$NetBSD: resize.c,v 1.13 2015/11/30 19:59:34 christos Exp $");
}  #endif
}  
}  #include <sys/types.h>
} @@ -166,10 +166,8 @@ resize(int fd)
}       gpt_write(fd, lbt);
}       gpt_write(fd, tpg);
}  
} -     printf("Partition %d resized, use:\n", entry);
} -     printf("\tdkctl %s addwedge <wedgename> %" PRIu64 " %" PRIu64
} -         " <type>\n", device_arg, map->map_start, newsize);
} -     printf("to create a wedge for it\n");
} +     printf("Partition %d resized on %s: ", entry, device_arg);
} +     printf("%" PRIu64 " %" PRIu64 "\n", map->map_start, newsize);

     This message needs to depend on the new -n flag, otherwise it
may give incorrect information.

}  }
}  
}  int
} 
} --_----------=_1448913574208280--
} 
}-- End of excerpt from "Christos Zoulas"

Reply via email to