lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <202108181308.GTC6oVAB-lkp@intel.com>
Date:   Wed, 18 Aug 2021 13:34:31 +0800
From:   kernel test robot <lkp@...el.com>
To:     "Gustavo A. R. Silva" <gustavoars@...nel.org>
Cc:     clang-built-linux@...glegroups.com, kbuild-all@...ts.01.org,
        "Gustavo A. R. Silva" <gustavo@...eddedor.com>,
        LKML <linux-kernel@...r.kernel.org>,
        Kees Cook <keescook@...omium.org>
Subject: [gustavoars-linux:for-next/clang-fallthrough 1/1]
 drivers/scsi/st.c:3831:2: warning: unannotated fall-through between switch
 labels

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux.git for-next/clang-fallthrough
head:   3b37740f7d04ef32cc1a7bb17c2bc69d737c9056
commit: 3b37740f7d04ef32cc1a7bb17c2bc69d737c9056 [1/1] Makefile: Enable -Wimplicit-fallthrough for Clang
config: x86_64-randconfig-a016-20210816 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project af7818093677dcb4c0840aef96bc029deb219e57)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux.git/commit/?id=3b37740f7d04ef32cc1a7bb17c2bc69d737c9056
        git remote add gustavoars-linux https://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux.git
        git fetch --no-tags gustavoars-linux for-next/clang-fallthrough
        git checkout 3b37740f7d04ef32cc1a7bb17c2bc69d737c9056
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@...el.com>

All warnings (new ones prefixed by >>):

>> drivers/scsi/st.c:3831:2: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough]
           default:
           ^
   drivers/scsi/st.c:3831:2: note: insert 'break;' to avoid fall-through
           default:
           ^
           break; 
   1 warning generated.


vim +3831 drivers/scsi/st.c

