Skip to contentSkip to conversation

fdformat: Add new switches -f/--from, -t/--to, -r/--repair

PATCH Applied Jaromir Capik 3 participants 10 messages Jul 25, 2014 – Sep 16, 2014 1 message not in the archive Util-Linux package

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 fdformat: Add new switches -f/--from, -t/--to, -r/--repair

Hello everyone.

The attached patch adds support for user configurable from/to track and a basic repair mode for broken floppies. It also fixes a recently introduced bug that causes line breakage when printing the track number.

Please, review and share your feelings / merge.

Thanks in advance,
Jaromir.

--
Jaromir Capik
Red Hat Czech, s.r.o.
Software Engineer / Secondary Arch

Email: [email protected]
Web: www.cz.redhat.com
Red Hat Czech s.r.o., Purkynova 99/71, 612 45, Brno, Czech Republic
IC: 27690016

From d3543ce591fd34a787176993958237864049fbe0 Mon Sep 17 00:00:00 2001
From: Jaromir Capik <[email protected]>
Date: Fri, 25 Jul 2014 17:16:56 +0200
Subject: [PATCH] fdformat: Add new switches -f/--from, -t/--to, -r/--repair

This commit introduces a support for user configurable from/to track and a basic repair mode for broken floppies. It also fixes a recently introduced bug that causes a line breakage when printing the track number.

---
 disk-utils/Makemodule.am |   1 +
 disk-utils/fdformat.8    |  11 ++-
 disk-utils/fdformat.c    | 206 +++++++++++++++++++++++++++++++++--------------
 3 files changed, 157 insertions(+), 61 deletions(-)
disk-utils/Makemodule.am +1 -0
index c6183f5..995e085 100644
@@ -110,6 +110,7 @@ if BUILD_FDFORMAT
 usrsbin_exec_PROGRAMS += fdformat
 dist_man_MANS += disk-utils/fdformat.8
 fdformat_SOURCES = disk-utils/fdformat.c
+fdformat_LDADD = $(LDADD) libcommon.la
 endif
 
 if BUILD_BLOCKDEV
disk-utils/fdformat.8 +10 -1
index df4153f..797f50f 100644
@@ -1,6 +1,6 @@
 .\" Copyright 1992, 1993 Rickard E. Faith ([email protected])
 .\" May be distributed under the GNU General Public License
-.TH FDFORMAT 8 "July 2011" "util-linux" "System Administration"
+.TH FDFORMAT 8 "July 2014" "util-linux" "System Administration"
 .SH NAME
 fdformat \- low-level format a floppy disk
 .SH SYNOPSIS
@@ -45,6 +45,15 @@ autodetected earlier.  In this case, use
 to load the disk parameters.
 .SH OPTIONS
 .TP
+\fB\-f\fR, \fB\-\-from\fR \fIN\fR
+Start at the track \fIN\fR (default is 0).
+.TP
+\fB\-t\fR, \fB\-\-to\fR \fIN\fR
+Stop at the track \fIN\fR (default is 0).
+.TP
+\fB\-r\fR, \fB\-\-repair\fR \fIN\fR
+Try to repair tracks failed during the verification (max \fIN\fR retries).
+.TP
 \fB\-n\fR, \fB\-\-no-verify\fR
 Skip the verification that is normally performed after the formatting.
 .TP
disk-utils/fdformat.c +146 -60

277 lines not on this page · raw message

Signature · 1 line
1.9.3
#2 lore raw

On 25 July 2014 16:29, Jaromir Capik <[email protected]> wrote:

Hi Jaromir,

Quoted 2 lines

It also fixes a recently introduced bug that causes line breakage when printing the track number.

Do you mean commit 18b1fcb9cc62f4dd26eccd1c35f612ac6db1cd9b or some other change? It would be nice to know details of what exactly was wrong, and how the fix is fixing it. The change you sent is rather long, and at least I cannot see where is the correction. That said splitting the change to smaller chunks would be nice.

Quoted 60 lines
disk-utils/Makemodule.am +1 -0
index c6183f5..995e085 100644
@@ -110,6 +110,7 @@ if BUILD_FDFORMAT
 usrsbin_exec_PROGRAMS += fdformat
 dist_man_MANS += disk-utils/fdformat.8
 fdformat_SOURCES = disk-utils/fdformat.c
+fdformat_LDADD = $(LDADD) libcommon.la
 endif
 
 if BUILD_BLOCKDEV
disk-utils/fdformat.8 +10 -1
index df4153f..797f50f 100644
@@ -1,6 +1,6 @@
 .\" Copyright 1992, 1993 Rickard E. Faith ([email protected])
 .\" May be distributed under the GNU General Public License
-.TH FDFORMAT 8 "July 2011" "util-linux" "System Administration"
+.TH FDFORMAT 8 "July 2014" "util-linux" "System Administration"
 .SH NAME
 fdformat \- low-level format a floppy disk
 .SH SYNOPSIS
@@ -45,6 +45,15 @@ autodetected earlier.  In this case, use
 to load the disk parameters.
 .SH OPTIONS
 .TP
+\fB\-f\fR, \fB\-\-from\fR \fIN\fR
+Start at the track \fIN\fR (default is 0).
+.TP
+\fB\-t\fR, \fB\-\-to\fR \fIN\fR
+Stop at the track \fIN\fR (default is 0).
+.TP
+\fB\-r\fR, \fB\-\-repair\fR \fIN\fR
+Try to repair tracks failed during the verification (max \fIN\fR retries).
+.TP
 \fB\-n\fR, \fB\-\-no-verify\fR
 Skip the verification that is normally performed after the formatting.
 .TP
disk-utils/fdformat.c +4 -1
index e6ae8e4..c8b2a81 100644
@@ -12,6 +12,7 @@
 #include <unistd.h>
 
 #include "c.h"
+#include "strutils.h"
 #include "closestream.h"
 #include "nls.h"
 #include "xalloc.h"
@@ -20,74 +21,119 @@ struct floppy_struct param;
 
 #define SECTOR_SIZE 512
 
-static void format_disk(int ctrl)
+
+static void format_begin(int ctrl)
+{

disk-utils/fdformat.c struct floppy_struct param; · line 36

Quoted 10 lines
disk-utils/fdformat.c +10 -0
+ if (ioctl(ctrl, FDFMTBEG, NULL) < 0)
+ err(EXIT_FAILURE, "ioctl: FDFMTBEG");
+}
+
+static void format_end(int ctrl)
+{
+ if (ioctl(ctrl, FDFMTEND, NULL) < 0)
+ err(EXIT_FAILURE, "ioctl: FDFMTEND");
+}
+

The format_begin() and format_end() are not doing much, are they really needed?

Quoted 6 lines
disk-utils/fdformat.c +3 -1
+static void format_track_head(int ctrl, unsigned int track, unsigned int head)
 {
  struct format_descr descr;
- unsigned int track;
+
+ descr.track = track;

disk-utils/fdformat.c struct floppy_struct param; · line 51

Quoted 10 lines
disk-utils/fdformat.c +10 -0
+ descr.head = head;
+ if (ioctl(ctrl, FDFMTTRK, (long) &descr) < 0)
+ err(EXIT_FAILURE, "ioctl: FDFMTTRK");
+}
+
+static void seek_track_head(int ctrl, unsigned int track, unsigned int head)
+{
+ lseek(ctrl, (track * param.head + head) * param.sect * SECTOR_SIZE, SEEK_SET);
+}
+

Would it be possible to more 'struct floppy_struct param;' out of the global scope? That would make it a bit less mysterious where param.head came from.

disk-utils/fdformat.c struct floppy_struct param; · line 54

