1999-08-28 01:08:13 +00:00
|
|
|
/* $FreeBSD$ */
|
1998-02-18 09:28:47 +00:00
|
|
|
/* $NetBSD: msdosfs_vnops.c,v 1.68 1998/02/10 14:10:04 mrg Exp $ */
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*-
|
1998-02-18 09:28:47 +00:00
|
|
|
* Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
|
|
|
|
* Copyright (C) 1994, 1995, 1997 TooLs GmbH.
|
1994-09-19 15:41:57 +00:00
|
|
|
* All rights reserved.
|
|
|
|
* Original code by Paul Popelka (paulp@uts.amdahl.com) (see below).
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by TooLs GmbH.
|
|
|
|
* 4. The name of TooLs GmbH may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
2005-01-06 18:10:42 +00:00
|
|
|
/*-
|
1994-09-19 15:41:57 +00:00
|
|
|
* Written by Paul Popelka (paulp@uts.amdahl.com)
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1994-09-19 15:41:57 +00:00
|
|
|
* You can do anything you want with this software, just don't say you wrote
|
|
|
|
* it, and don't remove this notice.
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1994-09-19 15:41:57 +00:00
|
|
|
* This software is provided "as is".
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1994-09-19 15:41:57 +00:00
|
|
|
* The author supplies this software to be publicly redistributed on the
|
|
|
|
* understanding that the author is not responsible for the correct
|
|
|
|
* functioning of this software in any circumstances and is not liable for
|
|
|
|
* any damages caused by this software.
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1994-09-19 15:41:57 +00:00
|
|
|
* October 1992
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2007-08-07 02:28:33 +00:00
|
|
|
#include <sys/bio.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/clock.h>
|
|
|
|
#include <sys/dirent.h>
|
2007-08-07 01:40:27 +00:00
|
|
|
#include <sys/lock.h>
|
2003-12-29 10:12:02 +00:00
|
|
|
#include <sys/lockf.h>
|
2007-08-07 02:28:33 +00:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mount.h>
|
2007-08-07 01:40:27 +00:00
|
|
|
#include <sys/mutex.h>
|
1994-09-19 15:41:57 +00:00
|
|
|
#include <sys/namei.h>
|
2006-11-06 13:42:10 +00:00
|
|
|
#include <sys/priv.h>
|
2007-08-07 02:28:33 +00:00
|
|
|
#include <sys/stat.h>
|
1996-09-03 14:25:27 +00:00
|
|
|
#include <sys/unistd.h>
|
1994-09-19 15:41:57 +00:00
|
|
|
#include <sys/vnode.h>
|
1994-09-27 20:42:59 +00:00
|
|
|
|
|
|
|
#include <vm/vm.h>
|
1995-12-07 12:48:31 +00:00
|
|
|
#include <vm/vm_extern.h>
|
2000-10-04 01:29:17 +00:00
|
|
|
|
2001-05-25 08:14:14 +00:00
|
|
|
#include <fs/msdosfs/bpb.h>
|
|
|
|
#include <fs/msdosfs/direntry.h>
|
|
|
|
#include <fs/msdosfs/denode.h>
|
|
|
|
#include <fs/msdosfs/fat.h>
|
2007-08-07 02:28:33 +00:00
|
|
|
#include <fs/msdosfs/msdosfsmount.h>
|
1995-10-29 15:33:36 +00:00
|
|
|
|
2000-01-02 03:30:42 +00:00
|
|
|
#define DOS_FILESIZE_MAX 0xffffffff
|
|
|
|
|
1995-10-29 15:33:36 +00:00
|
|
|
/*
|
|
|
|
* Prototypes for MSDOSFS vnode operations
|
|
|
|
*/
|
2004-12-01 12:24:41 +00:00
|
|
|
static vop_create_t msdosfs_create;
|
|
|
|
static vop_mknod_t msdosfs_mknod;
|
2005-01-29 16:23:39 +00:00
|
|
|
static vop_open_t msdosfs_open;
|
2004-12-01 12:24:41 +00:00
|
|
|
static vop_close_t msdosfs_close;
|
|
|
|
static vop_access_t msdosfs_access;
|
|
|
|
static vop_getattr_t msdosfs_getattr;
|
|
|
|
static vop_setattr_t msdosfs_setattr;
|
|
|
|
static vop_read_t msdosfs_read;
|
|
|
|
static vop_write_t msdosfs_write;
|
|
|
|
static vop_fsync_t msdosfs_fsync;
|
|
|
|
static vop_remove_t msdosfs_remove;
|
|
|
|
static vop_link_t msdosfs_link;
|
|
|
|
static vop_rename_t msdosfs_rename;
|
|
|
|
static vop_mkdir_t msdosfs_mkdir;
|
|
|
|
static vop_rmdir_t msdosfs_rmdir;
|
|
|
|
static vop_symlink_t msdosfs_symlink;
|
|
|
|
static vop_readdir_t msdosfs_readdir;
|
|
|
|
static vop_bmap_t msdosfs_bmap;
|
|
|
|
static vop_strategy_t msdosfs_strategy;
|
|
|
|
static vop_print_t msdosfs_print;
|
|
|
|
static vop_pathconf_t msdosfs_pathconf;
|
2007-02-15 22:08:35 +00:00
|
|
|
static vop_vptofh_t msdosfs_vptofh;
|
1995-10-29 15:33:36 +00:00
|
|
|
|
1994-09-19 15:41:57 +00:00
|
|
|
/*
|
|
|
|
* Some general notes:
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1994-09-19 15:41:57 +00:00
|
|
|
* In the ufs filesystem the inodes, superblocks, and indirect blocks are
|
|
|
|
* read/written using the vnode for the filesystem. Blocks that represent
|
|
|
|
* the contents of a file are read/written using the vnode for the file
|
|
|
|
* (including directories when they are read/written as files). This
|
|
|
|
* presents problems for the dos filesystem because data that should be in
|
|
|
|
* an inode (if dos had them) resides in the directory itself. Since we
|
|
|
|
* must update directory entries without the benefit of having the vnode
|
|
|
|
* for the directory we must use the vnode for the filesystem. This means
|
|
|
|
* that when a directory is actually read/written (via read, write, or
|
|
|
|
* readdir, or seek) we must use the vnode for the filesystem instead of
|
|
|
|
* the vnode for the directory as would happen in ufs. This is to insure we
|
|
|
|
* retreive the correct block from the buffer cache since the hash value is
|
|
|
|
* based upon the vnode address and the desired block number.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a regular file. On entry the directory to contain the file being
|
|
|
|
* created is locked. We must release before we return. We must also free
|
|
|
|
* the pathname buffer pointed at by cnp->cn_pnbuf, always on error, or
|
|
|
|
* only if the SAVESTART bit in cn_flags is clear on success.
|
|
|
|
*/
|
1995-10-29 15:33:36 +00:00
|
|
|
static int
|
2015-01-09 14:50:08 +00:00
|
|
|
msdosfs_create(struct vop_create_args *ap)
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
|
|
|
struct componentname *cnp = ap->a_cnp;
|
|
|
|
struct denode ndirent;
|
|
|
|
struct denode *dep;
|
|
|
|
struct denode *pdep = VTODE(ap->a_dvp);
|
|
|
|
struct timespec ts;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
#ifdef MSDOSFS_DEBUG
|
1998-02-18 09:28:47 +00:00
|
|
|
printf("msdosfs_create(cnp %p, vap %p\n", cnp, ap->a_vap);
|
1994-09-19 15:41:57 +00:00
|
|
|
#endif
|
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
/*
|
|
|
|
* If this is the root directory and there is no space left we
|
|
|
|
* can't do anything. This is because the root directory can not
|
|
|
|
* change size.
|
|
|
|
*/
|
|
|
|
if (pdep->de_StartCluster == MSDOSFSROOT
|
|
|
|
&& pdep->de_fndoffset >= pdep->de_FileSize) {
|
|
|
|
error = ENOSPC;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
1994-09-19 15:41:57 +00:00
|
|
|
/*
|
|
|
|
* Create a directory entry for the file, then call createde() to
|
|
|
|
* have it installed. NOTE: DOS files are always executable. We
|
|
|
|
* use the absence of the owner write bit to make the file
|
|
|
|
* readonly.
|
|
|
|
*/
|
|
|
|
#ifdef DIAGNOSTIC
|
1998-02-18 09:28:47 +00:00
|
|
|
if ((cnp->cn_flags & HASBUF) == 0)
|
1994-09-19 15:41:57 +00:00
|
|
|
panic("msdosfs_create: no name");
|
|
|
|
#endif
|
|
|
|
bzero(&ndirent, sizeof(ndirent));
|
1998-02-18 09:28:47 +00:00
|
|
|
error = uniqdosname(pdep, cnp, ndirent.de_Name);
|
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
|
Expand the use of stat(2) flags to allow storing some Windows/DOS
and CIFS file attributes as BSD stat(2) flags.
This work is intended to be compatible with ZFS, the Solaris CIFS
server's interaction with ZFS, somewhat compatible with MacOS X,
and of course compatible with Windows.
The Windows attributes that are implemented were chosen based on
the attributes that ZFS already supports.
The summary of the flags is as follows:
UF_SYSTEM: Command line name: "system" or "usystem"
ZFS name: XAT_SYSTEM, ZFS_SYSTEM
Windows: FILE_ATTRIBUTE_SYSTEM
This flag means that the file is used by the
operating system. FreeBSD does not enforce any
special handling when this flag is set.
UF_SPARSE: Command line name: "sparse" or "usparse"
ZFS name: XAT_SPARSE, ZFS_SPARSE
Windows: FILE_ATTRIBUTE_SPARSE_FILE
This flag means that the file is sparse. Although
ZFS may modify this in some situations, there is
not generally any special handling for this flag.
UF_OFFLINE: Command line name: "offline" or "uoffline"
ZFS name: XAT_OFFLINE, ZFS_OFFLINE
Windows: FILE_ATTRIBUTE_OFFLINE
This flag means that the file has been moved to
offline storage. FreeBSD does not have any special
handling for this flag.
UF_REPARSE: Command line name: "reparse" or "ureparse"
ZFS name: XAT_REPARSE, ZFS_REPARSE
Windows: FILE_ATTRIBUTE_REPARSE_POINT
This flag means that the file is a Windows reparse
point. ZFS has special handling code for reparse
points, but we don't currently have the other
supporting infrastructure for them.
UF_HIDDEN: Command line name: "hidden" or "uhidden"
ZFS name: XAT_HIDDEN, ZFS_HIDDEN
Windows: FILE_ATTRIBUTE_HIDDEN
This flag means that the file may be excluded from
a directory listing if the application honors it.
FreeBSD has no special handling for this flag.
The name and bit definition for UF_HIDDEN are
identical to the definition in MacOS X.
UF_READONLY: Command line name: "urdonly", "rdonly", "readonly"
ZFS name: XAT_READONLY, ZFS_READONLY
Windows: FILE_ATTRIBUTE_READONLY
This flag means that the file may not written or
appended, but its attributes may be changed.
ZFS currently enforces this flag, but Illumos
developers have discussed disabling enforcement.
The behavior of this flag is different than MacOS X.
MacOS X uses UF_IMMUTABLE to represent the DOS
readonly permission, but that flag has a stronger
meaning than the semantics of DOS readonly permissions.
UF_ARCHIVE: Command line name: "uarch", "uarchive"
ZFS_NAME: XAT_ARCHIVE, ZFS_ARCHIVE
Windows name: FILE_ATTRIBUTE_ARCHIVE
The UF_ARCHIVED flag means that the file has changed and
needs to be archived. The meaning is same as
the Windows FILE_ATTRIBUTE_ARCHIVE attribute, and
the ZFS XAT_ARCHIVE and ZFS_ARCHIVE attribute.
msdosfs and ZFS have special handling for this flag.
i.e. they will set it when the file changes.
sys/param.h: Bump __FreeBSD_version to 1000047 for the
addition of new stat(2) flags.
chflags.1: Document the new command line flag names
(e.g. "system", "hidden") available to the
user.
ls.1: Reference chflags(1) for a list of file flags
and their meanings.
strtofflags.c: Implement the mapping between the new
command line flag names and new stat(2)
flags.
chflags.2: Document all of the new stat(2) flags, and
explain the intended behavior in a little
more detail. Explain how they map to
Windows file attributes.
Different filesystems behave differently
with respect to flags, so warn the
application developer to take care when
using them.
zfs_vnops.c: Add support for getting and setting the
UF_ARCHIVE, UF_READONLY, UF_SYSTEM, UF_HIDDEN,
UF_REPARSE, UF_OFFLINE, and UF_SPARSE flags.
All of these flags are implemented using
attributes that ZFS already supports, so
the on-disk format has not changed.
ZFS currently doesn't allow setting the
UF_REPARSE flag, and we don't really have
the other infrastructure to support reparse
points.
msdosfs_denode.c,
msdosfs_vnops.c: Add support for getting and setting
UF_HIDDEN, UF_SYSTEM and UF_READONLY
in MSDOSFS.
It supported SF_ARCHIVED, but this has been
changed to be UF_ARCHIVE, which has the same
semantics as the DOS archive attribute instead
of inverse semantics like SF_ARCHIVED.
After discussion with Bruce Evans, change
several things in the msdosfs behavior:
Use UF_READONLY to indicate whether a file
is writeable instead of file permissions, but
don't actually enforce it.
Refuse to change attributes on the root
directory, because it is special in FAT
filesystems, but allow most other attribute
changes on directories.
Don't set the archive attribute on a directory
when its modification time is updated.
Windows and DOS don't set the archive attribute
in that scenario, so we are now bug-for-bug
compatible.
smbfs_node.c,
smbfs_vnops.c: Add support for UF_HIDDEN, UF_SYSTEM,
UF_READONLY and UF_ARCHIVE in SMBFS.
This is similar to changes that Apple has
made in their version of SMBFS (as of
smb-583.8, posted on opensource.apple.com),
but not quite the same.
We map SMB_FA_READONLY to UF_READONLY,
because UF_READONLY is intended to match
the semantics of the DOS readonly flag.
The MacOS X code maps both UF_IMMUTABLE
and SF_IMMUTABLE to SMB_FA_READONLY, but
the immutable flags have stronger meaning
than the DOS readonly bit.
stat.h: Add definitions for UF_SYSTEM, UF_SPARSE,
UF_OFFLINE, UF_REPARSE, UF_ARCHIVE, UF_READONLY
and UF_HIDDEN.
The definition of UF_HIDDEN is the same as
the MacOS X definition.
Add commented-out definitions of
UF_COMPRESSED and UF_TRACKED. They are
defined in MacOS X (as of 10.8.2), but we
do not implement them (yet).
ufs_vnops.c: Add support for getting and setting
UF_ARCHIVE, UF_HIDDEN, UF_OFFLINE, UF_READONLY,
UF_REPARSE, UF_SPARSE, and UF_SYSTEM in UFS.
Alphabetize the flags that are supported.
These new flags are only stored, UFS does
not take any action if the flag is set.
Sponsored by: Spectra Logic
Reviewed by: bde (earlier version)
2013-08-21 23:04:48 +00:00
|
|
|
ndirent.de_Attributes = ATTR_ARCHIVE;
|
1998-11-21 00:20:24 +00:00
|
|
|
ndirent.de_LowerCase = 0;
|
1994-09-19 15:41:57 +00:00
|
|
|
ndirent.de_StartCluster = 0;
|
|
|
|
ndirent.de_FileSize = 0;
|
1998-02-18 09:28:47 +00:00
|
|
|
ndirent.de_pmp = pdep->de_pmp;
|
|
|
|
ndirent.de_flag = DE_ACCESS | DE_CREATE | DE_UPDATE;
|
1998-03-26 20:54:05 +00:00
|
|
|
getnanotime(&ts);
|
1998-02-18 09:28:47 +00:00
|
|
|
DETIMES(&ndirent, &ts, &ts, &ts);
|
|
|
|
error = createde(&ndirent, pdep, &dep, cnp);
|
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
*ap->a_vpp = DETOV(dep);
|
2014-12-21 13:29:33 +00:00
|
|
|
if ((cnp->cn_flags & MAKEENTRY) != 0)
|
|
|
|
cache_enter(ap->a_dvp, *ap->a_vpp, cnp);
|
1998-02-18 09:28:47 +00:00
|
|
|
return (0);
|
|
|
|
|
|
|
|
bad:
|
|
|
|
return (error);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
1995-10-29 15:33:36 +00:00
|
|
|
static int
|
2015-01-09 14:50:08 +00:00
|
|
|
msdosfs_mknod(struct vop_mknod_args *ap)
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
2007-08-07 03:43:28 +00:00
|
|
|
|
2001-07-19 19:15:42 +00:00
|
|
|
return (EINVAL);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
2005-01-29 16:23:39 +00:00
|
|
|
static int
|
2015-01-09 14:50:08 +00:00
|
|
|
msdosfs_open(struct vop_open_args *ap)
|
2005-01-29 16:23:39 +00:00
|
|
|
{
|
|
|
|
struct denode *dep = VTODE(ap->a_vp);
|
|
|
|
vnode_create_vobject(ap->a_vp, dep->de_FileSize, ap->a_td);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1995-10-29 15:33:36 +00:00
|
|
|
static int
|
2015-01-09 14:50:08 +00:00
|
|
|
msdosfs_close(struct vop_close_args *ap)
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct denode *dep = VTODE(vp);
|
1998-02-18 09:28:47 +00:00
|
|
|
struct timespec ts;
|
1994-09-19 15:41:57 +00:00
|
|
|
|
2002-09-25 02:32:42 +00:00
|
|
|
VI_LOCK(vp);
|
1998-02-18 09:28:47 +00:00
|
|
|
if (vp->v_usecount > 1) {
|
1998-03-26 20:54:05 +00:00
|
|
|
getnanotime(&ts);
|
1998-02-18 09:28:47 +00:00
|
|
|
DETIMES(dep, &ts, &ts, &ts);
|
|
|
|
}
|
2002-09-25 02:32:42 +00:00
|
|
|
VI_UNLOCK(vp);
|
1994-09-19 15:41:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1995-10-29 15:33:36 +00:00
|
|
|
static int
|
2015-01-09 14:50:08 +00:00
|
|
|
msdosfs_access(struct vop_access_args *ap)
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
1995-10-22 09:32:48 +00:00
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct denode *dep = VTODE(ap->a_vp);
|
|
|
|
struct msdosfsmount *pmp = dep->de_pmp;
|
2008-10-28 13:44:11 +00:00
|
|
|
mode_t file_mode;
|
|
|
|
accmode_t accmode = ap->a_accmode;
|
1995-10-22 09:32:48 +00:00
|
|
|
|
Expand the use of stat(2) flags to allow storing some Windows/DOS
and CIFS file attributes as BSD stat(2) flags.
This work is intended to be compatible with ZFS, the Solaris CIFS
server's interaction with ZFS, somewhat compatible with MacOS X,
and of course compatible with Windows.
The Windows attributes that are implemented were chosen based on
the attributes that ZFS already supports.
The summary of the flags is as follows:
UF_SYSTEM: Command line name: "system" or "usystem"
ZFS name: XAT_SYSTEM, ZFS_SYSTEM
Windows: FILE_ATTRIBUTE_SYSTEM
This flag means that the file is used by the
operating system. FreeBSD does not enforce any
special handling when this flag is set.
UF_SPARSE: Command line name: "sparse" or "usparse"
ZFS name: XAT_SPARSE, ZFS_SPARSE
Windows: FILE_ATTRIBUTE_SPARSE_FILE
This flag means that the file is sparse. Although
ZFS may modify this in some situations, there is
not generally any special handling for this flag.
UF_OFFLINE: Command line name: "offline" or "uoffline"
ZFS name: XAT_OFFLINE, ZFS_OFFLINE
Windows: FILE_ATTRIBUTE_OFFLINE
This flag means that the file has been moved to
offline storage. FreeBSD does not have any special
handling for this flag.
UF_REPARSE: Command line name: "reparse" or "ureparse"
ZFS name: XAT_REPARSE, ZFS_REPARSE
Windows: FILE_ATTRIBUTE_REPARSE_POINT
This flag means that the file is a Windows reparse
point. ZFS has special handling code for reparse
points, but we don't currently have the other
supporting infrastructure for them.
UF_HIDDEN: Command line name: "hidden" or "uhidden"
ZFS name: XAT_HIDDEN, ZFS_HIDDEN
Windows: FILE_ATTRIBUTE_HIDDEN
This flag means that the file may be excluded from
a directory listing if the application honors it.
FreeBSD has no special handling for this flag.
The name and bit definition for UF_HIDDEN are
identical to the definition in MacOS X.
UF_READONLY: Command line name: "urdonly", "rdonly", "readonly"
ZFS name: XAT_READONLY, ZFS_READONLY
Windows: FILE_ATTRIBUTE_READONLY
This flag means that the file may not written or
appended, but its attributes may be changed.
ZFS currently enforces this flag, but Illumos
developers have discussed disabling enforcement.
The behavior of this flag is different than MacOS X.
MacOS X uses UF_IMMUTABLE to represent the DOS
readonly permission, but that flag has a stronger
meaning than the semantics of DOS readonly permissions.
UF_ARCHIVE: Command line name: "uarch", "uarchive"
ZFS_NAME: XAT_ARCHIVE, ZFS_ARCHIVE
Windows name: FILE_ATTRIBUTE_ARCHIVE
The UF_ARCHIVED flag means that the file has changed and
needs to be archived. The meaning is same as
the Windows FILE_ATTRIBUTE_ARCHIVE attribute, and
the ZFS XAT_ARCHIVE and ZFS_ARCHIVE attribute.
msdosfs and ZFS have special handling for this flag.
i.e. they will set it when the file changes.
sys/param.h: Bump __FreeBSD_version to 1000047 for the
addition of new stat(2) flags.
chflags.1: Document the new command line flag names
(e.g. "system", "hidden") available to the
user.
ls.1: Reference chflags(1) for a list of file flags
and their meanings.
strtofflags.c: Implement the mapping between the new
command line flag names and new stat(2)
flags.
chflags.2: Document all of the new stat(2) flags, and
explain the intended behavior in a little
more detail. Explain how they map to
Windows file attributes.
Different filesystems behave differently
with respect to flags, so warn the
application developer to take care when
using them.
zfs_vnops.c: Add support for getting and setting the
UF_ARCHIVE, UF_READONLY, UF_SYSTEM, UF_HIDDEN,
UF_REPARSE, UF_OFFLINE, and UF_SPARSE flags.
All of these flags are implemented using
attributes that ZFS already supports, so
the on-disk format has not changed.
ZFS currently doesn't allow setting the
UF_REPARSE flag, and we don't really have
the other infrastructure to support reparse
points.
msdosfs_denode.c,
msdosfs_vnops.c: Add support for getting and setting
UF_HIDDEN, UF_SYSTEM and UF_READONLY
in MSDOSFS.
It supported SF_ARCHIVED, but this has been
changed to be UF_ARCHIVE, which has the same
semantics as the DOS archive attribute instead
of inverse semantics like SF_ARCHIVED.
After discussion with Bruce Evans, change
several things in the msdosfs behavior:
Use UF_READONLY to indicate whether a file
is writeable instead of file permissions, but
don't actually enforce it.
Refuse to change attributes on the root
directory, because it is special in FAT
filesystems, but allow most other attribute
changes on directories.
Don't set the archive attribute on a directory
when its modification time is updated.
Windows and DOS don't set the archive attribute
in that scenario, so we are now bug-for-bug
compatible.
smbfs_node.c,
smbfs_vnops.c: Add support for UF_HIDDEN, UF_SYSTEM,
UF_READONLY and UF_ARCHIVE in SMBFS.
This is similar to changes that Apple has
made in their version of SMBFS (as of
smb-583.8, posted on opensource.apple.com),
but not quite the same.
We map SMB_FA_READONLY to UF_READONLY,
because UF_READONLY is intended to match
the semantics of the DOS readonly flag.
The MacOS X code maps both UF_IMMUTABLE
and SF_IMMUTABLE to SMB_FA_READONLY, but
the immutable flags have stronger meaning
than the DOS readonly bit.
stat.h: Add definitions for UF_SYSTEM, UF_SPARSE,
UF_OFFLINE, UF_REPARSE, UF_ARCHIVE, UF_READONLY
and UF_HIDDEN.
The definition of UF_HIDDEN is the same as
the MacOS X definition.
Add commented-out definitions of
UF_COMPRESSED and UF_TRACKED. They are
defined in MacOS X (as of 10.8.2), but we
do not implement them (yet).
ufs_vnops.c: Add support for getting and setting
UF_ARCHIVE, UF_HIDDEN, UF_OFFLINE, UF_READONLY,
UF_REPARSE, UF_SPARSE, and UF_SYSTEM in UFS.
Alphabetize the flags that are supported.
These new flags are only stored, UFS does
not take any action if the flag is set.
Sponsored by: Spectra Logic
Reviewed by: bde (earlier version)
2013-08-21 23:04:48 +00:00
|
|
|
file_mode = S_IRWXU|S_IRWXG|S_IRWXO;
|
2003-08-12 20:06:56 +00:00
|
|
|
file_mode &= (vp->v_type == VDIR ? pmp->pm_dirmask : pmp->pm_mask);
|
1995-10-22 09:32:48 +00:00
|
|
|
|
|
|
|
/*
|
2007-08-07 05:42:10 +00:00
|
|
|
* Disallow writing to directories and regular files if the
|
|
|
|
* filesystem is read-only.
|
1995-10-22 09:32:48 +00:00
|
|
|
*/
|
2008-10-28 13:44:11 +00:00
|
|
|
if (accmode & VWRITE) {
|
1995-10-22 09:32:48 +00:00
|
|
|
switch (vp->v_type) {
|
|
|
|
case VREG:
|
Expand the use of stat(2) flags to allow storing some Windows/DOS
and CIFS file attributes as BSD stat(2) flags.
This work is intended to be compatible with ZFS, the Solaris CIFS
server's interaction with ZFS, somewhat compatible with MacOS X,
and of course compatible with Windows.
The Windows attributes that are implemented were chosen based on
the attributes that ZFS already supports.
The summary of the flags is as follows:
UF_SYSTEM: Command line name: "system" or "usystem"
ZFS name: XAT_SYSTEM, ZFS_SYSTEM
Windows: FILE_ATTRIBUTE_SYSTEM
This flag means that the file is used by the
operating system. FreeBSD does not enforce any
special handling when this flag is set.
UF_SPARSE: Command line name: "sparse" or "usparse"
ZFS name: XAT_SPARSE, ZFS_SPARSE
Windows: FILE_ATTRIBUTE_SPARSE_FILE
This flag means that the file is sparse. Although
ZFS may modify this in some situations, there is
not generally any special handling for this flag.
UF_OFFLINE: Command line name: "offline" or "uoffline"
ZFS name: XAT_OFFLINE, ZFS_OFFLINE
Windows: FILE_ATTRIBUTE_OFFLINE
This flag means that the file has been moved to
offline storage. FreeBSD does not have any special
handling for this flag.
UF_REPARSE: Command line name: "reparse" or "ureparse"
ZFS name: XAT_REPARSE, ZFS_REPARSE
Windows: FILE_ATTRIBUTE_REPARSE_POINT
This flag means that the file is a Windows reparse
point. ZFS has special handling code for reparse
points, but we don't currently have the other
supporting infrastructure for them.
UF_HIDDEN: Command line name: "hidden" or "uhidden"
ZFS name: XAT_HIDDEN, ZFS_HIDDEN
Windows: FILE_ATTRIBUTE_HIDDEN
This flag means that the file may be excluded from
a directory listing if the application honors it.
FreeBSD has no special handling for this flag.
The name and bit definition for UF_HIDDEN are
identical to the definition in MacOS X.
UF_READONLY: Command line name: "urdonly", "rdonly", "readonly"
ZFS name: XAT_READONLY, ZFS_READONLY
Windows: FILE_ATTRIBUTE_READONLY
This flag means that the file may not written or
appended, but its attributes may be changed.
ZFS currently enforces this flag, but Illumos
developers have discussed disabling enforcement.
The behavior of this flag is different than MacOS X.
MacOS X uses UF_IMMUTABLE to represent the DOS
readonly permission, but that flag has a stronger
meaning than the semantics of DOS readonly permissions.
UF_ARCHIVE: Command line name: "uarch", "uarchive"
ZFS_NAME: XAT_ARCHIVE, ZFS_ARCHIVE
Windows name: FILE_ATTRIBUTE_ARCHIVE
The UF_ARCHIVED flag means that the file has changed and
needs to be archived. The meaning is same as
the Windows FILE_ATTRIBUTE_ARCHIVE attribute, and
the ZFS XAT_ARCHIVE and ZFS_ARCHIVE attribute.
msdosfs and ZFS have special handling for this flag.
i.e. they will set it when the file changes.
sys/param.h: Bump __FreeBSD_version to 1000047 for the
addition of new stat(2) flags.
chflags.1: Document the new command line flag names
(e.g. "system", "hidden") available to the
user.
ls.1: Reference chflags(1) for a list of file flags
and their meanings.
strtofflags.c: Implement the mapping between the new
command line flag names and new stat(2)
flags.
chflags.2: Document all of the new stat(2) flags, and
explain the intended behavior in a little
more detail. Explain how they map to
Windows file attributes.
Different filesystems behave differently
with respect to flags, so warn the
application developer to take care when
using them.
zfs_vnops.c: Add support for getting and setting the
UF_ARCHIVE, UF_READONLY, UF_SYSTEM, UF_HIDDEN,
UF_REPARSE, UF_OFFLINE, and UF_SPARSE flags.
All of these flags are implemented using
attributes that ZFS already supports, so
the on-disk format has not changed.
ZFS currently doesn't allow setting the
UF_REPARSE flag, and we don't really have
the other infrastructure to support reparse
points.
msdosfs_denode.c,
msdosfs_vnops.c: Add support for getting and setting
UF_HIDDEN, UF_SYSTEM and UF_READONLY
in MSDOSFS.
It supported SF_ARCHIVED, but this has been
changed to be UF_ARCHIVE, which has the same
semantics as the DOS archive attribute instead
of inverse semantics like SF_ARCHIVED.
After discussion with Bruce Evans, change
several things in the msdosfs behavior:
Use UF_READONLY to indicate whether a file
is writeable instead of file permissions, but
don't actually enforce it.
Refuse to change attributes on the root
directory, because it is special in FAT
filesystems, but allow most other attribute
changes on directories.
Don't set the archive attribute on a directory
when its modification time is updated.
Windows and DOS don't set the archive attribute
in that scenario, so we are now bug-for-bug
compatible.
smbfs_node.c,
smbfs_vnops.c: Add support for UF_HIDDEN, UF_SYSTEM,
UF_READONLY and UF_ARCHIVE in SMBFS.
This is similar to changes that Apple has
made in their version of SMBFS (as of
smb-583.8, posted on opensource.apple.com),
but not quite the same.
We map SMB_FA_READONLY to UF_READONLY,
because UF_READONLY is intended to match
the semantics of the DOS readonly flag.
The MacOS X code maps both UF_IMMUTABLE
and SF_IMMUTABLE to SMB_FA_READONLY, but
the immutable flags have stronger meaning
than the DOS readonly bit.
stat.h: Add definitions for UF_SYSTEM, UF_SPARSE,
UF_OFFLINE, UF_REPARSE, UF_ARCHIVE, UF_READONLY
and UF_HIDDEN.
The definition of UF_HIDDEN is the same as
the MacOS X definition.
Add commented-out definitions of
UF_COMPRESSED and UF_TRACKED. They are
defined in MacOS X (as of 10.8.2), but we
do not implement them (yet).
ufs_vnops.c: Add support for getting and setting
UF_ARCHIVE, UF_HIDDEN, UF_OFFLINE, UF_READONLY,
UF_REPARSE, UF_SPARSE, and UF_SYSTEM in UFS.
Alphabetize the flags that are supported.
These new flags are only stored, UFS does
not take any action if the flag is set.
Sponsored by: Spectra Logic
Reviewed by: bde (earlier version)
2013-08-21 23:04:48 +00:00
|
|
|
case VDIR:
|
1995-10-22 09:32:48 +00:00
|
|
|
if (vp->v_mount->mnt_flag & MNT_RDONLY)
|
|
|
|
return (EROFS);
|
|
|
|
break;
|
1999-01-27 22:42:27 +00:00
|
|
|
default:
|
|
|
|
break;
|
1995-10-22 09:32:48 +00:00
|
|
|
}
|
|
|
|
}
|
1995-05-30 08:16:23 +00:00
|
|
|
|
2000-08-20 08:36:26 +00:00
|
|
|
return (vaccess(vp->v_type, file_mode, pmp->pm_uid, pmp->pm_gid,
|
2008-10-28 13:44:11 +00:00
|
|
|
ap->a_accmode, ap->a_cred, NULL));
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
1995-10-29 15:33:36 +00:00
|
|
|
static int
|
2015-01-09 14:50:08 +00:00
|
|
|
msdosfs_getattr(struct vop_getattr_args *ap)
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
|
|
|
struct denode *dep = VTODE(ap->a_vp);
|
1998-02-18 09:28:47 +00:00
|
|
|
struct msdosfsmount *pmp = dep->de_pmp;
|
1994-09-19 15:41:57 +00:00
|
|
|
struct vattr *vap = ap->a_vap;
|
1998-02-18 09:28:47 +00:00
|
|
|
mode_t mode;
|
|
|
|
struct timespec ts;
|
|
|
|
u_long dirsperblk = pmp->pm_BytesPerSec / sizeof(struct direntry);
|
2004-07-03 13:22:38 +00:00
|
|
|
uint64_t fileid;
|
1994-09-19 15:41:57 +00:00
|
|
|
|
1998-03-26 20:54:05 +00:00
|
|
|
getnanotime(&ts);
|
1998-02-18 09:28:47 +00:00
|
|
|
DETIMES(dep, &ts, &ts, &ts);
|
2009-02-27 20:00:15 +00:00
|
|
|
vap->va_fsid = dev2udev(pmp->pm_dev);
|
1994-09-19 15:41:57 +00:00
|
|
|
/*
|
|
|
|
* The following computation of the fileid must be the same as that
|
|
|
|
* used in msdosfs_readdir() to compute d_fileno. If not, pwd
|
|
|
|
* doesn't work.
|
|
|
|
*/
|
|
|
|
if (dep->de_Attributes & ATTR_DIRECTORY) {
|
2004-07-03 13:22:38 +00:00
|
|
|
fileid = (uint64_t)cntobn(pmp, dep->de_StartCluster) *
|
|
|
|
dirsperblk;
|
1998-02-18 09:28:47 +00:00
|
|
|
if (dep->de_StartCluster == MSDOSFSROOT)
|
|
|
|
fileid = 1;
|
1994-09-19 15:41:57 +00:00
|
|
|
} else {
|
2004-07-03 13:22:38 +00:00
|
|
|
fileid = (uint64_t)cntobn(pmp, dep->de_dirclust) *
|
|
|
|
dirsperblk;
|
1998-02-18 09:28:47 +00:00
|
|
|
if (dep->de_dirclust == MSDOSFSROOT)
|
2004-07-03 13:22:38 +00:00
|
|
|
fileid = (uint64_t)roottobn(pmp, 0) * dirsperblk;
|
2007-08-07 03:43:28 +00:00
|
|
|
fileid += (uoff_t)dep->de_diroffset / sizeof(struct direntry);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
2007-01-30 03:11:45 +00:00
|
|
|
|
|
|
|
if (pmp->pm_flags & MSDOSFS_LARGEFS)
|
|
|
|
vap->va_fileid = msdosfs_fileno_map(pmp->pm_mountp, fileid);
|
|
|
|
else
|
|
|
|
vap->va_fileid = (long)fileid;
|
|
|
|
|
Expand the use of stat(2) flags to allow storing some Windows/DOS
and CIFS file attributes as BSD stat(2) flags.
This work is intended to be compatible with ZFS, the Solaris CIFS
server's interaction with ZFS, somewhat compatible with MacOS X,
and of course compatible with Windows.
The Windows attributes that are implemented were chosen based on
the attributes that ZFS already supports.
The summary of the flags is as follows:
UF_SYSTEM: Command line name: "system" or "usystem"
ZFS name: XAT_SYSTEM, ZFS_SYSTEM
Windows: FILE_ATTRIBUTE_SYSTEM
This flag means that the file is used by the
operating system. FreeBSD does not enforce any
special handling when this flag is set.
UF_SPARSE: Command line name: "sparse" or "usparse"
ZFS name: XAT_SPARSE, ZFS_SPARSE
Windows: FILE_ATTRIBUTE_SPARSE_FILE
This flag means that the file is sparse. Although
ZFS may modify this in some situations, there is
not generally any special handling for this flag.
UF_OFFLINE: Command line name: "offline" or "uoffline"
ZFS name: XAT_OFFLINE, ZFS_OFFLINE
Windows: FILE_ATTRIBUTE_OFFLINE
This flag means that the file has been moved to
offline storage. FreeBSD does not have any special
handling for this flag.
UF_REPARSE: Command line name: "reparse" or "ureparse"
ZFS name: XAT_REPARSE, ZFS_REPARSE
Windows: FILE_ATTRIBUTE_REPARSE_POINT
This flag means that the file is a Windows reparse
point. ZFS has special handling code for reparse
points, but we don't currently have the other
supporting infrastructure for them.
UF_HIDDEN: Command line name: "hidden" or "uhidden"
ZFS name: XAT_HIDDEN, ZFS_HIDDEN
Windows: FILE_ATTRIBUTE_HIDDEN
This flag means that the file may be excluded from
a directory listing if the application honors it.
FreeBSD has no special handling for this flag.
The name and bit definition for UF_HIDDEN are
identical to the definition in MacOS X.
UF_READONLY: Command line name: "urdonly", "rdonly", "readonly"
ZFS name: XAT_READONLY, ZFS_READONLY
Windows: FILE_ATTRIBUTE_READONLY
This flag means that the file may not written or
appended, but its attributes may be changed.
ZFS currently enforces this flag, but Illumos
developers have discussed disabling enforcement.
The behavior of this flag is different than MacOS X.
MacOS X uses UF_IMMUTABLE to represent the DOS
readonly permission, but that flag has a stronger
meaning than the semantics of DOS readonly permissions.
UF_ARCHIVE: Command line name: "uarch", "uarchive"
ZFS_NAME: XAT_ARCHIVE, ZFS_ARCHIVE
Windows name: FILE_ATTRIBUTE_ARCHIVE
The UF_ARCHIVED flag means that the file has changed and
needs to be archived. The meaning is same as
the Windows FILE_ATTRIBUTE_ARCHIVE attribute, and
the ZFS XAT_ARCHIVE and ZFS_ARCHIVE attribute.
msdosfs and ZFS have special handling for this flag.
i.e. they will set it when the file changes.
sys/param.h: Bump __FreeBSD_version to 1000047 for the
addition of new stat(2) flags.
chflags.1: Document the new command line flag names
(e.g. "system", "hidden") available to the
user.
ls.1: Reference chflags(1) for a list of file flags
and their meanings.
strtofflags.c: Implement the mapping between the new
command line flag names and new stat(2)
flags.
chflags.2: Document all of the new stat(2) flags, and
explain the intended behavior in a little
more detail. Explain how they map to
Windows file attributes.
Different filesystems behave differently
with respect to flags, so warn the
application developer to take care when
using them.
zfs_vnops.c: Add support for getting and setting the
UF_ARCHIVE, UF_READONLY, UF_SYSTEM, UF_HIDDEN,
UF_REPARSE, UF_OFFLINE, and UF_SPARSE flags.
All of these flags are implemented using
attributes that ZFS already supports, so
the on-disk format has not changed.
ZFS currently doesn't allow setting the
UF_REPARSE flag, and we don't really have
the other infrastructure to support reparse
points.
msdosfs_denode.c,
msdosfs_vnops.c: Add support for getting and setting
UF_HIDDEN, UF_SYSTEM and UF_READONLY
in MSDOSFS.
It supported SF_ARCHIVED, but this has been
changed to be UF_ARCHIVE, which has the same
semantics as the DOS archive attribute instead
of inverse semantics like SF_ARCHIVED.
After discussion with Bruce Evans, change
several things in the msdosfs behavior:
Use UF_READONLY to indicate whether a file
is writeable instead of file permissions, but
don't actually enforce it.
Refuse to change attributes on the root
directory, because it is special in FAT
filesystems, but allow most other attribute
changes on directories.
Don't set the archive attribute on a directory
when its modification time is updated.
Windows and DOS don't set the archive attribute
in that scenario, so we are now bug-for-bug
compatible.
smbfs_node.c,
smbfs_vnops.c: Add support for UF_HIDDEN, UF_SYSTEM,
UF_READONLY and UF_ARCHIVE in SMBFS.
This is similar to changes that Apple has
made in their version of SMBFS (as of
smb-583.8, posted on opensource.apple.com),
but not quite the same.
We map SMB_FA_READONLY to UF_READONLY,
because UF_READONLY is intended to match
the semantics of the DOS readonly flag.
The MacOS X code maps both UF_IMMUTABLE
and SF_IMMUTABLE to SMB_FA_READONLY, but
the immutable flags have stronger meaning
than the DOS readonly bit.
stat.h: Add definitions for UF_SYSTEM, UF_SPARSE,
UF_OFFLINE, UF_REPARSE, UF_ARCHIVE, UF_READONLY
and UF_HIDDEN.
The definition of UF_HIDDEN is the same as
the MacOS X definition.
Add commented-out definitions of
UF_COMPRESSED and UF_TRACKED. They are
defined in MacOS X (as of 10.8.2), but we
do not implement them (yet).
ufs_vnops.c: Add support for getting and setting
UF_ARCHIVE, UF_HIDDEN, UF_OFFLINE, UF_READONLY,
UF_REPARSE, UF_SPARSE, and UF_SYSTEM in UFS.
Alphabetize the flags that are supported.
These new flags are only stored, UFS does
not take any action if the flag is set.
Sponsored by: Spectra Logic
Reviewed by: bde (earlier version)
2013-08-21 23:04:48 +00:00
|
|
|
mode = S_IRWXU|S_IRWXG|S_IRWXO;
|
2003-08-12 20:06:56 +00:00
|
|
|
vap->va_mode = mode &
|
2007-08-07 03:43:28 +00:00
|
|
|
(ap->a_vp->v_type == VDIR ? pmp->pm_dirmask : pmp->pm_mask);
|
1998-02-18 09:28:47 +00:00
|
|
|
vap->va_uid = pmp->pm_uid;
|
|
|
|
vap->va_gid = pmp->pm_gid;
|
1994-09-19 15:41:57 +00:00
|
|
|
vap->va_nlink = 1;
|
2008-09-20 19:49:15 +00:00
|
|
|
vap->va_rdev = NODEV;
|
1994-09-19 15:41:57 +00:00
|
|
|
vap->va_size = dep->de_FileSize;
|
2006-10-24 11:14:05 +00:00
|
|
|
fattime2timespec(dep->de_MDate, dep->de_MTime, 0, 0, &vap->va_mtime);
|
2006-12-03 19:04:26 +00:00
|
|
|
vap->va_ctime = vap->va_mtime;
|
1998-02-18 09:28:47 +00:00
|
|
|
if (pmp->pm_flags & MSDOSFSMNT_LONGNAME) {
|
2006-10-24 11:14:05 +00:00
|
|
|
fattime2timespec(dep->de_ADate, 0, 0, 0, &vap->va_atime);
|
|
|
|
fattime2timespec(dep->de_CDate, dep->de_CTime, dep->de_CHun,
|
2006-12-03 19:04:26 +00:00
|
|
|
0, &vap->va_birthtime);
|
1998-02-18 09:28:47 +00:00
|
|
|
} else {
|
|
|
|
vap->va_atime = vap->va_mtime;
|
2006-12-03 19:04:26 +00:00
|
|
|
vap->va_birthtime.tv_sec = -1;
|
|
|
|
vap->va_birthtime.tv_nsec = 0;
|
1998-02-18 09:28:47 +00:00
|
|
|
}
|
|
|
|
vap->va_flags = 0;
|
Expand the use of stat(2) flags to allow storing some Windows/DOS
and CIFS file attributes as BSD stat(2) flags.
This work is intended to be compatible with ZFS, the Solaris CIFS
server's interaction with ZFS, somewhat compatible with MacOS X,
and of course compatible with Windows.
The Windows attributes that are implemented were chosen based on
the attributes that ZFS already supports.
The summary of the flags is as follows:
UF_SYSTEM: Command line name: "system" or "usystem"
ZFS name: XAT_SYSTEM, ZFS_SYSTEM
Windows: FILE_ATTRIBUTE_SYSTEM
This flag means that the file is used by the
operating system. FreeBSD does not enforce any
special handling when this flag is set.
UF_SPARSE: Command line name: "sparse" or "usparse"
ZFS name: XAT_SPARSE, ZFS_SPARSE
Windows: FILE_ATTRIBUTE_SPARSE_FILE
This flag means that the file is sparse. Although
ZFS may modify this in some situations, there is
not generally any special handling for this flag.
UF_OFFLINE: Command line name: "offline" or "uoffline"
ZFS name: XAT_OFFLINE, ZFS_OFFLINE
Windows: FILE_ATTRIBUTE_OFFLINE
This flag means that the file has been moved to
offline storage. FreeBSD does not have any special
handling for this flag.
UF_REPARSE: Command line name: "reparse" or "ureparse"
ZFS name: XAT_REPARSE, ZFS_REPARSE
Windows: FILE_ATTRIBUTE_REPARSE_POINT
This flag means that the file is a Windows reparse
point. ZFS has special handling code for reparse
points, but we don't currently have the other
supporting infrastructure for them.
UF_HIDDEN: Command line name: "hidden" or "uhidden"
ZFS name: XAT_HIDDEN, ZFS_HIDDEN
Windows: FILE_ATTRIBUTE_HIDDEN
This flag means that the file may be excluded from
a directory listing if the application honors it.
FreeBSD has no special handling for this flag.
The name and bit definition for UF_HIDDEN are
identical to the definition in MacOS X.
UF_READONLY: Command line name: "urdonly", "rdonly", "readonly"
ZFS name: XAT_READONLY, ZFS_READONLY
Windows: FILE_ATTRIBUTE_READONLY
This flag means that the file may not written or
appended, but its attributes may be changed.
ZFS currently enforces this flag, but Illumos
developers have discussed disabling enforcement.
The behavior of this flag is different than MacOS X.
MacOS X uses UF_IMMUTABLE to represent the DOS
readonly permission, but that flag has a stronger
meaning than the semantics of DOS readonly permissions.
UF_ARCHIVE: Command line name: "uarch", "uarchive"
ZFS_NAME: XAT_ARCHIVE, ZFS_ARCHIVE
Windows name: FILE_ATTRIBUTE_ARCHIVE
The UF_ARCHIVED flag means that the file has changed and
needs to be archived. The meaning is same as
the Windows FILE_ATTRIBUTE_ARCHIVE attribute, and
the ZFS XAT_ARCHIVE and ZFS_ARCHIVE attribute.
msdosfs and ZFS have special handling for this flag.
i.e. they will set it when the file changes.
sys/param.h: Bump __FreeBSD_version to 1000047 for the
addition of new stat(2) flags.
chflags.1: Document the new command line flag names
(e.g. "system", "hidden") available to the
user.
ls.1: Reference chflags(1) for a list of file flags
and their meanings.
strtofflags.c: Implement the mapping between the new
command line flag names and new stat(2)
flags.
chflags.2: Document all of the new stat(2) flags, and
explain the intended behavior in a little
more detail. Explain how they map to
Windows file attributes.
Different filesystems behave differently
with respect to flags, so warn the
application developer to take care when
using them.
zfs_vnops.c: Add support for getting and setting the
UF_ARCHIVE, UF_READONLY, UF_SYSTEM, UF_HIDDEN,
UF_REPARSE, UF_OFFLINE, and UF_SPARSE flags.
All of these flags are implemented using
attributes that ZFS already supports, so
the on-disk format has not changed.
ZFS currently doesn't allow setting the
UF_REPARSE flag, and we don't really have
the other infrastructure to support reparse
points.
msdosfs_denode.c,
msdosfs_vnops.c: Add support for getting and setting
UF_HIDDEN, UF_SYSTEM and UF_READONLY
in MSDOSFS.
It supported SF_ARCHIVED, but this has been
changed to be UF_ARCHIVE, which has the same
semantics as the DOS archive attribute instead
of inverse semantics like SF_ARCHIVED.
After discussion with Bruce Evans, change
several things in the msdosfs behavior:
Use UF_READONLY to indicate whether a file
is writeable instead of file permissions, but
don't actually enforce it.
Refuse to change attributes on the root
directory, because it is special in FAT
filesystems, but allow most other attribute
changes on directories.
Don't set the archive attribute on a directory
when its modification time is updated.
Windows and DOS don't set the archive attribute
in that scenario, so we are now bug-for-bug
compatible.
smbfs_node.c,
smbfs_vnops.c: Add support for UF_HIDDEN, UF_SYSTEM,
UF_READONLY and UF_ARCHIVE in SMBFS.
This is similar to changes that Apple has
made in their version of SMBFS (as of
smb-583.8, posted on opensource.apple.com),
but not quite the same.
We map SMB_FA_READONLY to UF_READONLY,
because UF_READONLY is intended to match
the semantics of the DOS readonly flag.
The MacOS X code maps both UF_IMMUTABLE
and SF_IMMUTABLE to SMB_FA_READONLY, but
the immutable flags have stronger meaning
than the DOS readonly bit.
stat.h: Add definitions for UF_SYSTEM, UF_SPARSE,
UF_OFFLINE, UF_REPARSE, UF_ARCHIVE, UF_READONLY
and UF_HIDDEN.
The definition of UF_HIDDEN is the same as
the MacOS X definition.
Add commented-out definitions of
UF_COMPRESSED and UF_TRACKED. They are
defined in MacOS X (as of 10.8.2), but we
do not implement them (yet).
ufs_vnops.c: Add support for getting and setting
UF_ARCHIVE, UF_HIDDEN, UF_OFFLINE, UF_READONLY,
UF_REPARSE, UF_SPARSE, and UF_SYSTEM in UFS.
Alphabetize the flags that are supported.
These new flags are only stored, UFS does
not take any action if the flag is set.
Sponsored by: Spectra Logic
Reviewed by: bde (earlier version)
2013-08-21 23:04:48 +00:00
|
|
|
if (dep->de_Attributes & ATTR_ARCHIVE)
|
|
|
|
vap->va_flags |= UF_ARCHIVE;
|
|
|
|
if (dep->de_Attributes & ATTR_HIDDEN)
|
|
|
|
vap->va_flags |= UF_HIDDEN;
|
|
|
|
if (dep->de_Attributes & ATTR_READONLY)
|
|
|
|
vap->va_flags |= UF_READONLY;
|
|
|
|
if (dep->de_Attributes & ATTR_SYSTEM)
|
|
|
|
vap->va_flags |= UF_SYSTEM;
|
1994-09-19 15:41:57 +00:00
|
|
|
vap->va_gen = 0;
|
1998-02-18 09:28:47 +00:00
|
|
|
vap->va_blocksize = pmp->pm_bpcluster;
|
|
|
|
vap->va_bytes =
|
|
|
|
(dep->de_FileSize + pmp->pm_crbomask) & ~pmp->pm_crbomask;
|
1994-09-19 15:41:57 +00:00
|
|
|
vap->va_type = ap->a_vp->v_type;
|
1995-08-02 13:00:40 +00:00
|
|
|
vap->va_filerev = dep->de_modrev;
|
1998-02-18 09:28:47 +00:00
|
|
|
return (0);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
1995-10-29 15:33:36 +00:00
|
|
|
static int
|
2015-01-09 14:50:08 +00:00
|
|
|
msdosfs_setattr(struct vop_setattr_args *ap)
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
1995-10-22 09:32:48 +00:00
|
|
|
struct vnode *vp = ap->a_vp;
|
1994-09-19 15:41:57 +00:00
|
|
|
struct denode *dep = VTODE(ap->a_vp);
|
1998-02-18 09:28:47 +00:00
|
|
|
struct msdosfsmount *pmp = dep->de_pmp;
|
1994-09-19 15:41:57 +00:00
|
|
|
struct vattr *vap = ap->a_vap;
|
|
|
|
struct ucred *cred = ap->a_cred;
|
2008-08-28 15:23:18 +00:00
|
|
|
struct thread *td = curthread;
|
1995-10-22 09:32:48 +00:00
|
|
|
int error = 0;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
#ifdef MSDOSFS_DEBUG
|
2008-08-28 15:23:18 +00:00
|
|
|
printf("msdosfs_setattr(): vp %p, vap %p, cred %p\n",
|
|
|
|
ap->a_vp, vap, cred);
|
1998-02-18 09:28:47 +00:00
|
|
|
#endif
|
|
|
|
|
1995-10-22 09:32:48 +00:00
|
|
|
/*
|
|
|
|
* Check for unsettable attributes.
|
|
|
|
*/
|
|
|
|
if ((vap->va_type != VNON) || (vap->va_nlink != VNOVAL) ||
|
|
|
|
(vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
|
|
|
|
(vap->va_blocksize != VNOVAL) || (vap->va_rdev != VNOVAL) ||
|
|
|
|
(vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
|
1998-02-18 09:28:47 +00:00
|
|
|
#ifdef MSDOSFS_DEBUG
|
|
|
|
printf("msdosfs_setattr(): returning EINVAL\n");
|
|
|
|
printf(" va_type %d, va_nlink %x, va_fsid %lx, va_fileid %lx\n",
|
|
|
|
vap->va_type, vap->va_nlink, vap->va_fsid, vap->va_fileid);
|
|
|
|
printf(" va_blocksize %lx, va_rdev %x, va_bytes %qx, va_gen %lx\n",
|
|
|
|
vap->va_blocksize, vap->va_rdev, vap->va_bytes, vap->va_gen);
|
|
|
|
printf(" va_uid %x, va_gid %x\n",
|
|
|
|
vap->va_uid, vap->va_gid);
|
|
|
|
#endif
|
1995-10-22 09:32:48 +00:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
Expand the use of stat(2) flags to allow storing some Windows/DOS
and CIFS file attributes as BSD stat(2) flags.
This work is intended to be compatible with ZFS, the Solaris CIFS
server's interaction with ZFS, somewhat compatible with MacOS X,
and of course compatible with Windows.
The Windows attributes that are implemented were chosen based on
the attributes that ZFS already supports.
The summary of the flags is as follows:
UF_SYSTEM: Command line name: "system" or "usystem"
ZFS name: XAT_SYSTEM, ZFS_SYSTEM
Windows: FILE_ATTRIBUTE_SYSTEM
This flag means that the file is used by the
operating system. FreeBSD does not enforce any
special handling when this flag is set.
UF_SPARSE: Command line name: "sparse" or "usparse"
ZFS name: XAT_SPARSE, ZFS_SPARSE
Windows: FILE_ATTRIBUTE_SPARSE_FILE
This flag means that the file is sparse. Although
ZFS may modify this in some situations, there is
not generally any special handling for this flag.
UF_OFFLINE: Command line name: "offline" or "uoffline"
ZFS name: XAT_OFFLINE, ZFS_OFFLINE
Windows: FILE_ATTRIBUTE_OFFLINE
This flag means that the file has been moved to
offline storage. FreeBSD does not have any special
handling for this flag.
UF_REPARSE: Command line name: "reparse" or "ureparse"
ZFS name: XAT_REPARSE, ZFS_REPARSE
Windows: FILE_ATTRIBUTE_REPARSE_POINT
This flag means that the file is a Windows reparse
point. ZFS has special handling code for reparse
points, but we don't currently have the other
supporting infrastructure for them.
UF_HIDDEN: Command line name: "hidden" or "uhidden"
ZFS name: XAT_HIDDEN, ZFS_HIDDEN
Windows: FILE_ATTRIBUTE_HIDDEN
This flag means that the file may be excluded from
a directory listing if the application honors it.
FreeBSD has no special handling for this flag.
The name and bit definition for UF_HIDDEN are
identical to the definition in MacOS X.
UF_READONLY: Command line name: "urdonly", "rdonly", "readonly"
ZFS name: XAT_READONLY, ZFS_READONLY
Windows: FILE_ATTRIBUTE_READONLY
This flag means that the file may not written or
appended, but its attributes may be changed.
ZFS currently enforces this flag, but Illumos
developers have discussed disabling enforcement.
The behavior of this flag is different than MacOS X.
MacOS X uses UF_IMMUTABLE to represent the DOS
readonly permission, but that flag has a stronger
meaning than the semantics of DOS readonly permissions.
UF_ARCHIVE: Command line name: "uarch", "uarchive"
ZFS_NAME: XAT_ARCHIVE, ZFS_ARCHIVE
Windows name: FILE_ATTRIBUTE_ARCHIVE
The UF_ARCHIVED flag means that the file has changed and
needs to be archived. The meaning is same as
the Windows FILE_ATTRIBUTE_ARCHIVE attribute, and
the ZFS XAT_ARCHIVE and ZFS_ARCHIVE attribute.
msdosfs and ZFS have special handling for this flag.
i.e. they will set it when the file changes.
sys/param.h: Bump __FreeBSD_version to 1000047 for the
addition of new stat(2) flags.
chflags.1: Document the new command line flag names
(e.g. "system", "hidden") available to the
user.
ls.1: Reference chflags(1) for a list of file flags
and their meanings.
strtofflags.c: Implement the mapping between the new
command line flag names and new stat(2)
flags.
chflags.2: Document all of the new stat(2) flags, and
explain the intended behavior in a little
more detail. Explain how they map to
Windows file attributes.
Different filesystems behave differently
with respect to flags, so warn the
application developer to take care when
using them.
zfs_vnops.c: Add support for getting and setting the
UF_ARCHIVE, UF_READONLY, UF_SYSTEM, UF_HIDDEN,
UF_REPARSE, UF_OFFLINE, and UF_SPARSE flags.
All of these flags are implemented using
attributes that ZFS already supports, so
the on-disk format has not changed.
ZFS currently doesn't allow setting the
UF_REPARSE flag, and we don't really have
the other infrastructure to support reparse
points.
msdosfs_denode.c,
msdosfs_vnops.c: Add support for getting and setting
UF_HIDDEN, UF_SYSTEM and UF_READONLY
in MSDOSFS.
It supported SF_ARCHIVED, but this has been
changed to be UF_ARCHIVE, which has the same
semantics as the DOS archive attribute instead
of inverse semantics like SF_ARCHIVED.
After discussion with Bruce Evans, change
several things in the msdosfs behavior:
Use UF_READONLY to indicate whether a file
is writeable instead of file permissions, but
don't actually enforce it.
Refuse to change attributes on the root
directory, because it is special in FAT
filesystems, but allow most other attribute
changes on directories.
Don't set the archive attribute on a directory
when its modification time is updated.
Windows and DOS don't set the archive attribute
in that scenario, so we are now bug-for-bug
compatible.
smbfs_node.c,
smbfs_vnops.c: Add support for UF_HIDDEN, UF_SYSTEM,
UF_READONLY and UF_ARCHIVE in SMBFS.
This is similar to changes that Apple has
made in their version of SMBFS (as of
smb-583.8, posted on opensource.apple.com),
but not quite the same.
We map SMB_FA_READONLY to UF_READONLY,
because UF_READONLY is intended to match
the semantics of the DOS readonly flag.
The MacOS X code maps both UF_IMMUTABLE
and SF_IMMUTABLE to SMB_FA_READONLY, but
the immutable flags have stronger meaning
than the DOS readonly bit.
stat.h: Add definitions for UF_SYSTEM, UF_SPARSE,
UF_OFFLINE, UF_REPARSE, UF_ARCHIVE, UF_READONLY
and UF_HIDDEN.
The definition of UF_HIDDEN is the same as
the MacOS X definition.
Add commented-out definitions of
UF_COMPRESSED and UF_TRACKED. They are
defined in MacOS X (as of 10.8.2), but we
do not implement them (yet).
ufs_vnops.c: Add support for getting and setting
UF_ARCHIVE, UF_HIDDEN, UF_OFFLINE, UF_READONLY,
UF_REPARSE, UF_SPARSE, and UF_SYSTEM in UFS.
Alphabetize the flags that are supported.
These new flags are only stored, UFS does
not take any action if the flag is set.
Sponsored by: Spectra Logic
Reviewed by: bde (earlier version)
2013-08-21 23:04:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We don't allow setting attributes on the root directory.
|
|
|
|
* The special case for the root directory is because before
|
|
|
|
* FAT32, the root directory didn't have an entry for itself
|
|
|
|
* (and was otherwise special). With FAT32, the root
|
|
|
|
* directory is not so special, but still doesn't have an
|
|
|
|
* entry for itself.
|
|
|
|
*/
|
|
|
|
if (vp->v_vflag & VV_ROOT)
|
|
|
|
return (EINVAL);
|
|
|
|
|
1995-10-22 09:32:48 +00:00
|
|
|
if (vap->va_flags != VNOVAL) {
|
|
|
|
if (vp->v_mount->mnt_flag & MNT_RDONLY)
|
|
|
|
return (EROFS);
|
2006-11-06 13:42:10 +00:00
|
|
|
if (cred->cr_uid != pmp->pm_uid) {
|
2007-06-12 00:12:01 +00:00
|
|
|
error = priv_check_cred(cred, PRIV_VFS_ADMIN, 0);
|
2006-11-06 13:42:10 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
}
|
1995-10-22 09:32:48 +00:00
|
|
|
/*
|
|
|
|
* We are very inconsistent about handling unsupported
|
1998-06-09 13:20:29 +00:00
|
|
|
* attributes. We ignored the access time and the
|
1995-10-22 09:32:48 +00:00
|
|
|
* read and execute bits. We were strict for the other
|
|
|
|
* attributes.
|
|
|
|
*/
|
Expand the use of stat(2) flags to allow storing some Windows/DOS
and CIFS file attributes as BSD stat(2) flags.
This work is intended to be compatible with ZFS, the Solaris CIFS
server's interaction with ZFS, somewhat compatible with MacOS X,
and of course compatible with Windows.
The Windows attributes that are implemented were chosen based on
the attributes that ZFS already supports.
The summary of the flags is as follows:
UF_SYSTEM: Command line name: "system" or "usystem"
ZFS name: XAT_SYSTEM, ZFS_SYSTEM
Windows: FILE_ATTRIBUTE_SYSTEM
This flag means that the file is used by the
operating system. FreeBSD does not enforce any
special handling when this flag is set.
UF_SPARSE: Command line name: "sparse" or "usparse"
ZFS name: XAT_SPARSE, ZFS_SPARSE
Windows: FILE_ATTRIBUTE_SPARSE_FILE
This flag means that the file is sparse. Although
ZFS may modify this in some situations, there is
not generally any special handling for this flag.
UF_OFFLINE: Command line name: "offline" or "uoffline"
ZFS name: XAT_OFFLINE, ZFS_OFFLINE
Windows: FILE_ATTRIBUTE_OFFLINE
This flag means that the file has been moved to
offline storage. FreeBSD does not have any special
handling for this flag.
UF_REPARSE: Command line name: "reparse" or "ureparse"
ZFS name: XAT_REPARSE, ZFS_REPARSE
Windows: FILE_ATTRIBUTE_REPARSE_POINT
This flag means that the file is a Windows reparse
point. ZFS has special handling code for reparse
points, but we don't currently have the other
supporting infrastructure for them.
UF_HIDDEN: Command line name: "hidden" or "uhidden"
ZFS name: XAT_HIDDEN, ZFS_HIDDEN
Windows: FILE_ATTRIBUTE_HIDDEN
This flag means that the file may be excluded from
a directory listing if the application honors it.
FreeBSD has no special handling for this flag.
The name and bit definition for UF_HIDDEN are
identical to the definition in MacOS X.
UF_READONLY: Command line name: "urdonly", "rdonly", "readonly"
ZFS name: XAT_READONLY, ZFS_READONLY
Windows: FILE_ATTRIBUTE_READONLY
This flag means that the file may not written or
appended, but its attributes may be changed.
ZFS currently enforces this flag, but Illumos
developers have discussed disabling enforcement.
The behavior of this flag is different than MacOS X.
MacOS X uses UF_IMMUTABLE to represent the DOS
readonly permission, but that flag has a stronger
meaning than the semantics of DOS readonly permissions.
UF_ARCHIVE: Command line name: "uarch", "uarchive"
ZFS_NAME: XAT_ARCHIVE, ZFS_ARCHIVE
Windows name: FILE_ATTRIBUTE_ARCHIVE
The UF_ARCHIVED flag means that the file has changed and
needs to be archived. The meaning is same as
the Windows FILE_ATTRIBUTE_ARCHIVE attribute, and
the ZFS XAT_ARCHIVE and ZFS_ARCHIVE attribute.
msdosfs and ZFS have special handling for this flag.
i.e. they will set it when the file changes.
sys/param.h: Bump __FreeBSD_version to 1000047 for the
addition of new stat(2) flags.
chflags.1: Document the new command line flag names
(e.g. "system", "hidden") available to the
user.
ls.1: Reference chflags(1) for a list of file flags
and their meanings.
strtofflags.c: Implement the mapping between the new
command line flag names and new stat(2)
flags.
chflags.2: Document all of the new stat(2) flags, and
explain the intended behavior in a little
more detail. Explain how they map to
Windows file attributes.
Different filesystems behave differently
with respect to flags, so warn the
application developer to take care when
using them.
zfs_vnops.c: Add support for getting and setting the
UF_ARCHIVE, UF_READONLY, UF_SYSTEM, UF_HIDDEN,
UF_REPARSE, UF_OFFLINE, and UF_SPARSE flags.
All of these flags are implemented using
attributes that ZFS already supports, so
the on-disk format has not changed.
ZFS currently doesn't allow setting the
UF_REPARSE flag, and we don't really have
the other infrastructure to support reparse
points.
msdosfs_denode.c,
msdosfs_vnops.c: Add support for getting and setting
UF_HIDDEN, UF_SYSTEM and UF_READONLY
in MSDOSFS.
It supported SF_ARCHIVED, but this has been
changed to be UF_ARCHIVE, which has the same
semantics as the DOS archive attribute instead
of inverse semantics like SF_ARCHIVED.
After discussion with Bruce Evans, change
several things in the msdosfs behavior:
Use UF_READONLY to indicate whether a file
is writeable instead of file permissions, but
don't actually enforce it.
Refuse to change attributes on the root
directory, because it is special in FAT
filesystems, but allow most other attribute
changes on directories.
Don't set the archive attribute on a directory
when its modification time is updated.
Windows and DOS don't set the archive attribute
in that scenario, so we are now bug-for-bug
compatible.
smbfs_node.c,
smbfs_vnops.c: Add support for UF_HIDDEN, UF_SYSTEM,
UF_READONLY and UF_ARCHIVE in SMBFS.
This is similar to changes that Apple has
made in their version of SMBFS (as of
smb-583.8, posted on opensource.apple.com),
but not quite the same.
We map SMB_FA_READONLY to UF_READONLY,
because UF_READONLY is intended to match
the semantics of the DOS readonly flag.
The MacOS X code maps both UF_IMMUTABLE
and SF_IMMUTABLE to SMB_FA_READONLY, but
the immutable flags have stronger meaning
than the DOS readonly bit.
stat.h: Add definitions for UF_SYSTEM, UF_SPARSE,
UF_OFFLINE, UF_REPARSE, UF_ARCHIVE, UF_READONLY
and UF_HIDDEN.
The definition of UF_HIDDEN is the same as
the MacOS X definition.
Add commented-out definitions of
UF_COMPRESSED and UF_TRACKED. They are
defined in MacOS X (as of 10.8.2), but we
do not implement them (yet).
ufs_vnops.c: Add support for getting and setting
UF_ARCHIVE, UF_HIDDEN, UF_OFFLINE, UF_READONLY,
UF_REPARSE, UF_SPARSE, and UF_SYSTEM in UFS.
Alphabetize the flags that are supported.
These new flags are only stored, UFS does
not take any action if the flag is set.
Sponsored by: Spectra Logic
Reviewed by: bde (earlier version)
2013-08-21 23:04:48 +00:00
|
|
|
if (vap->va_flags & ~(UF_ARCHIVE | UF_HIDDEN | UF_READONLY |
|
|
|
|
UF_SYSTEM))
|
1998-06-10 06:30:31 +00:00
|
|
|
return EOPNOTSUPP;
|
Expand the use of stat(2) flags to allow storing some Windows/DOS
and CIFS file attributes as BSD stat(2) flags.
This work is intended to be compatible with ZFS, the Solaris CIFS
server's interaction with ZFS, somewhat compatible with MacOS X,
and of course compatible with Windows.
The Windows attributes that are implemented were chosen based on
the attributes that ZFS already supports.
The summary of the flags is as follows:
UF_SYSTEM: Command line name: "system" or "usystem"
ZFS name: XAT_SYSTEM, ZFS_SYSTEM
Windows: FILE_ATTRIBUTE_SYSTEM
This flag means that the file is used by the
operating system. FreeBSD does not enforce any
special handling when this flag is set.
UF_SPARSE: Command line name: "sparse" or "usparse"
ZFS name: XAT_SPARSE, ZFS_SPARSE
Windows: FILE_ATTRIBUTE_SPARSE_FILE
This flag means that the file is sparse. Although
ZFS may modify this in some situations, there is
not generally any special handling for this flag.
UF_OFFLINE: Command line name: "offline" or "uoffline"
ZFS name: XAT_OFFLINE, ZFS_OFFLINE
Windows: FILE_ATTRIBUTE_OFFLINE
This flag means that the file has been moved to
offline storage. FreeBSD does not have any special
handling for this flag.
UF_REPARSE: Command line name: "reparse" or "ureparse"
ZFS name: XAT_REPARSE, ZFS_REPARSE
Windows: FILE_ATTRIBUTE_REPARSE_POINT
This flag means that the file is a Windows reparse
point. ZFS has special handling code for reparse
points, but we don't currently have the other
supporting infrastructure for them.
UF_HIDDEN: Command line name: "hidden" or "uhidden"
ZFS name: XAT_HIDDEN, ZFS_HIDDEN
Windows: FILE_ATTRIBUTE_HIDDEN
This flag means that the file may be excluded from
a directory listing if the application honors it.
FreeBSD has no special handling for this flag.
The name and bit definition for UF_HIDDEN are
identical to the definition in MacOS X.
UF_READONLY: Command line name: "urdonly", "rdonly", "readonly"
ZFS name: XAT_READONLY, ZFS_READONLY
Windows: FILE_ATTRIBUTE_READONLY
This flag means that the file may not written or
appended, but its attributes may be changed.
ZFS currently enforces this flag, but Illumos
developers have discussed disabling enforcement.
The behavior of this flag is different than MacOS X.
MacOS X uses UF_IMMUTABLE to represent the DOS
readonly permission, but that flag has a stronger
meaning than the semantics of DOS readonly permissions.
UF_ARCHIVE: Command line name: "uarch", "uarchive"
ZFS_NAME: XAT_ARCHIVE, ZFS_ARCHIVE
Windows name: FILE_ATTRIBUTE_ARCHIVE
The UF_ARCHIVED flag means that the file has changed and
needs to be archived. The meaning is same as
the Windows FILE_ATTRIBUTE_ARCHIVE attribute, and
the ZFS XAT_ARCHIVE and ZFS_ARCHIVE attribute.
msdosfs and ZFS have special handling for this flag.
i.e. they will set it when the file changes.
sys/param.h: Bump __FreeBSD_version to 1000047 for the
addition of new stat(2) flags.
chflags.1: Document the new command line flag names
(e.g. "system", "hidden") available to the
user.
ls.1: Reference chflags(1) for a list of file flags
and their meanings.
strtofflags.c: Implement the mapping between the new
command line flag names and new stat(2)
flags.
chflags.2: Document all of the new stat(2) flags, and
explain the intended behavior in a little
more detail. Explain how they map to
Windows file attributes.
Different filesystems behave differently
with respect to flags, so warn the
application developer to take care when
using them.
zfs_vnops.c: Add support for getting and setting the
UF_ARCHIVE, UF_READONLY, UF_SYSTEM, UF_HIDDEN,
UF_REPARSE, UF_OFFLINE, and UF_SPARSE flags.
All of these flags are implemented using
attributes that ZFS already supports, so
the on-disk format has not changed.
ZFS currently doesn't allow setting the
UF_REPARSE flag, and we don't really have
the other infrastructure to support reparse
points.
msdosfs_denode.c,
msdosfs_vnops.c: Add support for getting and setting
UF_HIDDEN, UF_SYSTEM and UF_READONLY
in MSDOSFS.
It supported SF_ARCHIVED, but this has been
changed to be UF_ARCHIVE, which has the same
semantics as the DOS archive attribute instead
of inverse semantics like SF_ARCHIVED.
After discussion with Bruce Evans, change
several things in the msdosfs behavior:
Use UF_READONLY to indicate whether a file
is writeable instead of file permissions, but
don't actually enforce it.
Refuse to change attributes on the root
directory, because it is special in FAT
filesystems, but allow most other attribute
changes on directories.
Don't set the archive attribute on a directory
when its modification time is updated.
Windows and DOS don't set the archive attribute
in that scenario, so we are now bug-for-bug
compatible.
smbfs_node.c,
smbfs_vnops.c: Add support for UF_HIDDEN, UF_SYSTEM,
UF_READONLY and UF_ARCHIVE in SMBFS.
This is similar to changes that Apple has
made in their version of SMBFS (as of
smb-583.8, posted on opensource.apple.com),
but not quite the same.
We map SMB_FA_READONLY to UF_READONLY,
because UF_READONLY is intended to match
the semantics of the DOS readonly flag.
The MacOS X code maps both UF_IMMUTABLE
and SF_IMMUTABLE to SMB_FA_READONLY, but
the immutable flags have stronger meaning
than the DOS readonly bit.
stat.h: Add definitions for UF_SYSTEM, UF_SPARSE,
UF_OFFLINE, UF_REPARSE, UF_ARCHIVE, UF_READONLY
and UF_HIDDEN.
The definition of UF_HIDDEN is the same as
the MacOS X definition.
Add commented-out definitions of
UF_COMPRESSED and UF_TRACKED. They are
defined in MacOS X (as of 10.8.2), but we
do not implement them (yet).
ufs_vnops.c: Add support for getting and setting
UF_ARCHIVE, UF_HIDDEN, UF_OFFLINE, UF_READONLY,
UF_REPARSE, UF_SPARSE, and UF_SYSTEM in UFS.
Alphabetize the flags that are supported.
These new flags are only stored, UFS does
not take any action if the flag is set.
Sponsored by: Spectra Logic
Reviewed by: bde (earlier version)
2013-08-21 23:04:48 +00:00
|
|
|
if (vap->va_flags & UF_ARCHIVE)
|
1995-10-22 09:32:48 +00:00
|
|
|
dep->de_Attributes |= ATTR_ARCHIVE;
|
Expand the use of stat(2) flags to allow storing some Windows/DOS
and CIFS file attributes as BSD stat(2) flags.
This work is intended to be compatible with ZFS, the Solaris CIFS
server's interaction with ZFS, somewhat compatible with MacOS X,
and of course compatible with Windows.
The Windows attributes that are implemented were chosen based on
the attributes that ZFS already supports.
The summary of the flags is as follows:
UF_SYSTEM: Command line name: "system" or "usystem"
ZFS name: XAT_SYSTEM, ZFS_SYSTEM
Windows: FILE_ATTRIBUTE_SYSTEM
This flag means that the file is used by the
operating system. FreeBSD does not enforce any
special handling when this flag is set.
UF_SPARSE: Command line name: "sparse" or "usparse"
ZFS name: XAT_SPARSE, ZFS_SPARSE
Windows: FILE_ATTRIBUTE_SPARSE_FILE
This flag means that the file is sparse. Although
ZFS may modify this in some situations, there is
not generally any special handling for this flag.
UF_OFFLINE: Command line name: "offline" or "uoffline"
ZFS name: XAT_OFFLINE, ZFS_OFFLINE
Windows: FILE_ATTRIBUTE_OFFLINE
This flag means that the file has been moved to
offline storage. FreeBSD does not have any special
handling for this flag.
UF_REPARSE: Command line name: "reparse" or "ureparse"
ZFS name: XAT_REPARSE, ZFS_REPARSE
Windows: FILE_ATTRIBUTE_REPARSE_POINT
This flag means that the file is a Windows reparse
point. ZFS has special handling code for reparse
points, but we don't currently have the other
supporting infrastructure for them.
UF_HIDDEN: Command line name: "hidden" or "uhidden"
ZFS name: XAT_HIDDEN, ZFS_HIDDEN
Windows: FILE_ATTRIBUTE_HIDDEN
This flag means that the file may be excluded from
a directory listing if the application honors it.
FreeBSD has no special handling for this flag.
The name and bit definition for UF_HIDDEN are
identical to the definition in MacOS X.
UF_READONLY: Command line name: "urdonly", "rdonly", "readonly"
ZFS name: XAT_READONLY, ZFS_READONLY
Windows: FILE_ATTRIBUTE_READONLY
This flag means that the file may not written or
appended, but its attributes may be changed.
ZFS currently enforces this flag, but Illumos
developers have discussed disabling enforcement.
The behavior of this flag is different than MacOS X.
MacOS X uses UF_IMMUTABLE to represent the DOS
readonly permission, but that flag has a stronger
meaning than the semantics of DOS readonly permissions.
UF_ARCHIVE: Command line name: "uarch", "uarchive"
ZFS_NAME: XAT_ARCHIVE, ZFS_ARCHIVE
Windows name: FILE_ATTRIBUTE_ARCHIVE
The UF_ARCHIVED flag means that the file has changed and
needs to be archived. The meaning is same as
the Windows FILE_ATTRIBUTE_ARCHIVE attribute, and
the ZFS XAT_ARCHIVE and ZFS_ARCHIVE attribute.
msdosfs and ZFS have special handling for this flag.
i.e. they will set it when the file changes.
sys/param.h: Bump __FreeBSD_version to 1000047 for the
addition of new stat(2) flags.
chflags.1: Document the new command line flag names
(e.g. "system", "hidden") available to the
user.
ls.1: Reference chflags(1) for a list of file flags
and their meanings.
strtofflags.c: Implement the mapping between the new
command line flag names and new stat(2)
flags.
chflags.2: Document all of the new stat(2) flags, and
explain the intended behavior in a little
more detail. Explain how they map to
Windows file attributes.
Different filesystems behave differently
with respect to flags, so warn the
application developer to take care when
using them.
zfs_vnops.c: Add support for getting and setting the
UF_ARCHIVE, UF_READONLY, UF_SYSTEM, UF_HIDDEN,
UF_REPARSE, UF_OFFLINE, and UF_SPARSE flags.
All of these flags are implemented using
attributes that ZFS already supports, so
the on-disk format has not changed.
ZFS currently doesn't allow setting the
UF_REPARSE flag, and we don't really have
the other infrastructure to support reparse
points.
msdosfs_denode.c,
msdosfs_vnops.c: Add support for getting and setting
UF_HIDDEN, UF_SYSTEM and UF_READONLY
in MSDOSFS.
It supported SF_ARCHIVED, but this has been
changed to be UF_ARCHIVE, which has the same
semantics as the DOS archive attribute instead
of inverse semantics like SF_ARCHIVED.
After discussion with Bruce Evans, change
several things in the msdosfs behavior:
Use UF_READONLY to indicate whether a file
is writeable instead of file permissions, but
don't actually enforce it.
Refuse to change attributes on the root
directory, because it is special in FAT
filesystems, but allow most other attribute
changes on directories.
Don't set the archive attribute on a directory
when its modification time is updated.
Windows and DOS don't set the archive attribute
in that scenario, so we are now bug-for-bug
compatible.
smbfs_node.c,
smbfs_vnops.c: Add support for UF_HIDDEN, UF_SYSTEM,
UF_READONLY and UF_ARCHIVE in SMBFS.
This is similar to changes that Apple has
made in their version of SMBFS (as of
smb-583.8, posted on opensource.apple.com),
but not quite the same.
We map SMB_FA_READONLY to UF_READONLY,
because UF_READONLY is intended to match
the semantics of the DOS readonly flag.
The MacOS X code maps both UF_IMMUTABLE
and SF_IMMUTABLE to SMB_FA_READONLY, but
the immutable flags have stronger meaning
than the DOS readonly bit.
stat.h: Add definitions for UF_SYSTEM, UF_SPARSE,
UF_OFFLINE, UF_REPARSE, UF_ARCHIVE, UF_READONLY
and UF_HIDDEN.
The definition of UF_HIDDEN is the same as
the MacOS X definition.
Add commented-out definitions of
UF_COMPRESSED and UF_TRACKED. They are
defined in MacOS X (as of 10.8.2), but we
do not implement them (yet).
ufs_vnops.c: Add support for getting and setting
UF_ARCHIVE, UF_HIDDEN, UF_OFFLINE, UF_READONLY,
UF_REPARSE, UF_SPARSE, and UF_SYSTEM in UFS.
Alphabetize the flags that are supported.
These new flags are only stored, UFS does
not take any action if the flag is set.
Sponsored by: Spectra Logic
Reviewed by: bde (earlier version)
2013-08-21 23:04:48 +00:00
|
|
|
else
|
|
|
|
dep->de_Attributes &= ~ATTR_ARCHIVE;
|
|
|
|
if (vap->va_flags & UF_HIDDEN)
|
|
|
|
dep->de_Attributes |= ATTR_HIDDEN;
|
|
|
|
else
|
|
|
|
dep->de_Attributes &= ~ATTR_HIDDEN;
|
|
|
|
/* We don't allow changing the readonly bit on directories. */
|
|
|
|
if (vp->v_type != VDIR) {
|
|
|
|
if (vap->va_flags & UF_READONLY)
|
|
|
|
dep->de_Attributes |= ATTR_READONLY;
|
|
|
|
else
|
|
|
|
dep->de_Attributes &= ~ATTR_READONLY;
|
|
|
|
}
|
|
|
|
if (vap->va_flags & UF_SYSTEM)
|
|
|
|
dep->de_Attributes |= ATTR_SYSTEM;
|
|
|
|
else
|
|
|
|
dep->de_Attributes &= ~ATTR_SYSTEM;
|
1995-10-22 09:32:48 +00:00
|
|
|
dep->de_flag |= DE_MODIFIED;
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
|
|
|
|
uid_t uid;
|
|
|
|
gid_t gid;
|
2003-03-02 15:56:49 +00:00
|
|
|
|
1995-10-22 09:32:48 +00:00
|
|
|
if (vp->v_mount->mnt_flag & MNT_RDONLY)
|
|
|
|
return (EROFS);
|
1998-02-18 09:28:47 +00:00
|
|
|
uid = vap->va_uid;
|
|
|
|
if (uid == (uid_t)VNOVAL)
|
|
|
|
uid = pmp->pm_uid;
|
|
|
|
gid = vap->va_gid;
|
|
|
|
if (gid == (gid_t)VNOVAL)
|
|
|
|
gid = pmp->pm_gid;
|
2006-11-06 13:42:10 +00:00
|
|
|
if (cred->cr_uid != pmp->pm_uid || uid != pmp->pm_uid ||
|
|
|
|
(gid != pmp->pm_gid && !groupmember(gid, cred))) {
|
2007-06-12 00:12:01 +00:00
|
|
|
error = priv_check_cred(cred, PRIV_VFS_CHOWN, 0);
|
2006-11-06 13:42:10 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
}
|
1998-02-18 09:28:47 +00:00
|
|
|
if (uid != pmp->pm_uid || gid != pmp->pm_gid)
|
1998-06-10 13:46:46 +00:00
|
|
|
return EINVAL;
|
1994-12-27 12:37:36 +00:00
|
|
|
}
|
1998-02-18 09:28:47 +00:00
|
|
|
|
1994-09-19 15:41:57 +00:00
|
|
|
if (vap->va_size != VNOVAL) {
|
1995-10-22 09:32:48 +00:00
|
|
|
switch (vp->v_type) {
|
|
|
|
case VDIR:
|
|
|
|
return (EISDIR);
|
|
|
|
case VREG:
|
2007-08-07 05:42:10 +00:00
|
|
|
/*
|
|
|
|
* Truncation is only supported for regular files,
|
|
|
|
* Disallow it if the filesystem is read-only.
|
|
|
|
*/
|
1995-10-22 09:32:48 +00:00
|
|
|
if (vp->v_mount->mnt_flag & MNT_RDONLY)
|
|
|
|
return (EROFS);
|
|
|
|
break;
|
1999-01-27 22:42:27 +00:00
|
|
|
default:
|
2007-08-07 05:42:10 +00:00
|
|
|
/*
|
|
|
|
* According to POSIX, the result is unspecified
|
|
|
|
* for file types other than regular files,
|
|
|
|
* directories and shared memory objects. We
|
|
|
|
* don't support any file types except regular
|
|
|
|
* files and directories in this file system, so
|
|
|
|
* this (default) case is unreachable and can do
|
|
|
|
* anything. Keep falling through to detrunc()
|
|
|
|
* for now.
|
|
|
|
*/
|
1999-01-27 22:42:27 +00:00
|
|
|
break;
|
1995-10-22 09:32:48 +00:00
|
|
|
}
|
2012-04-23 13:21:28 +00:00
|
|
|
error = detrunc(dep, vap->va_size, 0, cred);
|
1994-09-27 20:42:59 +00:00
|
|
|
if (error)
|
1994-09-19 15:41:57 +00:00
|
|
|
return error;
|
|
|
|
}
|
1998-02-18 09:28:47 +00:00
|
|
|
if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
|
1995-10-22 09:32:48 +00:00
|
|
|
if (vp->v_mount->mnt_flag & MNT_RDONLY)
|
|
|
|
return (EROFS);
|
2014-06-17 07:11:00 +00:00
|
|
|
error = vn_utimes_perm(vp, vap, cred, td);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
Expand the use of stat(2) flags to allow storing some Windows/DOS
and CIFS file attributes as BSD stat(2) flags.
This work is intended to be compatible with ZFS, the Solaris CIFS
server's interaction with ZFS, somewhat compatible with MacOS X,
and of course compatible with Windows.
The Windows attributes that are implemented were chosen based on
the attributes that ZFS already supports.
The summary of the flags is as follows:
UF_SYSTEM: Command line name: "system" or "usystem"
ZFS name: XAT_SYSTEM, ZFS_SYSTEM
Windows: FILE_ATTRIBUTE_SYSTEM
This flag means that the file is used by the
operating system. FreeBSD does not enforce any
special handling when this flag is set.
UF_SPARSE: Command line name: "sparse" or "usparse"
ZFS name: XAT_SPARSE, ZFS_SPARSE
Windows: FILE_ATTRIBUTE_SPARSE_FILE
This flag means that the file is sparse. Although
ZFS may modify this in some situations, there is
not generally any special handling for this flag.
UF_OFFLINE: Command line name: "offline" or "uoffline"
ZFS name: XAT_OFFLINE, ZFS_OFFLINE
Windows: FILE_ATTRIBUTE_OFFLINE
This flag means that the file has been moved to
offline storage. FreeBSD does not have any special
handling for this flag.
UF_REPARSE: Command line name: "reparse" or "ureparse"
ZFS name: XAT_REPARSE, ZFS_REPARSE
Windows: FILE_ATTRIBUTE_REPARSE_POINT
This flag means that the file is a Windows reparse
point. ZFS has special handling code for reparse
points, but we don't currently have the other
supporting infrastructure for them.
UF_HIDDEN: Command line name: "hidden" or "uhidden"
ZFS name: XAT_HIDDEN, ZFS_HIDDEN
Windows: FILE_ATTRIBUTE_HIDDEN
This flag means that the file may be excluded from
a directory listing if the application honors it.
FreeBSD has no special handling for this flag.
The name and bit definition for UF_HIDDEN are
identical to the definition in MacOS X.
UF_READONLY: Command line name: "urdonly", "rdonly", "readonly"
ZFS name: XAT_READONLY, ZFS_READONLY
Windows: FILE_ATTRIBUTE_READONLY
This flag means that the file may not written or
appended, but its attributes may be changed.
ZFS currently enforces this flag, but Illumos
developers have discussed disabling enforcement.
The behavior of this flag is different than MacOS X.
MacOS X uses UF_IMMUTABLE to represent the DOS
readonly permission, but that flag has a stronger
meaning than the semantics of DOS readonly permissions.
UF_ARCHIVE: Command line name: "uarch", "uarchive"
ZFS_NAME: XAT_ARCHIVE, ZFS_ARCHIVE
Windows name: FILE_ATTRIBUTE_ARCHIVE
The UF_ARCHIVED flag means that the file has changed and
needs to be archived. The meaning is same as
the Windows FILE_ATTRIBUTE_ARCHIVE attribute, and
the ZFS XAT_ARCHIVE and ZFS_ARCHIVE attribute.
msdosfs and ZFS have special handling for this flag.
i.e. they will set it when the file changes.
sys/param.h: Bump __FreeBSD_version to 1000047 for the
addition of new stat(2) flags.
chflags.1: Document the new command line flag names
(e.g. "system", "hidden") available to the
user.
ls.1: Reference chflags(1) for a list of file flags
and their meanings.
strtofflags.c: Implement the mapping between the new
command line flag names and new stat(2)
flags.
chflags.2: Document all of the new stat(2) flags, and
explain the intended behavior in a little
more detail. Explain how they map to
Windows file attributes.
Different filesystems behave differently
with respect to flags, so warn the
application developer to take care when
using them.
zfs_vnops.c: Add support for getting and setting the
UF_ARCHIVE, UF_READONLY, UF_SYSTEM, UF_HIDDEN,
UF_REPARSE, UF_OFFLINE, and UF_SPARSE flags.
All of these flags are implemented using
attributes that ZFS already supports, so
the on-disk format has not changed.
ZFS currently doesn't allow setting the
UF_REPARSE flag, and we don't really have
the other infrastructure to support reparse
points.
msdosfs_denode.c,
msdosfs_vnops.c: Add support for getting and setting
UF_HIDDEN, UF_SYSTEM and UF_READONLY
in MSDOSFS.
It supported SF_ARCHIVED, but this has been
changed to be UF_ARCHIVE, which has the same
semantics as the DOS archive attribute instead
of inverse semantics like SF_ARCHIVED.
After discussion with Bruce Evans, change
several things in the msdosfs behavior:
Use UF_READONLY to indicate whether a file
is writeable instead of file permissions, but
don't actually enforce it.
Refuse to change attributes on the root
directory, because it is special in FAT
filesystems, but allow most other attribute
changes on directories.
Don't set the archive attribute on a directory
when its modification time is updated.
Windows and DOS don't set the archive attribute
in that scenario, so we are now bug-for-bug
compatible.
smbfs_node.c,
smbfs_vnops.c: Add support for UF_HIDDEN, UF_SYSTEM,
UF_READONLY and UF_ARCHIVE in SMBFS.
This is similar to changes that Apple has
made in their version of SMBFS (as of
smb-583.8, posted on opensource.apple.com),
but not quite the same.
We map SMB_FA_READONLY to UF_READONLY,
because UF_READONLY is intended to match
the semantics of the DOS readonly flag.
The MacOS X code maps both UF_IMMUTABLE
and SF_IMMUTABLE to SMB_FA_READONLY, but
the immutable flags have stronger meaning
than the DOS readonly bit.
stat.h: Add definitions for UF_SYSTEM, UF_SPARSE,
UF_OFFLINE, UF_REPARSE, UF_ARCHIVE, UF_READONLY
and UF_HIDDEN.
The definition of UF_HIDDEN is the same as
the MacOS X definition.
Add commented-out definitions of
UF_COMPRESSED and UF_TRACKED. They are
defined in MacOS X (as of 10.8.2), but we
do not implement them (yet).
ufs_vnops.c: Add support for getting and setting
UF_ARCHIVE, UF_HIDDEN, UF_OFFLINE, UF_READONLY,
UF_REPARSE, UF_SPARSE, and UF_SYSTEM in UFS.
Alphabetize the flags that are supported.
These new flags are only stored, UFS does
not take any action if the flag is set.
Sponsored by: Spectra Logic
Reviewed by: bde (earlier version)
2013-08-21 23:04:48 +00:00
|
|
|
if ((pmp->pm_flags & MSDOSFSMNT_NOWIN95) == 0 &&
|
|
|
|
vap->va_atime.tv_sec != VNOVAL) {
|
|
|
|
dep->de_flag &= ~DE_ACCESS;
|
|
|
|
timespec2fattime(&vap->va_atime, 0,
|
|
|
|
&dep->de_ADate, NULL, NULL);
|
|
|
|
}
|
|
|
|
if (vap->va_mtime.tv_sec != VNOVAL) {
|
|
|
|
dep->de_flag &= ~DE_UPDATE;
|
|
|
|
timespec2fattime(&vap->va_mtime, 0,
|
|
|
|
&dep->de_MDate, &dep->de_MTime, NULL);
|
1998-02-18 09:28:47 +00:00
|
|
|
}
|
Expand the use of stat(2) flags to allow storing some Windows/DOS
and CIFS file attributes as BSD stat(2) flags.
This work is intended to be compatible with ZFS, the Solaris CIFS
server's interaction with ZFS, somewhat compatible with MacOS X,
and of course compatible with Windows.
The Windows attributes that are implemented were chosen based on
the attributes that ZFS already supports.
The summary of the flags is as follows:
UF_SYSTEM: Command line name: "system" or "usystem"
ZFS name: XAT_SYSTEM, ZFS_SYSTEM
Windows: FILE_ATTRIBUTE_SYSTEM
This flag means that the file is used by the
operating system. FreeBSD does not enforce any
special handling when this flag is set.
UF_SPARSE: Command line name: "sparse" or "usparse"
ZFS name: XAT_SPARSE, ZFS_SPARSE
Windows: FILE_ATTRIBUTE_SPARSE_FILE
This flag means that the file is sparse. Although
ZFS may modify this in some situations, there is
not generally any special handling for this flag.
UF_OFFLINE: Command line name: "offline" or "uoffline"
ZFS name: XAT_OFFLINE, ZFS_OFFLINE
Windows: FILE_ATTRIBUTE_OFFLINE
This flag means that the file has been moved to
offline storage. FreeBSD does not have any special
handling for this flag.
UF_REPARSE: Command line name: "reparse" or "ureparse"
ZFS name: XAT_REPARSE, ZFS_REPARSE
Windows: FILE_ATTRIBUTE_REPARSE_POINT
This flag means that the file is a Windows reparse
point. ZFS has special handling code for reparse
points, but we don't currently have the other
supporting infrastructure for them.
UF_HIDDEN: Command line name: "hidden" or "uhidden"
ZFS name: XAT_HIDDEN, ZFS_HIDDEN
Windows: FILE_ATTRIBUTE_HIDDEN
This flag means that the file may be excluded from
a directory listing if the application honors it.
FreeBSD has no special handling for this flag.
The name and bit definition for UF_HIDDEN are
identical to the definition in MacOS X.
UF_READONLY: Command line name: "urdonly", "rdonly", "readonly"
ZFS name: XAT_READONLY, ZFS_READONLY
Windows: FILE_ATTRIBUTE_READONLY
This flag means that the file may not written or
appended, but its attributes may be changed.
ZFS currently enforces this flag, but Illumos
developers have discussed disabling enforcement.
The behavior of this flag is different than MacOS X.
MacOS X uses UF_IMMUTABLE to represent the DOS
readonly permission, but that flag has a stronger
meaning than the semantics of DOS readonly permissions.
UF_ARCHIVE: Command line name: "uarch", "uarchive"
ZFS_NAME: XAT_ARCHIVE, ZFS_ARCHIVE
Windows name: FILE_ATTRIBUTE_ARCHIVE
The UF_ARCHIVED flag means that the file has changed and
needs to be archived. The meaning is same as
the Windows FILE_ATTRIBUTE_ARCHIVE attribute, and
the ZFS XAT_ARCHIVE and ZFS_ARCHIVE attribute.
msdosfs and ZFS have special handling for this flag.
i.e. they will set it when the file changes.
sys/param.h: Bump __FreeBSD_version to 1000047 for the
addition of new stat(2) flags.
chflags.1: Document the new command line flag names
(e.g. "system", "hidden") available to the
user.
ls.1: Reference chflags(1) for a list of file flags
and their meanings.
strtofflags.c: Implement the mapping between the new
command line flag names and new stat(2)
flags.
chflags.2: Document all of the new stat(2) flags, and
explain the intended behavior in a little
more detail. Explain how they map to
Windows file attributes.
Different filesystems behave differently
with respect to flags, so warn the
application developer to take care when
using them.
zfs_vnops.c: Add support for getting and setting the
UF_ARCHIVE, UF_READONLY, UF_SYSTEM, UF_HIDDEN,
UF_REPARSE, UF_OFFLINE, and UF_SPARSE flags.
All of these flags are implemented using
attributes that ZFS already supports, so
the on-disk format has not changed.
ZFS currently doesn't allow setting the
UF_REPARSE flag, and we don't really have
the other infrastructure to support reparse
points.
msdosfs_denode.c,
msdosfs_vnops.c: Add support for getting and setting
UF_HIDDEN, UF_SYSTEM and UF_READONLY
in MSDOSFS.
It supported SF_ARCHIVED, but this has been
changed to be UF_ARCHIVE, which has the same
semantics as the DOS archive attribute instead
of inverse semantics like SF_ARCHIVED.
After discussion with Bruce Evans, change
several things in the msdosfs behavior:
Use UF_READONLY to indicate whether a file
is writeable instead of file permissions, but
don't actually enforce it.
Refuse to change attributes on the root
directory, because it is special in FAT
filesystems, but allow most other attribute
changes on directories.
Don't set the archive attribute on a directory
when its modification time is updated.
Windows and DOS don't set the archive attribute
in that scenario, so we are now bug-for-bug
compatible.
smbfs_node.c,
smbfs_vnops.c: Add support for UF_HIDDEN, UF_SYSTEM,
UF_READONLY and UF_ARCHIVE in SMBFS.
This is similar to changes that Apple has
made in their version of SMBFS (as of
smb-583.8, posted on opensource.apple.com),
but not quite the same.
We map SMB_FA_READONLY to UF_READONLY,
because UF_READONLY is intended to match
the semantics of the DOS readonly flag.
The MacOS X code maps both UF_IMMUTABLE
and SF_IMMUTABLE to SMB_FA_READONLY, but
the immutable flags have stronger meaning
than the DOS readonly bit.
stat.h: Add definitions for UF_SYSTEM, UF_SPARSE,
UF_OFFLINE, UF_REPARSE, UF_ARCHIVE, UF_READONLY
and UF_HIDDEN.
The definition of UF_HIDDEN is the same as
the MacOS X definition.
Add commented-out definitions of
UF_COMPRESSED and UF_TRACKED. They are
defined in MacOS X (as of 10.8.2), but we
do not implement them (yet).
ufs_vnops.c: Add support for getting and setting
UF_ARCHIVE, UF_HIDDEN, UF_OFFLINE, UF_READONLY,
UF_REPARSE, UF_SPARSE, and UF_SYSTEM in UFS.
Alphabetize the flags that are supported.
These new flags are only stored, UFS does
not take any action if the flag is set.
Sponsored by: Spectra Logic
Reviewed by: bde (earlier version)
2013-08-21 23:04:48 +00:00
|
|
|
/*
|
|
|
|
* We don't set the archive bit when modifying the time of
|
|
|
|
* a directory to emulate the Windows/DOS behavior.
|
|
|
|
*/
|
|
|
|
if (vp->v_type != VDIR)
|
|
|
|
dep->de_Attributes |= ATTR_ARCHIVE;
|
|
|
|
dep->de_flag |= DE_MODIFIED;
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
/*
|
1994-12-27 12:37:36 +00:00
|
|
|
* DOS files only have the ability to have their writability
|
1994-09-19 15:41:57 +00:00
|
|
|
* attribute set, so we use the owner write bit to set the readonly
|
|
|
|
* attribute.
|
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
if (vap->va_mode != (mode_t)VNOVAL) {
|
1995-10-22 09:32:48 +00:00
|
|
|
if (vp->v_mount->mnt_flag & MNT_RDONLY)
|
|
|
|
return (EROFS);
|
2006-11-06 13:42:10 +00:00
|
|
|
if (cred->cr_uid != pmp->pm_uid) {
|
2007-06-12 00:12:01 +00:00
|
|
|
error = priv_check_cred(cred, PRIV_VFS_ADMIN, 0);
|
2006-11-06 13:42:10 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
}
|
1998-02-18 09:28:47 +00:00
|
|
|
if (vp->v_type != VDIR) {
|
|
|
|
/* We ignore the read and execute bits. */
|
|
|
|
if (vap->va_mode & VWRITE)
|
|
|
|
dep->de_Attributes &= ~ATTR_READONLY;
|
|
|
|
else
|
|
|
|
dep->de_Attributes |= ATTR_READONLY;
|
2002-04-05 14:01:04 +00:00
|
|
|
dep->de_Attributes |= ATTR_ARCHIVE;
|
1998-02-18 09:28:47 +00:00
|
|
|
dep->de_flag |= DE_MODIFIED;
|
|
|
|
}
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
2007-10-18 07:26:21 +00:00
|
|
|
return (deupdat(dep, 0));
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
1995-10-29 15:33:36 +00:00
|
|
|
static int
|
2015-01-09 14:50:08 +00:00
|
|
|
msdosfs_read(struct vop_read_args *ap)
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
|
|
|
int error = 0;
|
1998-02-18 09:28:47 +00:00
|
|
|
int blsize;
|
1994-09-19 15:41:57 +00:00
|
|
|
int isadir;
|
2012-02-21 01:05:12 +00:00
|
|
|
ssize_t orig_resid;
|
2000-01-02 03:30:42 +00:00
|
|
|
u_int n;
|
|
|
|
u_long diff;
|
|
|
|
u_long on;
|
1994-09-19 15:41:57 +00:00
|
|
|
daddr_t lbn;
|
1998-03-03 02:50:24 +00:00
|
|
|
daddr_t rablock;
|
1994-09-19 15:41:57 +00:00
|
|
|
int rasize;
|
1999-09-20 23:27:58 +00:00
|
|
|
int seqcount;
|
1994-09-19 15:41:57 +00:00
|
|
|
struct buf *bp;
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct denode *dep = VTODE(vp);
|
|
|
|
struct msdosfsmount *pmp = dep->de_pmp;
|
|
|
|
struct uio *uio = ap->a_uio;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If they didn't ask for any data, then we are done.
|
|
|
|
*/
|
1999-07-25 04:01:32 +00:00
|
|
|
orig_resid = uio->uio_resid;
|
In msdosfs_read() and msdosfs_write(), don't check explicitly for
(uio_offset < 0) since this can't happen. If this happens, then the
general code handles the problem safely (better than before for reading,
returning 0 (EOF) instead of the bogus errno EINVAL, and the same as
before for writing, returning EFBIG).
In msdosfs_read(), don't check for (uio_resid < 0). msdosfs_write()
already didn't check.
In msdosfs_read(), document in a comment our assumptions that the caller
passed a valid uio_offset and uio_resid. ffs checks using KASSERT(),
and that is enough sanity checking. In the same comment, partly document
there is no need to check for the EOVERFLOW case, unlike in ffs where this
case can happen at least in theory.
In msdosfs_write(), add a comment about why the checking of
(uio_resid == 0) is explicit, unlike in ffs.
In msdosfs_write(), check for impossibly large final offsets before
checking if the file size rlimit would be exceeded, so that we don't
have an overflow bug in the rlimit check and are consistent with ffs.
We now return EFBIG instead of EFBIG plus a SIGXFSZ signal if the final
offset would be impossibly large but not so large as to cause overflow.
Overflow normally gave the benign behaviour of no signal.
Approved by: re (kensmith) (blanket)
2007-08-07 10:35:27 +00:00
|
|
|
if (orig_resid == 0)
|
1998-02-18 09:28:47 +00:00
|
|
|
return (0);
|
1994-09-19 15:41:57 +00:00
|
|
|
|
In msdosfs_read() and msdosfs_write(), don't check explicitly for
(uio_offset < 0) since this can't happen. If this happens, then the
general code handles the problem safely (better than before for reading,
returning 0 (EOF) instead of the bogus errno EINVAL, and the same as
before for writing, returning EFBIG).
In msdosfs_read(), don't check for (uio_resid < 0). msdosfs_write()
already didn't check.
In msdosfs_read(), document in a comment our assumptions that the caller
passed a valid uio_offset and uio_resid. ffs checks using KASSERT(),
and that is enough sanity checking. In the same comment, partly document
there is no need to check for the EOVERFLOW case, unlike in ffs where this
case can happen at least in theory.
In msdosfs_write(), add a comment about why the checking of
(uio_resid == 0) is explicit, unlike in ffs.
In msdosfs_write(), check for impossibly large final offsets before
checking if the file size rlimit would be exceeded, so that we don't
have an overflow bug in the rlimit check and are consistent with ffs.
We now return EFBIG instead of EFBIG plus a SIGXFSZ signal if the final
offset would be impossibly large but not so large as to cause overflow.
Overflow normally gave the benign behaviour of no signal.
Approved by: re (kensmith) (blanket)
2007-08-07 10:35:27 +00:00
|
|
|
/*
|
|
|
|
* The caller is supposed to ensure that
|
|
|
|
* uio->uio_offset >= 0 and uio->uio_resid >= 0.
|
|
|
|
* We don't need to check for large offsets as in ffs because
|
|
|
|
* dep->de_FileSize <= DOS_FILESIZE_MAX < OFF_MAX, so large
|
|
|
|
* offsets cannot cause overflow even in theory.
|
|
|
|
*/
|
|
|
|
|
2002-12-28 20:37:50 +00:00
|
|
|
seqcount = ap->a_ioflag >> IO_SEQSHIFT;
|
1999-09-20 23:27:58 +00:00
|
|
|
|
1994-09-19 15:41:57 +00:00
|
|
|
isadir = dep->de_Attributes & ATTR_DIRECTORY;
|
|
|
|
do {
|
1999-12-28 15:34:23 +00:00
|
|
|
if (uio->uio_offset >= dep->de_FileSize)
|
|
|
|
break;
|
1998-02-18 09:28:47 +00:00
|
|
|
lbn = de_cluster(pmp, uio->uio_offset);
|
2007-07-20 16:21:47 +00:00
|
|
|
rablock = lbn + 1;
|
|
|
|
blsize = pmp->pm_bpcluster;
|
|
|
|
on = uio->uio_offset & pmp->pm_crbomask;
|
1994-09-19 15:41:57 +00:00
|
|
|
/*
|
|
|
|
* If we are operating on a directory file then be sure to
|
|
|
|
* do i/o with the vnode for the filesystem instead of the
|
|
|
|
* vnode for the directory.
|
|
|
|
*/
|
|
|
|
if (isadir) {
|
2000-01-02 03:30:42 +00:00
|
|
|
/* convert cluster # to block # */
|
|
|
|
error = pcbmap(dep, lbn, &lbn, 0, &blsize);
|
2000-01-08 10:45:54 +00:00
|
|
|
if (error == E2BIG) {
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
} else if (error)
|
2000-01-02 03:30:42 +00:00
|
|
|
break;
|
1998-02-18 09:28:47 +00:00
|
|
|
error = bread(pmp->pm_devvp, lbn, blsize, NOCRED, &bp);
|
2007-07-20 16:21:47 +00:00
|
|
|
} else if (de_cn2off(pmp, rablock) >= dep->de_FileSize) {
|
|
|
|
error = bread(vp, lbn, blsize, NOCRED, &bp);
|
2007-07-20 17:06:57 +00:00
|
|
|
} else if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERR) == 0) {
|
|
|
|
error = cluster_read(vp, dep->de_FileSize, lbn, blsize,
|
2013-03-14 20:28:26 +00:00
|
|
|
NOCRED, on + uio->uio_resid, seqcount, 0, &bp);
|
2007-07-20 16:21:47 +00:00
|
|
|
} else if (seqcount > 1) {
|
|
|
|
rasize = blsize;
|
|
|
|
error = breadn(vp, lbn,
|
|
|
|
blsize, &rablock, &rasize, 1, NOCRED, &bp);
|
1994-09-19 15:41:57 +00:00
|
|
|
} else {
|
2007-07-20 16:21:47 +00:00
|
|
|
error = bread(vp, lbn, blsize, NOCRED, &bp);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
if (error) {
|
|
|
|
brelse(bp);
|
1999-07-25 04:01:32 +00:00
|
|
|
break;
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
2000-01-02 03:30:42 +00:00
|
|
|
diff = pmp->pm_bpcluster - on;
|
|
|
|
n = diff > uio->uio_resid ? uio->uio_resid : diff;
|
|
|
|
diff = dep->de_FileSize - uio->uio_offset;
|
|
|
|
if (diff < n)
|
|
|
|
n = diff;
|
|
|
|
diff = blsize - bp->b_resid;
|
|
|
|
if (diff < n)
|
|
|
|
n = diff;
|
1994-09-19 15:41:57 +00:00
|
|
|
error = uiomove(bp->b_data + on, (int) n, uio);
|
|
|
|
brelse(bp);
|
|
|
|
} while (error == 0 && uio->uio_resid > 0 && n != 0);
|
1999-07-25 04:01:32 +00:00
|
|
|
if (!isadir && (error == 0 || uio->uio_resid != orig_resid) &&
|
2014-10-11 19:09:56 +00:00
|
|
|
(vp->v_mount->mnt_flag & (MNT_NOATIME | MNT_RDONLY)) == 0)
|
1998-11-29 22:38:57 +00:00
|
|
|
dep->de_flag |= DE_ACCESS;
|
1998-02-18 09:28:47 +00:00
|
|
|
return (error);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write data to a file or directory.
|
|
|
|
*/
|
1995-10-29 15:33:36 +00:00
|
|
|
static int
|
2015-01-09 14:50:08 +00:00
|
|
|
msdosfs_write(struct vop_write_args *ap)
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
|
|
|
int n;
|
|
|
|
int croffset;
|
2012-02-21 01:05:12 +00:00
|
|
|
ssize_t resid;
|
1998-02-18 09:28:47 +00:00
|
|
|
u_long osize;
|
1994-09-19 15:41:57 +00:00
|
|
|
int error = 0;
|
|
|
|
u_long count;
|
2007-07-20 17:06:57 +00:00
|
|
|
int seqcount;
|
1994-09-19 15:41:57 +00:00
|
|
|
daddr_t bn, lastcn;
|
|
|
|
struct buf *bp;
|
|
|
|
int ioflag = ap->a_ioflag;
|
|
|
|
struct uio *uio = ap->a_uio;
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct vnode *thisvp;
|
|
|
|
struct denode *dep = VTODE(vp);
|
|
|
|
struct msdosfsmount *pmp = dep->de_pmp;
|
|
|
|
struct ucred *cred = ap->a_cred;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1994-09-19 15:41:57 +00:00
|
|
|
#ifdef MSDOSFS_DEBUG
|
1998-02-18 09:28:47 +00:00
|
|
|
printf("msdosfs_write(vp %p, uio %p, ioflag %x, cred %p\n",
|
|
|
|
vp, uio, ioflag, cred);
|
|
|
|
printf("msdosfs_write(): diroff %lu, dirclust %lu, startcluster %lu\n",
|
|
|
|
dep->de_diroffset, dep->de_dirclust, dep->de_StartCluster);
|
1994-09-19 15:41:57 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
switch (vp->v_type) {
|
|
|
|
case VREG:
|
|
|
|
if (ioflag & IO_APPEND)
|
|
|
|
uio->uio_offset = dep->de_FileSize;
|
|
|
|
thisvp = vp;
|
|
|
|
break;
|
|
|
|
case VDIR:
|
1998-02-18 09:28:47 +00:00
|
|
|
return EISDIR;
|
1994-09-19 15:41:57 +00:00
|
|
|
default:
|
|
|
|
panic("msdosfs_write(): bad file type");
|
|
|
|
}
|
|
|
|
|
In msdosfs_read() and msdosfs_write(), don't check explicitly for
(uio_offset < 0) since this can't happen. If this happens, then the
general code handles the problem safely (better than before for reading,
returning 0 (EOF) instead of the bogus errno EINVAL, and the same as
before for writing, returning EFBIG).
In msdosfs_read(), don't check for (uio_resid < 0). msdosfs_write()
already didn't check.
In msdosfs_read(), document in a comment our assumptions that the caller
passed a valid uio_offset and uio_resid. ffs checks using KASSERT(),
and that is enough sanity checking. In the same comment, partly document
there is no need to check for the EOVERFLOW case, unlike in ffs where this
case can happen at least in theory.
In msdosfs_write(), add a comment about why the checking of
(uio_resid == 0) is explicit, unlike in ffs.
In msdosfs_write(), check for impossibly large final offsets before
checking if the file size rlimit would be exceeded, so that we don't
have an overflow bug in the rlimit check and are consistent with ffs.
We now return EFBIG instead of EFBIG plus a SIGXFSZ signal if the final
offset would be impossibly large but not so large as to cause overflow.
Overflow normally gave the benign behaviour of no signal.
Approved by: re (kensmith) (blanket)
2007-08-07 10:35:27 +00:00
|
|
|
/*
|
|
|
|
* This is needed (unlike in ffs_write()) because we extend the
|
|
|
|
* file outside of the loop but we don't want to extend the file
|
|
|
|
* for writes of 0 bytes.
|
|
|
|
*/
|
1994-09-19 15:41:57 +00:00
|
|
|
if (uio->uio_resid == 0)
|
1998-02-18 09:28:47 +00:00
|
|
|
return (0);
|
1994-09-19 15:41:57 +00:00
|
|
|
|
In msdosfs_read() and msdosfs_write(), don't check explicitly for
(uio_offset < 0) since this can't happen. If this happens, then the
general code handles the problem safely (better than before for reading,
returning 0 (EOF) instead of the bogus errno EINVAL, and the same as
before for writing, returning EFBIG).
In msdosfs_read(), don't check for (uio_resid < 0). msdosfs_write()
already didn't check.
In msdosfs_read(), document in a comment our assumptions that the caller
passed a valid uio_offset and uio_resid. ffs checks using KASSERT(),
and that is enough sanity checking. In the same comment, partly document
there is no need to check for the EOVERFLOW case, unlike in ffs where this
case can happen at least in theory.
In msdosfs_write(), add a comment about why the checking of
(uio_resid == 0) is explicit, unlike in ffs.
In msdosfs_write(), check for impossibly large final offsets before
checking if the file size rlimit would be exceeded, so that we don't
have an overflow bug in the rlimit check and are consistent with ffs.
We now return EFBIG instead of EFBIG plus a SIGXFSZ signal if the final
offset would be impossibly large but not so large as to cause overflow.
Overflow normally gave the benign behaviour of no signal.
Approved by: re (kensmith) (blanket)
2007-08-07 10:35:27 +00:00
|
|
|
/*
|
|
|
|
* The caller is supposed to ensure that
|
|
|
|
* uio->uio_offset >= 0 and uio->uio_resid >= 0.
|
|
|
|
*/
|
|
|
|
if ((uoff_t)uio->uio_offset + uio->uio_resid > DOS_FILESIZE_MAX)
|
|
|
|
return (EFBIG);
|
|
|
|
|
1994-09-19 15:41:57 +00:00
|
|
|
/*
|
|
|
|
* If they've exceeded their filesize limit, tell them about it.
|
|
|
|
*/
|
2010-05-06 18:43:19 +00:00
|
|
|
if (vn_rlimit_fsize(vp, uio, uio->uio_td))
|
2010-05-05 16:44:25 +00:00
|
|
|
return (EFBIG);
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the offset we are starting the write at is beyond the end of
|
|
|
|
* the file, then they've done a seek. Unix filesystems allow
|
|
|
|
* files with holes in them, DOS doesn't so we must fill the hole
|
|
|
|
* with zeroed blocks.
|
|
|
|
*/
|
|
|
|
if (uio->uio_offset > dep->de_FileSize) {
|
|
|
|
error = deextend(dep, uio->uio_offset, cred);
|
|
|
|
if (error)
|
1998-02-18 09:28:47 +00:00
|
|
|
return (error);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remember some values in case the write fails.
|
|
|
|
*/
|
|
|
|
resid = uio->uio_resid;
|
|
|
|
osize = dep->de_FileSize;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we write beyond the end of the file, extend it to its ultimate
|
|
|
|
* size ahead of the time to hopefully get a contiguous area.
|
|
|
|
*/
|
|
|
|
if (uio->uio_offset + resid > osize) {
|
1998-02-18 09:28:47 +00:00
|
|
|
count = de_clcount(pmp, uio->uio_offset + resid) -
|
|
|
|
de_clcount(pmp, osize);
|
|
|
|
error = extendfile(dep, count, NULL, NULL, 0);
|
|
|
|
if (error && (error != ENOSPC || (ioflag & IO_UNIT)))
|
1994-09-19 15:41:57 +00:00
|
|
|
goto errexit;
|
|
|
|
lastcn = dep->de_fc[FC_LASTFC].fc_frcn;
|
|
|
|
} else
|
|
|
|
lastcn = de_clcount(pmp, osize) - 1;
|
1995-05-30 08:16:23 +00:00
|
|
|
|
2007-07-20 17:06:57 +00:00
|
|
|
seqcount = ioflag >> IO_SEQSHIFT;
|
1994-09-19 15:41:57 +00:00
|
|
|
do {
|
1998-02-18 09:28:47 +00:00
|
|
|
if (de_cluster(pmp, uio->uio_offset) > lastcn) {
|
1994-09-19 15:41:57 +00:00
|
|
|
error = ENOSPC;
|
|
|
|
break;
|
|
|
|
}
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1996-10-02 05:01:17 +00:00
|
|
|
croffset = uio->uio_offset & pmp->pm_crbomask;
|
|
|
|
n = min(uio->uio_resid, pmp->pm_bpcluster - croffset);
|
|
|
|
if (uio->uio_offset + n > dep->de_FileSize) {
|
|
|
|
dep->de_FileSize = uio->uio_offset + n;
|
|
|
|
/* The object size needs to be set before buffer is allocated */
|
|
|
|
vnode_pager_setsize(vp, dep->de_FileSize);
|
|
|
|
}
|
|
|
|
|
1998-03-03 02:50:24 +00:00
|
|
|
bn = de_cluster(pmp, uio->uio_offset);
|
1994-09-19 15:41:57 +00:00
|
|
|
if ((uio->uio_offset & pmp->pm_crbomask) == 0
|
2003-03-02 15:56:49 +00:00
|
|
|
&& (de_cluster(pmp, uio->uio_offset + uio->uio_resid)
|
|
|
|
> de_cluster(pmp, uio->uio_offset)
|
1994-09-19 15:41:57 +00:00
|
|
|
|| uio->uio_offset + uio->uio_resid >= dep->de_FileSize)) {
|
|
|
|
/*
|
|
|
|
* If either the whole cluster gets written,
|
|
|
|
* or we write the cluster from its start beyond EOF,
|
|
|
|
* then no need to read data from disk.
|
|
|
|
*/
|
2003-03-04 00:04:44 +00:00
|
|
|
bp = getblk(thisvp, bn, pmp->pm_bpcluster, 0, 0, 0);
|
2007-07-20 16:21:47 +00:00
|
|
|
vfs_bio_clrbuf(bp);
|
1994-09-19 15:41:57 +00:00
|
|
|
/*
|
|
|
|
* Do the bmap now, since pcbmap needs buffers
|
|
|
|
* for the fat table. (see msdosfs_strategy)
|
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
if (bp->b_blkno == bp->b_lblkno) {
|
2002-03-15 18:49:47 +00:00
|
|
|
error = pcbmap(dep, bp->b_lblkno, &bn, 0, 0);
|
1998-02-18 09:28:47 +00:00
|
|
|
if (error)
|
|
|
|
bp->b_blkno = -1;
|
2002-03-15 18:49:47 +00:00
|
|
|
else
|
|
|
|
bp->b_blkno = bn;
|
1998-02-18 09:28:47 +00:00
|
|
|
}
|
|
|
|
if (bp->b_blkno == -1) {
|
|
|
|
brelse(bp);
|
|
|
|
if (!error)
|
|
|
|
error = EIO; /* XXX */
|
|
|
|
break;
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* The block we need to write into exists, so read it in.
|
|
|
|
*/
|
1994-09-27 20:42:59 +00:00
|
|
|
error = bread(thisvp, bn, pmp->pm_bpcluster, cred, &bp);
|
1998-02-18 09:28:47 +00:00
|
|
|
if (error) {
|
|
|
|
brelse(bp);
|
1994-09-19 15:41:57 +00:00
|
|
|
break;
|
1998-02-18 09:28:47 +00:00
|
|
|
}
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Should these vnode_pager_* functions be done on dir
|
|
|
|
* files?
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy the data from user space into the buf header.
|
|
|
|
*/
|
|
|
|
error = uiomove(bp->b_data + croffset, n, uio);
|
1999-12-28 16:14:54 +00:00
|
|
|
if (error) {
|
|
|
|
brelse(bp);
|
|
|
|
break;
|
|
|
|
}
|
1994-09-19 15:41:57 +00:00
|
|
|
|
2007-07-20 17:06:57 +00:00
|
|
|
/* Prepare for clustered writes in some else clauses. */
|
|
|
|
if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERW) == 0)
|
|
|
|
bp->b_flags |= B_CLUSTEROK;
|
|
|
|
|
1994-09-19 15:41:57 +00:00
|
|
|
/*
|
2007-07-20 16:21:47 +00:00
|
|
|
* If IO_SYNC, then each buffer is written synchronously.
|
2007-07-20 17:06:57 +00:00
|
|
|
* Otherwise, if we have a severe page deficiency then
|
|
|
|
* write the buffer asynchronously. Otherwise, if on a
|
2007-07-20 16:21:47 +00:00
|
|
|
* cluster boundary then write the buffer asynchronously,
|
2007-07-20 17:06:57 +00:00
|
|
|
* combining it with contiguous clusters if permitted and
|
|
|
|
* possible, since we don't expect more writes into this
|
2007-07-20 16:21:47 +00:00
|
|
|
* buffer soon. Otherwise, do a delayed write because we
|
|
|
|
* expect more writes into this buffer soon.
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
|
|
|
if (ioflag & IO_SYNC)
|
2007-07-20 16:21:47 +00:00
|
|
|
(void)bwrite(bp);
|
2007-07-20 17:06:57 +00:00
|
|
|
else if (vm_page_count_severe() || buf_dirty_count_severe())
|
1994-09-19 15:41:57 +00:00
|
|
|
bawrite(bp);
|
2007-07-20 17:06:57 +00:00
|
|
|
else if (n + croffset == pmp->pm_bpcluster) {
|
|
|
|
if ((vp->v_mount->mnt_flag & MNT_NOCLUSTERW) == 0)
|
|
|
|
cluster_write(vp, bp, dep->de_FileSize,
|
2013-03-14 20:28:26 +00:00
|
|
|
seqcount, 0);
|
2007-07-20 17:06:57 +00:00
|
|
|
else
|
|
|
|
bawrite(bp);
|
|
|
|
} else
|
1994-09-19 15:41:57 +00:00
|
|
|
bdwrite(bp);
|
|
|
|
dep->de_flag |= DE_UPDATE;
|
|
|
|
} while (error == 0 && uio->uio_resid > 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the write failed and they want us to, truncate the file back
|
|
|
|
* to the size it was before the write was attempted.
|
|
|
|
*/
|
|
|
|
errexit:
|
|
|
|
if (error) {
|
|
|
|
if (ioflag & IO_UNIT) {
|
2012-04-23 13:21:28 +00:00
|
|
|
detrunc(dep, osize, ioflag & IO_SYNC, NOCRED);
|
1994-09-19 15:41:57 +00:00
|
|
|
uio->uio_offset -= resid - uio->uio_resid;
|
|
|
|
uio->uio_resid = resid;
|
|
|
|
} else {
|
2012-04-23 13:21:28 +00:00
|
|
|
detrunc(dep, dep->de_FileSize, ioflag & IO_SYNC, NOCRED);
|
1994-09-19 15:41:57 +00:00
|
|
|
if (uio->uio_resid != resid)
|
|
|
|
error = 0;
|
|
|
|
}
|
1998-02-18 09:28:47 +00:00
|
|
|
} else if (ioflag & IO_SYNC)
|
|
|
|
error = deupdat(dep, 1);
|
|
|
|
return (error);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flush the blocks of a file to disk.
|
|
|
|
*/
|
1995-10-29 15:33:36 +00:00
|
|
|
static int
|
2015-01-09 14:50:08 +00:00
|
|
|
msdosfs_fsync(struct vop_fsync_args *ap)
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
2013-05-02 20:00:11 +00:00
|
|
|
struct vnode *devvp;
|
|
|
|
int allerror, error;
|
2003-02-09 11:28:35 +00:00
|
|
|
|
2007-08-07 03:43:28 +00:00
|
|
|
vop_stdfsync(ap);
|
2013-05-02 20:00:11 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the syncing request comes from fsync(2), sync the entire
|
|
|
|
* FAT and any other metadata that happens to be on devvp. We
|
|
|
|
* need this mainly for the FAT. We write the FAT sloppily, and
|
|
|
|
* syncing it all now is the best we can easily do to get all
|
|
|
|
* directory entries associated with the file (not just the file)
|
|
|
|
* fully synced. The other metadata includes critical metadata
|
|
|
|
* for all directory entries, but only in the MNT_ASYNC case. We
|
|
|
|
* will soon sync all metadata in the file's directory entry.
|
|
|
|
* Non-critical metadata for associated directory entries only
|
|
|
|
* gets synced accidentally, as in most file systems.
|
|
|
|
*/
|
|
|
|
if (ap->a_waitfor == MNT_WAIT) {
|
|
|
|
devvp = VTODE(ap->a_vp)->de_pmp->pm_devvp;
|
|
|
|
vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
|
|
|
|
allerror = VOP_FSYNC(devvp, MNT_WAIT, ap->a_td);
|
|
|
|
VOP_UNLOCK(devvp, 0);
|
|
|
|
} else
|
|
|
|
allerror = 0;
|
|
|
|
|
|
|
|
error = deupdat(VTODE(ap->a_vp), ap->a_waitfor == MNT_WAIT);
|
|
|
|
if (allerror == 0)
|
|
|
|
allerror = error;
|
|
|
|
return (allerror);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
1995-10-29 15:33:36 +00:00
|
|
|
static int
|
2015-01-09 14:50:08 +00:00
|
|
|
msdosfs_remove(struct vop_remove_args *ap)
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
|
|
|
struct denode *dep = VTODE(ap->a_vp);
|
|
|
|
struct denode *ddep = VTODE(ap->a_dvp);
|
1998-05-07 04:58:58 +00:00
|
|
|
int error;
|
1994-09-19 15:41:57 +00:00
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
if (ap->a_vp->v_type == VDIR)
|
|
|
|
error = EPERM;
|
|
|
|
else
|
|
|
|
error = removede(ddep, dep);
|
1994-09-19 15:41:57 +00:00
|
|
|
#ifdef MSDOSFS_DEBUG
|
1998-02-18 09:28:47 +00:00
|
|
|
printf("msdosfs_remove(), dep %p, v_usecount %d\n", dep, ap->a_vp->v_usecount);
|
1994-09-19 15:41:57 +00:00
|
|
|
#endif
|
1998-02-18 09:28:47 +00:00
|
|
|
return (error);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-10-22 14:24:30 +00:00
|
|
|
* DOS filesystems don't know what links are.
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
1995-10-29 15:33:36 +00:00
|
|
|
static int
|
2015-01-09 14:50:08 +00:00
|
|
|
msdosfs_link(struct vop_link_args *ap)
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
1998-05-07 04:58:58 +00:00
|
|
|
return (EOPNOTSUPP);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Renames on files require moving the denode to a new hash queue since the
|
|
|
|
* denode's location is used to compute which hash queue to put the file
|
|
|
|
* in. Unless it is a rename in place. For example "mv a b".
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1994-09-19 15:41:57 +00:00
|
|
|
* What follows is the basic algorithm:
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1994-09-19 15:41:57 +00:00
|
|
|
* if (file move) {
|
|
|
|
* if (dest file exists) {
|
|
|
|
* remove dest file
|
|
|
|
* }
|
|
|
|
* if (dest and src in same directory) {
|
|
|
|
* rewrite name in existing directory slot
|
|
|
|
* } else {
|
|
|
|
* write new entry in dest directory
|
|
|
|
* update offset and dirclust in denode
|
|
|
|
* move denode to new hash chain
|
|
|
|
* clear old directory entry
|
|
|
|
* }
|
|
|
|
* } else {
|
|
|
|
* directory move
|
|
|
|
* if (dest directory exists) {
|
|
|
|
* if (dest is not empty) {
|
|
|
|
* return ENOTEMPTY
|
|
|
|
* }
|
|
|
|
* remove dest directory
|
|
|
|
* }
|
|
|
|
* if (dest and src in same directory) {
|
|
|
|
* rewrite name in existing entry
|
|
|
|
* } else {
|
|
|
|
* be sure dest is not a child of src directory
|
|
|
|
* write entry in dest directory
|
|
|
|
* update "." and ".." in moved directory
|
|
|
|
* clear old directory entry for moved directory
|
|
|
|
* }
|
|
|
|
* }
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1994-09-19 15:41:57 +00:00
|
|
|
* On entry:
|
|
|
|
* source's parent directory is unlocked
|
|
|
|
* source file or directory is unlocked
|
|
|
|
* destination's parent directory is locked
|
|
|
|
* destination file or directory is locked if it exists
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1994-09-19 15:41:57 +00:00
|
|
|
* On exit:
|
|
|
|
* all denodes should be released
|
|
|
|
*/
|
1995-10-29 15:33:36 +00:00
|
|
|
static int
|
2015-01-09 14:50:08 +00:00
|
|
|
msdosfs_rename(struct vop_rename_args *ap)
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
1998-02-18 09:28:47 +00:00
|
|
|
struct vnode *tdvp = ap->a_tdvp;
|
|
|
|
struct vnode *fvp = ap->a_fvp;
|
|
|
|
struct vnode *fdvp = ap->a_fdvp;
|
1994-09-19 15:41:57 +00:00
|
|
|
struct vnode *tvp = ap->a_tvp;
|
1998-02-18 09:28:47 +00:00
|
|
|
struct componentname *tcnp = ap->a_tcnp;
|
1997-02-26 14:23:16 +00:00
|
|
|
struct componentname *fcnp = ap->a_fcnp;
|
1998-02-18 09:28:47 +00:00
|
|
|
struct denode *ip, *xp, *dp, *zp;
|
2008-07-04 09:40:52 +00:00
|
|
|
u_char toname[12], oldname[11];
|
1998-02-18 09:28:47 +00:00
|
|
|
u_long from_diroffset, to_diroffset;
|
|
|
|
u_char to_count;
|
|
|
|
int doingdirectory = 0, newparent = 0;
|
|
|
|
int error;
|
2013-02-01 18:06:06 +00:00
|
|
|
u_long cn, pcl;
|
1998-02-18 09:28:47 +00:00
|
|
|
daddr_t bn;
|
1994-09-19 15:41:57 +00:00
|
|
|
struct msdosfsmount *pmp;
|
|
|
|
struct direntry *dotdotp;
|
|
|
|
struct buf *bp;
|
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
pmp = VFSTOMSDOSFS(fdvp->v_mount);
|
1994-09-19 15:41:57 +00:00
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if ((tcnp->cn_flags & HASBUF) == 0 ||
|
|
|
|
(fcnp->cn_flags & HASBUF) == 0)
|
|
|
|
panic("msdosfs_rename: no name");
|
|
|
|
#endif
|
1994-09-19 15:41:57 +00:00
|
|
|
/*
|
1998-02-18 09:28:47 +00:00
|
|
|
* Check for cross-device rename.
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
2007-08-07 03:43:28 +00:00
|
|
|
if (fvp->v_mount != tdvp->v_mount ||
|
|
|
|
(tvp && fvp->v_mount != tvp->v_mount)) {
|
1998-02-18 09:28:47 +00:00
|
|
|
error = EXDEV;
|
|
|
|
abortit:
|
|
|
|
if (tdvp == tvp)
|
|
|
|
vrele(tdvp);
|
|
|
|
else
|
|
|
|
vput(tdvp);
|
|
|
|
if (tvp)
|
|
|
|
vput(tvp);
|
|
|
|
vrele(fdvp);
|
|
|
|
vrele(fvp);
|
|
|
|
return (error);
|
|
|
|
}
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
1998-02-18 09:28:47 +00:00
|
|
|
* If source and dest are the same, do nothing.
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
if (tvp == fvp) {
|
|
|
|
error = 0;
|
|
|
|
goto abortit;
|
|
|
|
}
|
|
|
|
|
2008-01-10 01:10:58 +00:00
|
|
|
error = vn_lock(fvp, LK_EXCLUSIVE);
|
1998-02-18 09:28:47 +00:00
|
|
|
if (error)
|
|
|
|
goto abortit;
|
|
|
|
dp = VTODE(fdvp);
|
|
|
|
ip = VTODE(fvp);
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Be sure we are not renaming ".", "..", or an alias of ".". This
|
|
|
|
* leads to a crippled directory tree. It's pretty tough to do a
|
|
|
|
* "ls" or "pwd" with the "." directory entry missing, and "cd .."
|
|
|
|
* doesn't work if the ".." entry is missing.
|
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
if (ip->de_Attributes & ATTR_DIRECTORY) {
|
|
|
|
/*
|
|
|
|
* Avoid ".", "..", and aliases of "." for obvious reasons.
|
|
|
|
*/
|
|
|
|
if ((fcnp->cn_namelen == 1 && fcnp->cn_nameptr[0] == '.') ||
|
|
|
|
dp == ip ||
|
|
|
|
(fcnp->cn_flags & ISDOTDOT) ||
|
|
|
|
(tcnp->cn_flags & ISDOTDOT) ||
|
|
|
|
(ip->de_flag & DE_RENAME)) {
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(fvp, 0);
|
1998-02-18 09:28:47 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto abortit;
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
1998-02-18 09:28:47 +00:00
|
|
|
ip->de_flag |= DE_RENAME;
|
|
|
|
doingdirectory++;
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1998-02-18 09:28:47 +00:00
|
|
|
* When the target exists, both the directory
|
|
|
|
* and target vnodes are returned locked.
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
dp = VTODE(tdvp);
|
|
|
|
xp = tvp ? VTODE(tvp) : NULL;
|
|
|
|
/*
|
|
|
|
* Remember direntry place to use for destination
|
|
|
|
*/
|
|
|
|
to_diroffset = dp->de_fndoffset;
|
|
|
|
to_count = dp->de_fndcnt;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If ".." must be changed (ie the directory gets a new
|
|
|
|
* parent) then the source directory must not be in the
|
2010-02-20 10:19:19 +00:00
|
|
|
* directory hierarchy above the target, as this would
|
1998-02-18 09:28:47 +00:00
|
|
|
* orphan everything below the source directory. Also
|
|
|
|
* the user must have write permission in the source so
|
|
|
|
* as to be able to change "..". We must repeat the call
|
|
|
|
* to namei, as the parent directory is unlocked by the
|
|
|
|
* call to doscheckpath().
|
|
|
|
*/
|
2001-09-12 08:38:13 +00:00
|
|
|
error = VOP_ACCESS(fvp, VWRITE, tcnp->cn_cred, tcnp->cn_thread);
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(fvp, 0);
|
1998-02-18 09:28:47 +00:00
|
|
|
if (VTODE(fdvp)->de_StartCluster != VTODE(tdvp)->de_StartCluster)
|
1994-09-19 15:41:57 +00:00
|
|
|
newparent = 1;
|
1998-02-18 09:28:47 +00:00
|
|
|
if (doingdirectory && newparent) {
|
|
|
|
if (error) /* write access check above */
|
1994-09-19 15:41:57 +00:00
|
|
|
goto bad;
|
1998-02-18 09:28:47 +00:00
|
|
|
if (xp != NULL)
|
|
|
|
vput(tvp);
|
|
|
|
/*
|
|
|
|
* doscheckpath() vput()'s dp,
|
|
|
|
* so we have to do a relookup afterwards
|
|
|
|
*/
|
|
|
|
error = doscheckpath(ip, dp);
|
1994-09-27 20:42:59 +00:00
|
|
|
if (error)
|
1998-02-18 09:28:47 +00:00
|
|
|
goto out;
|
|
|
|
if ((tcnp->cn_flags & SAVESTART) == 0)
|
|
|
|
panic("msdosfs_rename: lost to startdir");
|
|
|
|
error = relookup(tdvp, &tvp, tcnp);
|
|
|
|
if (error)
|
|
|
|
goto out;
|
|
|
|
dp = VTODE(tdvp);
|
|
|
|
xp = tvp ? VTODE(tvp) : NULL;
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
if (xp != NULL) {
|
|
|
|
/*
|
|
|
|
* Target must be empty if a directory and have no links
|
|
|
|
* to it. Also, ensure source and target are compatible
|
|
|
|
* (both directories, or both not directories).
|
|
|
|
*/
|
|
|
|
if (xp->de_Attributes & ATTR_DIRECTORY) {
|
|
|
|
if (!dosdirempty(xp)) {
|
1994-09-19 15:41:57 +00:00
|
|
|
error = ENOTEMPTY;
|
|
|
|
goto bad;
|
|
|
|
}
|
1998-02-18 09:28:47 +00:00
|
|
|
if (!doingdirectory) {
|
|
|
|
error = ENOTDIR;
|
1994-09-19 15:41:57 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
1998-02-18 09:28:47 +00:00
|
|
|
cache_purge(tdvp);
|
|
|
|
} else if (doingdirectory) {
|
|
|
|
error = EISDIR;
|
|
|
|
goto bad;
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
1998-02-18 09:28:47 +00:00
|
|
|
error = removede(dp, xp);
|
1994-09-27 20:42:59 +00:00
|
|
|
if (error)
|
1994-09-19 15:41:57 +00:00
|
|
|
goto bad;
|
1998-02-18 09:28:47 +00:00
|
|
|
vput(tvp);
|
|
|
|
xp = NULL;
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1998-02-18 09:28:47 +00:00
|
|
|
* Convert the filename in tcnp into a dos filename. We copy this
|
|
|
|
* into the denode and directory entry for the destination
|
|
|
|
* file/directory.
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
error = uniqdosname(VTODE(tdvp), tcnp, toname);
|
|
|
|
if (error)
|
|
|
|
goto abortit;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Since from wasn't locked at various places above,
|
|
|
|
* have to do a relookup here.
|
|
|
|
*/
|
|
|
|
fcnp->cn_flags &= ~MODMASK;
|
|
|
|
fcnp->cn_flags |= LOCKPARENT | LOCKLEAF;
|
|
|
|
if ((fcnp->cn_flags & SAVESTART) == 0)
|
|
|
|
panic("msdosfs_rename: lost from startdir");
|
|
|
|
if (!newparent)
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(tdvp, 0);
|
2000-07-14 11:52:56 +00:00
|
|
|
if (relookup(fdvp, &fvp, fcnp) == 0)
|
|
|
|
vrele(fdvp);
|
1998-02-18 09:28:47 +00:00
|
|
|
if (fvp == NULL) {
|
1994-09-19 15:41:57 +00:00
|
|
|
/*
|
1998-02-18 09:28:47 +00:00
|
|
|
* From name has disappeared.
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
if (doingdirectory)
|
|
|
|
panic("rename: lost dir entry");
|
|
|
|
if (newparent)
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(tdvp, 0);
|
1998-02-18 09:28:47 +00:00
|
|
|
vrele(tdvp);
|
2006-02-01 00:25:26 +00:00
|
|
|
vrele(ap->a_fvp);
|
1998-02-18 09:28:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
xp = VTODE(fvp);
|
|
|
|
zp = VTODE(fdvp);
|
|
|
|
from_diroffset = zp->de_fndoffset;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ensure that the directory entry still exists and has not
|
|
|
|
* changed till now. If the source is a file the entry may
|
|
|
|
* have been unlinked or renamed. In either case there is
|
|
|
|
* no further work to be done. If the source is a directory
|
|
|
|
* then it cannot have been rmdir'ed or renamed; this is
|
|
|
|
* prohibited by the DE_RENAME flag.
|
|
|
|
*/
|
|
|
|
if (xp != ip) {
|
|
|
|
if (doingdirectory)
|
|
|
|
panic("rename: lost dir entry");
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(fvp, 0);
|
1998-02-18 09:28:47 +00:00
|
|
|
if (newparent)
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(fdvp, 0);
|
2006-02-01 00:25:26 +00:00
|
|
|
vrele(ap->a_fvp);
|
1998-02-18 09:28:47 +00:00
|
|
|
xp = NULL;
|
1994-09-19 15:41:57 +00:00
|
|
|
} else {
|
1998-02-18 09:28:47 +00:00
|
|
|
vrele(fvp);
|
|
|
|
xp = NULL;
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
1998-02-18 09:28:47 +00:00
|
|
|
* First write a new entry in the destination
|
|
|
|
* directory and mark the entry in the source directory
|
|
|
|
* as deleted. Then move the denode to the correct hash
|
1994-09-19 15:41:57 +00:00
|
|
|
* chain for its new location in the filesystem. And, if
|
|
|
|
* we moved a directory, then update its .. entry to point
|
1998-02-18 09:28:47 +00:00
|
|
|
* to the new parent directory.
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
bcopy(ip->de_Name, oldname, 11);
|
|
|
|
bcopy(toname, ip->de_Name, 11); /* update denode */
|
|
|
|
dp->de_fndoffset = to_diroffset;
|
|
|
|
dp->de_fndcnt = to_count;
|
|
|
|
error = createde(ip, dp, (struct denode **)0, tcnp);
|
1994-09-27 20:42:59 +00:00
|
|
|
if (error) {
|
1998-02-18 09:28:47 +00:00
|
|
|
bcopy(oldname, ip->de_Name, 11);
|
|
|
|
if (newparent)
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(fdvp, 0);
|
|
|
|
VOP_UNLOCK(fvp, 0);
|
1994-09-19 15:41:57 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
2014-05-03 16:11:55 +00:00
|
|
|
/*
|
|
|
|
* If ip is for a directory, then its name should always
|
|
|
|
* be "." since it is for the directory entry in the
|
|
|
|
* directory itself (msdosfs_lookup() always translates
|
|
|
|
* to the "." entry so as to get a unique denode, except
|
|
|
|
* for the root directory there are different
|
|
|
|
* complications). However, we just corrupted its name
|
|
|
|
* to pass the correct name to createde(). Undo this.
|
|
|
|
*/
|
|
|
|
if ((ip->de_Attributes & ATTR_DIRECTORY) != 0)
|
|
|
|
bcopy(oldname, ip->de_Name, 11);
|
1998-02-18 09:28:47 +00:00
|
|
|
ip->de_refcnt++;
|
|
|
|
zp->de_fndoffset = from_diroffset;
|
|
|
|
error = removede(zp, ip);
|
1994-09-27 20:42:59 +00:00
|
|
|
if (error) {
|
2006-01-23 17:45:57 +00:00
|
|
|
/* XXX should downgrade to ro here, fs is corrupt */
|
1998-02-18 09:28:47 +00:00
|
|
|
if (newparent)
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(fdvp, 0);
|
|
|
|
VOP_UNLOCK(fvp, 0);
|
1994-09-19 15:41:57 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
1998-02-18 09:28:47 +00:00
|
|
|
if (!doingdirectory) {
|
|
|
|
error = pcbmap(dp, de_cluster(pmp, to_diroffset), 0,
|
|
|
|
&ip->de_dirclust, 0);
|
|
|
|
if (error) {
|
2006-01-23 17:45:57 +00:00
|
|
|
/* XXX should downgrade to ro here, fs is corrupt */
|
1998-02-18 09:28:47 +00:00
|
|
|
if (newparent)
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(fdvp, 0);
|
|
|
|
VOP_UNLOCK(fvp, 0);
|
1998-02-18 09:28:47 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
1998-09-13 15:39:01 +00:00
|
|
|
if (ip->de_dirclust == MSDOSFSROOT)
|
|
|
|
ip->de_diroffset = to_diroffset;
|
|
|
|
else
|
1998-02-18 09:28:47 +00:00
|
|
|
ip->de_diroffset = to_diroffset & pmp->pm_crbomask;
|
1995-06-11 19:33:05 +00:00
|
|
|
}
|
1998-02-18 09:28:47 +00:00
|
|
|
reinsert(ip);
|
|
|
|
if (newparent)
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(fdvp, 0);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we moved a directory to a new parent directory, then we must
|
|
|
|
* fixup the ".." entry in the moved directory.
|
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
if (doingdirectory && newparent) {
|
|
|
|
cn = ip->de_StartCluster;
|
1994-09-19 15:41:57 +00:00
|
|
|
if (cn == MSDOSFSROOT) {
|
|
|
|
/* this should never happen */
|
1995-03-19 14:29:26 +00:00
|
|
|
panic("msdosfs_rename(): updating .. in root directory?");
|
1998-02-18 09:28:47 +00:00
|
|
|
} else
|
1994-09-19 15:41:57 +00:00
|
|
|
bn = cntobn(pmp, cn);
|
|
|
|
error = bread(pmp->pm_devvp, bn, pmp->pm_bpcluster,
|
|
|
|
NOCRED, &bp);
|
|
|
|
if (error) {
|
2006-01-23 17:45:57 +00:00
|
|
|
/* XXX should downgrade to ro here, fs is corrupt */
|
1998-02-18 09:28:47 +00:00
|
|
|
brelse(bp);
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(fvp, 0);
|
1994-09-19 15:41:57 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
1998-02-18 09:28:47 +00:00
|
|
|
dotdotp = (struct direntry *)bp->b_data + 1;
|
2013-02-01 18:06:06 +00:00
|
|
|
pcl = dp->de_StartCluster;
|
|
|
|
if (FAT32(pmp) && pcl == pmp->pm_rootdirblk)
|
|
|
|
pcl = MSDOSFSROOT;
|
|
|
|
putushort(dotdotp->deStartCluster, pcl);
|
1998-02-18 09:28:47 +00:00
|
|
|
if (FAT32(pmp))
|
2013-02-01 18:06:06 +00:00
|
|
|
putushort(dotdotp->deHighClust, pcl >> 16);
|
2012-02-22 13:01:17 +00:00
|
|
|
if (DOINGASYNC(fvp))
|
2007-10-19 12:23:25 +00:00
|
|
|
bdwrite(bp);
|
|
|
|
else if ((error = bwrite(bp)) != 0) {
|
2006-01-23 17:45:57 +00:00
|
|
|
/* XXX should downgrade to ro here, fs is corrupt */
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(fvp, 0);
|
1994-09-19 15:41:57 +00:00
|
|
|
goto bad;
|
|
|
|
}
|
1998-02-18 09:28:47 +00:00
|
|
|
}
|
|
|
|
|
2010-10-08 07:17:22 +00:00
|
|
|
/*
|
|
|
|
* The msdosfs lookup is case insensitive. Several aliases may
|
|
|
|
* be inserted for a single directory entry. As a consequnce,
|
|
|
|
* name cache purge done by lookup for fvp when DELETE op for
|
|
|
|
* namei is specified, might be not enough to expunge all
|
|
|
|
* namecache entries that were installed for this direntry.
|
|
|
|
*/
|
2010-10-07 08:36:02 +00:00
|
|
|
cache_purge(fvp);
|
2008-01-13 14:44:15 +00:00
|
|
|
VOP_UNLOCK(fvp, 0);
|
1998-02-18 09:28:47 +00:00
|
|
|
bad:
|
|
|
|
if (xp)
|
|
|
|
vput(tvp);
|
|
|
|
vput(tdvp);
|
|
|
|
out:
|
|
|
|
ip->de_flag &= ~DE_RENAME;
|
|
|
|
vrele(fdvp);
|
|
|
|
vrele(fvp);
|
|
|
|
return (error);
|
|
|
|
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
1995-10-29 15:33:36 +00:00
|
|
|
static struct {
|
1994-09-19 15:41:57 +00:00
|
|
|
struct direntry dot;
|
|
|
|
struct direntry dotdot;
|
1998-02-18 09:28:47 +00:00
|
|
|
} dosdirtemplate = {
|
2010-02-13 12:41:07 +00:00
|
|
|
{ ". ", /* the . entry */
|
1998-02-18 09:28:47 +00:00
|
|
|
ATTR_DIRECTORY, /* file attribute */
|
2003-03-02 15:56:49 +00:00
|
|
|
0, /* reserved */
|
1998-02-18 09:28:47 +00:00
|
|
|
0, { 0, 0 }, { 0, 0 }, /* create time & date */
|
|
|
|
{ 0, 0 }, /* access date */
|
|
|
|
{ 0, 0 }, /* high bits of start cluster */
|
|
|
|
{ 210, 4 }, { 210, 4 }, /* modify time & date */
|
|
|
|
{ 0, 0 }, /* startcluster */
|
2003-03-02 15:56:49 +00:00
|
|
|
{ 0, 0, 0, 0 } /* filesize */
|
1998-02-18 09:28:47 +00:00
|
|
|
},
|
2010-02-13 12:41:07 +00:00
|
|
|
{ ".. ", /* the .. entry */
|
1998-02-18 09:28:47 +00:00
|
|
|
ATTR_DIRECTORY, /* file attribute */
|
2003-03-02 15:56:49 +00:00
|
|
|
0, /* reserved */
|
1998-02-18 09:28:47 +00:00
|
|
|
0, { 0, 0 }, { 0, 0 }, /* create time & date */
|
|
|
|
{ 0, 0 }, /* access date */
|
|
|
|
{ 0, 0 }, /* high bits of start cluster */
|
|
|
|
{ 210, 4 }, { 210, 4 }, /* modify time & date */
|
|
|
|
{ 0, 0 }, /* startcluster */
|
|
|
|
{ 0, 0, 0, 0 } /* filesize */
|
|
|
|
}
|
1994-09-19 15:41:57 +00:00
|
|
|
};
|
|
|
|
|
1995-10-29 15:33:36 +00:00
|
|
|
static int
|
2015-01-09 14:50:08 +00:00
|
|
|
msdosfs_mkdir(struct vop_mkdir_args *ap)
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
1998-02-18 09:28:47 +00:00
|
|
|
struct componentname *cnp = ap->a_cnp;
|
|
|
|
struct denode *dep;
|
|
|
|
struct denode *pdep = VTODE(ap->a_dvp);
|
1994-09-19 15:41:57 +00:00
|
|
|
struct direntry *denp;
|
1998-02-18 09:28:47 +00:00
|
|
|
struct msdosfsmount *pmp = pdep->de_pmp;
|
1994-09-19 15:41:57 +00:00
|
|
|
struct buf *bp;
|
1998-05-07 04:58:58 +00:00
|
|
|
u_long newcluster, pcl;
|
|
|
|
int bn;
|
|
|
|
int error;
|
|
|
|
struct denode ndirent;
|
1994-09-19 15:41:57 +00:00
|
|
|
struct timespec ts;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is the root directory and there is no space left we
|
|
|
|
* can't do anything. This is because the root directory can not
|
|
|
|
* change size.
|
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
if (pdep->de_StartCluster == MSDOSFSROOT
|
|
|
|
&& pdep->de_fndoffset >= pdep->de_FileSize) {
|
|
|
|
error = ENOSPC;
|
|
|
|
goto bad2;
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a cluster to hold the about to be created directory.
|
|
|
|
*/
|
1994-09-27 20:42:59 +00:00
|
|
|
error = clusteralloc(pmp, 0, 1, CLUST_EOFE, &newcluster, NULL);
|
1998-02-18 09:28:47 +00:00
|
|
|
if (error)
|
|
|
|
goto bad2;
|
|
|
|
|
|
|
|
bzero(&ndirent, sizeof(ndirent));
|
|
|
|
ndirent.de_pmp = pmp;
|
|
|
|
ndirent.de_flag = DE_ACCESS | DE_CREATE | DE_UPDATE;
|
1998-03-26 20:54:05 +00:00
|
|
|
getnanotime(&ts);
|
1998-02-18 09:28:47 +00:00
|
|
|
DETIMES(&ndirent, &ts, &ts, &ts);
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now fill the cluster with the "." and ".." entries. And write
|
|
|
|
* the cluster to disk. This way it is there for the parent
|
|
|
|
* directory to be pointing at if there were a crash.
|
|
|
|
*/
|
|
|
|
bn = cntobn(pmp, newcluster);
|
|
|
|
/* always succeeds */
|
2003-03-04 00:04:44 +00:00
|
|
|
bp = getblk(pmp->pm_devvp, bn, pmp->pm_bpcluster, 0, 0, 0);
|
1994-09-19 15:41:57 +00:00
|
|
|
bzero(bp->b_data, pmp->pm_bpcluster);
|
|
|
|
bcopy(&dosdirtemplate, bp->b_data, sizeof dosdirtemplate);
|
1998-02-18 09:28:47 +00:00
|
|
|
denp = (struct direntry *)bp->b_data;
|
|
|
|
putushort(denp[0].deStartCluster, newcluster);
|
|
|
|
putushort(denp[0].deCDate, ndirent.de_CDate);
|
|
|
|
putushort(denp[0].deCTime, ndirent.de_CTime);
|
|
|
|
denp[0].deCHundredth = ndirent.de_CHun;
|
|
|
|
putushort(denp[0].deADate, ndirent.de_ADate);
|
|
|
|
putushort(denp[0].deMDate, ndirent.de_MDate);
|
|
|
|
putushort(denp[0].deMTime, ndirent.de_MTime);
|
|
|
|
pcl = pdep->de_StartCluster;
|
2013-02-01 18:06:06 +00:00
|
|
|
/*
|
|
|
|
* Although the root directory has a non-magic starting cluster
|
|
|
|
* number for FAT32, chkdsk and fsck_msdosfs still require
|
|
|
|
* references to it in dotdot entries to be magic.
|
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
if (FAT32(pmp) && pcl == pmp->pm_rootdirblk)
|
2013-02-01 18:06:06 +00:00
|
|
|
pcl = MSDOSFSROOT;
|
1998-02-18 09:28:47 +00:00
|
|
|
putushort(denp[1].deStartCluster, pcl);
|
|
|
|
putushort(denp[1].deCDate, ndirent.de_CDate);
|
|
|
|
putushort(denp[1].deCTime, ndirent.de_CTime);
|
|
|
|
denp[1].deCHundredth = ndirent.de_CHun;
|
|
|
|
putushort(denp[1].deADate, ndirent.de_ADate);
|
|
|
|
putushort(denp[1].deMDate, ndirent.de_MDate);
|
|
|
|
putushort(denp[1].deMTime, ndirent.de_MTime);
|
|
|
|
if (FAT32(pmp)) {
|
|
|
|
putushort(denp[0].deHighClust, newcluster >> 16);
|
2013-02-01 18:06:06 +00:00
|
|
|
putushort(denp[1].deHighClust, pcl >> 16);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
2012-02-22 13:01:17 +00:00
|
|
|
if (DOINGASYNC(ap->a_dvp))
|
2007-10-19 12:23:25 +00:00
|
|
|
bdwrite(bp);
|
|
|
|
else if ((error = bwrite(bp)) != 0)
|
1998-02-18 09:28:47 +00:00
|
|
|
goto bad;
|
|
|
|
|
1994-09-19 15:41:57 +00:00
|
|
|
/*
|
|
|
|
* Now build up a directory entry pointing to the newly allocated
|
|
|
|
* cluster. This will be written to an empty slot in the parent
|
|
|
|
* directory.
|
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if ((cnp->cn_flags & HASBUF) == 0)
|
|
|
|
panic("msdosfs_mkdir: no name");
|
1994-09-19 15:41:57 +00:00
|
|
|
#endif
|
1998-02-18 09:28:47 +00:00
|
|
|
error = uniqdosname(pdep, cnp, ndirent.de_Name);
|
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
|
|
|
|
ndirent.de_Attributes = ATTR_DIRECTORY;
|
1998-11-21 00:20:24 +00:00
|
|
|
ndirent.de_LowerCase = 0;
|
1998-02-18 09:28:47 +00:00
|
|
|
ndirent.de_StartCluster = newcluster;
|
|
|
|
ndirent.de_FileSize = 0;
|
|
|
|
error = createde(&ndirent, pdep, &dep, cnp);
|
|
|
|
if (error)
|
|
|
|
goto bad;
|
|
|
|
*ap->a_vpp = DETOV(dep);
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
bad:
|
|
|
|
clusterfree(pmp, newcluster, NULL);
|
|
|
|
bad2:
|
|
|
|
return (error);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
1995-10-29 15:33:36 +00:00
|
|
|
static int
|
2015-01-09 14:50:08 +00:00
|
|
|
msdosfs_rmdir(struct vop_rmdir_args *ap)
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
2003-03-02 15:56:49 +00:00
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct vnode *dvp = ap->a_dvp;
|
|
|
|
struct componentname *cnp = ap->a_cnp;
|
|
|
|
struct denode *ip, *dp;
|
1998-02-18 09:28:47 +00:00
|
|
|
int error;
|
2003-03-02 15:56:49 +00:00
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
ip = VTODE(vp);
|
|
|
|
dp = VTODE(dvp);
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
1998-02-18 09:28:47 +00:00
|
|
|
* Verify the directory is empty (and valid).
|
|
|
|
* (Rmdir ".." won't be valid since
|
|
|
|
* ".." will contain a reference to
|
|
|
|
* the current directory and thus be
|
|
|
|
* non-empty.)
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
error = 0;
|
|
|
|
if (!dosdirempty(ip) || ip->de_flag & DE_RENAME) {
|
1994-09-19 15:41:57 +00:00
|
|
|
error = ENOTEMPTY;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Delete the entry from the directory. For dos filesystems this
|
|
|
|
* gets rid of the directory entry on disk, the in memory copy
|
|
|
|
* still exists but the de_refcnt is <= 0. This prevents it from
|
|
|
|
* being found by deget(). When the vput() on dep is done we give
|
|
|
|
* up access and eventually msdosfs_reclaim() will be called which
|
|
|
|
* will remove it from the denode cache.
|
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
error = removede(dp, ip);
|
1994-09-27 20:42:59 +00:00
|
|
|
if (error)
|
1994-09-19 15:41:57 +00:00
|
|
|
goto out;
|
|
|
|
/*
|
|
|
|
* This is where we decrement the link count in the parent
|
|
|
|
* directory. Since dos filesystems don't do this we just purge
|
1998-05-07 04:58:58 +00:00
|
|
|
* the name cache.
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
cache_purge(dvp);
|
1994-09-19 15:41:57 +00:00
|
|
|
/*
|
|
|
|
* Truncate the directory that is being deleted.
|
|
|
|
*/
|
2012-04-23 13:21:28 +00:00
|
|
|
error = detrunc(ip, (u_long)0, IO_SYNC, cnp->cn_cred);
|
1998-02-18 09:28:47 +00:00
|
|
|
cache_purge(vp);
|
1998-05-07 04:58:58 +00:00
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
out:
|
|
|
|
return (error);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DOS filesystems don't know what symlinks are.
|
|
|
|
*/
|
1995-10-29 15:33:36 +00:00
|
|
|
static int
|
2015-01-09 14:50:08 +00:00
|
|
|
msdosfs_symlink(struct vop_symlink_args *ap)
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
1998-02-18 09:28:47 +00:00
|
|
|
return (EOPNOTSUPP);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
1995-10-29 15:33:36 +00:00
|
|
|
static int
|
2015-01-09 14:50:08 +00:00
|
|
|
msdosfs_readdir(struct vop_readdir_args *ap)
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
2007-08-31 22:29:55 +00:00
|
|
|
struct mbnambuf nb;
|
1994-09-19 15:41:57 +00:00
|
|
|
int error = 0;
|
|
|
|
int diff;
|
|
|
|
long n;
|
1998-02-18 09:28:47 +00:00
|
|
|
int blsize;
|
1994-09-19 15:41:57 +00:00
|
|
|
long on;
|
|
|
|
u_long cn;
|
2004-07-03 13:22:38 +00:00
|
|
|
uint64_t fileno;
|
1998-02-18 09:28:47 +00:00
|
|
|
u_long dirsperblk;
|
1994-09-19 15:41:57 +00:00
|
|
|
long bias = 0;
|
1998-02-18 09:28:47 +00:00
|
|
|
daddr_t bn, lbn;
|
1994-09-19 15:41:57 +00:00
|
|
|
struct buf *bp;
|
|
|
|
struct denode *dep = VTODE(ap->a_vp);
|
|
|
|
struct msdosfsmount *pmp = dep->de_pmp;
|
|
|
|
struct direntry *dentp;
|
1998-02-18 09:28:47 +00:00
|
|
|
struct dirent dirbuf;
|
1994-09-19 15:41:57 +00:00
|
|
|
struct uio *uio = ap->a_uio;
|
1998-02-18 09:28:47 +00:00
|
|
|
u_long *cookies = NULL;
|
1994-09-28 16:45:22 +00:00
|
|
|
int ncookies = 0;
|
1998-02-18 09:28:47 +00:00
|
|
|
off_t offset, off;
|
|
|
|
int chksum = -1;
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
#ifdef MSDOSFS_DEBUG
|
1998-02-18 09:28:47 +00:00
|
|
|
printf("msdosfs_readdir(): vp %p, uio %p, cred %p, eofflagp %p\n",
|
|
|
|
ap->a_vp, uio, ap->a_cred, ap->a_eofflag);
|
1994-09-19 15:41:57 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* msdosfs_readdir() won't operate properly on regular files since
|
2011-02-21 09:01:34 +00:00
|
|
|
* it does i/o only with the filesystem vnode, and hence can
|
1994-09-19 15:41:57 +00:00
|
|
|
* retrieve the wrong block from the buffer cache for a plain file.
|
|
|
|
* So, fail attempts to readdir() on a plain file.
|
|
|
|
*/
|
|
|
|
if ((dep->de_Attributes & ATTR_DIRECTORY) == 0)
|
1998-02-18 09:28:47 +00:00
|
|
|
return (ENOTDIR);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* To be safe, initialize dirbuf
|
|
|
|
*/
|
|
|
|
bzero(dirbuf.d_name, sizeof(dirbuf.d_name));
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the user buffer is smaller than the size of one dos directory
|
|
|
|
* entry or the file offset is not a multiple of the size of a
|
|
|
|
* directory entry, then we fail the read.
|
|
|
|
*/
|
1998-02-26 06:45:46 +00:00
|
|
|
off = offset = uio->uio_offset;
|
|
|
|
if (uio->uio_resid < sizeof(struct direntry) ||
|
1998-02-18 09:28:47 +00:00
|
|
|
(offset & (sizeof(struct direntry) - 1)))
|
|
|
|
return (EINVAL);
|
|
|
|
|
|
|
|
if (ap->a_ncookies) {
|
|
|
|
ncookies = uio->uio_resid / 16;
|
2008-10-23 15:53:51 +00:00
|
|
|
cookies = malloc(ncookies * sizeof(u_long), M_TEMP,
|
2003-02-19 05:47:46 +00:00
|
|
|
M_WAITOK);
|
1998-02-18 09:28:47 +00:00
|
|
|
*ap->a_cookies = cookies;
|
|
|
|
*ap->a_ncookies = ncookies;
|
|
|
|
}
|
|
|
|
|
|
|
|
dirsperblk = pmp->pm_BytesPerSec / sizeof(struct direntry);
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If they are reading from the root directory then, we simulate
|
|
|
|
* the . and .. entries since these don't exist in the root
|
|
|
|
* directory. We also set the offset bias to make up for having to
|
|
|
|
* simulate these entries. By this I mean that at file offset 64 we
|
|
|
|
* read the first entry in the root directory that lives on disk.
|
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
if (dep->de_StartCluster == MSDOSFSROOT
|
|
|
|
|| (FAT32(pmp) && dep->de_StartCluster == pmp->pm_rootdirblk)) {
|
|
|
|
#if 0
|
|
|
|
printf("msdosfs_readdir(): going after . or .. in root dir, offset %d\n",
|
|
|
|
offset);
|
|
|
|
#endif
|
1994-09-19 15:41:57 +00:00
|
|
|
bias = 2 * sizeof(struct direntry);
|
1998-02-18 09:28:47 +00:00
|
|
|
if (offset < bias) {
|
|
|
|
for (n = (int)offset / sizeof(struct direntry);
|
|
|
|
n < 2; n++) {
|
|
|
|
if (FAT32(pmp))
|
2004-07-03 13:22:38 +00:00
|
|
|
fileno = (uint64_t)cntobn(pmp,
|
1998-02-18 09:28:47 +00:00
|
|
|
pmp->pm_rootdirblk)
|
|
|
|
* dirsperblk;
|
|
|
|
else
|
2004-07-03 13:22:38 +00:00
|
|
|
fileno = 1;
|
2007-01-30 03:11:45 +00:00
|
|
|
if (pmp->pm_flags & MSDOSFS_LARGEFS) {
|
|
|
|
dirbuf.d_fileno =
|
|
|
|
msdosfs_fileno_map(pmp->pm_mountp,
|
|
|
|
fileno);
|
|
|
|
} else {
|
|
|
|
|
|
|
|
dirbuf.d_fileno = (uint32_t)fileno;
|
|
|
|
}
|
1998-02-18 09:28:47 +00:00
|
|
|
dirbuf.d_type = DT_DIR;
|
|
|
|
switch (n) {
|
|
|
|
case 0:
|
|
|
|
dirbuf.d_namlen = 1;
|
|
|
|
strcpy(dirbuf.d_name, ".");
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
dirbuf.d_namlen = 2;
|
|
|
|
strcpy(dirbuf.d_name, "..");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
dirbuf.d_reclen = GENERIC_DIRSIZ(&dirbuf);
|
|
|
|
if (uio->uio_resid < dirbuf.d_reclen)
|
|
|
|
goto out;
|
2003-03-02 15:50:23 +00:00
|
|
|
error = uiomove(&dirbuf, dirbuf.d_reclen, uio);
|
1998-02-18 09:28:47 +00:00
|
|
|
if (error)
|
|
|
|
goto out;
|
1998-02-26 06:45:46 +00:00
|
|
|
offset += sizeof(struct direntry);
|
|
|
|
off = offset;
|
1998-02-18 09:28:47 +00:00
|
|
|
if (cookies) {
|
|
|
|
*cookies++ = offset;
|
|
|
|
if (--ncookies <= 0)
|
|
|
|
goto out;
|
|
|
|
}
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-02-18 09:28:47 +00:00
|
|
|
|
2007-08-31 22:29:55 +00:00
|
|
|
mbnambuf_init(&nb);
|
1998-02-18 09:28:47 +00:00
|
|
|
off = offset;
|
|
|
|
while (uio->uio_resid > 0) {
|
|
|
|
lbn = de_cluster(pmp, offset - bias);
|
|
|
|
on = (offset - bias) & pmp->pm_crbomask;
|
|
|
|
n = min(pmp->pm_bpcluster - on, uio->uio_resid);
|
|
|
|
diff = dep->de_FileSize - (offset - bias);
|
1995-11-13 18:47:40 +00:00
|
|
|
if (diff <= 0)
|
|
|
|
break;
|
1998-02-18 09:28:47 +00:00
|
|
|
n = min(n, diff);
|
|
|
|
error = pcbmap(dep, lbn, &bn, &cn, &blsize);
|
1994-09-19 15:41:57 +00:00
|
|
|
if (error)
|
|
|
|
break;
|
1998-02-18 09:28:47 +00:00
|
|
|
error = bread(pmp->pm_devvp, bn, blsize, NOCRED, &bp);
|
1994-09-19 15:41:57 +00:00
|
|
|
if (error) {
|
|
|
|
brelse(bp);
|
1998-02-18 09:28:47 +00:00
|
|
|
return (error);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
1998-02-18 09:28:47 +00:00
|
|
|
n = min(n, blsize - bp->b_resid);
|
2003-07-03 14:54:47 +00:00
|
|
|
if (n == 0) {
|
|
|
|
brelse(bp);
|
|
|
|
return (EIO);
|
|
|
|
}
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
1998-02-18 09:28:47 +00:00
|
|
|
* Convert from dos directory entries to fs-independent
|
|
|
|
* directory entries.
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
for (dentp = (struct direntry *)(bp->b_data + on);
|
|
|
|
(char *)dentp < bp->b_data + on + n;
|
|
|
|
dentp++, offset += sizeof(struct direntry)) {
|
|
|
|
#if 0
|
|
|
|
printf("rd: dentp %08x prev %08x crnt %08x deName %02x attr %02x\n",
|
|
|
|
dentp, prev, crnt, dentp->deName[0], dentp->deAttributes);
|
|
|
|
#endif
|
1994-09-19 15:41:57 +00:00
|
|
|
/*
|
1998-02-18 09:28:47 +00:00
|
|
|
* If this is an unused entry, we can stop.
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
if (dentp->deName[0] == SLOT_EMPTY) {
|
|
|
|
brelse(bp);
|
|
|
|
goto out;
|
|
|
|
}
|
1994-09-19 15:41:57 +00:00
|
|
|
/*
|
1998-02-18 09:28:47 +00:00
|
|
|
* Skip deleted entries.
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
if (dentp->deName[0] == SLOT_DELETED) {
|
|
|
|
chksum = -1;
|
2007-08-31 22:29:55 +00:00
|
|
|
mbnambuf_init(&nb);
|
1998-02-18 09:28:47 +00:00
|
|
|
continue;
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
1995-05-30 08:16:23 +00:00
|
|
|
|
1998-02-18 09:28:47 +00:00
|
|
|
/*
|
|
|
|
* Handle Win95 long directory entries
|
|
|
|
*/
|
|
|
|
if (dentp->deAttributes == ATTR_WIN95) {
|
|
|
|
if (pmp->pm_flags & MSDOSFSMNT_SHORTNAME)
|
|
|
|
continue;
|
2007-08-31 22:29:55 +00:00
|
|
|
chksum = win2unixfn(&nb,
|
|
|
|
(struct winentry *)dentp, chksum, pmp);
|
1998-02-18 09:28:47 +00:00
|
|
|
continue;
|
|
|
|
}
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
1998-02-18 09:28:47 +00:00
|
|
|
* Skip volume labels
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
1998-02-18 09:28:47 +00:00
|
|
|
if (dentp->deAttributes & ATTR_VOLUME) {
|
|
|
|
chksum = -1;
|
2007-08-31 22:29:55 +00:00
|
|
|
mbnambuf_init(&nb);
|
1998-02-18 09:28:47 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* This computation of d_fileno must match
|
|
|
|
* the computation of va_fileid in
|
|
|
|
* msdosfs_getattr.
|
|
|
|
*/
|
|
|
|
if (dentp->deAttributes & ATTR_DIRECTORY) {
|
|
|
|
fileno = getushort(dentp->deStartCluster);
|
|
|
|
if (FAT32(pmp))
|
|
|
|
fileno |= getushort(dentp->deHighClust) << 16;
|
|
|
|
/* if this is the root directory */
|
|
|
|
if (fileno == MSDOSFSROOT)
|
|
|
|
if (FAT32(pmp))
|
2004-07-03 13:22:38 +00:00
|
|
|
fileno = (uint64_t)cntobn(pmp,
|
1998-02-18 09:28:47 +00:00
|
|
|
pmp->pm_rootdirblk)
|
|
|
|
* dirsperblk;
|
|
|
|
else
|
|
|
|
fileno = 1;
|
|
|
|
else
|
2004-07-03 13:22:38 +00:00
|
|
|
fileno = (uint64_t)cntobn(pmp, fileno) *
|
|
|
|
dirsperblk;
|
1998-02-18 09:28:47 +00:00
|
|
|
dirbuf.d_type = DT_DIR;
|
|
|
|
} else {
|
2007-08-07 03:43:28 +00:00
|
|
|
fileno = (uoff_t)offset /
|
|
|
|
sizeof(struct direntry);
|
1998-02-18 09:28:47 +00:00
|
|
|
dirbuf.d_type = DT_REG;
|
|
|
|
}
|
2007-01-30 03:11:45 +00:00
|
|
|
if (pmp->pm_flags & MSDOSFS_LARGEFS) {
|
|
|
|
dirbuf.d_fileno =
|
|
|
|
msdosfs_fileno_map(pmp->pm_mountp, fileno);
|
|
|
|
} else
|
|
|
|
dirbuf.d_fileno = (uint32_t)fileno;
|
|
|
|
|
2010-02-13 12:41:07 +00:00
|
|
|
if (chksum != winChksum(dentp->deName)) {
|
1998-02-18 09:28:47 +00:00
|
|
|
dirbuf.d_namlen = dos2unixfn(dentp->deName,
|
|
|
|
(u_char *)dirbuf.d_name,
|
1998-11-21 00:20:24 +00:00
|
|
|
dentp->deLowerCase |
|
|
|
|
((pmp->pm_flags & MSDOSFSMNT_SHORTNAME) ?
|
|
|
|
(LCASE_BASE | LCASE_EXT) : 0),
|
2003-09-26 20:26:25 +00:00
|
|
|
pmp);
|
2007-08-31 22:29:55 +00:00
|
|
|
mbnambuf_init(&nb);
|
2003-09-26 20:26:25 +00:00
|
|
|
} else
|
2007-08-31 22:29:55 +00:00
|
|
|
mbnambuf_flush(&nb, &dirbuf);
|
1998-02-18 09:28:47 +00:00
|
|
|
chksum = -1;
|
|
|
|
dirbuf.d_reclen = GENERIC_DIRSIZ(&dirbuf);
|
|
|
|
if (uio->uio_resid < dirbuf.d_reclen) {
|
|
|
|
brelse(bp);
|
|
|
|
goto out;
|
|
|
|
}
|
2003-03-02 15:50:23 +00:00
|
|
|
error = uiomove(&dirbuf, dirbuf.d_reclen, uio);
|
1998-02-18 09:28:47 +00:00
|
|
|
if (error) {
|
|
|
|
brelse(bp);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (cookies) {
|
1998-02-26 06:45:46 +00:00
|
|
|
*cookies++ = offset + sizeof(struct direntry);
|
1998-02-18 09:28:47 +00:00
|
|
|
if (--ncookies <= 0) {
|
|
|
|
brelse(bp);
|
|
|
|
goto out;
|
|
|
|
}
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
1998-02-26 06:45:46 +00:00
|
|
|
off = offset + sizeof(struct direntry);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
brelse(bp);
|
|
|
|
}
|
1998-02-18 09:28:47 +00:00
|
|
|
out:
|
|
|
|
/* Subtract unused cookies */
|
|
|
|
if (ap->a_ncookies)
|
|
|
|
*ap->a_ncookies -= ncookies;
|
|
|
|
|
1998-02-26 06:45:46 +00:00
|
|
|
uio->uio_offset = off;
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
1994-10-27 18:44:31 +00:00
|
|
|
* Set the eofflag (NFS uses it)
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
1999-05-06 18:13:11 +00:00
|
|
|
if (ap->a_eofflag) {
|
1998-02-18 09:28:47 +00:00
|
|
|
if (dep->de_FileSize - (offset - bias) <= 0)
|
1994-09-28 16:45:22 +00:00
|
|
|
*ap->a_eofflag = 1;
|
|
|
|
else
|
|
|
|
*ap->a_eofflag = 0;
|
1999-05-06 18:13:11 +00:00
|
|
|
}
|
1998-02-18 09:28:47 +00:00
|
|
|
return (error);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
2007-07-20 16:21:47 +00:00
|
|
|
/*-
|
|
|
|
* a_vp - pointer to the file's vnode
|
|
|
|
* a_bn - logical block number within the file (cluster number for us)
|
|
|
|
* a_bop - where to return the bufobj of the special file containing the fs
|
|
|
|
* a_bnp - where to return the "physical" block number corresponding to a_bn
|
|
|
|
* (relative to the special file; units are blocks of size DEV_BSIZE)
|
|
|
|
* a_runp - where to return the "run past" a_bn. This is the count of logical
|
|
|
|
* blocks whose physical blocks (together with a_bn's physical block)
|
|
|
|
* are contiguous.
|
|
|
|
* a_runb - where to return the "run before" a_bn.
|
1994-09-19 15:41:57 +00:00
|
|
|
*/
|
1995-10-29 15:33:36 +00:00
|
|
|
static int
|
2015-01-09 14:50:08 +00:00
|
|
|
msdosfs_bmap(struct vop_bmap_args *ap)
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
2007-07-20 16:21:47 +00:00
|
|
|
struct denode *dep;
|
2007-07-20 17:06:57 +00:00
|
|
|
struct mount *mp;
|
2007-07-20 16:21:47 +00:00
|
|
|
struct msdosfsmount *pmp;
|
|
|
|
struct vnode *vp;
|
2007-07-20 17:06:57 +00:00
|
|
|
daddr_t runbn;
|
2007-07-20 16:21:47 +00:00
|
|
|
u_long cn;
|
2007-07-20 17:06:57 +00:00
|
|
|
int bnpercn, error, maxio, maxrun, run;
|
1994-09-19 15:41:57 +00:00
|
|
|
|
2007-07-20 16:21:47 +00:00
|
|
|
vp = ap->a_vp;
|
|
|
|
dep = VTODE(vp);
|
|
|
|
pmp = dep->de_pmp;
|
2004-11-15 09:18:27 +00:00
|
|
|
if (ap->a_bop != NULL)
|
2007-07-20 16:21:47 +00:00
|
|
|
*ap->a_bop = &pmp->pm_devvp->v_bufobj;
|
1994-09-19 15:41:57 +00:00
|
|
|
if (ap->a_bnp == NULL)
|
1998-02-18 09:28:47 +00:00
|
|
|
return (0);
|
2007-07-20 16:21:47 +00:00
|
|
|
if (ap->a_runp != NULL)
|
1994-09-19 15:41:57 +00:00
|
|
|
*ap->a_runp = 0;
|
2007-07-20 16:21:47 +00:00
|
|
|
if (ap->a_runb != NULL)
|
1995-09-04 00:21:16 +00:00
|
|
|
*ap->a_runb = 0;
|
2007-07-20 16:21:47 +00:00
|
|
|
cn = ap->a_bn;
|
|
|
|
if (cn != ap->a_bn)
|
|
|
|
return (EFBIG);
|
|
|
|
error = pcbmap(dep, cn, ap->a_bnp, NULL, NULL);
|
2007-07-20 17:06:57 +00:00
|
|
|
if (error != 0 || (ap->a_runp == NULL && ap->a_runb == NULL))
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
mp = vp->v_mount;
|
|
|
|
maxio = mp->mnt_iosize_max / mp->mnt_stat.f_iosize;
|
|
|
|
bnpercn = de_cn2bn(pmp, 1);
|
|
|
|
if (ap->a_runp != NULL) {
|
|
|
|
maxrun = ulmin(maxio - 1, pmp->pm_maxcluster - cn);
|
|
|
|
for (run = 1; run <= maxrun; run++) {
|
|
|
|
if (pcbmap(dep, cn + run, &runbn, NULL, NULL) != 0 ||
|
|
|
|
runbn != *ap->a_bnp + run * bnpercn)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*ap->a_runp = run - 1;
|
|
|
|
}
|
|
|
|
if (ap->a_runb != NULL) {
|
|
|
|
maxrun = ulmin(maxio - 1, cn);
|
|
|
|
for (run = 1; run < maxrun; run++) {
|
|
|
|
if (pcbmap(dep, cn - run, &runbn, NULL, NULL) != 0 ||
|
|
|
|
runbn != *ap->a_bnp - run * bnpercn)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*ap->a_runb = run - 1;
|
|
|
|
}
|
|
|
|
return (0);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
1995-10-29 15:33:36 +00:00
|
|
|
static int
|
2015-01-09 14:50:08 +00:00
|
|
|
msdosfs_strategy(struct vop_strategy_args *ap)
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
|
|
|
struct buf *bp = ap->a_bp;
|
2004-10-27 06:48:21 +00:00
|
|
|
struct denode *dep = VTODE(ap->a_vp);
|
2004-10-29 10:40:14 +00:00
|
|
|
struct bufobj *bo;
|
1994-09-19 15:41:57 +00:00
|
|
|
int error = 0;
|
2002-03-15 18:49:47 +00:00
|
|
|
daddr_t blkno;
|
1994-09-19 15:41:57 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we don't already know the filesystem relative block number
|
|
|
|
* then get it using pcbmap(). If pcbmap() returns the block
|
|
|
|
* number as -1 then we've got a hole in the file. DOS filesystems
|
|
|
|
* don't allow files with holes, so we shouldn't ever see this.
|
|
|
|
*/
|
|
|
|
if (bp->b_blkno == bp->b_lblkno) {
|
2002-03-15 18:49:47 +00:00
|
|
|
error = pcbmap(dep, bp->b_lblkno, &blkno, 0, 0);
|
|
|
|
bp->b_blkno = blkno;
|
1998-02-18 09:28:47 +00:00
|
|
|
if (error) {
|
|
|
|
bp->b_error = error;
|
2000-04-02 15:24:56 +00:00
|
|
|
bp->b_ioflags |= BIO_ERROR;
|
2000-04-15 05:54:02 +00:00
|
|
|
bufdone(bp);
|
2008-12-16 21:13:11 +00:00
|
|
|
return (0);
|
1998-02-18 09:28:47 +00:00
|
|
|
}
|
|
|
|
if ((long)bp->b_blkno == -1)
|
|
|
|
vfs_bio_clrbuf(bp);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
if (bp->b_blkno == -1) {
|
2000-04-15 05:54:02 +00:00
|
|
|
bufdone(bp);
|
1998-02-18 09:28:47 +00:00
|
|
|
return (0);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Read/write the block from/to the disk that contains the desired
|
|
|
|
* file block.
|
|
|
|
*/
|
2003-10-18 14:10:28 +00:00
|
|
|
bp->b_iooffset = dbtob(bp->b_blkno);
|
2004-10-29 10:40:14 +00:00
|
|
|
bo = dep->de_pmp->pm_bo;
|
2005-01-11 09:10:46 +00:00
|
|
|
BO_STRATEGY(bo, bp);
|
1998-02-18 09:28:47 +00:00
|
|
|
return (0);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
1995-10-29 15:33:36 +00:00
|
|
|
static int
|
2015-01-09 14:50:08 +00:00
|
|
|
msdosfs_print(struct vop_print_args *ap)
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
|
|
|
struct denode *dep = VTODE(ap->a_vp);
|
|
|
|
|
2003-03-03 19:15:40 +00:00
|
|
|
printf("\tstartcluster %lu, dircluster %lu, diroffset %lu, ",
|
2002-09-18 20:42:04 +00:00
|
|
|
dep->de_StartCluster, dep->de_dirclust, dep->de_diroffset);
|
2009-02-27 20:00:15 +00:00
|
|
|
printf("on dev %s\n", devtoname(dep->de_pmp->pm_dev));
|
1998-02-18 09:28:47 +00:00
|
|
|
return (0);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
1995-10-29 15:33:36 +00:00
|
|
|
static int
|
2015-01-09 14:50:08 +00:00
|
|
|
msdosfs_pathconf(struct vop_pathconf_args *ap)
|
1994-09-19 15:41:57 +00:00
|
|
|
{
|
1998-02-18 09:28:47 +00:00
|
|
|
struct msdosfsmount *pmp = VTODE(ap->a_vp)->de_pmp;
|
|
|
|
|
1994-09-19 15:41:57 +00:00
|
|
|
switch (ap->a_name) {
|
|
|
|
case _PC_LINK_MAX:
|
|
|
|
*ap->a_retval = 1;
|
1998-02-18 09:28:47 +00:00
|
|
|
return (0);
|
1994-09-19 15:41:57 +00:00
|
|
|
case _PC_NAME_MAX:
|
1998-02-18 09:28:47 +00:00
|
|
|
*ap->a_retval = pmp->pm_flags & MSDOSFSMNT_LONGNAME ? WIN_MAXLEN : 12;
|
|
|
|
return (0);
|
1994-09-19 15:41:57 +00:00
|
|
|
case _PC_PATH_MAX:
|
1998-02-18 09:28:47 +00:00
|
|
|
*ap->a_retval = PATH_MAX;
|
|
|
|
return (0);
|
1994-09-19 15:41:57 +00:00
|
|
|
case _PC_CHOWN_RESTRICTED:
|
|
|
|
*ap->a_retval = 1;
|
1998-02-18 09:28:47 +00:00
|
|
|
return (0);
|
1994-09-19 15:41:57 +00:00
|
|
|
case _PC_NO_TRUNC:
|
|
|
|
*ap->a_retval = 0;
|
1998-02-18 09:28:47 +00:00
|
|
|
return (0);
|
1994-09-19 15:41:57 +00:00
|
|
|
default:
|
1998-02-18 09:28:47 +00:00
|
|
|
return (EINVAL);
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
1998-02-18 09:28:47 +00:00
|
|
|
/* NOTREACHED */
|
1994-09-19 15:41:57 +00:00
|
|
|
}
|
|
|
|
|
2007-02-15 22:08:35 +00:00
|
|
|
static int
|
2015-01-09 14:50:08 +00:00
|
|
|
msdosfs_vptofh(struct vop_vptofh_args *ap)
|
2007-02-15 22:08:35 +00:00
|
|
|
{
|
|
|
|
struct denode *dep;
|
|
|
|
struct defid *defhp;
|
|
|
|
|
|
|
|
dep = VTODE(ap->a_vp);
|
|
|
|
defhp = (struct defid *)ap->a_fhp;
|
|
|
|
defhp->defid_len = sizeof(struct defid);
|
|
|
|
defhp->defid_dirclust = dep->de_dirclust;
|
|
|
|
defhp->defid_dirofs = dep->de_diroffset;
|
|
|
|
/* defhp->defid_gen = dep->de_gen; */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1994-09-19 15:41:57 +00:00
|
|
|
/* Global vfs data structures for msdosfs */
|
2004-12-01 23:16:38 +00:00
|
|
|
struct vop_vector msdosfs_vnodeops = {
|
|
|
|
.vop_default = &default_vnodeops,
|
2005-01-13 18:59:48 +00:00
|
|
|
|
2004-12-01 23:16:38 +00:00
|
|
|
.vop_access = msdosfs_access,
|
|
|
|
.vop_bmap = msdosfs_bmap,
|
|
|
|
.vop_cachedlookup = msdosfs_lookup,
|
2005-01-29 16:23:39 +00:00
|
|
|
.vop_open = msdosfs_open,
|
2004-12-01 23:16:38 +00:00
|
|
|
.vop_close = msdosfs_close,
|
|
|
|
.vop_create = msdosfs_create,
|
|
|
|
.vop_fsync = msdosfs_fsync,
|
|
|
|
.vop_getattr = msdosfs_getattr,
|
|
|
|
.vop_inactive = msdosfs_inactive,
|
|
|
|
.vop_link = msdosfs_link,
|
|
|
|
.vop_lookup = vfs_cache_lookup,
|
|
|
|
.vop_mkdir = msdosfs_mkdir,
|
|
|
|
.vop_mknod = msdosfs_mknod,
|
|
|
|
.vop_pathconf = msdosfs_pathconf,
|
|
|
|
.vop_print = msdosfs_print,
|
|
|
|
.vop_read = msdosfs_read,
|
|
|
|
.vop_readdir = msdosfs_readdir,
|
|
|
|
.vop_reclaim = msdosfs_reclaim,
|
|
|
|
.vop_remove = msdosfs_remove,
|
|
|
|
.vop_rename = msdosfs_rename,
|
|
|
|
.vop_rmdir = msdosfs_rmdir,
|
|
|
|
.vop_setattr = msdosfs_setattr,
|
|
|
|
.vop_strategy = msdosfs_strategy,
|
|
|
|
.vop_symlink = msdosfs_symlink,
|
|
|
|
.vop_write = msdosfs_write,
|
2007-02-15 22:08:35 +00:00
|
|
|
.vop_vptofh = msdosfs_vptofh,
|
1994-09-19 15:41:57 +00:00
|
|
|
};
|