linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] new system call mknod64
Date: 21 Apr 2003 12:59:13 -0700	[thread overview]
Message-ID: <b81iih$5f3$1@cesium.transmeta.com> (raw)
In-Reply-To: Pine.LNX.4.44.0304211153270.9109-100000@home.transmeta.com

Followup to:  <Pine.LNX.4.44.0304211153270.9109-100000@home.transmeta.com>
By author:    Linus Torvalds <torvalds@transmeta.com>
In newsgroup: linux.dev.kernel
> 
> But that _will_ force aliasing, unless you start doing some really funky 
> things (make the dev_t look more like a UTF-8 unicode-like extension, 
> which is obviously possible). In other words, there will be OTHER values 
> for "dev_t" that will _also_ look like the tuple <3,1>.
> 
>  - other values of dev_t that also look like <3,1> had better act 
>    _identically_ to the legacy values. It _has_ to work this way, since 
>    otherwise you'd have a total maintenance nightmare, with "ls -l"  
>    showing two device files as being identical, yet having different
>    behaviour.
> 

Actually, the lessons learned from many things including UTF-8 (which
unfortunately does have aliasing) seems to indicate that the only
right answer is that noncanonical aliases are *illegal.*  If we do
mapping on the syscall boundary, then the kernel will always report
canonical form, and we should just throw -EINVAL on receiving a
noncanonical device number if such a thing can exist at all.

FWIW, here is a completely alias-free encoding of dev_t which is also
backwards compatible and hole-free:

  dev_t := major<31:8> . minor<31:8> . major<7:0> . minor<7:0>

where . is bitwise concatenation.  One of the major advantages, other
that being alias-free, is that the resulting code is free from
conditionals.

typedef __u64 dev_t;

static inline __u32 MAJOR(dev_t __d)
{
	return (__u32)(__d >> 32) & 0xffffff00 |
	       (__u32)(__d >> 8)  & 0x000000ff;
}
static inline __u32 MINOR(dev_t __d)
{
	return (__u32)(__d >> 8) & 0xffffff00 |
	       (__u32)__d & 0x000000ff;
}
static inline dev_t MKDEV(__u32 __ma, __u32 __mi)
{
	return ((dev_t)(__ma & 0xffffff00) << 32) |
	       ((dev_t)(__ma & 0x000000ff) << 8) |
	       ((dev_t)(__mi & 0xffffff00) << 8) |
	       ((dev_t)__mi & 0x000000ff);
}

In i386 assembly language, using regcall(%eax,%edx,%ecx):

MAJOR:
	movb %ah,%dl
	movl %edx,%eax
	ret

MINOR:
	movb %al,%ah
	movb %dl,%al
	rorl $8,%eax
	ret

MKDEV:
	movl %eax,%ecx
	shll $8,%eax
	movb %dl,%ah
	movb %cl,%al
	shrl $24,%ecx
	movb %cl,%dl
	ret
-- 
<hpa@transmeta.com> at work, <hpa@zytor.com> in private!
"Unix gives you enough rope to shoot yourself in the foot."
Architectures needed: ia64 m68k mips64 ppc ppc64 s390 s390x sh v850 x86-64

  reply	other threads:[~2003-04-21 19:48 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-20 21:26 [PATCH] new system call mknod64 Andries.Brouwer
2003-04-20 21:43 ` David S. Miller
2003-04-20 21:56   ` Linus Torvalds
2003-04-21 11:59     ` Roman Zippel
2003-04-21 18:01       ` Linus Torvalds
2003-04-21 18:10         ` Christoph Hellwig
2003-04-21 18:21           ` viro
2003-04-21 18:22           ` Linus Torvalds
2003-04-21 18:27             ` viro
2003-04-21 18:35               ` Linus Torvalds
2003-04-21 18:54                 ` viro
2003-04-21 19:16                   ` Jörn Engel
2003-04-21 18:35             ` Christoph Hellwig
2003-04-21 18:42               ` H. Peter Anvin
2003-04-21 18:44               ` Linus Torvalds
2003-04-21 18:47                 ` Christoph Hellwig
2003-04-21 18:58                   ` viro
2003-04-21 19:05                     ` Linus Torvalds
2003-04-21 19:35                       ` viro
2003-04-21 20:02                         ` Linus Torvalds
2003-04-21 19:04                   ` Linus Torvalds
2003-04-21 19:59                     ` H. Peter Anvin [this message]
2003-04-21 18:51                 ` H. Peter Anvin
2003-04-21 23:49             ` Roman Zippel
     [not found] <20030421215009$2052@gated-at.bofh.it>
     [not found] ` <20030421231010$7ee3@gated-at.bofh.it>
     [not found]   ` <20030422000016$17e3@gated-at.bofh.it>
     [not found]     ` <20030422083014$0fe2@gated-at.bofh.it>
2003-04-22 20:02       ` Arnd Bergmann
  -- strict thread matches above, loose matches on Subject: below --
2003-04-22  1:02 Andries.Brouwer
2003-04-22  1:32 ` H. Peter Anvin
2003-04-22  2:01   ` Jamie Lokier
2003-04-22  2:52     ` H. Peter Anvin
2003-04-22  6:00       ` jw schultz
2003-04-22 17:17         ` H. Peter Anvin
2003-04-21 21:48 Andries.Brouwer
2003-04-21 22:07 ` Linus Torvalds
2003-04-21 21:43 Andries.Brouwer
2003-04-21 23:02 ` H. Peter Anvin
2003-04-21 23:50   ` Jamie Lokier
2003-04-22  8:24     ` Shachar Shemesh
2003-04-20 22:12 Andries.Brouwer
2003-04-21  6:31 ` H. Peter Anvin
2003-04-20 20:34 Andries.Brouwer
2003-04-20 21:12 ` David S. Miller
2003-04-20 18:39 Andries.Brouwer
2003-04-20 18:52 ` Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='b81iih$5f3$1@cesium.transmeta.com' \
    --to=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).