Quoted 3 lines
disk-utils/fdformat.c +3 -0
+static void format_disk(int ctrl, unsigned int track_from, unsigned int track_to)
+{
+ unsigned int track, head;

The track & head could be replaced with

struct format_descr descr;

When the two helper variables are gone the format_track_head() turns to a single if (ioctl... statement, and I'd claim it is unnecessary.

Quoted 82 lines
disk-utils/fdformat.c +26 -44
  printf(_("Formatting ... "));
  fflush(stdout);
- if (ioctl(ctrl, FDFMTBEG, NULL) < 0)
- err(EXIT_FAILURE, "ioctl: FDFMTBEG");
- for (track = 0; track < param.track; track++) {
- descr.track = track;
- descr.head = 0;
- if (ioctl(ctrl, FDFMTTRK, (long) &descr) < 0)
- err(EXIT_FAILURE, "ioctl: FDFMTTRK");
-
- printf("%3ud\b\b\b", track);
- fflush(stdout);
- if (param.head == 2) {
- descr.head = 1;
- if (ioctl(ctrl, FDFMTTRK, (long)&descr) < 0)
- err(EXIT_FAILURE, "ioctl: FDFMTTRK");
+
+ format_begin(ctrl);
+
+ for (track = track_from; track <= track_to; track++) {
+ for (head = 0; head < param.head; head++) {
+ printf("%3u/%u\b\b\b\b\b", track, head);
+ fflush(stdout);
+ format_track_head(ctrl, track, head);
  }
  }
- if (ioctl(ctrl, FDFMTEND, NULL) < 0)
- err(EXIT_FAILURE, "ioctl: FDFMTEND");
+
+ format_end(ctrl);
+
  printf(_("done\n"));
 }
 
-static void verify_disk(char *name)
+static void verify_disk(int ctrl, unsigned int track_from, unsigned int track_to, int repair)
 {
  unsigned char *data;
- unsigned int cyl;
- int fd, cyl_size, count;
+ unsigned int track, head;
+ int track_size, count, retries_left;
 
- cyl_size = param.sect * param.head * 512;
- data = xmalloc(cyl_size);
+ track_size = param.sect * SECTOR_SIZE;
+ data = xmalloc(track_size);
  printf(_("Verifying ... "));
  fflush(stdout);
- if ((fd = open(name, O_RDONLY)) < 0)
- err(EXIT_FAILURE, _("cannot open %s"), name);
- for (cyl = 0; cyl < param.track; cyl++) {
- int read_bytes;
-
- printf("%u3d\b\b\b", cyl);
- fflush(stdout);
- read_bytes = read(fd, data, cyl_size);
- if (read_bytes != cyl_size) {
- if (read_bytes < 0)
- perror(_("Read: "));
- fprintf(stderr,
- _("Problem reading cylinder %d,"
-  " expected %d, read %d\n"),
- cyl, cyl_size, read_bytes);
- free(data);
- exit(EXIT_FAILURE);
- }
- for (count = 0; count < cyl_size; count++)
- if (data[count] != FD_FILL_BYTE) {
- printf(_("bad data in cyl %d\n"
- "Continuing ... "), cyl);
- fflush(stdout);
+
+ seek_track_head (ctrl, track_from, 0);
+
+ for (track = track_from; track <= track_to; track++) {
+ for (head = 0; head < param.head; head++) {
+ int read_bytes;
+
+ printf("%3u\b\b\b", track);
+ fflush(stdout);
+

disk-utils/fdformat.c struct floppy_struct param; · line 103

Quoted 10 lines
disk-utils/fdformat.c +10 -0
+ retries_left = repair;
+ do {
+ read_bytes = read(ctrl, data, track_size);
+ if (read_bytes != track_size) {
+ if (retries_left) {
+ format_begin(ctrl);
+ format_track_head(ctrl, track, head);
+ format_end(ctrl);
+ seek_track_head (ctrl, track, head);
+ retries_left--;

Will the retries work if IO error happens? There are calls to err() all over, so am I thinking wrong the program will exit rather than re-attempt until retries end.

disk-utils/fdformat.c struct floppy_struct param; · line 103

Quoted 1 line
disk-utils/fdformat.c +1 -0
+ if (retries_left) continue;

New line & indent step missing.

Quoted 9 lines
disk-utils/fdformat.c +9 -0
+ }
+ if (read_bytes < 0)
+ perror(_("Read: "));
+ fprintf(stderr,
+ _("Problem reading track/head %u/%u,"
+  " expected %d, read %d\n"),
+ track, head, track_size, read_bytes);
+ free(data);
+ exit(EXIT_FAILURE);

disk-utils/fdformat.c struct floppy_struct param; · line 123

Quoted 10 lines
disk-utils/fdformat.c +10 -0
+ }
+ for (count = 0; count < track_size; count++)
+ if (data[count] != FD_FILL_BYTE) {
+ if (retries_left) {
+ format_begin(ctrl);
+ format_track_head(ctrl, track, head);
+ format_end(ctrl);
+ seek_track_head (ctrl, track, head);
+ retries_left--;
+ if (retries_left) continue;

Same as previous two comments.

Quoted 37 lines
disk-utils/fdformat.c +16 -6
+ }
+ printf(_("bad data in track/head %u/%u\n"
+ "Continuing ... "), track, head);
+ fflush(stdout);
+ break;
+ }
  break;
- }
+ } while (retries_left);
+ }
  }
+
  free(data);
  printf(_("done\n"));
- if (close(fd) < 0)
- err(EXIT_FAILURE, "close");
 }
 
 static void __attribute__ ((__noreturn__)) usage(FILE * out)
@@ -96,9 +142,13 @@ static void __attribute__ ((__noreturn__)) usage(FILE * out)
  program_invocation_short_name);
 
  fprintf(out, _("\nOptions:\n"
-       " -n, --no-verify  disable the verification after the format\n"
-       " -V, --version    output version information and exit\n"
-       " -h, --help       display this help and exit\n\n"));
+       " -f, --from <N>    start at the track N (default 0)\n"
+       " -t, --to <N>      stop at the track N\n"
+       " -r, --repair <N>  try to repair tracks failed during\n"
+       "                   the verification (max N retries)\n"
+       " -n, --no-verify   disable the verification after the format\n"
+       " -V, --version     output version information and exit\n"
+       " -h, --help        display this help and exit\n\n"));
 
  exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
 }

