just include fcntl.h not sys/fcntl.h
[oweals/busybox.git] / util-linux / fdformat.c
index 930525848b1e72257d14cb4ce065025111b8b3ca..5772e13090fcd1a5aec1fa25180de86a7012caef 100644 (file)
@@ -85,7 +85,7 @@ int fdformat_main(int argc,char **argv)
 
        /* R_OK is needed for verifying */
        if (stat(*argv,&st) < 0 || access(*argv,W_OK | R_OK ) < 0) {
-               bb_perror_msg_and_die(*argv);
+               bb_perror_msg_and_die("%s",*argv);
        }
        if (!S_ISBLK(st.st_mode)) {
                bb_error_msg_and_die("%s: not a block device",*argv);
@@ -107,12 +107,18 @@ int fdformat_main(int argc,char **argv)
        bb_xioctl(fd, FDFMTBEG,NULL,"FDFMTBEG");
 
        /* n == track */
-       for (n = 0; n < param.track; n++) {
-               descr.track = n;
-               for(descr.head=0, print_and_flush("%3d\b\b\b", n) ; descr.head < param.head; descr.head++){
-                       bb_xioctl(fd,FDFMTTRK, &descr,"FDFMTTRK");
-               }
+       for (n = 0; n < param.track; n++)
+       {
+           descr.head = 0;
+           descr.track = n;
+           bb_xioctl(fd, FDFMTTRK,&descr,"FDFMTTRK");
+           print_and_flush("%3d\b\b\b", n);
+           if (param.head == 2) {
+               descr.head = 1;
+               bb_xioctl(fd, FDFMTTRK,&descr,"FDFMTTRK");
+           }
        }
+
        bb_xioctl(fd,FDFMTEND,NULL,"FDFMTEND");
        print_and_flush("done\n", NULL);
 
@@ -128,7 +134,7 @@ int fdformat_main(int argc,char **argv)
                        if((read_bytes = safe_read(fd,data,n))!= n ) {
                                if(read_bytes < 0) {
                                        bb_perror_msg("Read: ");
-                       }
+                               }
                                bb_error_msg_and_die("Problem reading cylinder %d, expected %d, read %d", cyl, n, read_bytes);
                        }
                        /* Check backwards so we don't need a counter */
@@ -141,14 +147,14 @@ int fdformat_main(int argc,char **argv)
                /* There is no point in freeing blocks at the end of a program, because
                all of the program's space is given back to the system when the process
                terminates.*/
-#ifdef CONFIG_FEATURE_CLEAN_UP
-               free(data);
-#endif
+
+               if (ENABLE_FEATURE_CLEAN_UP) free(data);
+
                print_and_flush("done\n", NULL);
        }
-#ifdef CONFIG_FEATURE_CLEAN_UP
-       close(fd);
-#endif
+
+       if (ENABLE_FEATURE_CLEAN_UP) close(fd);
+
        /* Don't bother closing.  Exit does
         * that, so we can save a few bytes */
        return EXIT_SUCCESS;