[Haiku-commits] r30996 - haiku/trunk/src/add-ons/kernel/file_systems/ntfs
axeld at BerliOS
axeld at mail.berlios.de
Mon Jun 8 10:53:55 CEST 2009
Author: axeld
Date: 2009-06-08 10:53:53 +0200 (Mon, 08 Jun 2009)
New Revision: 30996
ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=30996&view=rev
Modified:
haiku/trunk/src/add-ons/kernel/file_systems/ntfs/fs_func.c
haiku/trunk/src/add-ons/kernel/file_systems/ntfs/fs_func.h
Log:
* Fixed missing B_FS_IS_READONLY flag in fs_rfsstat(). This fixes bug #4009.
* Fixed many occurences of incorrect operator order, ie. "!flags & FLAG" does
not what you might think it does.
* Added TODOs to functionally questionable code. I really don't think this file
system should actually be used read-write. Deleting files seems to be
completely broken.
* Fixed mixup of B_MOUNT_READ_ONLY vs. B_FS_IS_READONLY in nspace::flags.
* Fixed many, many style issues, that file really was a mess.
* Honoured 80 characters per line limit.
Modified: haiku/trunk/src/add-ons/kernel/file_systems/ntfs/fs_func.c
===================================================================
--- haiku/trunk/src/add-ons/kernel/file_systems/ntfs/fs_func.c 2009-06-08 07:01:58 UTC (rev 30995)
+++ haiku/trunk/src/add-ons/kernel/file_systems/ntfs/fs_func.c 2009-06-08 08:53:53 UTC (rev 30996)
@@ -66,7 +66,7 @@
if (!na)
return ENOENT;
- if (!ni->flags & FILE_ATTR_HIDDEN) {
+ if (!(ni->flags & FILE_ATTR_HIDDEN)) {
if (na->data_size == 0)
*_type = S_IFIFO;
}
@@ -101,9 +101,9 @@
{
NTFS_BOOT_SECTOR boot;
identify_cookie *cookie;
- ntfs_volume *ntVolume;
- uint8 *buf=(uint8*)&boot;
- char devpath[256];
+ 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");
@@ -112,53 +112,56 @@
}
// check boot signature
- if (((buf[0x1fe] != 0x55) || (buf[0x1ff] != 0xaa)) && (buf[0x15] == 0xf8))
+ if ((buf[0x1fe] != 0x55 || buf[0x1ff] != 0xaa) && buf[0x15] == 0xf8)
return -1;
- //check boot signature NTFS
- if (memcmp(buf+3, "NTFS ", 8)!=0)
+ // check boot signature NTFS
+ if (memcmp(buf + 3, "NTFS ", 8) != 0)
return -1;
- //get path for device
- if(!ioctl(fd,B_GET_PATH_FOR_DEVICE,devpath))
+ // get path for device
+ if (!ioctl(fd, B_GET_PATH_FOR_DEVICE, devpath))
return -1;
- //try mount
- ntVolume = utils_mount_volume(devpath,MS_RDONLY,true);
- if(!ntVolume)
+
+ // try mount
+ ntVolume = utils_mount_volume(devpath, MS_RDONLY, true);
+ if (!ntVolume)
return -1;
- //allocate identify_cookie
+ // allocate identify_cookie
cookie = (identify_cookie *)malloc(sizeof(identify_cookie));
if (!cookie)
return -1;
- memcpy(&(cookie->boot),&boot,512);
+ 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);
+ if (ntVolume->vol_name && ntVolume->vol_name[0] != '\0')
+ strcpy(cookie->label, ntVolume->vol_name);
- ntfs_umount( ntVolume, true );
+ ntfs_umount(ntVolume, true);
*_cookie = cookie;
return 0.8f;
}
+
status_t
fs_scan_partition(int fd, partition_data *partition, void *_cookie)
{
identify_cookie *cookie = (identify_cookie *)_cookie;
partition->status = B_PARTITION_VALID;
partition->flags |= B_PARTITION_FILE_SYSTEM;
- partition->content_size = sle64_to_cpu(cookie->boot.number_of_sectors) * le16_to_cpu(cookie->boot.bpb.bytes_per_sector);
+ partition->content_size = sle64_to_cpu(cookie->boot.number_of_sectors)
+ * le16_to_cpu(cookie->boot.bpb.bytes_per_sector);
partition->block_size = le16_to_cpu(cookie->boot.bpb.bytes_per_sector);
partition->content_name = strdup(cookie->label);
return B_OK;
}
+
void
fs_free_identify_partition_cookie(partition_data *partition, void *_cookie)
{
@@ -168,51 +171,55 @@
status_t
-fs_mount(fs_volume *_vol, const char *device, ulong flags, const char *args, ino_t *_rootID)
+fs_mount(fs_volume *_vol, const char *device, ulong flags, const char *args,
+ ino_t *_rootID)
{
- nspace *ns;
- vnode *newNode = NULL;
- char lockname[32];
- void *handle;
- unsigned long mnt_flags = 0;
- status_t result = B_NO_ERROR;
+ nspace *ns;
+ vnode *newNode = NULL;
+ char lockname[32];
+ void *handle;
+ unsigned long mountFlags = 0;
+ status_t result = B_NO_ERROR;
ERRPRINT("fs_mount - ENTER\n");
ns = ntfs_malloc(sizeof(nspace));
if (!ns) {
result = ENOMEM;
- goto exit;
+ goto exit;
}
*ns = (nspace) {
.state = NF_FreeClustersOutdate | NF_FreeMFTOutdate,
.show_sys_files = false,
- .ro = false
+ .ro = false,
+ .flags = 0
};
- ns->flags = flags;
-
strcpy(ns->devicePath,device);
sprintf(lockname, "ntfs_lock %lx", ns->id);
recursive_lock_init_etc(&(ns->vlock), lockname, MUTEX_FLAG_CLONE_NAME);
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;
+ 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->ro || (flags & B_MOUNT_READ_ONLY) != 0) {
+ mountFlags |= MS_RDONLY;
+ ns->flags |= B_FS_IS_READONLY;
}
// if (ns->noatime)
// mnt_flags |= MS_NOATIME;
- ns->ntvol=utils_mount_volume(device,mnt_flags,true);
- if(ns->ntvol!=NULL)
+ // TODO: this does not take read-only volumes into account!
+ ns->ntvol = utils_mount_volume(device, mountFlags, true);
+ if (ns->ntvol != NULL)
result = B_NO_ERROR;
else
result = errno;
@@ -223,22 +230,20 @@
_vol->private_volume = (void *)ns;
_vol->ops = &gNTFSVolumeOps;
- newNode = (vnode*)ntfs_calloc( sizeof(vnode) );
- if ( newNode == NULL )
+ newNode = (vnode*)ntfs_calloc(sizeof(vnode));
+ if (newNode == NULL)
result = ENOMEM;
else {
-
newNode->vnid = *_rootID;
newNode->parent_vnid = -1;
- result = publish_vnode( _vol, *_rootID, (void*)newNode,
+ result = publish_vnode(_vol, *_rootID, (void*)newNode,
&gNTFSVnodeOps, S_IFDIR, 0);
- if ( result != B_NO_ERROR ) {
- free( ns );
+ if (result != B_NO_ERROR) {
+ free(ns);
result = EINVAL;
- goto exit;
- }
- else {
+ goto exit;
+ } else {
result = B_NO_ERROR;
ntfs_mark_free_space_outdated(ns);
ntfs_calc_free_space(ns);
@@ -247,36 +252,37 @@
}
exit:
-
ERRPRINT("fs_mount - EXIT, result code is %s\n", strerror(result));
return result;
}
+
status_t
fs_unmount(fs_volume *_vol)
{
- nspace *ns = (nspace*)_vol->private_volume;
- status_t result = B_NO_ERROR;
+ nspace *ns = (nspace*)_vol->private_volume;
+ status_t result = B_NO_ERROR;
ERRPRINT("fs_unmount - ENTER\n");
- ntfs_umount( ns->ntvol, true );
+ ntfs_umount(ns->ntvol, true);
recursive_lock_destroy(&(ns->vlock));
- free( ns );
+ free(ns);
ERRPRINT("fs_unmount - EXIT, result is %s\n", strerror(result));
return result;
}
+
status_t
-fs_rfsstat( fs_volume *_vol, struct fs_info * fss )
+fs_rfsstat(fs_volume *_vol, struct fs_info *fss)
{
- nspace *ns = (nspace*)_vol->private_volume;
- int i;
+ nspace *ns = (nspace*)_vol->private_volume;
+ int i;
LOCK_VOL(ns);
@@ -286,23 +292,25 @@
fss->dev = ns->id;
fss->root = FILE_root;
- fss->flags = B_FS_IS_PERSISTENT|B_FS_HAS_MIME|B_FS_HAS_ATTR;
+ fss->flags = B_FS_IS_PERSISTENT | B_FS_HAS_MIME | B_FS_HAS_ATTR | ns->flags;
+
fss->block_size = ns->ntvol->cluster_size;
fss->io_size = 65536;
fss->total_blocks = ns->ntvol->nr_clusters;
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) );
+ 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--)
+ for (i = strlen(fss->volume_name) - 1; i >=0 ; i--) {
if (fss->volume_name[i] != ' ')
break;
+ }
if (i < 0)
strcpy(fss->volume_name, "NTFS Untitled");
else
fss->volume_name[i + 1] = 0;
- strcpy( fss->fsh_name, "NTFS" );
+ strcpy(fss->fsh_name, "NTFS");
ERRPRINT("fs_rfsstat - EXIT\n");
@@ -313,10 +321,10 @@
status_t
-fs_wfsstat( fs_volume *_vol, const struct fs_info * fss, uint32 mask)
+fs_wfsstat(fs_volume *_vol, const struct fs_info *fss, uint32 mask)
{
- nspace* ns = (nspace*)_vol->private_volume;
- status_t result = B_NO_ERROR;
+ nspace* ns = (nspace*)_vol->private_volume;
+ status_t result = B_NO_ERROR;
if (ns->flags & B_FS_IS_READONLY) {
ERRPRINT("ntfs is read-only\n");
@@ -326,79 +334,78 @@
LOCK_VOL(ns);
if (mask & FS_WRITE_FSINFO_NAME) {
- result = ntfs_change_label( ns->ntvol, (char*)fss->volume_name );
+ result = ntfs_change_label(ns->ntvol, (char*)fss->volume_name);
goto exit;
}
exit:
-
UNLOCK_VOL(ns);
return result;
}
+
status_t
fs_walk(fs_volume *_vol, fs_vnode *_dir, const char *file, ino_t *vnid)
{
- nspace *ns = (nspace*)_vol->private_volume;
- vnode *baseNode = (vnode*)_dir->private_node;
- vnode *newNode = NULL;
- ntfschar *unicode = NULL;
- ntfs_inode *bi = NULL;
- status_t result = B_NO_ERROR;
- int len;
+ nspace *ns = (nspace*)_vol->private_volume;
+ vnode *baseNode = (vnode*)_dir->private_node;
+ vnode *newNode = NULL;
+ ntfschar *unicode = NULL;
+ ntfs_inode *bi = NULL;
+ status_t result = B_NO_ERROR;
+ int len;
LOCK_VOL(ns);
ERRPRINT("fs_walk - ENTER : find for \"%s\"\n",file);
- if(ns == NULL || _dir == NULL || file == NULL || vnid == NULL) {
- result = EINVAL;
- goto exit;
- }
+ if (ns == NULL || _dir == NULL || file == NULL || vnid == NULL) {
+ result = EINVAL;
+ goto exit;
+ }
- if ( !strcmp( file, "." ) ) {
+ if (!strcmp(file, ".")) {
*vnid = baseNode->vnid;
- if ( get_vnode( _vol, *vnid, (void**)&newNode ) != 0 )
+ if (get_vnode(_vol, *vnid, (void**)&newNode) != 0)
result = ENOENT;
- } else if ( !strcmp( file, ".." ) && baseNode->vnid != FILE_root ) {
+ } else if (!strcmp(file, "..") && baseNode->vnid != FILE_root) {
*vnid = baseNode->parent_vnid;
- if ( get_vnode( _vol, *vnid, (void**)&newNode ) != 0 )
+ if (get_vnode(_vol, *vnid, (void**)&newNode) != 0)
result = ENOENT;
} else {
- unicode = ntfs_calloc(MAX_PATH);
- len = ntfs_mbstoucs(file, &unicode);
- if (len < 0) {
- result = EILSEQ;
- goto exit;
- }
+ unicode = ntfs_calloc(MAX_PATH);
+ len = ntfs_mbstoucs(file, &unicode);
+ if (len < 0) {
+ result = EILSEQ;
+ goto exit;
+ }
- bi = ntfs_inode_open(ns->ntvol, baseNode->vnid);
- if(!bi) {
- result = ENOENT;
- 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) );
- ERRPRINT("fs_walk - VNID = %d\n",*vnid);
+ *vnid = MREF(ntfs_inode_lookup_by_name(bi, unicode, len));
+ ERRPRINT("fs_walk - VNID = %d\n",*vnid);
- ntfs_inode_close(bi);
- free(unicode);
+ ntfs_inode_close(bi);
+ free(unicode);
- if ( *vnid == (u64) -1 ) {
- result = EINVAL;
- goto exit;
- }
+ if (*vnid == (u64)-1) {
+ result = EINVAL;
+ goto exit;
+ }
- if( get_vnode( _vol, *vnid, (void**)&newNode ) !=0 )
- result = ENOENT;
+ if (get_vnode(_vol, *vnid, (void**)&newNode) != 0)
+ result = ENOENT;
- if(newNode!=NULL)
- newNode->parent_vnid = baseNode->vnid;
+ if (newNode!=NULL)
+ newNode->parent_vnid = baseNode->vnid;
}
exit:
-
ERRPRINT("fs_walk - EXIT, result is %s\n", strerror(result));
UNLOCK_VOL(ns);
@@ -406,37 +413,39 @@
return result;
}
+
status_t
-fs_get_vnode_name(fs_volume *_vol, fs_vnode *_vnode, char *buffer, size_t bufferSize)
+fs_get_vnode_name(fs_volume *_vol, fs_vnode *_vnode, char *buffer,
+ size_t bufferSize)
{
- nspace *ns = (nspace*)_vol->private_volume;
- vnode *node = (vnode*)_vnode->private_node;
- ntfs_inode *ni=NULL;
- status_t result = B_NO_ERROR;
+ nspace *ns = (nspace*)_vol->private_volume;
+ vnode *node = (vnode*)_vnode->private_node;
+ ntfs_inode *ni = NULL;
+ status_t result = B_NO_ERROR;
- char path[MAX_PATH];
- char *name;
+ char path[MAX_PATH];
+ char *name;
LOCK_VOL(ns);
ni = ntfs_inode_open(ns->ntvol, node->vnid);
- if(ni==NULL) {
- result = ENOENT;
- goto exit;
+ if (ni == NULL) {
+ result = ENOENT;
+ goto exit;
}
- if(utils_inode_get_name(ni, path, MAX_PATH)==0) {
+ if (utils_inode_get_name(ni, path, MAX_PATH) == 0) {
result = EINVAL;
- goto exit;
+ goto exit;
}
+
name = strrchr(path, '/');
name++;
strlcpy(buffer, name, bufferSize);
exit:
-
- if(ni)
+ if (ni)
ntfs_inode_close(ni);
UNLOCK_VOL(ns);
@@ -446,14 +455,15 @@
status_t
-fs_read_vnode(fs_volume *_vol, ino_t vnid, fs_vnode *_node, int *_type, uint32 *_flags, bool reenter)
+fs_read_vnode(fs_volume *_vol, ino_t vnid, fs_vnode *_node, int *_type,
+ uint32 *_flags, bool reenter)
{
- nspace *ns = (nspace*)_vol->private_volume;
- vnode *newNode = NULL;
- ntfs_inode *ni=NULL;
- status_t result = B_NO_ERROR;
+ nspace *ns = (nspace*)_vol->private_volume;
+ vnode *newNode = NULL;
+ ntfs_inode *ni = NULL;
+ status_t result = B_NO_ERROR;
- if ( !reenter )
+ if (!reenter)
LOCK_VOL(ns);
ERRPRINT("fs_read_vnode - ENTER\n");
@@ -462,8 +472,8 @@
_node->ops = &gNTFSVnodeOps;
_flags = 0;
- newNode = (vnode*)ntfs_calloc( sizeof(vnode) );
- if ( newNode != NULL ) {
+ newNode = (vnode*)ntfs_calloc(sizeof(vnode));
+ if (newNode != NULL) {
char *name = NULL;
ni = ntfs_inode_open(ns->ntvol, vnid);
@@ -480,23 +490,22 @@
newNode->vnid = vnid;
newNode->parent_vnid = ntfs_get_parent_ref(ni);
- if( ni->mrec->flags & MFT_RECORD_IS_DIRECTORY )
+ if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)
set_mime(newNode, ".***");
else {
name = (char*)malloc(MAX_PATH);
- if(name!=NULL) {
- if(utils_inode_get_name(ni, name,MAX_PATH)==1)
+ if (name != NULL) {
+ if (utils_inode_get_name(ni, name,MAX_PATH) == 1)
set_mime(newNode, name);
free(name);
}
}
_node->private_node = newNode;
- }
- else
+ } else
result = ENOMEM;
+
exit:
-
if (ni != NULL)
ntfs_inode_close(ni);
@@ -505,78 +514,80 @@
ERRPRINT("fs_read_vnode - EXIT, result is %s\n", strerror(result));
- if ( !reenter )
+ if (!reenter)
UNLOCK_VOL(ns);
return result;
}
+
status_t
-fs_write_vnode( fs_volume *_vol, fs_vnode *_node, bool reenter )
+fs_write_vnode(fs_volume *_vol, fs_vnode *_node, bool reenter)
{
- nspace *ns = (nspace*)_vol->private_volume;
- vnode *node = (vnode*)_node->private_node;
- status_t result = B_NO_ERROR;
+ nspace *ns = (nspace*)_vol->private_volume;
+ vnode *node = (vnode*)_node->private_node;
+ status_t result = B_NO_ERROR;
- if ( !reenter )
+ if (!reenter)
LOCK_VOL(ns);
ERRPRINT("fs_write_vnode - ENTER (%Ld)\n", node->vnid);
- if (node)
- free( node );
+ free(node);
ERRPRINT("fs_write_vnode - EXIT\n");
- if ( !reenter )
+ if (!reenter)
UNLOCK_VOL(ns);
return result;
}
+
status_t
-fs_remove_vnode( fs_volume *_vol, fs_vnode *_node, bool reenter )
+fs_remove_vnode(fs_volume *_vol, fs_vnode *_node, bool reenter)
{
- nspace *ns = (nspace*)_vol->private_volume;
- vnode *node = (vnode*)_node->private_node;
- status_t result = B_NO_ERROR;
+ nspace *ns = (nspace*)_vol->private_volume;
+ vnode *node = (vnode*)_node->private_node;
+ status_t result = B_NO_ERROR;
- if ( !reenter )
+ // TODO: this does not look right! The space if the node must be freed *here*
+ if (!reenter)
LOCK_VOL(ns);
ERRPRINT("fs_remove_vnode - ENTER (%Ld)\n", node->vnid);
- if(node)
- free(node);
+ free(node);
ERRPRINT("fs_remove_vnode - EXIT, result is %s\n", strerror(result));
- if ( !reenter )
+ if (!reenter)
UNLOCK_VOL(ns);
return result;
}
+
status_t
-fs_rstat( fs_volume *_vol, fs_vnode *_node, struct stat *stbuf )
+fs_rstat(fs_volume *_vol, fs_vnode *_node, struct stat *stbuf)
{
- nspace *ns = (nspace*)_vol->private_volume;
- vnode *node = (vnode*)_node->private_node;
- ntfs_inode *ni = NULL;
- ntfs_attr *na;
- status_t result = B_NO_ERROR;
+ nspace *ns = (nspace*)_vol->private_volume;
+ vnode *node = (vnode*)_node->private_node;
+ ntfs_inode *ni = NULL;
+ ntfs_attr *na;
+ status_t result = B_NO_ERROR;
LOCK_VOL(ns);
ERRPRINT("fs_rstat - ENTER:\n");
- if(ns==NULL || node ==NULL ||stbuf==NULL) {
+ if (ns == NULL || node == NULL ||stbuf == NULL) {
result = ENOENT;
goto exit;
}
ni = ntfs_inode_open(ns->ntvol, node->vnid);
- if(ni==NULL) {
+ if (ni == NULL) {
result = ENOENT;
goto exit;
}
@@ -584,7 +595,7 @@
stbuf->st_dev = ns->id;
stbuf->st_ino = MREF(ni->mft_no);
- if ( ni->mrec->flags & MFT_RECORD_IS_DIRECTORY ) {
+ if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) {
stbuf->st_mode = FS_DIR_MODE;
na = ntfs_attr_open(ni, AT_INDEX_ALLOCATION, NTFS_INDEX_I30, 4);
if (na) {
@@ -608,12 +619,14 @@
stbuf->st_size = na->data_size;
- if (!ni->flags & FILE_ATTR_HIDDEN) {
+ if (!(ni->flags & FILE_ATTR_HIDDEN)) {
if (na->data_size == 0)
stbuf->st_mode = S_IFIFO;
}
- if (na->data_size <= sizeof(INTX_FILE_TYPES) + sizeof(ntfschar) * MAX_PATH && na->data_size >sizeof(INTX_FILE_TYPES)) {
+ if (na->data_size <= sizeof(INTX_FILE_TYPES)
+ + sizeof(ntfschar) * MAX_PATH
+ && na->data_size >sizeof(INTX_FILE_TYPES)) {
INTX_FILE *intx_file;
intx_file = ntfs_malloc(na->data_size);
@@ -622,7 +635,8 @@
ntfs_attr_close(na);
goto exit;
}
- if (ntfs_attr_pread(na, 0, na->data_size,intx_file) != na->data_size) {
+ if (ntfs_attr_pread(na, 0, na->data_size,intx_file)
+ != na->data_size) {
result = EINVAL;
free(intx_file);
ntfs_attr_close(na);
@@ -637,7 +651,7 @@
}
if (ns->flags & B_FS_IS_READONLY) {
- stbuf->st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
+ stbuf->st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
}
stbuf->st_uid = 0;
@@ -647,8 +661,7 @@
stbuf->st_mtime = ni->last_data_change_time;
exit:
-
- if(ni)
+ if (ni)
ntfs_inode_close(ni);
ERRPRINT("fs_rstat - EXIT, result is %s\n", strerror(result));
@@ -656,35 +669,33 @@
UNLOCK_VOL(ns);
return result;
-
}
+
status_t
-fs_wstat( fs_volume *_vol, fs_vnode *_node, const struct stat *st, uint32 mask )
+fs_wstat(fs_volume *_vol, fs_vnode *_node, const struct stat *st, uint32 mask)
{
- nspace *ns = (nspace*)_vol->private_volume;
- vnode *node = (vnode*)_node->private_node;
- ntfs_inode *ni = NULL;
- status_t result = B_NO_ERROR;
+ nspace *ns = (nspace*)_vol->private_volume;
+ vnode *node = (vnode*)_node->private_node;
+ ntfs_inode *ni = NULL;
+ status_t result = B_NO_ERROR;
LOCK_VOL(ns);
ERRPRINT("fs_wstat: ENTER\n");
ni = ntfs_inode_open(ns->ntvol, node->vnid);
- if(ni==NULL) {
- result = ENOENT;
- goto exit;
+ if (ni == NULL) {
+ result = ENOENT;
+ goto exit;
}
- if ( mask & B_STAT_SIZE ) {
-
+ if (mask & B_STAT_SIZE) {
ERRPRINT("fs_wstat: setting file size to %Lx\n", st->st_size);
- if ( ni->mrec->flags & MFT_RECORD_IS_DIRECTORY ) {
+ if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) {
result = EISDIR;
} else {
-
ntfs_attr *na = ntfs_attr_open(ni, AT_DATA, NULL, 0);
if (!na) {
result = EINVAL;
@@ -701,7 +712,6 @@
}
if (mask & B_STAT_MODIFICATION_TIME) {
-
ERRPRINT("fs_wstat: setting modification time\n");
ni->last_access_time = st->st_atime;
@@ -712,8 +722,7 @@
}
exit:
-
- if(ni)
+ if (ni)
ntfs_inode_close(ni);
ERRPRINT("fs_wstat: EXIT with (%s)\n", strerror(result));
@@ -744,10 +753,10 @@
status_t
fs_fsync(fs_volume *_vol, fs_vnode *_node)
{
- nspace *ns = (nspace*)_vol->private_volume;
- vnode *node = (vnode*)_node->private_node;
- ntfs_inode *ni = NULL;
- status_t result = B_NO_ERROR;
+ nspace *ns = (nspace*)_vol->private_volume;
+ vnode *node = (vnode*)_node->private_node;
+ ntfs_inode *ni = NULL;
+ status_t result = B_NO_ERROR;
LOCK_VOL(ns);
@@ -759,16 +768,15 @@
}
ni = ntfs_inode_open(ns->ntvol, node->vnid);
- if(ni==NULL) {
- result = ENOENT;
- goto exit;
+ if (ni == NULL) {
+ result = ENOENT;
+ goto exit;
}
ntfs_inode_sync(ni);
exit:
-
- if(ni)
+ if (ni)
ntfs_inode_close(ni);
ERRPRINT("fs_fsync: EXIT\n");
@@ -778,56 +786,54 @@
return result;
}
+
status_t
fs_open(fs_volume *_vol, fs_vnode *_node, int omode, void **_cookie)
{
- nspace *ns = (nspace*)_vol->private_volume;
- vnode *node = (vnode*)_node->private_node;
- filecookie *cookie=NULL;
- ntfs_inode *ni=NULL;
- ntfs_attr *na = NULL;
- status_t result = B_NO_ERROR;
+ nspace *ns = (nspace*)_vol->private_volume;
+ vnode *node = (vnode*)_node->private_node;
+ filecookie *cookie = NULL;
+ ntfs_inode *ni = NULL;
+ ntfs_attr *na = NULL;
+ status_t result = B_NO_ERROR;
LOCK_VOL(ns);
ERRPRINT("fs_open - ENTER\n");
- if(node==NULL) {
+ if (node == NULL) {
result = EINVAL;
- goto exit;
+ goto exit;
}
ni = ntfs_inode_open(ns->ntvol, node->vnid);
- if(ni==NULL) {
- result = errno;
- goto exit;
+ if (ni == NULL) {
+ result = errno;
+ goto exit;
}
- if(omode & O_TRUNC) {
- na = ntfs_attr_open(ni, AT_DATA, NULL, 0);
- if(na) {
- if(ntfs_attr_truncate(na, 0))
- result = errno;
- } else
+ if (omode & O_TRUNC) {
+ na = ntfs_attr_open(ni, AT_DATA, NULL, 0);
+ if (na) {
+ if (ntfs_attr_truncate(na, 0))
result = errno;
- }
+ } else
+ result = errno;
+ }
- cookie = (filecookie*)ntfs_calloc( sizeof(filecookie) );
+ cookie = (filecookie*)ntfs_calloc(sizeof(filecookie));
- if ( cookie != NULL )
- {
+ if (cookie != NULL) {
cookie->omode = omode;
*_cookie = (void*)cookie;
- }
- else
+ } else
result = ENOMEM;
exit:
-
- if(na)
+ if (na)
ntfs_attr_close(na);
- if(ni)
+ if (ni)
ntfs_inode_close(ni);
ERRPRINT("fs_open - EXIT\n");
@@ -839,18 +845,19 @@
status_t
-fs_create(fs_volume *_vol, fs_vnode *_dir, const char *name, int omode, int perms, void **_cookie, ino_t *_vnid)
+fs_create(fs_volume *_vol, fs_vnode *_dir, const char *name, int omode,
+ int perms, void **_cookie, ino_t *_vnid)
{
- nspace *ns = (nspace*)_vol->private_volume;
- vnode *dir = (vnode*)_dir->private_node;
- filecookie *cookie = NULL;
- vnode *newNode = NULL;
- ntfs_attr *na = NULL;
- ntfs_inode *ni=NULL;
- ntfs_inode *bi=NULL;
- ntfschar *uname = NULL;
- status_t result = B_NO_ERROR;
- int uname_len;
+ nspace *ns = (nspace*)_vol->private_volume;
+ vnode *dir = (vnode*)_dir->private_node;
+ filecookie *cookie = NULL;
+ vnode *newNode = NULL;
+ ntfs_attr *na = NULL;
+ ntfs_inode *ni = NULL;
+ ntfs_inode *bi = NULL;
+ ntfschar *uname = NULL;
+ status_t result = B_NO_ERROR;
+ int unameLength;
if (ns->flags & B_FS_IS_READONLY) {
ERRPRINT("ntfs is read-only\n");
@@ -861,64 +868,65 @@
ERRPRINT("fs_create - ENTER: name=%s\n",name);
- if(_vol==NULL || _dir==NULL) {
+ if (_vol == NULL || _dir == NULL) {
result = EINVAL;
goto exit;
}
- if (name == NULL || *name == '\0' || strchr(name, '/') || strcmp(name, ".") == 0 || strcmp(name, "..") == 0) {
+ 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);
- if(bi==NULL) {
- result = ENOENT;
- goto exit;
+ if (bi == NULL) {
+ result = ENOENT;
+ goto exit;
}
- if ( !bi->mrec->flags & MFT_RECORD_IS_DIRECTORY ) {
- result = EINVAL;
+ if (!(bi->mrec->flags & MFT_RECORD_IS_DIRECTORY)) {
+ result = EINVAL;
goto exit;
}
- uname_len = ntfs_mbstoucs(name, &uname);
- if (uname_len < 0) {
+ unameLength = ntfs_mbstoucs(name, &uname);
+ if (unameLength < 0) {
result = EINVAL;
goto exit;
}
- cookie = (filecookie*)ntfs_calloc( sizeof(filecookie) );
+ cookie = (filecookie*)ntfs_calloc(sizeof(filecookie));
- if ( cookie != NULL ) {
+ if (cookie != NULL) {
cookie->omode = omode;
} else {
result = ENOMEM;
- goto exit;
+ 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 (ni) {
+ // file exists
+ *_vnid = MREF(ni->mft_no);
+ if (omode & O_TRUNC) {
na = ntfs_attr_open(ni, AT_DATA, NULL, 0);
- if(na) {
- if(ntfs_attr_truncate(na, 0))
+ if (na) {
+ if (ntfs_attr_truncate(na, 0))
result = errno;
} else
result = errno;
}
} else {
- ni = ntfs_create(bi, uname, uname_len, S_IFREG);
-
+ ni = ntfs_create(bi, uname, unameLength, 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;
+ newNode = (vnode*)ntfs_calloc(sizeof(vnode));
+ if (newNode == NULL) {
+ result = ENOMEM;
goto exit;
- }
+ }
newNode->vnid = *_vnid;
newNode->parent_vnid = MREF(bi->mft_no);
@@ -930,8 +938,7 @@
ntfs_mark_free_space_outdated(ns);
- notify_entry_created(ns->id, MREF( bi->mft_no ), name, *_vnid);
[... truncated: 1148 lines follow ...]
More information about the Haiku-commits
mailing list