disk-utils/fdformat.c int main(int argc, char **argv) · line 163

Quoted 6 lines
disk-utils/fdformat.c +3 -0
@@ -108,22 +158,45 @@ int main(int argc, char **argv)
  int ch;
  int ctrl;
  int verify = 1;
+ int repair = 0;
+ int track_from = 0;
+ int track_to = -1;

In floppy_struct track is unsigned int. It would be best to not mix types unnecessarily.

Quoted 15 lines
disk-utils/fdformat.c +5 -0
+ unsigned long arg;
  struct stat st;
 
  static const struct option longopts[] = {
+ {"from", required_argument, NULL, 'f'},
+ {"to", required_argument, NULL, 't'},
+ {"repair", required_argument, NULL, 'r'},
  {"no-verify", no_argument, NULL, 'n'},
  {"version", no_argument, NULL, 'V'},
  {"help", no_argument, NULL, 'h'},
  {NULL, 0, NULL, 0}
  };
 
+
  setlocale(LC_ALL, "");

disk-utils/fdformat.c int main(int argc, char **argv) · line 187

Quoted 10 lines
disk-utils/fdformat.c +4 -1
  bindtextdomain(PACKAGE, LOCALEDIR);
  textdomain(PACKAGE);
  atexit(close_stdout);
 
- while ((ch = getopt_long(argc, argv, "nVh", longopts, NULL)) != -1)
+ while ((ch = getopt_long(argc, argv, "f:t:r:nVh", longopts, NULL)) != -1)
  switch (ch) {
+ case 'f':
+ arg = strtoul_or_err(optarg, _("invalid argument - from"));
+ if (arg > INT_MAX) err(EXIT_FAILURE, _("invalid argument - from"));

Use strtou32_or_err() and remove INT_MAX check.

Quoted 28 lines
disk-utils/fdformat.c +13 -2
+ track_from = arg;
+ break;
+ case 't':
+ arg = strtoul_or_err(optarg, _("invalid argument - to"));
+ if (arg > INT_MAX) err(EXIT_FAILURE, _("invalid argument - to"));
+ track_to = arg;
+ break;
+ case 'r':
+ arg = strtoul_or_err(optarg, _("invalid argument - repair"));
+ if (arg > INT_MAX) err(EXIT_FAILURE, _("invalid argument - repair"));
+ repair = arg;
+ break;
  case 'n':
  verify = 0;
  break;
@@ -149,20 +222,33 @@ int main(int argc, char **argv)
  if (access(argv[0], W_OK) < 0)
  err(EXIT_FAILURE, _("cannot access file %s"), argv[0]);
 
- ctrl = open(argv[0], O_WRONLY);
+ ctrl = open(argv[0], O_RDWR);
  if (ctrl < 0)
  err(EXIT_FAILURE, _("cannot open %s"), argv[0]);
  if (ioctl(ctrl, FDGETPRM, (long)&param) < 0)
  err(EXIT_FAILURE, _("Could not determine current format type"));
 
  printf(_("%s-sided, %d tracks, %d sec/track. Total capacity %d kB.\n"),
-       (param.head == 2) ? _("Double") : _("Single"),

disk-utils/fdformat.c int main(int argc, char **argv) · line 237

Quoted 10 lines
disk-utils/fdformat.c +6 -4
-       param.track, param.sect, param.size >> 1);
- format_disk(ctrl);
- if (close_fd(ctrl) != 0)
- err(EXIT_FAILURE, _("write failed"));
+ (param.head == 2) ? _("Double") : _("Single"),
+ param.track, param.sect, param.size >> 1);
+
+ if (track_to == -1)
+ track_to = param.track - 1;
+

Adding a 'user_defined_tracks' variable seems better approach, than using contents of the variable to figure out whether it was set or not.

disk-utils/fdformat.c int main(int argc, char **argv) · line 243

Quoted 6 lines
disk-utils/fdformat.c +6 -0
+ if ((unsigned int)track_from > param.track - 1)
+ err(EXIT_FAILURE, _("'from' is out of allowed range\n"));
+ if ((unsigned int)track_to > param.track - 1)
+ err(EXIT_FAILURE, _("'to' is out of allowed range\n"));
+ if (track_from > track_to)
+ err(EXIT_FAILURE, _("'from' is higher than 'to'\n"));

