Verzeichnis umbenennen



  • Kann man dann davon ausgehen, dass im Prinzip ein (gemountetes) Laufwerk auch mit einem Filedeskriptor angesprochen werden kann?
    Wobei sich mir dann gleich die Frage aufdrängt, wie man ein Laufwerk mittels Code(C/C++) mountet. Aber da findet man vielleicht auch was mit dr Suche oder FAQ.
    Danke jedenfalls für die Info.
    Tschau arni



  • arni schrieb:

    Kann man dann davon ausgehen, dass im Prinzip ein (gemountetes) Laufwerk auch mit einem Filedeskriptor angesprochen werden kann?

    Ein Laufwerk selbst ist auch nur eine spezielle Art von Datei unterhalb von /dev. Zum Beispiel eine zweite Festplatte, die als /dev/hdb1 (erste primäre Partition auf dem Master des zweiten IDE Kanal) angesprochen werden kann und die du auf einen normalen Filedescriptor (= Mountpoint) z.B. nach /mnt/data mountest.

    arni schrieb:

    Wobei sich mir dann gleich die Frage aufdrängt, wie man ein Laufwerk mittels Code(C/C++) mountet.

    siehe Manpages mount(2) und umount(2)

    MOUNT(2)		   Linux Programmer's Manual		      MOUNT(2)
    
    NAME
           mount, umount - mount and unmount filesystems.
    
    SYNOPSIS
           #include <sys/mount.h>
    
           int  mount(const  char  *specialfile,  const  char * dir , const char *
           filesystemtype, unsigned long mountflags , const void * data);
    
           int umount(const char *dir);
    
    DESCRIPTION
           mount attaches the filesystem specified by specialfile (which is  often
           a device name) to the directory specified by dir.
    
           umount  removes	the  attachment of the (topmost) filesystem mounted on
           dir.
    
           Only the super-user may mount and unmount filesystems.
    
           The filesystemtype argument may	take  one  of  the  values  listed  in
           /proc/filesystems   (like  "minix",  "ext2",  "msdos",  "proc",	"nfs",
           "iso9660" etc.).
    
           The mountflags argument may have the magic number 0xC0ED in the top  16
           bits, and various mount flags (as defined in <linux/fs.h> for libc4 and
           libc5 and in <sys/mount.h> for glibc2) in the low order 16 bits:
    
           #define MS_RDONLY	1 /* mount read-only */
           #define MS_NOSUID	2 /* ignore suid and sgid bits */
           #define MS_NODEV 	4 /* no access to device special files */
           #define MS_NOEXEC	8 /* no program execution */
           #define MS_SYNCHRONOUS  16 /* writes are synced at once */
           #define MS_REMOUNT      32 /* alter flags of a mounted fs */
           #define MS_MANDLOCK     64 /* allow mandatory locks */
           #define MS_NOATIME    1024 /* do not update access times */
           #define MS_NODIRATIME 2048 /* do not update dir access times */
           #define MS_BIND	     4096 /* bind subtree elsewhere */
    
           The data argument is interpreted by the different file systems.
    
    RETURN VALUE
           On success, zero is returned.  On error, -1 is returned, and  errno  is
           set appropriately.
    
    ERRORS
           The  error  values  given below result from filesystem type independent
           errors. Each filesystem type may have its own special  errors  and  its
           own special behavior.  See the kernel source code for details.
    
           EPERM  The user is not the super-user.
    
           ENODEV Filesystemtype not configured in the kernel.
    
           ENOTBLK
    	      Specialfile is not a block device (if a device was required).
    
           EBUSY  Specialfile is already mounted. Or, it cannot be remounted read-
    	      only, because it still holds files open  for  writing.   Or,  it
    	      cannot  be  mounted  on dir because dir is still busy (it is the
    	      working directory of some  task,	the  mount  point  of  another
    	      device, has open files, etc.).
    
           EINVAL Specialfile  had	an  invalid  superblock.   Or,	a  remount was
    	      attempted, while specialfile was not  already  mounted  on  dir.
    	      Or, an umount was attempted, while dir was not a mount point.
    
           EFAULT One  of  the  pointer  arguments points outside the user address
    	      space.
    
           ENOMEM The kernel could not allocate a free page to copy  filenames  or
    	      data into.
    
           ENAMETOOLONG
    	      A pathname was longer than MAXPATHLEN.
    
           ENOENT A pathname was empty or had a nonexistent component.
    
           ENOTDIR
    	      The second argument, or a prefix of the first argument, is not a
    	      directory.
    
           EACCES A component of a path was not searchable.
    	      Or, mounting a read-only filesystem was attempted without giving
    	      the MS_RDONLY flag.
    	      Or,  the	block  device  Specialfile  is located on a filesystem
    	      mounted with the MS_NODEV option.
    
           ENXIO  The major number of the  block  device  specialfile  is  out  of
    	      range.
    
           EMFILE (In case no block device is required:) Table of dummy devices is
    	      full.
    
    CONFORMING TO
           These functions are Linux-specific and should not be used  in  programs
           intended to be portable.
    
    HISTORY
           The  original  umount  function	was called as umount(device) and would
           return ENOTBLK when called with something other than  a	block  device.
           In  Linux  0.98p4  a  call  umount(dir)	was added, in order to support
           anonymous devices.  In Linux 2.3.99-pre7 the  call  umount(device)  was
           removed,  leaving only umount(dir) (since now devices can be mounted in
           more than one place, so specifying the device does not suffice).
    
           The original MS_SYNC flag was renamed MS_SYNCHRONOUS in 1.1.69  when  a
           different MS_SYNC was added to <mman.h>.
    
    SEE ALSO
           mount(8), umount(8)
    

    Als Ergänzung noch die gleiche Manpage aus BSD:

    MOUNT(2)		  FreeBSD System Calls Manual		      MOUNT(2)
    
    NAME
         mount, unmount - mount or dismount a file system
    
    LIBRARY
         Standard C Library (libc, -lc)
    
    SYNOPSIS
         #include <sys/param.h>
         #include <sys/mount.h>
    
         int
         mount(const char *type, const char *dir, int flags, void *data);
    
         int
         unmount(const char *dir, int flags);
    
    DESCRIPTION
         The mount() function grafts a file system object onto the system file
         tree at the point dir.  The argument data describes the file system
         object to be mounted.  The argument type tells the kernel how to inter-
         pret data (See type below).  The contents of the file system become
         available through the new mount point dir.  Any files in dir at the time
         of a successful mount are swept under the carpet so to speak, and are
         unavailable until the file system is unmounted.
    
         The following flags may be specified to suppress default semantics which
         affect file system access.
    
         MNT_RDONLY       The file system should be treated as read-only; Even the
    		      super-user may not write on it.
    
         MNT_NOEXEC       Do not allow files to be executed from the file system.
    
         MNT_NOSUID       Do not honor setuid or setgid bits on files when execut-
    		      ing them.
    
         MNT_NODEV	      Do not interpret special files on the file system.
    
         MNT_UNION	      Union with underlying filesystem instead of obscuring
    		      it.
    
         MNT_SYNCHRONOUS  All I/O to the file system should be done synchronously.
    
         MNT_ASYNC	      All I/O to the file system should be done asyn-
    		      chronously.
    
         MNT_NOCOREDUMP   Do not allow programs to dump core files on the file
    		      system.
    
         MNT_NOATIME      Never update access time in the file system.
    
         MNT_SYMPERM      Recognize the permission of symbolic link when reading
    		      or traversing.
    
         MNT_NODEVMTIME   Never update modification time of device files.
    
         MNT_SOFTDEP      Use soft dependencies.
    
         The flag MNT_UPDATE indicates that the mount command is being applied to
         an already mounted file system.  This allows the mount flags to be
         changed without requiring that the file system be unmounted and
         remounted.  Some file systems may not allow all flags to be changed.  For
         example, most file systems will not allow a change from read-write to
         read-only.
    
         The type argument defines the type of the file system.  The types of file
         systems known to the system are defined in <sys/mount.h>.	data is a
         pointer to a structure that contains the type specific arguments to
         mount.  The currently supported types of file systems and their type spe-
         cific data are:
    
         MOUNT_FFS
    	   struct ufs_args {
    		 char	   *fspec;	       /* block special file to mount */
    		 struct    export_args export; /* network export information */
    	   };
    
         MOUNT_NFS
    	   struct nfs_args {
    		 int		 version;      /* args structure version */
    		 struct sockaddr *addr;        /* file server address */
    		 int		 addrlen;      /* length of address */
    		 int		 sotype;       /* Socket type */
    		 int		 proto;        /* and Protocol */
    		 u_char 	 *fh;	       /* File handle to be mounted */
    		 int		 fhsize;       /* Size, in bytes, of fh */
    		 int		 flags;        /* flags */
    		 int		 wsize;        /* write size in bytes */
    		 int		 rsize;        /* read size in bytes */
    		 int		 readdirsize;  /* readdir size in bytes */
    		 int		 timeo;        /* initial timeout in .1 secs */
    		 int		 retrans;      /* times to retry send */
    		 int		 maxgrouplist; /* Max. size of group list */
    		 int		 readahead;    /* # of blocks to readahead */
    		 int		 leaseterm;    /* Term (sec) of lease */
    		 int		 deadthresh;   /* Retrans threshold */
    		 char		 *hostname;    /* server's name */
    	   };
    
         MOUNT_MFS
    	   struct mfs_args {
    		 char	   *fspec;	       /* name to export for statfs */
    		 struct    export_args export; /* if we can export an MFS */
    		 caddr_t   base;	       /* base of file system in mem */
    		 u_long    size;	       /* size of file system */
    	   };
    
         The unmount() function call disassociates the file system from the speci-
         fied mount point dir.
    
         The flags argument may specify MNT_FORCE to specify that the file system
         should be forcibly unmounted even if files are still active.  Active spe-
         cial devices continue to work, but any further accesses to any other
         active files result in errors even if the file system is later remounted.
    
    RETURN VALUES
         mount() returns the value 0 if the mount was successful, otherwise -1 is
         returned and the variable errno is set to indicate the error.
    
         unmount() returns the value 0 if the unmount succeeded; otherwise -1 is
         returned and the variable errno is set to indicate the error.
    
    ERRORS
         mount() will fail when one of the following occurs:
    
         [EPERM]		The caller is not the super-user.
    
         [ENAMETOOLONG]	A component of a pathname exceeded {NAME_MAX} charac-
    			ters, or an entire path name exceeded {PATH_MAX} char-
    			acters.
    
         [ELOOP]		Too many symbolic links were encountered in translat-
    			ing a pathname.
    
         [ENOENT]		A component of dir does not exist.
    
         [ENOTDIR]		A component of name is not a directory, or a path pre-
    			fix of special is not a directory.
    
         [EBUSY]		Another process currently holds a reference to dir.
    
         [EFAULT]		dir points outside the process's allocated address
    			space.
    
         The following errors can occur for a ufs file system mount:
    
         [ENODEV]		A component of ufs_args fspec does not exist.
    
         [ENOTBLK]		Fspec is not a block device.
    
         [ENXIO]		The major device number of fspec is out of range (this
    			indicates no device driver exists for the associated
    			hardware).
    
         [EBUSY]		Fspec is already mounted.
    
         [EMFILE]		No space remains in the mount table.
    
         [EINVAL]		The super block for the file system had a bad magic
    			number or an out of range block size.
    
         [ENOMEM]		Not enough memory was available to read the cylinder
    			group information for the file system.
    
         [EIO]		An I/O error occurred while reading the super block or
    			cylinder group information.
    
         [EFAULT]		Fspec points outside the process's allocated address
    			space.
    
         The following errors can occur for a nfs file system mount:
    
         [ETIMEDOUT]	Nfs timed out trying to contact the server.
    
         [EFAULT]		Some part of the information described by nfs_args
    			points outside the process's allocated address space.
    
         The following errors can occur for a mfs file system mount:
    
         [EMFILE]		No space remains in the mount table.
    
         [EINVAL]		The super block for the file system had a bad magic
    			number or an out of range block size.
    
         [ENOMEM]		Not enough memory was available to read the cylinder
    			group information for the file system.
    
         [EIO]		A paging error occurred while reading the super block
    			or cylinder group information.
    
         [EFAULT]		Name points outside the process's allocated address
    			space.
    
         unmount() may fail with one of the following errors:
    
         [EPERM]		The caller is not the super-user.
    
         [ENOTDIR]		A component of the path is not a directory.
    
         [ENAMETOOLONG]	A component of a pathname exceeded {NAME_MAX} charac-
    			ters, or an entire path name exceeded {PATH_MAX} char-
    			acters.
    
         [ELOOP]		Too many symbolic links were encountered in translat-
    			ing the pathname.
    
         [EINVAL]		The requested directory is not in the mount table.
    
         [EBUSY]		A process is holding a reference to a file located on
    			the file system.
    
         [EIO]		An I/O error occurred while writing cached file system
    			information.
    
         [EFAULT]		dir points outside the process's allocated address
    			space.
    
         A ufs or mfs mount can also fail if the maximum number of file systems
         are currently mounted.
    
    SEE ALSO
         getfsstat(2), getmntinfo(3), symlink(7), mount(8), sysctl(8), umount(8)
    
    HISTORY
         The mount() and umount() (now unmount()) function calls appeared in
         Version 6 AT&T UNIX.
    
    BUGS
         Some of the error codes need translation to more obvious messages.
    
    FreeBSD 4.7		       November 7, 1999 		   FreeBSD 4.7
    


  • Um Verzeichnisse umzubenennen kann man auch einen Trick verwenden mit dem Befehl "move":

    z.B.:

    Verzeichnis heisst /home/test
    test soll umbenannt werden in "nameneu"

    wechseln in das Verzeichnis /home dann:
    Befehl: mv test nameneu

    lg
    theVOICE



  • theVOICE schrieb:

    Um Verzeichnisse umzubenennen kann man auch einen Trick verwenden mit dem Befehl "move":

    Befehl: mv test nameneu

    Es ging hier eigentlich um C-Programmierung.



  • naja gut du hättest ja auch in deinem c-programm mv verwenden können oder nicht?

    MFG eiskalt



  • Wozu wenn das ganze auch portabel per (std::)rename geht?



  • nman schrieb:

    Wozu wenn das ganze auch portabel per (std::)rename geht?

    ...wobei zu beachten ist, dass ein rename() über Mountgrenzen (z.B. rename("/u01/oracle/tbs_system1.ora", "/u02/oracle/tbs_system2.ora") ) hinweg nicht funktioniert -- ein Aufruf von system() und "mv" hingegen schon.



  • Descartes schrieb:

    ...wobei zu beachten ist, dass ein rename() über Mountgrenzen (z.B. rename("/u01/oracle/tbs_system1.ora", "/u02/oracle/tbs_system2.ora") ) hinweg nicht funktioniert -- ein Aufruf von system() und "mv" hingegen schon.

    Also system() würde ich dafür auf keinen Fall verwenden da der Umweg über die Shell hierbei keinerlei Vorteile haben dürfte und ein exec und mv auch nur dann wenn feststeht dass eine Datei zwischen 2 verschiedenen Dateisystemen verschoben werden muss.
    (Und dass rename sich so verhält kann man sich auch denken, schließlich operiert es (zumindest unter GNU/ Linux) normalerweise im Grunde nur auf Hardlinks, oder?)



  • ist ja wirklich interessant, was man hier so alles lernen kann. Auch weil Vor- und Nachteile der verschiedenen Zugriffe mit angesprochen werden. Hätte noch zwei Fragen zu dem Thread:
    Was sind Mountgrenzen? Ist damit der Zugriff auf verschiedene Hardware gemeint? also auf zwei verschiedene Festplatten zum Beispiel?
    Und:
    Der Zugang zu den Manpages ist mir ja klar, aber wie komme ich an das BSD-Manual heran? Die Quelle habe ich jetzt zum ersten Mal gesehen.
    Danke arni



  • da findest du alle möglichen Manpages

    http://www.freebsd.org/cgi/man.cgi


Anmelden zum Antworten