Some code and style cleanup

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20309 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Gerasim Troeglazov 2007-03-03 06:59:35 +00:00
parent 348be5b50b
commit 6a15f740b9
4 changed files with 47 additions and 73 deletions

View File

@ -40,10 +40,6 @@
#include "volume_util.h" #include "volume_util.h"
#include "fs_func.h" #include "fs_func.h"
#ifndef _READ_ONLY_
static status_t do_unlink(nspace *vol, vnode *dir, const char *name, bool isdir);
#endif
#ifdef __HAIKU__ #ifdef __HAIKU__
typedef struct identify_cookie { typedef struct identify_cookie {
@ -129,10 +125,6 @@ fs_mount(nspace_id nsid, const char *device, ulong flags, void *parms, size_t le
*ns = (nspace) { *ns = (nspace) {
.state = NF_FreeClustersOutdate | NF_FreeMFTOutdate, .state = NF_FreeClustersOutdate | NF_FreeMFTOutdate,
.uid = 0,
.gid = 0,
.fmask = 0177,
.dmask = 0777,
.show_sys_files = false, .show_sys_files = false,
}; };
@ -558,7 +550,7 @@ fs_rstat( void *_ns, void *_node, struct stat *stbuf )
stbuf->st_ino = MREF(ni->mft_no); 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 = S_IFDIR | (0777 & ~ns->dmask); stbuf->st_mode = S_IFDIR | 0777;
na = ntfs_attr_open(ni, AT_INDEX_ALLOCATION, NTFS_INDEX_I30, 4); na = ntfs_attr_open(ni, AT_INDEX_ALLOCATION, NTFS_INDEX_I30, 4);
if (na) { if (na) {
stbuf->st_size = na->data_size; stbuf->st_size = na->data_size;
@ -606,10 +598,10 @@ fs_rstat( void *_ns, void *_node, struct stat *stbuf )
free(intx_file); free(intx_file);
} }
ntfs_attr_close(na); ntfs_attr_close(na);
stbuf->st_mode |= (0777 & ~ns->fmask); stbuf->st_mode |= 0666;
} }
stbuf->st_uid = ns->uid; stbuf->st_uid = 0;
stbuf->st_gid = ns->gid; stbuf->st_gid = 0;
stbuf->st_atime = ni->last_access_time; stbuf->st_atime = ni->last_access_time;
stbuf->st_ctime = ni->last_mft_change_time; stbuf->st_ctime = ni->last_mft_change_time;
stbuf->st_mtime = ni->last_data_change_time; stbuf->st_mtime = ni->last_data_change_time;
@ -704,7 +696,7 @@ exit:
if(ni) if(ni)
ntfs_inode_close(ni); ntfs_inode_close(ni);
ERRPRINT("dosfs_wstat: EXIT with (%s)\n", strerror(result)); ERRPRINT("fs_wstat: EXIT with (%s)\n", strerror(result));
UNLOCK_VOL(ns); UNLOCK_VOL(ns);
@ -1694,7 +1686,6 @@ exit:
#endif #endif
#ifndef _READ_ONLY_ #ifndef _READ_ONLY_
static
status_t status_t
do_unlink(nspace *vol, vnode *dir, const char *name, bool isdir) do_unlink(nspace *vol, vnode *dir, const char *name, bool isdir)
{ {

View File

@ -117,7 +117,7 @@ int fs_create_symlink(void *ns, void *_dir, const char *name, const char *path
#endif //__HAIKU__ #endif //__HAIKU__
#ifndef _READ_ONLY_ #ifndef _READ_ONLY_
static status_t do_unlink(nspace *vol, vnode *dir, const char *name, bool isdir); status_t do_unlink(nspace *vol, vnode *dir, const char *name, bool isdir);
#endif #endif
#endif #endif

View File

@ -122,10 +122,6 @@ typedef struct nspace
int state; int state;
s64 free_clusters; s64 free_clusters;
long free_mft; long free_mft;
unsigned int uid;
unsigned int gid;
unsigned int fmask;
unsigned int dmask;
BOOL ro; BOOL ro;
BOOL show_sys_files; BOOL show_sys_files;
BOOL silent; BOOL silent;

View File

@ -46,17 +46,16 @@ int _ntfs_dirent_dot_filler(void *_dirent, const ntfschar *name,
char *filename = NULL; char *filename = NULL;
dircookie *cookie = (dircookie*)_dirent; dircookie *cookie = (dircookie*)_dirent;
if (name_type == FILE_NAME_DOS)return 0; if (name_type == FILE_NAME_DOS)
return 0;
if (ntfs_ucstombs(name, name_len, &filename, 0) < 0) if (ntfs_ucstombs(name, name_len, &filename, 0) < 0) {
{
ERRPRINT("Skipping unrepresentable filename\n"); ERRPRINT("Skipping unrepresentable filename\n");
return 0; return 0;
} }
if(strcmp(filename,".")==0 || strcmp(filename,"..")==0) if(strcmp(filename,".")==0 || strcmp(filename,"..")==0) {
if (MREF(mref) == FILE_root || MREF(mref) >= FILE_first_user || false) if (MREF(mref) == FILE_root || MREF(mref) >= FILE_first_user || false) {
{
struct direntry *ent = (direntry*)ntfs_calloc(sizeof(direntry)); struct direntry *ent = (direntry*)ntfs_calloc(sizeof(direntry));
ent->name = (char*)ntfs_calloc(strlen(filename)+1); ent->name = (char*)ntfs_calloc(strlen(filename)+1);
strcpy(ent->name,filename); strcpy(ent->name,filename);
@ -64,8 +63,7 @@ int _ntfs_dirent_dot_filler(void *_dirent, const ntfschar *name,
ent->ino=MREF(mref); ent->ino=MREF(mref);
ent->next = NULL; ent->next = NULL;
if(cookie->root==NULL) if(cookie->root==NULL) {
{
cookie->root = ent; cookie->root = ent;
cookie->walk = ent; cookie->walk = ent;
} }
@ -74,12 +72,11 @@ int _ntfs_dirent_dot_filler(void *_dirent, const ntfschar *name,
cookie->last->next = ent; cookie->last->next = ent;
cookie->last = ent; cookie->last = ent;
} else { } else {
free(filename);
free(filename); return -1;
return -1; }
} }
free(filename); free(filename);
return 0; return 0;
} }
@ -92,19 +89,18 @@ int _ntfs_dirent_filler(void *_dirent, const ntfschar *name,
char *filename = NULL; char *filename = NULL;
dircookie *cookie = (dircookie*)_dirent; dircookie *cookie = (dircookie*)_dirent;
if (name_type == FILE_NAME_DOS)return 0; if (name_type == FILE_NAME_DOS)
return 0;
if (ntfs_ucstombs(name, name_len, &filename, 0) < 0) if (ntfs_ucstombs(name, name_len, &filename, 0) < 0) {
{
ERRPRINT("Skipping unrepresentable filename\n"); ERRPRINT("Skipping unrepresentable filename\n");
return 0; return 0;
} }
if(strcmp(filename,".")==0 || strcmp(filename,"..")==0) if(strcmp(filename,".")==0 || strcmp(filename,"..")==0)
return 0; return 0;
if (MREF(mref) == FILE_root || MREF(mref) >= FILE_first_user || false) if (MREF(mref) == FILE_root || MREF(mref) >= FILE_first_user || false) {
{
struct direntry *ent = (direntry*)ntfs_calloc(sizeof(direntry)); struct direntry *ent = (direntry*)ntfs_calloc(sizeof(direntry));
ent->name = (char*)ntfs_calloc(strlen(filename)+1); ent->name = (char*)ntfs_calloc(strlen(filename)+1);
strcpy(ent->name,filename); strcpy(ent->name,filename);
@ -112,8 +108,7 @@ int _ntfs_dirent_filler(void *_dirent, const ntfschar *name,
ent->ino=MREF(mref); ent->ino=MREF(mref);
ent->next = NULL; ent->next = NULL;
if(cookie->root==NULL) if(cookie->root==NULL) {
{
cookie->root = ent; cookie->root = ent;
cookie->walk = ent; cookie->walk = ent;
} }
@ -163,7 +158,6 @@ fs_opendir( void *_ns, void *_node, void **_cookie )
int result = B_NO_ERROR; int result = B_NO_ERROR;
ntfs_inode *ni=NULL; ntfs_inode *ni=NULL;
dircookie *cookie = (dircookie*)ntfs_calloc( sizeof(dircookie) ); dircookie *cookie = (dircookie*)ntfs_calloc( sizeof(dircookie) );
u64 pos=0;
LOCK_VOL(ns); LOCK_VOL(ns);
@ -180,8 +174,7 @@ fs_opendir( void *_ns, void *_node, void **_cookie )
goto exit; goto exit;
} }
if ( cookie != NULL ) if ( cookie != NULL ) {
{
cookie->dev = ns->id; cookie->dev = ns->id;
cookie->pos = 0; cookie->pos = 0;
//cookie->walk_dir = ni; //cookie->walk_dir = ni;
@ -190,9 +183,9 @@ fs_opendir( void *_ns, void *_node, void **_cookie )
cookie->last = NULL; cookie->last = NULL;
cookie->walk = NULL; cookie->walk = NULL;
*_cookie = (void*)cookie; *_cookie = (void*)cookie;
} } else {
else
result = ENOMEM; result = ENOMEM;
}
exit: exit:
if(ni) if(ni)
@ -222,22 +215,22 @@ fs_closedir( void *_ns, void *node, void *_cookie )
ERRPRINT("fs_closedir - ENTER\n"); ERRPRINT("fs_closedir - ENTER\n");
entry=cookie->root; entry=cookie->root;
if(entry) if(entry) {
for(;;) for(;;) {
{ entrynext = entry->next;
entrynext = entry->next;
if(entry->name) if(entry->name)
free(entry->name); free(entry->name);
if(entry) if(entry)
free(entry); free(entry);
entry = entrynext; entry = entrynext;
if(!entry) if(!entry)
break; break;
} }
}
ERRPRINT("fs_closedir - EXIT\n"); ERRPRINT("fs_closedir - EXIT\n");
@ -266,14 +259,12 @@ fs_readdir(void *_ns, void *_node, void *_cookie, long *num, struct dirent *buf,
ERRPRINT("fs_readdir - ENTER:\n"); ERRPRINT("fs_readdir - ENTER:\n");
if (!ns || !node || !cookie || !num || bufsize < sizeof(buf)) if (!ns || !node || !cookie || !num || bufsize < sizeof(buf)) {
{
result = -1; result = -1;
goto quit; goto quit;
} }
if(cookie->pos==0) if(cookie->pos==0) {
{
ni = ntfs_inode_open(ns->ntvol, node->vnid); ni = ntfs_inode_open(ns->ntvol, node->vnid);
if(ni==NULL) { if(ni==NULL) {
result = ENOENT; result = ENOENT;
@ -281,28 +272,25 @@ fs_readdir(void *_ns, void *_node, void *_cookie, long *num, struct dirent *buf,
} }
ntfs_readdir(ni, &pos, cookie, (ntfs_filldir_t)_ntfs_dirent_dot_filler); ntfs_readdir(ni, &pos, cookie, (ntfs_filldir_t)_ntfs_dirent_dot_filler);
cookie->pos+=2; cookie->pos+=2;
} } else {
else if(cookie->pos==2) {
if(cookie->pos==2) ni = ntfs_inode_open(ns->ntvol, node->vnid);
{
ni = ntfs_inode_open(ns->ntvol, node->vnid);
if(ni==NULL) { if(ni==NULL) {
result = ENOENT; result = ENOENT;
goto quit; goto quit;
} }
ntfs_readdir(ni, &pos, cookie, (ntfs_filldir_t)_ntfs_dirent_filler); ntfs_readdir(ni, &pos, cookie, (ntfs_filldir_t)_ntfs_dirent_filler);
cookie->pos++; cookie->pos++;
}
} }
if(cookie->root==NULL || cookie->last==NULL) if(cookie->root==NULL || cookie->last==NULL) {
{
result = -1; result = -1;
goto quit; goto quit;
} }
if(cookie->walk==NULL) if(cookie->walk==NULL) {
{
result = ENOENT; result = ENOENT;
goto quit; goto quit;
} }
@ -354,9 +342,8 @@ fs_rewinddir( void *_ns, void *_node, void *_cookie )
LOCK_VOL(ns); LOCK_VOL(ns);
ERRPRINT("fs_rewinddir - ENTER\n"); ERRPRINT("fs_rewinddir - ENTER\n");
if ( cookie != NULL ) if ( cookie != NULL ) {
{ cookie->pos = 0;
//cookie->pos = 0;
cookie->walk = cookie->root; cookie->walk = cookie->root;
result = B_NO_ERROR; result = B_NO_ERROR;
} }