The err() adds new line to print out, so the messages above will print unexpected empty line.

<nitpick>
Writing the if cases in smaller greater order makes code quicker to read.

if (smaller_value < greater_value)
err()
</nitpick>

Quoted 12 lines
disk-utils/fdformat.c +7 -1
+
+ format_disk(ctrl, track_from, track_to);
 
  if (verify)
- verify_disk(argv[0]);
+ verify_disk(ctrl, track_from, track_to, repair);
+
+ if (close_fd(ctrl) != 0)
+ err(EXIT_FAILURE, _("close failed"));
+
  return EXIT_SUCCESS;
 }
Signature · 2 lines
Sami Kerola
http://www.iki.fi/kerolasa/
#3 lore raw
Quoted 2 lines

Hi Jaromir,

Hi Sami.

Quoted 5 lines
Quoted 2 lines

It also fixes a recently introduced bug that causes line breakage when printing the track number.

Do you mean commit 18b1fcb9cc62f4dd26eccd1c35f612ac6db1cd9b or some other change?

Yes, exactly this commit.

Quoted 2 lines

It would be nice to know details of what exactly was wrong, and how the fix is fixing it.

Ok ... so:
1.) The following hunk changes %3d to invalid %3ud and that caused an extra character 'd' printed with each track change and as there are only 3 backspaces, the whole string was slowly moving to the right instead of staying at the same place.

- printf("%3d\b\b\b", track);
+ printf("%3ud\b\b\b", track);

Note, that 'u' is NOT a modifier, that needs to be prepended to 'd'. The 'd' specifier needs to be replaced with 'u' instead.

2.) The following hunk changes %3d to invalid %u3d and that caused extra characters '3d' appended to each track number.

- printf("%3d\b\b\b", cyl);
+ printf("%u3d\b\b\b", cyl);

And after crossing the 10th track the final result was '103d' where 3 backspace chars were unable to return to the first characters and that produced something like:

111111111122222222223333333333444444473d

Note that '3' is a width modifier and always needs to be prepended to the 'u' type specifier. So, the position matters:

Quoted 3 lines

The change you sent is rather long, and at
least I cannot see where is the correction. That said splitting the change to smaller chunks would be nice.

It has no sense to split that as I modified the code to support heads and the format string had to be changed to a different one.

Quoted 7 lines
Quoted 7 lines
disk-utils/fdformat.c +7 -0
+static void format_begin(int ctrl)
+{
+ if (ioctl(ctrl, FDFMTBEG, NULL) < 0)
+ err(EXIT_FAILURE, "ioctl: FDFMTBEG");
+}
+
+static void format_end(int ctrl)
Quoted 8 lines

disk-utils/fdformat.c struct floppy_struct param; · line 36

Quoted 5 lines
disk-utils/fdformat.c +5 -0
+{
+ if (ioctl(ctrl, FDFMTEND, NULL) < 0)
+ err(EXIT_FAILURE, "ioctl: FDFMTEND");
+}
+

The format_begin() and format_end() are not doing much, are they really needed?

They increase the code abstraction and readability. There's a condition checking the return state and the code is reused 3 times. Nobody can notice those wasted microseconds when the whole format takes minutes. I really believe it is worthy. We could possibly change them to inline functions, but it is really not necessary in this case.

Quoted 15 lines
Quoted 15 lines

+static void format_track_head(int ctrl, unsigned int track, unsigned int head)
{
struct format_descr descr;
- unsigned int track;

disk-utils/fdformat.c +8 -0
+
+ descr.track = track;
+ descr.head = head;
+ if (ioctl(ctrl, FDFMTTRK, (long) &descr) < 0)
+ err(EXIT_FAILURE, "ioctl: FDFMTTRK");
+}
+
+static void seek_track_head(int ctrl, unsigned int track, unsigned int

head)
+{

Quoted 8 lines

Review

Quoted 4 lines

+ lseek(ctrl, (track * param.head + head) * param.sect * SECTOR_SIZE, SEEK_SET);

(quoted diff) +2 -0
+}
+

Would it be possible to more 'struct floppy_struct param;' out of the global scope? That would make it a bit less mysterious where param.head came from.

At first I tested exactly this variant, then I rewrote it to 2 separate variables as (according to my opinion) the code looked better readable and understandable. But I'm not against changing this as both variants make sense for me.

Quoted 11 lines
Quoted 4 lines

