From 5e2ef462ec217bde96ca3facd40711db324b1126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 24 Mar 2008 12:04:47 +0000 Subject: [PATCH] * Got rid of the duality of FS_WRITE_STAT_* vs. B_STAT_* flags (removed the former ones). * Removed extraneous white space. * net_server settings are now also updated when the size of the file changed. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24552 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/drivers/fs_interface.h | 21 +- headers/private/fs_shell/fssh_api_wrapper.h | 19 +- headers/private/fs_shell/fssh_fs_interface.h | 19 +- src/add-ons/kernel/file_systems/fat/file.c | 146 +-- .../kernel/file_systems/nfs/nfs_add_on.h | 28 +- .../kernel/file_systems/ntfs/fs_func.c | 860 +++++++++--------- src/servers/net/Settings.cpp | 6 +- src/system/kernel/fs/devfs.cpp | 12 +- src/system/libroot/posix/sys/chmod.c | 14 +- src/system/libroot/posix/unistd/chown.c | 16 +- src/system/libroot/posix/unistd/truncate.c | 13 +- src/system/libroot/posix/utime.c | 12 +- src/tools/fs_shell/fssh.cpp | 13 +- 13 files changed, 576 insertions(+), 603 deletions(-) diff --git a/headers/os/drivers/fs_interface.h b/headers/os/drivers/fs_interface.h index d4330909b9..26a2ccc777 100644 --- a/headers/os/drivers/fs_interface.h +++ b/headers/os/drivers/fs_interface.h @@ -1,5 +1,5 @@ /* - * Copyright 2004-2007, Haiku Inc. All Rights Reserved. + * Copyright 2004-2008, Haiku Inc. All Rights Reserved. * Distributed under the terms of the MIT License. */ #ifndef _FS_INTERFACE_H @@ -26,18 +26,9 @@ typedef void *fs_volume; typedef void *fs_cookie; typedef void *fs_vnode; -/* passed to write_stat() */ -enum write_stat_mask { - FS_WRITE_STAT_MODE = 0x0001, - FS_WRITE_STAT_UID = 0x0002, - FS_WRITE_STAT_GID = 0x0004, - FS_WRITE_STAT_SIZE = 0x0008, - FS_WRITE_STAT_ATIME = 0x0010, - FS_WRITE_STAT_MTIME = 0x0020, - FS_WRITE_STAT_CRTIME = 0x0040 - // NOTE: Changing these constants will break +/* additional flags passed to write_stat() (see NodeMonitor.h for the others) */ + // NOTE: Changing the constants here or in NodeMonitor.h will break // src/kits/storage/LibBeAdapter.cpp:_kern_write_stat(). -}; /* passed to write_fs_info() */ #define FS_WRITE_FSINFO_NAME 0x0001 @@ -51,7 +42,7 @@ struct file_io_vec { #ifdef __cplusplus extern "C" { -#endif +#endif typedef struct file_system_module_info { struct module_info info; @@ -68,7 +59,7 @@ typedef struct file_system_module_info { void (*free_partition_content_cookie)(partition_data *partition); /* general operations */ - status_t (*mount)(dev_t id, const char *device, uint32 flags, + status_t (*mount)(dev_t id, const char *device, uint32 flags, const char *args, fs_volume *_fs, ino_t *_rootVnodeID); status_t (*unmount)(fs_volume fs); @@ -201,7 +192,7 @@ typedef struct file_system_module_info { port_id port, uint32 token, fs_cookie *_cookie); status_t (*close_query)(fs_volume fs, fs_cookie cookie); status_t (*free_query_cookie)(fs_volume fs, fs_cookie cookie); - status_t (*read_query)(fs_volume fs, fs_cookie cookie, + status_t (*read_query)(fs_volume fs, fs_cookie cookie, struct dirent *buffer, size_t bufferSize, uint32 *_num); status_t (*rewind_query)(fs_volume fs, fs_cookie cookie); diff --git a/headers/private/fs_shell/fssh_api_wrapper.h b/headers/private/fs_shell/fssh_api_wrapper.h index 8dcdee60b1..ffb230cb4f 100644 --- a/headers/private/fs_shell/fssh_api_wrapper.h +++ b/headers/private/fs_shell/fssh_api_wrapper.h @@ -874,17 +874,6 @@ #define fs_cookie fssh_fs_cookie #define fs_vnode fssh_fs_vnode -/* passed to write_stat() */ -#define write_stat_mask fssh_write_stat_mask - -#define FS_WRITE_STAT_MODE FSSH_FS_WRITE_STAT_MODE -#define FS_WRITE_STAT_UID FSSH_FS_WRITE_STAT_UID -#define FS_WRITE_STAT_GID FSSH_FS_WRITE_STAT_GID -#define FS_WRITE_STAT_SIZE FSSH_FS_WRITE_STAT_SIZE -#define FS_WRITE_STAT_ATIME FSSH_FS_WRITE_STAT_ATIME -#define FS_WRITE_STAT_MTIME FSSH_FS_WRITE_STAT_MTIME -#define FS_WRITE_STAT_CRTIME FSSH_FS_WRITE_STAT_CRTIME - /* passed to write_fs_info() */ #define FS_WRITE_FSINFO_NAME FSSH_FS_WRITE_FSINFO_NAME @@ -896,7 +885,7 @@ /* file system add-ons only prototypes */ -#define new_vnode fssh_new_vnode +#define new_vnode fssh_new_vnode #define publish_vnode fssh_publish_vnode #define get_vnode fssh_get_vnode #define put_vnode fssh_put_vnode @@ -1099,9 +1088,9 @@ #define suspend_thread fssh_suspend_thread #define rename_thread fssh_rename_thread -#define set_thread_priority fssh_set_thread_priority +#define set_thread_priority fssh_set_thread_priority #define exit_thread fssh_exit_thread -#define wait_for_thread fssh_wait_for_thread +#define wait_for_thread fssh_wait_for_thread #define on_exit_thread fssh_on_exit_thread #define find_thread fssh_find_thread @@ -1497,7 +1486,7 @@ #define sync fssh_sync #define fsync fssh_fsync -/* access permissions */ +/* access permissions */ #define getegid fssh_getegid #define geteuid fssh_geteuid #define getgid fssh_getgid diff --git a/headers/private/fs_shell/fssh_fs_interface.h b/headers/private/fs_shell/fssh_fs_interface.h index 4cbf9fdbb2..4c43c22eb1 100644 --- a/headers/private/fs_shell/fssh_fs_interface.h +++ b/headers/private/fs_shell/fssh_fs_interface.h @@ -1,5 +1,5 @@ /* - * Copyright 2004-2007, Haiku Inc. All Rights Reserved. + * Copyright 2004-2008, Haiku Inc. All Rights Reserved. * Distributed under the terms of the MIT License. */ #ifndef _FSSH_FS_INTERFACE_H @@ -28,16 +28,7 @@ typedef void *fssh_fs_volume; typedef void *fssh_fs_cookie; typedef void *fssh_fs_vnode; -/* passed to write_stat() */ -enum fssh_write_stat_mask { - FSSH_FS_WRITE_STAT_MODE = 0x0001, - FSSH_FS_WRITE_STAT_UID = 0x0002, - FSSH_FS_WRITE_STAT_GID = 0x0004, - FSSH_FS_WRITE_STAT_SIZE = 0x0008, - FSSH_FS_WRITE_STAT_ATIME = 0x0010, - FSSH_FS_WRITE_STAT_MTIME = 0x0020, - FSSH_FS_WRITE_STAT_CRTIME = 0x0040 -}; +/* additional flags passed to write_stat() */ /* passed to write_fs_info() */ #define FSSH_FS_WRITE_FSINFO_NAME 0x0001 @@ -51,7 +42,7 @@ struct fssh_file_io_vec { #ifdef __cplusplus extern "C" { -#endif +#endif typedef struct fssh_file_system_module_info { struct fssh_module_info info; @@ -68,7 +59,7 @@ typedef struct fssh_file_system_module_info { void (*free_partition_content_cookie)(fssh_partition_data *partition); /* general operations */ - fssh_status_t (*mount)(fssh_mount_id id, const char *device, uint32_t flags, + fssh_status_t (*mount)(fssh_mount_id id, const char *device, uint32_t flags, const char *args, fssh_fs_volume *_fs, fssh_vnode_id *_rootVnodeID); fssh_status_t (*unmount)(fssh_fs_volume fs); @@ -235,7 +226,7 @@ typedef struct fssh_file_system_module_info { fssh_status_t (*close_query)(fssh_fs_volume fs, fssh_fs_cookie cookie); fssh_status_t (*free_query_cookie)(fssh_fs_volume fs, fssh_fs_cookie cookie); - fssh_status_t (*read_query)(fssh_fs_volume fs, fssh_fs_cookie cookie, + fssh_status_t (*read_query)(fssh_fs_volume fs, fssh_fs_cookie cookie, struct fssh_dirent *buffer, fssh_size_t bufferSize, uint32_t *_num); fssh_status_t (*rewind_query)(fssh_fs_volume fs, fssh_fs_cookie cookie); diff --git a/src/add-ons/kernel/file_systems/fat/file.c b/src/add-ons/kernel/file_systems/fat/file.c index dede087809..7f41fa9f91 100644 --- a/src/add-ons/kernel/file_systems/fat/file.c +++ b/src/add-ons/kernel/file_systems/fat/file.c @@ -62,7 +62,7 @@ status_t write_vnode_entry(nspace *vol, vnode *node) struct diri diri; uint8 *buffer; - + // TODO : is it needed ? vfs job ? // don't update entries of deleted files //if (is_vnode_removed(vol->id, node->vnid) > 0) return 0; @@ -80,7 +80,7 @@ status_t write_vnode_entry(nspace *vol, vnode *node) return ENOENT; buffer[0x0b] = node->mode; // file attributes - + memset(buffer+0xc, 0, 0x16-0xc); i = time_t2dos(node->st_time); buffer[0x16] = i & 0xff; @@ -113,7 +113,7 @@ status_t write_vnode_entry(nspace *vol, vnode *node) // called when fs is done with vnode // after close, etc. free vnode resources here -status_t +status_t dosfs_release_vnode(void *_vol, void *_node, bool reenter) { nspace *vol = (nspace *)_vol; @@ -127,7 +127,7 @@ dosfs_release_vnode(void *_vol, void *_node, bool reenter) } DPRINTF(0, ("dosfs_write_vnode (ino_t %Lx)\n", ((vnode *)_node)->vnid)); - + if ((vol->fs_flags & FS_FLAGS_OP_SYNC) && node->dirty) { LOCK_VOL(vol); _dosfs_sync(vol); @@ -138,7 +138,7 @@ dosfs_release_vnode(void *_vol, void *_node, bool reenter) #if TRACK_FILENAME if (node->filename) free(node->filename); #endif - + if (node->vnid != vol->root_vnode.vnid) { node->magic = ~VNODE_MAGIC; // munge magic number to be safe file_cache_delete(node->cache); @@ -151,7 +151,7 @@ dosfs_release_vnode(void *_vol, void *_node, bool reenter) } -status_t +status_t dosfs_rstat(void *_vol, void *_node, struct stat *st) { nspace *vol = (nspace*)_vol; @@ -190,7 +190,7 @@ dosfs_rstat(void *_vol, void *_node, struct stat *st) } -status_t +status_t dosfs_wstat(void *_vol, void *_node, const struct stat *st, uint32 mask) { int err = B_OK; @@ -220,7 +220,7 @@ dosfs_wstat(void *_vol, void *_node, const struct stat *st, uint32 mask) return EPERM; } - if (mask & FS_WRITE_STAT_MODE) { + if (mask & B_STAT_MODE) { DPRINTF(0, ("setting file mode to %o\n", st->st_mode)); if (st->st_mode & S_IWUSR) node->mode &= ~FAT_READ_ONLY; @@ -229,7 +229,7 @@ dosfs_wstat(void *_vol, void *_node, const struct stat *st, uint32 mask) dirty = true; } - if (mask & FS_WRITE_STAT_SIZE) { + if (mask & B_STAT_SIZE) { DPRINTF(0, ("setting file size to %Lx\n", st->st_size)); if (node->mode & FAT_SUBDIR) { dprintf("dosfs_wstat: can't set file size of directory!\n"); @@ -249,8 +249,8 @@ dosfs_wstat(void *_vol, void *_node, const struct stat *st, uint32 mask) } } } - - if (mask & FS_WRITE_STAT_MTIME) { + + if (mask & B_STAT_MODIFICATION_TIME) { DPRINTF(0, ("setting modification time\n")); node->st_time = st->st_mtime; dirty = true; @@ -270,12 +270,12 @@ dosfs_wstat(void *_vol, void *_node, const struct stat *st, uint32 mask) if (err != B_OK) DPRINTF(0, ("dosfs_wstat (%s)\n", strerror(err))); UNLOCK_VOL(vol); - + return err; } -status_t +status_t dosfs_open(void *_vol, void *_node, int omode, void **_cookie) { status_t result = EINVAL; @@ -301,7 +301,7 @@ dosfs_open(void *_vol, void *_node, int omode, void **_cookie) goto error; } - if ((vol->flags & B_FS_IS_READONLY) || + if ((vol->flags & B_FS_IS_READONLY) || (node->mode & FAT_READ_ONLY) || (node->disk_image != 0) || // allow opening directories for ioctl() calls @@ -348,7 +348,7 @@ error: } -status_t +status_t dosfs_read(void *_vol, void *_node, void *_cookie, off_t pos, void *buf, size_t *len) { @@ -393,7 +393,7 @@ dosfs_read(void *_vol, void *_node, void *_cookie, off_t pos, // truncate bytes to read to file size if (pos + *len >= node->st_size) *len = node->st_size - pos; - + result = file_cache_read(node->cache, cookie, pos, buf, len); #if 0 @@ -416,7 +416,7 @@ dosfs_read(void *_vol, void *_node, void *_cookie, off_t pos, dprintf("dosfs_read: invalid starting cluster (%lx)\n", cluster1); goto bi; } - + if (diff && ((result = iter_csi(&iter, diff)) != B_OK)) { dprintf("dosfs_read: end of file reached (init)\n"); result = EIO; @@ -480,8 +480,8 @@ dosfs_read(void *_vol, void *_node, void *_cookie, off_t pos, csi_release_block(&iter); bytes_read += amt; } - - if (*len) { + + if (*len) { cookie->ccache.iteration = node->iteration; cookie->ccache.index = (pos + *len - 1) / vol->bytes_per_sector / vol->sectors_per_cluster; cookie->ccache.cluster = iter.cluster; @@ -491,7 +491,7 @@ dosfs_read(void *_vol, void *_node, void *_cookie, off_t pos, result = B_OK; #endif - + bi: if (result != B_OK) { DPRINTF(0, ("dosfs_read (%s)\n", strerror(result))); @@ -499,12 +499,12 @@ bi: DPRINTF(0, ("dosfs_read: read %lx bytes\n", *len)); } UNLOCK_VOL(vol); - + return result; } -status_t +status_t dosfs_write(void *_vol, void *_node, void *_cookie, off_t pos, const void *buf, size_t *len) { @@ -534,11 +534,11 @@ dosfs_write(void *_vol, void *_node, void *_cookie, off_t pos, *len = 0; UNLOCK_VOL(vol); return EISDIR; - + } DPRINTF(0, ("dosfs_write called %lx bytes at %Lx from buffer at %lx (vnode id %Lx)\n", *len, pos, (uint32)buf, node->vnid)); - + if ((cookie->mode & O_RWMASK) == O_RDONLY) { dprintf("dosfs_write: called on file opened as read-only\n"); *len = 0; @@ -547,10 +547,10 @@ dosfs_write(void *_vol, void *_node, void *_cookie, off_t pos, } if (pos < 0) pos = 0; - + if (cookie->mode & O_APPEND) { pos = node->st_size; - } + } if (pos >= MAX_FILE_SIZE) { dprintf("dosfs_write: write position exceeds fat limits\n"); @@ -562,10 +562,10 @@ dosfs_write(void *_vol, void *_node, void *_cookie, off_t pos, if (pos + *len >= MAX_FILE_SIZE) { *len = (size_t)(MAX_FILE_SIZE - pos); } - + #if 0 - if (node->st_size && + if (node->st_size && (cookie->ccache.iteration == node->iteration) && (pos >= cookie->ccache.index * vol->bytes_per_sector * vol->sectors_per_cluster)) { ASSERT(IS_DATA_CLUSTER(cookie->ccache.cluster)); @@ -598,9 +598,9 @@ dosfs_write(void *_vol, void *_node, void *_cookie, off_t pos, file_cache_set_size(node->cache, node->st_size); file_map_set_size(node->file_map, node->st_size); } - + result = file_cache_write(node->cache, cookie, pos, buf, len); - + #if 0 if (cluster1 == 0xffffffff) { cluster1 = node->cluster; @@ -612,7 +612,7 @@ dosfs_write(void *_vol, void *_node, void *_cookie, off_t pos, dprintf("dosfs_write: invalid starting cluster (%lx)\n", cluster1); goto bi; } - + if (diff && ((result = iter_csi(&iter, diff)) != B_OK)) { dprintf("dosfs_write: end of file reached (init)\n"); result = EIO; @@ -682,7 +682,7 @@ dosfs_write(void *_vol, void *_node, void *_cookie, off_t pos, bytes_written += amt; } - if (*len) { + if (*len) { cookie->ccache.iteration = node->iteration; cookie->ccache.index = (pos + *len - 1) / vol->bytes_per_sector / vol->sectors_per_cluster; cookie->ccache.cluster = iter.cluster; @@ -692,7 +692,7 @@ dosfs_write(void *_vol, void *_node, void *_cookie, off_t pos, result = B_OK; #endif - + bi: if (result != B_OK) { DPRINTF(0, ("dosfs_write (%s)\n", strerror(result))); @@ -700,12 +700,12 @@ bi: DPRINTF(0, ("dosfs_write: wrote %lx bytes\n", *len)); } UNLOCK_VOL(vol); - + return result; } -status_t +status_t dosfs_close(void *_vol, void *_node, void *_cookie) { nspace *vol = (nspace *)_vol; @@ -733,7 +733,7 @@ dosfs_close(void *_vol, void *_node, void *_cookie) } -status_t +status_t dosfs_free_cookie(void *_vol, void *_node, void *_cookie) { nspace *vol = _vol; @@ -759,7 +759,7 @@ dosfs_free_cookie(void *_vol, void *_node, void *_cookie) } -status_t +status_t dosfs_create(void *_vol, void *_dir, const char *name, int omode, int perms, void **_cookie, ino_t *vnid) { @@ -768,7 +768,7 @@ dosfs_create(void *_vol, void *_dir, const char *name, int omode, filecookie *cookie; status_t result = EINVAL; bool dups_exist; - + LOCK_VOL(vol); if (check_nspace_magic(vol, "dosfs_create") @@ -785,7 +785,7 @@ dosfs_create(void *_vol, void *_dir, const char *name, int omode, } DPRINTF(0, ("dosfs_create called: %Lx/%s perms=%o omode=%o\n", dir->vnid, name, perms, omode)); - + if (vol->flags & B_FS_IS_READONLY) { dprintf("dosfs_create called on read-only volume\n"); UNLOCK_VOL(vol); @@ -819,7 +819,7 @@ dosfs_create(void *_vol, void *_dir, const char *name, int omode, result = EEXIST; goto bi; } - + if (file->mode & FAT_SUBDIR) { dprintf("can't dosfs_create over an existing subdirectory\n"); put_vnode(vol->id, file->vnid); @@ -839,7 +839,7 @@ dosfs_create(void *_vol, void *_dir, const char *name, int omode, file->st_size = 0; file->iteration++; } - } else if (result == ENOENT && dups_exist) { + } else if (result == ENOENT && dups_exist) { // the file doesn't exist in the exact case, but another does in the // non-exact case. We wont create the new file. result = EEXIST; @@ -884,7 +884,7 @@ dosfs_create(void *_vol, void *_dir, const char *name, int omode, } else { goto bi; } - + cookie->magic = FILECOOKIE_MAGIC; cookie->mode = omode; cookie->ccache.iteration = file->iteration; @@ -902,14 +902,14 @@ dosfs_create(void *_vol, void *_dir, const char *name, int omode, bi: if (result != B_OK) free(cookie); UNLOCK_VOL(vol); - + if (result != B_OK) DPRINTF(0, ("dosfs_create (%s)\n", strerror(result))); return result; } -status_t +status_t dosfs_mkdir(void *_vol, void *_dir, const char *name, int perms, ino_t *_vnid) { nspace *vol = (nspace *)_vol; @@ -918,7 +918,7 @@ dosfs_mkdir(void *_vol, void *_dir, const char *name, int perms, ino_t *_vnid) struct csi csi; uchar *buffer; uint32 i; - + LOCK_VOL(vol); if (check_nspace_magic(vol, "dosfs_mkdir") @@ -1061,7 +1061,7 @@ bi: dummy.magic = ~VNODE_MAGIC; } -status_t +status_t dosfs_rename(void *_vol, void *_odir, const char *oldname, void *_ndir, const char *newname) { @@ -1182,7 +1182,7 @@ dosfs_rename(void *_vol, void *_odir, const char *oldname, if ((result = erase_dir_entry(vol, file)) != B_OK) { dprintf("dosfs_rename: error erasing old directory entry for %s (%s)\n", newname, strerror(result)); goto bi1; - } + } } else if (result == ENOENT && (!dups_exist || (odir->vnid == ndir->vnid && !strcasecmp(oldname, newname)))) { // there isn't an entry and there are no duplicates in the target dir or // there isn't an entry and the target dir is the same as the source dir and @@ -1195,7 +1195,7 @@ dosfs_rename(void *_vol, void *_odir, const char *oldname, } dirty = true; - + // create the new directory entry if ((result = create_dir_entry(vol, ndir, file, newname, &ns, &ne)) != B_OK) { dprintf("dosfs_rename: error creating directory entry for %s\n", newname); @@ -1222,10 +1222,10 @@ dosfs_rename(void *_vol, void *_odir, const char *oldname, // update vcache vcache_set_entry(vol, file->vnid, (file->st_size) ? - GENERATE_DIR_CLUSTER_VNID(file->dir_vnid, file->cluster) : + GENERATE_DIR_CLUSTER_VNID(file->dir_vnid, file->cluster) : GENERATE_DIR_INDEX_VNID(file->dir_vnid, file->sindex)); - // XXX: only write changes in the directory entry if needed + // XXX: only write changes in the directory entry if needed // (i.e. old entry, not new) write_vnode_entry(vol, file); @@ -1276,7 +1276,7 @@ dosfs_rename(void *_vol, void *_odir, const char *oldname, } result = 0; - + bi2: if (result != B_OK) put_vnode(vol->id, file2->vnid); bi1: @@ -1290,7 +1290,7 @@ bi: } -status_t +status_t dosfs_remove_vnode(void *_vol, void *_node, bool reenter) { nspace *vol = (nspace *)_vol; @@ -1329,7 +1329,7 @@ dosfs_remove_vnode(void *_vol, void *_node, bool reenter) node->magic = ~VNODE_MAGIC; // munge magic number to be safe free(node); - + if (!reenter) { if (vol->fs_flags & FS_FLAGS_OP_SYNC) { // sync the entire filesystem, @@ -1344,7 +1344,7 @@ dosfs_remove_vnode(void *_vol, void *_node, bool reenter) } // get rid of node or directory -static status_t +static status_t do_unlink(void *_vol, void *_dir, const char *name, bool is_file) { status_t result = EINVAL; @@ -1441,7 +1441,7 @@ do_unlink(void *_vol, void *_dir, const char *name, bool is_file) remove_vnode(vol->id, file->vnid); result = 0; - + if (vol->fs_flags & FS_FLAGS_OP_SYNC) _dosfs_sync(vol); @@ -1453,7 +1453,7 @@ bi: UNLOCK_VOL(vol); return result; } -status_t +status_t dosfs_unlink(void *vol, void *dir, const char *name) { DPRINTF(1, ("dosfs_unlink called\n")); @@ -1462,11 +1462,11 @@ dosfs_unlink(void *vol, void *dir, const char *name) } -status_t +status_t dosfs_rmdir(void *vol, void *dir, const char *name) { DPRINTF(1, ("dosfs_rmdir called\n")); - + return do_unlink(vol, dir, name, false); } @@ -1612,7 +1612,7 @@ dosfs_get_file_map(void *_fs, void *_node, off_t pos, size_t len, } DPRINTF(0, ("dosfs_get_file_map called %lx bytes at %Lx (vnode id %Lx)\n", len, pos, node->vnid)); - + if (pos < 0) pos = 0; if ((node->st_size == 0) || (len == 0) || (pos >= node->st_size)) { @@ -1623,7 +1623,7 @@ dosfs_get_file_map(void *_fs, void *_node, off_t pos, size_t len, // truncate bytes to read to file size if (pos + len >= node->st_size) len = node->st_size - pos; - + /* the fat chain changed, so we have to start from the beginning */ cluster1 = node->cluster; diff = pos; @@ -1633,19 +1633,19 @@ dosfs_get_file_map(void *_fs, void *_node, off_t pos, size_t len, dprintf("dosfs_get_file_map: invalid starting cluster (%lx)\n", cluster1); goto bi; } - + if (diff && ((result = iter_csi(&iter, diff)) != B_OK)) { dprintf("dosfs_get_file_map: end of file reached (init)\n"); result = EIO; goto bi; } - + ASSERT(iter.cluster == get_nth_fat_entry(vol, node->cluster, pos / vol->bytes_per_sector / vol->sectors_per_cluster)); if ((pos % vol->bytes_per_sector) != 0) { // read in partial first sector if necessary size_t amt = vol->bytes_per_sector - (pos % vol->bytes_per_sector); - if (amt > len) + if (amt > len) amt = len; vecs[index].offset = csi_to_block(&iter) * vol->bytes_per_sector + (pos % vol->bytes_per_sector); vecs[index].length = amt; @@ -1655,7 +1655,7 @@ dosfs_get_file_map(void *_fs, void *_node, off_t pos, size_t len, result = B_BUFFER_OVERFLOW; goto bi; } - + bytes_read += amt; if (bytes_read < len) @@ -1672,7 +1672,7 @@ dosfs_get_file_map(void *_fs, void *_node, off_t pos, size_t len, uint32 sectors = 1; off_t block = csi_to_block(&iter); status_t err; - + while (1) { old_csi = iter; err = iter_csi(&iter, 1); @@ -1682,19 +1682,19 @@ dosfs_get_file_map(void *_fs, void *_node, off_t pos, size_t len, break; sectors++; } - + vecs[index].offset = block * vol->bytes_per_sector; vecs[index].length = sectors * vol->bytes_per_sector; bytes_read += sectors * vol->bytes_per_sector; index++; iter = old_csi; - + if (index >= max) { // we're out of file_io_vecs; let's bail out result = B_BUFFER_OVERFLOW; goto bi; } - + if (bytes_read < len) if ((result = iter_csi(&iter, 1)) != B_OK) { dprintf("dosfs_get_file_map: end of file reached\n"); @@ -1702,7 +1702,7 @@ dosfs_get_file_map(void *_fs, void *_node, off_t pos, size_t len, goto bi; } } - + // read part of remaining sector if needed if (bytes_read < len) { size_t amt = len - bytes_read; @@ -1710,22 +1710,22 @@ dosfs_get_file_map(void *_fs, void *_node, off_t pos, size_t len, vecs[index].length = amt; index++; bytes_read += amt; - + if (index >= max) { // we're out of file_io_vecs; let's bail out result = B_BUFFER_OVERFLOW; goto bi; } } - + result = B_OK; bi: *_count = index; - + if (result != B_OK) { DPRINTF(0, ("dosfs_get_file_map (%s)\n", strerror(result))); } UNLOCK_VOL(vol); - + return result; } diff --git a/src/add-ons/kernel/file_systems/nfs/nfs_add_on.h b/src/add-ons/kernel/file_systems/nfs/nfs_add_on.h index 1768d90e03..19959bff55 100644 --- a/src/add-ons/kernel/file_systems/nfs/nfs_add_on.h +++ b/src/add-ons/kernel/file_systems/nfs/nfs_add_on.h @@ -7,14 +7,14 @@ # include # include typedef dev_t nspace_id; -# define WSTAT_MODE FS_WRITE_STAT_MODE -# define WSTAT_UID FS_WRITE_STAT_UID -# define WSTAT_GID FS_WRITE_STAT_GID -# define WSTAT_SIZE FS_WRITE_STAT_SIZE -# define WSTAT_ATIME FS_WRITE_STAT_ATIME -# define WSTAT_MTIME FS_WRITE_STAT_MTIME -# define WSTAT_CRTIME FS_WRITE_STAT_CRTIME - +# define WSTAT_MODE B_STAT_MODE +# define WSTAT_UID B_STAT_UID +# define WSTAT_GID B_STAT_GID +# define WSTAT_SIZE B_STAT_SIZE +# define WSTAT_ATIME B_STAT_ACCESS_TIME +# define WSTAT_MTIME B_STAT_MODIFICATION_TIME +# define WSTAT_CRTIME B_STAT_CREATION_TIME + #else # include "fsproto.h" # define publish_vnode new_vnode @@ -34,7 +34,7 @@ typedef int socklen_t; struct mount_nfs_params { unsigned int serverIP; char *server; - char *_export; + char *_export; uid_t uid; gid_t gid; char *hostname; @@ -49,24 +49,24 @@ struct fs_node { struct fs_nspace { nspace_id nsid; - thread_id tid; + thread_id tid; bool quit; int s; struct RPCPendingCalls pendingCalls; - + struct sockaddr_in mountAddr,nfsAddr; - int32 xid; + int32 xid; ino_t rootid; - + sem_id sem; struct fs_node *first; struct mount_nfs_params params; bigtime_t last_rfsstat; - + }; void fs_nspaceInit (struct fs_nspace *nspace); diff --git a/src/add-ons/kernel/file_systems/ntfs/fs_func.c b/src/add-ons/kernel/file_systems/ntfs/fs_func.c index fa968d2c5d..bebe09d55b 100644 --- a/src/add-ons/kernel/file_systems/ntfs/fs_func.c +++ b/src/add-ons/kernel/file_systems/ntfs/fs_func.c @@ -19,7 +19,7 @@ * file COPYING); if not, write to the Free Software Foundation,Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA */ - + #include #include #include @@ -56,13 +56,13 @@ fs_identify_partition(int fd, partition_data *partition, void **_cookie) ntfs_volume *ntVolume; uint8 *buf=(uint8*)&boot; char devpath[256]; - + // read in the boot sector ERRPRINT("fs_identify_partition: read in the boot sector\n"); if (read_pos(fd, 0, (void*)&boot, 512) != 512) { return -1; } - + // check boot signature if (((buf[0x1fe] != 0x55) || (buf[0x1ff] != 0xaa)) && (buf[0x15] == 0xf8)) return -1; @@ -78,7 +78,7 @@ fs_identify_partition(int fd, partition_data *partition, void **_cookie) ntVolume = utils_mount_volume(devpath,MS_RDONLY|MS_NOATIME,true); if(!ntVolume) return -1; - + //allocate identify_cookie cookie = (identify_cookie *)malloc(sizeof(identify_cookie)); if (!cookie) @@ -86,12 +86,12 @@ fs_identify_partition(int fd, partition_data *partition, void **_cookie) memcpy(&(cookie->boot),&boot,512); - strcpy(cookie->label,"NTFS Volume"); + strcpy(cookie->label,"NTFS Volume"); if(ntVolume->vol_name) if(strlen(ntVolume->vol_name)>0) - strcpy(cookie->label,ntVolume->vol_name); - + strcpy(cookie->label,ntVolume->vol_name); + ntfs_umount( ntVolume, true ); *_cookie = cookie; @@ -120,22 +120,22 @@ fs_free_identify_partition_cookie(partition_data *partition, void *_cookie) #endif //__HAIKU__ #ifdef __HAIKU__ -status_t +status_t fs_mount(dev_t nsid, const char *device, ulong flags, const char *args, void **data, ino_t *vnid) #else -int +int fs_mount(nspace_id nsid, const char *device, ulong flags, void *parms, size_t len, void **data, ino_t *vnid) #endif { nspace *ns; vnode *newNode = NULL; char lockname[32]; - void *handle; - unsigned long mnt_flags = 0; + void *handle; + unsigned long mnt_flags = 0; status_t result = B_NO_ERROR; ERRPRINT("fs_mount - ENTER\n"); - + ns = ntfs_malloc(sizeof(nspace)); if (!ns) { result = ENOMEM; @@ -147,55 +147,55 @@ fs_mount(nspace_id nsid, const char *device, ulong flags, void *parms, size_t le .show_sys_files = false, .ro = false }; - + ns->flags = flags; - + strcpy(ns->devicePath,device); - + sprintf(lockname, "ntfs_lock %lx", ns->id); - -#ifdef __HAIKU__ + +#ifdef __HAIKU__ if ((result = recursive_lock_init(&(ns->vlock), lockname)) != 0) #else if ((result = new_lock(&(ns->vlock), lockname)) != B_OK) -#endif +#endif { ERRPRINT("fs_mount - error creating lock (%s)\n", strerror(result)); goto exit; } - + handle = load_driver_settings("ntfs"); ns->show_sys_files = ! (strcasecmp(get_driver_parameter(handle, "hide_sys_files", "true", "true"), "true") == 0); ns->ro = strcasecmp(get_driver_parameter(handle, "read_only", "false", "false"), "false") != 0; ns->noatime = strcasecmp(get_driver_parameter(handle, "no_atime", "true", "true"), "true") == 0; unload_driver_settings(handle); - + if (ns->ro || ns->flags & B_MOUNT_READ_ONLY) { mnt_flags |= MS_RDONLY; ns->flags |= B_MOUNT_READ_ONLY; } if (ns->noatime) - mnt_flags |= MS_NOATIME; - + mnt_flags |= MS_NOATIME; + ns->ntvol=utils_mount_volume(device,mnt_flags,true); if(ns->ntvol!=NULL) result = B_NO_ERROR; else result = errno; - + if (result == B_NO_ERROR) { *vnid = FILE_root; *data = (void*)ns; ns->id = nsid; - + newNode = (vnode*)ntfs_calloc( sizeof(vnode) ); if ( newNode == NULL ) result = ENOMEM; else { - + newNode->vnid = *vnid; newNode->parent_vnid = -1; - + result = publish_vnode( nsid, *vnid, (void*)newNode ); if ( result != B_NO_ERROR ) { free( ns ); @@ -204,21 +204,21 @@ fs_mount(nspace_id nsid, const char *device, ulong flags, void *parms, size_t le } else { result = B_NO_ERROR; - ntfs_mark_free_space_outdated(ns); - ntfs_calc_free_space(ns); - } + ntfs_mark_free_space_outdated(ns); + ntfs_calc_free_space(ns); + } } } - + exit: ERRPRINT("fs_mount - EXIT, result code is %s\n", strerror(result)); - + return result; } #ifdef __HAIKU__ -status_t +status_t fs_unmount(void *_ns) #else int @@ -227,21 +227,21 @@ fs_unmount(void *_ns) { nspace *ns = (nspace*)_ns; status_t result = B_NO_ERROR; - + ERRPRINT("fs_unmount - ENTER\n"); - + ntfs_umount( ns->ntvol, true ); -#ifdef __HAIKU__ +#ifdef __HAIKU__ recursive_lock_destroy(&(ns->vlock)); #else - free_lock(&(ns->vlock)); -#endif - + free_lock(&(ns->vlock)); +#endif + free( ns ); ERRPRINT("fs_unmount - EXIT, result is %s\n", strerror(result)); - + return result; } @@ -255,13 +255,13 @@ fs_rfsstat( void *_ns, struct fs_info * fss ) { nspace *ns = (nspace*)_ns; int i; - + LOCK_VOL(ns); ERRPRINT("fs_rfsstat - ENTER\n"); - + ntfs_calc_free_space(ns); - + fss->dev = ns->id; fss->root = FILE_root; fss->flags = B_FS_IS_PERSISTENT|B_FS_HAS_MIME|B_FS_HAS_ATTR; @@ -271,15 +271,15 @@ fs_rfsstat( void *_ns, struct fs_info * fss ) fss->free_blocks = ns->free_clusters; strncpy( fss->device_name, ns->devicePath, sizeof(fss->device_name)); strncpy( fss->volume_name, ns->ntvol->vol_name, sizeof(fss->volume_name) ); - + for (i = strlen(fss->volume_name)-1; i >=0 ; i--) if (fss->volume_name[i] != ' ') - break; + break; if (i < 0) strcpy(fss->volume_name, "NTFS Untitled"); else fss->volume_name[i + 1] = 0; - + strcpy( fss->fsh_name, "NTFS" ); ERRPRINT("fs_rfsstat - EXIT\n"); @@ -308,14 +308,14 @@ fs_wfsstat(void *_vol, struct fs_info *fss, long mask) LOCK_VOL(ns); #ifdef __HAIKU__ - if (mask & FS_WRITE_FSINFO_NAME) { + if (mask & FS_WRITE_FSINFO_NAME) { #else if (mask & WFSSTAT_NAME) { -#endif +#endif result = ntfs_change_label( ns->ntvol, (char*)fss->volume_name ); - goto exit; + goto exit; } - + exit: UNLOCK_VOL(ns); @@ -363,18 +363,18 @@ fs_walk(void *_ns, void *_base, const char *file, char **newpath, ino_t *vnid) result = EILSEQ; goto exit; } - + bi = ntfs_inode_open(ns->ntvol, baseNode->vnid); if(!bi) { result = ENOENT; goto exit; } - + *vnid = MREF( ntfs_inode_lookup_by_name(bi, unicode, len) ); - - ntfs_inode_close(bi); + + ntfs_inode_close(bi); free(unicode); - + if ( *vnid == (u64) -1 ) { result = EINVAL; goto exit; @@ -382,9 +382,9 @@ fs_walk(void *_ns, void *_base, const char *file, char **newpath, ino_t *vnid) if( get_vnode( ns->id, *vnid, (void**)&newNode ) !=0 ) result = ENOENT; - + if(newNode!=NULL) - newNode->parent_vnid = baseNode->vnid; + newNode->parent_vnid = baseNode->vnid; } exit: @@ -404,32 +404,32 @@ fs_get_vnode_name(void *_ns, void *_node, char *buffer, size_t bufferSize) vnode *node = (vnode*)_node; ntfs_inode *ni=NULL; status_t result = B_NO_ERROR; - + char path[MAX_PATH]; - char *name; - + char *name; + LOCK_VOL(ns); - - ni = ntfs_inode_open(ns->ntvol, node->vnid); + + ni = ntfs_inode_open(ns->ntvol, node->vnid); if(ni==NULL) { result = ENOENT; goto exit; - } - + } + if(utils_inode_get_name(ni, path, MAX_PATH)==0) { result = EINVAL; goto exit; } name = strrchr(path, '/'); name++; - + strlcpy(buffer, name, bufferSize); - + exit: if(ni) ntfs_inode_close(ni); - + UNLOCK_VOL(ns); return result; @@ -439,7 +439,7 @@ exit: #ifdef __HAIKU__ -status_t +status_t fs_read_vnode(void *_ns, ino_t vnid, void **node, bool reenter) #else int @@ -450,50 +450,50 @@ fs_read_vnode(void *_ns, ino_t vnid, char reenter, void **node) vnode *newNode = NULL; ntfs_inode *ni=NULL; status_t result = B_NO_ERROR; - + if ( !reenter ) LOCK_VOL(ns); - + ERRPRINT("fs_read_vnode - ENTER\n"); - + newNode = (vnode*)ntfs_calloc( sizeof(vnode) ); if ( newNode != NULL ) { char *name = NULL; - - ni = ntfs_inode_open(ns->ntvol, vnid); + + ni = ntfs_inode_open(ns->ntvol, vnid); if(ni==NULL) { result = ENOENT; goto exit; - } - + } + newNode->vnid = vnid; newNode->parent_vnid = ntfs_get_parent_ref(ni); - + if( ni->mrec->flags & MFT_RECORD_IS_DIRECTORY ) set_mime(newNode, ".***"); - else { + else { name = (char*)malloc(MAX_PATH); - if(name!=NULL) { + if(name!=NULL) { if(utils_inode_get_name(ni, name,MAX_PATH)==1) set_mime(newNode, name); free(name); } - } - + } + *node = (void*)newNode; } else result = ENOMEM; exit: - + if(ni) ntfs_inode_close(ni); - + ERRPRINT("fs_read_vnode - EXIT, result is %s\n", strerror(result)); - + if ( !reenter ) UNLOCK_VOL(ns); - + return result; } @@ -508,20 +508,20 @@ fs_write_vnode( void *_ns, void *_node, char reenter ) nspace *ns = (nspace*)_ns; vnode *node = (vnode*)_node; status_t result = B_NO_ERROR; - + if ( !reenter ) LOCK_VOL(ns); - + ERRPRINT("fs_write_vnode - ENTER (%Ld)\n", node->vnid); if (node) free( node ); - + ERRPRINT("fs_write_vnode - EXIT\n"); - + if ( !reenter ) UNLOCK_VOL(ns); - + return result; } @@ -536,24 +536,24 @@ fs_remove_vnode( void *_ns, void *_node, char reenter ) nspace *ns = (nspace*)_ns; vnode *node = (vnode*)_node; status_t result = B_NO_ERROR; - + if ( !reenter ) LOCK_VOL(ns); - + ERRPRINT("fs_remove_vnode - ENTER (%Ld)\n", node->vnid); - + if(node) free(node); - + ERRPRINT("fs_remove_vnode - EXIT, result is %s\n", strerror(result)); - + if ( !reenter ) UNLOCK_VOL(ns); - + return result; } -#ifdef __HAIKU__ +#ifdef __HAIKU__ status_t fs_rstat( void *_ns, void *_node, struct stat *stbuf ) #else @@ -565,26 +565,26 @@ fs_rstat( void *_ns, void *_node, struct stat *stbuf ) vnode *node = (vnode*)_node; ntfs_inode *ni = NULL; ntfs_attr *na; - status_t result = B_NO_ERROR; - + status_t result = B_NO_ERROR; + LOCK_VOL(ns); - ERRPRINT("fs_rstat - ENTER:\n"); - + ERRPRINT("fs_rstat - ENTER:\n"); + if(ns==NULL || node ==NULL ||stbuf==NULL) { result = ENOENT; - goto exit; + goto exit; } - - ni = ntfs_inode_open(ns->ntvol, node->vnid); + + ni = ntfs_inode_open(ns->ntvol, node->vnid); if(ni==NULL) { result = ENOENT; goto exit; } - + stbuf->st_dev = ns->id; stbuf->st_ino = MREF(ni->mft_no); - + if ( ni->mrec->flags & MFT_RECORD_IS_DIRECTORY ) { stbuf->st_mode = S_IFDIR | 0777; na = ntfs_attr_open(ni, AT_INDEX_ALLOCATION, NTFS_INDEX_I30, 4); @@ -594,9 +594,9 @@ fs_rstat( void *_ns, void *_node, struct stat *stbuf ) } else { stbuf->st_size = 0; } - stbuf->st_nlink = 1; // Needed for correct find work. + stbuf->st_nlink = 1; // Needed for correct find work. } else { - // Regular or Interix (INTX) file. + // Regular or Interix (INTX) file. stbuf->st_mode = S_IFREG; stbuf->st_size = ni->data_size; stbuf->st_nlink = le16_to_cpu(ni->mrec->link_count); @@ -634,28 +634,28 @@ fs_rstat( void *_ns, void *_node, struct stat *stbuf ) free(intx_file); } ntfs_attr_close(na); - stbuf->st_mode |= 0666; + stbuf->st_mode |= 0666; } if (ns->flags & B_FS_IS_READONLY) { stbuf->st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH); } - + stbuf->st_uid = 0; stbuf->st_gid = 0; stbuf->st_atime = ni->last_access_time; stbuf->st_ctime = ni->last_mft_change_time; stbuf->st_mtime = ni->last_data_change_time; - + exit: if(ni) ntfs_inode_close(ni); - + ERRPRINT("fs_rstat - EXIT, result is %s\n", strerror(result)); - + UNLOCK_VOL(ns); - + return result; } @@ -671,75 +671,75 @@ fs_wstat(void *_vol, void *_node, struct stat *st, long mask) nspace *ns = (nspace*)_vol; vnode *node = (vnode*)_node; ntfs_inode *ni = NULL; - status_t result = B_NO_ERROR; - + status_t result = B_NO_ERROR; + LOCK_VOL(ns); - + ERRPRINT("fs_wstat: ENTER\n"); - - ni = ntfs_inode_open(ns->ntvol, node->vnid); + + ni = ntfs_inode_open(ns->ntvol, node->vnid); if(ni==NULL) { result = ENOENT; goto exit; } #ifdef __HAIKU__ - if ( mask & FS_WRITE_STAT_SIZE ) { + if ( mask & B_STAT_SIZE ) { #else if (mask & WSTAT_SIZE) { -#endif +#endif ERRPRINT("fs_wstat: setting file size to %Lx\n", st->st_size); - + if ( ni->mrec->flags & MFT_RECORD_IS_DIRECTORY ) { - result = EISDIR; + result = EISDIR; } else { - + ntfs_attr *na = ntfs_attr_open(ni, AT_DATA, NULL, 0); if (!na) { result = EINVAL; goto exit; } - + ntfs_attr_truncate(na, st->st_size); ntfs_attr_close(na); - + ntfs_mark_free_space_outdated(ns); -#ifdef __HAIKU__ +#ifdef __HAIKU__ notify_stat_changed(ns->id, MREF(ni->mft_no), mask); #else notify_listener(B_STAT_CHANGED, ns->id, 0, 0, MREF(ni->mft_no), NULL); -#endif +#endif } } - -#ifdef __HAIKU__ - if (mask & FS_WRITE_STAT_MTIME) { -#else + +#ifdef __HAIKU__ + if (mask & B_STAT_MODIFICATION_TIME) { +#else if (mask & WSTAT_MTIME) { -#endif +#endif ERRPRINT("fs_wstat: setting modification time\n"); - + ni->last_access_time = st->st_atime; ni->last_data_change_time = st->st_mtime; ni->last_mft_change_time = st->st_ctime; -#ifdef __HAIKU__ +#ifdef __HAIKU__ notify_stat_changed(ns->id, MREF(ni->mft_no), mask); -#else +#else notify_listener(B_STAT_CHANGED, ns->id, 0, 0, MREF(ni->mft_no), NULL); -#endif +#endif } exit: if(ni) ntfs_inode_close(ni); - + ERRPRINT("fs_wstat: EXIT with (%s)\n", strerror(result)); - + UNLOCK_VOL(ns); - + return result; } @@ -753,7 +753,7 @@ fs_sync(void *_ns) #endif { nspace *ns = (nspace *)_ns; - + LOCK_VOL(ns); ERRPRINT("fs_sync - ENTER\n"); @@ -777,39 +777,39 @@ fs_fsync(void *_ns, void *_node) nspace *ns = (nspace*)_ns; vnode *node = (vnode*)_node; ntfs_inode *ni = NULL; - status_t result = B_NO_ERROR; - + status_t result = B_NO_ERROR; + LOCK_VOL(ns); - + ERRPRINT("fs_fsync: ENTER\n"); - + if (ns ==NULL || node== NULL) { result = ENOENT; goto exit; } - - ni = ntfs_inode_open(ns->ntvol, node->vnid); + + ni = ntfs_inode_open(ns->ntvol, node->vnid); if(ni==NULL) { result = ENOENT; goto exit; } - + ntfs_inode_sync(ni); - -exit: + +exit: if(ni) ntfs_inode_close(ni); - + ERRPRINT("fs_fsync: EXIT\n"); - + UNLOCK_VOL(ns); - + return result; } #ifdef __HAIKU__ -status_t +status_t fs_open(void *_ns, void *_node, int omode, void **_cookie) #else int @@ -821,33 +821,33 @@ fs_open(void *_ns, void *_node, int omode, void **_cookie) filecookie *cookie=NULL; ntfs_inode *ni=NULL; ntfs_attr *na = NULL; - status_t result = B_NO_ERROR; - + status_t result = B_NO_ERROR; + LOCK_VOL(ns); - + ERRPRINT("fs_open - ENTER\n"); - + if(node==NULL) { result = EINVAL; goto exit; } - ni = ntfs_inode_open(ns->ntvol, node->vnid); + ni = ntfs_inode_open(ns->ntvol, node->vnid); if(ni==NULL) { result = errno; goto exit; - } + } - if(omode & O_TRUNC) { + if(omode & O_TRUNC) { na = ntfs_attr_open(ni, AT_DATA, NULL, 0); if(na) { if(ntfs_attr_truncate(na, 0)) result = errno; - } else + } else result = errno; } - - cookie = (filecookie*)ntfs_calloc( sizeof(filecookie) ); + + cookie = (filecookie*)ntfs_calloc( sizeof(filecookie) ); if ( cookie != NULL ) { @@ -855,26 +855,26 @@ fs_open(void *_ns, void *_node, int omode, void **_cookie) *_cookie = (void*)cookie; } else - result = ENOMEM; - + result = ENOMEM; + exit: if(na) ntfs_attr_close(na); - + if(ni) ntfs_inode_close(ni); - + ERRPRINT("fs_open - EXIT\n"); - + UNLOCK_VOL(ns); - + return result; } #ifdef __HAIKU__ -status_t +status_t fs_create(void *_ns, void *_dir, const char *name, int omode, int perms, void **_cookie, ino_t *_vnid) #else int @@ -884,51 +884,51 @@ fs_create(void *_ns, void *_dir, const char *name, int omode, int perms, ino_t * nspace *ns = (nspace*)_ns; vnode *dir = (vnode*)_dir; filecookie *cookie = NULL; - vnode *newNode = NULL; + vnode *newNode = NULL; ntfs_attr *na = NULL; ntfs_inode *ni=NULL; - ntfs_inode *bi=NULL; + ntfs_inode *bi=NULL; ntfschar *uname = NULL; - status_t result = B_NO_ERROR; + status_t result = B_NO_ERROR; int uname_len; if (ns->flags & B_FS_IS_READONLY) { ERRPRINT("ntfs is read-only\n"); return EROFS; - } - + } + LOCK_VOL(ns); - - ERRPRINT("fs_create - ENTER: name=%s\n",name); - + + ERRPRINT("fs_create - ENTER: name=%s\n",name); + if(_ns==NULL || _dir==NULL) { result = EINVAL; goto exit; } - + if (name == NULL || *name == '\0' || strchr(name, '/') || strcmp(name, ".") == 0 || strcmp(name, "..") == 0) { result = EINVAL; goto exit; } - - bi = ntfs_inode_open(ns->ntvol, dir->vnid); + + bi = ntfs_inode_open(ns->ntvol, dir->vnid); if(bi==NULL) { result = ENOENT; goto exit; } - + if ( !bi->mrec->flags & MFT_RECORD_IS_DIRECTORY ) { result = EINVAL; goto exit; } - + uname_len = ntfs_mbstoucs(name, &uname, 0); if (uname_len < 0) { result = EINVAL; goto exit; } - - cookie = (filecookie*)ntfs_calloc( sizeof(filecookie) ); + + cookie = (filecookie*)ntfs_calloc( sizeof(filecookie) ); if ( cookie != NULL ) { cookie->omode = omode; @@ -936,69 +936,69 @@ fs_create(void *_ns, void *_dir, const char *name, int omode, int perms, ino_t * result = ENOMEM; goto exit; } - + ni = ntfs_pathname_to_inode(ns->ntvol, bi, name); if(ni) { //file exist *_vnid = MREF( ni->mft_no ); - if(omode & O_TRUNC) { + if(omode & O_TRUNC) { na = ntfs_attr_open(ni, AT_DATA, NULL, 0); if(na) { if(ntfs_attr_truncate(na, 0)) result = errno; - } else + } else result = errno; } } else { - ni = ntfs_create(bi, uname, uname_len, S_IFREG); + ni = ntfs_create(bi, uname, uname_len, S_IFREG); if (ni) { - *_vnid = MREF( ni->mft_no ); - + *_vnid = MREF( ni->mft_no ); + newNode = (vnode*)ntfs_calloc( sizeof(vnode) ); if(newNode==NULL) { result=ENOMEM; goto exit; } - + newNode->vnid = *_vnid; newNode->parent_vnid = MREF(bi->mft_no); - set_mime(newNode, name); + set_mime(newNode, name); result = B_NO_ERROR; - result = publish_vnode(ns->id, *_vnid, (void*)newNode); - - ntfs_mark_free_space_outdated(ns); + result = publish_vnode(ns->id, *_vnid, (void*)newNode); -#ifdef __HAIKU__ - notify_entry_created(ns->id, MREF( bi->mft_no ), name, *_vnid); -#else - notify_listener(B_ENTRY_CREATED, ns->id, MREF( bi->mft_no ), 0, *_vnid, name); + ntfs_mark_free_space_outdated(ns); + +#ifdef __HAIKU__ + notify_entry_created(ns->id, MREF( bi->mft_no ), name, *_vnid); +#else + notify_listener(B_ENTRY_CREATED, ns->id, MREF( bi->mft_no ), 0, *_vnid, name); #endif - + } else result = errno; - } - - free(uname); - + } + + free(uname); + exit: if(result >= B_OK) { *_cookie = cookie; } else free(cookie); - + if(na) ntfs_attr_close(na); if(ni) ntfs_inode_close(ni); if(bi) ntfs_inode_close(bi); - + ERRPRINT("fs_create - EXIT, result is %s\n", strerror(result)); - + UNLOCK_VOL(ns); - + return result; } @@ -1011,19 +1011,19 @@ fs_read( void *_ns, void *_node, void *_cookie, off_t offset, void *buf, size_t #endif { nspace *ns = (nspace*)_ns; - vnode *node = (vnode*)_node; - //filecookie *cookie = (filecookie*)_cookie; //temporary not used + vnode *node = (vnode*)_node; + //filecookie *cookie = (filecookie*)_cookie; //temporary not used ntfs_inode *ni = NULL; ntfs_attr *na = NULL; size_t size = *len; int total = 0; status_t result = B_NO_ERROR; - + LOCK_VOL(ns); ERRPRINT("fs_read - ENTER\n"); - ni = ntfs_inode_open(ns->ntvol, node->vnid); + ni = ntfs_inode_open(ns->ntvol, node->vnid); if(ni==NULL) { *len = 0; result = ENOENT; @@ -1036,7 +1036,7 @@ fs_read( void *_ns, void *_node, void *_cookie, off_t offset, void *buf, size_t result = EISDIR; goto exit2; } - + if(offset < 0) { *len = 0; result = EINVAL; @@ -1065,7 +1065,7 @@ fs_read( void *_ns, void *_node, void *_cookie, off_t offset, void *buf, size_t total += result; } result = total; - *len = result; + *len = result; exit: if (na) @@ -1075,11 +1075,11 @@ exit2: if (ni) ntfs_inode_close(ni); - + UNLOCK_VOL(ns); ERRPRINT("fs_read - EXIT, result is %s\n", strerror(result)); - + return result; } @@ -1093,24 +1093,24 @@ fs_write( void *_ns, void *_node, void *_cookie, off_t offset, const void *buf, #endif { nspace *ns = (nspace*)_ns; - vnode *node = (vnode*)_node; - filecookie *cookie = (filecookie*)_cookie; + vnode *node = (vnode*)_node; + filecookie *cookie = (filecookie*)_cookie; ntfs_inode *ni = NULL; ntfs_attr *na = NULL; int total = 0; size_t size=*len; status_t result = B_NO_ERROR; - + if (ns->flags & B_FS_IS_READONLY) { ERRPRINT("ntfs is read-only\n"); return EROFS; - } - + } + LOCK_VOL(ns); ERRPRINT("fs_write - ENTER, offset=%d, len=%d\n",(int)offset, (int)(*len)); - ni = ntfs_inode_open(ns->ntvol, node->vnid); + ni = ntfs_inode_open(ns->ntvol, node->vnid); if(ni==NULL) { *len = 0; result = ENOENT; @@ -1123,7 +1123,7 @@ fs_write( void *_ns, void *_node, void *_cookie, off_t offset, const void *buf, result = EISDIR; goto exit2; } - + if(offset < 0) { ERRPRINT(("fs_write - offset < 0.\n")); *len = 0; @@ -1138,20 +1138,20 @@ fs_write( void *_ns, void *_node, void *_cookie, off_t offset, const void *buf, result = EINVAL; goto exit2; } - + if (cookie->omode & O_APPEND) - offset = na->data_size; - + offset = na->data_size; + if (offset + size > na->data_size) { - ntfs_mark_free_space_outdated(ns); + ntfs_mark_free_space_outdated(ns); if(ntfs_attr_truncate(na, offset + size)) size = na->data_size - offset; else -#ifdef __HAIKU__ - notify_stat_changed(ns->id, MREF(ni->mft_no), B_STAT_SIZE); +#ifdef __HAIKU__ + notify_stat_changed(ns->id, MREF(ni->mft_no), B_STAT_SIZE); #else notify_listener(B_STAT_CHANGED, ns->id, 0, 0, MREF(ni->mft_no), NULL); -#endif +#endif } while (size) { @@ -1180,15 +1180,15 @@ exit2: ntfs_inode_close(ni); ERRPRINT("fs_write - EXIT, result is %s, writed %d bytes\n", strerror(result),(int)(*len)); - + UNLOCK_VOL(ns); - - return result; + + return result; } #ifdef __HAIKU__ -status_t +status_t fs_close(void *ns, void *node, void *cookie) #else int @@ -1196,7 +1196,7 @@ fs_close(void *ns, void *node, void *cookie) #endif { ERRPRINT("fs_close - ENTER\n"); - + ERRPRINT("fs_close - EXIT\n"); return B_NO_ERROR; } @@ -1210,10 +1210,10 @@ fs_free_cookie( void *ns, void *node, void *cookie ) #endif { ERRPRINT("fs_free_cookie - ENTER\n"); - + if(cookie) free(cookie); - + ERRPRINT("fs_free_cookie - EXIT\n"); return B_NO_ERROR; } @@ -1226,8 +1226,8 @@ int fs_access( void *ns, void *node, int mode ) #endif { - ERRPRINT("fs_access - ENTER\n"); - + ERRPRINT("fs_access - ENTER\n"); + ERRPRINT("fs_access - EXIT\n"); return B_NO_ERROR; } @@ -1241,29 +1241,29 @@ fs_readlink(void *_ns, void *_node, char *buff, size_t *buff_size) #endif { nspace *ns = (nspace*)_ns; - vnode *node = (vnode*)_node; + vnode *node = (vnode*)_node; ntfs_attr *na = NULL; INTX_FILE *intx_file = NULL; - ntfs_inode *ni = NULL; + ntfs_inode *ni = NULL; char *buf = NULL; - status_t result = B_NO_ERROR; + status_t result = B_NO_ERROR; int l=0; - + LOCK_VOL(ns); - - ERRPRINT("fs_readlink - ENTER\n"); - + + ERRPRINT("fs_readlink - ENTER\n"); + if(ns==NULL || node==NULL || buff ==NULL || buff_size ==NULL) { result = EINVAL; goto exit; } - - ni = ntfs_inode_open(ns->ntvol, node->vnid); + + ni = ntfs_inode_open(ns->ntvol, node->vnid); if(ni==NULL) { result = ENOENT; goto exit; } - + /* Sanity checks. */ if (!(ni->flags & FILE_ATTR_SYSTEM)) { result = EINVAL; @@ -1300,22 +1300,22 @@ fs_readlink(void *_ns, void *_node, char *buff, size_t *buff_size) } /* Convert link from unicode to local encoding. */ l = ntfs_ucstombs(intx_file->target, (na->data_size - offsetof(INTX_FILE, target)) / sizeof(ntfschar), &buf, 0); - + if ( l < 0) { result = errno; goto exit; } - + ERRPRINT("fs_readlink - LINK:[%s]\n",buf); - + strcpy(buff,buf); if(buf) free(buf); - + *buff_size = l+1; - + result = B_NO_ERROR; - + exit: if (intx_file) @@ -1323,12 +1323,12 @@ exit: if (na) ntfs_attr_close(na); if(ni) - ntfs_inode_close(ni); - + ntfs_inode_close(ni); + ERRPRINT("fs_readlink - EXIT, result is %s\n", strerror(result)); UNLOCK_VOL(ns); - + return result; } @@ -1343,83 +1343,83 @@ fs_create_symlink(void *_ns, void *_dir, const char *name, const char *target) nspace *ns = (nspace*)_ns; vnode *dir = (vnode*)_dir; ntfs_inode *sym = NULL; - ntfs_inode *bi = NULL; + ntfs_inode *bi = NULL; vnode *symnode = NULL; ntfschar *uname = NULL, *utarget = NULL; int uname_len, utarget_len; - status_t result = B_NO_ERROR; - + status_t result = B_NO_ERROR; + LOCK_VOL(ns); - - ERRPRINT("fs_symlink - ENTER, name=%s, path=%s\n",name, target); - + + ERRPRINT("fs_symlink - ENTER, name=%s, path=%s\n",name, target); + if(ns == NULL || dir == NULL || name == NULL || target == NULL) { result = EINVAL; goto exit; } - - bi = ntfs_inode_open(ns->ntvol, dir->vnid); + + bi = ntfs_inode_open(ns->ntvol, dir->vnid); if(bi==NULL) { result = ENOENT; goto exit; } - + uname_len = ntfs_mbstoucs(name, &uname, 0); if (uname_len < 0) { result = EINVAL; goto exit; } - + utarget_len = ntfs_mbstoucs(target, &utarget, 0); if (utarget_len < 0) { result = EINVAL; goto exit; } - + sym = ntfs_create_symlink(bi, uname, uname_len, utarget, utarget_len); if(sym==NULL) { result = EINVAL; goto exit; - } - + } + symnode = (vnode*)ntfs_calloc( sizeof(vnode) ); if(symnode==NULL) { result = ENOMEM; goto exit; } - + symnode->vnid = MREF(sym->mft_no); symnode->parent_vnid = MREF(bi->mft_no); - + if(sym->mrec->flags & MFT_RECORD_IS_DIRECTORY) set_mime(symnode, ".***"); else set_mime(symnode, name); - + if ((result = publish_vnode(ns->id, MREF(sym->mft_no), symnode)) != 0) ERRPRINT("fs_symlink - new_vnode failed for vnid %Ld: %s\n", MREF(sym->mft_no), strerror(result)); put_vnode(ns->id, MREF(sym->mft_no) ); -#ifdef __HAIKU__ - notify_entry_created(ns->id, MREF( bi->mft_no ), name, MREF(sym->mft_no)); +#ifdef __HAIKU__ + notify_entry_created(ns->id, MREF( bi->mft_no ), name, MREF(sym->mft_no)); #else notify_listener(B_ENTRY_CREATED, ns->id, MREF(bi->mft_no), 0, MREF(sym->mft_no), name); #endif - -exit: - + +exit: + if(sym) ntfs_inode_close(sym); if(bi) ntfs_inode_close(bi); - + ERRPRINT("fs_symlink - EXIT, result is %s\n", strerror(result)); UNLOCK_VOL(ns); - + return result; } @@ -1434,56 +1434,56 @@ fs_mkdir(void *_ns, void *_node, const char *name, int perms) { nspace *ns = (nspace*)_ns; vnode *dir = (vnode*)_node; - vnode *newNode =NULL; + vnode *newNode =NULL; ntfschar *uname = NULL; - int uname_len; + int uname_len; ntfs_inode *ni = NULL; ntfs_inode *bi = NULL; - status_t result = B_NO_ERROR; + status_t result = B_NO_ERROR; if (ns->flags & B_FS_IS_READONLY) { ERRPRINT("ntfs is read-only\n"); return EROFS; } - + LOCK_VOL(ns); - - ERRPRINT("fs_mkdir - ENTER: name=%s\n",name); - + + ERRPRINT("fs_mkdir - ENTER: name=%s\n",name); + if(_ns==NULL || _node==NULL || name==NULL) { result = EINVAL; goto exit; } - - bi = ntfs_inode_open(ns->ntvol, dir->vnid); + + bi = ntfs_inode_open(ns->ntvol, dir->vnid); if(bi==NULL) { result = ENOENT; goto exit; } -#ifndef __HAIKU__ +#ifndef __HAIKU__ if (is_vnode_removed(ns->id, MREF(bi->mft_no)) > 0) { ERRPRINT("fs_mkdir - called in removed directory\n"); result = EPERM; goto exit; } #endif - + if (! bi->mrec->flags & MFT_RECORD_IS_DIRECTORY) { result = EINVAL; goto exit; } - + uname_len = ntfs_mbstoucs(name, &uname, 0); if (uname_len < 0) { result = EINVAL; goto exit; } - + ni = ntfs_create(bi, uname, uname_len, S_IFDIR); - + if (ni) { - ino_t vnid = MREF( ni->mft_no ); + ino_t vnid = MREF( ni->mft_no ); newNode = (vnode*)ntfs_calloc( sizeof(vnode) ); if(newNode==NULL) { @@ -1495,17 +1495,17 @@ fs_mkdir(void *_ns, void *_node, const char *name, int perms) newNode->vnid = vnid; newNode->parent_vnid = MREF(bi->mft_no); set_mime(newNode, ".***"); - - result = publish_vnode(ns->id, vnid, (void*)newNode); -#ifdef __HAIKU__ - *_vnid = vnid; -#endif - put_vnode(ns->id, MREF(ni->mft_no)); - - ntfs_mark_free_space_outdated(ns); -#ifdef __HAIKU__ - notify_entry_created(ns->id, MREF( bi->mft_no ), name, vnid); + result = publish_vnode(ns->id, vnid, (void*)newNode); +#ifdef __HAIKU__ + *_vnid = vnid; +#endif + put_vnode(ns->id, MREF(ni->mft_no)); + + ntfs_mark_free_space_outdated(ns); + +#ifdef __HAIKU__ + notify_entry_created(ns->id, MREF( bi->mft_no ), name, vnid); #else notify_listener(B_ENTRY_CREATED, ns->id, MREF( bi->mft_no ), 0, vnid, name); #endif @@ -1513,8 +1513,8 @@ fs_mkdir(void *_ns, void *_node, const char *name, int perms) } else result = errno; - -exit: + +exit: if(ni) ntfs_inode_close(ni); @@ -1522,9 +1522,9 @@ exit: ntfs_inode_close(bi); ERRPRINT("fs_mkdir - EXIT, result is %s\n", strerror(result)); - + UNLOCK_VOL(ns); - + return result; } @@ -1539,46 +1539,46 @@ fs_rename(void *_ns, void *_odir, const char *oldname, void *_ndir, const char * nspace *ns = (nspace*)_ns; vnode *odir = (vnode*)_odir; vnode *ndir = (vnode*)_ndir; - + vnode *onode = NULL; vnode *nnode = NULL; - + ino_t ovnid,nvnid; - - ntfs_inode *oi = NULL; - ntfs_inode *ndi = NULL; + + ntfs_inode *oi = NULL; + ntfs_inode *ndi = NULL; ntfs_inode *odi = NULL; - + ntfschar *unewname = NULL, *uoldname=NULL; int unewname_len, uoldname_len; - - status_t result = B_NO_ERROR; - + + status_t result = B_NO_ERROR; + if (ns->flags & B_FS_IS_READONLY) { ERRPRINT("ntfs is read-only\n"); return EROFS; - } - + } + LOCK_VOL(ns); - - ERRPRINT("fs_rename - oldname:%s newname:%s\n", oldname, newname); + + ERRPRINT("fs_rename - oldname:%s newname:%s\n", oldname, newname); if (_ns == NULL || _odir == NULL || _ndir == NULL || oldname == NULL || *oldname == '\0' || newname == NULL || *newname == '\0' || !strcmp(oldname, ".") || !strcmp(oldname, "..") || !strcmp(newname, ".") || !strcmp(newname, "..") - || strchr(newname, '/') != NULL) { + || strchr(newname, '/') != NULL) { result = EINVAL; goto exit; } - + //stupid renaming check if (odir == ndir && !strcmp(oldname, newname)) goto exit; - + //convert names from utf8 to unicode string unewname_len = ntfs_mbstoucs(newname, &unewname, 0); if (unewname_len < 0) { @@ -1591,14 +1591,14 @@ fs_rename(void *_ns, void *_odir, const char *oldname, void *_ndir, const char * result = EINVAL; goto exit; } - - //open source directory inode - odi = ntfs_inode_open(ns->ntvol, odir->vnid); + + //open source directory inode + odi = ntfs_inode_open(ns->ntvol, odir->vnid); if(odi==NULL) { result = ENOENT; goto exit; - } - + } + ovnid = MREF( ntfs_inode_lookup_by_name(odi, uoldname, uoldname_len) ); if (ovnid == (u64) -1) { result = EINVAL; @@ -1608,125 +1608,125 @@ fs_rename(void *_ns, void *_odir, const char *oldname, void *_ndir, const char * result = get_vnode( ns->id, ovnid, (void**)&onode ); if( result != B_NO_ERROR) goto exit; - - + + if(odir != ndir) { //moving - ndi = ntfs_inode_open(ns->ntvol, ndir->vnid); + ndi = ntfs_inode_open(ns->ntvol, ndir->vnid); if(ndi!=NULL) { nvnid = MREF( ntfs_inode_lookup_by_name(ndi, unewname, unewname_len) ); if (nvnid != (u64) -1) get_vnode( ns->id, nvnid, (void**)&nnode ); - } - + } + if(nnode!=NULL) { result = EINVAL; put_vnode(ns->id, nnode->vnid); goto exit; - } - - oi = ntfs_inode_open(ns->ntvol, onode->vnid); + } + + oi = ntfs_inode_open(ns->ntvol, onode->vnid); if(oi==NULL) { result = EINVAL; goto exit; } - + if (ntfs_link(oi, ndi, unewname, unewname_len)) { ntfs_inode_close(oi); - result = EINVAL; + result = EINVAL; goto exit; - } - + } + if(oi->mrec->flags & MFT_RECORD_IS_DIRECTORY) set_mime(onode, ".***"); else - set_mime(onode, newname); - - ntfs_inode_close(oi); - - oi = ntfs_inode_open(ns->ntvol, onode->vnid); + set_mime(onode, newname); + + ntfs_inode_close(oi); + + oi = ntfs_inode_open(ns->ntvol, onode->vnid); if(oi==NULL) { result = EINVAL; goto exit; - } - - ntfs_delete(oi, odi, uoldname, uoldname_len); - - onode->parent_vnid = MREF( ndi->mft_no ); + } -#ifdef __HAIKU__ + ntfs_delete(oi, odi, uoldname, uoldname_len); + + onode->parent_vnid = MREF( ndi->mft_no ); + +#ifdef __HAIKU__ notify_entry_moved(ns->id, MREF( odi->mft_no ), oldname, MREF( ndi->mft_no ), newname, onode->vnid ); - notify_attribute_changed(ns->id, onode->vnid, "BEOS:TYPE", B_ATTR_CHANGED); + notify_attribute_changed(ns->id, onode->vnid, "BEOS:TYPE", B_ATTR_CHANGED); #else notify_listener(B_ENTRY_MOVED, ns->id, MREF( odi->mft_no ), MREF( ndi->mft_no ), MREF( onode->vnid ), newname); notify_listener(B_ATTR_CHANGED, ns->id, 0, 0, onode->vnid, "BEOS:TYPE"); #endif - - put_vnode(ns->id, onode->vnid ); - + + put_vnode(ns->id, onode->vnid ); + } else { //renaming - + nvnid = MREF( ntfs_inode_lookup_by_name(odi, unewname, unewname_len) ); if (nvnid != (u64) -1) get_vnode( ns->id, nvnid, (void**)&nnode ); - + if(nnode!=NULL) { result = EINVAL; put_vnode(ns->id, nnode->vnid); goto exit; - } - - oi = ntfs_inode_open(ns->ntvol, onode->vnid); + } + + oi = ntfs_inode_open(ns->ntvol, onode->vnid); if(oi==NULL) { result = EINVAL; goto exit; } - + if (ntfs_link(oi, odi, unewname, unewname_len)) { ntfs_inode_close(oi); - result = EINVAL; + result = EINVAL; goto exit; - } - + } + if(oi->mrec->flags & MFT_RECORD_IS_DIRECTORY) set_mime(onode, ".***"); else - set_mime(onode, newname); - - ntfs_inode_close(oi); - - oi = ntfs_inode_open(ns->ntvol, onode->vnid); + set_mime(onode, newname); + + ntfs_inode_close(oi); + + oi = ntfs_inode_open(ns->ntvol, onode->vnid); if(oi==NULL) { result = EINVAL; goto exit; - } - + } + ntfs_delete(oi, odi, uoldname, uoldname_len); #ifdef __HAIKU__ notify_entry_moved(ns->id, MREF( odi->mft_no ), oldname, MREF( odi->mft_no ), newname, onode->vnid ); notify_attribute_changed(ns->id, onode->vnid, "BEOS:TYPE", B_ATTR_CHANGED); -#else +#else notify_listener(B_ENTRY_MOVED, ns->id, MREF( odi->mft_no ), MREF( odi->mft_no ), MREF( onode->vnid ), newname); - notify_listener(B_ATTR_CHANGED, ns->id, 0, 0, onode->vnid, "BEOS:TYPE"); -#endif + notify_listener(B_ATTR_CHANGED, ns->id, 0, 0, onode->vnid, "BEOS:TYPE"); +#endif put_vnode(ns->id, onode->vnid ); } - - + + exit: - if(unewname!=NULL)free(unewname); - if(uoldname!=NULL)free(uoldname); - + if(unewname!=NULL)free(unewname); + if(uoldname!=NULL)free(uoldname); + if(odi) - ntfs_inode_close(odi); + ntfs_inode_close(odi); if(ndi) ntfs_inode_close(ndi); - + ERRPRINT("fs_rename - EXIT, result is %s\n", strerror(result)); - + UNLOCK_VOL(ns); - - return result; - + + return result; + } status_t @@ -1737,82 +1737,82 @@ do_unlink(nspace *vol, vnode *dir, const char *name, bool isdir) ntfs_inode *ni = NULL; ntfs_inode *bi = NULL; ntfschar *uname = NULL; - int uname_len; + int uname_len; status_t result = B_NO_ERROR; - + uname_len = ntfs_mbstoucs(name, &uname, 0); if (uname_len < 0) { result = EINVAL; goto exit1; } - bi = ntfs_inode_open(vol->ntvol, dir->vnid); + bi = ntfs_inode_open(vol->ntvol, dir->vnid); if(bi==NULL) { result = ENOENT; goto exit1; - } + } vnid = MREF( ntfs_inode_lookup_by_name(bi, uname, uname_len) ); - - if ( vnid == (u64) -1 || vnid == FILE_root) { + + if ( vnid == (u64) -1 || vnid == FILE_root) { result = EINVAL; goto exit1; } - + result = get_vnode(vol->id, vnid, (void**) & node); - + if(result != B_NO_ERROR || node==NULL) { result = ENOENT; goto exit1; } - - ni = ntfs_inode_open(vol->ntvol, node->vnid); + + ni = ntfs_inode_open(vol->ntvol, node->vnid); if(ni==NULL) { result = ENOENT; goto exit2; - } - + } + if(isdir) { if (!ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { result = ENOTDIR; goto exit2; - } + } if (ntfs_check_empty_dir(ni)<0) { result = ENOTEMPTY; goto exit2; - } + } } else if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { result = EISDIR; goto exit2; } - + if(ntfs_delete(ni, bi, uname, uname_len)) result = errno; else - ni = NULL; - + ni = NULL; + node->parent_vnid = dir->vnid; -#ifdef __HAIKU__ - notify_entry_removed(vol->id, dir->vnid, name, vnid); +#ifdef __HAIKU__ + notify_entry_removed(vol->id, dir->vnid, name, vnid); #else - notify_listener(B_ENTRY_REMOVED, vol->id, MREF(dir->vnid), 0, vnid, NULL); + notify_listener(B_ENTRY_REMOVED, vol->id, MREF(dir->vnid), 0, vnid, NULL); #endif result = remove_vnode(vol->id, vnid); exit2: put_vnode(vol->id, vnid); -exit1: +exit1: if(uname!=NULL) free(uname); if(ni) - ntfs_inode_close(ni); - + ntfs_inode_close(ni); + if(bi) ntfs_inode_close(bi); - + return result; } @@ -1835,9 +1835,9 @@ fs_rmdir(void *_ns, void *_node, const char *name) } LOCK_VOL(ns); - + ERRPRINT("fs_rmdir - ENTER: name %s\n", name==NULL?"NULL":name); - + if( ns == NULL || dir == NULL || name ==NULL) { result = EINVAL; goto exit1; @@ -1847,22 +1847,22 @@ fs_rmdir(void *_ns, void *_node, const char *name) result = EPERM; goto exit1; } - + if (strcmp(name, "..") == 0) { result = EPERM; goto exit1; } - - result = do_unlink(ns, dir, name, true); - + + result = do_unlink(ns, dir, name, true); + ntfs_mark_free_space_outdated(ns); exit1: - + ERRPRINT("fs_rmdir - EXIT, result is %s\n", strerror(result)); - + UNLOCK_VOL(ns); - + return result; } @@ -1885,9 +1885,9 @@ fs_unlink(void *_ns, void *_node, const char *name) } LOCK_VOL(ns); - + ERRPRINT("fs_unlink - ENTER: name %s\n", name==NULL?"NULL":name); - + if( ns == NULL || dir == NULL || name ==NULL) { result = EINVAL; goto exit; @@ -1897,22 +1897,22 @@ fs_unlink(void *_ns, void *_node, const char *name) result = EPERM; goto exit; } - + if (strcmp(name, "..") == 0) { result = EPERM; goto exit; } - - result = do_unlink(ns, dir, name, false); - + + result = do_unlink(ns, dir, name, false); + ntfs_mark_free_space_outdated(ns); exit: - + ERRPRINT("fs_unlink - EXIT, result is %s\n", strerror(result)); - + UNLOCK_VOL(ns); - + return result; } diff --git a/src/servers/net/Settings.cpp b/src/servers/net/Settings.cpp index 3ef6a06b85..69226c7313 100644 --- a/src/servers/net/Settings.cpp +++ b/src/servers/net/Settings.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007, Haiku, Inc. All Rights Reserved. + * Copyright 2006-2008, Haiku, Inc. All Rights Reserved. * Distributed under the terms of the MIT License. * * Authors: @@ -342,8 +342,8 @@ Settings::Update(BMessage* message) int32 fields; if (opcode == B_STAT_CHANGED && message->FindInt32("fields", &fields) == B_OK - && (fields & FS_WRITE_STAT_MTIME) == 0) { - // only update when the modified time has changed + && (fields & (B_STAT_MODIFICATION_TIME | B_STAT_SIZE)) == 0) { + // only update when the modified time or size has changed return B_OK; } diff --git a/src/system/kernel/fs/devfs.cpp b/src/system/kernel/fs/devfs.cpp index 9446c6e576..42cbd9742f 100644 --- a/src/system/kernel/fs/devfs.cpp +++ b/src/system/kernel/fs/devfs.cpp @@ -2499,24 +2499,24 @@ devfs_write_stat(fs_volume _fs, fs_vnode _vnode, const struct stat *stat, stat)); // we cannot change the size of anything - if (statMask & FS_WRITE_STAT_SIZE) + if (statMask & B_STAT_SIZE) return B_BAD_VALUE; RecursiveLocker locker(&fs->lock); - if (statMask & FS_WRITE_STAT_MODE) { + if (statMask & B_STAT_MODE) { vnode->stream.type = (vnode->stream.type & ~S_IUMSK) | (stat->st_mode & S_IUMSK); } - if (statMask & FS_WRITE_STAT_UID) + if (statMask & B_STAT_UID) vnode->uid = stat->st_uid; - if (statMask & FS_WRITE_STAT_GID) + if (statMask & B_STAT_GID) vnode->gid = stat->st_gid; - if (statMask & FS_WRITE_STAT_MTIME) + if (statMask & B_STAT_MODIFICATION_TIME) vnode->modification_time = stat->st_mtime; - if (statMask & FS_WRITE_STAT_CRTIME) + if (statMask & B_STAT_CREATION_TIME) vnode->creation_time = stat->st_crtime; notify_stat_changed(fs->id, vnode->id, statMask); diff --git a/src/system/libroot/posix/sys/chmod.c b/src/system/libroot/posix/sys/chmod.c index 5039d132bb..661baabe02 100644 --- a/src/system/libroot/posix/sys/chmod.c +++ b/src/system/libroot/posix/sys/chmod.c @@ -1,10 +1,10 @@ -/* -** Copyright 2002-2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. -** Distributed under the terms of the Haiku License. -*/ +/* + * Copyright 2002-2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ -#include +#include #include #include @@ -27,7 +27,7 @@ chmod(const char *path, mode_t mode) stat.st_mode = mode; status = _kern_write_stat(-1, path, true, &stat, sizeof(struct stat), - FS_WRITE_STAT_MODE); + B_STAT_MODE); RETURN_AND_SET_ERRNO(status); } @@ -41,7 +41,7 @@ fchmod(int fd, mode_t mode) stat.st_mode = mode; status = _kern_write_stat(fd, NULL, false, &stat, sizeof(struct stat), - FS_WRITE_STAT_MODE); + B_STAT_MODE); RETURN_AND_SET_ERRNO(status); } diff --git a/src/system/libroot/posix/unistd/chown.c b/src/system/libroot/posix/unistd/chown.c index 3c69081e3b..72daa93703 100644 --- a/src/system/libroot/posix/unistd/chown.c +++ b/src/system/libroot/posix/unistd/chown.c @@ -1,10 +1,10 @@ -/* -** Copyright 2002-2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. -** Distributed under the terms of the Haiku License. -*/ +/* + * Copyright 2002-2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ -#include +#include #include #include @@ -28,7 +28,7 @@ chown(const char *path, uid_t owner, gid_t group) stat.st_uid = owner; stat.st_gid = group; status = _kern_write_stat(-1, path, true, &stat, sizeof(struct stat), - FS_WRITE_STAT_UID | FS_WRITE_STAT_GID); + B_STAT_UID | B_STAT_GID); RETURN_AND_SET_ERRNO(status); } @@ -43,7 +43,7 @@ lchown(const char *path, uid_t owner, gid_t group) stat.st_uid = owner; stat.st_gid = group; status = _kern_write_stat(-1, path, false, &stat, sizeof(struct stat), - FS_WRITE_STAT_UID | FS_WRITE_STAT_GID); + B_STAT_UID | B_STAT_GID); RETURN_AND_SET_ERRNO(status); } @@ -58,7 +58,7 @@ fchown(int fd, uid_t owner, gid_t group) stat.st_uid = owner; stat.st_gid = group; status = _kern_write_stat(fd, NULL, false, &stat, sizeof(struct stat), - FS_WRITE_STAT_UID | FS_WRITE_STAT_GID); + B_STAT_UID | B_STAT_GID); RETURN_AND_SET_ERRNO(status); } diff --git a/src/system/libroot/posix/unistd/truncate.c b/src/system/libroot/posix/unistd/truncate.c index f12d65720a..4cb6e9d9ed 100644 --- a/src/system/libroot/posix/unistd/truncate.c +++ b/src/system/libroot/posix/unistd/truncate.c @@ -1,10 +1,11 @@ -/* -** Copyright 2002-2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. -** Distributed under the terms of the Haiku License. -*/ +/* + * Copyright 2002-2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ #include +#include #include #include @@ -27,7 +28,7 @@ truncate(const char *path, off_t newSize) stat.st_size = newSize; status = _kern_write_stat(-1, path, true, &stat, sizeof(struct stat), - FS_WRITE_STAT_SIZE); + B_STAT_SIZE); RETURN_AND_SET_ERRNO(status); } @@ -41,7 +42,7 @@ ftruncate(int fd, off_t newSize) stat.st_size = newSize; status = _kern_write_stat(fd, NULL, false, &stat, sizeof(struct stat), - FS_WRITE_STAT_SIZE); + B_STAT_SIZE); RETURN_AND_SET_ERRNO(status); } diff --git a/src/system/libroot/posix/utime.c b/src/system/libroot/posix/utime.c index 5e01a7aaac..e06ddb51ae 100644 --- a/src/system/libroot/posix/utime.c +++ b/src/system/libroot/posix/utime.c @@ -1,10 +1,10 @@ -/* -** Copyright 2002-2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. -** Distributed under the terms of the Haiku License. -*/ +/* + * Copyright 2002-2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ -#include +#include #include #include @@ -33,7 +33,7 @@ utime(const char *path, const struct utimbuf *times) stat.st_atime = stat.st_mtime = time(NULL); status = _kern_write_stat(-1, path, true, &stat, sizeof(struct stat), - FS_WRITE_STAT_MTIME | FS_WRITE_STAT_ATIME); + B_STAT_MODIFICATION_TIME | B_STAT_ACCESS_TIME); RETURN_AND_SET_ERRNO(status); } diff --git a/src/tools/fs_shell/fssh.cpp b/src/tools/fs_shell/fssh.cpp index 0060469627..4b0b1f85a8 100644 --- a/src/tools/fs_shell/fssh.cpp +++ b/src/tools/fs_shell/fssh.cpp @@ -24,6 +24,7 @@ #include "fssh_errno.h" #include "fssh_errors.h" #include "fssh_module.h" +#include "fssh_node_monitor.h" #include "fssh_stat.h" #include "fssh_string.h" #include "fssh_type_constants.h" @@ -94,7 +95,7 @@ init_kernel() return rootDev; } - // set cwd to "/" + // set cwd to "/" error = _kern_setcwd(-1, "/"); if (error != FSSH_B_OK) { fprintf(stderr, "setting cwd failed: %s\n", fssh_strerror(error)); @@ -348,7 +349,7 @@ command_chmod(int argc, const char* const* argv) } fssh_status_t error = _kern_write_stat(-1, file, false, &st, sizeof(st), - FSSH_FS_WRITE_STAT_MODE); + FSSH_B_STAT_MODE); if (error != FSSH_B_OK) { fprintf(stderr, "Error: Failed to change mode of \"%s\"!\n", file); return error; @@ -435,7 +436,7 @@ command_ln(int argc, const char* const* argv) fprintf(stderr, "Error: Resulting target path is too long.\n"); return FSSH_B_BAD_VALUE; } - + strcpy(targetBuffer, target); strcat(targetBuffer, "/"); strcat(targetBuffer, leaf); @@ -777,7 +778,7 @@ command_mkindex(int argc, const char* const* argv) fssh_dev_t volumeID = get_volume_id(); if (volumeID < 0) return volumeID; - + // create the index fssh_status_t error =_kern_create_index(volumeID, indexName, FSSH_B_STRING_TYPE, 0); @@ -805,7 +806,7 @@ command_query(int argc, const char* const* argv) fssh_dev_t volumeID = get_volume_id(); if (volumeID < 0) return volumeID; - + // open query int fd = _kern_open_query(volumeID, query, strlen(query), 0, -1, -1); if (fd < 0) { @@ -977,7 +978,7 @@ command_rm(int argc, char **argv) } } } - + // check params if (argi >= argc) { fprintf(stderr, "Usage: %s [ -r ] ...\n", argv[0]);