server: Store the Unix name in the fd.
diff --git a/server/fd.c b/server/fd.c
index 72ebcfe..f57ed97 100644
--- a/server/fd.c
+++ b/server/fd.c
@@ -190,6 +190,7 @@
unsigned int access; /* file access (FILE_READ_DATA etc.) */
unsigned int options; /* file options (FILE_DELETE_ON_CLOSE, FILE_SYNCHRONOUS...) */
unsigned int sharing; /* file sharing mode */
+ char *unix_name; /* unix file name */
int unix_fd; /* unix file descriptor */
unsigned int no_fd_status;/* status to return when unix_fd is -1 */
unsigned int signaled :1; /* is the fd signaled? */
@@ -1368,6 +1369,7 @@
if (fd->completion) release_object( fd->completion );
remove_fd_locks( fd );
+ free( fd->unix_name );
list_remove( &fd->inode_entry );
if (fd->poll_index != -1) remove_poll_user( fd, fd->poll_index );
if (fd->inode)
@@ -1438,6 +1440,7 @@
fd->options = 0;
fd->sharing = 0;
fd->unix_fd = -1;
+ fd->unix_name = NULL;
fd->signaled = 1;
fd->fs_locks = 1;
fd->poll_index = -1;
@@ -1470,6 +1473,7 @@
fd->access = 0;
fd->options = options;
fd->sharing = 0;
+ fd->unix_name = NULL;
fd->unix_fd = -1;
fd->signaled = 0;
fd->fs_locks = 0;
@@ -1577,6 +1581,9 @@
}
else rw_mode = O_RDONLY;
+ if (!(fd->unix_name = mem_alloc( strlen(name) + 1 ))) goto error;
+ strcpy( fd->unix_name, name );
+
if ((fd->unix_fd = open( name, rw_mode | (flags & ~O_TRUNC), *mode )) == -1)
{
/* if we tried to open a directory for write access, retry read-only */
@@ -2003,6 +2010,24 @@
if (root) release_object( root );
}
+/* get the Unix name from a file handle */
+DECL_HANDLER(get_handle_unix_name)
+{
+ struct fd *fd;
+
+ if ((fd = get_handle_fd_obj( current->process, req->handle, 0 )))
+ {
+ if (fd->unix_name)
+ {
+ data_size_t name_len = strlen( fd->unix_name );
+ reply->name_len = name_len;
+ if (name_len <= get_reply_max_size()) set_reply_data( fd->unix_name, name_len );
+ else set_error( STATUS_BUFFER_OVERFLOW );
+ }
+ release_object( fd );
+ }
+}
+
/* get a Unix fd to access a file */
DECL_HANDLER(get_handle_fd)
{
diff --git a/server/protocol.def b/server/protocol.def
index a0e1702..ca44e38 100644
--- a/server/protocol.def
+++ b/server/protocol.def
@@ -1003,6 +1003,15 @@
@END
+/* Get the Unix name from a file handle */
+@REQ(get_handle_unix_name)
+ obj_handle_t handle; /* file handle */
+@REPLY
+ data_size_t name_len; /* unix name length */
+ VARARG(name,string); /* unix name */
+@END
+
+
/* Get a Unix fd to access a file */
@REQ(get_handle_fd)
obj_handle_t handle; /* handle to the file */
diff --git a/server/request.h b/server/request.h
index 87b6a75..8aa8a9d 100644
--- a/server/request.h
+++ b/server/request.h
@@ -148,6 +148,7 @@
DECL_HANDLER(create_file);
DECL_HANDLER(open_file_object);
DECL_HANDLER(alloc_file_handle);
+DECL_HANDLER(get_handle_unix_name);
DECL_HANDLER(get_handle_fd);
DECL_HANDLER(flush_file);
DECL_HANDLER(lock_file);
@@ -394,6 +395,7 @@
(req_handler)req_create_file,
(req_handler)req_open_file_object,
(req_handler)req_alloc_file_handle,
+ (req_handler)req_get_handle_unix_name,
(req_handler)req_get_handle_fd,
(req_handler)req_flush_file,
(req_handler)req_lock_file,
@@ -846,6 +848,9 @@
C_ASSERT( FIELD_OFFSET(struct alloc_file_handle_request, fd) == 20 );
C_ASSERT( FIELD_OFFSET(struct alloc_file_handle_reply, handle) == 8 );
C_ASSERT( sizeof(struct alloc_file_handle_reply) == 16 );
+C_ASSERT( FIELD_OFFSET(struct get_handle_unix_name_request, handle) == 12 );
+C_ASSERT( FIELD_OFFSET(struct get_handle_unix_name_reply, name_len) == 8 );
+C_ASSERT( sizeof(struct get_handle_unix_name_reply) == 16 );
C_ASSERT( FIELD_OFFSET(struct get_handle_fd_request, handle) == 12 );
C_ASSERT( FIELD_OFFSET(struct get_handle_fd_reply, type) == 8 );
C_ASSERT( FIELD_OFFSET(struct get_handle_fd_reply, removable) == 12 );
diff --git a/server/trace.c b/server/trace.c
index b7dec85..a529e5b 100644
--- a/server/trace.c
+++ b/server/trace.c
@@ -1457,6 +1457,17 @@
fprintf( stderr, " handle=%04x", req->handle );
}
+static void dump_get_handle_unix_name_request( const struct get_handle_unix_name_request *req )
+{
+ fprintf( stderr, " handle=%04x", req->handle );
+}
+
+static void dump_get_handle_unix_name_reply( const struct get_handle_unix_name_reply *req )
+{
+ fprintf( stderr, " name_len=%u", req->name_len );
+ dump_varargs_string( ", name=", cur_size );
+}
+
static void dump_get_handle_fd_request( const struct get_handle_fd_request *req )
{
fprintf( stderr, " handle=%04x", req->handle );
@@ -3832,6 +3843,7 @@
(dump_func)dump_create_file_request,
(dump_func)dump_open_file_object_request,
(dump_func)dump_alloc_file_handle_request,
+ (dump_func)dump_get_handle_unix_name_request,
(dump_func)dump_get_handle_fd_request,
(dump_func)dump_flush_file_request,
(dump_func)dump_lock_file_request,
@@ -4075,6 +4087,7 @@
(dump_func)dump_create_file_reply,
(dump_func)dump_open_file_object_reply,
(dump_func)dump_alloc_file_handle_reply,
+ (dump_func)dump_get_handle_unix_name_reply,
(dump_func)dump_get_handle_fd_reply,
(dump_func)dump_flush_file_reply,
(dump_func)dump_lock_file_reply,
@@ -4318,6 +4331,7 @@
"create_file",
"open_file_object",
"alloc_file_handle",
+ "get_handle_unix_name",
"get_handle_fd",
"flush_file",
"lock_file",