L4Re/departure

libext2fs/lib/libe2p/fgetflags.c

617:2733e5770ee9
9 months ago Paul Boddie Made the run command wait for completion, introducing the spawn command to run programs in the background. Introduced conveniences for waiting for the last job to be initiated and for piping from the last job, also subscribing to signals from pipe-supplying jobs so that they may be transparently removed from the job list upon completion. Augmented the job listing with the "+" notation familiar from Unix. Prevented new jobs from being started when no job slots are available.
     1 /*     2  * fgetflags.c		- Get a file flags on an ext2 file system     3  *     4  * Copyright (C) 1993, 1994  Remy Card <card@masi.ibp.fr>     5  *                           Laboratoire MASI, Institut Blaise Pascal     6  *                           Universite Pierre et Marie Curie (Paris VI)     7  *     8  * %Begin-Header%     9  * This file may be redistributed under the terms of the GNU Library    10  * General Public License, version 2.    11  * %End-Header%    12  */    13     14 /*    15  * History:    16  * 93/10/30	- Creation    17  */    18     19 #ifndef _LARGEFILE_SOURCE    20 #define _LARGEFILE_SOURCE    21 #endif    22 #ifndef _LARGEFILE64_SOURCE    23 #define _LARGEFILE64_SOURCE    24 #endif    25     26 #include "config.h"    27 #if HAVE_ERRNO_H    28 #include <errno.h>    29 #endif    30 #if HAVE_UNISTD_H    31 #include <unistd.h>    32 #endif    33 #include <sys/types.h>    34 #include <sys/stat.h>    35 #if HAVE_EXT2_IOCTLS    36 #include <fcntl.h>    37 #include <sys/ioctl.h>    38 #endif    39     40 #include "e2p.h"    41     42 #ifndef O_LARGEFILE    43 #define O_LARGEFILE 0    44 #endif    45 #ifndef O_NOFOLLOW    46 #define O_NOFOLLOW 0    47 #endif    48     49 #define OPEN_FLAGS (O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_NOFOLLOW)    50     51 int fgetflags (const char * name, unsigned long * flags)    52 {    53 	struct stat buf;    54 #if HAVE_STAT_FLAGS && !(APPLE_DARWIN && HAVE_EXT2_IOCTLS)    55     56 	if (stat (name, &buf) == -1)    57 		return -1;    58     59 	*flags = 0;    60 #ifdef UF_IMMUTABLE    61 	if (buf.st_flags & UF_IMMUTABLE)    62 		*flags |= EXT2_IMMUTABLE_FL;    63 #endif    64 #ifdef UF_APPEND    65 	if (buf.st_flags & UF_APPEND)    66 		*flags |= EXT2_APPEND_FL;    67 #endif    68 #ifdef UF_NODUMP    69 	if (buf.st_flags & UF_NODUMP)    70 		*flags |= EXT2_NODUMP_FL;    71 #endif    72     73 	return 0;    74 #elif APPLE_DARWIN && HAVE_EXT2_IOCTLS    75 	int f, save_errno = 0;    76     77 	f = -1;    78 	save_errno = syscall(SYS_fsctl, name, EXT2_IOC_GETFLAGS, &f, 0);    79 	*flags = f;    80 	return (save_errno);    81 #elif HAVE_EXT2_IOCTLS    82 	int fd, r, f, save_errno = 0;    83     84 	fd = open(name, OPEN_FLAGS);    85 	if (fd == -1) {    86 		if (errno == ELOOP || errno == ENXIO)    87 			errno = EOPNOTSUPP;    88 		return -1;    89 	}    90 	r = ioctl(fd, EXT2_IOC_GETFLAGS, &f);    91 	if (r == -1) {    92 		if (errno == ENOTTY)    93 			errno = EOPNOTSUPP;    94 		save_errno = errno;    95 	}    96 	*flags = f;    97 	close(fd);    98 	if (save_errno)    99 		errno = save_errno;   100 	return r;   101 #else   102 	errno = EOPNOTSUPP;   103 	return -1;   104 #endif   105 }