---
name: "FAT_IOCTL_SET_ATTRIBUTES"
section: "2const"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/FAT_IOCTL_SET_ATTRIBUTES"
---

# FAT\_IOCTL\_SET\_ATTRIBUTES(2const)

get and set file attributes in a FAT filesystem

## NAME

FAT\_IOCTL\_GET\_ATTRIBUTES, FAT\_IOCTL\_SET\_ATTRIBUTES - get and set file attributes in a FAT filesystem

## LIBRARY

Standard C library (*libc*, *-lc*)

## SYNOPSIS

```
#include <linux/msdos_fs.h>  /* Definition of FAT_* and
                                ATTR_* constants */
#include <sys/ioctl.h>
```

**int ioctl(int** *fd***, FAT\_IOCTL\_GET\_ATTRIBUTES, uint32\_t \****attr***);** **int ioctl(int** *fd***, FAT\_IOCTL\_SET\_ATTRIBUTES, uint32\_t \****attr***);**

## DESCRIPTION

Files and directories in the FAT filesystem possess an attribute bit mask that can be read with **FAT\_IOCTL\_GET\_ATTRIBUTES** and written with **FAT\_IOCTL\_SET\_ATTRIBUTES**.

The *fd* argument contains a file descriptor for a file or directory. It is sufficient to create the file descriptor by calling [**open**(2)](/open/2.md) with the **O\_RDONLY** flag.

The *attr* argument contains a pointer to a bit mask. The bits of the bit mask are:

- **ATTR\_RO**

  This bit specifies that the file or directory is read-only.

- **ATTR\_HIDDEN**

  This bit specifies that the file or directory is hidden.

- **ATTR\_SYS**

  This bit specifies that the file is a system file.

- **ATTR\_VOLUME**

  This bit specifies that the file is a volume label. This attribute is read-only.

- **ATTR\_DIR**

  This bit specifies that this is a directory. This attribute is read-only.

- **ATTR\_ARCH**

  This bit indicates that this file or directory should be archived. It is set when a file is created or modified. It is reset by an archiving system.

The zero value **ATTR\_NONE** can be used to indicate that no attribute bit is set.

## RETURN VALUE

On success, 0 is returned. On error, -1 is returned, and *errno* is set to indicate the error.

## STANDARDS

Linux.

## HISTORY

Linux 2.6.12.

## EXAMPLES

The following program demonstrates the usage of [**ioctl**(2)](/ioctl/2.md) to manipulate file attributes. The program reads and displays the archive attribute of a file. After inverting the value of the attribute, the program reads and displays the attribute again.

The following was recorded when applying the program for the file */mnt/user/foo*:

```
# ./toggle_fat_archive_flag /mnt/user/foo
Archive flag is set
Toggling archive flag
Archive flag is not set
```

### Program source (toggle\_fat\_archive\_flag.c)

```
#include <fcntl.h>
#include <linux/msdos_fs.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h>
/*
 * Read file attributes of a file on a FAT filesystem.
 * Output the state of the archive flag.
 */
static uint32_t
readattr(int fd)
{
    int       ret;
    uint32_t  attr;
    ret = ioctl(fd, FAT_IOCTL_GET_ATTRIBUTES, &attr);
    if (ret == -1) {
        perror("ioctl");
        exit(EXIT_FAILURE);
    }
    if (attr & ATTR_ARCH)
        printf("Archive flag is set\n");
    else
        printf("Archive flag is not set\n");
    return attr;
}
int
main(int argc, char *argv[])
{
    int       fd;
    int       ret;
    uint32_t  attr;
    if (argc != 2) {
        printf("Usage: %s FILENAME\n", argv[0]);
        exit(EXIT_FAILURE);
    }
    fd = open(argv[1], O_RDONLY);
    if (fd == -1) {
        perror("open");
        exit(EXIT_FAILURE);
    }
    /*
     * Read and display the FAT file attributes.
     */
    attr = readattr(fd);
    /*
     * Invert archive attribute.
     */
    printf("Toggling archive flag\n");
    attr ^= ATTR_ARCH;
    /*
     * Write the changed FAT file attributes.
     */
    ret = ioctl(fd, FAT_IOCTL_SET_ATTRIBUTES, &attr);
    if (ret == -1) {
        perror("ioctl");
        exit(EXIT_FAILURE);
    }
    /*
     * Read and display the FAT file attributes.
     */
    readattr(fd);
    close(fd);
    exit(EXIT_SUCCESS);
}
```

## SEE ALSO

[**ioctl**(2)](/ioctl/2.md), [**ioctl\_fat**(2)](/ioctl_fat/2.md)
