From patchwork Thu Mar 29 08:23:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rosy Song X-Patchwork-Id: 892631 X-Patchwork-Delegate: blogic@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=rosinson.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="nn4H2bmE"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40Bd8W1B4hz9ryk for ; Thu, 29 Mar 2018 19:24:43 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:Message-ID:Mime-Version:To:From :Date:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=pvMVbFQoHv8Rd34OH4At/f2uzQ+L1i/tDj134B7UlhU=; b=nn4H2bmECs8Db2 xnE7tidK3jLzrEWSscGsmvBFCqouE0Hj6JXHyrPv7yYGx9x50UBGR/i+nsFAlt1yK0Jwh4p6rL3hr c0cVVSDP4javz8GsHh+BHueiWc9KV2msJI3wXsSeUpFSoyPTV3nUvw+YHUbIOLLbR09K5eWZQZ6MJ 7kTaK4KlMoPkW2Z9qsIdB2fdd6cLLbdcmjpY5DmHKAdZcD8Umoxk5NbakJ5yCKhZatAuKU+YZTmoK 7pK77E4kBCfWdRSNh89ENMkcVCOPTmRXRNhv6RHvyHZJt0zpopR659FK+P7NX3Z0cOiDgr742urvq 6pEX3WUydLRNLbvgiwGA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f1Sqw-00005q-Er; Thu, 29 Mar 2018 08:24:10 +0000 Received: from out20-25.mail.aliyun.com ([115.124.20.25]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f1Sqn-0008Ug-J4 for lede-dev@lists.infradead.org; Thu, 29 Mar 2018 08:24:08 +0000 X-Alimail-AntiSpam: AC=CONTINUE; BC=0.07272582|-1; CH=green; FP=14936793583321950196|1|1|1|0|-1|-1|-1; HT=e02c03306; MF=rosysong@rosinson.com; NM=1; PH=DS; RN=2; RT=2; SR=0; TI=SMTPD_---.BUSt8BM_1522311815; Received: from USER-20180317FA(mailfrom:rosysong@rosinson.com fp:14.127.251.19) by smtp.aliyun-inc.com(10.147.40.26); Thu, 29 Mar 2018 16:23:35 +0800 Date: Thu, 29 Mar 2018 16:23:35 +0800 From: "rosysong@rosinson.com" To: lede-dev X-Priority: 3 X-Has-Attach: no X-Mailer: Foxmail 7.2.9.116[cn] Mime-Version: 1.0 Message-ID: <201803291623349651339@rosinson.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180329_012401_997903_3DE69870 X-CRM114-Status: GOOD ( 17.81 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [115.124.20.25 listed in list.dnswl.org] 0.0 T_SPF_TEMPERROR SPF: test of record failed (temperror) 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines Subject: [LEDE-DEV] [LEDE-DEV,1/3] fstools: add exfat filesystem support X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "banglang.huang" Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Add exfat filesystem support for fstools so that the block can detect and show the information of stroage in exfat format. Signed-off-by: Rosy Song ---  CMakeLists.txt                |   1 +  libblkid-tiny/blkidP.h        |  12 ++++  libblkid-tiny/exfat.c         | 155 ++++++++++++++++++++++++++++++++++++++++++  libblkid-tiny/libblkid-tiny.c |  87 ++++++++++++++++++++++++  libblkid-tiny/superblocks.h   |   6 ++  5 files changed, 261 insertions(+)  create mode 100644 libblkid-tiny/exfat.c --  2.13.3 Lede-dev mailing list Lede-dev@lists.infradead.org http://lists.infradead.org/mailman/listinfo/lede-dev diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e855bd..8efa56a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,7 @@ ADD_LIBRARY(blkid-tiny SHARED   libblkid-tiny/ext.c   libblkid-tiny/jffs2.c   libblkid-tiny/vfat.c + libblkid-tiny/exfat.c   libblkid-tiny/ntfs.c   libblkid-tiny/hfs.c   libblkid-tiny/swap.c diff --git a/libblkid-tiny/blkidP.h b/libblkid-tiny/blkidP.h index 1ba7673..a573166 100644 --- a/libblkid-tiny/blkidP.h +++ b/libblkid-tiny/blkidP.h @@ -557,4 +557,16 @@ extern size_t blkid_encode_to_utf8(int enc, unsigned char *dest, size_t len,  #define BLKID_ENC_UTF16BE 0  #define BLKID_ENC_UTF16LE 1   +enum uuid_format { + UUID_DOS = 0, /* 4 bytes */ + UUID_NTFS = 1, /* 8 bytes */ + UUID_DCE = 2, /* 16 bytes */ + UUID_DCE_STRING = 3, /* 36 bytes (VOLUME_ID_UUID_SIZE) */ +}; + +enum endian { + LE = 0, + BE = 1 +}; +  #endif /* _BLKID_BLKIDP_H */ diff --git a/libblkid-tiny/exfat.c b/libblkid-tiny/exfat.c new file mode 100644 index 0000000..8e69350 --- /dev/null +++ b/libblkid-tiny/exfat.c @@ -0,0 +1,155 @@ + /* + * Copyright (C) 1999 by Andries Brouwer + * Copyright (C) 1999, 2000, 2003 by Theodore Ts'o + * Copyright (C) 2001 by Andreas Dilger + * Copyright (C) 2004 Kay Sievers + * Copyright (C) 2008 Karel Zak + * Copyright (C) 2012 S-G Bergh + * Copyright (C) 2018 rosysong + * + * This file may be redistributed under the terms of the + * GNU Lesser General Public License. + */ + +#include +#include +#include +#include +#include +#include +#include + +#if 0 +#include "pt-mbr.h" +#endif + +#include "superblocks.h" + +#define EXFAT_SB_OFFSET 0 +#define EXFAT_DIR_ENTRY_SZ 32 +#define EXFAT_MAX_DIR_ENTRIES 100 + +struct exfat_super_block { +/* 0x00 */ uint8_t boot_jump[3]; +/* 0x03 */ uint8_t fs_name[8]; +/* 0x0B */ uint8_t must_be_zero[53]; +/* 0x40 */ uint64_t partition_offset; +/* 0x48 */ uint64_t volume_length; +/* 0x50 */ uint32_t fat_offset; // Sector address of 1st FAT +/* 0x54 */ uint32_t fat_size; // In sectors +/* 0x58 */ uint32_t cluster_heap_offset; // Sector address of Data Region +/* 0x5C */ uint32_t cluster_count; +/* 0x60 */ uint32_t root_dir; // Cluster address of Root Directory +/* 0x64 */ uint8_t vol_serial_nr[4]; // Volume ID +/* 0x68 */ uint16_t fs_revision; // VV.MM +/* 0x6A */ uint16_t vol_flags; +/* 0x6C */ uint8_t bytes_per_sector; // Power of 2: 9 => 512, 12 => 4096 +/* 0x6D */ uint8_t sectors_per_cluster; // Power of 2 +/* 0x6E */ uint8_t nr_of_fats; // 2 for TexFAT +/* 0x6F */ // ... +} __attribute__((packed)); + +struct exfat_dir_entry { +/* 0x00 */ uint8_t entry_type; + union { + struct volume_label { +/* 0x01 */ uint8_t char_count; // Length of label +/* 0x02 */ uint16_t vol_label[11]; // UTF16 string without null termination +/* 0x18 */ uint8_t reserved[8]; +/* 0x20 */ } __attribute__((packed)) label; + struct volume_guid { +/* 0x01 */ uint8_t sec_count; +/* 0x02 */ uint16_t set_checksum; +/* 0x04 */ uint16_t flags; +/* 0x06 */ uint8_t vol_guid[16]; +/* 0x16 */ uint8_t reserved[10]; +/* 0x20 */ } __attribute__((packed)) guid; + } __attribute__((packed)) type; +} __attribute__((packed)); + +static int probe_exfat(blkid_probe pr, const struct blkid_idmag *mag) +{ + struct exfat_super_block *sb; + struct exfat_dir_entry *de; + unsigned char *vol_label = 0; + unsigned char *vol_serno = NULL; + unsigned sector_sz; + unsigned cluster_sz; + uint64_t root_dir_off; + unsigned count; + unsigned need_lbl_guid; + const char *version = "EXFAT"; + + // Primary super block + DBG(LOWPROBE, ul_debug("exFAT: probing at offset 0x%x", EXFAT_SB_OFFSET)); + sb = blkid_probe_get_sb(pr, mag, struct exfat_super_block); + if (!sb) + return errno ? -errno : 1; + + if (memcmp(sb->fs_name, "EXFAT   ", 8) != 0) + return -1; + + sector_sz = 1 << sb->bytes_per_sector; + cluster_sz = sector_sz << sb->sectors_per_cluster; + // There are no clusters 0 and 1, so the first cluster is 2. + root_dir_off = (uint64_t)EXFAT_SB_OFFSET + + // Hmm... should we cast sector_sz/cluster_sz to uint64_t? + (le32_to_cpu(sb->cluster_heap_offset)) * sector_sz + + (le32_to_cpu(sb->root_dir) - 2) * cluster_sz; + DBG(LOWPROBE, ul_debug("exFAT: sector size 0x%x bytes", sector_sz)); + DBG(LOWPROBE, ul_debug("exFAT: cluster size 0x%x bytes", cluster_sz)); + DBG(LOWPROBE, ul_debug("exFAT: root dir is at 0x%llx", (long long)root_dir_off)); + + // Use DOS uuid(UUID_DOS) as fallback, if no GUID set + vol_serno = sb->vol_serial_nr; + blkid_probe_sprintf_uuid_exfat(pr, vol_serno, UUID_DOS); + + // EXFAT_MAX_DIR_ENTRIES is used as a safety belt. + // The Root Directory may hold an unlimited number of entries, + // so we do not want to check all. Usually label and GUID + // are in the beginning, but there are no guarantees. + need_lbl_guid = (1 << 0) | (1 << 1); + for (count = 0; count < EXFAT_MAX_DIR_ENTRIES; count++) { + de = (struct exfat_dir_entry *) + blkid_probe_get_buffer(pr, root_dir_off + (count * EXFAT_DIR_ENTRY_SZ), EXFAT_DIR_ENTRY_SZ); + if (de == NULL) + break; + if (de->entry_type == 0x00) { + // End of Directory Marker + DBG(LOWPROBE, ul_debug("exFAT: End of root directory reached after %u entries", count)); + break; + } + if (de->entry_type == 0x83) { + // Volume Label Directory Entry + vol_label = (unsigned char *)de->type.label.vol_label; + blkid_probe_set_unicode16label(pr, vol_label, LE, 2 * de->type.label.char_count); + need_lbl_guid &= ~(1 << 0); + } + if (de->entry_type == 0xA0) { + // Volume GUID Directory Entry (UUID_DCE) + vol_serno = de->type.guid.vol_guid; + blkid_probe_sprintf_uuid_exfat(pr, vol_serno, UUID_DCE); + need_lbl_guid &= ~(1 << 1); + } + if (!need_lbl_guid) + break; + } + + if (version) + blkid_probe_set_version(pr, version); + + return 0; +} + +const struct blkid_idinfo exfat_idinfo = +{ + .name = "exfat", + .usage = BLKID_USAGE_FILESYSTEM, + .probefunc = probe_exfat, + .magics = + { + { .magic = "EXFAT   ", .len = 8, .sboff = 0x03 }, + { NULL } + } +}; + diff --git a/libblkid-tiny/libblkid-tiny.c b/libblkid-tiny/libblkid-tiny.c index f020e23..ccfaf63 100644 --- a/libblkid-tiny/libblkid-tiny.c +++ b/libblkid-tiny/libblkid-tiny.c @@ -121,6 +121,51 @@ int blkid_probe_set_label(blkid_probe pr, unsigned char *label, size_t len)   return 0;  }   +int blkid_probe_set_unicode16(char *str, size_t len, const unsigned char *buf, enum endian endianess, size_t count) +{ + unsigned i, j; + unsigned c; + + j = 0; + for (i = 0; i + 2 <= count; i += 2) { + if (endianess == LE) + c = (buf[i+1] << 8) | buf[i]; + else + c = (buf[i] << 8) | buf[i+1]; + if (c == 0) + break; + if (j+1 >= len) + break; + if (c < 0x80) { + /* 0xxxxxxx */ + } else { + unsigned char topbits = 0xc0; + if (j+2 >= len) + break; + if (c < 0x800) { + /* 110yyyxx 10xxxxxx */ + } else { + if (j+3 >= len) + break; + /* 1110yyyy 10yyyyxx 10xxxxxx */ + str[j++] = (unsigned char) (0xe0 | (c >> 12)); + topbits = 0x80; + } + str[j++] = (unsigned char) (topbits | ((c >> 6) & 0x3f)); + c = 0x80 | (c & 0x3f); + } + str[j++] = (unsigned char) c; + } + str[j] = '\0'; + + return j; +} + +int blkid_probe_set_unicode16label(blkid_probe pr, unsigned char *label, enum endian endianess, size_t len) +{ + return blkid_probe_set_unicode16(pr->label, sizeof(pr->label), label, endianess, len); +} +  int blkid_probe_set_uuid_as(blkid_probe pr, unsigned char *uuid, const char *name)  {   short unsigned int*u = (short unsigned int*) uuid; @@ -135,6 +180,47 @@ int blkid_probe_set_uuid_as(blkid_probe pr, unsigned char *uuid, const char *nam   return 0;  }   +int blkid_probe_sprintf_uuid_exfat(blkid_probe pr, unsigned char *buf, enum uuid_format format) +{ + unsigned i; + unsigned count = 4 << format; + + /* if set, create string in the same format, the native platform uses */ + for (i = 0; i < count; i++) + if (buf[i] != 0) + goto set; + + /* all bytes are zero, leave it empty ("") */ + return 0; + +set: + switch (format) { + case UUID_DOS: + blkid_probe_sprintf_uuid(pr, buf, count, "%02X%02X-%02X%02X", + buf[3], buf[2], buf[1], buf[0]); + break; + case UUID_NTFS: + blkid_probe_sprintf_uuid(pr, buf, count, "%02X%02X%02X%02X%02X%02X%02X%02X", + buf[7], buf[6], buf[5], buf[4], + buf[3], buf[2], buf[1], buf[0]); + break; + case UUID_DCE: + blkid_probe_sprintf_uuid(pr, buf, count, + "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", + buf[0], buf[1], buf[2], buf[3], + buf[4], buf[5], buf[6], buf[7], + buf[8], buf[9], buf[10], buf[11], + buf[12], buf[13], buf[14], buf[15]); + break; + case UUID_DCE_STRING: + memcpy(pr->uuid, buf, count); + pr->uuid[count] = '\0'; + break; + } + + return count; +} +  int blkid_probe_set_uuid(blkid_probe pr, unsigned char *uuid)  {   return blkid_probe_set_uuid_as(pr, uuid, NULL); @@ -155,6 +241,7 @@ int blkid_probe_sprintf_uuid(blkid_probe pr, unsigned char *uuid,  static const struct blkid_idinfo *idinfos[] =  {   &vfat_idinfo, + &exfat_idinfo,   &swsuspend_idinfo,   &swap_idinfo,   &ext4dev_idinfo, diff --git a/libblkid-tiny/superblocks.h b/libblkid-tiny/superblocks.h index cde8a40..85c61f7 100644 --- a/libblkid-tiny/superblocks.h +++ b/libblkid-tiny/superblocks.h @@ -88,9 +88,15 @@ extern int blkid_probe_sprintf_version(blkid_probe pr, const char *fmt, ...)  extern int blkid_probe_set_label(blkid_probe pr, unsigned char *label, size_t len);  extern int blkid_probe_set_utf8label(blkid_probe pr, unsigned char *label,                  size_t len, int enc); +extern int blkid_probe_set_unicode16(char *str, size_t len, const unsigned char *buf, +                enum endian endianess, size_t count); +extern int blkid_probe_set_unicode16label(blkid_probe pr, unsigned char *label, +                enum endian endianess, size_t len);  extern int blkid_probe_sprintf_uuid(blkid_probe pr, unsigned char *uuid,                  size_t len, const char *fmt, ...)   __attribute__ ((__format__ (__printf__, 4, 5))); +extern int blkid_probe_sprintf_uuid_exfat(blkid_probe pr, unsigned char *buf, +                enum uuid_format format);  extern int blkid_probe_strncpy_uuid(blkid_probe pr, unsigned char *str, size_t len);    extern int blkid_probe_set_uuid(blkid_probe pr, unsigned char *uuid); From patchwork Thu Mar 29 08:25:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rosy Song X-Patchwork-Id: 892632 X-Patchwork-Delegate: blogic@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=rosinson.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="jXya39M5"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40Bd9T2gzvz9ryk for ; Thu, 29 Mar 2018 19:25:33 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:Message-ID:Mime-Version:To:From :Date:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=WiTnFyq9mm8KyPe3ksxoof80WDtmh4Ex6WUtMT2h8R0=; b=jXya39M5k8KVML PBllJRYw6ZzbgShV6YpUI7XK3MxvGyW37ba9OfKnygzIbLxqbBsUOoUTvCGURYhqr+HsTdHEx7bu2 tIIuXbLHGtAvI/7fFjkteSKZaOFL65EhtSoY1dxNu0k3xiBZyfoTdLXEN833V3JZVo62GX2P3WcZw mKNg+bHpRF8fuDOfR5jJHPEY8++DGqj75PAzow+BPnrKFSHJy5KhDQKXU+Q01pIU8h3bhaOBwODVi OqGazDm4seCXqwBLxzmT9+3UW7lItRJRnOJ+1dEveoxTqRugJ6pEswff3ub2KUvGOWaM0hvdODfCs qUyRQ+BeXBSimj1q1U1A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f1Ss4-0001sR-I9; Thu, 29 Mar 2018 08:25:20 +0000 Received: from out20-14.mail.aliyun.com ([115.124.20.14]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f1Ss0-0000cp-6K for lede-dev@lists.infradead.org; Thu, 29 Mar 2018 08:25:18 +0000 X-Alimail-AntiSpam: AC=CONTINUE; BC=0.3258748|-1; CH=green; FP=0|0|0|0|0|-1|-1|-1; HT=e02c03275; MF=rosysong@rosinson.com; NM=1; PH=DS; RN=1; RT=1; SR=0; TI=SMTPD_---.BUT3yXy_1522311902; Received: from USER-20180317FA(mailfrom:rosysong@rosinson.com fp:14.127.251.19) by smtp.aliyun-inc.com(10.147.42.16); Thu, 29 Mar 2018 16:25:02 +0800 Date: Thu, 29 Mar 2018 16:25:01 +0800 From: "rosysong@rosinson.com" To: lede-dev X-Priority: 3 X-Has-Attach: no X-Mailer: Foxmail 7.2.9.116[cn] Mime-Version: 1.0 Message-ID: <2018032916250165473610@rosinson.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180329_012516_401279_49CBEF10 X-CRM114-Status: UNSURE ( 6.73 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [115.124.20.14 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [115.124.20.14 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines Subject: [LEDE-DEV] [LEDE-DEV,2/3] fstools: fix potential memory leak X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Fix potential memory leak in fstools Signed-off-by: Rosy Song ---  libblkid-tiny/libblkid-tiny.c | 2 +-  1 file changed, 1 insertion(+), 1 deletion(-) --  2.13.3 Lede-dev mailing list Lede-dev@lists.infradead.org http://lists.infradead.org/mailman/listinfo/lede-dev diff --git a/libblkid-tiny/libblkid-tiny.c b/libblkid-tiny/libblkid-tiny.c index ccfaf63..12cab6f 100644 --- a/libblkid-tiny/libblkid-tiny.c +++ b/libblkid-tiny/libblkid-tiny.c @@ -282,7 +282,7 @@ int probe_block(char *block, struct blkid_struct_probe *pr)     mag = &idinfos[i]->magics[0];   - while (mag->magic) { + while (mag && mag->magic) {   int off = (mag->kboff * 1024) + mag->sboff;   char magic[32] = { 0 };   From patchwork Thu Mar 29 08:25:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rosy Song X-Patchwork-Id: 892633 X-Patchwork-Delegate: blogic@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=rosinson.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="qWnL6ILu"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40BdCQ6Gbbz9s0t for ; Thu, 29 Mar 2018 19:27:14 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:Message-ID:Mime-Version:To:From :Date:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=N2KWF1KGeLEnOfq9d1HqvawJxjhFOi0XLOFNTrlqCU8=; b=qWnL6ILuHSaYGn P6W7/aD4OWDgWij9dtWblhmw55GwQ/O0l1c+2KTGdkKSEi5D5kT1PN+AtvAmv/fP1Sdl73swemrGJ Qp/mCMrEqvdYaonvXu01TxEqz742VF0bZgGkRHjB1XBdQpnJu7BMQ2n0jwj4tcCG2qTZT9aZsv+QT PHuo4Yp1z/cMrQSwnjC8btGrLKphRFzPniqK8J9QRo7fMsVpvyeXOLBV+6yOQdbpdR9DsM8c9SWhs pBlvpQewnFw46OsexRpjFi1CyA3GmobrJFRVCWzYHyD/V8iLMkS+iNYi4Ex4img26oq5bq4pd8FqF mJVQggpiIaJmk6/6mR4w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f1Stg-0002pt-Kk; Thu, 29 Mar 2018 08:27:00 +0000 Received: from out20-98.mail.aliyun.com ([115.124.20.98]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f1Ssr-0002DH-R7 for lede-dev@lists.infradead.org; Thu, 29 Mar 2018 08:26:13 +0000 X-Alimail-AntiSpam: AC=CONTINUE; BC=0.07274823|-1; CH=green; FP=0|0|0|0|0|-1|-1|-1; HT=e02c03271; MF=rosysong@rosinson.com; NM=1; PH=DS; RN=1; RT=1; SR=0; TI=SMTPD_---.BUTG-fK_1522311952; Received: from USER-20180317FA(mailfrom:rosysong@rosinson.com fp:14.127.251.19) by smtp.aliyun-inc.com(10.147.40.233); Thu, 29 Mar 2018 16:25:53 +0800 Date: Thu, 29 Mar 2018 16:25:52 +0800 From: "rosysong@rosinson.com" To: lede-dev X-Priority: 3 X-Has-Attach: no X-Mailer: Foxmail 7.2.9.116[cn] Mime-Version: 1.0 Message-ID: <2018032916255252436911@rosinson.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180329_012610_106184_E822263E X-CRM114-Status: UNSURE ( 8.42 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [115.124.20.98 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines Subject: [LEDE-DEV] [LEDE-DEV, 3/3] fstools: fix lost mount point when first boot X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org When firmware is new flashed and reboot with a storage device plug in its usb interface. Though the filesystem is not ready (FS_STATE_UNKNOWN), the /dev/sda1 still mount on /mnt/sda1 by block-mount, then the system switching jffs... root@OpenWrt:~# dmesg ...... [   32.224522] jffs2_scan_eraseblock(): End of filesystem marker found at 0x0 [   32.270514] jffs2_build_filesystem(): unlocking the mtd device... [   32.278711] jffs2_build_filesystem(): erasing all blocks after the end marker... root@OpenWrt:~# mount ...... /dev/sda1 on /mnt/sda1 type exfat (rw,relatime,fmask=0000,dmask=0000,allow_utime=0022,iocharset=utf8,namecase=0,errors=remount-ro) mountd(pid1314) on /tmp/run/blockd type autofs (rw,relatime,fd=7,pgrp=1,timeout=30,minproto=5,maxproto=5,indirect) After few miniutes, when filesystem is ready (FS_STATE_READY, /overlay/.fs_state -> 2) the /dev/sda1 lost its mount point root@OpenWrt:~# dmesg ... [  207.439407] jffs2: notice: (1336) jffs2_build_xattr_subsystem: complete building xattr subsystem, 0 of xdatum (0 unchecked, 0 orphan) and 0 of xref (0 dead, 0 orphan) found. root@OpenWrt:~# mount ...... **no /mnt/sda1 found** ...... Signed-off-by: Rosy Song ---  mount_root.c | 11 ++++++++++-  1 file changed, 10 insertions(+), 1 deletion(-) --  2.13.3 Lede-dev mailing list Lede-dev@lists.infradead.org http://lists.infradead.org/mailman/listinfo/lede-dev diff --git a/mount_root.c b/mount_root.c index dffb0a6..110e4fd 100644 --- a/mount_root.c +++ b/mount_root.c @@ -101,6 +101,7 @@ stop(int argc, char *argv[1])  static int  done(int argc, char *argv[1])  { + int ret;   struct volume *v = volume_find("rootfs_data");     if (!v) @@ -109,7 +110,15 @@ done(int argc, char *argv[1])   switch (volume_identify(v)) {   case FS_NONE:   case FS_DEADCODE: - return jffs2_switch(v); + ret = jffs2_switch(v); + /* + * Devices mounted under /mnt will lost their mount point(see switch2jffs()) + * if the filesystem's(/overlay) state is not FS_STATE_READY, + * this action can fix it. + */ + if (!access("/sbin/block", X_OK)) + system("/sbin/block mount"); + return ret;     case FS_EXT4:   case FS_F2FS: