1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
/*
* misc.c - miscellaneous functions for the Linux file system degragmenter.
* $Id: misc.c,v 1.4 1997/08/17 14:02:33 linux Exp $
*
* Copyright (C) 1992, 1993 Stephen Tweedie (sct@dcs.ed.ac.uk)
*
* This file may be redistributed under the terms of the GNU General
* Public License.
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <mntent.h>
#include <errno.h>
#define MISC_C
#include "defrag.h"
void fatal_error (const char * fmt_string)
{
if (voyer_mode) {
stat_line("");
done_screen(FALSE); /* Maybe screen is not initalised yet, */
/* done_screen will check it itself */
}
fflush (stdout);
fprintf (stderr, fmt_string, program_name, device_name);
exit (1);
}
void usage()
{
fflush (stdout);
fprintf (stderr,
"Usage: %s [-V"
#ifndef NODEBUG
"d"
#endif
"rsv] [-i inode-list] [-b bad-inode] [-p pool-size] "
"/dev/name\n",
program_name);
fprintf (stderr, " -V : print full version information\n");
#ifndef NODEBUG
fprintf (stderr, " -d : debugging mode\n");
#endif
fprintf (stderr, " -r : read_only (testing) mode (implies -s)\n");
fprintf (stderr, " -s : show summary information\n");
fprintf (stderr, " -v : verbose (-vv is even more so)\n");
fprintf (stderr, " -n : runs without a picture\n");
exit (1);
}
void check_mount(char *device_name)
{
FILE * f;
struct mntent * mnt;
if ((f = setmntent (MOUNTED, "r")) == NULL)
return;
while ((mnt = getmntent (f)) != NULL)
if (strcmp (device_name, mnt->mnt_fsname) == 0)
break;
endmntent (f);
if (!mnt)
return;
fprintf (stderr,"Cannot work on a mounted device: %s\n", device_name);
exit (2);
}
loff_t nlseek (int fd, loff_t offset, int whence) {
loff_t r;
while ((r=defrag_llseek(fd,offset,whence))==((loff_t) -1) && errno == EINTR)
;
return r;
}
ssize_t nread (int fd, __ptr_t buf, size_t nbytes) {
ssize_t r;
while ((r=read(fd,buf,nbytes))==-1 && errno == EINTR)
;
return r;
}
ssize_t nwrite (int fd, __ptr_t buf, size_t nbytes) {
ssize_t r;
while ((r=write(fd,buf,nbytes))==-1 && errno == EINTR)
;
return r;
}
|