Re: [ast-developers] |*at()|-emulation, 3rd prototype...

2012-09-02 Thread Glenn Fowler

On Sun, 2 Sep 2012 12:43:58 +0200 Cedric Blancher wrote:
 On 2 September 2012 06:04, Glenn Fowler g...@research.att.com wrote:
 
  is there any rationale for there being no *at() variant for
 
  chdir()
  truncate()

 If I remember it right from the old POSIX conf calls: Everything which
 requires to access a file's content and has a f* function should go
 through openat()+f*(). In this case this means you'd have to call
 openat() to get a file handle and use ftruncate().

 chdir() has explicitly no at version because the same basic rule
 (replace file's content with directory's content) applies: Use
 openat() with O_SEARCH+fchdir(). It's two syscalls but it's almost
 having identical performance. And you always have the directory fd
 around for later usage :)

thanks
and I'll keep that 2 syscalls almost the same as 1 in my back pocket

___
ast-developers mailing list
ast-developers@research.att.com
https://mailman.research.att.com/mailman/listinfo/ast-developers


Re: [ast-developers] |*at()|-emulation, 3rd prototype...

2012-09-02 Thread Glenn Fowler

On Sun, 2 Sep 2012 17:05:20 +0200 Cedric Blancher wrote:
 On 2 September 2012 16:37, Glenn Fowler g...@research.att.com wrote:
 
  On Sun, 2 Sep 2012 12:43:58 +0200 Cedric Blancher wrote:
  On 2 September 2012 06:04, Glenn Fowler g...@research.att.com wrote:
  
   is there any rationale for there being no *at() variant for
  
   chdir()
   truncate()
 
  If I remember it right from the old POSIX conf calls: Everything which
  requires to access a file's content and has a f* function should go
  through openat()+f*(). In this case this means you'd have to call
  openat() to get a file handle and use ftruncate().
 
  chdir() has explicitly no at version because the same basic rule
  (replace file's content with directory's content) applies: Use
  openat() with O_SEARCH+fchdir(). It's two syscalls but it's almost
  having identical performance. And you always have the directory fd
  around for later usage :)
 
  thanks
  and I'll keep that 2 syscalls almost the same as 1 in my back pocket

 No, no, I didn't mean that as general rule. Just the combination of
 openat() and fchdir() is fast because fchdir() has almost nothing todo
 except swapping some pointers.

I figured that

___
ast-developers mailing list
ast-developers@research.att.com
https://mailman.research.att.com/mailman/listinfo/ast-developers


Re: [ast-developers] |*at()|-emulation, 3rd prototype...

2012-09-01 Thread Irek Szczesniak
On Tue, Aug 28, 2012 at 4:44 AM, Roland Mainz roland.ma...@nrubsig.org wrote:
 Attached (as astksh_fs_at_emulation003.diff.txt) is the 3rd
 prototype patch which adds a POSIX |*at()|-emulation (e.g.
 |openat()|co.) to libast. This is mainly the same patch as the
 astksh_fs_at_emulation002.diff.txt with minor fixes so that all
 three compile modes { native OS |*at()|, |*at()|-emulation using
 /dev/fd/, |*at()|-emulation using |fchdir()| } work properly

 Notes:
 - Tested with ast-@(ksh|open).2012-08-24
 - The code will currently only work on 64bit plattforms since it
 assumes |stat()|co. == |stat64()|co.
 - The emulation #defines calls like |stat()|co. to |fstatat()|co.
 and then calls the matching |ast_stat()|co. emulation. This was done
 to test the emulation and emulation overhead... to use a platform's
 native |*at()|-calls remove |#define AST_TEST_AT_EMULATION 1| from
 src/lib/libast/features/fcntl.c
 - Currently |openat()| itself is not emulated... I didn't find a
 usefull way to #define |openat()| to |ast_openat()| with CPP using the
 full arguments in the CPP macro (the problem is that |open()| and
 |openat()| are varargs functions... they may take a |mode_t|
 argument... or not). Any tips how to fix that very welcome
 - |utimesat()| emulation is now included... but not used (yet)
 - some applications _may_ fail if they do something like #define
 fchdir() or #define chdir() ... these functions or cpp macros MUST
 redirect to |ast_fchdir()|, |ast_chdir()| and |ast_close()| since the
 |*at()|-emulation remembers the last fd used to do some
 optimisations. If
 |ast_fchdir()|, |ast_chdir()| and |ast_close()| are bypassed then this
 remembered fd is likely stale and might cause subtle failures.
 This is not a bug.
 - libshell uses the libshell's |Shell_t-pwdfd| directory handle via
 |#define AST_AT_GET_FDCWD (shp-pwdfd)| in
 src/cmd/ksh93/include/defs.h ... note that this had to be overridden
 in src/cmd/ksh93/bltins/test.c, src/cmd/ksh93/edit/history.c,
 src/cmd/ksh93/sh/io.c and src/cmd/ksh93/sh/nvtype.c because there are
 functions which use file APIs without having a variable |shp| pointing
 to the |Shell_t|

 ToDo:
 - Add proper headers instead of stuffing everything into fcntl.c
 - Code cleanup
 - Add |readlinkat()| and |symlinkat()| (yeah yeah, I missed that...
 sorry... ;-( )
 - Add emulation mode selection: Either use native |*at()| API or {
 /dev/fd/, /proc/self/fd/ or use |fchdir()| } (in that order)
 - Feedback from Glenn whether he likes it
 - Fix src/cmd/ksh93/ to have a |shp| in every function which uses file APIs

I will have a closer look at the emulation next week. IMO it'll be
nice if you could provide the missing emulations (symlinkat,
readlinkat) and make sure that you define your own AT_FDCWD if the
system doesn't have one. We may want to talk about the license too
(preferably one which is compatible to Eclipse1.0, 2-clause BSD and
GPL/LGPL), because the code is very useful for many other projects out
there. The only other emulation-like API for f*at() is in GNU
coreutils and their code is neither very clean nor has it a suitable
license (GPL3.0) for anything except GPL3.0.

Irek
___
ast-developers mailing list
ast-developers@research.att.com
https://mailman.research.att.com/mailman/listinfo/ast-developers


Re: [ast-developers] |*at()|-emulation, 3rd prototype...

2012-09-01 Thread Glenn Fowler

is there any rationale for there being no *at() variant for

chdir()
truncate()

___
ast-developers mailing list
ast-developers@research.att.com
https://mailman.research.att.com/mailman/listinfo/ast-developers