Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10516188ybi; Thu, 11 Jul 2019 06:34:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqxVfA0DbmTfpbW9zZNLkdfddrZyL0SwxFQlAOrSR+Az9fs5D8/umjnfaHCrv9Fhjiesfq7p X-Received: by 2002:a65:4841:: with SMTP id i1mr4491836pgs.316.1562852083087; Thu, 11 Jul 2019 06:34:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562852083; cv=none; d=google.com; s=arc-20160816; b=iSvGQW7MseD60V6Nvoz0EZXotTGw0wkW5260nl4b1pHtnDwFr7bpVhJNy33TwpnkiP 15yxPp7vVFVlOzLBjS+NoI2cUY8ulHUCUHJf2cKjSoZYDq5Yd5Jai1XLNaZuogdBQc4F a297f01DTyTcqTh0yRkoGT+JWzUXsuyG5Vv6F3H5OR2HjX5INx8KBd9RBEwGZgp0Q+Da R0ZVQYoPyJktGR4wkWrB34t239dN1hAwEEPX5z1vgabO2ihMWa9EqGo/sX4TIZQ8Bi8o 8TalGOtg/OXAE5dkaoCqR5fEUPgRgDMgk0LMnsAAgRUfTAXxTnH/rsMhF/HgJ2E6W0ni gxbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=GGCfBTnKFypHSz3MKJ6YppDuAUrI5zYaZIUkoyhrq8o=; b=lf0soiNgZ6MGrFtN6jS2UlPfhAtGarthOQLlFb7gGZuwy3I4lWIlOz5Bs+z3rvWrQQ UGlEq664Tn/9SxlCdSHu/S4oTuTTIMPi9NFl1O0UHpDcngbvlf+xraQz7vAlIWnrp0QM nsnr19GlTGAiyPfUNYEbCeDWKHez8rY2tfm6SzMkagt+/Co2vGyn1AaUvXAjTS33d4Go BwUlkIktPZGrDu3WAfM7QKBgqREyPXiElamta6uEUXHb8ZLsB076115u06LhL27MmjK6 6AFl6964PT87c6cWpFRiHqQqv0+Zfwd3O3VnPRlE96CD5OU803wgeNMOvnDI82K1UKRD 1igA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@digidescorp.com header.s=google header.b=Jr7Vd7r1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e36si3313272pgm.17.2019.07.11.06.34.26; Thu, 11 Jul 2019 06:34:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@digidescorp.com header.s=google header.b=Jr7Vd7r1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728691AbfGKNE2 (ORCPT + 99 others); Thu, 11 Jul 2019 09:04:28 -0400 Received: from mail-io1-f42.google.com ([209.85.166.42]:43265 "EHLO mail-io1-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728383AbfGKNE1 (ORCPT ); Thu, 11 Jul 2019 09:04:27 -0400 Received: by mail-io1-f42.google.com with SMTP id k20so12283393ios.10 for ; Thu, 11 Jul 2019 06:04:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=digidescorp.com; s=google; h=from:to:cc:subject:date:message-id; bh=GGCfBTnKFypHSz3MKJ6YppDuAUrI5zYaZIUkoyhrq8o=; b=Jr7Vd7r1Z/ZvARlkea9pw32BCUC3MhmPvhr68LuqBqeireBBPu5+Ni1w7m/JhALmOV 0nzb43cKwCs1GzDj7NacJZm/A67UlNC/GyxiRY8/FWlCik6ZblyBIVbZ5GBNCt/Cifsn iR5X25cYmRA+t8rZDYxBkTMEbUSUcIcwzgL9w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=GGCfBTnKFypHSz3MKJ6YppDuAUrI5zYaZIUkoyhrq8o=; b=SnX7iMI33nNzjX2gcx5UH4HlDdYL62PXVBZQDZMamvGYX9Sg8VJ9Mw7Qw3zFN1T4bl rDGchtJnQi0Lehp81gquQlNc+Upfj5VhKZeYLqd/R8rF/MOfapOVIXWda65R65mB2Xyh 5GN1MQvxPQO889ojXlCgDKzLAHbvGc8uBVtw/r1vZTQOjtbSRu8f/zBMZErnc2LKw1hg daLgyThxHQUEq7tfmvIQjhl9GsgMxEzJAhLojDZ16tVIzddZ5oxyDUngNmfMWyS1Kz1s R7DDajobbNjrKBvpywNZjtlGzYA7b3fRWn4uIcvHUJKx7dZWgwoR+xscFJEwk1gXuONX Nz/g== X-Gm-Message-State: APjAAAXu2l6WYYuRGEH65Zhf7LP8o/5ivIbWg6hNO0AYMpHzrwvbjt6r 1UTTTXSQhchb0ZtTBFqr24+xwg== X-Received: by 2002:a5d:9e48:: with SMTP id i8mr2662448ioi.51.1562850266543; Thu, 11 Jul 2019 06:04:26 -0700 (PDT) Received: from iscandar.digidescorp.com (104-51-28-62.lightspeed.cicril.sbcglobal.net. [104.51.28.62]) by smtp.googlemail.com with ESMTPSA id l11sm4051951ioj.32.2019.07.11.06.04.25 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 11 Jul 2019 06:04:26 -0700 (PDT) From: "Steven J. Magnani" X-Google-Original-From: "Steven J. Magnani" To: Jan Kara Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, =?UTF-8?q?Pali=20Roh=C3=A1r?= , "Steven J . Magnani" Subject: [PATCH 1/2] udf: refactor VRS descriptor identification Date: Thu, 11 Jul 2019 08:04:09 -0500 Message-Id: <20190711130410.13047-1-steve@digidescorp.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Extract code that parses a Volume Recognition Sequence descriptor (component), in preparation for calling it twice against different locations in a block. Signed-off-by: Steven J. Magnani --- a/fs/udf/super.c 2019-07-10 18:57:41.192852154 -0500 +++ b/fs/udf/super.c 2019-07-10 20:47:50.438352500 -0500 @@ -685,16 +685,62 @@ out_unlock: return error; } -/* Check Volume Structure Descriptors (ECMA 167 2/9.1) */ -/* We also check any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) */ -static loff_t udf_check_vsd(struct super_block *sb) +static int identify_vsd(const struct volStructDesc *vsd) +{ + int vsd_id = 0; + + if (!strncmp(vsd->stdIdent, VSD_STD_ID_CD001, VSD_STD_ID_LEN)) { + switch (vsd->structType) { + case 0: + udf_debug("ISO9660 Boot Record found\n"); + break; + case 1: + udf_debug("ISO9660 Primary Volume Descriptor found\n"); + break; + case 2: + udf_debug("ISO9660 Supplementary Volume Descriptor found\n"); + break; + case 3: + udf_debug("ISO9660 Volume Partition Descriptor found\n"); + break; + case 255: + udf_debug("ISO9660 Volume Descriptor Set Terminator found\n"); + break; + default: + udf_debug("ISO9660 VRS (%u) found\n", vsd->structType); + break; + } + } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BEA01, VSD_STD_ID_LEN)) + vsd_id = 1; + else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR02, VSD_STD_ID_LEN)) + vsd_id = 2; + else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR03, VSD_STD_ID_LEN)) + vsd_id = 3; + else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BOOT2, VSD_STD_ID_LEN)) + ; /* vsd_id = 0 */ + else if (!strncmp(vsd->stdIdent, VSD_STD_ID_CDW02, VSD_STD_ID_LEN)) + ; /* vsd_id = 0 */ + else { + /* TEA01 or invalid id : end of volume recognition area */ + vsd_id = 255; + } + + return vsd_id; +} + +/* + * Check Volume Structure Descriptors (ECMA 167 2/9.1) + * We also check any "CD-ROM Volume Descriptor Set" (ECMA 167 2/8.3.1) + * @return 2 if NSR02 found, 3 if NSR03 found, + * -1 if first sector read error, 0 otherwise + */ +static int udf_check_vsd(struct super_block *sb) { struct volStructDesc *vsd = NULL; loff_t sector = VSD_FIRST_SECTOR_OFFSET; int sectorsize; struct buffer_head *bh = NULL; - int nsr02 = 0; - int nsr03 = 0; + int nsr = 0; struct udf_sb_info *sbi; sbi = UDF_SB(sb); @@ -718,71 +764,27 @@ static loff_t udf_check_vsd(struct super * activity. This actually happened with uninitialised SSD partitions * (all 0xFF) before the check for the limit and all valid IDs were * added */ - for (; !nsr02 && !nsr03 && sector < VSD_MAX_SECTOR_OFFSET; + for (; (nsr < 2) && sector < VSD_MAX_SECTOR_OFFSET; sector += sectorsize) { + int vsd_id; + /* Read a block */ bh = udf_tread(sb, sector >> sb->s_blocksize_bits); if (!bh) break; - /* Look for ISO descriptors */ vsd = (struct volStructDesc *)(bh->b_data + (sector & (sb->s_blocksize - 1))); - if (!strncmp(vsd->stdIdent, VSD_STD_ID_CD001, - VSD_STD_ID_LEN)) { - switch (vsd->structType) { - case 0: - udf_debug("ISO9660 Boot Record found\n"); - break; - case 1: - udf_debug("ISO9660 Primary Volume Descriptor found\n"); - break; - case 2: - udf_debug("ISO9660 Supplementary Volume Descriptor found\n"); - break; - case 3: - udf_debug("ISO9660 Volume Partition Descriptor found\n"); - break; - case 255: - udf_debug("ISO9660 Volume Descriptor Set Terminator found\n"); - break; - default: - udf_debug("ISO9660 VRS (%u) found\n", - vsd->structType); - break; - } - } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BEA01, - VSD_STD_ID_LEN)) - ; /* nothing */ - else if (!strncmp(vsd->stdIdent, VSD_STD_ID_TEA01, - VSD_STD_ID_LEN)) { - brelse(bh); - break; - } else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR02, - VSD_STD_ID_LEN)) - nsr02 = sector; - else if (!strncmp(vsd->stdIdent, VSD_STD_ID_NSR03, - VSD_STD_ID_LEN)) - nsr03 = sector; - else if (!strncmp(vsd->stdIdent, VSD_STD_ID_BOOT2, - VSD_STD_ID_LEN)) - ; /* nothing */ - else if (!strncmp(vsd->stdIdent, VSD_STD_ID_CDW02, - VSD_STD_ID_LEN)) - ; /* nothing */ - else { - /* invalid id : end of volume recognition area */ - brelse(bh); - break; - } + vsd_id = identify_vsd(vsd); + if (vsd_id > nsr) + nsr = vsd_id; + brelse(bh); } - if (nsr03) - return nsr03; - else if (nsr02) - return nsr02; + if ((nsr >= 2) && (nsr <= 3)) + return nsr; else if (!bh && sector - (sbi->s_session << sb->s_blocksize_bits) == VSD_FIRST_SECTOR_OFFSET) return -1; @@ -1936,7 +1938,7 @@ static int udf_load_vrs(struct super_blo int silent, struct kernel_lb_addr *fileset) { struct udf_sb_info *sbi = UDF_SB(sb); - loff_t nsr_off; + int nsr = 0; int ret; if (!sb_set_blocksize(sb, uopt->blocksize)) { @@ -1947,13 +1949,13 @@ static int udf_load_vrs(struct super_blo sbi->s_last_block = uopt->lastblock; if (!uopt->novrs) { /* Check that it is NSR02 compliant */ - nsr_off = udf_check_vsd(sb); - if (!nsr_off) { + nsr = udf_check_vsd(sb); + if (!nsr) { if (!silent) udf_warn(sb, "No VRS found\n"); return -EINVAL; } - if (nsr_off == -1) + if (nsr == 255) udf_debug("Failed to read sector at offset %d. " "Assuming open disc. Skipping validity " "check\n", VSD_FIRST_SECTOR_OFFSET);