Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method for creating volume label #31

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.DS_Store
.vscode/
node_modules/
package-lock.json
tests/label.img
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,20 @@ exports.createFileSystem = function (volume, opts, cb) {
else _.delayedCall(cb, S.err.NOSYS());
}, (_n_ === '_nested_')); };

fs.createLabel = function (name, cb) {
fs.open(name, "a", (e, _fd) => {
if (e) {
cb(e);
} else {
let fd = fileDescriptors[_fd]
fd.entry.Attr.volume_id = true
fd.entry.FstClusLO = 0
fd.entry.FstClusHI = 0

fs._updateEntry(fd.entry, {}, cb);
}
})
};

return fs;
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "fs implementation on top of raw FAT16/FAT32 block source",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"label-testcase": "nodejs tests/label.js"
},
"repository": {
"type": "git",
Expand Down
37 changes: 37 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

if ! [ -x "$(command -v blkid)" ]; then
echo 'Error: util-linux is not installed.' >&2
exit 1
fi

if ! [ -x "$(command -v dosfslabel)" ]; then
echo 'Error: dosfstools is not installed.' >&2
exit 1
fi

rm tests/label.img || true

set -e

dd if=/dev/zero of=tests/label.img bs=1M count=10
mkfs.vfat tests/label.img

npm run label-testcase

BLKID=$(blkid tests/label.img)
DOSFSLABEL=$(dosfslabel tests/label.img)

if ! [[ $BLKID == *'LABEL="CIDATA"'* ]]; then
echo "blkid: LABEL is invalid"
exit 1
fi

echo "blkid: LABEL is valid"

if ! [[ $DOSFSLABEL == *"CIDATA"* ]]; then
echo "dosfslabel: label is invalid"
exit 1
fi

echo "dosfslabel: label is valid"
8 changes: 8 additions & 0 deletions tests/label.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var fatfs = require("../");
var createDriverSync = require("../img_volume").createDriverSync

const buffer = createDriverSync("tests/label.img")

const fs = fatfs.createFileSystem(buffer, {allowLowercaseNames: true})

fs.createLabel("cidata", () => {})