+static void format_disk(int ctrl, unsigned int track_from, unsigned int track_to)
+{
+ unsigned int track, head;

The track & head could be replaced with

struct format_descr descr;

When the two helper variables are gone the format_track_head() turns to a single if (ioctl... statement, and I'd claim it is unnecessary.

... hopefully answered above.

Quoted 11 lines
Quoted 10 lines

+ retries_left = repair;
+ do {
+ read_bytes = read(ctrl, data, track_size);
+ if (read_bytes != track_size) {
+ if (retries_left) {
+ format_begin(ctrl);
+ format_track_head(ctrl, track, head);
+ format_end(ctrl);
+ seek_track_head (ctrl, track, head);
+ retries_left--;

Quoted 3 lines

Will the retries work if IO error happens? There are calls to err() all over, so am I thinking wrong the program will exit rather than re-attempt until retries end.

What IO error do you mean? IO errors are handled by the following condition:

  if (read_bytes != track_size) {

I tested the code with several broken floppies and it does exactly what I wanted to achieve. You probably missed that "continue" call when at least one retry is left. If the track is unreadable, it decreases the retry counter, re-format the track, re-seeks the track for verification and jumps back to the beginning of the track verification loop.

Quoted 4 lines
Quoted 2 lines

+ if (retries_left) continue;

New line & indent step missing.

I usually don't indent if well readable and other lines are longer, but no problem with that. Can be changed.

Quoted 10 lines

disk-utils/fdformat.c int main(int argc, char **argv) · line 163

Quoted 7 lines
disk-utils/fdformat.c +3 -0
@@ -108,22 +158,45 @@ int main(int argc, char **argv)
  int ch;
  int ctrl;
  int verify = 1;
+ int repair = 0;
+ int track_from = 0;
+ int track_to = -1;

In floppy_struct track is unsigned int. It would be best to not mix types unnecessarily.

The negative value is used as a flag here. -1 means it is not set by the user and this way I reused the same variable.
I correctly retype them when needed.

Quoted 1 line

Use strtou32_or_err() and remove INT_MAX check.

Ok, had no idea it exists. Looked at few other tools and copied that. This is a good candidate for a change.

Quoted 6 lines

disk-utils/fdformat.c int main(int argc, char **argv) · line 237

Quoted 3 lines
disk-utils/fdformat.c +3 -0
+ if (track_to == -1)
+ track_to = param.track - 1;
+

Adding a 'user_defined_tracks' variable seems better approach, than using contents of the variable to figure out whether it was set or not.

This is specific to the '-t/--to' switch only. Both switches can be used independently. You can use just one of them or both together. The variable would have to be called 'user_defined_track_to'.

Quoted 9 lines

disk-utils/fdformat.c int main(int argc, char **argv) · line 243

Quoted 6 lines
disk-utils/fdformat.c +6 -0
+ if ((unsigned int)track_from > param.track - 1)
+ err(EXIT_FAILURE, _("'from' is out of allowed range\n"));
+ if ((unsigned int)track_to > param.track - 1)
+ err(EXIT_FAILURE, _("'to' is out of allowed range\n"));
+ if (track_from > track_to)
+ err(EXIT_FAILURE, _("'from' is higher than 'to'\n"));

The err() adds new line to print out, so the messages above will print unexpected empty line.

This can be completely removed after the change to strtou32_or_err(), right?

Please, let me know.

Thanks,
Jaromir.

--
Jaromir Capik
Red Hat Czech, s.r.o.
Software Engineer / Secondary Arch

Email: [email protected]
Web: www.cz.redhat.com
Red Hat Czech s.r.o., Purkynova 99/71, 612 45, Brno, Czech Republic
IC: 27690016

maintainer
#4 lore raw
Quoted 2 lines · Jaromir Capik
Quoted 2 lines

Do you mean commit 18b1fcb9cc62f4dd26eccd1c35f612ac6db1cd9b or some other change?

...

Review

Quoted 2 lines
(quoted diff) +1 -1
-		printf("%3d\b\b\b", track);
+		printf("%3ud\b\b\b", track);

This is obvious...

Quoted 6 lines
Quoted 3 lines

The change you sent is rather long, and at
least I cannot see where is the correction. That said splitting the change to smaller chunks would be nice.

It has no sense to split that as I modified the code to support heads and the format string had to be changed to a different one.

Perfect is the enemy of good. It's no so huge (all the original code has ~160 lines).

Quoted 4 lines
Quoted 2 lines

The format_begin() and format_end() are not doing much, are they really needed?

They increase the code abstraction and readability.

+1

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

+ if (retries_left) continue;

New line & indent step missing.

I usually don't indent if well readable and other lines are longer, but no problem with that. Can be changed.

Please, change it.

Quoted 4 lines
Quoted 1 line

Use strtou32_or_err() and remove INT_MAX check.

Ok, had no idea it exists. Looked at few other tools and copied that. This is a good candidate for a change.

Yep.

Quoted 11 lines
Quoted 9 lines
Quoted 6 lines

+ if ((unsigned int)track_from > param.track - 1)
+ err(EXIT_FAILURE, _("'from' is out of allowed range\n"));
+ if ((unsigned int)track_to > param.track - 1)
+ err(EXIT_FAILURE, _("'to' is out of allowed range\n"));
+ if (track_from > track_to)
+ err(EXIT_FAILURE, _("'from' is higher than 'to'\n"));

The err() adds new line to print out, so the messages above will print unexpected empty line.

This can be completely removed after the change to strtou32_or_err(), right?

I guess you still want to check user's input against the hardware, so check if track_to is smaller than param.track is correct thing. Right?

Anyway, \n is unnecessary, errx() does not print error based on errno, err() follows errno.

Thank, it's nice to see we have someone to test fdformat!

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#5 lore raw

Ahoj Karle.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

+ if ((unsigned int)track_from > param.track - 1)
+ err(EXIT_FAILURE, _("'from' is out of allowed range\n"));
+ if ((unsigned int)track_to > param.track - 1)
+ err(EXIT_FAILURE, _("'to' is out of allowed range\n"));
+ if (track_from > track_to)
+ err(EXIT_FAILURE, _("'from' is higher than 'to'\n"));

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

The err() adds new line to print out, so the messages above will print unexpected empty line.

This can be completely removed after the change to strtou32_or_err(), right?

I guess you still want to check user's input against the hardware, so check if track_to is smaller than param.track is correct thing. Right?

The comparison with the param.track is done elsewhere as we don't know the disk parameters during the argument parsing yet.
We get the parameters after finishing the argument parsing.

Quoted 2 lines

Anyway, \n is unnecessary, errx() does not print error based on errno, err() follows errno.

Sure, this was more of a copy'n'paste error.

Quoted 1 line

Thank, it's nice to see we have someone to test fdformat!

Np. Can test any time.
Going to rework the patch.

Thx,
Jaromir.

--
Jaromir Capik
Red Hat Czech, s.r.o.
Software Engineer / Secondary Arch

Email: [email protected]
Web: www.cz.redhat.com
Red Hat Czech s.r.o., Purkynova 99/71, 612 45, Brno, Czech Republic
IC: 27690016

#6 lore raw
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 9 lines
Quoted 6 lines

+ if ((unsigned int)track_from > param.track - 1)
+ err(EXIT_FAILURE, _("'from' is out of allowed range\n"));
+ if ((unsigned int)track_to > param.track - 1)
+ err(EXIT_FAILURE, _("'to' is out of allowed range\n"));
+ if (track_from > track_to)
+ err(EXIT_FAILURE, _("'from' is higher than 'to'\n"));

The err() adds new line to print out, so the messages above will print unexpected empty line.

This can be completely removed after the change to strtou32_or_err(), right?

Quoted 7 lines
Quoted 3 lines

I guess you still want to check user's input against the hardware, so check
if track_to is smaller than param.track is correct thing. Right?

The comparison with the param.track is done elsewhere as we don't know the disk parameters during the argument parsing yet.
We get the parameters after finishing the argument parsing.

Sorry, I overlooked and thought you're writing about the argument parsing. Of course, this needs to be preserved.

I've reworked the patch, but I'll send it after doing few tests at home.

J.

#7 lore raw
In reply to Karel Zak

Hello guys.

The reworked patch is attached.

Please, review once more.

Thanks,
Jaromir.

--
Jaromir Capik
Red Hat Czech, s.r.o.
Software Engineer / Secondary Arch

Email: [email protected]
Web: www.cz.redhat.com
Red Hat Czech s.r.o., Purkynova 99/71, 612 45, Brno, Czech Republic
IC: 27690016

From 9b9954ec709cdb5ba44b142aa96dac9fdc09cac2 Mon Sep 17 00:00:00 2001
From: Jaromir Capik <[email protected]>
Date: Mon, 28 Jul 2014 20:47:09 +0200
Subject: [PATCH] fdformat: Add new switches -f/--from, -t/--to, -r/--repair

This commit introduces a support for user configurable from/to track and a basic repair mode for broken floppies. It also fixes a recently introduced bug that causes a line breakage when printing the track number.

---
 disk-utils/Makemodule.am |   1 +
 disk-utils/fdformat.8    |  11 ++-
 disk-utils/fdformat.c    | 210 ++++++++++++++++++++++++++++++++---------------
 3 files changed, 157 insertions(+), 65 deletions(-)
disk-utils/Makemodule.am +1 -0
index c6183f5..995e085 100644
@@ -110,6 +110,7 @@ if BUILD_FDFORMAT
 usrsbin_exec_PROGRAMS += fdformat
 dist_man_MANS += disk-utils/fdformat.8
 fdformat_SOURCES = disk-utils/fdformat.c
+fdformat_LDADD = $(LDADD) libcommon.la
 endif
 
 if BUILD_BLOCKDEV
disk-utils/fdformat.8 +10 -1
index df4153f..797f50f 100644
@@ -1,6 +1,6 @@
 .\" Copyright 1992, 1993 Rickard E. Faith ([email protected])
 .\" May be distributed under the GNU General Public License
-.TH FDFORMAT 8 "July 2011" "util-linux" "System Administration"
+.TH FDFORMAT 8 "July 2014" "util-linux" "System Administration"
 .SH NAME
 fdformat \- low-level format a floppy disk
 .SH SYNOPSIS
@@ -45,6 +45,15 @@ autodetected earlier.  In this case, use
 to load the disk parameters.
 .SH OPTIONS
 .TP
+\fB\-f\fR, \fB\-\-from\fR \fIN\fR
+Start at the track \fIN\fR (default is 0).
+.TP
+\fB\-t\fR, \fB\-\-to\fR \fIN\fR
+Stop at the track \fIN\fR (default is 0).
+.TP
+\fB\-r\fR, \fB\-\-repair\fR \fIN\fR
+Try to repair tracks failed during the verification (max \fIN\fR retries).
+.TP
 \fB\-n\fR, \fB\-\-no-verify\fR
 Skip the verification that is normally performed after the formatting.
 .TP
disk-utils/fdformat.c +146 -64

279 lines not on this page · raw message

Signature · 1 line
1.9.3
maintainer Applied
#8 lore raw
Quoted 4 lines · Jaromir Capik
 disk-utils/Makemodule.am |   1 +
 disk-utils/fdformat.8    |  11 ++-
 disk-utils/fdformat.c    | 210 ++++++++++++++++++++++++++++++++---------------
 3 files changed, 157 insertions(+), 65 deletions(-)

Applied, thanks!

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#9 lore raw
In reply to Jaromir Capik

Hello everyone.

I often re-check my patches few weeks after the push and that allowed me to find a copy'n'paste issue in the manual.

The fix is attached.

Thanks for pushing.

Regards,
Jaromir.

--
Jaromir Capik
Red Hat Czech, s.r.o.
Software Engineer / Secondary Arch

Email: [email protected]
Web: www.cz.redhat.com
Red Hat Czech s.r.o., Purkynova 99/71, 612 45, Brno, Czech Republic
IC: 27690016

----- Original Message -----

Quoted 20 lines

From: "Jaromir Capik" <[email protected]>
To: "Karel Zak" <[email protected]>
Cc: [email protected], "util-linux" <[email protected]>
Sent: Tuesday, July 29, 2014 1:32:03 PM
Subject: Re: [PATCH] fdformat: Add new switches -f/--from, -t/--to, -r/--repair

Hello guys.

The reworked patch is attached.

Please, review once more.

Thanks,
Jaromir.

--
Jaromir Capik
Red Hat Czech, s.r.o.
Software Engineer / Secondary Arch

Quoted 5 lines

Email: [email protected]
Web: www.cz.redhat.com
Red Hat Czech s.r.o., Purkynova 99/71, 612 45, Brno, Czech Republic
IC: 27690016

From 540b94d786e2c602b4b99da06cae3c6f81fa1315 Mon Sep 17 00:00:00 2001
From: Jaromir Capik <[email protected]>
Date: Mon, 8 Sep 2014 19:42:10 +0200
Subject: [PATCH] fdformat: fixing copy'n'paste issue in the manual

The end track default is media specific, not zero.

---
 disk-utils/fdformat.8 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
disk-utils/fdformat.8 +1 -1
index 797f50f..ae1e530 100644
@@ -49,7 +49,7 @@ to load the disk parameters.
 Start at the track \fIN\fR (default is 0).
 .TP
 \fB\-t\fR, \fB\-\-to\fR \fIN\fR
-Stop at the track \fIN\fR (default is 0).
+Stop at the track \fIN\fR.
 .TP
 \fB\-r\fR, \fB\-\-repair\fR \fIN\fR
 Try to repair tracks failed during the verification (max \fIN\fR retries).
Signature · 1 line
1.9.3
maintainer Applied
#10 lore raw
Quoted 1 line · Jaromir Capik

The fix is attached.

Applied, thanks.

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com