8038e6456a3e6f Kai Makisara      2016-02-09  3353  
8038e6456a3e6f Kai Makisara      2016-02-09  3354  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3355  /* Partition the tape into two partitions if size > 0 or one partition if
^1da177e4c3f41 Linus Torvalds    2005-04-16  3356     size == 0.
^1da177e4c3f41 Linus Torvalds    2005-04-16  3357  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3358     The block descriptors are read and written because Sony SDT-7000 does not
^1da177e4c3f41 Linus Torvalds    2005-04-16  3359     work without this (suggestion from Michael Schaefer <Michael.Schaefer@....de>).
^1da177e4c3f41 Linus Torvalds    2005-04-16  3360  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3361     My HP C1533A drive returns only one partition size field. This is used to
^1da177e4c3f41 Linus Torvalds    2005-04-16  3362     set the size of partition 1. There is no size field for the default partition.
^1da177e4c3f41 Linus Torvalds    2005-04-16  3363     Michael Schaefer's Sony SDT-7000 returns two descriptors and the second is
^1da177e4c3f41 Linus Torvalds    2005-04-16  3364     used to set the size of partition 1 (this is what the SCSI-3 standard specifies).
^1da177e4c3f41 Linus Torvalds    2005-04-16  3365     The following algorithm is used to accommodate both drives: if the number of
^1da177e4c3f41 Linus Torvalds    2005-04-16  3366     partition size fields is greater than the maximum number of additional partitions
^1da177e4c3f41 Linus Torvalds    2005-04-16  3367     in the mode page, the second field is used. Otherwise the first field is used.
^1da177e4c3f41 Linus Torvalds    2005-04-16  3368  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3369     For Seagate DDS drives the page length must be 8 when no partitions is defined
^1da177e4c3f41 Linus Torvalds    2005-04-16  3370     and 10 when 1 partition is defined (information from Eric Lee Green). This is
^1da177e4c3f41 Linus Torvalds    2005-04-16  3371     is acceptable also to some other old drives and enforced if the first partition
^1da177e4c3f41 Linus Torvalds    2005-04-16  3372     size field is used for the first additional partition size.
8038e6456a3e6f Kai Makisara      2016-02-09  3373  
8038e6456a3e6f Kai Makisara      2016-02-09  3374     For drives that advertize SCSI-3 or newer, use the SSC-3 methods.
^1da177e4c3f41 Linus Torvalds    2005-04-16  3375   */
^1da177e4c3f41 Linus Torvalds    2005-04-16  3376  static int partition_tape(struct scsi_tape *STp, int size)
^1da177e4c3f41 Linus Torvalds    2005-04-16  3377  {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3378  	int result;
8038e6456a3e6f Kai Makisara      2016-02-09  3379  	int target_partition;
8038e6456a3e6f Kai Makisara      2016-02-09  3380  	bool scsi3 = STp->device->scsi_level >= SCSI_3, needs_format = false;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3381  	int pgo, psd_cnt, psdo;
8038e6456a3e6f Kai Makisara      2016-02-09  3382  	int psum = PP_MSK_PSUM_MB, units = 0;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3383  	unsigned char *bp;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3384  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3385  	result = read_mode_page(STp, PART_PAGE, 0);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3386  	if (result) {
b30d8bca5b525b Hannes Reinecke   2014-06-25  3387  		DEBC_printk(STp, "Can't read partition mode page.\n");
^1da177e4c3f41 Linus Torvalds    2005-04-16  3388  		return result;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3389  	}
8038e6456a3e6f Kai Makisara      2016-02-09  3390  	target_partition = 1;
8038e6456a3e6f Kai Makisara      2016-02-09  3391  	if (size < 0) {
8038e6456a3e6f Kai Makisara      2016-02-09  3392  		target_partition = 0;
8038e6456a3e6f Kai Makisara      2016-02-09  3393  		size = -size;
8038e6456a3e6f Kai Makisara      2016-02-09  3394  	}
8038e6456a3e6f Kai Makisara      2016-02-09  3395  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3396  	/* The mode page is in the buffer. Let's modify it and write it. */
^1da177e4c3f41 Linus Torvalds    2005-04-16  3397  	bp = (STp->buffer)->b_data;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3398  	pgo = MODE_HEADER_LENGTH + bp[MH_OFF_BDESCS_LENGTH];
b30d8bca5b525b Hannes Reinecke   2014-06-25  3399  	DEBC_printk(STp, "Partition page length is %d bytes.\n",
b30d8bca5b525b Hannes Reinecke   2014-06-25  3400  		    bp[pgo + MP_OFF_PAGE_LENGTH] + 2);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3401  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3402  	psd_cnt = (bp[pgo + MP_OFF_PAGE_LENGTH] + 2 - PART_PAGE_FIXED_LENGTH) / 2;
8038e6456a3e6f Kai Makisara      2016-02-09  3403  
8038e6456a3e6f Kai Makisara      2016-02-09  3404  	if (scsi3) {
8038e6456a3e6f Kai Makisara      2016-02-09  3405  		needs_format = (bp[pgo + PP_OFF_FLAGS] & PP_MSK_POFM) != 0;
8038e6456a3e6f Kai Makisara      2016-02-09  3406  		if (needs_format && size == 0) {
8038e6456a3e6f Kai Makisara      2016-02-09  3407  			/* No need to write the mode page when clearing
8038e6456a3e6f Kai Makisara      2016-02-09  3408  			 *  partitioning
8038e6456a3e6f Kai Makisara      2016-02-09  3409  			 */
8038e6456a3e6f Kai Makisara      2016-02-09  3410  			DEBC_printk(STp, "Formatting tape with one partition.\n");
8038e6456a3e6f Kai Makisara      2016-02-09  3411  			result = format_medium(STp, 0);
8038e6456a3e6f Kai Makisara      2016-02-09  3412  			goto out;
8038e6456a3e6f Kai Makisara      2016-02-09  3413  		}
8038e6456a3e6f Kai Makisara      2016-02-09  3414  		if (needs_format)  /* Leave the old value for HP DATs claiming SCSI_3 */
8038e6456a3e6f Kai Makisara      2016-02-09  3415  			psd_cnt = 2;
8038e6456a3e6f Kai Makisara      2016-02-09  3416  		if ((bp[pgo + PP_OFF_FLAGS] & PP_MSK_PSUM_UNITS) == PP_MSK_PSUM_UNITS) {
8038e6456a3e6f Kai Makisara      2016-02-09  3417  			/* Use units scaling for large partitions if the device
8038e6456a3e6f Kai Makisara      2016-02-09  3418  			 * suggests it and no precision lost. Required for IBM
8038e6456a3e6f Kai Makisara      2016-02-09  3419  			 * TS1140/50 drives that don't support MB units.
8038e6456a3e6f Kai Makisara      2016-02-09  3420  			 */
8038e6456a3e6f Kai Makisara      2016-02-09  3421  			if (size >= 1000 && (size % 1000) == 0) {
8038e6456a3e6f Kai Makisara      2016-02-09  3422  				size /= 1000;
8038e6456a3e6f Kai Makisara      2016-02-09  3423  				psum = PP_MSK_PSUM_UNITS;
8038e6456a3e6f Kai Makisara      2016-02-09  3424  				units = 9; /* GB */
8038e6456a3e6f Kai Makisara      2016-02-09  3425  			}
8038e6456a3e6f Kai Makisara      2016-02-09  3426  		}
8038e6456a3e6f Kai Makisara      2016-02-09  3427  		/* Try it anyway if too large to specify in MB */
8038e6456a3e6f Kai Makisara      2016-02-09  3428  		if (psum == PP_MSK_PSUM_MB && size >= 65534) {
8038e6456a3e6f Kai Makisara      2016-02-09  3429  			size /= 1000;
8038e6456a3e6f Kai Makisara      2016-02-09  3430  			psum = PP_MSK_PSUM_UNITS;
8038e6456a3e6f Kai Makisara      2016-02-09  3431  			units = 9;  /* GB */
8038e6456a3e6f Kai Makisara      2016-02-09  3432  		}
8038e6456a3e6f Kai Makisara      2016-02-09  3433  	}
8038e6456a3e6f Kai Makisara      2016-02-09  3434  
8038e6456a3e6f Kai Makisara      2016-02-09  3435  	if (size >= 65535 ||  /* Does not fit into two bytes */
8038e6456a3e6f Kai Makisara      2016-02-09  3436  	    (target_partition == 0 && psd_cnt < 2)) {
8038e6456a3e6f Kai Makisara      2016-02-09  3437  		result = -EINVAL;
8038e6456a3e6f Kai Makisara      2016-02-09  3438  		goto out;
8038e6456a3e6f Kai Makisara      2016-02-09  3439  	}
8038e6456a3e6f Kai Makisara      2016-02-09  3440  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3441  	psdo = pgo + PART_PAGE_FIXED_LENGTH;
8038e6456a3e6f Kai Makisara      2016-02-09  3442  	/* The second condition is for HP DDS which use only one partition size
8038e6456a3e6f Kai Makisara      2016-02-09  3443  	 * descriptor
8038e6456a3e6f Kai Makisara      2016-02-09  3444  	 */
8038e6456a3e6f Kai Makisara      2016-02-09  3445  	if (target_partition > 0 &&
8038e6456a3e6f Kai Makisara      2016-02-09  3446  	    (psd_cnt > bp[pgo + PP_OFF_MAX_ADD_PARTS] ||
8038e6456a3e6f Kai Makisara      2016-02-09  3447  	     bp[pgo + PP_OFF_MAX_ADD_PARTS] != 1)) {
8038e6456a3e6f Kai Makisara      2016-02-09  3448  		bp[psdo] = bp[psdo + 1] = 0xff;  /* Rest to partition 0 */
^1da177e4c3f41 Linus Torvalds    2005-04-16  3449  		psdo += 2;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3450  	}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3451  	memset(bp + psdo, 0, bp[pgo + PP_OFF_NBR_ADD_PARTS] * 2);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3452  
b30d8bca5b525b Hannes Reinecke   2014-06-25  3453  	DEBC_printk(STp, "psd_cnt %d, max.parts %d, nbr_parts %d\n",
^1da177e4c3f41 Linus Torvalds    2005-04-16  3454  		    psd_cnt, bp[pgo + PP_OFF_MAX_ADD_PARTS],
b30d8bca5b525b Hannes Reinecke   2014-06-25  3455  		    bp[pgo + PP_OFF_NBR_ADD_PARTS]);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3456  
8038e6456a3e6f Kai Makisara      2016-02-09  3457  	if (size == 0) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3458  		bp[pgo + PP_OFF_NBR_ADD_PARTS] = 0;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3459  		if (psd_cnt <= bp[pgo + PP_OFF_MAX_ADD_PARTS])
^1da177e4c3f41 Linus Torvalds    2005-04-16  3460  		    bp[pgo + MP_OFF_PAGE_LENGTH] = 6;
b30d8bca5b525b Hannes Reinecke   2014-06-25  3461  		DEBC_printk(STp, "Formatting tape with one partition.\n");
^1da177e4c3f41 Linus Torvalds    2005-04-16  3462  	} else {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3463  		bp[psdo] = (size >> 8) & 0xff;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3464  		bp[psdo + 1] = size & 0xff;
8038e6456a3e6f Kai Makisara      2016-02-09  3465  		if (target_partition == 0)
8038e6456a3e6f Kai Makisara      2016-02-09  3466  			bp[psdo + 2] = bp[psdo + 3] = 0xff;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3467  		bp[pgo + 3] = 1;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3468  		if (bp[pgo + MP_OFF_PAGE_LENGTH] < 8)
^1da177e4c3f41 Linus Torvalds    2005-04-16  3469  		    bp[pgo + MP_OFF_PAGE_LENGTH] = 8;
8038e6456a3e6f Kai Makisara      2016-02-09  3470  		DEBC_printk(STp,
8038e6456a3e6f Kai Makisara      2016-02-09  3471  			    "Formatting tape with two partitions (%i = %d MB).\n",
8038e6456a3e6f Kai Makisara      2016-02-09  3472  			    target_partition, units > 0 ? size * 1000 : size);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3473  	}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3474  	bp[pgo + PP_OFF_PART_UNITS] = 0;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3475  	bp[pgo + PP_OFF_RESERVED] = 0;
8038e6456a3e6f Kai Makisara      2016-02-09  3476  	if (size != 1 || units != 0) {
8038e6456a3e6f Kai Makisara      2016-02-09  3477  		bp[pgo + PP_OFF_FLAGS] = PP_BIT_IDP | psum |
8038e6456a3e6f Kai Makisara      2016-02-09  3478  			(bp[pgo + PP_OFF_FLAGS] & 0x07);
8038e6456a3e6f Kai Makisara      2016-02-09  3479  		bp[pgo + PP_OFF_PART_UNITS] = units;
8038e6456a3e6f Kai Makisara      2016-02-09  3480  	} else
8038e6456a3e6f Kai Makisara      2016-02-09  3481  		bp[pgo + PP_OFF_FLAGS] = PP_BIT_FDP |
8038e6456a3e6f Kai Makisara      2016-02-09  3482  			(bp[pgo + PP_OFF_FLAGS] & 0x1f);
8038e6456a3e6f Kai Makisara      2016-02-09  3483  	bp[pgo + MP_OFF_PAGE_LENGTH] = 6 + psd_cnt * 2;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3484  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3485  	result = write_mode_page(STp, PART_PAGE, 1);
8038e6456a3e6f Kai Makisara      2016-02-09  3486  
8038e6456a3e6f Kai Makisara      2016-02-09  3487  	if (!result && needs_format)
8038e6456a3e6f Kai Makisara      2016-02-09  3488  		result = format_medium(STp, 1);
8038e6456a3e6f Kai Makisara      2016-02-09  3489  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3490  	if (result) {
b30d8bca5b525b Hannes Reinecke   2014-06-25  3491  		st_printk(KERN_INFO, STp, "Partitioning of tape failed.\n");
^1da177e4c3f41 Linus Torvalds    2005-04-16  3492  		result = (-EIO);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3493  	}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3494  
8038e6456a3e6f Kai Makisara      2016-02-09  3495  out:
^1da177e4c3f41 Linus Torvalds    2005-04-16  3496  	return result;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3497  }
^1da177e4c3f41 Linus Torvalds    2005-04-16  3498  .
^1da177e4c3f41 Linus Torvalds    2005-04-16  3499  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3500  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3501  /* The ioctl command */
dba7688fc9037c Christoph Hellwig 2021-07-24  3502  static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg)
^1da177e4c3f41 Linus Torvalds    2005-04-16  3503  {
dba7688fc9037c Christoph Hellwig 2021-07-24  3504  	void __user *p = (void __user *)arg;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3505  	int i, cmd_nr, cmd_type, bt;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3506  	int retval = 0;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3507  	unsigned int blk;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3508  	struct scsi_tape *STp = file->private_data;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3509  	struct st_modedef *STm;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3510  	struct st_partstat *STps;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3511  
28f85009e0cf6a Matthias Kaehlcke 2007-07-29  3512  	if (mutex_lock_interruptible(&STp->lock))
^1da177e4c3f41 Linus Torvalds    2005-04-16  3513  		return -ERESTARTSYS;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3514  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3515  	DEB(
^1da177e4c3f41 Linus Torvalds    2005-04-16  3516  	if (debugging && !STp->in_use) {
b30d8bca5b525b Hannes Reinecke   2014-06-25  3517  		st_printk(ST_DEB_MSG, STp, "Incorrect device.\n");
^1da177e4c3f41 Linus Torvalds    2005-04-16  3518  		retval = (-EIO);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3519  		goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3520  	} ) /* end DEB */
^1da177e4c3f41 Linus Torvalds    2005-04-16  3521  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3522  	STm = &(STp->modes[STp->current_mode]);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3523  	STps = &(STp->ps[STp->partition]);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3524  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3525  	/*
^1da177e4c3f41 Linus Torvalds    2005-04-16  3526  	 * If we are in the middle of error recovery, don't let anyone
^1da177e4c3f41 Linus Torvalds    2005-04-16  3527  	 * else try and use this device.  Also, if error recovery fails, it
^1da177e4c3f41 Linus Torvalds    2005-04-16  3528  	 * may try and take the device offline, in which case all further
^1da177e4c3f41 Linus Torvalds    2005-04-16  3529  	 * access to the device is prohibited.
^1da177e4c3f41 Linus Torvalds    2005-04-16  3530  	 */
906d15fbd23c12 Christoph Hellwig 2014-10-11  3531  	retval = scsi_ioctl_block_when_processing_errors(STp->device, cmd_in,
83ff6fe8580a7c Al Viro           2008-03-02  3532  			file->f_flags & O_NDELAY);
906d15fbd23c12 Christoph Hellwig 2014-10-11  3533  	if (retval)
^1da177e4c3f41 Linus Torvalds    2005-04-16  3534  		goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3535  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3536  	cmd_type = _IOC_TYPE(cmd_in);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3537  	cmd_nr = _IOC_NR(cmd_in);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3538  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3539  	if (cmd_type == _IOC_TYPE(MTIOCTOP) && cmd_nr == _IOC_NR(MTIOCTOP)) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3540  		struct mtop mtc;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3541  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3542  		if (_IOC_SIZE(cmd_in) != sizeof(mtc)) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3543  			retval = (-EINVAL);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3544  			goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3545  		}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3546  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3547  		i = copy_from_user(&mtc, p, sizeof(struct mtop));
^1da177e4c3f41 Linus Torvalds    2005-04-16  3548  		if (i) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3549  			retval = (-EFAULT);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3550  			goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3551  		}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3552  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3553  		if (mtc.mt_op == MTSETDRVBUFFER && !capable(CAP_SYS_ADMIN)) {
b30d8bca5b525b Hannes Reinecke   2014-06-25  3554  			st_printk(KERN_WARNING, STp,
b30d8bca5b525b Hannes Reinecke   2014-06-25  3555  				  "MTSETDRVBUFFER only allowed for root.\n");
^1da177e4c3f41 Linus Torvalds    2005-04-16  3556  			retval = (-EPERM);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3557  			goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3558  		}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3559  		if (!STm->defined &&
^1da177e4c3f41 Linus Torvalds    2005-04-16  3560  		    (mtc.mt_op != MTSETDRVBUFFER &&
^1da177e4c3f41 Linus Torvalds    2005-04-16  3561  		     (mtc.mt_count & MT_ST_OPTIONS) == 0)) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3562  			retval = (-ENXIO);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3563  			goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3564  		}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3565  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3566  		if (!STp->pos_unknown) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3567  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3568  			if (STps->eof == ST_FM_HIT) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3569  				if (mtc.mt_op == MTFSF || mtc.mt_op == MTFSFM ||
^1da177e4c3f41 Linus Torvalds    2005-04-16  3570                                      mtc.mt_op == MTEOM) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3571  					mtc.mt_count -= 1;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3572  					if (STps->drv_file >= 0)
^1da177e4c3f41 Linus Torvalds    2005-04-16  3573  						STps->drv_file += 1;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3574  				} else if (mtc.mt_op == MTBSF || mtc.mt_op == MTBSFM) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3575  					mtc.mt_count += 1;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3576  					if (STps->drv_file >= 0)
^1da177e4c3f41 Linus Torvalds    2005-04-16  3577  						STps->drv_file += 1;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3578  				}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3579  			}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3580  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3581  			if (mtc.mt_op == MTSEEK) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3582  				/* Old position must be restored if partition will be
^1da177e4c3f41 Linus Torvalds    2005-04-16  3583                                     changed */
^1da177e4c3f41 Linus Torvalds    2005-04-16  3584  				i = !STp->can_partitions ||
^1da177e4c3f41 Linus Torvalds    2005-04-16  3585  				    (STp->new_partition != STp->partition);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3586  			} else {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3587  				i = mtc.mt_op == MTREW || mtc.mt_op == MTOFFL ||
^1da177e4c3f41 Linus Torvalds    2005-04-16  3588  				    mtc.mt_op == MTRETEN || mtc.mt_op == MTEOM ||
^1da177e4c3f41 Linus Torvalds    2005-04-16  3589  				    mtc.mt_op == MTLOCK || mtc.mt_op == MTLOAD ||
^1da177e4c3f41 Linus Torvalds    2005-04-16  3590  				    mtc.mt_op == MTFSF || mtc.mt_op == MTFSFM ||
^1da177e4c3f41 Linus Torvalds    2005-04-16  3591  				    mtc.mt_op == MTBSF || mtc.mt_op == MTBSFM ||
^1da177e4c3f41 Linus Torvalds    2005-04-16  3592  				    mtc.mt_op == MTCOMPRESSION;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3593  			}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3594  			i = flush_buffer(STp, i);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3595  			if (i < 0) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3596  				retval = i;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3597  				goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3598  			}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3599  			if (STps->rw == ST_WRITING &&
^1da177e4c3f41 Linus Torvalds    2005-04-16  3600  			    (mtc.mt_op == MTREW || mtc.mt_op == MTOFFL ||
^1da177e4c3f41 Linus Torvalds    2005-04-16  3601  			     mtc.mt_op == MTSEEK ||
^1da177e4c3f41 Linus Torvalds    2005-04-16  3602  			     mtc.mt_op == MTBSF || mtc.mt_op == MTBSFM)) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3603  				i = st_int_ioctl(STp, MTWEOF, 1);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3604  				if (i < 0) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3605  					retval = i;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3606  					goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3607  				}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3608  				if (mtc.mt_op == MTBSF || mtc.mt_op == MTBSFM)
^1da177e4c3f41 Linus Torvalds    2005-04-16  3609  					mtc.mt_count++;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3610  				STps->rw = ST_IDLE;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3611  			     }
^1da177e4c3f41 Linus Torvalds    2005-04-16  3612  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3613  		} else {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3614  			/*
^1da177e4c3f41 Linus Torvalds    2005-04-16  3615  			 * If there was a bus reset, block further access
^1da177e4c3f41 Linus Torvalds    2005-04-16  3616  			 * to this device.  If the user wants to rewind the tape,
^1da177e4c3f41 Linus Torvalds    2005-04-16  3617  			 * then reset the flag and allow access again.
^1da177e4c3f41 Linus Torvalds    2005-04-16  3618  			 */
^1da177e4c3f41 Linus Torvalds    2005-04-16  3619  			if (mtc.mt_op != MTREW &&
^1da177e4c3f41 Linus Torvalds    2005-04-16  3620  			    mtc.mt_op != MTOFFL &&
^1da177e4c3f41 Linus Torvalds    2005-04-16  3621  			    mtc.mt_op != MTRETEN &&
^1da177e4c3f41 Linus Torvalds    2005-04-16  3622  			    mtc.mt_op != MTERASE &&
^1da177e4c3f41 Linus Torvalds    2005-04-16  3623  			    mtc.mt_op != MTSEEK &&
^1da177e4c3f41 Linus Torvalds    2005-04-16  3624  			    mtc.mt_op != MTEOM) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3625  				retval = (-EIO);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3626  				goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3627  			}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3628  			reset_state(STp);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3629  			/* remove this when the midlevel properly clears was_reset */
^1da177e4c3f41 Linus Torvalds    2005-04-16  3630  			STp->device->was_reset = 0;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3631  		}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3632  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3633  		if (mtc.mt_op != MTNOP && mtc.mt_op != MTSETBLK &&
^1da177e4c3f41 Linus Torvalds    2005-04-16  3634  		    mtc.mt_op != MTSETDENSITY && mtc.mt_op != MTWSM &&
^1da177e4c3f41 Linus Torvalds    2005-04-16  3635  		    mtc.mt_op != MTSETDRVBUFFER && mtc.mt_op != MTSETPART)
^1da177e4c3f41 Linus Torvalds    2005-04-16  3636  			STps->rw = ST_IDLE;	/* Prevent automatic WEOF and fsf */
^1da177e4c3f41 Linus Torvalds    2005-04-16  3637  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3638  		if (mtc.mt_op == MTOFFL && STp->door_locked != ST_UNLOCKED)
^1da177e4c3f41 Linus Torvalds    2005-04-16  3639  			do_door_lock(STp, 0);	/* Ignore result! */
^1da177e4c3f41 Linus Torvalds    2005-04-16  3640  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3641  		if (mtc.mt_op == MTSETDRVBUFFER &&
^1da177e4c3f41 Linus Torvalds    2005-04-16  3642  		    (mtc.mt_count & MT_ST_OPTIONS) != 0) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3643  			retval = st_set_options(STp, mtc.mt_count);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3644  			goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3645  		}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3646  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3647  		if (mtc.mt_op == MTSETPART) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3648  			if (!STp->can_partitions ||
^1da177e4c3f41 Linus Torvalds    2005-04-16  3649  			    mtc.mt_count < 0 || mtc.mt_count >= ST_NBR_PARTITIONS) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3650  				retval = (-EINVAL);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3651  				goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3652  			}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3653  			if (mtc.mt_count >= STp->nbr_partitions &&
^1da177e4c3f41 Linus Torvalds    2005-04-16  3654  			    (STp->nbr_partitions = nbr_partitions(STp)) < 0) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3655  				retval = (-EIO);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3656  				goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3657  			}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3658  			if (mtc.mt_count >= STp->nbr_partitions) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3659  				retval = (-EINVAL);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3660  				goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3661  			}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3662  			STp->new_partition = mtc.mt_count;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3663  			retval = 0;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3664  			goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3665  		}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3666  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3667  		if (mtc.mt_op == MTMKPART) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3668  			if (!STp->can_partitions) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3669  				retval = (-EINVAL);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3670  				goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3671  			}
8038e6456a3e6f Kai Makisara      2016-02-09  3672  			i = do_load_unload(STp, file, 1);
8038e6456a3e6f Kai Makisara      2016-02-09  3673  			if (i < 0) {
8038e6456a3e6f Kai Makisara      2016-02-09  3674  				retval = i;
8038e6456a3e6f Kai Makisara      2016-02-09  3675  				goto out;
8038e6456a3e6f Kai Makisara      2016-02-09  3676  			}
8038e6456a3e6f Kai Makisara      2016-02-09  3677  			i = partition_tape(STp, mtc.mt_count);
8038e6456a3e6f Kai Makisara      2016-02-09  3678  			if (i < 0) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3679  				retval = i;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3680  				goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3681  			}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3682  			for (i = 0; i < ST_NBR_PARTITIONS; i++) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3683  				STp->ps[i].rw = ST_IDLE;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3684  				STp->ps[i].at_sm = 0;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3685  				STp->ps[i].last_block_valid = 0;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3686  			}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3687  			STp->partition = STp->new_partition = 0;
8038e6456a3e6f Kai Makisara      2016-02-09  3688  			STp->nbr_partitions = mtc.mt_count != 0 ? 2 : 1;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3689  			STps->drv_block = STps->drv_file = 0;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3690  			retval = 0;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3691  			goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3692  		}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3693  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3694  		if (mtc.mt_op == MTSEEK) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3695  			i = set_location(STp, mtc.mt_count, STp->new_partition, 0);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3696  			if (!STp->can_partitions)
^1da177e4c3f41 Linus Torvalds    2005-04-16  3697  				STp->ps[0].rw = ST_IDLE;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3698  			retval = i;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3699  			goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3700  		}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3701  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3702  		if (mtc.mt_op == MTUNLOAD || mtc.mt_op == MTOFFL) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3703  			retval = do_load_unload(STp, file, 0);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3704  			goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3705  		}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3706  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3707  		if (mtc.mt_op == MTLOAD) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3708  			retval = do_load_unload(STp, file, max(1, mtc.mt_count));
^1da177e4c3f41 Linus Torvalds    2005-04-16  3709  			goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3710  		}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3711  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3712  		if (mtc.mt_op == MTLOCK || mtc.mt_op == MTUNLOCK) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3713  			retval = do_door_lock(STp, (mtc.mt_op == MTLOCK));
^1da177e4c3f41 Linus Torvalds    2005-04-16  3714  			goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3715  		}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3716  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3717  		if (STp->can_partitions && STp->ready == ST_READY &&
^1da177e4c3f41 Linus Torvalds    2005-04-16  3718  		    (i = switch_partition(STp)) < 0) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3719  			retval = i;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3720  			goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3721  		}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3722  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3723  		if (mtc.mt_op == MTCOMPRESSION)
^1da177e4c3f41 Linus Torvalds    2005-04-16  3724  			retval = st_compression(STp, (mtc.mt_count & 1));
^1da177e4c3f41 Linus Torvalds    2005-04-16  3725  		else
^1da177e4c3f41 Linus Torvalds    2005-04-16  3726  			retval = st_int_ioctl(STp, mtc.mt_op, mtc.mt_count);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3727  		goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3728  	}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3729  	if (!STm->defined) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3730  		retval = (-ENXIO);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3731  		goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3732  	}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3733  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3734  	if ((i = flush_buffer(STp, 0)) < 0) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3735  		retval = i;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3736  		goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3737  	}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3738  	if (STp->can_partitions &&
^1da177e4c3f41 Linus Torvalds    2005-04-16  3739  	    (i = switch_partition(STp)) < 0) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3740  		retval = i;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3741  		goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3742  	}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3743  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3744  	if (cmd_type == _IOC_TYPE(MTIOCGET) && cmd_nr == _IOC_NR(MTIOCGET)) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3745  		struct mtget mt_status;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3746  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3747  		if (_IOC_SIZE(cmd_in) != sizeof(struct mtget)) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3748  			 retval = (-EINVAL);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3749  			 goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3750  		}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3751  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3752  		mt_status.mt_type = STp->tape_type;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3753  		mt_status.mt_dsreg =
^1da177e4c3f41 Linus Torvalds    2005-04-16  3754  		    ((STp->block_size << MT_ST_BLKSIZE_SHIFT) & MT_ST_BLKSIZE_MASK) |
^1da177e4c3f41 Linus Torvalds    2005-04-16  3755  		    ((STp->density << MT_ST_DENSITY_SHIFT) & MT_ST_DENSITY_MASK);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3756  		mt_status.mt_blkno = STps->drv_block;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3757  		mt_status.mt_fileno = STps->drv_file;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3758  		if (STp->block_size != 0) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3759  			if (STps->rw == ST_WRITING)
^1da177e4c3f41 Linus Torvalds    2005-04-16  3760  				mt_status.mt_blkno +=
^1da177e4c3f41 Linus Torvalds    2005-04-16  3761  				    (STp->buffer)->buffer_bytes / STp->block_size;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3762  			else if (STps->rw == ST_READING)
^1da177e4c3f41 Linus Torvalds    2005-04-16  3763  				mt_status.mt_blkno -=
^1da177e4c3f41 Linus Torvalds    2005-04-16  3764                                          ((STp->buffer)->buffer_bytes +
^1da177e4c3f41 Linus Torvalds    2005-04-16  3765                                           STp->block_size - 1) / STp->block_size;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3766  		}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3767  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3768  		mt_status.mt_gstat = 0;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3769  		if (STp->drv_write_prot)
^1da177e4c3f41 Linus Torvalds    2005-04-16  3770  			mt_status.mt_gstat |= GMT_WR_PROT(0xffffffff);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3771  		if (mt_status.mt_blkno == 0) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3772  			if (mt_status.mt_fileno == 0)
^1da177e4c3f41 Linus Torvalds    2005-04-16  3773  				mt_status.mt_gstat |= GMT_BOT(0xffffffff);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3774  			else
^1da177e4c3f41 Linus Torvalds    2005-04-16  3775  				mt_status.mt_gstat |= GMT_EOF(0xffffffff);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3776  		}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3777  		mt_status.mt_erreg = (STp->recover_reg << MT_ST_SOFTERR_SHIFT);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3778  		mt_status.mt_resid = STp->partition;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3779  		if (STps->eof == ST_EOM_OK || STps->eof == ST_EOM_ERROR)
^1da177e4c3f41 Linus Torvalds    2005-04-16  3780  			mt_status.mt_gstat |= GMT_EOT(0xffffffff);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3781  		else if (STps->eof >= ST_EOM_OK)
^1da177e4c3f41 Linus Torvalds    2005-04-16  3782  			mt_status.mt_gstat |= GMT_EOD(0xffffffff);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3783  		if (STp->density == 1)
^1da177e4c3f41 Linus Torvalds    2005-04-16  3784  			mt_status.mt_gstat |= GMT_D_800(0xffffffff);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3785  		else if (STp->density == 2)
^1da177e4c3f41 Linus Torvalds    2005-04-16  3786  			mt_status.mt_gstat |= GMT_D_1600(0xffffffff);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3787  		else if (STp->density == 3)
^1da177e4c3f41 Linus Torvalds    2005-04-16  3788  			mt_status.mt_gstat |= GMT_D_6250(0xffffffff);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3789  		if (STp->ready == ST_READY)
^1da177e4c3f41 Linus Torvalds    2005-04-16  3790  			mt_status.mt_gstat |= GMT_ONLINE(0xffffffff);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3791  		if (STp->ready == ST_NO_TAPE)
^1da177e4c3f41 Linus Torvalds    2005-04-16  3792  			mt_status.mt_gstat |= GMT_DR_OPEN(0xffffffff);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3793  		if (STps->at_sm)
^1da177e4c3f41 Linus Torvalds    2005-04-16  3794  			mt_status.mt_gstat |= GMT_SM(0xffffffff);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3795  		if (STm->do_async_writes ||
^1da177e4c3f41 Linus Torvalds    2005-04-16  3796                      (STm->do_buffer_writes && STp->block_size != 0) ||
^1da177e4c3f41 Linus Torvalds    2005-04-16  3797  		    STp->drv_buffer != 0)
^1da177e4c3f41 Linus Torvalds    2005-04-16  3798  			mt_status.mt_gstat |= GMT_IM_REP_EN(0xffffffff);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3799  		if (STp->cleaning_req)
^1da177e4c3f41 Linus Torvalds    2005-04-16  3800  			mt_status.mt_gstat |= GMT_CLN(0xffffffff);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3801  
1207045da5a7c9 Arnd Bergmann     2018-09-07  3802  		retval = put_user_mtget(p, &mt_status);
1207045da5a7c9 Arnd Bergmann     2018-09-07  3803  		if (retval)
^1da177e4c3f41 Linus Torvalds    2005-04-16  3804  			goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3805  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3806  		STp->recover_reg = 0;		/* Clear after read */
^1da177e4c3f41 Linus Torvalds    2005-04-16  3807  		goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3808  	}			/* End of MTIOCGET */
^1da177e4c3f41 Linus Torvalds    2005-04-16  3809  	if (cmd_type == _IOC_TYPE(MTIOCPOS) && cmd_nr == _IOC_NR(MTIOCPOS)) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3810  		struct mtpos mt_pos;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3811  		if (_IOC_SIZE(cmd_in) != sizeof(struct mtpos)) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3812  			 retval = (-EINVAL);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3813  			 goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3814  		}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3815  		if ((i = get_location(STp, &blk, &bt, 0)) < 0) {
^1da177e4c3f41 Linus Torvalds    2005-04-16  3816  			retval = i;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3817  			goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3818  		}
^1da177e4c3f41 Linus Torvalds    2005-04-16  3819  		mt_pos.mt_blkno = blk;
1207045da5a7c9 Arnd Bergmann     2018-09-07  3820  		retval = put_user_mtpos(p, &mt_pos);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3821  		goto out;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3822  	}
28f85009e0cf6a Matthias Kaehlcke 2007-07-29  3823  	mutex_unlock(&STp->lock);
d320a9551e394c Arnd Bergmann     2019-03-15  3824  
dba7688fc9037c Christoph Hellwig 2021-07-24  3825  	switch (cmd_in) {
dba7688fc9037c Christoph Hellwig 2021-07-24  3826  	case SG_IO:
dba7688fc9037c Christoph Hellwig 2021-07-24  3827  	case SCSI_IOCTL_SEND_COMMAND:
dba7688fc9037c Christoph Hellwig 2021-07-24  3828  	case CDROM_SEND_PACKET:
dba7688fc9037c Christoph Hellwig 2021-07-24  3829  		if (!capable(CAP_SYS_RAWIO))
dba7688fc9037c Christoph Hellwig 2021-07-24  3830  			return -EPERM;
^1da177e4c3f41 Linus Torvalds    2005-04-16 @3831  	default:
^1da177e4c3f41 Linus Torvalds    2005-04-16  3832  		break;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3833  	}
dba7688fc9037c Christoph Hellwig 2021-07-24  3834  
2e27f576abc6f0 Christoph Hellwig 2021-07-24  3835  	retval = scsi_ioctl(STp->device, STp->disk, file->f_mode, cmd_in, p);
dba7688fc9037c Christoph Hellwig 2021-07-24  3836  	if (!retval && cmd_in == SCSI_IOCTL_STOP_UNIT) {
dba7688fc9037c Christoph Hellwig 2021-07-24  3837  		/* unload */
dba7688fc9037c Christoph Hellwig 2021-07-24  3838  		STp->rew_at_close = 0;
dba7688fc9037c Christoph Hellwig 2021-07-24  3839  		STp->ready = ST_NO_TAPE;
dba7688fc9037c Christoph Hellwig 2021-07-24  3840  	}
dba7688fc9037c Christoph Hellwig 2021-07-24  3841  	return retval;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3842  
^1da177e4c3f41 Linus Torvalds    2005-04-16  3843   out:
28f85009e0cf6a Matthias Kaehlcke 2007-07-29  3844  	mutex_unlock(&STp->lock);
^1da177e4c3f41 Linus Torvalds    2005-04-16  3845  	return retval;
^1da177e4c3f41 Linus Torvalds    2005-04-16  3846  }
^1da177e4c3f41 Linus Torvalds    2005-04-16  3847  

:::::: The code at line 3831 was first introduced by commit
:::::: 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 Linux-2.6.12-rc2

:::::: TO: Linus Torvalds <torvalds@...970.osdl.org>
:::::: CC: Linus Torvalds <torvalds@...970.osdl.org>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

Download attachment ".config.gz" of type "application/gzip" (34912 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