spanskiblog/content/posts/symlinks.md

44 lines
1.1 KiB
Markdown
Raw Normal View History

2022-12-24 17:42:40 +01:00
2022-12-24 17:09:22 +01:00
+++
2023-02-27 21:59:02 +01:00
date="2023-02-03"
2022-12-24 17:09:22 +01:00
author="spanskiduh"
title="symlinks"
2022-12-24 17:42:40 +01:00
description="click to read about symlinks"
2022-12-24 17:09:22 +01:00
+++
# Difference between hardlinks and symlinks
### Hardlinks
- implementation of `ln`
- kinda like shortcut, but a shortcut to a physical memory location!!!!
```c
/*
* creates new file, that points to same memory location as provided file
* - if one of the files is edited, then both files change
* - if one of the files gets deleted, then just inode of that file, that points to that location is deleted
* other file stays undeleted, with same content
*/
int hardlink(char *dest, char *name) {
if(link(dest, name) < 0)
return errno;
return 0;
}
```
### Softlinks
- implementation of `ln -s`
- it works like a shortcut to original file
```c
/*
* creates a new file, that points to provided file
* - if one of the files is edited, then both files change
* - if original file gets deleted, then also disk contents gets deleted, and link is broken
*/
int softlink(char *dest, char *name) {
if(symlink(dest, name) < 0)
return errno;
return 0;
}
```