]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libxcmd/projects.c
2 * Copyright (c) 2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <xfs/project.h>
24 #define PROJID "/etc/projid"
25 #define PROJECT_PATHS "/etc/projects"
29 static FILE *projects
;
30 static fs_project_t p
;
31 static char projects_buffer
[512];
33 static FILE *project_paths
;
34 static fs_project_path_t pp
;
35 static char project_paths_buffer
[1024];
43 projects_file
= PROJECT_PATHS
;
50 projects
= fopen(projid_file
, "r");
57 project_paths
= fopen(projects_file
, "r");
72 fclose(project_paths
);
79 char *idstart
, *idend
;
80 size_t size
= sizeof(projects_buffer
) - 1;
85 if (!fgets(projects_buffer
, size
, projects
))
88 * /etc/projid file format -- "name:id\n", ignore "^#..."
90 if (projects_buffer
[0] == '#')
92 idstart
= strchr(projects_buffer
, ':');
95 if ((idstart
+ 1) - projects_buffer
>= size
)
97 idend
= strchr(idstart
+1, ':');
101 p
.pr_prid
= atoi(idstart
+1);
102 p
.pr_name
= &projects_buffer
[0];
113 fs_project_t
*p
= NULL
;
116 while ((p
= getprent()) != NULL
)
117 if (strcmp(p
->pr_name
, name
) == 0)
127 fs_project_t
*p
= NULL
;
130 while ((p
= getprent()) != NULL
)
131 if (p
->pr_prid
== prid
)
140 char *nmstart
, *nmend
;
141 size_t size
= sizeof(project_paths_buffer
) - 1;
146 if (!fgets(project_paths_buffer
, size
, project_paths
))
149 * /etc/projects format -- "id:pathname\n", ignore "^#..."
151 if (project_paths_buffer
[0] == '#')
153 nmstart
= strchr(project_paths_buffer
, ':');
156 if ((nmstart
+ 1) - project_paths_buffer
>= size
)
158 nmend
= strchr(nmstart
+ 1, '\n');
162 pp
.pp_pathname
= nmstart
+ 1;
163 pp
.pp_prid
= atoi(&project_paths_buffer
[0]);
179 if (xfsctl(name
, fd
, XFS_IOC_FSGETXATTR
, &fsx
)) {
180 perror("XFS_IOC_FSGETXATTR");
183 *projid
= fsx
.fsx_projid
;
196 if ((error
= xfsctl(name
, fd
, XFS_IOC_FSGETXATTR
, &fsx
)) == 0) {
197 fsx
.fsx_projid
= projid
;
198 error
= xfsctl(name
, fd
, XFS_IOC_FSSETXATTR
, &fsx
);