From 53446b07f88cf3b0a20618c7ecc2ca6dbaba0cc1 Mon Sep 17 00:00:00 2001 From: cha0smaster Date: Tue, 8 Nov 2005 15:15:37 +0000 Subject: [PATCH] - Change @type parameter for ntfs_create() to be dev_t rather than internal NTFS_DT_* constants. - Teech ntfs_create() to create FIFOs and sockets. --- ChangeLog | 2 ++ include/ntfs/dir.h | 2 +- libntfs/dir.c | 37 ++++++++++++++++++++++++++----------- ntfsprogs/ntfsmount.c | 17 +++++++++++------ 4 files changed, 40 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index d9437578..6a358524 100644 --- a/ChangeLog +++ b/ChangeLog @@ -69,6 +69,8 @@ xx/xx/2005 - 1.12.2-WIP - Fix allocated data size for resident attributes. (Yura) - ntfsclone: check available free space on the destination before starting to clone or restore. (Szaka) + - Change @type parameter for ntfs_create() to be dev_t rather than + internal NTFS_DT_* constants. (Yura) 10/10/2005 - 1.12.1 - Minor fix to location of mount.ntfs-fuse and mkfs.ntfs. diff --git a/include/ntfs/dir.h b/include/ntfs/dir.h index 49fc88fc..d15c0424 100644 --- a/include/ntfs/dir.h +++ b/include/ntfs/dir.h @@ -49,7 +49,7 @@ extern ntfs_inode *ntfs_pathname_to_inode(ntfs_volume *vol, ntfs_inode *parent, const char *pathname); extern ntfs_inode *ntfs_create(ntfs_inode *dir_ni, ntfschar *name, u8 name_len, - const unsigned type); + dev_t type); extern int ntfs_delete(ntfs_inode *ni, ntfs_inode *dir_ni, ntfschar *name, u8 name_len); extern int ntfs_link(ntfs_inode *ni, ntfs_inode *dir_ni, ntfschar *name, diff --git a/libntfs/dir.c b/libntfs/dir.c index f822bee7..f5dd2428 100644 --- a/libntfs/dir.c +++ b/libntfs/dir.c @@ -34,6 +34,9 @@ #ifdef HAVE_STRING_H #include #endif +#ifdef HAVE_SYS_STAT_H +#include +#endif #include "types.h" #include "debug.h" @@ -1069,20 +1072,24 @@ err_out: } /** - * ntfs_create - create file or directory on ntfs volume + * ntfs_create - create object on ntfs volume * @dir_ni: ntfs inode for directory in which create new object * @name: unicode name of new object * @name_len: length of the name in unicode characters * @type: type of the object to create * - * @type can be either NTFS_DT_REG to create regular file or NTFS_DT_DIR to - * create directory, other valuer are invalid. + * @type can be: + * S_IFREG to create regular file + * S_IFDIR to create directory + * S_IFIFO to create FIFO + * S_IFSOCK to create socket + * other valuer are invalid. * - * Return opened ntfs inode that describes created file on success or NULL + * Return opened ntfs inode that describes created object on success or NULL * on error with errno set to the error code. */ ntfs_inode *ntfs_create(ntfs_inode *dir_ni, ntfschar *name, u8 name_len, - const unsigned type) + dev_t type) { ntfs_inode *ni; FILE_NAME_ATTR *fn = NULL; @@ -1091,8 +1098,9 @@ ntfs_inode *ntfs_create(ntfs_inode *dir_ni, ntfschar *name, u8 name_len, ntfs_log_trace("Entering.\n"); /* Sanity checks. */ - if (!dir_ni || !name || !name_len || - (type != NTFS_DT_REG && type != NTFS_DT_DIR)) { + if (!dir_ni || !name || !name_len || (type != S_IFREG && + type != S_IFDIR && type != S_IFIFO && + type != S_IFSOCK)) { ntfs_log_error("Invalid arguments."); return NULL; } @@ -1117,6 +1125,10 @@ ntfs_inode *ntfs_create(ntfs_inode *dir_ni, ntfschar *name, u8 name_len, si->last_data_change_time = utc2ntfs(ni->last_data_change_time); si->last_mft_change_time = utc2ntfs(ni->last_mft_change_time); si->last_access_time = utc2ntfs(ni->last_access_time); + if (type == S_IFSOCK || type == S_IFIFO) { + si->file_attributes = FILE_ATTR_SYSTEM; + ni->flags = FILE_ATTR_SYSTEM; + } /* Add STANDARD_INFORMATION to inode. */ if (ntfs_attr_add(ni, AT_STANDARD_INFORMATION, AT_UNNAMED, 0, (u8*)si, si_len)) { @@ -1124,7 +1136,7 @@ ntfs_inode *ntfs_create(ntfs_inode *dir_ni, ntfschar *name, u8 name_len, ntfs_log_error("Failed to add STANDARD_INFORMATION attribute."); goto err_out; } - if (type == NTFS_DT_DIR) { + if (type == S_IFDIR) { INDEX_ROOT *ir = NULL; INDEX_ENTRY *ie; int ir_len, index_len; @@ -1164,7 +1176,8 @@ ntfs_inode *ntfs_create(ntfs_inode *dir_ni, ntfschar *name, u8 name_len, } } else { /* Add DATA attribute to inode. */ - if (ntfs_attr_add(ni, AT_DATA, AT_UNNAMED, 0, NULL, 0)) { + if (ntfs_attr_add(ni, AT_DATA, AT_UNNAMED, 0, NULL, + (type == S_IFSOCK) ? 1 : 0)) { err = errno; ntfs_log_error("Failed to add DATA attribute."); goto err_out; @@ -1182,8 +1195,10 @@ ntfs_inode *ntfs_create(ntfs_inode *dir_ni, ntfschar *name, u8 name_len, le16_to_cpu(dir_ni->mrec->sequence_number)); fn->file_name_length = name_len; fn->file_name_type = FILE_NAME_POSIX; - if (type == NTFS_DT_DIR) + if (type == S_IFDIR) fn->file_attributes = FILE_ATTR_DUP_FILE_NAME_INDEX_PRESENT; + if (type == S_IFIFO || type == S_IFSOCK) + fn->file_attributes = FILE_ATTR_SYSTEM; fn->creation_time = utc2ntfs(ni->creation_time); fn->last_data_change_time = utc2ntfs(ni->last_data_change_time); fn->last_mft_change_time = utc2ntfs(ni->last_mft_change_time); @@ -1204,7 +1219,7 @@ ntfs_inode *ntfs_create(ntfs_inode *dir_ni, ntfschar *name, u8 name_len, } /* Set hard links count and directory flag. */ ni->mrec->link_count = cpu_to_le16(1); - if (type == NTFS_DT_DIR) + if (type == S_IFDIR) ni->mrec->flags |= MFT_RECORD_IS_DIRECTORY; ntfs_inode_mark_dirty(ni); /* Done! */ diff --git a/ntfsprogs/ntfsmount.c b/ntfsprogs/ntfsmount.c index 1925da85..7ae3318a 100644 --- a/ntfsprogs/ntfsmount.c +++ b/ntfsprogs/ntfsmount.c @@ -316,7 +316,6 @@ static int ntfs_fuse_getattr(const char *org_path, struct stat *stbuf) stbuf->st_mode = S_IFREG; stbuf->st_size = ni->data_size; stbuf->st_blocks = ni->allocated_size >> vol->sector_size_bits; - stbuf->st_mode |= (0777 & ~ctx->fmask); stbuf->st_nlink = le16_to_cpu(ni->mrec->link_count); if (ni->flags & FILE_ATTR_SYSTEM || stream_name_len) { na = ntfs_attr_open(ni, AT_DATA, stream_name, @@ -388,6 +387,7 @@ static int ntfs_fuse_getattr(const char *org_path, struct stat *stbuf) } ntfs_attr_close(na); } + stbuf->st_mode |= (0777 & ~ctx->fmask); } stbuf->st_uid = ctx->uid; stbuf->st_gid = ctx->gid; @@ -703,7 +703,7 @@ static int ntfs_fuse_chmod(const char *path, return -EOPNOTSUPP; } -static int ntfs_fuse_create(const char *org_path, const unsigned type) +static int ntfs_fuse_create(const char *org_path, dev_t type) { char *name; ntfschar *uname = NULL; @@ -759,7 +759,7 @@ static int ntfs_fuse_create_stream(const char *path, * If such file does not exist, create it and try once * again to add stream to it. */ - res = ntfs_fuse_create(path, NTFS_DT_REG); + res = ntfs_fuse_create(path, S_IFREG); if (!res) return ntfs_fuse_create_stream(path, stream_name, stream_name_len); @@ -783,16 +783,21 @@ static int ntfs_fuse_mknod(const char *org_path, mode_t mode, int stream_name_len; int res = 0; - if (mode && !(mode & S_IFREG)) + if (mode && !(mode & (S_IFREG | S_IFIFO | S_IFSOCK))) return -EOPNOTSUPP; stream_name_len = ntfs_fuse_parse_path(org_path, &path, &stream_name); if (stream_name_len < 0) return stream_name_len; + if (stream_name_len && mode && !(mode & S_IFREG)) { + res = -EINVAL; + goto exit; + } if (!stream_name_len) - res = ntfs_fuse_create(path, NTFS_DT_REG); + res = ntfs_fuse_create(path, mode & S_IFMT); else res = ntfs_fuse_create_stream(path, stream_name, stream_name_len); +exit: free(path); if (stream_name_len) free(stream_name); @@ -963,7 +968,7 @@ static int ntfs_fuse_mkdir(const char *path, { if (strchr(path, ':') && ctx->streams == NF_STREAMS_INTERFACE_WINDOWS) return -EINVAL; /* n/a for named data streams. */ - return ntfs_fuse_create(path, NTFS_DT_DIR); + return ntfs_fuse_create(path, S_IFDIR); } static int ntfs_fuse_rmdir(const char *path)