Received: from list by lists.gnu.org with archive (Exim 4.71) id 1ff3uY-0005FN-4K for mharc-grub-devel@gnu.org; Mon, 16 Jul 2018 09:51:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59425) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ff3uV-0005Ab-FE for grub-devel@gnu.org; Mon, 16 Jul 2018 09:51:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ff3uQ-0002h2-JX for grub-devel@gnu.org; Mon, 16 Jul 2018 09:51:31 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:41654) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ff3uQ-0002f7-A6 for grub-devel@gnu.org; Mon, 16 Jul 2018 09:51:26 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w6GDmplO171480; Mon, 16 Jul 2018 13:51:23 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : content-transfer-encoding : in-reply-to; s=corp-2018-07-02; bh=xSxz2pK4t55r4lZ9sXF5uQ4oE55h3HgsBkJ4e5w4Zz8=; b=cb2po4tXfZm/wu0BR6JLbb4w0aMkOImx2xtEOuxMCRXOCUt3xkwsbEsvYo59aEvOiXxo D4EVbKmzpeYiWsFtr0BJcf3nqpOk+3nJqzfc0n6ejicafYMVDG12SI9HVnnulqitkqrp Md/Ujiw4uPqNyZFwjnE3bnt7sj/obGr2Dbmlw9hBj0MQtACLEX8X7uQTppaeiOxirDlh DUAY1O3n93TZdh9YWCGLWoBFjJxAliGSMBHfP18WW7ZPgUkGD2aNoMqKrSKxnjn/c45h ertrpOSyR6scWSITi7r7YhHQmlG5oQg9IOEC4XmVSR8BwzuZ4b51eeBl/uvaBHLybqag SQ== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2k7a3jmgup-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 Jul 2018 13:51:23 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w6GDpMVh011497 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 16 Jul 2018 13:51:22 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w6GDpL7H016677; Mon, 16 Jul 2018 13:51:22 GMT Received: from olila.local.net-space.pl (/10.175.160.9) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 16 Jul 2018 06:51:21 -0700 Date: Mon, 16 Jul 2018 15:51:17 +0200 From: Daniel Kiper To: Eric Snowberg Cc: The development of GNU GRUB , John Paul Adrian Glaubitz Subject: Re: [PATCH v2] ieee1275: obdisk driver Message-ID: <20180716135117.GF26572@olila.local.net-space.pl> References: <1527724522-32305-1-git-send-email-eric.snowberg@oracle.com> <20180615120218.GO20016@olila.local.net-space.pl> <3C2AB209-D05C-4C0C-B2D9-FF3C0AD7B2E7@oracle.com> <20180621165822.GA20016@olila.local.net-space.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8955 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1806210000 definitions=main-1807160162 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by userp2120.oracle.com id w6GDmplO171480 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.85 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Jul 2018 13:51:33 -0000 Sorry for late reply but I was busy with other stuff. On Thu, Jun 21, 2018 at 01:46:46PM -0600, Eric Snowberg wrote: > > On Jun 21, 2018, at 10:58 AM, Daniel Kiper = wrote: > > On Fri, Jun 15, 2018 at 09:58:56AM -0600, Eric Snowberg wrote: > >>> On Jun 15, 2018, at 6:02 AM, Daniel Kiper = wrote: > >>> On Wed, May 30, 2018 at 04:55:22PM -0700, Eric Snowberg wrote: [...] > >>>> +static char * > >>>> +replace_escaped_commas (char *src) > >>>> +{ > >>>> + char *iptr; > >>>> + > >>>> + if (src =3D=3D NULL) > >>>> + return NULL; > >>>> + for (iptr =3D src; *iptr; ) > >>>> + { > >>>> + if ((*iptr =3D=3D '\\') && (*(iptr + 1) =3D=3D ',')) > >>>> + { > >>>> + *iptr++ =3D '_'; > >>>> + *iptr++ =3D '_'; > >>>> + } > >>>> + iptr++; > >>>> + } > >>>> + > >>>> + return src; > >>>> +} > >>>> + > >>>> +static int > >>>> +count_commas (const char *src) > >>>> +{ > >>>> + int count =3D 0; > >>>> + > >>>> + for ( ; *src; src++) > >>>> + if (*src =3D=3D ',') > >>>> + count++; > >>>> + > >>>> + return count; > >>>> +} > >>>> + > >>>> +static void > >>>> +escape_commas (const char *src, char *dest) > >>> > >>> I am confused by this play with commas. Could explain somewhere > >>> where this commas are needed unescaped, escaped, replaced, etc. > >>> Could not we simplify this somehow? > >> > >> I=E2=80=99m open for recommendations. > > > > Great! However, I need more info which layer need what WRT ",=E2=80=9D= , > > AFAIK all layers above expect it: > https://www.gnu.org/software/grub/manual/grub/grub.html#Device-syntax > > Everything above this driver expects it to be escaped. Obviously when Do you mean from the command line? If yes could you give an example with proper escaping? > the driver talks to the actual hardware these devices can not have the > escaped names. OK but this is not clear. So, please add a comment explaining it in the code somewhere. > > how often this conversions must be done, why you have chosen that > > solution, etc. Then I will try to optimize solution a bit. > > Under normal circumstances it only takes place once per disk as they > are enumerated. All disks are cached within this driver so it should > not happen often. That is why I store both versions so I don=E2=80=99t= have > to go back and forth. Look at the current driver ofdisk. It has a > function called compute_dev_path which does this conversion on every > single open (grub_ofdisk_open). That does not happen with this new > driver. IMHO this is a much more optimized solution than the current > driver. Then OK. However, this have to be explained somewhere in the code. Additionally, I think that proper variable naming would help too, e.g. name and name_esc. And I would do this: - s/decode_grub_devname/unescape_grub_devnam/, - s/encode_grub_devname/escape_grub_devname/, - extract unscaping code to the unescape_commas() function; even if it is called once; just for the completeness. What is replace_escaped_commas()? Why do we need that function? [...] > >>>> + grub_free (canon); > >>>> + return (ret); > >>>> +} > >>>> + > >>>> +static grub_err_t > >>>> +grub_obdisk_read (grub_disk_t disk, grub_disk_addr_t sector, > >>>> + grub_size_t size, char *dest) > >>>> +{ > >>>> + grub_err_t ret =3D GRUB_ERR_NONE; > >>>> + struct disk_dev *dev; > >>>> + unsigned long long pos; > >>>> + grub_ssize_t result =3D 0; > >>>> + > >>>> + if (disk->data =3D=3D NULL) > >>>> + return grub_error (GRUB_ERR_BAD_DEVICE, "invalid disk data"); > >>>> + > >>>> + dev =3D (struct disk_dev *)disk->data; > >>>> + pos =3D sector << disk->log_sector_size; > >>>> + grub_ieee1275_seek (dev->ihandle, pos, &result); > >>>> + > >>>> + if (result < 0) > >>>> + { > >>>> + dev->opened =3D 0; > >>>> + return grub_error (GRUB_ERR_READ_ERROR, "seek error, can't = seek block %llu", > >>>> + (long long) sector); > >>>> + } > >>>> + > >>>> + grub_ieee1275_read (dev->ihandle, dest, size << disk->log_secto= r_size, > >>>> + &result); > >>>> + > >>>> + if (result !=3D (grub_ssize_t) (size << disk->log_sector_size)) > >>>> + { > >>>> + dev->opened =3D 0; > >>>> + return grub_error (GRUB_ERR_READ_ERROR, N_("failure reading= sector 0x%llx " > >>>> + "from `%s'"), > >>>> + (unsigned long long) sector, > >>>> + disk->name); > >>>> + } > >>>> + return ret; > >>>> +} > >>>> + > >>>> +static void > >>>> +grub_obdisk_close (grub_disk_t disk) > >>> > >>> s/grub_obdisk_close/grub_obdisk_clear/? > >> > > > >> It really is a close as far as the grub driver is concerned > >> (grub_disk_dev). If you insist I=E2=80=99ll change it, but naming it= clear > >> doesn't make sense to me. > > > > If similar functions in other drivers do just memset() or so and they > > are named *close* then I am not going to insist. If it is not true th= en > > I will ask you to do that change. > > From what I can see _close seems like the standard name here. Some > drivers such as efidisk just do a grub_dprintf and nothing more within > its close. So, lets leave it as is. Daniel