linux - Is it possible to use "/" in a filename? -


i know not should ever done, there way use slash character separates directories within filename in linux?

the answer can't, unless filesystem has bug. here's why:

there system call renaming file defined in fs/namei.c called renameat:

syscall_define4(renameat, int, olddfd, const char __user *, oldname,                 int, newdfd, const char __user *, newname) 

when system call gets invoked, path lookup (do_path_lookup) on name. keep tracing this, , link_path_walk has this:

static int link_path_walk(const char *name, struct nameidata *nd) {        struct path next;        int err;        unsigned int lookup_flags = nd->flags;         while (*name=='/')               name++;        if (!*name)               return 0; ... 

this code applies file system. what's mean? means if try pass parameter actual '/' character name of file using traditional means, not want. there no way escape character. if filesystem "supports" this, it's because either:

  • use unicode character or looks slash isn't.
  • they have bug.

furthermore, if did go in , edit bytes add slash character file name, bad things happen. that's because never refer file name :( since anytime did, linux assume referring nonexistent directory. using 'rm *' technique not work either, since bash expands filename. rm -rf wouldn't work, since simple strace reveals how things go on under hood (shortened):

$ ls testdir myfile2 out $ strace -vf rm -rf testdir ... unlinkat(3, "myfile2", 0)               = 0 unlinkat(3, "out", 0)                   = 0 fcntl(3, f_getfd)                       = 0x1 (flags fd_cloexec) close(3)                                = 0 unlinkat(at_fdcwd, "testdir", at_removedir) = 0 ... 

notice these calls unlinkat fail because need refer files name.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -