LLAPI\_FILE\_OPEN(3) Lustre Library Functions LLAPI\_FILE\_OPEN(3)

# [NAME](#NAME)

llapi\_file\_open, llapi\_file\_create - open and possibly create a file or a device on a Lustre filesystem

# [SYNOPSIS](#SYNOPSIS)

```
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <lustre/lustreapi.h>
```

```
int llapi_file_open(const char *name, int flags, int mode,
                    unsigned long long stripe_size, int stripe_offset,
                    int stripe_count, int stripe_pattern);
```

```
int llapi_file_create(const char *name, unsigned long long stripe_size,
                      int stripe_offset, int stripe_count,
                      int stripe_pattern);

```

# [DESCRIPTION](#DESCRIPTION)

**llapi\_file\_create()** call is equivalent to **llapi\_file\_open** call with *flags* equal to **O\_CREAT|O\_WRONLY** and *mode* equal to **0644**, followed by file close.

**llapi\_file\_open()** opens a file with a given *name* on a Lustre filesystem.

[*flags*](#flags)

can be a combination of **O\_RDONLY**, **O\_WRONLY**, **O\_RDWR**, **O\_CREAT**, **O\_EXCL**, **O\_NOCTTY**, **O\_TRUNC**, **O\_APPEND**, **O\_NONBLOCK**, **O\_SYNC**, **FASYNC**, **O\_DIRECT**, **O\_LARGEFILE**, **O\_DIRECTORY**, **O\_NOFOLLOW**, **O\_NOATIME**.

Refer to [**open(2)**](/man/enterprise-packages/lustre/open.2) man page for a detailed description.

[*mode*](#mode)

specifies the permission bits to be used for a new file when **O\_CREAT** is used.

Refer to [**open(2)**](/man/enterprise-packages/lustre/open.2) man page for a detailed description.

[*stripe\_size*](#stripe_size)

specifies stripe size in bytes and should be multiple of 64 KiB not exceeding 4 GiB.

[*stripe\_offset*](#stripe_offset)

specifies an OST index from which the file should start, -1 to use the default setting.

[*stripe\_count*](#stripe_count)

specifies number of OSTs to stripe the file across, -1 to use the default setting.

[*stripe\_pattern*](#stripe_pattern)

specifies striping pattern, only LOV\_PATTERN\_RAID0 is available in this Lustre version, 0 to use the default setting.

# [RETURN VALUES](#RETURN_VALUES)

**llapi\_file\_open()** and **llapi\_file\_create()** return:

&gt;=0

on success, for **llapi\_file\_open** the return value is a file descriptor.

&lt;0

on failure, the absolute value is an error code.

# [ERRORS](#ERRORS)

EINVAL

*stripe\_size* or *stripe\_offset* or *stripe\_count* or *stripe\_pattern* is invalid.

EEXIST

Striping information has already been set and cannot be altered.

*name* already exists.

EALREADY

Striping information has already been set and cannot be altered.

ENOTTY

*name* may not point to a Lustre filesystem.

# [EXAMPLES](#EXAMPLES)

```
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <lustre/lustreapi.h>
int main(int argc, char *argv[])
{


        int rc;


        if (argc != 2)


                return -1;


        rc = llapi_file_create(argv[1], 1048576, 0, 2, LOV_PATTERN_RAID0);


        if (rc < 0) {


                fprintf(stderr, "file creation has failed, %s\n", strerror(-rc));


                return -1;


        }


        printf("%s with stripe size 1048576, striped across 2 OSTs,"


               " has been created!\n", argv[1]);


        return 0;
}
```

# [AVAILABILITY](#AVAILABILITY)

**llapi\_file\_open()** and **llapi\_file\_create()** are part of the [**lustre**(7)](/man/enterprise-packages/lustre/lustre.7) user application interface library since release 2.4.0

# [SEE ALSO](#SEE_ALSO)

[**open**(2)](/man/enterprise-packages/lustre/open.2), [**lustre**(7)](/man/enterprise-packages/lustre/lustre.7), [**lustreapi**(7)](/man/enterprise-packages/lustre/lustreapi.7)

2024-08-23 Lustre User API

---

Document: llapi_file_create(3) from lustre 2.17.59-r1 (Chainguard OS)
Source: https://github.com/lustre/lustre-release
