2015-01-23 19:54:44 +00:00
|
|
|
.\" Copyright (C) 2014, Heinrich Schuchardt <xypron.glpk@gmx.de>
|
|
|
|
.\"
|
|
|
|
.\" %%%LICENSE_START(VERBATIM)
|
|
|
|
.\" Permission is granted to make and distribute verbatim copies of this
|
|
|
|
.\" manual provided the copyright notice and this permission notice are
|
|
|
|
.\" preserved on all copies.
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to copy and distribute modified versions of
|
|
|
|
.\" this manual under the conditions for verbatim copying, provided that
|
|
|
|
.\" the entire resulting derived work is distributed under the terms of
|
|
|
|
.\" a permission notice identical to this one.
|
|
|
|
.\"
|
|
|
|
.\" Since the Linux kernel and libraries are constantly changing, this
|
2015-02-03 09:19:22 +00:00
|
|
|
.\" manual page may be incorrect or out-of-date. The author(s) assume
|
|
|
|
.\" no responsibility for errors or omissions, or for damages resulting
|
|
|
|
.\" from the use of the information contained herein. The author(s) may
|
|
|
|
.\" not have taken the same level of care in the production of this
|
|
|
|
.\" manual, which is licensed free of charge, as they might when working
|
2015-01-23 19:54:44 +00:00
|
|
|
.\" professionally.
|
|
|
|
.\"
|
|
|
|
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
|
|
.\" the source, must acknowledge the copyright and authors of this work.
|
|
|
|
.\" %%%LICENSE_END
|
memusage.1, memusagestat.1, pldd.1, accept.2, adjtimex.2, arch_prctl.2, bdflush.2, bpf.2, close.2, epoll_ctl.2, epoll_wait.2, execve.2, execveat.2, fanotify_init.2, fanotify_mark.2, fcntl.2, fsync.2, get_kernel_syms.2, getdomainname.2, getgroups.2, gethostname.2, getrandom.2, getrlimit.2, getrusage.2, getsid.2, getunwind.2, io_getevents.2, ioctl_fat.2, kexec_load.2, killpg.2, listxattr.2, lseek.2, madvise.2, memfd_create.2, mknod.2, mlock.2, modify_ldt.2, msgctl.2, msgget.2, msgop.2, readlink.2, readv.2, reboot.2, recvmmsg.2, rename.2, request_key.2, restart_syscall.2, sched_setaffinity.2, sched_setattr.2, sched_setparam.2, seccomp.2, select_tut.2, semctl.2, semget.2, semop.2, set_thread_area.2, seteuid.2, setgid.2, setpgid.2, setresuid.2, setreuid.2, setsid.2, setuid.2, shmctl.2, shmget.2, shmop.2, sigaction.2, sigprocmask.2, stat.2, symlink.2, syscall.2, sysctl.2, unlink.2, bindresvport.3, byteorder.3, dlopen.3, endian.3, error.3, ffs.3, fmemopen.3, getcwd.3, getlogin.3, getnetent.3, getprotoent.3, getservent.3, getumask.3, getutent.3, glob.3, isalpha.3, lio_listio.3, login.3, mbsinit.3, mbstowcs.3, mbtowc.3, mkstemp.3, nextup.3, ntp_gettime.3, posix_fallocate.3, posix_spawn.3, pthread_join.3, pthread_rwlockattr_setkind_np.3, random.3, rcmd.3, realpath.3, resolver.3, setjmp.3, setnetgrent.3, sigvec.3, strerror.3, strverscmp.3, system.3, toupper.3, towlower.3, towupper.3, wcstombs.3, wordexp.3, cciss.4, loop.4, mouse.4, random.4, core.5, group.5, hosts.5, resolv.conf.5, ascii.7, environ.7, epoll.7, glob.7, ip.7, mq_overview.7, packet.7, pipe.7, raw.7, sched.7, signal.7, socket.7, symlink.7, ld.so.8, sln.8: tstamp
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2016-10-08 10:53:47 +00:00
|
|
|
.TH IOCTL-FAT 2 2016-10-08 "Linux" "Linux Programmer's Manual"
|
iconv.1, localedef.1, access.2, execveat.2, fanotify_init.2, futex.2, ioctl_fat.2, mount.2, ftw.3, sd.4, tty_ioctl.4, fanotify.7, futex.7, posixoptions.7, iconvconfig.8: srcfix: Remove useless quotes from .SS and .SH sections
Signed-off-by: Stéphane Aulery <saulery@free.fr>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2015-03-08 02:03:52 +00:00
|
|
|
.SH NAME
|
2015-02-03 07:47:01 +00:00
|
|
|
ioctl_fat \- manipulating the FAT filesystem
|
2015-01-23 19:54:44 +00:00
|
|
|
.SH SYNOPSIS
|
|
|
|
.nf
|
|
|
|
.B #include <linux/msdos_fs.h>
|
|
|
|
.br
|
|
|
|
.B #include <sys/ioctl.h>
|
|
|
|
.sp
|
2015-02-03 07:47:01 +00:00
|
|
|
.BI "int ioctl(int " fd ", FAT_IOCTL_GET_ATTRIBUTES, uint32_t * " attr );
|
|
|
|
.BI "int ioctl(int " fd ", FAT_IOCTL_SET_ATTRIBUTES, uint32_t * " attr );
|
|
|
|
.BI "int ioctl(int " fd ", FAT_IOCTL_GET_VOLUME_ID, uint32_t * " id );
|
2015-01-23 19:54:44 +00:00
|
|
|
.BI "int ioctl(int " fd ", VFAT_IOCTL_READDIR_BOTH,
|
2015-02-03 07:47:01 +00:00
|
|
|
.BI " struct __fat_dirent[2] " entry );
|
2015-01-23 19:54:44 +00:00
|
|
|
.BI "int ioctl(int " fd ", VFAT_IOCTL_READDIR_SHORT,
|
2015-02-03 07:47:01 +00:00
|
|
|
.BI " struct __fat_dirent[2] " entry );
|
2015-01-23 19:54:44 +00:00
|
|
|
.SH DESCRIPTION
|
|
|
|
The
|
|
|
|
.BR ioctl (2)
|
2015-02-03 07:47:01 +00:00
|
|
|
system call can be used to read and write metadata of FAT filesystems that
|
2015-01-23 19:54:44 +00:00
|
|
|
are not accessible using other system calls.
|
|
|
|
.SS Reading and setting file attributes
|
|
|
|
Files and directories in the FAT filesystem possess an attribute bit mask that
|
|
|
|
can be read with
|
|
|
|
.B FAT_IOCTL_GET_ATTRIBUTES
|
|
|
|
and written with
|
|
|
|
.BR FAT_IOCTL_SET_ATTRIBUTES .
|
|
|
|
.PP
|
|
|
|
The
|
|
|
|
.I fd
|
2015-02-03 07:47:01 +00:00
|
|
|
argument contains a file descriptor for a file or directory.
|
2015-01-23 19:54:44 +00:00
|
|
|
It is sufficient to create the file descriptor by calling
|
|
|
|
.BR open (2)
|
|
|
|
with the
|
|
|
|
.B O_RDONLY
|
|
|
|
flag.
|
|
|
|
.PP
|
|
|
|
The
|
|
|
|
.I attr
|
2015-02-03 07:47:01 +00:00
|
|
|
argument contains a pointer to a bit mask.
|
|
|
|
The bits of the bit mask are:
|
2015-01-23 19:54:44 +00:00
|
|
|
.TP
|
|
|
|
.B ATTR_RO
|
|
|
|
This bit specifies that the file or directory is read-only.
|
|
|
|
.TP
|
|
|
|
.B ATTR_HIDDEN
|
|
|
|
This bit specifies that the file or directory is hidden.
|
|
|
|
.TP
|
|
|
|
.B ATTR_SYS
|
|
|
|
This bit specifies that the file is a system file.
|
|
|
|
.TP
|
|
|
|
.B ATTR_VOLUME
|
|
|
|
This bit specifies that the file is a volume label.
|
|
|
|
This attribute is read-only.
|
|
|
|
.TP
|
|
|
|
.B ATTR_DIR
|
|
|
|
This bit specifies that this is a directory.
|
|
|
|
This attribute is read-only.
|
|
|
|
.TP
|
|
|
|
.B ATTR_ARCH
|
|
|
|
This bit indicates that this file or directory should be archived.
|
|
|
|
It is set when a file is created or modified.
|
|
|
|
It is reset by an archiving system.
|
|
|
|
.PP
|
|
|
|
The zero value
|
|
|
|
.B ATTR_NONE
|
|
|
|
can be used to indicate that no attribute bit is set.
|
|
|
|
.SS Reading the volume label
|
2015-02-03 07:47:01 +00:00
|
|
|
FAT filesystems are identified by a volume label.
|
2015-01-23 19:54:44 +00:00
|
|
|
The volume label can be read with
|
|
|
|
.BR FAT_IOCTL_GET_VOLUME_ID .
|
|
|
|
.PP
|
|
|
|
The
|
|
|
|
.I fd
|
|
|
|
argument can be a file descriptor for any file or directory of the
|
|
|
|
filesystem.
|
|
|
|
It is sufficient to create the file descriptor by calling
|
|
|
|
.BR open (2)
|
|
|
|
with the
|
|
|
|
.B O_RDONLY
|
|
|
|
flag.
|
|
|
|
.PP
|
|
|
|
The
|
|
|
|
.I id
|
|
|
|
argument is a pointer to the field that will be filled with the volume ID.
|
|
|
|
Typically the volume label is displayed to the user as a group of two
|
2015-02-03 07:47:01 +00:00
|
|
|
16-bit fields:
|
2015-01-23 19:54:44 +00:00
|
|
|
.PP
|
|
|
|
.in +4n
|
|
|
|
.nf
|
2016-05-07 08:42:52 +00:00
|
|
|
printf("Volume ID %04x-%04x\\n", id >> 16, id & 0xFFFF);
|
2015-01-23 19:54:44 +00:00
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
.SS Reading short file names of a directory
|
|
|
|
A file or directory on a FAT filesystem always has a short filename
|
|
|
|
consisting of up to 8 capital letters, optionally followed by a period
|
|
|
|
and up to 3 capital letters for the file extension.
|
|
|
|
If the actual filename does not fit into this scheme, it is stored
|
|
|
|
as a long filename of up to 255 UTF-16 characters.
|
|
|
|
.PP
|
|
|
|
The short filenames in a directory can be read with
|
|
|
|
.BR VFAT_IOCTL_READDIR_SHORT .
|
|
|
|
.B VFAT_IOCTL_READDIR_BOTH
|
|
|
|
reads both the short and the long filenames.
|
|
|
|
.PP
|
|
|
|
The
|
|
|
|
.I fd
|
|
|
|
argument must be a file descriptor for a directory.
|
|
|
|
It is sufficient to create the file descriptor by calling
|
|
|
|
.BR open (2)
|
|
|
|
with the
|
|
|
|
.B O_RDONLY
|
|
|
|
flag.
|
2015-02-03 07:47:01 +00:00
|
|
|
The file descriptor can be used only once to iterate over the directory
|
2015-01-23 19:54:44 +00:00
|
|
|
entries by calling
|
|
|
|
.BR ioctl (2)
|
|
|
|
repeatedly.
|
|
|
|
.PP
|
|
|
|
The
|
|
|
|
.I entry
|
2015-02-03 07:47:01 +00:00
|
|
|
argument is a two-element array of the following structures:
|
2015-01-23 19:54:44 +00:00
|
|
|
|
|
|
|
.in +4n
|
|
|
|
.nf
|
|
|
|
struct __fat_dirent {
|
|
|
|
long d_ino;
|
|
|
|
__kernel_off_t d_off;
|
|
|
|
uint32_t short d_reclen;
|
|
|
|
char d_name[256];
|
|
|
|
};
|
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
.PP
|
|
|
|
The first entry in the array is for the short filename.
|
|
|
|
The second entry is for the long filename.
|
|
|
|
.PP
|
2015-02-09 08:11:29 +00:00
|
|
|
The
|
2015-02-06 22:10:38 +00:00
|
|
|
.I d_ino
|
|
|
|
and
|
|
|
|
.I d_off
|
2015-02-09 08:11:29 +00:00
|
|
|
fields are filled only for long filenames.
|
|
|
|
The
|
2015-02-06 22:10:38 +00:00
|
|
|
.I d_ino
|
2015-02-09 08:11:29 +00:00
|
|
|
field holds the inode number of the directory.
|
|
|
|
The
|
2015-02-06 22:10:38 +00:00
|
|
|
.I d_off
|
2015-02-09 08:11:29 +00:00
|
|
|
field holds the offset of the file entry in the directory.
|
2015-02-06 22:10:38 +00:00
|
|
|
As these values are not available for short filenames, the user code should
|
|
|
|
simply ignore them.
|
|
|
|
.PP
|
2015-02-03 07:47:01 +00:00
|
|
|
The field
|
2015-01-23 19:54:44 +00:00
|
|
|
.I d_reclen
|
2015-02-03 07:47:01 +00:00
|
|
|
contains the length of the filename in the field
|
2015-01-23 19:54:44 +00:00
|
|
|
.IR d_name .
|
2015-02-09 08:11:29 +00:00
|
|
|
To keep backward compatibility, a length of 0 for the short filename signals
|
2015-02-06 22:10:38 +00:00
|
|
|
that the end of the directory has been reached.
|
2015-02-09 08:11:29 +00:00
|
|
|
However, the preferred method for detecting the end of the directory
|
|
|
|
is to test the
|
2016-08-07 19:45:32 +00:00
|
|
|
.BR ioctl (2)
|
2015-02-09 08:11:29 +00:00
|
|
|
return value.
|
2015-02-06 22:10:38 +00:00
|
|
|
If no long filename exists, field
|
|
|
|
.I d_reclen
|
|
|
|
is set to 0 and
|
|
|
|
.I d_name
|
|
|
|
is a character string of length 0 for the long filename.
|
2015-01-23 19:54:44 +00:00
|
|
|
.SH RETURN VALUE
|
2015-02-03 07:47:01 +00:00
|
|
|
On error, \-1 is returned, and
|
|
|
|
.I errno
|
|
|
|
is set to indicate the error.
|
2015-02-06 22:10:38 +00:00
|
|
|
.PP
|
|
|
|
For
|
|
|
|
.B VFAT_IOCTL_READDIR_BOTH
|
|
|
|
and
|
|
|
|
.B VFAT_IOCTL_READDIR_SHORT
|
|
|
|
a return value of 1 signals that a new directory entry has been read and
|
|
|
|
a return value of 0 signals that the end of the directory has been reached.
|
2015-01-23 19:54:44 +00:00
|
|
|
.SH ERRORS
|
|
|
|
.TP
|
2015-02-06 22:10:38 +00:00
|
|
|
.B ENOENT
|
2015-01-23 19:54:44 +00:00
|
|
|
This error is returned by
|
2015-02-06 22:10:38 +00:00
|
|
|
.B VFAT_IOCTL_READDIR_BOTH
|
|
|
|
and
|
2015-01-23 19:54:44 +00:00
|
|
|
.B VFAT_IOCTL_READDIR_SHORT
|
2015-02-06 22:10:38 +00:00
|
|
|
if the file descriptor
|
|
|
|
.I fd
|
|
|
|
refers to a removed, but still open directory.
|
|
|
|
.TP
|
|
|
|
.B ENOTDIR
|
|
|
|
This error is returned by
|
|
|
|
.B VFAT_IOCTL_READDIR_BOTH
|
2015-01-23 19:54:44 +00:00
|
|
|
and
|
|
|
|
.B VFAT_IOCTL_READDIR_SHORT
|
2015-02-06 22:10:38 +00:00
|
|
|
if the file descriptor
|
2015-02-03 07:47:01 +00:00
|
|
|
.I fd
|
|
|
|
does not refer to a directory.
|
2015-01-23 19:54:44 +00:00
|
|
|
.TP
|
|
|
|
.B ENOTTY
|
2015-02-03 07:47:01 +00:00
|
|
|
The file descriptor
|
|
|
|
.I fd
|
|
|
|
does not refer to an object in a FAT filesystem.
|
2015-01-23 19:54:44 +00:00
|
|
|
.PP
|
2015-02-03 07:47:01 +00:00
|
|
|
For further error values, see
|
2015-01-23 19:54:44 +00:00
|
|
|
.BR ioctl (2).
|
|
|
|
.SH VERSIONS
|
2015-02-03 07:52:35 +00:00
|
|
|
.BR VFAT_IOCTL_READDIR_BOTH
|
|
|
|
and
|
|
|
|
.B VFAT_IOCTL_READDIR_SHORT
|
|
|
|
first appeared in Linux 2.0.
|
|
|
|
|
|
|
|
.BR FAT_IOCTL_GET_ATTRIBUTES
|
|
|
|
and
|
|
|
|
.BR FAT_IOCTL_SET_ATTRIBUTES
|
|
|
|
first appeared
|
|
|
|
.\" just before we got Git history
|
|
|
|
in Linux 2.6.12.
|
|
|
|
|
2015-01-23 19:54:44 +00:00
|
|
|
.B FAT_IOCTL_GET_VOLUME_ID
|
2015-02-03 07:47:01 +00:00
|
|
|
was introduced in version 3.11
|
|
|
|
.\" commit 6e5b93ee55d401f1619092fb675b57c28c9ed7ec
|
|
|
|
of the Linux kernel.
|
iconv.1, localedef.1, access.2, execveat.2, fanotify_init.2, futex.2, ioctl_fat.2, mount.2, ftw.3, sd.4, tty_ioctl.4, fanotify.7, futex.7, posixoptions.7, iconvconfig.8: srcfix: Remove useless quotes from .SS and .SH sections
Signed-off-by: Stéphane Aulery <saulery@free.fr>
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2015-03-08 02:03:52 +00:00
|
|
|
.SH CONFORMING TO
|
2015-01-23 19:54:44 +00:00
|
|
|
This API is Linux-specific.
|
|
|
|
.SH EXAMPLE
|
|
|
|
.SS Toggling the archive flag
|
2015-02-03 07:47:01 +00:00
|
|
|
The following program demonstrates the usage of
|
2016-08-07 19:45:32 +00:00
|
|
|
.BR ioctl (2)
|
2015-02-03 07:47:01 +00:00
|
|
|
to manipulate file attributes.
|
|
|
|
The program reads and displays the archive attribute of a file.
|
|
|
|
After inverting the value of the attribute,
|
|
|
|
the program reads and displays the attribute again.
|
2015-01-23 19:54:44 +00:00
|
|
|
.PP
|
|
|
|
The following was recorded when applying the program for the file
|
2015-02-03 07:47:01 +00:00
|
|
|
.IR /mnt/user/foo :
|
|
|
|
|
2015-01-23 19:54:44 +00:00
|
|
|
.in +4n
|
|
|
|
.nf
|
2015-02-03 08:04:18 +00:00
|
|
|
# ./toggle_fat_archive_flag /mnt/user/foo
|
2015-01-23 19:54:44 +00:00
|
|
|
Archive flag is set
|
|
|
|
Toggling archive flag
|
|
|
|
Archive flag is not set
|
|
|
|
.fi
|
|
|
|
.in
|
2015-02-03 08:04:18 +00:00
|
|
|
.SS Program source (toggle_fat_archive_flag.c)
|
2015-01-23 19:54:44 +00:00
|
|
|
.in +4n
|
|
|
|
.nf
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <linux/msdos_fs.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read file attributes of a file on a FAT filesystem.
|
|
|
|
* Output the state of the archive flag.
|
|
|
|
*/
|
|
|
|
static uint32_t
|
|
|
|
readattr(int fd)
|
|
|
|
{
|
|
|
|
uint32_t attr;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = ioctl(fd, FAT_IOCTL_GET_ATTRIBUTES, &attr);
|
|
|
|
if (ret == \-1) {
|
|
|
|
perror("ioctl");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (attr & ATTR_ARCH)
|
|
|
|
printf("Archive flag is set\\n");
|
|
|
|
else
|
|
|
|
printf("Archive flag is not set\\n");
|
|
|
|
|
|
|
|
return attr;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
uint32_t attr;
|
|
|
|
int fd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (argc != 2) {
|
|
|
|
printf("Usage: %s FILENAME\\n", argv[0]);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
fd = open(argv[1], O_RDONLY);
|
|
|
|
if (fd == \-1) {
|
|
|
|
perror("open");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read and display the FAT file attributes.
|
|
|
|
*/
|
|
|
|
attr = readattr(fd);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Invert archive attribute.
|
|
|
|
*/
|
|
|
|
printf("Toggling archive flag\\n");
|
|
|
|
attr ^= ATTR_ARCH;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write the changed FAT file attributes.
|
|
|
|
*/
|
|
|
|
ret = ioctl(fd, FAT_IOCTL_SET_ATTRIBUTES, &attr);
|
|
|
|
if (ret == \-1) {
|
|
|
|
perror("ioctl");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read and display the FAT file attributes.
|
|
|
|
*/
|
|
|
|
readattr(fd);
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
2015-02-03 11:14:04 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
2015-01-23 19:54:44 +00:00
|
|
|
}
|
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
.SS Reading the volume label
|
2015-02-03 07:47:01 +00:00
|
|
|
The following program demonstrates the use of
|
|
|
|
.BR ioctl (2)
|
|
|
|
to display the volume label of a FAT filesystem.
|
2015-01-23 19:54:44 +00:00
|
|
|
.PP
|
|
|
|
The following output was recorded when applying the program for
|
|
|
|
directory
|
2015-02-03 07:47:01 +00:00
|
|
|
.IR /mnt/user :
|
|
|
|
|
2015-01-23 19:54:44 +00:00
|
|
|
.in +4n
|
|
|
|
.nf
|
2015-02-03 08:04:18 +00:00
|
|
|
$ ./display_fat_volume_id /mnt/user
|
2015-01-23 19:54:44 +00:00
|
|
|
Volume ID 6443-6241
|
|
|
|
.fi
|
|
|
|
.in
|
2015-02-03 08:04:18 +00:00
|
|
|
.SS Program source (display_fat_volume_id.c)
|
2015-01-23 19:54:44 +00:00
|
|
|
.in +4n
|
|
|
|
.nf
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <linux/msdos_fs.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
uint32_t id;
|
|
|
|
int fd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (argc != 2) {
|
|
|
|
printf("Usage: %s FILENAME\\n", argv[0]);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
fd = open(argv[1], O_RDONLY);
|
|
|
|
if (fd == \-1) {
|
|
|
|
perror("open");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read volume ID.
|
|
|
|
*/
|
|
|
|
ret = ioctl(fd, FAT_IOCTL_GET_VOLUME_ID, &id);
|
|
|
|
if (ret == \-1) {
|
|
|
|
perror("ioctl");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Format the output as two groups of 16 bits each.
|
|
|
|
*/
|
2016-05-07 08:42:52 +00:00
|
|
|
printf("Volume ID %04x\-%04x\\n", id >> 16, id & 0xFFFF);
|
2015-01-23 19:54:44 +00:00
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
2015-02-03 11:14:04 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
2015-01-23 19:54:44 +00:00
|
|
|
}
|
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
.SS Listing a directory
|
2015-02-03 07:47:01 +00:00
|
|
|
The following program demonstrates the use of
|
|
|
|
.BR ioctl (2)
|
|
|
|
to list a directory.
|
2015-01-23 19:54:44 +00:00
|
|
|
.PP
|
2015-02-03 07:47:01 +00:00
|
|
|
The following was recorded when applying the program to the directory
|
|
|
|
.IR /mnt/user :
|
|
|
|
|
2015-01-23 19:54:44 +00:00
|
|
|
.in +4n
|
|
|
|
.nf
|
|
|
|
$ ./fat_dir /mnt/user
|
|
|
|
\[char46] -> ''
|
|
|
|
\[char46]. -> ''
|
|
|
|
ALONGF~1.TXT -> 'a long filename.txt'
|
|
|
|
UPPER.TXT -> ''
|
|
|
|
LOWER.TXT -> 'lower.txt'
|
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
.SS Program source
|
|
|
|
.in +4n
|
|
|
|
.nf
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <linux/msdos_fs.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct __fat_dirent entry[2];
|
|
|
|
int fd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (argc != 2) {
|
|
|
|
printf("Usage: %s DIRECTORY\\n", argv[0]);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open file descriptor for the directory.
|
|
|
|
*/
|
|
|
|
fd = open(argv[1], O_RDONLY | O_DIRECTORY);
|
|
|
|
if (fd == \-1) {
|
|
|
|
perror("open");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read next directory entry.
|
|
|
|
*/
|
|
|
|
ret = ioctl( fd, VFAT_IOCTL_READDIR_BOTH, entry);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If an error occurs, the return value is \-1.
|
2015-02-06 22:10:38 +00:00
|
|
|
* If the end of the directory list has been reached,
|
|
|
|
* the return value is 0.
|
|
|
|
* For backward compatibility the end of the directory
|
|
|
|
* list is also signaled by d_reclen == 0.
|
2015-01-23 19:54:44 +00:00
|
|
|
*/
|
2015-02-06 22:10:38 +00:00
|
|
|
if (ret < 1)
|
2015-01-23 19:54:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write both the short name and the long name.
|
|
|
|
*/
|
|
|
|
printf("%s \-> '%s'\\n", entry[0].d_name, entry[1].d_name);
|
|
|
|
}
|
2015-02-03 07:47:01 +00:00
|
|
|
|
2015-01-23 19:54:44 +00:00
|
|
|
if (ret == \-1) {
|
|
|
|
perror("VFAT_IOCTL_READDIR_BOTH");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Close the file descriptor.
|
|
|
|
*/
|
|
|
|
close(fd);
|
|
|
|
|
2015-02-03 11:14:04 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
2015-01-23 19:54:44 +00:00
|
|
|
}
|
|
|
|
.fi
|
|
|
|
.in
|
|
|
|
.SH SEE ALSO
|
|
|
|
.BR ioctl (2)
|