Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:lafenghu
ziptool
ziptool-1.4.0.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File ziptool-1.4.0.patch of Package ziptool
--- ziptool.c 2002-08-28 05:07:36.000000000 +0200 +++ ziptool.c.new 2003-07-24 16:39:35.000000000 +0200 @@ -44,19 +44,51 @@ #include <sys/ioctl.h> -#include <linux/fs.h> #include <linux/major.h> #include <scsi/scsi.h> #include <scsi/scsi_ioctl.h> +#include <sys/types.h> +#include <sys/wait.h> #ifndef PROG_VERSION # define PROG_VERSION "1.4.0" #endif +#ifndef SCSI_REMOVAL_PREVENT +#define SCSI_REMOVAL_PREVENT 1 +#endif +#ifndef SCSI_REMOVAL_ALLOW +#define SCSI_REMOVAL_ALLOW 0 +#endif + +#ifndef MAJOR +#define MAJOR(dev) ((dev)>>8) +#endif +#ifndef MINOR +#define MINOR(dev) ((dev) & 0xff) +#endif #ifndef MNTTYPE_AUTO -# define MNTTYPE_AUTO "auto" +#define MNTTYPE_AUTO "auto" +#endif +#ifndef MNTTYPE_PROC +#define MNTTYPE_PROC "proc" +#endif +#ifndef MNTTYPE_PTS +#define MNTTYPE_PTS "devpts" +#endif +#ifndef MNTTYPE_AUTOFS +#define MNTTYPE_AUTOFS "autofs" +#endif +#ifndef MNTTYPE_SHM +#define MNTTYPE_SHM "shm" +#endif +#ifndef MNTTYPE_USBDEVFS +#define MNTTYPE_USBDEVFS "usbdevfs" +#endif +#ifndef MNTTYPE_NONE +#define MNTTYPE_NONE "none" #endif /* Patched kernels will have IOMEGA_*_PROT_MODE defined. */ @@ -90,13 +122,14 @@ * insensitive. */ static char *jaz_models[] = { - "iomega jaz 1gb", - "iomega jaz 2gb", /* ams */ + "iomega JAZ 1GB", + "iomega JAZ 2GB", /* correct values */ NULL }; static char *zip_models[] = { "Iomega ZIP 100", + "Iomega ZIP 250", NULL }; @@ -161,9 +194,7 @@ ) { int result; - char cmd[255]; - - *cmd = '\0'; + char *a[3]; /* Generate command for mounting or unmounting. */ switch(oper) @@ -180,9 +211,11 @@ strncat(cmd, " ", 1); strncat(cmd, mnt, strlen(mnt) + 1); */ - strncpy(cmd, MOUNT_CMD, strlen(MOUNT_CMD) + 1); - strncat(cmd, " ", 1); - strncat(cmd, mnt, strlen(mnt) + 1); + a[0] = MOUNT_CMD; + a[1] = mnt; + a[2] = NULL; + if( !fork() ) + execve(*a, a, NULL); break; case UMOUNT_DISK: @@ -193,19 +226,26 @@ strncat(cmd, dev, strlen(dev)); */ /* Note that mnt may be NULL in this case. */ - strncpy(cmd, UMOUNT_CMD, strlen(UMOUNT_CMD) + 1); - strncat(cmd, " ", 1); - strncat(cmd, dev, strlen(dev)); + a[0] = MOUNT_CMD; + a[1] = dev; + a[2] = NULL; + if( !fork() ) + execve(*a, a, NULL); break; } /* Execute mount or unmount command. */ - result = system(cmd); - if(result == 0) + wait(&result); + + if( WIFEXITED(result) ) { - if(oper == MOUNT_DISK) + if( !(result = WEXITSTATUS(result)) && oper == MOUNT_DISK ) jazip_ctrldoor(jazipfd, SCSI_REMOVAL_PREVENT); } + else + { + result = -1; + } return(result); } @@ -221,31 +261,90 @@ */ static int jazip_check_dev(char *dev) { - FILE *mtab_fp; - char mounts[255]; + FILE *mtab; char **model; char scsi_signature[25]; int i, jazipfd; + struct stat st_dev, st_mnt; + struct mntent *mnt; - /* Check to see if the device is mounted by reading - * /etc/mtab - */ - if(!(mtab_fp = fopen("/etc/mtab", "r"))) - { - perror("Opening /etc/mtab"); - exit(1); - } - while(!feof(mtab_fp)) - { - fgets(mounts, 254, mtab_fp); - if(strstr(mounts, dev)) - { - mounted = 1; - } - } - fclose(mtab_fp); +/* + * Get file info and check, if we have a raw SCSI disk. Conditions: + * -> Blockdevice + * -> Major is SCSI_DISK_MAJOR + * -> Minor is a multiple of 16 (or 0) + */ + if (stat (dev, &st_dev)) { + (void) fprintf (stderr, "%s: stat(%s) failed: %s.\n", + progname, dev, strerror (errno)); + return (-1); + } + + if (!S_ISBLK (st_dev.st_mode) +#if defined SCSI_DISK0_MAJOR + || MAJOR (st_dev.st_rdev) != SCSI_DISK0_MAJOR +#else + || MAJOR (st_dev.st_rdev) != SCSI_DISK_MAJOR +#endif + || MINOR (st_dev.st_rdev) % 16 != 0) { + (void) fprintf (stderr, "%s: %s (%02d/%02d) is no raw scsi device.\n", + progname, dev, (int) MAJOR (st_dev.st_rdev), (int) MINOR (st_dev.st_rdev)); + return (-1); + } + + + +/* + * Now check if any partition of this device is already mounted (this + * includes checking if the device is mounted under a different name). + */ + if ((mtab = setmntent (MOUNTED, "r")) == NULL) { + (void) fprintf (stderr, "%s: can't open %s.\n", + progname, MOUNTED); + return (-1); + } + + while (mnt = getmntent (mtab)) { + if (!strcmp (mnt->mnt_type, MNTTYPE_NFS) + || !strcmp (mnt->mnt_type, MNTTYPE_PROC) + || !strcmp (mnt->mnt_type, MNTTYPE_AUTO) + || !strcmp (mnt->mnt_type, MNTTYPE_PTS) + || !strcmp (mnt->mnt_type, MNTTYPE_AUTOFS) + || !strcmp (mnt->mnt_type, MNTTYPE_SHM) + || !strcmp (mnt->mnt_type, MNTTYPE_USBDEVFS) + || !strcmp (mnt->mnt_type, MNTTYPE_NONE) + || !strcmp (mnt->mnt_type, MNTTYPE_IGNORE)) + continue; + + if (stat (mnt->mnt_fsname, &st_mnt)) { + (void) fprintf (stderr, "%s: stat(%s) failed: %s.\n", + progname, mnt->mnt_fsname, strerror (errno)); + (void) endmntent (mtab); + return (-1); + } + + + if (S_ISBLK (st_mnt.st_mode)) { +#if defined SCSI_DISK0_MAJOR + if (MAJOR (st_mnt.st_rdev) == SCSI_DISK0_MAJOR +#else + if (MAJOR (st_mnt.st_rdev) == SCSI_DISK_MAJOR +#endif + && MINOR (st_mnt.st_rdev) >= MINOR (st_dev.st_rdev) + && MINOR (st_mnt.st_rdev) <= MINOR (st_dev.st_rdev) + 15) { + (void) fprintf (stderr, "%s: %s%d (%02d/%02d) is " + "mounted on %s.\n", progname, dev, + (int) (MINOR (st_mnt.st_rdev) - MINOR (st_dev.st_rdev)), + (int) MAJOR (st_dev.st_rdev), (int) MINOR (st_dev.st_rdev), + mnt->mnt_dir); + (void) endmntent (mtab); + return (-1); + } + } + } + (void) endmntent (mtab); /* Now open the device and read its model signature. Check if * it is the one that we expect. @@ -881,7 +980,15 @@ /* Got atleast 2 arguments? */ if(argc >= 3) { - if((jazipfd = jazip_check_dev(argv[2])) >= 0) + if(!strcmp(argv[1], "-u")) + { + result = jazip_ctrlmount( + 0, UMOUNT_DISK, + argv[2], + (argc >= 4) ? argv[3] : NULL + ); + } + else if((jazipfd = jazip_check_dev(argv[2])) >= 0) { if(!strcmp(argv[1], "-e")) { @@ -947,14 +1054,6 @@ argv[2], argv[3] ); } - else if((!strcmp(argv[1], "-u")) && (argc >= 3)) - { - result = jazip_ctrlmount( - jazipfd, UMOUNT_DISK, - argv[2], - (argc >= 4) ? argv[3] : NULL - ); - } else { jazip_usage (progname);
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor