source: trunk/kernel/libk/user_dir.h @ 654

Last change on this file since 654 was 651, checked in by alain, 5 years ago

1) Improve the VMM MMAP allocator: implement the "buddy" algorithm
to allocate only aligned blocks.
2) fix a bug in the pthread_join() / pthread_exit() mmechanism.

File size: 6.3 KB
Line 
1/*
2 * user_dir.h -  DIR related operations definition.
3 *
4 * Authors   Alain Greiner   (2016,2017,2018,2019)
5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#ifndef _REMOTE_DIR_H_
25#define _REMOTE_DIR_H_
26
27#include <kernel_config.h>
28#include <hal_kernel_types.h>
29#include <xlist.h>
30
31/*** Forward declarations   ***/
32struct vfs_inode_s;
33
34/*****************************************************************************************
35 * This file defines the operations on a directory open by an user process
36 *
37 * - An user process open a directory by calling the "opendir()" syscall.
38 *   The user_dir_create() function allocates physical memory to create in the cluster
39 *   containing the directory inode one or several physical pages to implement an array
40 *   of "dirent". This array is mapped in the user process space as an ANON vseg.
41 *   It allocates also an "user_dir_t" descriptor structure defined below, registered
42 *   in the xlist rooted in the reference user process descriptor.
43 * - This "user_dir_t" structure contains the total number of "entries", the "current"
44 *   pointer used by the readdir() syscall, and an "ident" field, that is actually
45 *   the DIR user pointer on the "dirent" array in user space.
46 * - all these structures are destroyed by the closedir() syscall, that release to the
47 *   kernel all allocated memory.
48 *
49 * WARNING: ALMOS-MKH makes explicitely the assumption that sizeof(dirent) == 64
50 ****************************************************************************************/
51
52/*****************************************************************************************
53 * This structure defines the user_dir_t decriptor, that is the kernel implementation
54 * of a directory open by an user process.
55 ****************************************************************************************/
56
57typedef struct user_dir_s
58{
59    intptr_t           ident;           /*! pointer on dirent array in user space       */ 
60    xlist_entry_t      list;            /*! member of list of open dir in same process  */
61    uint32_t           entries;         /*! actual number of dirent in dirent array     */
62    uint32_t           current;         /*! current dirent index in dirent array        */
63}
64user_dir_t;
65
66/*****************************************************************************************
67 * This function returns an extended pointer on the user_dir_t structure,
68 * identified by the DIR pointer in the user process virtual space.
69 * It makes an associative search, scanning the xlist of user_dir_t rooted
70 * in the reference process descriptor.
71 *****************************************************************************************
72 * @ ident    : [in] DIR virtual address, used as identifier.
73 * @ returns extended pointer on user_dir_t if success / returns XPTR_NULL if not found.
74 ****************************************************************************************/
75xptr_t user_dir_from_ident( intptr_t  ident );
76
77/*****************************************************************************************
78 * This function allocates memory and initializes a user_dir_t structure in the cluster
79 * containing the directory inode identified by the <inode> argument and map the
80 * user accessible dirent array in the reference user process VSL, identified by the
81 * <ref_xp> argument.
82 * It must be executed by a thread running in the cluster containing the target inode.
83 * Use the RPC_USER_DIR_CREATE when the client thread is remote.
84 * It makes the following actions:
85 * - the allocation of one user_dir_t descriptor in the directory inode cluster.
86 * - the allocation of one or several physical pages in reference cluster to store
87 *   all directory entries in an array of 64 bytes dirent structures,
88 * - the initialisation of this array from informations found in the directory mapper.
89 * - the creation of an ANON vseg containing this dirent array in reference process VMM,
90 *   and the mapping of the relevant physical pages in this vseg.
91 * - the registration of the created user_dir_t structure in the xlist rooted
92 *   in the reference process,
93 * It returns a local pointer on the created user_dir_t structure.
94 *****************************************************************************************
95 * @ inode    : [in] local pointer on the directory inode.
96 * @ ref_xp   : [in] extended pointer on the reference user process descriptor.
97 * @ return local pointer on user_dir_t if success / return XPTR_NULL if failure.
98 ****************************************************************************************/
99user_dir_t * user_dir_create( struct vfs_inode_s * inode,
100                              xptr_t               ref_xp );
101
102/*****************************************************************************************
103 * This function removes a user_dir_t structure from the xlist of user_dir_t
104 * structures rooted in the reference process descriptor, release all memory
105 * allocated for the user_dir_t struct in the directory inode cluster, including
106 * the dirent array, and delete the ANON vseg copies in all process VMM copies,
107 * using parallel RPCs.
108 * It must be executed by a thread running in the cluster containing the target inode.
109 * Use the RPC_USER_DIR_DESTROY when the client thread is remote.
110 *****************************************************************************************
111 * @ dir      : [in] local pointer on user_dir_t structure.
112 * @ ref_xp   : [in] extended pointer on the reference user process descriptor.
113 ****************************************************************************************/
114void user_dir_destroy( struct user_dir_s * dir,
115                       xptr_t              ref_xp );
116
117
118#endif
Note: See TracBrowser for help on using the repository browser.