Technische Universität Braunschweig
  • Study & Teaching
    • Beginning your Studies
      • Prospective Students
      • Degree Programmes
      • Application
      • Fit4TU
      • Why Braunschweig?
    • During your Studies
      • Fresher's Hub
      • Term Dates
      • Courses
      • Practical Information
      • Beratungsnavi
      • Additional Qualifications
      • Financing and Costs
      • Special Circumstances
      • Health and Well-being
      • Campus life
    • At the End of your Studies
      • Discontinuation and Credentials Certification
      • After graduation
      • Alumni*ae
    • For Teaching Staff
      • Strategy, Offers and Information
      • Learning Management System Stud.IP
    • Contact
      • Study Service Centre
      • Academic Advice Service
      • Student Office
      • Career Service
  • Research
    • Research Profile
      • Core Research Areas
      • Clusters of Excellence at TU Braunschweig
      • Research Projects
      • Research Centres
      • Professors‘ Research Profiles
    • Early Career Researchers
      • Support in the early stages of an academic career
      • PhD-Students
      • Postdocs
      • Junior research group leaders
      • Junior Professorship and Tenure-Track
      • Habilitation
      • Service Offers for Scientists
    • Research Data & Transparency
      • Transparency in Research
      • Research Data
      • Open Access Strategy
      • Digital Research Announcement
    • Research Funding
      • Research Funding Network
      • Research funding
    • Contact
      • Research Services
      • Academy for Graduates
  • International
    • International Students
      • Why Braunschweig?
      • Degree seeking students
      • Exchange Studies
      • TU Braunschweig Summer School
      • Refugees
      • International Student Support
    • Going Abroad
      • Studying abroad
      • Internships abroad
      • Teaching and research abroad
      • Working abroad
    • International Researchers
      • Welcome Support
      • PhD Studies
      • Service for host institutes
    • Language and intercultural competence training
      • Learning German
      • Learning Foreign Languages
      • Intercultural Communication
    • International Profile
      • Internationalisation
      • International Cooperations
      • Strategic Partnerships
      • International networks
    • International House
      • About us
      • Contact & Office Hours
      • News and Events
      • International Days
      • 5th Student Conference: Internationalisation of Higher Education
      • Newsletter, Podcast & Videos
      • Job Advertisements
  • TU Braunschweig
    • Our Profile
      • Aims & Values
      • Regulations and Guidelines
      • Alliances & Partners
      • The University Development Initiative 2030
      • Foundation University
      • Facts & Figures
      • Our History
    • Career
      • Working at TU Braunschweig
      • Vacancies
    • Economy & Business
      • Entrepreneurship
      • Friends & Supporters
    • General Public
      • Check-in for Students
      • The Student House
      • Access to the University Library
    • Media Services
      • Communications and Press Service
      • Services for media
      • Film and photo permits
      • Advices for scientists
      • Topics and stories
    • Contact
      • General Contact
      • Getting here
  • Organisation
    • Presidency & Administration
      • Executive Board
      • Designated Offices
      • Administration
      • Committees
    • Faculties
      • Carl-Friedrich-Gauß-Fakultät
      • Faculty of Life Sciences
      • Faculty of Architecture, Civil Engineering and Environmental Sciences
      • Faculty of Mechanical Engineering
      • Faculty of Electrical Engineering, Information Technology, Physics
      • Faculty of Humanities and Education
    • Institutes
      • Institutes from A to Z
    • Facilities
      • University Library
      • Gauß-IT-Zentrum
      • Professional and Personnel Development
      • International House
      • The Project House of the TU Braunschweig
      • Transfer Service
      • University Sports Center
      • Facilities from A to Z
    • Equal Opportunity Office
      • Equal Opportunity Office
      • Family
      • Diversity for Students
  • Search
  • Quicklinks
    • People Search
    • Webmail
    • cloud.TU Braunschweig
    • Messenger
    • Cafeteria
    • Courses
    • Stud.IP
    • Library Catalogue
    • IT Services
    • Information Portal (employees)
    • Link Collection
    • DE
    • EN
    • IBR YouTube
    • Facebook
    • Instagram
    • YouTube
    • LinkedIn
    • Mastodon
Menu
  • Organisation
  • Faculties
  • Carl-Friedrich-Gauß-Fakultät
  • Institutes
  • Institute of Operating Systems and Computer Networks
  • Prof. Dr.-Ing. Christian Dietrich
  • Advent(2)
  • For Christmas, Checks are Extended
Logo IBR
IBR Login
  • Institute of Operating Systems and Computer Networks
    • News
    • About us
      • Whole Team
      • Directions
      • Floor Plan
      • Projects
      • Publications
      • Software
      • News Archive
    • Connected and Mobile Systems
      • Team
      • Courses
      • Theses
      • Projects
      • Publications
      • Software
      • Datasets
    • Reliable System Software
      • Overview
      • Team
      • Teaching
      • Theses & Jobs
      • Research
      • Publications
    • Algorithms
      • Team
      • Courses
      • Theses
      • Projects
      • Publications
    • Microprocessor Lab
    • Education
      • Winter 2025/2026
      • Summer 2025
      • Winter 2024/2025
      • Theses
    • Services
      • Library
      • Mailinglists
      • Webmail
      • Knowledge Base
      • Wiki
      • Account Management
      • Services Status
    • Spin-Offs
      • Docoloc
      • bliq (formerly AIPARK)
      • Confidential Technologies
    • Research Cooperations
      • IST.hub
  • Task Overview
  • Git repository
  • Mailing list
  • Matrix-Channel

For Christmas, Checks are Extended

☃️
Git-Repository: Template Solution Solution-Diff (Solution is posted at 18:00 CET)
Workload: 65 lines of code
Important System-Calls: getxattr(2), setxattr(2), listxattr(2)
Recommended Reads:
  • Dec. 3: A Map to Persistance! memory 65 lines [mmap(2), ftruncate(2)]
Illustration for this exercsie

Oh noes! Yesterday, we build a utility to sort the wishlists of all children on the entire planet. However, it would be a shame if the hardware, where we store that wishlist pile, had a disk error and little Helen received a set of "bleeding crooks" instead of the desired "building bricks" due to some bit flips on the disk. That would be quite disappointing and not at all joyful and happy. Therefore, the ELF team decided to add some checksums to the sorting office.

Extended File Attributes

With a checksum over the content of a file, we calculate meta data that is closely associated with the file. While we could store the wishlist and the checksum in two different files (e.g., helen and helen.sha256), it would be great if we could associate data and meta data more closely. For example, if we use the 2-file solution and rename one or more a wishlists, we always have to remember to also rename the checksum file. Not even speaking of those poor children whose names end with .sha256... looking at you little bobby table.

And with modern Linuxes, we can solve this problem with extended file attributes (xattr(7)). With extended attributes, we can attach key-value pairs to a file and the OS keeps track of those attributes and moves files and attributes synchronously. Unlike Windows' NTFS file streams, Linux imposes some restrictions for the size of the attribute list. But for our checksum that we want to attach to the wishlist, we are just fine.

If you want to play around with extended attributes, you should install the xattr(1) tool:

$ touch my-file
$ xattr -w user.checksum 1235 my-file
$ xattr -l my-file
user.checksum: 1235

Interestingly, extended attributes are a quite basic mechanism in Linux and are the basis for other well-known mechanisms. For example, on ext4, the access control lists (acl(5) are stored as serialized objects within extended attributes:

$ setfacl -m "u:stettberger:rwx" my-file
$ xattr -l my-file
user.checksum: 1235
system.posix_acl_access:
0000   02 00 00 00 01 00 06 00 FF FF FF FF 02 00 07 00    ................
0010   78 27 00 00 04 00 04 00 FF FF FF FF 10 00 07 00    x'..............
0020   FF FF FF FF 20 00 04 00 FF FF FF FF                .... .......

With these ACLs, users can control access to a file in a much more fine-grained way. For this to work, the user sets the serialized ACLs as an attribute, which the kernel interprets when accessing a file. To distinguish between different uses of extended attributes, the attribute key is a stringly-typed name with different prefixes. To obey this, we have to prefix our checksum attribute with user..

Task

Write a small utility program that takes a file name, maps its contents into its address space with mmap(2), and uses calc_checksum to derive an checksum over the file contents. If the given file has no user.checksum attribute yet, just set the checksum, otherwise, compare the old checksum with the newly calculated one and issue an error message if they mismatch.

Hints

  • Do not try to serialize the checksum to hexadecimal, just dump the checksum as a byte array of fixed size as an extended attribute.

Last modified: 2023-12-01 15:52:27.556043, Last author: , Permalink: /p/advent-09-xattr


last changed 2023-12-01, 15:52 by Prof. Dr.-Ing. Christian Dietrich

For All Visitors

Vacancies of TU Braunschweig
Career Service' Job Exchange 
Merchandising

For Students

Term Dates
Courses
Degree Programmes
Information for Freshman
TUCard

Internal Tools

Glossary (GER-EN)
Change your Personal Data

Contact

Technische Universität Braunschweig
Universitätsplatz 2
38106 Braunschweig

P. O. Box: 38092 Braunschweig
GERMANY

Phone: +49 (0) 531 391-0

Getting here

© Technische Universität Braunschweig
Imprint Privacy Accessibility